Files
MachinePainting 271b24849c v2.1.3 - Compat fixes: align OpenCV deps, Pillow Resampling, JS absolute imports, registry icon
- Aligned pyproject.toml and requirements.txt to opencv-python-headless (resolves install conflicts on headless servers)
- Replaced deprecated Image.LANCZOS with Image.Resampling.LANCZOS for Pillow 11+ compatibility
- Pinned numpy<3 to avoid breakage when NumPy 3 ships
- Standardized JS frontend imports to absolute /scripts/app.js paths
- Added emoji icon to [tool.comfy] registry metadata
2026-05-07 19:10:03 -07:00

57 lines
2.1 KiB
JavaScript

import { app } from "/scripts/app.js";
// Auto-scale view nodes based on node width
app.registerExtension({
name: "MachinePainting.ViewNodes",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
const viewNodes = ["HistogramView", "ColorWheelView"];
if (!viewNodes.includes(nodeData.name)) return;
const onNodeCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function() {
onNodeCreated?.apply(this, arguments);
// Set minimum size
this.size[0] = Math.max(this.size[0], 280);
this.size[1] = Math.max(this.size[1], 200);
// Find and update width widget
this.updateWidthWidget();
};
nodeType.prototype.updateWidthWidget = function() {
const widthWidget = this.widgets?.find(w => w.name === "width" || w.name === "size");
if (widthWidget) {
const nodeWidth = Math.max(256, Math.min(1024, this.size[0] - 20));
widthWidget.value = nodeWidth;
}
};
const onResize = nodeType.prototype.onResize;
nodeType.prototype.onResize = function(size) {
// Clamp size
size[0] = Math.max(280, Math.min(1050, size[0]));
size[1] = Math.max(200, size[1]);
onResize?.apply(this, arguments);
// Update width widget when node is resized
this.updateWidthWidget();
};
// Hide the width/size widget since it's auto-controlled
const onDrawForeground = nodeType.prototype.onDrawForeground;
nodeType.prototype.onDrawForeground = function(ctx) {
onDrawForeground?.apply(this, arguments);
// Hide width widget
const widthWidget = this.widgets?.find(w => w.name === "width" || w.name === "size");
if (widthWidget && widthWidget.computeSize) {
widthWidget.computeSize = () => [0, -4];
}
};
}
});