A list of pictures runs these nodes once per picture, and the panels only showed one of them (#204). Arrows (2 / 5) now appear on the node when a run brings more than one picture: Compare steps through its pairs, A and B together, and Erase saves the pair on screen. The shared preview panel gets the same arrows, so Save Image, Mask Refine, Mask by Name, LaMa Inpaint and Select Frame step through their results. A node too narrow for the arrows widens to fit while they show.
22 lines
862 B
JavaScript
22 lines
862 B
JavaScript
// Which picture of a run to show, and the "2 / 5" that says so. DOM-free
|
|
// so node:test covers it; the arrows themselves are picture_stepper.mjs.
|
|
|
|
// Which picture to show when a run brings `count` of them: the one shown
|
|
// before if there still is one, else the last one there is.
|
|
export function keepIndex(index, count) {
|
|
if (!(count > 0)) return 0;
|
|
const whole = Number.isFinite(index) ? Math.trunc(index) : 0;
|
|
return Math.min(Math.max(whole, 0), count - 1);
|
|
}
|
|
|
|
// One step back (-1) or on (+1), round from the last picture to the first.
|
|
export function stepIndex(index, count, step) {
|
|
if (!(count > 0)) return 0;
|
|
const next = keepIndex(index, count) + Math.sign(Number(step) || 0);
|
|
return ((next % count) + count) % count;
|
|
}
|
|
|
|
export function stepperLabel(index, count) {
|
|
return count > 1 ? `${keepIndex(index, count) + 1} / ${count}` : "";
|
|
}
|