import{r as e,h as t,H as i,a as n}from"./p-bace3d90.js";const o=class{constructor(t){e(this,t),this.coordinates=null,this.node=null,this.container=null}componentDidLoad(){this.setupEventListener()}setupEventListener(){document.addEventListener("selectionchange",(()=>{console.log(document.getSelection().toString())}))}saveSelection(){if(window.getSelection){const e=window.getSelection();if(e.getRangeAt&&e.rangeCount)return e.getRangeAt(0)}return null}restoreSelection(e){if(e&&window.getSelection){const t=window.getSelection();t.removeAllRanges(),t.addRange(e)}}onMouseup(e){if("menu"!==e.path[1].id)if(e.composedPath().includes(document.querySelector("route-editor"))){this.coordinates={x:e.clientX,y:e.clientY};const t=document.getSelection(),i=t.getRangeAt(0),n=t.focusNode.parentNode;if(n&&(this.container=n),t.toString().length>0){const e=document.createElement("corejam-type");e.innerHTML=t.toString().trim(),i.surroundContents(e),this.node=e}}else this.coordinates=null,this.node=null,this.container=null}renderMenu(){if(this.coordinates&&this.node)return t("div",{id:"menu",style:{position:"fixed",zIndex:"100",top:this.coordinates.y+10+"px",left:this.coordinates.x+"px",padding:"10px",background:"#000",color:"#fff"}},t("span",{onClick:()=>this.node.weight="bold"},"Bold "),t("span",{style:{userSelect:"none"},onClick:e=>{e.preventDefault();const t=this.saveSelection();this.node.decoration="underline",this.restoreSelection(t)}},"Underline"," "),t("span",{onClick:()=>this.node.fontStyle="italic"},"Italic "),t("span",{onClick:()=>{const e=window.prompt("color");this.node.color=e}},"Color"))}render(){return t(i,null,this.renderMenu(),t("corejam-box",{style:{outline:"none"},spellcheck:!1},t("corejam-box",{p:12,contentEditable:"true"},"Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sapiente officiis officia sequi obcaecati voluptatibus at repellendus numquam expedita tenetur delectus ratione iure eius explicabo et magni quaerat nam, placeat temporibus."),t("corejam-type",{contentEditable:"true"},"lorem")))}get el(){return n(this)}};export{o as route_editor}