Compare commits

...
4 changed files with 93 additions and 14 deletions
+6
View File
@@ -4,6 +4,12 @@ All notable changes to ComfyUI-AusBoss are documented here.
## Unreleased
- **A node saved with an older version opens at the size it was saved at.**
When a node's face gained a row in a later release, a saved node opened
taller and could cover what sat under it in the workflow. H3 Prompt Writer
🆎 in Person Swap opened 35 px taller and ran into the note below. The
node's text box now gives up that space, so the node keeps its saved size.
Drag the node taller to get the bigger text box back.
- **Mask Refine 🆎's guided and matting edges follow the picture.** Both
edge modes now look further from the mask's edge and snap to the real
edge in the guide image, so hair and thin parts a rough mask missed come
+19 -8
View File
@@ -40,7 +40,7 @@ import { limitsLabel, narrowedRange } from "./wired_limits.mjs";
import { hideWidget } from "./widget_visibility.mjs";
import {
CARD_PADDING, GROUP_HEIGHT, ROW_GAP, ROW_HEIGHT, SECTION_HEIGHT, SLOT_OFFSET, UNIT_SLOT_WIDTH,
cardChangeRestore, cardHeight, choiceLabel, commitWidgetValue, comboValues, rowHeight, rowInLook, rowKind, rowMuted, rowTops, scrubSteps, socketWidgetY, visibleRows,
cardChangeRestore, cardHeight, choiceLabel, commitWidgetValue, comboValues, rowHeight, rowInLook, rowKind, rowMuted, rowTops, savedHeightGives, scrubSteps, socketWidgetY, visibleRows,
liftSocket, widgetTooltip,
} from "./widget_card_math.mjs";
@@ -240,7 +240,7 @@ export function mountWidgetCard(node, { rows, minWidth = 300, first = false, hid
ensureCardCss();
const root = el("div", "ausboss-card");
const managed = [];
const state = { node, root, rows: [], groups: {}, height: 0, widget: null, rowTop: new Map(), rowSpan: new Map(), socketed: [], pickers: [], observers: [], look: "" };
const state = { node, root, rows: [], groups: {}, height: 0, widget: null, rowTop: new Map(), rowSpan: new Map(), socketed: [], pickers: [], observers: [], look: "", given: new Map() };
node.__ausbossCard = state;
const values = () => Object.fromEntries((node.widgets ?? []).map((widget) => [widget.name, widget.value]));
@@ -774,21 +774,32 @@ export function mountWidgetCard(node, { rows, minWidth = 300, first = false, hid
// takes its height in this look.
for (const entry of state.rows) {
if (entry.row.kind !== "textarea" && !entry.row.looks) continue;
const height = `${rowHeight(entry.row, look)}px`;
if (entry.row.grow) entry.element.style.minHeight = height;
else entry.element.style.height = height;
if (entry.row.grow) entry.element.style.minHeight = `${rowHeight(entry.row, look) - (state.given.get(entry.row) ?? 0)}px`;
else entry.element.style.height = `${rowHeight(entry.row, look)}px`;
}
}
const groups = {};
for (const entry of state.rows) if (entry.header) groups[entry.row.group] = groupOpen(entry.row.group);
const visible = visibleRows(state.rows.map((entry) => entry.row), vals, groups, node);
const visibleSet = new Set(visible);
const tops = rowTops(visible, look);
if (state.restoring) {
// A node saved by a release whose card was shorter sits under today's
// floor. Its growing rows give up the difference, so it keeps the
// height it was saved at and covers nothing below it.
const before = state.height;
state.height = cardHeight(visible, look);
state.given = savedHeightGives(visible, look, Number(node.computeSize?.()[1]) - state.savedHeight);
state.height = before;
for (const entry of state.rows) {
if (entry.row.grow) entry.element.style.minHeight = `${rowHeight(entry.row, look) - (state.given.get(entry.row) ?? 0)}px`;
}
}
const tops = rowTops(visible, look, state.given);
state.rowTop = new Map();
state.rowSpan = new Map();
visible.forEach((row, index) => {
const entry = state.rows.find((item) => item.row === row);
for (const name of entry?.names ?? []) { state.rowTop.set(name, tops[index]); state.rowSpan.set(name, rowHeight(row, look)); }
for (const name of entry?.names ?? []) { state.rowTop.set(name, tops[index]); state.rowSpan.set(name, rowHeight(row, look) - (state.given.get(row) ?? 0)); }
if (entry?.header) { state.rowTop.set(`group:${row.group}`, tops[index]); }
});
// A row folded under a closed group: its socket rides the header.
@@ -822,7 +833,7 @@ export function mountWidgetCard(node, { rows, minWidth = 300, first = false, hid
for (const sync of entry.syncs) sync(vals, linked);
}
if (tools?.sync) root.style.setProperty("--ausboss-card-corner", `${Math.max(0, Number(tools.sync(vals)) || 0)}px`);
const height = cardHeight(visible, look);
const height = cardHeight(visible, look, state.given);
if (height !== state.height) {
const first = !state.height;
const change = first ? 0 : height - state.height;
+31 -5
View File
@@ -72,19 +72,45 @@ export function rowHeight(row, look = null) {
return height > 0 ? height : ROW_HEIGHT;
}
// The least height a growing row is squeezed to for a saved node.
export const GROW_FLOOR = 72;
// What each growing row gives up so a saved node keeps its height. A face
// that gains a row in a later release gets a taller floor, and a node saved
// before that sits under it: lifted to the floor it would cover what is
// below it in the workflow. `short` is how far the saved node is under the
// floor. The growing rows take that from their own height, in order, down to
// GROW_FLOOR; anything left over still lifts the node. Returns row -> pixels.
export function savedHeightGives(rows, look = null, short = 0) {
const given = new Map();
let left = Number(short);
if (!(left > 0)) return given;
for (const row of rows) {
if (!row.grow) continue;
const give = Math.min(left, Math.max(0, rowHeight(row, look) - GROW_FLOOR));
if (give > 0) given.set(row, give);
left -= give;
if (left <= 0) break;
}
return given;
}
const heightLeft = (row, look, given) => rowHeight(row, look) - (given?.get(row) ?? 0);
// Card height for a list of visible rows: rows, section captions and group
// headers each add their own height plus the gap between them.
export function cardHeight(rows, look = null) {
// headers each add their own height plus the gap between them. `given` is
// what savedHeightGives took from the growing rows.
export function cardHeight(rows, look = null, given = null) {
if (!rows.length) return CARD_PADDING * 2;
return CARD_PADDING * 2 + rows.reduce((sum, row) => sum + rowHeight(row, look), 0) + ROW_GAP * (rows.length - 1);
return CARD_PADDING * 2 + rows.reduce((sum, row) => sum + heightLeft(row, look, given), 0) + ROW_GAP * (rows.length - 1);
}
// Where each visible row starts, measured from the card's top edge.
export function rowTops(rows, look = null) {
export function rowTops(rows, look = null, given = null) {
let y = CARD_PADDING;
return rows.map((row) => {
const top = y;
y += rowHeight(row, look) + ROW_GAP;
y += heightLeft(row, look, given) + ROW_GAP;
return top;
});
}
+37 -1
View File
@@ -6,7 +6,7 @@ import { fileURLToPath } from "node:url";
import {
CARD_PADDING, GROUP_HEIGHT, ROW_GAP, ROW_HEIGHT, SECTION_HEIGHT, SLOT_OFFSET, SOCKETLESS_CHOICE, SOCKETLESS_TEXT,
cardHeight, choiceLabel, commitWidgetValue, holdsUnknownValue, liftSlot, liftSocket, markSocketless, resetUnknownValues, rowHeight, rowInLook, rowKind, rowMuted, rowTops,
GROW_FLOOR, cardHeight, choiceLabel, commitWidgetValue, holdsUnknownValue, liftSlot, liftSocket, markSocketless, resetUnknownValues, rowHeight, rowInLook, rowKind, rowMuted, rowTops, savedHeightGives,
scrubSteps, segmentFits, socketWidgetY, visibleRows, widgetTooltip,
} from "../js/shared/widget_card_math.mjs";
@@ -466,3 +466,39 @@ test("every group a card folds rows into has a header that opens it", () => {
for (const group of folded) assert.ok(headers.has(group), `${id} folds rows into "${group}" with no header row to open it`);
}
});
// A face that gains a row gets a taller floor. A node saved by an earlier
// release sits under that floor, and lifting it covers what is below it.
const face = [{ panel: () => {}, height: 30 }, { widget: "script", kind: "textarea", height: 118, grow: true }, { widget: "seconds" }];
test("a growing row gives up what a saved node is short of", () => {
const given = savedHeightGives(face, null, 35);
assert.equal(given.get(face[1]), 35);
assert.equal(given.size, 1);
assert.equal(cardHeight(face, null, given), cardHeight(face) - 35);
});
test("the rows under a growing row move up by what it gave", () => {
const given = savedHeightGives(face, null, 35);
assert.deepEqual(rowTops(face, null, given), [CARD_PADDING, CARD_PADDING + 30 + ROW_GAP, CARD_PADDING + 30 + ROW_GAP + 83 + ROW_GAP]);
});
test("a growing row never gives so much that it goes under its own floor", () => {
const given = savedHeightGives(face, null, 200);
assert.equal(given.get(face[1]), 118 - GROW_FLOOR);
});
test("nothing is given when the saved node is tall enough, or its height is unknown", () => {
for (const short of [0, -40, NaN, undefined]) assert.equal(savedHeightGives(face, null, short).size, 0);
});
test("a card with no growing row gives nothing", () => {
assert.equal(savedHeightGives([{ widget: "a" }, { widget: "b" }], null, 35).size, 0);
});
test("two growing rows give in order, the first one first", () => {
const rows = [{ widget: "a", kind: "textarea", height: 100, grow: true }, { widget: "b", kind: "textarea", height: 96, grow: true }];
const given = savedHeightGives(rows, null, 40);
assert.equal(given.get(rows[0]), 28);
assert.equal(given.get(rows[1]), 12);
});