mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-23 15:59:47 +00:00
Backport of #10118 to `core/1.42` Automatically created by backport workflow. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-10172-backport-core-1-42-feat-add-linear-interpolation-type-to-CURVE-widget-3266d73d365081bca197d5cf30c4f9b5) by [Unito](https://www.unito.io) Co-authored-by: Terry Jia <terryjia88@gmail.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { CurveData } from '@/components/curve/types'
|
|
import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
|
|
import type { ICurveWidget } from '@/lib/litegraph/src/types/widgets'
|
|
import type {
|
|
CurveInputSpec,
|
|
InputSpec as InputSpecV2
|
|
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import type { ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
|
|
|
const DEFAULT_CURVE_DATA: CurveData = {
|
|
points: [
|
|
[0, 0],
|
|
[1, 1]
|
|
],
|
|
interpolation: 'monotone_cubic'
|
|
}
|
|
|
|
export const useCurveWidget = (): ComfyWidgetConstructorV2 => {
|
|
return (node: LGraphNode, inputSpec: InputSpecV2): ICurveWidget => {
|
|
const spec = inputSpec as CurveInputSpec
|
|
const defaultValue: CurveData = spec.default
|
|
? { ...spec.default, points: [...spec.default.points] }
|
|
: { ...DEFAULT_CURVE_DATA, points: [...DEFAULT_CURVE_DATA.points] }
|
|
|
|
const rawWidget = node.addWidget('curve', spec.name, defaultValue, () => {})
|
|
|
|
if (rawWidget.type !== 'curve') {
|
|
throw new Error(`Unexpected widget type: ${rawWidget.type}`)
|
|
}
|
|
|
|
return rawWidget as ICurveWidget
|
|
}
|
|
}
|