/* esm.sh - @milkdown/plugin-slash@7.22.3 */
import{Plugin as u,PluginKey as f,TextSelection as p}from"../../../prose@7.22.3/X-ZHByb3NlbWlycm9yLW1vZGVsQDEuMjUuMTI/es2022/state.mjs";import{$ctx as g,$prose as y}from"../../../utils@7.22.3/X-ZEBtaWxrZG93bi9jb3JlQDcuMjIuMyxAbWlsa2Rvd24vY3R4QDcuMjIuMyxAbWlsa2Rvd24vcHJvc2VANy4yMi4zLHByb3NlbWlycm9yLW1vZGVsQDEuMjUuMTI/es2022/utils.mjs";import{computePosition as S,flip as k,offset as x}from"../../../../@floating-ui/dom@^1.5.1?target=es2022";import{findParentNode as $,posToDOMRect as w}from"../../../prose@7.22.3/X-ZHByb3NlbWlycm9yLW1vZGVsQDEuMjUuMTI/es2022/prose.mjs";import{debounce as P}from"../../../../lodash-es@^4.17.21?target=es2022";function B(s){let t=g({},`${s}_SLASH_SPEC`),e=y(i=>{let o=i.get(t.key);return new u({key:new f(`${s}_SLASH`),...o})}),n=[t,e];return n.key=t.key,n.pluginKey=e.key,t.meta={package:"@milkdown/plugin-slash",displayName:`Ctx<slashSpec>|${s}`},e.meta={package:"@milkdown/plugin-slash",displayName:`Prose<slash>|${s}`},n}var M=class{#e;#n;#o;#i;#a;#t;#h;#s;#r;constructor(s){this.#e=!1,this.onShow=()=>{},this.onHide=()=>{},this.#c=(t,e)=>{let{state:n,composing:i}=t,{selection:o,doc:r}=n,{ranges:h}=o,c=Math.min(...h.map(a=>a.$from.pos)),l=Math.max(...h.map(a=>a.$to.pos)),m=e&&e.doc.eq(r)&&e.selection.eq(o);if(this.#e||((this.#i??t.dom.parentElement??document.body).appendChild(this.element),this.#e=!0),!(i||m)){if(!this.#h(t,e)){this.hide();return}S({getBoundingClientRect:()=>w(t,c,l)},this.element,{placement:"bottom-start",middleware:[k(),x(this.#r),...this.#n],...this.#o}).then(({x:a,y:d})=>{Object.assign(this.element.style,{left:`${a}px`,top:`${d}px`})}).catch(console.error),this.show()}},this.#l=t=>{let e=this.getContent(t);if(!e)return!1;let n=e.at(-1);return n?Array.isArray(this.#t)?this.#t.includes(n):this.#t===n:!1},this.update=(t,e)=>{this.#s(t,e)},this.getContent=(t,e=n=>n.type.name==="paragraph")=>{let{selection:n}=t.state,{empty:i,$from:o}=n,r=t.state.selection instanceof p;if(typeof document>"u")return;let h=this.element.contains(document.activeElement),c=!t.hasFocus()&&!h,l=!t.editable,m=!$(e)(t.state.selection);if(!(c||l||!i||!r||m))return o.parent.textBetween(Math.max(0,o.parentOffset-500),o.parentOffset,void 0,"\uFFFC")},this.destroy=()=>{this.#s.cancel()},this.show=()=>{this.element.dataset.show="true",this.onShow()},this.hide=()=>{this.element.dataset.show="false",this.onHide()},this.element=s.content,this.#a=s.debounce??200,this.#h=s.shouldShow??this.#l,this.#t=s.trigger??"/",this.#r=s.offset,this.#n=s.middleware??[],this.#o=s.floatingUIOptions??{},this.#i=s.root,this.#s=P(this.#c,this.#a)}#c;#l};export{M as SlashProvider,B as slashFactory};
//# sourceMappingURL=plugin-slash.mjs.map