Line data Source code
1 : <script setup lang="ts">
2 : import { computed } from 'vue'
3 :
4 : import { getSlotColor, MAX_MULTITYPE_SLICES } from '@/constants/slotColors'
5 : import type { INodeSlot } from '@/lib/litegraph/src/litegraph'
6 : import { RenderShape } from '@comfyorg/graph-model/globalEnums'
7 : import type { SlotId } from '@comfyorg/graph-model/slotId'
8 : import { cn } from '@comfyorg/tailwind-utils'
9 : import type { ClassValue } from '@comfyorg/tailwind-utils'
10 :
11 35744 : const props = defineProps<{
12 : slotData?: INodeSlot
13 : class?: ClassValue
14 : hasError?: boolean
15 : multi?: boolean
16 : slotKey?: SlotId
17 : }>()
18 :
19 35744 : const clipPath = computed(() => {
20 226 : switch (props.slotData?.shape) {
21 : case 6:
22 0 : return 'url(#square)'
23 : case 7:
24 215 : return 'url(#hollow)'
25 : default:
26 11 : return undefined
27 : }
28 : })
29 :
30 35744 : const types = computed(() => {
31 63435 : if (props.hasError) return ['var(--destructive)']
32 : //TODO Support connected/disconnected colors?
33 63435 : if (!props.slotData) return [getSlotColor()]
34 63435 : if (props.slotData.type === '*') return ['']
35 63307 : return `${props.slotData.type}`
36 : .split(',')
37 : .map(getSlotColor)
38 : .slice(0, MAX_MULTITYPE_SLICES)
39 : })
40 :
41 35744 : const isListShape = computed(() => props.slotData?.shape === RenderShape.GRID)
42 :
43 35744 : const slotClass = computed(() =>
44 : cn(
45 : 'slot-dot bg-ink-100',
46 : isListShape.value ? 'rounded-[1px]' : 'rounded-full',
47 : 'transition-all duration-150',
48 : 'border border-solid border-foreground/10',
49 : props.multi
50 : ? 'h-5 w-2'
51 : : 'size-2 cursor-crosshair group-hover/slot:scale-125 group-hover/slot:border-foreground/50'
52 : )
53 : )
54 35744 : </script>
55 :
56 : <template>
57 63437 : <div
58 : data-testid="slot-connection-dot"
59 : :class="
60 : cn(
61 : 'group/slot relative flex size-6 items-center justify-center after:absolute after:inset-y-0 after:w-5/2',
62 : props.class
63 : )
64 : "
65 : >
66 : <div
67 : v-if="types.length === 1 && (slotData?.shape == undefined || isListShape)"
68 : :data-slot-key="slotKey"
69 : :style="{ backgroundColor: types.length === 1 ? types[0] : undefined }"
70 : :class="slotClass"
71 : data-testid="slot-dot"
72 : />
73 : <svg
74 : v-else
75 : :data-slot-key="slotKey"
76 : :class="slotClass"
77 : data-testid="slot-dot"
78 : viewBox="0 0 100 100"
79 : xmlns="http://www.w3.org/2000/svg"
80 : >
81 : <defs>
82 : <clipPath id="square">
83 : <rect x="20" y="20" width="60" height="60" />
84 : </clipPath>
85 : <clipPath id="hollow">
86 : <path
87 : d="M-50 50
88 : A100 100 0 0 1 150 50
89 : A100 100 0 0 1 -50 50
90 : M30 50
91 : A20 20 0 0 0 70 50
92 : A20 20 0 0 0 30 50"
93 : />
94 : </clipPath>
95 : </defs>
96 : <circle
97 : v-if="types.length === 1"
98 : :clip-path
99 : cx="50"
100 : cy="50"
101 : r="50"
102 : :fill="types[0]"
103 : />
104 : <g v-else-if="types.length === 2" :clip-path stroke-width="4">
105 : <path d="M0 50 A 50 50 0 0 1 100 50" :fill="types[0]" />
106 : <path d="M100 50 A 50 50 0 0 1 0 50" :fill="types[1]" />
107 : <path d="M0 50L100 50" stroke="var(--inner-stroke, black)" />
108 : <path
109 : d="M50 2A48 48 0 0 1 50 98A48 48 0 0 1 50 2"
110 : fill="transparent"
111 : stroke="var(--outer-stroke, transparent)"
112 : />
113 : </g>
114 : <g v-else :clip-path stroke-width="4">
115 : <path d="M0 50A50 50 0 0 0 75 93L50 50" :fill="types[0]" />
116 : <path d="M75 93A50 50 0 0 0 75 7L50 50" :fill="types[1]" />
117 : <path d="M75 7A50 50 0 0 0 0 50L50 50" :fill="types[2]" />
118 : <path
119 : d="M50 50L0 50M50 50L75 93M50 50L75 7"
120 : stroke="var(--inner-stroke, black)"
121 : />
122 : <path
123 : d="M50 2A48 48 0 0 1 50 98A48 48 0 0 1 50 2"
124 : fill="transparent"
125 : stroke="var(--outer-stroke, transparent)"
126 : />
127 : </g>
128 : </svg>
129 : </div>
130 : </template>
|