Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
2 : import type {
3 : IVideoEditWidget,
4 : IWidgetVideoEditOptions,
5 : VideoEditValue
6 : } from '@comfyorg/graph-model/widgets'
7 : import type {
8 : InputSpec as InputSpecV2,
9 : VideoEditInputSpec
10 : } from '@comfyorg/object-info-parser/schemas/nodeDefSchemaV2'
11 : import type { ComfyWidgetConstructorV2 } from '@/types/widgetConstructor'
12 :
13 2356 : export const useVideoEditWidget = (): ComfyWidgetConstructorV2 => {
14 2356 : return (node: LGraphNode, inputSpec: InputSpecV2): IVideoEditWidget => {
15 0 : const spec = inputSpec as VideoEditInputSpec
16 0 : const features = spec.features ?? ['trim', 'crop']
17 :
18 0 : const defaultValue: VideoEditValue = spec.default ?? {
19 : ...(features.includes('trim') && {
20 : trim: { start_time: 0, duration: 0 }
21 : }),
22 : ...(features.includes('crop') && {
23 : crop: { x: 0, y: 0, width: 0, height: 0 }
24 : })
25 : }
26 :
27 0 : const options: IWidgetVideoEditOptions = {
28 : features,
29 : serialize: true,
30 : hideInPanel: true
31 : }
32 :
33 0 : const rawWidget = node.addWidget(
34 : 'videoedit',
35 : spec.name,
36 : structuredClone(defaultValue),
37 : () => {},
38 : options
39 : )
40 :
41 0 : if (rawWidget.type !== 'videoedit') {
42 0 : throw new Error(`Unexpected widget type: ${rawWidget.type}`)
43 : }
44 :
45 0 : return rawWidget as IVideoEditWidget
46 : }
47 : }
|