import{r as t,c as i,h as s,H as o}from"./p-1ea36ff3.js";let n=class{constructor(s){t(this,s),this.change=i(this,"change",7),this.enterKeyDown=i(this,"enterKeyDown",7),this.lastBackspaceKeyDown=i(this,"lastBackspaceKeyDown",7),this.arrowDown=i(this,"arrowDown",7),this.arrowUp=i(this,"arrowUp",7),this.isContentCleared=!1,this.lastCursorPosition=0,this.retainPosition=t=>{this.lastCursorPosition=function(t){let i=0;const s=t.ownerDocument||t.document,o=s.defaultView||s.parentWindow;let n;if(void 0!==o.getSelection){if(n=o.getSelection(),n.rangeCount>0){const s=o.getSelection().getRangeAt(0),n=s.cloneRange();n.selectNodeContents(t),n.setEnd(s.endContainer,s.endOffset),i=n.toString().length}}else if((n=s.selection)&&"Control"!=n.type){const o=n.createRange(),e=s.body.createTextRange();e.moveToElementText(t),e.setEndPoint("EndToEnd",o),i=e.text.length}return i}(t.target)}}componentShouldUpdate(t){return this.input.innerHTML!==t.text}async focusOnInput(){this.input.focus(),function(t,i){if(t.focus(),void 0!==window.getSelection&&void 0!==document.createRange){const s=document.createRange();s.selectNodeContents(t),0!==i&&s.setStart(t.childNodes[0],i),s.collapse(!0);const o=window.getSelection();o.removeAllRanges(),o.addRange(s)}else if(void 0!==document.body.createTextRange){const i=document.body.createTextRange();i.moveToElementText(t),i.collapse(!1),i.select()}}(this.input,this.lastCursorPosition)}render(){const t=this.type||"h1";return s(o,null,s(t,{ref:t=>this.input=t,id:`${t}-${this.id}`,key:`${t}-${this.id}`,contenteditable:!0,onInput:t=>{this.retainPosition(t);const i=t.target.innerHTML;this.change.emit({id:this.id,value:{text:i}}),0===i.length&&setTimeout((()=>this.isContentCleared=!0),100)},onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),this.enterKeyDown.emit(t)):"Backspace"===t.key&&this.isContentCleared?this.lastBackspaceKeyDown.emit(t):"ArrowDown"===t.key?this.value.text.length===window.getSelection().getRangeAt(0).endOffset&&this.arrowDown.emit(t):"ArrowUp"===t.key&&0===window.getSelection().getRangeAt(0).endOffset&&this.arrowUp.emit(t)}},this.value.text))}};n.style="dvn-rich-editor-heading-block{display:block;-ms-flex:1;flex:1}dvn-rich-editor-heading-block h1{font-size:2rem;margin:0;display:block}dvn-rich-editor-heading-block h2{font-size:1.6rem;margin:0;display:block}dvn-rich-editor-heading-block h3{font-size:1.2rem;margin:0;display:block}";export{n as dvn_rich_editor_heading_block}