Line data Source code
1 : import { cn } from '@comfyorg/tailwind-utils'
2 :
3 : import type { MissingNodeType } from '@/platform/workflowErrors/nodeReplacement/types'
4 :
5 : // The negative margin and matching padding cancel out, so the background
6 : // bleeds 6px past the content without shifting the text.
7 2355 : const EMPHASIS_CLASS = 'rounded-sm bg-primary/30 -mx-1.5 px-1.5'
8 :
9 : // Present even when unhighlighted so the emphasis animates both ways.
10 2355 : const TRANSITION_CLASS =
11 : 'transition-[background-color,margin,padding,border-radius] duration-200'
12 :
13 : /** Classes emphasizing rows/cards that belong to the canvas selection. */
14 148 : export function selectionEmphasisClass(highlighted: boolean | undefined) {
15 148 : return cn(TRANSITION_CLASS, highlighted && EMPHASIS_CLASS)
16 : }
17 :
18 : /** True when any node type resolves to a node in the given id set. */
19 59 : export function someNodeTypeInSelection(
20 : nodeTypes: MissingNodeType[],
21 : nodeIds: Set<string> | undefined
22 : ): boolean {
23 59 : if (!nodeIds?.size) return false
24 5 : return nodeTypes.some(
25 : (nodeType) =>
26 : typeof nodeType !== 'string' &&
27 : nodeType.nodeId != null &&
28 : nodeIds.has(String(nodeType.nodeId))
29 : )
30 : }
|