2024-01-08 22:06:44 +00:00
|
|
|
import { api } from "./api.js";
|
|
|
|
import { ComfyDialog as _ComfyDialog } from "./ui/dialog.js";
|
2024-01-16 13:27:40 +00:00
|
|
|
import { toggleSwitch } from "./ui/toggleSwitch.js";
|
2024-01-08 22:06:44 +00:00
|
|
|
import { ComfySettingsDialog } from "./ui/settings.js";
|
|
|
|
|
|
|
|
export const ComfyDialog = _ComfyDialog;
|
2023-03-02 21:34:29 +00:00
|
|
|
|
2024-01-13 20:43:20 +00:00
|
|
|
/**
|
2024-06-25 10:49:25 +00:00
|
|
|
* @template { string | (keyof HTMLElementTagNameMap) } K
|
|
|
|
* @typedef { K extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[K] : HTMLElement } ElementType
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @template { string | (keyof HTMLElementTagNameMap) } K
|
|
|
|
* @param { K } tag HTML Element Tag and optional classes e.g. div.class1.class2
|
|
|
|
* @param { string | Element | Element[] | ({
|
2024-01-13 20:43:20 +00:00
|
|
|
* parent?: Element,
|
2024-06-25 10:49:25 +00:00
|
|
|
* $?: (el: ElementType<K>) => void,
|
2024-01-13 20:43:20 +00:00
|
|
|
* dataset?: DOMStringMap,
|
2024-06-25 10:49:25 +00:00
|
|
|
* style?: Partial<CSSStyleDeclaration>,
|
2024-01-13 20:43:20 +00:00
|
|
|
* for?: string
|
2024-06-25 10:49:25 +00:00
|
|
|
* } & Omit<Partial<ElementType<K>>, "style">) | undefined } [propsOrChildren]
|
|
|
|
* @param { string | Element | Element[] | undefined } [children]
|
|
|
|
* @returns { ElementType<K> }
|
2024-01-13 20:43:20 +00:00
|
|
|
*/
|
2023-03-28 02:36:53 +00:00
|
|
|
export function $el(tag, propsOrChildren, children) {
|
2023-03-03 15:20:49 +00:00
|
|
|
const split = tag.split(".");
|
|
|
|
const element = document.createElement(split.shift());
|
2023-06-15 16:36:52 +00:00
|
|
|
if (split.length > 0) {
|
|
|
|
element.classList.add(...split);
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:20:49 +00:00
|
|
|
if (propsOrChildren) {
|
2024-01-13 20:43:20 +00:00
|
|
|
if (typeof propsOrChildren === "string") {
|
|
|
|
propsOrChildren = { textContent: propsOrChildren };
|
|
|
|
} else if (propsOrChildren instanceof Element) {
|
|
|
|
propsOrChildren = [propsOrChildren];
|
|
|
|
}
|
2023-03-03 15:20:49 +00:00
|
|
|
if (Array.isArray(propsOrChildren)) {
|
|
|
|
element.append(...propsOrChildren);
|
|
|
|
} else {
|
2023-06-15 16:36:52 +00:00
|
|
|
const {parent, $: cb, dataset, style} = propsOrChildren;
|
2023-03-03 15:20:49 +00:00
|
|
|
delete propsOrChildren.parent;
|
|
|
|
delete propsOrChildren.$;
|
2023-04-08 13:38:45 +00:00
|
|
|
delete propsOrChildren.dataset;
|
|
|
|
delete propsOrChildren.style;
|
2023-03-03 15:20:49 +00:00
|
|
|
|
2023-06-15 16:36:52 +00:00
|
|
|
if (Object.hasOwn(propsOrChildren, "for")) {
|
|
|
|
element.setAttribute("for", propsOrChildren.for)
|
|
|
|
}
|
|
|
|
|
2023-04-08 13:38:45 +00:00
|
|
|
if (style) {
|
|
|
|
Object.assign(element.style, style);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataset) {
|
|
|
|
Object.assign(element.dataset, dataset);
|
2023-03-08 20:03:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 15:20:49 +00:00
|
|
|
Object.assign(element, propsOrChildren);
|
|
|
|
if (children) {
|
2024-06-25 10:49:25 +00:00
|
|
|
element.append(...(children instanceof Array ? children.filter(Boolean) : [children]));
|
2023-03-03 15:20:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
parent.append(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cb) {
|
|
|
|
cb(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2023-03-26 14:01:34 +00:00
|
|
|
function dragElement(dragEl, settings) {
|
2023-03-26 02:06:00 +00:00
|
|
|
var posDiffX = 0,
|
|
|
|
posDiffY = 0,
|
|
|
|
posStartX = 0,
|
|
|
|
posStartY = 0,
|
|
|
|
newPosX = 0,
|
|
|
|
newPosY = 0;
|
2023-03-26 14:01:34 +00:00
|
|
|
if (dragEl.getElementsByClassName("drag-handle")[0]) {
|
2023-03-25 23:23:46 +00:00
|
|
|
// if present, the handle is where you move the DIV from:
|
2023-03-26 14:01:34 +00:00
|
|
|
dragEl.getElementsByClassName("drag-handle")[0].onmousedown = dragMouseDown;
|
2023-03-25 23:23:46 +00:00
|
|
|
} else {
|
|
|
|
// otherwise, move the DIV from anywhere inside the DIV:
|
|
|
|
dragEl.onmousedown = dragMouseDown;
|
|
|
|
}
|
|
|
|
|
2023-03-30 19:14:01 +00:00
|
|
|
// When the element resizes (e.g. view queue) ensure it is still in the windows bounds
|
|
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
|
|
ensureInBounds();
|
|
|
|
}).observe(dragEl);
|
|
|
|
|
2023-03-26 14:01:34 +00:00
|
|
|
function ensureInBounds() {
|
2024-04-17 20:36:49 +00:00
|
|
|
try {
|
2023-03-30 19:15:12 +00:00
|
|
|
newPosX = Math.min(document.body.clientWidth - dragEl.clientWidth, Math.max(0, dragEl.offsetLeft));
|
|
|
|
newPosY = Math.min(document.body.clientHeight - dragEl.clientHeight, Math.max(0, dragEl.offsetTop));
|
2023-03-26 14:01:34 +00:00
|
|
|
|
2023-03-30 19:15:12 +00:00
|
|
|
positionElement();
|
|
|
|
}
|
2024-04-17 20:36:49 +00:00
|
|
|
catch(exception){
|
|
|
|
// robust
|
|
|
|
}
|
2023-03-30 19:14:01 +00:00
|
|
|
}
|
2023-03-26 14:01:34 +00:00
|
|
|
|
|
|
|
function positionElement() {
|
2024-06-25 10:49:25 +00:00
|
|
|
if(dragEl.style.display === "none") return;
|
|
|
|
|
2023-03-26 14:01:34 +00:00
|
|
|
const halfWidth = document.body.clientWidth / 2;
|
|
|
|
const anchorRight = newPosX + dragEl.clientWidth / 2 > halfWidth;
|
|
|
|
|
|
|
|
// set the element's new position:
|
|
|
|
if (anchorRight) {
|
|
|
|
dragEl.style.left = "unset";
|
|
|
|
dragEl.style.right = document.body.clientWidth - newPosX - dragEl.clientWidth + "px";
|
|
|
|
} else {
|
|
|
|
dragEl.style.left = newPosX + "px";
|
|
|
|
dragEl.style.right = "unset";
|
|
|
|
}
|
2023-04-08 13:38:45 +00:00
|
|
|
|
2023-03-30 19:15:48 +00:00
|
|
|
dragEl.style.top = newPosY + "px";
|
|
|
|
dragEl.style.bottom = "unset";
|
2023-03-26 14:01:34 +00:00
|
|
|
|
|
|
|
if (savePos) {
|
|
|
|
localStorage.setItem(
|
|
|
|
"Comfy.MenuPosition",
|
|
|
|
JSON.stringify({
|
2023-03-30 19:14:01 +00:00
|
|
|
x: dragEl.offsetLeft,
|
|
|
|
y: dragEl.offsetTop,
|
2023-03-26 14:01:34 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function restorePos() {
|
|
|
|
let pos = localStorage.getItem("Comfy.MenuPosition");
|
|
|
|
if (pos) {
|
|
|
|
pos = JSON.parse(pos);
|
2023-03-30 19:14:01 +00:00
|
|
|
newPosX = pos.x;
|
|
|
|
newPosY = pos.y;
|
|
|
|
positionElement();
|
2023-03-26 14:01:34 +00:00
|
|
|
ensureInBounds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let savePos = undefined;
|
|
|
|
settings.addSetting({
|
|
|
|
id: "Comfy.MenuPosition",
|
|
|
|
name: "Save menu position",
|
|
|
|
type: "boolean",
|
|
|
|
defaultValue: savePos,
|
|
|
|
onChange(value) {
|
|
|
|
if (savePos === undefined && value) {
|
|
|
|
restorePos();
|
|
|
|
}
|
|
|
|
savePos = value;
|
|
|
|
},
|
|
|
|
});
|
2023-06-15 16:36:52 +00:00
|
|
|
|
2023-03-25 23:23:46 +00:00
|
|
|
function dragMouseDown(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
e.preventDefault();
|
|
|
|
// get the mouse cursor position at startup:
|
2023-03-26 02:06:00 +00:00
|
|
|
posStartX = e.clientX;
|
|
|
|
posStartY = e.clientY;
|
2023-03-25 23:23:46 +00:00
|
|
|
document.onmouseup = closeDragElement;
|
|
|
|
// call a function whenever the cursor moves:
|
|
|
|
document.onmousemove = elementDrag;
|
|
|
|
}
|
|
|
|
|
|
|
|
function elementDrag(e) {
|
|
|
|
e = e || window.event;
|
|
|
|
e.preventDefault();
|
2023-03-26 14:01:34 +00:00
|
|
|
|
|
|
|
dragEl.classList.add("comfy-menu-manual-pos");
|
|
|
|
|
2023-03-25 23:23:46 +00:00
|
|
|
// calculate the new cursor position:
|
2023-03-26 02:06:00 +00:00
|
|
|
posDiffX = e.clientX - posStartX;
|
|
|
|
posDiffY = e.clientY - posStartY;
|
|
|
|
posStartX = e.clientX;
|
|
|
|
posStartY = e.clientY;
|
2023-03-26 14:01:34 +00:00
|
|
|
|
|
|
|
newPosX = Math.min(document.body.clientWidth - dragEl.clientWidth, Math.max(0, dragEl.offsetLeft + posDiffX));
|
|
|
|
newPosY = Math.min(document.body.clientHeight - dragEl.clientHeight, Math.max(0, dragEl.offsetTop + posDiffY));
|
|
|
|
|
|
|
|
positionElement();
|
2023-03-25 23:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-03-26 14:01:34 +00:00
|
|
|
window.addEventListener("resize", () => {
|
2023-04-08 13:38:45 +00:00
|
|
|
ensureInBounds();
|
2023-03-26 14:01:34 +00:00
|
|
|
});
|
|
|
|
|
2023-03-25 23:23:46 +00:00
|
|
|
function closeDragElement() {
|
|
|
|
// stop moving when mouse button is released:
|
|
|
|
document.onmouseup = null;
|
|
|
|
document.onmousemove = null;
|
|
|
|
}
|
2024-06-25 10:49:25 +00:00
|
|
|
|
|
|
|
return restorePos;
|
2023-03-25 23:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 21:34:29 +00:00
|
|
|
class ComfyList {
|
2023-03-03 15:20:49 +00:00
|
|
|
#type;
|
|
|
|
#text;
|
2023-09-02 19:36:45 +00:00
|
|
|
#reverse;
|
2023-03-03 15:20:49 +00:00
|
|
|
|
2023-09-02 19:36:45 +00:00
|
|
|
constructor(text, type, reverse) {
|
2023-03-03 15:20:49 +00:00
|
|
|
this.#text = text;
|
|
|
|
this.#type = type || text.toLowerCase();
|
2023-09-02 19:36:45 +00:00
|
|
|
this.#reverse = reverse || false;
|
2023-03-03 15:20:49 +00:00
|
|
|
this.element = $el("div.comfy-list");
|
2023-03-02 21:34:29 +00:00
|
|
|
this.element.style.display = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
get visible() {
|
|
|
|
return this.element.style.display !== "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
async load() {
|
2023-03-03 15:20:49 +00:00
|
|
|
const items = await api.getItems(this.#type);
|
|
|
|
this.element.replaceChildren(
|
|
|
|
...Object.keys(items).flatMap((section) => [
|
|
|
|
$el("h4", {
|
|
|
|
textContent: section,
|
|
|
|
}),
|
|
|
|
$el("div.comfy-list-items", [
|
2023-09-02 19:36:45 +00:00
|
|
|
...(this.#reverse ? items[section].reverse() : items[section]).map((item) => {
|
2023-03-03 15:20:49 +00:00
|
|
|
// Allow items to specify a custom remove action (e.g. for interrupt current prompt)
|
|
|
|
const removeAction = item.remove || {
|
|
|
|
name: "Delete",
|
|
|
|
cb: () => api.deleteItem(this.#type, item.prompt[1]),
|
|
|
|
};
|
2023-06-15 16:36:52 +00:00
|
|
|
return $el("div", {textContent: item.prompt[0] + ": "}, [
|
2023-03-03 15:20:49 +00:00
|
|
|
$el("button", {
|
|
|
|
textContent: "Load",
|
2023-11-30 19:13:27 +00:00
|
|
|
onclick: async () => {
|
2024-06-03 23:48:27 +00:00
|
|
|
await app.loadGraphData(item.prompt[3].extra_pnginfo.workflow, true, false);
|
2023-03-03 15:20:49 +00:00
|
|
|
if (item.outputs) {
|
Execution Model Inversion (#2666)
* Execution Model Inversion
This PR inverts the execution model -- from recursively calling nodes to
using a topological sort of the nodes. This change allows for
modification of the node graph during execution. This allows for two
major advantages:
1. The implementation of lazy evaluation in nodes. For example, if a
"Mix Images" node has a mix factor of exactly 0.0, the second image
input doesn't even need to be evaluated (and visa-versa if the mix
factor is 1.0).
2. Dynamic expansion of nodes. This allows for the creation of dynamic
"node groups". Specifically, custom nodes can return subgraphs that
replace the original node in the graph. This is an incredibly
powerful concept. Using this functionality, it was easy to
implement:
a. Components (a.k.a. node groups)
b. Flow control (i.e. while loops) via tail recursion
c. All-in-one nodes that replicate the WebUI functionality
d. and more
All of those were able to be implemented entirely via custom nodes,
so those features are *not* a part of this PR. (There are some
front-end changes that should occur before that functionality is
made widely available, particularly around variant sockets.)
The custom nodes associated with this PR can be found at:
https://github.com/BadCafeCode/execution-inversion-demo-comfyui
Note that some of them require that variant socket types ("*") be
enabled.
* Allow `input_info` to be of type `None`
* Handle errors (like OOM) more gracefully
* Add a command-line argument to enable variants
This allows the use of nodes that have sockets of type '*' without
applying a patch to the code.
* Fix an overly aggressive assertion.
This could happen when attempting to evaluate `IS_CHANGED` for a node
during the creation of the cache (in order to create the cache key).
* Fix Pyright warnings
* Add execution model unit tests
* Fix issue with unused literals
Behavior should now match the master branch with regard to undeclared
inputs. Undeclared inputs that are socket connections will be used while
undeclared inputs that are literals will be ignored.
* Make custom VALIDATE_INPUTS skip normal validation
Additionally, if `VALIDATE_INPUTS` takes an argument named `input_types`,
that variable will be a dictionary of the socket type of all incoming
connections. If that argument exists, normal socket type validation will
not occur. This removes the last hurdle for enabling variant types
entirely from custom nodes, so I've removed that command-line option.
I've added appropriate unit tests for these changes.
* Fix example in unit test
This wouldn't have caused any issues in the unit test, but it would have
bugged the UI if someone copy+pasted it into their own node pack.
* Use fstrings instead of '%' formatting syntax
* Use custom exception types.
* Display an error for dependency cycles
Previously, dependency cycles that were created during node expansion
would cause the application to quit (due to an uncaught exception). Now,
we'll throw a proper error to the UI. We also make an attempt to 'blame'
the most relevant node in the UI.
* Add docs on when ExecutionBlocker should be used
* Remove unused functionality
* Rename ExecutionResult.SLEEPING to PENDING
* Remove superfluous function parameter
* Pass None for uneval inputs instead of default
This applies to `VALIDATE_INPUTS`, `check_lazy_status`, and lazy values
in evaluation functions.
* Add a test for mixed node expansion
This test ensures that a node that returns a combination of expanded
subgraphs and literal values functions correctly.
* Raise exception for bad get_node calls.
* Minor refactor of IsChangedCache.get
* Refactor `map_node_over_list` function
* Fix ui output for duplicated nodes
* Add documentation on `check_lazy_status`
* Add file for execution model unit tests
* Clean up Javascript code as per review
* Improve documentation
Converted some comments to docstrings as per review
* Add a new unit test for mixed lazy results
This test validates that when an output list is fed to a lazy node, the
node will properly evaluate previous nodes that are needed by any inputs
to the lazy node.
No code in the execution model has been changed. The test already
passes.
* Allow kwargs in VALIDATE_INPUTS functions
When kwargs are used, validation is skipped for all inputs as if they
had been mentioned explicitly.
* List cached nodes in `execution_cached` message
This was previously just bugged in this PR.
2024-08-15 15:21:11 +00:00
|
|
|
app.nodeOutputs = {};
|
|
|
|
for (const [key, value] of Object.entries(item.outputs)) {
|
|
|
|
const realKey = item?.meta?.[key]?.display_node ?? key;
|
|
|
|
app.nodeOutputs[realKey] = value;
|
|
|
|
}
|
2023-03-03 15:20:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
$el("button", {
|
|
|
|
textContent: removeAction.name,
|
|
|
|
onclick: async () => {
|
|
|
|
await removeAction.cb();
|
|
|
|
await this.update();
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
$el("div.comfy-list-actions", [
|
|
|
|
$el("button", {
|
|
|
|
textContent: "Clear " + this.#text,
|
|
|
|
onclick: async () => {
|
|
|
|
await api.clearItems(this.#type);
|
|
|
|
await this.load();
|
|
|
|
},
|
|
|
|
}),
|
2023-06-15 16:36:52 +00:00
|
|
|
$el("button", {textContent: "Refresh", onclick: () => this.load()}),
|
2023-03-03 15:20:49 +00:00
|
|
|
])
|
|
|
|
);
|
2023-03-02 21:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async update() {
|
|
|
|
if (this.visible) {
|
|
|
|
await this.load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async show() {
|
|
|
|
this.element.style.display = "block";
|
2023-03-03 15:20:49 +00:00
|
|
|
this.button.textContent = "Close";
|
|
|
|
|
2023-03-02 21:34:29 +00:00
|
|
|
await this.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
this.element.style.display = "none";
|
2023-08-04 07:22:47 +00:00
|
|
|
this.button.textContent = "View " + this.#text;
|
2023-03-02 21:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toggle() {
|
|
|
|
if (this.visible) {
|
|
|
|
this.hide();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
this.show();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ComfyUI {
|
|
|
|
constructor(app) {
|
|
|
|
this.app = app;
|
|
|
|
this.dialog = new ComfyDialog();
|
2024-01-08 22:06:44 +00:00
|
|
|
this.settings = new ComfySettingsDialog(app);
|
2023-03-02 21:34:29 +00:00
|
|
|
|
2023-03-10 09:38:35 +00:00
|
|
|
this.batchCount = 1;
|
2023-03-19 04:03:18 +00:00
|
|
|
this.lastQueueSize = 0;
|
2023-03-03 15:20:49 +00:00
|
|
|
this.queue = new ComfyList("Queue");
|
2023-09-02 19:36:45 +00:00
|
|
|
this.history = new ComfyList("History", "history", true);
|
2023-03-02 21:34:29 +00:00
|
|
|
|
2023-03-03 15:20:49 +00:00
|
|
|
api.addEventListener("status", () => {
|
|
|
|
this.queue.update();
|
|
|
|
this.history.update();
|
|
|
|
});
|
2023-03-02 21:34:29 +00:00
|
|
|
|
2023-04-05 21:56:41 +00:00
|
|
|
const confirmClear = this.settings.addSetting({
|
|
|
|
id: "Comfy.ConfirmClear",
|
|
|
|
name: "Require confirmation when clearing workflow",
|
|
|
|
type: "boolean",
|
|
|
|
defaultValue: true,
|
|
|
|
});
|
2023-04-08 13:38:45 +00:00
|
|
|
|
2023-04-16 05:25:11 +00:00
|
|
|
const promptFilename = this.settings.addSetting({
|
|
|
|
id: "Comfy.PromptFilename",
|
|
|
|
name: "Prompt for filename when saving workflow",
|
|
|
|
type: "boolean",
|
|
|
|
defaultValue: true,
|
|
|
|
});
|
|
|
|
|
improve: lightweight preview to reduce network traffic (#733)
* To reduce bandwidth traffic in a remote environment, a lossy compression-based preview mode is provided for displaying simple visualizations in node-based widgets.
* Added 'preview=[image format]' option to the '/view' API.
* Updated node to use preview for displaying images as widgets.
* Excluded preview usage in the open image, save image, mask editor where the original data is required.
* Made preview_format parameterizable for extensibility.
* default preview format changed: jpeg -> webp
* Support advanced preview_format option.
- grayscale option for visual debugging
- quality option for aggressive reducing
L?;format;quality?
ex)
jpeg => rgb, jpeg, quality 90
L;webp;80 => grayscale, webp, quality 80
L;png => grayscale, png, quality 90
webp;50 => rgb, webp, quality 50
* move comment
* * add settings for preview_format
* default value is ''(= don't reencode)
---------
Co-authored-by: Lt.Dr.Data <lt.dr.data@gmail.com>
2023-06-05 05:49:43 +00:00
|
|
|
/**
|
|
|
|
* file format for preview
|
|
|
|
*
|
2023-06-05 05:38:32 +00:00
|
|
|
* format;quality
|
improve: lightweight preview to reduce network traffic (#733)
* To reduce bandwidth traffic in a remote environment, a lossy compression-based preview mode is provided for displaying simple visualizations in node-based widgets.
* Added 'preview=[image format]' option to the '/view' API.
* Updated node to use preview for displaying images as widgets.
* Excluded preview usage in the open image, save image, mask editor where the original data is required.
* Made preview_format parameterizable for extensibility.
* default preview format changed: jpeg -> webp
* Support advanced preview_format option.
- grayscale option for visual debugging
- quality option for aggressive reducing
L?;format;quality?
ex)
jpeg => rgb, jpeg, quality 90
L;webp;80 => grayscale, webp, quality 80
L;png => grayscale, png, quality 90
webp;50 => rgb, webp, quality 50
* move comment
* * add settings for preview_format
* default value is ''(= don't reencode)
---------
Co-authored-by: Lt.Dr.Data <lt.dr.data@gmail.com>
2023-06-05 05:49:43 +00:00
|
|
|
*
|
|
|
|
* ex)
|
2023-06-05 05:38:32 +00:00
|
|
|
* webp;50 -> webp, quality 50
|
improve: lightweight preview to reduce network traffic (#733)
* To reduce bandwidth traffic in a remote environment, a lossy compression-based preview mode is provided for displaying simple visualizations in node-based widgets.
* Added 'preview=[image format]' option to the '/view' API.
* Updated node to use preview for displaying images as widgets.
* Excluded preview usage in the open image, save image, mask editor where the original data is required.
* Made preview_format parameterizable for extensibility.
* default preview format changed: jpeg -> webp
* Support advanced preview_format option.
- grayscale option for visual debugging
- quality option for aggressive reducing
L?;format;quality?
ex)
jpeg => rgb, jpeg, quality 90
L;webp;80 => grayscale, webp, quality 80
L;png => grayscale, png, quality 90
webp;50 => rgb, webp, quality 50
* move comment
* * add settings for preview_format
* default value is ''(= don't reencode)
---------
Co-authored-by: Lt.Dr.Data <lt.dr.data@gmail.com>
2023-06-05 05:49:43 +00:00
|
|
|
* jpeg;80 -> rgb, jpeg, quality 80
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
const previewImage = this.settings.addSetting({
|
|
|
|
id: "Comfy.PreviewFormat",
|
2023-06-15 16:36:52 +00:00
|
|
|
name: "When displaying a preview in the image widget, convert it to a lightweight image, e.g. webp, jpeg, webp;50, etc.",
|
|
|
|
type: "text",
|
improve: lightweight preview to reduce network traffic (#733)
* To reduce bandwidth traffic in a remote environment, a lossy compression-based preview mode is provided for displaying simple visualizations in node-based widgets.
* Added 'preview=[image format]' option to the '/view' API.
* Updated node to use preview for displaying images as widgets.
* Excluded preview usage in the open image, save image, mask editor where the original data is required.
* Made preview_format parameterizable for extensibility.
* default preview format changed: jpeg -> webp
* Support advanced preview_format option.
- grayscale option for visual debugging
- quality option for aggressive reducing
L?;format;quality?
ex)
jpeg => rgb, jpeg, quality 90
L;webp;80 => grayscale, webp, quality 80
L;png => grayscale, png, quality 90
webp;50 => rgb, webp, quality 50
* move comment
* * add settings for preview_format
* default value is ''(= don't reencode)
---------
Co-authored-by: Lt.Dr.Data <lt.dr.data@gmail.com>
2023-06-05 05:49:43 +00:00
|
|
|
defaultValue: "",
|
|
|
|
});
|
|
|
|
|
2023-08-01 22:50:06 +00:00
|
|
|
this.settings.addSetting({
|
|
|
|
id: "Comfy.DisableSliders",
|
|
|
|
name: "Disable sliders.",
|
|
|
|
type: "boolean",
|
|
|
|
defaultValue: false,
|
|
|
|
});
|
|
|
|
|
2023-09-19 03:20:00 +00:00
|
|
|
this.settings.addSetting({
|
|
|
|
id: "Comfy.DisableFloatRounding",
|
|
|
|
name: "Disable rounding floats (requires page reload).",
|
|
|
|
type: "boolean",
|
|
|
|
defaultValue: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.settings.addSetting({
|
|
|
|
id: "Comfy.FloatRoundingPrecision",
|
|
|
|
name: "Decimal places [0 = auto] (requires page reload).",
|
|
|
|
type: "slider",
|
|
|
|
attrs: {
|
|
|
|
min: 0,
|
|
|
|
max: 6,
|
|
|
|
step: 1,
|
|
|
|
},
|
|
|
|
defaultValue: 0,
|
|
|
|
});
|
|
|
|
|
2023-03-03 15:27:08 +00:00
|
|
|
const fileInput = $el("input", {
|
2023-04-16 05:25:11 +00:00
|
|
|
id: "comfy-file-input",
|
2023-03-03 15:27:08 +00:00
|
|
|
type: "file",
|
2024-06-27 05:28:59 +00:00
|
|
|
accept: ".json,image/png,.latent,.safetensors,image/webp,audio/flac",
|
2023-06-15 16:36:52 +00:00
|
|
|
style: {display: "none"},
|
2023-03-03 15:27:08 +00:00
|
|
|
parent: document.body,
|
|
|
|
onchange: () => {
|
|
|
|
app.handleFile(fileInput.files[0]);
|
|
|
|
},
|
2023-03-03 15:20:49 +00:00
|
|
|
});
|
2023-03-02 21:34:29 +00:00
|
|
|
|
2024-06-25 10:49:25 +00:00
|
|
|
this.loadFile = () => fileInput.click();
|
|
|
|
|
2024-01-16 13:27:40 +00:00
|
|
|
const autoQueueModeEl = toggleSwitch(
|
|
|
|
"autoQueueMode",
|
|
|
|
[
|
|
|
|
{ text: "instant", tooltip: "A new prompt will be queued as soon as the queue reaches 0" },
|
|
|
|
{ text: "change", tooltip: "A new prompt will be queued when the queue is at 0 and the graph is/has changed" },
|
|
|
|
],
|
|
|
|
{
|
|
|
|
onChange: (value) => {
|
|
|
|
this.autoQueueMode = value.item.value;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
autoQueueModeEl.style.display = "none";
|
|
|
|
|
|
|
|
api.addEventListener("graphChanged", () => {
|
2024-01-22 02:34:39 +00:00
|
|
|
if (this.autoQueueMode === "change" && this.autoQueueEnabled === true) {
|
2024-01-16 13:27:40 +00:00
|
|
|
if (this.lastQueueSize === 0) {
|
|
|
|
this.graphHasChanged = false;
|
|
|
|
app.queuePrompt(0, this.batchCount);
|
|
|
|
} else {
|
|
|
|
this.graphHasChanged = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-22 18:56:43 +00:00
|
|
|
this.menuHamburger = $el(
|
|
|
|
"div.comfy-menu-hamburger",
|
|
|
|
{
|
|
|
|
parent: document.body,
|
|
|
|
onclick: () => {
|
|
|
|
this.menuContainer.style.display = "block";
|
|
|
|
this.menuHamburger.style.display = "none";
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[$el("div"), $el("div"), $el("div")]
|
|
|
|
);
|
|
|
|
|
|
|
|
this.menuContainer = $el("div.comfy-menu", { parent: document.body }, [
|
|
|
|
$el("div.drag-handle.comfy-menu-header", {
|
2023-06-15 16:36:52 +00:00
|
|
|
style: {
|
|
|
|
overflow: "hidden",
|
|
|
|
position: "relative",
|
|
|
|
width: "100%",
|
|
|
|
cursor: "default"
|
|
|
|
}
|
2024-01-22 18:56:43 +00:00
|
|
|
}, [
|
2023-03-25 23:23:46 +00:00
|
|
|
$el("span.drag-handle"),
|
2024-01-22 18:56:43 +00:00
|
|
|
$el("span.comfy-menu-queue-size", { $: (q) => (this.queueSize = q) }),
|
|
|
|
$el("div.comfy-menu-actions", [
|
|
|
|
$el("button.comfy-settings-btn", {
|
|
|
|
textContent: "⚙️",
|
|
|
|
onclick: () => this.settings.show(),
|
|
|
|
}),
|
|
|
|
$el("button.comfy-close-menu-btn", {
|
|
|
|
textContent: "\u00d7",
|
|
|
|
onclick: () => {
|
|
|
|
this.menuContainer.style.display = "none";
|
|
|
|
this.menuHamburger.style.display = "flex";
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
2023-03-08 20:03:37 +00:00
|
|
|
]),
|
2023-03-26 14:01:34 +00:00
|
|
|
$el("button.comfy-queue-btn", {
|
2023-04-16 05:25:11 +00:00
|
|
|
id: "queue-button",
|
2023-03-26 14:01:34 +00:00
|
|
|
textContent: "Queue Prompt",
|
|
|
|
onclick: () => app.queuePrompt(0, this.batchCount),
|
|
|
|
}),
|
2023-03-14 07:16:48 +00:00
|
|
|
$el("div", {}, [
|
2023-06-15 16:36:52 +00:00
|
|
|
$el("label", {innerHTML: "Extra options"}, [
|
2023-03-26 14:01:34 +00:00
|
|
|
$el("input", {
|
|
|
|
type: "checkbox",
|
|
|
|
onchange: (i) => {
|
|
|
|
document.getElementById("extraOptions").style.display = i.srcElement.checked ? "block" : "none";
|
|
|
|
this.batchCount = i.srcElement.checked ? document.getElementById("batchCountInputRange").value : 1;
|
|
|
|
document.getElementById("autoQueueCheckbox").checked = false;
|
2024-01-16 13:27:40 +00:00
|
|
|
this.autoQueueEnabled = false;
|
2023-03-26 14:01:34 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
2023-03-14 07:16:48 +00:00
|
|
|
]),
|
2023-06-15 16:36:52 +00:00
|
|
|
$el("div", {id: "extraOptions", style: {width: "100%", display: "none"}}, [
|
2023-09-02 06:58:23 +00:00
|
|
|
$el("div",[
|
|
|
|
|
|
|
|
$el("label", {innerHTML: "Batch count"}),
|
2023-03-26 14:01:34 +00:00
|
|
|
$el("input", {
|
|
|
|
id: "batchCountInputNumber",
|
|
|
|
type: "number",
|
|
|
|
value: this.batchCount,
|
|
|
|
min: "1",
|
2023-06-15 16:36:52 +00:00
|
|
|
style: {width: "35%", "margin-left": "0.4em"},
|
2023-03-26 14:01:34 +00:00
|
|
|
oninput: (i) => {
|
2023-03-10 09:38:35 +00:00
|
|
|
this.batchCount = i.target.value;
|
2023-03-26 14:01:34 +00:00
|
|
|
document.getElementById("batchCountInputRange").value = this.batchCount;
|
|
|
|
},
|
2023-03-10 09:38:35 +00:00
|
|
|
}),
|
2023-03-26 14:01:34 +00:00
|
|
|
$el("input", {
|
|
|
|
id: "batchCountInputRange",
|
|
|
|
type: "range",
|
|
|
|
min: "1",
|
|
|
|
max: "100",
|
|
|
|
value: this.batchCount,
|
2023-03-10 09:38:35 +00:00
|
|
|
oninput: (i) => {
|
|
|
|
this.batchCount = i.srcElement.value;
|
2023-03-26 14:01:34 +00:00
|
|
|
document.getElementById("batchCountInputNumber").value = i.srcElement.value;
|
|
|
|
},
|
2023-09-02 06:58:23 +00:00
|
|
|
}),
|
|
|
|
]),
|
|
|
|
$el("div",[
|
|
|
|
$el("label",{
|
|
|
|
for:"autoQueueCheckbox",
|
|
|
|
innerHTML: "Auto Queue"
|
2023-03-26 14:01:34 +00:00
|
|
|
}),
|
|
|
|
$el("input", {
|
|
|
|
id: "autoQueueCheckbox",
|
|
|
|
type: "checkbox",
|
|
|
|
checked: false,
|
2023-09-02 06:58:23 +00:00
|
|
|
title: "Automatically queue prompt when the queue size hits 0",
|
2024-01-16 13:27:40 +00:00
|
|
|
onchange: (e) => {
|
|
|
|
this.autoQueueEnabled = e.target.checked;
|
|
|
|
autoQueueModeEl.style.display = this.autoQueueEnabled ? "" : "none";
|
|
|
|
}
|
2023-03-10 09:38:35 +00:00
|
|
|
}),
|
2024-01-16 13:27:40 +00:00
|
|
|
autoQueueModeEl
|
2023-09-02 06:58:23 +00:00
|
|
|
])
|
2023-03-09 17:02:03 +00:00
|
|
|
]),
|
2023-03-03 15:20:49 +00:00
|
|
|
$el("div.comfy-menu-btns", [
|
2023-06-15 16:36:52 +00:00
|
|
|
$el("button", {
|
|
|
|
id: "queue-front-button",
|
|
|
|
textContent: "Queue Front",
|
|
|
|
onclick: () => app.queuePrompt(-1, this.batchCount)
|
|
|
|
}),
|
2023-03-03 15:20:49 +00:00
|
|
|
$el("button", {
|
|
|
|
$: (b) => (this.queue.button = b),
|
2023-04-16 05:25:11 +00:00
|
|
|
id: "comfy-view-queue-button",
|
2023-03-03 15:20:49 +00:00
|
|
|
textContent: "View Queue",
|
|
|
|
onclick: () => {
|
|
|
|
this.history.hide();
|
|
|
|
this.queue.toggle();
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
$el("button", {
|
|
|
|
$: (b) => (this.history.button = b),
|
2023-04-16 05:25:11 +00:00
|
|
|
id: "comfy-view-history-button",
|
2023-03-03 15:20:49 +00:00
|
|
|
textContent: "View History",
|
|
|
|
onclick: () => {
|
|
|
|
this.queue.hide();
|
|
|
|
this.history.toggle();
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
this.queue.element,
|
|
|
|
this.history.element,
|
|
|
|
$el("button", {
|
2023-04-16 05:25:11 +00:00
|
|
|
id: "comfy-save-button",
|
2023-03-03 15:20:49 +00:00
|
|
|
textContent: "Save",
|
|
|
|
onclick: () => {
|
2023-04-16 05:25:11 +00:00
|
|
|
let filename = "workflow.json";
|
|
|
|
if (promptFilename.value) {
|
|
|
|
filename = prompt("Save workflow as:", filename);
|
|
|
|
if (!filename) return;
|
|
|
|
if (!filename.toLowerCase().endsWith(".json")) {
|
|
|
|
filename += ".json";
|
|
|
|
}
|
|
|
|
}
|
2023-10-26 23:52:41 +00:00
|
|
|
app.graphToPrompt().then(p=>{
|
|
|
|
const json = JSON.stringify(p.workflow, null, 2); // convert the data to a JSON string
|
|
|
|
const blob = new Blob([json], {type: "application/json"});
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const a = $el("a", {
|
|
|
|
href: url,
|
|
|
|
download: filename,
|
|
|
|
style: {display: "none"},
|
|
|
|
parent: document.body,
|
|
|
|
});
|
|
|
|
a.click();
|
|
|
|
setTimeout(function () {
|
|
|
|
a.remove();
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
}, 0);
|
2023-03-03 15:20:49 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
}),
|
2023-07-14 01:08:54 +00:00
|
|
|
$el("button", {
|
|
|
|
id: "comfy-dev-save-api-button",
|
|
|
|
textContent: "Save (API Format)",
|
|
|
|
style: {width: "100%", display: "none"},
|
|
|
|
onclick: () => {
|
|
|
|
let filename = "workflow_api.json";
|
|
|
|
if (promptFilename.value) {
|
|
|
|
filename = prompt("Save workflow (API) as:", filename);
|
|
|
|
if (!filename) return;
|
|
|
|
if (!filename.toLowerCase().endsWith(".json")) {
|
|
|
|
filename += ".json";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
app.graphToPrompt().then(p=>{
|
|
|
|
const json = JSON.stringify(p.output, null, 2); // convert the data to a JSON string
|
|
|
|
const blob = new Blob([json], {type: "application/json"});
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
const a = $el("a", {
|
|
|
|
href: url,
|
|
|
|
download: filename,
|
|
|
|
style: {display: "none"},
|
|
|
|
parent: document.body,
|
|
|
|
});
|
|
|
|
a.click();
|
|
|
|
setTimeout(function () {
|
|
|
|
a.remove();
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}),
|
2023-06-15 16:36:52 +00:00
|
|
|
$el("button", {id: "comfy-load-button", textContent: "Load", onclick: () => fileInput.click()}),
|
|
|
|
$el("button", {
|
|
|
|
id: "comfy-refresh-button",
|
|
|
|
textContent: "Refresh",
|
|
|
|
onclick: () => app.refreshComboInNodes()
|
|
|
|
}),
|
|
|
|
$el("button", {id: "comfy-clipspace-button", textContent: "Clipspace", onclick: () => app.openClipspace()}),
|
|
|
|
$el("button", {
|
|
|
|
id: "comfy-clear-button", textContent: "Clear", onclick: () => {
|
|
|
|
if (!confirmClear.value || confirm("Clear workflow?")) {
|
|
|
|
app.clean();
|
|
|
|
app.graph.clear();
|
2024-05-10 21:30:52 +00:00
|
|
|
app.resetView();
|
2023-06-15 16:36:52 +00:00
|
|
|
}
|
2023-04-05 03:20:49 +00:00
|
|
|
}
|
2023-06-15 16:36:52 +00:00
|
|
|
}),
|
|
|
|
$el("button", {
|
2023-11-30 19:13:27 +00:00
|
|
|
id: "comfy-load-default-button", textContent: "Load Default", onclick: async () => {
|
2023-06-15 16:36:52 +00:00
|
|
|
if (!confirmClear.value || confirm("Load default workflow?")) {
|
2024-05-10 21:30:52 +00:00
|
|
|
app.resetView();
|
2023-11-30 19:13:27 +00:00
|
|
|
await app.loadGraphData()
|
2023-06-15 16:36:52 +00:00
|
|
|
}
|
2023-04-05 03:20:49 +00:00
|
|
|
}
|
2023-06-15 16:36:52 +00:00
|
|
|
}),
|
2024-05-10 21:30:52 +00:00
|
|
|
$el("button", {
|
|
|
|
id: "comfy-reset-view-button", textContent: "Reset View", onclick: async () => {
|
|
|
|
app.resetView();
|
|
|
|
}
|
|
|
|
}),
|
2023-03-03 15:20:49 +00:00
|
|
|
]);
|
2023-03-02 21:34:29 +00:00
|
|
|
|
2023-07-14 01:08:54 +00:00
|
|
|
const devMode = this.settings.addSetting({
|
|
|
|
id: "Comfy.DevMode",
|
|
|
|
name: "Enable Dev mode Options",
|
|
|
|
type: "boolean",
|
|
|
|
defaultValue: false,
|
2024-06-25 10:49:25 +00:00
|
|
|
onChange: function(value) { document.getElementById("comfy-dev-save-api-button").style.display = value ? "flex" : "none"},
|
2023-07-14 01:08:54 +00:00
|
|
|
});
|
|
|
|
|
2024-06-25 10:49:25 +00:00
|
|
|
this.restoreMenuPosition = dragElement(this.menuContainer, this.settings);
|
2023-03-25 23:23:46 +00:00
|
|
|
|
2023-06-15 16:36:52 +00:00
|
|
|
this.setStatus({exec_info: {queue_remaining: "X"}});
|
2023-03-02 21:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setStatus(status) {
|
|
|
|
this.queueSize.textContent = "Queue size: " + (status ? status.exec_info.queue_remaining : "ERR");
|
2023-03-19 04:03:18 +00:00
|
|
|
if (status) {
|
2023-03-26 14:01:34 +00:00
|
|
|
if (
|
|
|
|
this.lastQueueSize != 0 &&
|
|
|
|
status.exec_info.queue_remaining == 0 &&
|
2024-01-16 13:27:40 +00:00
|
|
|
this.autoQueueEnabled &&
|
|
|
|
(this.autoQueueMode === "instant" || this.graphHasChanged) &&
|
|
|
|
!app.lastExecutionError
|
2023-03-26 14:01:34 +00:00
|
|
|
) {
|
2023-03-19 04:03:18 +00:00
|
|
|
app.queuePrompt(0, this.batchCount);
|
2024-01-16 13:27:40 +00:00
|
|
|
status.exec_info.queue_remaining += this.batchCount;
|
|
|
|
this.graphHasChanged = false;
|
2023-03-19 04:03:18 +00:00
|
|
|
}
|
2023-03-26 14:01:34 +00:00
|
|
|
this.lastQueueSize = status.exec_info.queue_remaining;
|
2023-03-19 04:03:18 +00:00
|
|
|
}
|
2023-03-02 21:34:29 +00:00
|
|
|
}
|
|
|
|
}
|