Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
2 : import type {
3 : IResolutionPreviewWidget,
4 : IWidgetResolutionPreviewOptions
5 : } from '@comfyorg/graph-model/widgets'
6 : import { isResolutionPreviewInputSpec } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
7 : import type { InputSpec as InputSpecV2 } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
8 : import type { ComfyWidgetConstructorV2 } from '@/types/widgetConstructor'
9 :
10 2356 : export const useResolutionPreviewWidget = (): ComfyWidgetConstructorV2 => {
11 2356 : return (
12 : node: LGraphNode,
13 : inputSpec: InputSpecV2
14 : ): IResolutionPreviewWidget => {
15 3 : const spec = isResolutionPreviewInputSpec(inputSpec) ? inputSpec : undefined
16 3 : const options: IWidgetResolutionPreviewOptions = {
17 : serialize: false,
18 : canvasOnly: false,
19 : hideInPanel: true,
20 : ratio_widget: spec?.ratio_widget,
21 : megapixels_widget: spec?.megapixels_widget,
22 : multiple_widget: spec?.multiple_widget
23 : }
24 3 : const rawWidget = node.addWidget(
25 : 'resolutionpreview',
26 : inputSpec.name,
27 : null,
28 : () => {},
29 : options
30 : )
31 3 : rawWidget.serialize = false
32 :
33 3 : return rawWidget as IResolutionPreviewWidget
34 : }
35 : }
|