Simplifies the preset-chip picker (Smart Resize / Smart Batch Resize) to a single canvas implementation - drops the dual DOM-widget path, so chips stay positioned correctly under "Longest side (px)" in both classic and Nodes 2.0 rendering instead of jumping to the bottom of the node. Adds a shared setWidgetVisible() helper so dynamic show/hide (Counter start, the hidden customtext output on every node) actually works under Nodes 2.0's Vue reactivity - it previously only worked in classic canvas mode. Fixes two silent Nodes 2.0 rendering bugs: widgets only repaint via their own triggerDraw(), not setDirtyCanvas(), so the active preset chip and status-box text were going visually stale after an update even though the underlying value was correct. And Nodes 2.0's WidgetLegacy bridge permanently stamps a widget.width that classic mode's own click hit-test then reads forever after - once a node had ever rendered under Nodes 2.0, classic mode silently lost clicks on the right side of a wide node. Both fixed by keeping widget state in sync on every draw() instead of trusting it to survive across renderer switches. Also centers section-divider labels with flanking lines (was label-left/line-right) and brightens the line color, which had become nearly invisible under Nodes 2.0's extra canvas scaling. README: reorders node sections into actual pipeline order (Prompt Controller -> Profile Switch -> Resize -> Resolution Multiplier -> Batch Resize, standalone tool last instead of mid-list), adds a Nodes 2.0 compatibility screenshot, and refreshes the Smart Batch Resize screenshot to match its current UI.
44 lines
1.7 KiB
JavaScript
44 lines
1.7 KiB
JavaScript
import { app } from "../../scripts/app.js";
|
|
import { createPresetPickerWidget } from "./shared/preset_picker_widget.mjs?v=6";
|
|
|
|
app.registerExtension({
|
|
name: "Craftopia.SmartResize",
|
|
|
|
async nodeCreated(node) {
|
|
if (node.comfyClass !== "SmartResize") return;
|
|
|
|
const longestSideWidget = node.widgets?.find(w => w.name === "longest_side");
|
|
if (!longestSideWidget) return;
|
|
|
|
const PRESETS = [512, 768, 1024, 1536];
|
|
const presetWidget = createPresetPickerWidget(node, longestSideWidget, PRESETS);
|
|
|
|
// Override serialize to exclude the non-serializable preset widget from
|
|
// widgets_values — same drift fix as SmartBatchResize (see that file for details).
|
|
const origSerialize = node.serialize;
|
|
node.serialize = function () {
|
|
const data = origSerialize.call(this);
|
|
if (data.widgets_values) {
|
|
data.widgets_values = this.widgets
|
|
.filter(w => w.serialize !== false && w.options?.serialize !== false)
|
|
.map(w => w.value);
|
|
}
|
|
return data;
|
|
};
|
|
|
|
// Move preset row to right after longest_side
|
|
const lsIdx = node.widgets.indexOf(longestSideWidget);
|
|
const pwIdx = node.widgets.indexOf(presetWidget);
|
|
if (pwIdx !== lsIdx + 1) {
|
|
node.widgets.splice(pwIdx, 1);
|
|
node.widgets.splice(lsIdx + 1, 0, presetWidget);
|
|
}
|
|
|
|
// Force a full size/layout recompute now that the preset widget has
|
|
// been added and repositioned — see the comment in
|
|
// smart_batch_resize.js for why this is needed.
|
|
node.setSize(node.computeSize());
|
|
node.setDirtyCanvas(true, true);
|
|
},
|
|
});
|