import{Kt as e}from"./xY0c-UfG.js";import{i as t,t as n}from"./C04V7v3Y.js";import{p as r}from"./XcWejFm_.js";import{a as i}from"./C1trcC8M.js";var a=e({commentSelectionPopup:()=>l,requestCommentEffect:()=>o}),o=r.define(),s=180;function c(e,t,n){let r=e.state.doc.sliceString(t,n).trim();if(!r)return null;let i=/^!\[[^\]]*\]\([^)]*\)$/.test(r),a=/^\[[^\]]*\]\([^)]*\/api\/assets\/[^)]*\)$/.test(r);return i||a?t:null}function l(e){let r=e.debounceMs??s;return i.define(i=>{let a=null,s=null,l=null,u=null,d=null,f=null,p=null;function m(){if(a)return a;let e=document.createElement(`div`);e.className=`sg-selection-bar`,e.style.position=`absolute`,e.style.zIndex=`40`,e.style.visibility=`hidden`;let n=document.createElement(`button`);n.type=`button`,n.className=`sg-selection-bar-btn sg-embed-source-btn`,n.innerHTML=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="16" height="16" fill="currentColor" aria-hidden="true"><path d="M31 16 24 23 22.59 21.59 28.17 16 22.59 10.41 24 9 31 16z"/><path d="M1 16 8 9 9.41 10.41 3.83 16 9.41 21.59 8 23 1 16z"/><path d="M5.91 15H26.08V17H5.91z" transform="rotate(-75 15.996 16)"/></svg>`,n.setAttribute(`aria-label`,`Show markdown source`),n.style.display=`none`,n.addEventListener(`mousedown`,e=>{e.preventDefault(),e.stopPropagation(),f!=null&&(i.dispatch({effects:t.of(f)}),i.focus(),h())}),s=n;let r=document.createElement(`span`);r.className=`sg-selection-bar-sep`,r.style.display=`none`,l=r;let o=document.createElement(`button`);return o.type=`button`,o.className=`sg-selection-bar-btn`,o.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>`,o.setAttribute(`aria-label`,`Add comment to selection`),o.addEventListener(`mousedown`,e=>{e.preventDefault(),g()}),e.append(n,r,o),i.scrollDOM.appendChild(e),a=e,e}function h(){if(!s)return;let e=f!=null;if(s.style.display=e?``:`none`,l&&(l.style.display=e?``:`none`),!e)return;let t=!!i.state.field(n,!1)?.has(f);s.classList.toggle(`is-active`,t),s.title=t?`Hide markdown`:`Show markdown`}function g(){let t=i.state.selection.main,n=t.empty?d:{from:t.from,to:t.to};n&&e.onCommentRequested(n),p=n,_()}function _(){a&&(a.style.visibility=`hidden`),d=null,f=null}function v(e,t){f=c(i,e,t);let n,r,a=f==null?null:i.contentDOM.querySelector(`.cm-embed-selected, .cm-image-selected`);if(a){let e=a.getBoundingClientRect();n=e.right,r=e.bottom}else{let e=i.coordsAtPos(t,-1);if(!e)return;n=e.left,r=e.bottom}let o=i.scrollDOM.getBoundingClientRect(),s=m();h(),s.style.visibility=`visible`;let l=r-o.top+i.scrollDOM.scrollTop+6,u=i.contentDOM.getBoundingClientRect(),p=s.offsetWidth||32,g=i.scrollDOM.scrollLeft-o.left,_=u.left+g+8,v=u.right+g-p-8,y=n+g,b=Math.max(_,Math.min(y,v));s.style.top=`${l}px`,s.style.left=`${b}px`,d={from:e,to:t}}function y(e){if(u&&clearTimeout(u),e.state.selection.main.empty){_(),p=null;return}u=setTimeout(()=>{u=null;let e=i.state.selection.main;if(e.empty){_(),p=null;return}p&&e.from===p.from&&e.to===p.to||(p=null,v(e.from,e.to))},r)}return{update(e){if(e.transactions.some(e=>e.effects.some(e=>e.is(o)))){g();return}if(e.transactions.some(e=>e.effects.some(e=>e.is(t)))&&a&&a.style.visibility===`visible`&&h(),a&&a.style.visibility===`visible`&&e.geometryChanged&&!e.selectionSet&&!e.docChanged){let e=i.state.selection.main;if(!e.empty){v(e.from,e.to);return}}(e.selectionSet||e.docChanged||e.viewportChanged||e.geometryChanged)&&y(e)},destroy(){u&&clearTimeout(u),a?.remove(),a=null,s=null,l=null}}})}export{o as n,a as t};