Selection toolbox color picker button (#2637)

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chenlei Hu
2025-02-19 15:25:46 -05:00
committed by GitHub
parent 08a6867c00
commit 6c6d86a30b
13 changed files with 299 additions and 8 deletions

View File

@@ -1,5 +1,7 @@
import type { IWidget, LGraphNode } from '@comfyorg/litegraph'
import type { ColorOption, IWidget } from '@comfyorg/litegraph'
import { LGraphNode, isColorable } from '@comfyorg/litegraph'
import type { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
import _ from 'lodash'
export function isImageNode(node: LGraphNode) {
return (
@@ -22,3 +24,21 @@ export const isLGraphNode = (item: unknown): item is LGraphNode => {
const name = item?.constructor?.name
return name === 'ComfyNode' || name === 'LGraphNode'
}
/**
* Get the color option of all canvas items if they are all the same.
* @param items - The items to get the color option of.
* @returns The color option of the item.
*/
export const getItemsColorOption = (items: unknown[]): ColorOption | null => {
const validItems = _.filter(items, isColorable)
if (_.isEmpty(validItems)) return null
const colorOptions = _.map(validItems, (item) => item.getColorOption())
return _.every(colorOptions, (option) =>
_.isEqual(option, _.head(colorOptions))
)
? _.head(colorOptions)!
: null
}