import{isEmpty}from"../../base/helpers.mjs";import{FormView}from"../../view/forms/base.mjs";import{NumberInputView,FloatInputView}from"../../view/forms/input.mjs";import{Controller}from"../base.mjs";class RefiningForm extends FormView{static autoSubmit=!0;static collapseFieldSets=!0;static fieldSets={Refining:{refinerStrength:{label:"Refiner Denoising Strength",class:FloatInputView,config:{minimum:0,maximum:1,step:.01,value:.3,tooltip:"When using a refiner, this will control how much of the original image is kept, and how much of it is replaced with refined content. A value of 1.0 represents total destruction of the first image."}},refinerGuidanceScale:{label:"Refiner Guidance Scale",class:FloatInputView,config:{minimum:0,maximum:100,step:.01,value:5,tooltip:"When using a refiner, this will control how closely to follow the guidance of the model. Low values can result in soft details, whereas high values can result in high-contrast ones."}},refinerAestheticScore:{label:"Refiner Aesthetic Score",class:FloatInputView,config:{minimum:0,maximum:100,step:.01,value:6,tooltip:"Aesthetic scores are assigned to images in SDXL refinement; this controls the positive score."}},refinerNegativeAestheticScore:{label:"Refiner Negative Aesthetic Score",class:FloatInputView,config:{minimum:0,maximum:100,step:.01,value:2.5,tooltip:"Aesthetic scores are assigned to images in SDXL refinement; this controls the negative score."}}}}}class RefiningController extends Controller{getState(){return{refining:this.refiningForm.values}}getDefaultState(){return{refining:{refinerStrength:.3,refinerGuidanceScale:5,refinerAestheticScore:6,refinerNegativeAestheticScore:2.5}}}setState(e){isEmpty(e.refining)||this.refiningForm.setValues(e.refining).then((()=>this.refiningForm.submit()))}async initialize(){this.refiningForm=new RefiningForm(this.config),this.refiningForm.onSubmit((async e=>{this.engine.refinerStrength=e.refinerStrength,this.engine.refinerGuidanceScale=e.refinerGuidanceScale,this.engine.refinerAestheticScore=e.refinerAestheticScore,this.engine.refinerNegativeAestheticScore=e.refinerNegativeAestheticScore})),this.refiningForm.hide(),this.application.sidebar.addChild(this.refiningForm),this.subscribe("modelPickerChange",(e=>{if(isEmpty(e)||isEmpty(e.refiner))this.refiningForm.hide();else{let i=e.defaultConfiguration,t={};isEmpty(i.refiner_strength)||(t.refinerStrength=i.refiner_strength),isEmpty(i.refiner_guidance_scale)||(t.refinerGuidanceScale=i.refiner_guidance_scale),isEmpty(i.refiner_aesthetic_score)||(t.refinerAestheticScore=i.refiner_aesthetic_score),isEmpty(i.refiner_negative_aesthetic_score)||(t.refinerNegativeAestheticScore=i.refiner_negative_aesthetic_score),isEmpty(t)||this.refiningForm.setValues(t),this.refiningForm.show()}})),this.subscribe("engineRefinerChange",(e=>{isEmpty(e)?this.refiningForm.hide():this.refiningForm.show()}))}}export{RefiningController as SidebarController};
