import{r as i,h as t,H as n,g as s}from"./p-9f21f85f.js";const e=[{name:"bold",icon:"uil-bold"},{name:"italic",icon:"uil-italic"},{name:"underline",icon:"uil-underline"},{name:"strike",icon:"uil-text-strike-through"},{name:"link",icon:"uil-link-h"}],o=[{name:"bold",icon:"uil-bold"},{name:"italic",icon:"uil-italic"},{name:"underline",icon:"uil-underline"},{name:"strike",icon:"uil-text-strike-through"},{name:"unlink",icon:"uil-link-broken"}],a=class{constructor(t){i(this,t),this.isShowingLinkInput=!1,this.isShown=!1,this.urlInputValue="",this.showAnimation=!1,this.getActions=()=>e.filter((i=>!this.enabledActions||this.enabledActions.includes(i.name))),this.getActionsWithRemoveLink=()=>o.filter((i=>"unlink"===i.name||!this.enabledActions||this.enabledActions.includes(i.name))),this.onActionClick=i=>"link"===i?(this.isShowingLinkInput=!0,void setTimeout((()=>this.inputElement.focus()),100)):"unlink"===i?(this.onOverlayMenuAction(this.range,"link",!1),this.urlInputValue="",this.isShowingLinkInput=!1,void(this.shownActions=this.getActions())):void this.onOverlayMenuAction(this.range,i),this.onTextChange=i=>{this.urlInputValue=i},this.onKeyDown=i=>{"Enter"===i.key&&(this.onOverlayMenuAction(this.range,"link",this.urlInputValue),this.isShowingLinkInput=!1,this.hide())}}async show(i,t){0!=i.length?(this.shownActions=this.getActions(),this.range=i,this.rect=window.getSelection().getRangeAt(0).getBoundingClientRect(),this.isShown=this.rect&&Math.floor(this.rect.width)>0,this.urlInputValue="",this.isShowingLinkInput=!1,t.link&&(this.shownActions=this.getActionsWithRemoveLink(),this.isShown=!0,this.urlInputValue=t.link,this.isShowingLinkInput=!0),this.showAnimation=!0,setTimeout((()=>this.showAnimation=!1),300)):this.isShown=!1}async hide(){this.isShowingLinkInput||(this.rect=void 0,this.range=void 0,this.isShown=!1)}render(){const{isShowingLinkInput:i,isShown:s,rect:e,shownActions:o}=this;if(!s)return t(n,null);const a=this.el.parentElement.getBoundingClientRect();return t(n,null,t("div",{class:{"menu-container":!0,"has-animation":this.showAnimation},style:{top:e.top-a.top-36+"px",left:e.left-a.left+"px",height:"36px",width:`${e.width}px`}},t("dvn-input-group",{leaned:!0},o.map((i=>t("dvn-button",{onClick:()=>this.onActionClick(i.name),scale:"small",tint:"primary",view:"ghost"},t("dvn-icon",{iconName:i.icon})))),i&&t("dvn-input",{ref:i=>this.inputElement=i,scale:"small",onChange:i=>this.onTextChange(i.detail),onKeyDown:this.onKeyDown,value:this.urlInputValue,width:"200px"}))))}get el(){return s(this)}};a.style="dvn-rich-editor-overlay-menu{display:block;-webkit-transition:width 0.3s linear;transition:width 0.3s linear}dvn-rich-editor-overlay-menu .menu-container{position:absolute;display:-ms-flexbox;display:flex;-ms-flex-pack:center;justify-content:center;-ms-flex-align:start;align-items:flex-start;outline:none}dvn-rich-editor-overlay-menu .menu-container.has-animation{-webkit-animation:rich-editor-overlay-menu-appear-animation 0.3s 0s both;animation:rich-editor-overlay-menu-appear-animation 0.3s 0s both}@-webkit-keyframes rich-editor-overlay-menu-appear-animation{0%{opacity:0;margin-top:8px}100%{opacity:1;margin-top:0}}@keyframes rich-editor-overlay-menu-appear-animation{0%{opacity:0;margin-top:8px}100%{opacity:1;margin-top:0}}";export{a as dvn_rich_editor_overlay_menu}