diff_match_patch.prototype.fcn_prettyHtml=function(t){for(var e=[],i=/&/g,n=//g,s=/\n/g,l=0;l");switch(a){case 1:e[l]=`${r}`;break;case-1:e[l]=`${r}`;break;case 0:e[l]=`${r}`}}return e.join("")},application.register("fictioneer-suggestion",class extends Stimulus.Controller{modal=_$$$("suggestions-modal");floatingButton=_$$$("selection-tools");input=_$$$("suggestions-modal-input");current=_$$$("suggestions-modal-original");diff=_$$$("suggestions-modal-diff");reset=_$$$("button-suggestion-reset");submit=_$$$("button-suggestion-submit");original="";text="";open=!1;paragraph=null;dmp=new diff_match_patch;initialize(){this.floatingButton&&this.floatingButton.addEventListener("click",(t=>{this.toggleModalViaSelection(t.currentTarget)})),this.input.addEventListener("input",(()=>this.#t())),this.reset.addEventListener("click",(()=>this.#e())),this.submit.addEventListener("click",(()=>this.#i()))}connect(){window.FictioneerApp.Controllers.fictioneerSuggestion=this}clickOutside(){this.open&&this.#n()}toggleModalViaSelection(t){this.paragraph=this.#o(),this.toggleModalVisibility(t)}toggleModalViaParagraph(t){this.paragraph=_$(".selected-paragraph"),this.text=FcnUtils.extractTextNodes(this.paragraph),this.toggleModalVisibility(t.currentTarget)}toggleModalVisibility(t){const e=fcn(),i=window.FictioneerApp.Controllers.fictioneerChapter;e?i?(e.toggleModalVisibility(t,"suggestions-modal"),i.closeTools(),this.#s(),this.original=this.text,this.current.innerText=this.text,this.diff.innerText=this.text,this.input.value=this.text,this.input.focus()):fcn_showNotification("Error: Chapter Controller not connected.",3,"warning"):fcn_showNotification("Error: Fictioneer Controller not connected.",3,"warning")}toggleFloatingButton(){FcnGlobals.eSite.classList.contains("transformed-site")||window.getSelection().rangeCount<1||!window.getSelection().getRangeAt(0).startContainer.parentNode.closest(".content-section")||setTimeout((()=>{if(this.text=window.getSelection().toString().replaceAll("\n\n","\n").trim(),""!==this.text){const t=this.#l();this.#a(t.x,t.y)}else this.#n()}),10)}closeModal(){this.open=!1,this.original="",this.text="",this.paragraph=null,fcn().closeModals()}#a(t,e){this.open=!0;const i=document.documentElement.offsetWidth/2+this.floatingButton.offsetWidth,n=_$$$("wpadminbar")?.offsetHeight??0;this.floatingButton.style.transform=t>i?"translate(-100%)":"translate(0)",this.floatingButton.style.top=e+4-n+"px",this.floatingButton.style.left=`${t}px`,this.floatingButton.classList.remove("invisible")}#n(){this.open=!1,this.floatingButton.style.top="0",this.floatingButton.style.left="-1000px",this.floatingButton.classList.add("invisible")}#o(){const t=window.getSelection();return t.rangeCount?t.getRangeAt(0).startContainer.parentNode.closest("p"):null}#l(){let t=0,e=0;if(void 0!==window.getSelection){const i=window.getSelection();if(0!==i.rangeCount){let n=i.getRangeAt(0).cloneRange().getClientRects();n=n[n.length-1],n&&(t=n.right+window.scrollX,e=n.bottom+window.scrollY)}}return{x:t,y:e}}#s(){window.getSelection&&(window.getSelection().empty?window.getSelection().empty():window.getSelection().removeAllRanges&&window.getSelection().removeAllRanges())}#t(){this.diff.innerHTML=this.#r(this.original,this.input.value)}#e(){this.input.value=this.original,this.diff.innerText=this.original}#r(t,e){const i=this.dmp.diff_main(t,e);return this.dmp.diff_cleanupEfficiency(i),this.dmp.fcn_prettyHtml(i)}#i(){const t=this.paragraph?.id??null;let e=this.diff.innerHTML;[["ΒΆ","¶\n"],["
","\n"],["","[ins]"],["","[/ins]"],["","[del]"],["","[/del]"]].forEach((([t,i])=>{e=e.replaceAll(t,i)})),t&&(e=`${e} [anchor]${t}[/anchor]`),FcnUtils.appendToComment(`\n[quote]${e}[/quote]\n`),this.closeModal(),fcn_showNotification(fictioneer_tl.notification.suggestionAppendedToComment)}});