import{isEmpty}from"../../base/helpers.mjs";import{ScribbleView}from"../../view/scribble.mjs";import{ImageEditorNodeView}from"./base.mjs";class ImageEditorScribbleNodeView extends ImageEditorNodeView{static nodeTypeName="Scribble";static hideHeader=!0;static pencilSquareIcon="fa-regular fa-square";static pencilSquareTooltip="Change Pencil Shape to Square";static pencilCircleIcon="fa-regular fa-circle";static pencilCircleTooltip="Change Pencil Shape to Circle";static eraserIcon="fa-solid fa-eraser";static eraserTooltip="Switch to Eraser (Hold <code>alt</code> To Quick-Toggle)";static pencilIcon="fa-solid fa-pencil";static pencilTooltip="Switch Back to Pencil";static nodeButtons={...ImageEditorNodeView.nodeButtons,shape:{icon:ImageEditorScribbleNodeView.pencilSquareIcon,tooltip:ImageEditorScribbleNodeView.pencilSquareTooltip,shortcut:"e",callback:function(){this.togglePencilShape()}},erase:{icon:ImageEditorScribbleNodeView.eraserIcon,tooltip:ImageEditorScribbleNodeView.eraserTooltip,shortcut:"t",callback:function(){this.toggleEraser()}},clear:{icon:"fa-solid fa-delete-left",tooltip:"Clear the entire canvas",shortcut:"l",callback:function(){this.clearMemory()}},increase:{icon:"fa-solid fa-plus",tooltip:"Increase Pencil Size",shortcut:"i",callback:function(){this.increaseSize()}},decrease:{icon:"fa-solid fa-minus",tooltip:"Decrease Pencil Size",shortcut:"d",callback:function(){this.decreaseSize()}}};constructor(e,t,i,o,s,c,r){super(e,t,new ScribbleView(e.config,c,r),o,s,c,r)}async scaleToCanvasSize(){await super.scaleToCanvasSize(),window.requestAnimationFrame((()=>{this.resized()}))}clearMemory(){this.content.clearMemory()}increaseSize(){this.content.increaseSize()}decreaseSize(){this.content.decreaseSize()}togglePencilShape(){"circle"===this.content.shape?(this.content.shape="square",this.buttons.shape.tooltip=this.constructor.pencilCircleTooltip,this.buttons.shape.icon=this.constructor.pencilCircleIcon):(this.content.shape="circle",this.buttons.shape.tooltip=this.constructor.pencilSquareTooltip,this.buttons.shape.icon=this.constructor.pencilSquareIcon),this.rebuildHeaderButtons()}toggleEraser(){!0===this.content.isEraser?(this.content.isEraser=!1,this.buttons.erase.icon=this.constructor.eraserIcon,this.buttons.erase.tooltip=this.constructor.eraserTooltip):(this.content.isEraser=!0,this.buttons.erase.icon=this.constructor.pencilIcon,this.buttons.erase.tooltip=this.constructor.pencilTooltip),this.rebuildHeaderButtons()}async resized(){await super.resized(),this.content.resizeCanvas(this.visibleWidth-2*this.constructor.padding,this.visibleHeight-2*this.constructor.padding)}getState(e=!0){let t=super.getState(e);return t.src=e?this.content.src:null,t}setState(e){if(super.setState(e),isEmpty(e.src))this.content.clearMemory();else{let t=new Image;t.onload=()=>this.content.setMemory(t),t.src=e.src}}}export{ImageEditorScribbleNodeView};
