Files
ComfyUI_frontend/src/components/gradientslider/gradients.ts
Terry Jia f7a83f6dfa feat: add gradient-slider widget for FLOAT inputs (#8992)
## Summary
Add a new 'gradient-slider' display mode for FLOAT widget inputs. Nodes
can specify gradient_stops (color stop arrays) to render a colored
gradient track behind the slider thumb, useful for color adjustment
parameters like hue, saturation, brightness, etc.

- GradientSlider.vue: reusable Reka UI-based gradient slider component
- GradientSliderWidget.ts: litegraph canvas-mode fallback rendering
- WidgetInputNumberGradientSlider.vue: Vue node widget integration
- Schema, registry, and type updates for gradient-slider support

this is prerequisite for color correct and balance

BE changes https://github.com/Comfy-Org/ComfyUI/pull/12536

## Screenshots (if applicable)

<img width="610" height="237" alt="image"
src="https://github.com/user-attachments/assets/b0577ca8-8576-4062-8f14-0a3612e56242"
/>

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-8992-feat-add-gradient-slider-widget-for-FLOAT-inputs-30d6d73d36508199b3e8db6a0c213ab4)
by [Unito](https://www.unito.io)

---------

Co-authored-by: Alexander Brown <drjkl@comfy.org>
2026-02-20 20:51:10 -05:00

41 lines
1.2 KiB
TypeScript

import type { ColorStop } from '@/lib/litegraph/src/interfaces'
export function stopsToGradient(stops: ColorStop[]): string {
if (!stops.length) return 'transparent'
const colors = stops.map(
({ offset, color: [r, g, b] }) => `rgb(${r},${g},${b}) ${offset * 100}%`
)
return `linear-gradient(to right, ${colors.join(', ')})`
}
export function interpolateStops(stops: ColorStop[], t: number): string {
if (!stops.length) return 'transparent'
const clamped = Math.max(0, Math.min(1, t))
if (clamped <= stops[0].offset) {
const [r, g, b] = stops[0].color
return `rgb(${r},${g},${b})`
}
for (let i = 0; i < stops.length - 1; i++) {
const {
offset: o1,
color: [r1, g1, b1]
} = stops[i]
const {
offset: o2,
color: [r2, g2, b2]
} = stops[i + 1]
if (clamped >= o1 && clamped <= o2) {
const f = o2 === o1 ? 0 : (clamped - o1) / (o2 - o1)
const r = Math.round(r1 + (r2 - r1) * f)
const g = Math.round(g1 + (g2 - g1) * f)
const b = Math.round(b1 + (b2 - b1) * f)
return `rgb(${r},${g},${b})`
}
}
const [r, g, b] = stops[stops.length - 1].color
return `rgb(${r},${g},${b})`
}