Line data Source code
1 16 : <template>
2 32 : <div class="flex flex-col gap-3 pb-3">
3 : <h3
4 : class="mt-2.5 text-center font-sans text-[15px] font-bold text-muted-foreground"
5 : >
6 : {{ t('maskEditor.brushSettings') }}
7 : </h3>
8 :
9 : <Button
10 : variant="outline"
11 : size="unset"
12 : class="h-7.5 w-32 rounded-[10px] bg-background"
13 : @click="resetToDefault"
14 : >
15 : {{ t('maskEditor.resetToDefault') }}
16 : </Button>
17 :
18 : <!-- Brush Shape -->
19 : <div class="flex flex-col gap-3 pb-3">
20 : <span class="text-left font-sans text-xs text-muted-foreground">
21 : {{ t('maskEditor.brushShape') }}
22 : </span>
23 :
24 : <div
25 : class="flex h-[50px] w-full items-center gap-2.5 rounded-[10px] bg-accent"
26 : >
27 : <button
28 : type="button"
29 : :aria-label="t('maskEditor.brushShapeCircle')"
30 : :aria-pressed="store.brushSettings.type === BrushShape.Arc"
31 : :class="
32 : cn(
33 : 'ml-2 size-[35px] cursor-pointer appearance-none rounded-full border border-solid p-0 transition-colors',
34 : store.brushSettings.type === BrushShape.Arc
35 : ? 'bg-background'
36 : : 'bg-transparent hover:bg-background/60'
37 : )
38 : "
39 : @click="setBrushShape(BrushShape.Arc)"
40 : />
41 :
42 : <button
43 : type="button"
44 : :aria-label="t('maskEditor.brushShapeSquare')"
45 : :aria-pressed="store.brushSettings.type === BrushShape.Rect"
46 : :class="
47 : cn(
48 : 'size-[35px] cursor-pointer appearance-none border border-solid p-0 transition-colors',
49 : store.brushSettings.type === BrushShape.Rect
50 : ? 'bg-background'
51 : : 'bg-transparent hover:bg-background/60'
52 : )
53 : "
54 : @click="setBrushShape(BrushShape.Rect)"
55 : />
56 : </div>
57 : </div>
58 :
59 : <!-- Color -->
60 : <div class="flex flex-col gap-3 pb-3">
61 : <span class="text-left font-sans text-xs text-muted-foreground">
62 : {{ t('maskEditor.colorSelector') }}
63 : </span>
64 : <input
65 : ref="colorInputRef"
66 : v-model="store.rgbColor"
67 : type="color"
68 : class="h-10 cursor-pointer rounded-md"
69 : />
70 : </div>
71 :
72 : <!-- Thickness -->
73 : <div class="flex flex-col gap-2">
74 : <div class="flex items-center justify-between">
75 : <span class="text-left font-sans text-xs text-muted-foreground">
76 : {{ t('maskEditor.thickness') }}
77 : </span>
78 : <input
79 : v-model.number="brushSize"
80 : data-testid="brush-thickness-input"
81 : type="number"
82 : class="w-16 rounded-md border bg-background px-2 py-1 text-center text-sm text-foreground"
83 : :min="1"
84 : :max="250"
85 : :step="1"
86 : />
87 : </div>
88 : <SliderControl
89 : v-model="brushSizeSliderValue"
90 : class="flex-1"
91 : label=""
92 : :min="0"
93 : :max="1"
94 : :step="0.001"
95 : />
96 : </div>
97 :
98 : <!-- Opacity -->
99 : <div class="flex flex-col gap-2">
100 : <div class="flex items-center justify-between">
101 : <span class="text-left font-sans text-xs text-muted-foreground">
102 : {{ t('maskEditor.opacity') }}
103 : </span>
104 : <input
105 : v-model.number="brushOpacity"
106 : type="number"
107 : class="w-16 rounded-md border bg-background px-2 py-1 text-center text-sm text-foreground"
108 : :min="0"
109 : :max="1"
110 : :step="0.01"
111 : />
112 : </div>
113 : <SliderControl
114 : v-model="brushOpacity"
115 : class="flex-1"
116 : label=""
117 : :min="0"
118 : :max="1"
119 : :step="0.01"
120 : />
121 : </div>
122 :
123 : <!-- Hardness -->
124 : <div class="flex flex-col gap-2">
125 : <div class="flex items-center justify-between">
126 : <span class="text-left font-sans text-xs text-muted-foreground">
127 : {{ t('maskEditor.hardness') }}
128 : </span>
129 : <input
130 : v-model.number="brushHardness"
131 : type="number"
132 : class="w-16 rounded-md border bg-background px-2 py-1 text-center text-sm text-foreground"
133 : :min="0"
134 : :max="1"
135 : :step="0.01"
136 : />
137 : </div>
138 : <SliderControl
139 : v-model="brushHardness"
140 : class="flex-1"
141 : label=""
142 : :min="0"
143 : :max="1"
144 : :step="0.01"
145 : />
146 : </div>
147 :
148 : <!-- Step Size -->
149 : <div class="flex flex-col gap-2">
150 : <div class="flex items-center justify-between">
151 : <span class="text-left font-sans text-xs text-muted-foreground">
152 : {{ t('maskEditor.stepSize') }}
153 : </span>
154 : <input
155 : v-model.number="brushStepSize"
156 : type="number"
157 : class="w-16 rounded-md border bg-background px-2 py-1 text-center text-sm text-foreground"
158 : :min="1"
159 : :max="100"
160 : :step="1"
161 : />
162 : </div>
163 : <SliderControl
164 : v-model="brushStepSize"
165 : class="flex-1"
166 : label=""
167 : :min="1"
168 : :max="100"
169 : :step="1"
170 : />
171 : </div>
172 : </div>
173 : </template>
174 :
175 : <script setup lang="ts">
176 : import Button from '@comfyorg/design-system/button/Button'
177 : import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
178 : import { useI18n } from 'vue-i18n'
179 :
180 : import { BrushShape } from '#/types'
181 : import { useMaskEditorStore } from '#/maskEditorStore'
182 : import { cn } from '@comfyorg/tailwind-utils'
183 :
184 : import SliderControl from './controls/SliderControl.vue'
185 :
186 29 : const { t } = useI18n()
187 29 : const store = useMaskEditorStore()
188 :
189 29 : const colorInputRef = ref<HTMLInputElement>()
190 :
191 : /* Computed properties that use store setters for validation */
192 29 : const brushSize = computed({
193 : get: () => store.brushSettings.size,
194 : set: (value: number) => store.setBrushSize(value)
195 : })
196 :
197 29 : const rawSliderValue = ref<number | null>(null)
198 :
199 29 : const brushSizeSliderValue = computed({
200 : get: () => {
201 32 : if (rawSliderValue.value !== null) {
202 0 : const cachedSize = Math.round(Math.pow(250, rawSliderValue.value))
203 : if (cachedSize === brushSize.value) {
204 0 : return rawSliderValue.value
205 : }
206 : }
207 :
208 32 : return Math.log(brushSize.value) / Math.log(250)
209 : },
210 : set: (value: number) => {
211 0 : rawSliderValue.value = value
212 0 : const size = Math.round(Math.pow(250, value))
213 0 : store.setBrushSize(size)
214 : }
215 : })
216 :
217 29 : const brushOpacity = computed({
218 : get: () => store.brushSettings.opacity,
219 : set: (value: number) => store.setBrushOpacity(value)
220 : })
221 :
222 29 : const brushHardness = computed({
223 : get: () => store.brushSettings.hardness,
224 : set: (value: number) => store.setBrushHardness(value)
225 : })
226 :
227 29 : const brushStepSize = computed({
228 : get: () => store.brushSettings.stepSize,
229 : set: (value: number) => store.setBrushStepSize(value)
230 : })
231 :
232 : /* Brush shape */
233 29 : const setBrushShape = (shape: BrushShape) => {
234 0 : store.brushSettings.type = shape
235 : }
236 :
237 : /* Reset */
238 29 : const resetToDefault = () => {
239 0 : store.resetBrushToDefault()
240 : }
241 :
242 29 : onMounted(() => {
243 29 : if (colorInputRef.value) {
244 29 : store.colorInput = colorInputRef.value
245 : }
246 : })
247 :
248 29 : onBeforeUnmount(() => {
249 7 : store.colorInput = null
250 : })
251 : </script>
|