import{a as e}from"./eJNbcV2s.js";var t=180;function n(n){let r=n.debounceMs??t;return e.define(e=>{let t=null,i=null,a=null,o=null;function s(){if(t)return t;let r=document.createElement(`button`);return r.type=`button`,r.className=`sg-comment-selection-btn`,r.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="14" height="14" fill="currentColor" aria-hidden="true"><path d="M17.74 30 16 29l4-7h6a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h9v2H6a4 4 0 0 1-4-4V8a4 4 0 0 1 4-4h20a4 4 0 0 1 4 4v12a4 4 0 0 1-4 4h-4.84Z"/></svg><span>Comment</span>`,r.setAttribute(`aria-label`,`Add comment to selection`),r.style.position=`absolute`,r.style.zIndex=`40`,r.style.visibility=`hidden`,r.addEventListener(`mousedown`,t=>{t.preventDefault();let r=e.state.selection.main,i=r.empty?a:{from:r.from,to:r.to};i&&n.onCommentRequested(i),o=i,c()}),e.scrollDOM.appendChild(r),t=r,r}function c(){t&&(t.style.visibility=`hidden`),a=null}function l(t,n){let r=e.coordsAtPos(n);if(!r)return;let i=e.scrollDOM.getBoundingClientRect(),o=s();o.style.visibility=`visible`;let c=r.bottom-i.top+e.scrollDOM.scrollTop+6,l=Math.max(8,r.left-i.left+e.scrollDOM.scrollLeft);o.style.top=`${c}px`,o.style.left=`${l}px`,a={from:t,to:n}}function u(t){if(i&&clearTimeout(i),t.state.selection.main.empty){c(),o=null;return}i=setTimeout(()=>{i=null;let t=e.state.selection.main;if(t.empty){c(),o=null;return}o&&t.from===o.from&&t.to===o.to||(o=null,l(t.from,t.to))},r)}return{update(e){(e.selectionSet||e.docChanged||e.viewportChanged||e.geometryChanged)&&u(e)},destroy(){i&&clearTimeout(i),t?.remove(),t=null}}})}export{n as commentSelectionPopup};