mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-27 02:04:09 +00:00
Selection toolbox color picker button (#2637)
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user