| import { app } from '../../../scripts/app.js' |
|
|
| function addResizeHook(node, padding, useOldMin=false) { |
| let origOnCreated = node.onNodeCreated |
| node.onNodeCreated = function() { |
| let r = origOnCreated?.apply(this, arguments) |
| let size = this.computeSize(); |
| size[0] += padding || 0; |
| if (useOldMin) { |
| |
| size[0] = Math.max(size[0], 315) |
| } |
| this.setSize(size); |
| return r |
| } |
| } |
|
|
| app.registerExtension({ |
| name: "AdvancedControlNet.autosize", |
| async beforeRegisterNodeDef(nodeType, nodeData, app) { |
| |
| |
| if (nodeData?.name?.startsWith("ACN_") |
| || nodeData.python_module == 'custom_nodes.ComfyUI-Advanced-ControlNet') { |
| if (nodeData?.input?.hidden?.autosize) { |
| addResizeHook(nodeType.prototype, nodeData.input.hidden.autosize[1]?.padding) |
| } else if (!nodeData?.input?.optional?.autosize) { |
| addResizeHook(nodeType.prototype, 0, true) |
| } |
| } |
| }, |
| async getCustomWidgets() { |
| return { |
| ACNAUTOSIZE(node, inputName, inputData) { |
| let w = { |
| name : inputName, |
| type : "ACN.AUTOSIZE", |
| value : "", |
| options : {"serialize": false}, |
| computeSize : function(width) { |
| return [0, -4]; |
| } |
| } |
| if (!node.widgets) { |
| node.widgets = [] |
| } |
| node.widgets.push(w) |
| addResizeHook(node, inputData[1].padding); |
| return w; |
| } |
| } |
| } |
| }); |
|
|