Files
Maxed-Out-99-ComfyUI-MaxedOut/web/mxd_runtime.js
T
Maxed-Out-99 a9fd90d608 Integrate Lora Loader MXD into MaxedOut
Add integrated Lora Loader MXD support and frontend. Introduces a new loraloader_mxd package (constants, logging, power node, prompt utils, server API routes, model info utils, server helpers, general utils, and userdata migration/IO). Adds many web frontend files for the MXD UI and registers the node in the top-level __init__.py. Updates README with merge/migration notes and adds userdata/ to .gitignore. Also includes minor comment/tuning change in maxedoutnodes.py and small updates to existing web/index.js and project metadata.
2026-02-21 18:21:54 -08:00

98 lines
3.0 KiB
JavaScript

import { app } from "../../scripts/app.js";
class LogSession {
constructor(name) {
this.name = name || "[mxd]";
}
logParts(level, message, ...args) {
const method = level === "error" ? "error" : level === "warn" ? "warn" : "log";
return [method, [`${this.name} ${message}`, ...args]];
}
errorParts(message, ...args) {
return this.logParts("error", message, ...args);
}
}
class MxdRuntime {
constructor() {
this.loadingApiJson = null;
this.lastCanvasMouseEvent = null;
this.canvasCurrentlyCopyingToClipboard = false;
this.canvasCurrentlyCopyingToClipboardWithMultipleNodes = false;
this.canvasCurrentlyPastingFromClipboard = false;
this.initializeHooks();
}
initializeHooks() {
const runtime = this;
const loadApiJson = app.loadApiJson;
app.loadApiJson = async function (apiData, fileName) {
runtime.loadingApiJson = apiData;
try {
return await loadApiJson.apply(app, [...arguments]);
} finally {
runtime.loadingApiJson = null;
}
};
const adjustMouseEvent = LGraphCanvas.prototype.adjustMouseEvent;
LGraphCanvas.prototype.adjustMouseEvent = function (e) {
adjustMouseEvent.apply(this, [...arguments]);
runtime.lastCanvasMouseEvent = e;
};
const copyToClipboard = LGraphCanvas.prototype.copyToClipboard;
LGraphCanvas.prototype.copyToClipboard = function (items) {
runtime.canvasCurrentlyCopyingToClipboard = true;
runtime.canvasCurrentlyCopyingToClipboardWithMultipleNodes =
Object.values(items || this.selected_nodes || {}).length > 1;
try {
return copyToClipboard.apply(this, [...arguments]);
} finally {
runtime.canvasCurrentlyCopyingToClipboard = false;
runtime.canvasCurrentlyCopyingToClipboardWithMultipleNodes = false;
}
};
const pasteFromClipboard = LGraphCanvas.prototype.pasteFromClipboard;
LGraphCanvas.prototype.pasteFromClipboard = function () {
runtime.canvasCurrentlyPastingFromClipboard = true;
try {
return pasteFromClipboard.apply(this, [...arguments]);
} finally {
runtime.canvasCurrentlyPastingFromClipboard = false;
}
};
}
newLogSession(name) {
return new LogSession(name);
}
showMessage({ id, type, message, timeout }) {
const msgId = id || `mxd-${Date.now()}`;
let container = document.querySelector(".mxd-top-messages-container");
if (!container) {
container = document.createElement("div");
container.className = "mxd-top-messages-container";
document.body.appendChild(container);
}
const node = document.createElement("div");
node.className = `mxd-top-message ${type || "info"}`;
node.setAttribute("msg-id", msgId);
node.textContent = message || "";
container.appendChild(node);
setTimeout(() => node.remove(), timeout || 3000);
}
isDevMode() {
return false;
}
}
export const mxdRuntime = new MxdRuntime();
window.mxdRuntime = mxdRuntime;