mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-01 13:59:54 +00:00
33 lines
948 B
TypeScript
33 lines
948 B
TypeScript
import type { InputSpec } from '@/types/apiTypes'
|
|
|
|
export function getNumberDefaults(
|
|
inputOptions: InputSpec[1],
|
|
options: {
|
|
defaultStep: number
|
|
precision?: number
|
|
enableRounding: boolean
|
|
}
|
|
) {
|
|
const { defaultStep } = options
|
|
const {
|
|
default: defaultVal = 0,
|
|
min = 0,
|
|
max = 2048,
|
|
step = defaultStep
|
|
} = inputOptions
|
|
// precision is the number of decimal places to show.
|
|
// by default, display the the smallest number of decimal places such that changes of size step are visible.
|
|
const { precision = Math.max(-Math.floor(Math.log10(step)), 0) } = options
|
|
|
|
let round = inputOptions.round
|
|
if (options.enableRounding && (round == undefined || round === true)) {
|
|
// by default, round the value to those decimal places shown.
|
|
round = Math.round(1000000 * Math.pow(0.1, precision)) / 1000000
|
|
}
|
|
|
|
return {
|
|
val: defaultVal,
|
|
config: { min, max, step: 10.0 * step, round, precision }
|
|
}
|
|
}
|