import{isEmpty}from"../../../base/helpers.mjs";import{FormView}from"../../forms/base.mjs";import{NodeView}from"../base.mjs";import{TextInputView,FloatInputView,NumberInputView,CheckboxInputView}from"../../forms/input.mjs";class ImageEditorBaseOptionsFormView extends FormView{static fieldSets={Prompts:{prompt:{label:"Prompt",class:TextInputView,config:{tooltip:"This prompt will control what is in this frame. When left blank, the global prompt will be used."}},negativePrompt:{label:"Negative Prompt",class:TextInputView,config:{tooltip:"This prompt will control what is in not this frame. When left blank, the global negative prompt will be used."}}},Tweaks:{guidanceScale:{label:"Guidance Scale",class:FloatInputView,config:{min:0,max:100,step:.1,value:null,tooltip:"How closely to follow the text prompt; high values result in high-contrast images closely adhering to your text, low values result in low-contrast images with more randomness."}},inferenceSteps:{label:"Inference Steps",class:NumberInputView,config:{min:5,max:250,step:1,value:null,tooltip:"How many steps to take during primary inference, larger values take longer to process."}}},Other:{scaleToModelSize:{label:"Scale to Model Size",class:CheckboxInputView,config:{tooltip:"When this node has any dimension smaller than the size of the configured model, scale it up so it's smallest dimension is the same size as the model, then scale it down after diffusion.<br />This generally improves image quality in slightly rectangular shapes or square shapes smaller than the engine size, but can also result in ghosting and increased processing time.<br />This will have no effect if your node is larger than the model size in all dimensions.<br />If unchecked and your node is smaller than the model size, TensorRT will be disabled for this node."}},removeBackground:{label:"Remove Background",class:CheckboxInputView,config:{tooltip:"After diffusion, run the resulting image though an AI background removal algorithm. This can improve image consistency when using multiple nodes."}}}};static autoSubmit=!0;static className="options-form-view"}class ImageEditorNodeView extends NodeView{static canFlipHeader=!0;static minHeight=32;static minWidth=32;static snapSize=8;static padding=8;static edgeHandlerTolerance=8;static hideHeader=!0;static closeText="Remove";static nodeButtons={anchor:{icon:"fa-solid fa-sliders",tooltip:"Show/Hide Options",callback:function(){this.toggleOptions()}}};static optionsFormView=ImageEditorBaseOptionsFormView;async updateOptions(e){this.prompt=e.prompt,this.negativePrompt=e.negativePrompt,this.guidanceScale=e.guidanceScale,this.inferenceSteps=e.inferenceSteps,this.scaleToModelSize=e.scaleToModelSize,this.removeBackground=e.removeBackground}async toggleOptions(){if(isEmpty(this.optionsForm)){this.optionsForm=new this.constructor.optionsFormView(this.config),this.optionsForm.onSubmit((e=>this.updateOptions(e)));let e=await this.optionsForm.getNode();this.optionsForm.setValues(this.getState()),this.node.find("enfugue-node-contents").append(e)}else this.optionsForm.hidden?this.optionsForm.show():this.optionsForm.hide()}setState(e){super.setState({name:e.name,x:e.x-this.constructor.padding,y:e.y-this.constructor.padding,h:e.h+2*this.constructor.padding,w:e.w+2*this.constructor.padding}),this.updateOptions(e),isEmpty(this.optionsForm)||this.optionsForm.setValues(e)}getState(){let e=super.getState();return e.prompt=this.prompt||null,e.negativePrompt=this.negativePrompt||null,e.guidanceScale=this.guidanceScale||null,e.inferenceSteps=this.inferenceSteps||null,e.removeBackground=this.removeBackground||!1,e.scaleToModelSize=this.scaleToModelSize||!1,e}}export{ImageEditorBaseOptionsFormView,ImageEditorNodeView};
