import{isEmpty}from"../../base/helpers.mjs";import{FormView}from"../../view/forms/base.mjs";import{NumberInputView}from"../../view/forms/input.mjs";import{Controller}from"../base.mjs";let defaultWidth=512,defaultHeight=512,defaultChunkingSize=64,defaultChunkingBlur=64;class CanvasForm extends FormView{static collapseFieldSets=!0;static autoSubmit=!0;static fieldSets={Dimensions:{width:{label:"Width",class:NumberInputView,config:{min:64,max:4096,value:defaultWidth,step:8,tooltip:"The width of the canvas in pixels."}},height:{label:"Height",class:NumberInputView,config:{min:64,max:4096,value:defaultHeight,step:8,tooltip:"The height of the canvas in pixels."}},chunkingSize:{label:"Chunk Size",class:NumberInputView,config:{min:0,value:defaultChunkingSize,step:8,tooltip:"<p>The number of pixels to move the frame when doing chunked diffusion.</p><p>When this number is greater than 0, the engine will only ever process a square in the size of the configured model size at once. After each square, the frame will be moved by this many pixels along either the horizontal or vertical axis, and then the image is re-diffused. When this number is 0, chunking is disabled, and the entire canvas will be diffused at once.</p><p>Disabling this (setting it to 0) can have varying visual results, but a guaranteed result is drastically increased VRAM usage for large images. A low number can produce more detailed results, but can be noisy, and takes longer to process. A high number is faster to process, but can have poor results especially along frame boundaries. The recommended value is set by default.</p>"}},chunkingBlur:{label:"Chunk Blur",class:NumberInputView,config:{min:0,value:defaultChunkingBlur,step:8,tooltip:"The number of pixels to feather along the edge of the frame when blending chunked diffusions together. Low numbers can produce less blurry but more noisy results, and can potentially result in visible breaks in the frame. High numbers can help blend frames, but produce blurrier results. The recommended value is set by default."}}}}}class CanvasController extends Controller{getState(){return{canvas:this.canvasForm.values}}getDefaultState(){return{canvas:{width:defaultWidth,height:defaultHeight,chunkingSize:defaultChunkingSize,chunkingBlur:defaultChunkingBlur}}}setState(e){isEmpty(e.canvas)||this.canvasForm.setValues(e.canvas).then((()=>this.canvasForm.submit()))}async initialize(){defaultWidth=this.application.config.model.invocation.width,defaultHeight=this.application.config.model.invocation.height,defaultChunkingSize=this.application.config.model.invocation.chunkingSize,defaultChunkingBlur=this.application.config.model.invocation.chunkingBlur,this.canvasForm=new CanvasForm(this.config),this.canvasForm.onSubmit((async e=>{this.images.width=e.width,this.images.height=e.height,this.engine.width=e.width,this.engine.height=e.height,this.engine.chunkingSize=e.chunkingSize})),this.application.sidebar.addChild(this.canvasForm),this.subscribe("modelPickerChange",(async e=>{let i=this.engine.width,t=this.engine.height,n=!1;if(i<e.size){let i=await this.canvasForm.getInputView("width");i.setValue(e.size),i.setMin(e.size),this.engine.width=e.size,this.images.width=e.size,n=!0}if(t<e.size){let i=await this.canvasForm.getInputView("height");i.setValue(e.size),i.setMin(e.size),this.engine.height=e.size,this.images.height=e.size,n=!0}n&&this.notify("info","Dimensions Changed","The base model specifies a size larger than the current canvas, it has been modified to match.")}))}}export{CanvasController as SidebarController};
