Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
2 : import type {
3 : IBaseWidget,
4 : IWidgetBoundingBoxesOptions
5 : } from '@comfyorg/graph-model/widgets'
6 : import type {
7 : BoundingBoxesInputSpec,
8 : InputSpec as InputSpecV2
9 : } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
10 : import type { ComfyWidgetConstructorV2 } from '@/types/widgetConstructor'
11 : import type { BoundingBox } from '@comfyorg/graph-model/boundingBoxes'
12 :
13 2356 : export const useBoundingBoxesWidget = (): ComfyWidgetConstructorV2 => {
14 2356 : return (node: LGraphNode, inputSpec: InputSpecV2): IBaseWidget => {
15 0 : const spec = inputSpec as BoundingBoxesInputSpec
16 0 : const defaultValue: BoundingBox[] =
17 : spec.default?.map((box) => ({
18 : ...box,
19 : metadata: { ...box.metadata, palette: [...box.metadata.palette] }
20 : })) ?? []
21 0 : const options: IWidgetBoundingBoxesOptions = {
22 : serialize: true,
23 : hideInPanel: true,
24 : max_boxes: spec.max_boxes
25 : }
26 0 : return node.addWidget(
27 : 'boundingboxes',
28 : spec.name,
29 : defaultValue,
30 : null,
31 : options
32 : )
33 : }
34 : }
|