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