"use strict";var m=Object.defineProperty;var g=(i,t,e)=>t in i?m(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var h=(i,t,e)=>(g(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("../core/emitter.js"),r=require("./base.js"),L=require("../core/selection.js"),f=require("../ui/icons.js"),E=require("../core/quill.js"),x=require("../../../../lodash-es@4.17.21/node_modules/lodash-es/merge.js"),T=[["bold","italic","link"],[{header:1},{header:2},"blockquote"]];class c extends r.BaseTooltip{constructor(t,e){super(t,e),this.quill.on(n.default.events.EDITOR_CHANGE,(s,l,S,p)=>{if(s===n.default.events.SELECTION_CHANGE)if(l!=null&&l.length>0&&p===n.default.sources.USER){this.show(),this.root.style.left="0px",this.root.style.width="",this.root.style.width=`${this.root.offsetWidth}px`;const u=this.quill.getLines(l.index,l.length);if(u.length===1){const o=this.quill.getBounds(l);o!=null&&this.position(o)}else{const o=u[u.length-1],d=this.quill.getIndex(o),b=Math.min(o.length()-1,l.index+l.length-d),a=this.quill.getBounds(new L.Range(d,b));a!=null&&this.position(a)}}else document.activeElement!==this.textbox&&this.quill.hasFocus()&&this.hide()})}listen(){super.listen(),this.root.querySelector(".ql-close").addEventListener("click",()=>{this.root.classList.remove("ql-editing")}),this.quill.on(n.default.events.SCROLL_OPTIMIZE,()=>{setTimeout(()=>{if(this.root.classList.contains("ql-hidden"))return;const t=this.quill.getSelection();if(t!=null){const e=this.quill.getBounds(t);e!=null&&this.position(e)}},1)})}cancel(){this.show()}position(t){const e=super.position(t),s=this.root.querySelector(".ql-tooltip-arrow");return s.style.marginLeft="",e!==0&&(s.style.marginLeft=`${-1*e-s.offsetWidth/2}px`),e}}h(c,"TEMPLATE",['<span class="ql-tooltip-arrow"></span>','<div class="ql-tooltip-editor">','<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">','<a class="ql-close"></a>',"</div>"].join(""));class q extends r.default{constructor(t,e){e.modules.toolbar!=null&&e.modules.toolbar.container==null&&(e.modules.toolbar.container=T),super(t,e),this.quill.container.classList.add("ql-bubble")}extendToolbar(t){this.tooltip=new c(this.quill,this.options.bounds),t.container!=null&&(this.tooltip.root.appendChild(t.container),this.buildButtons(t.container.querySelectorAll("button"),f.default),this.buildPickers(t.container.querySelectorAll("select"),f.default))}}q.DEFAULTS=x.default({},r.default.DEFAULTS,{modules:{toolbar:{handlers:{link(i){i?this.quill.theme.tooltip.edit():this.quill.format("link",!1,E.default.sources.USER)}}}}});exports.BubbleTooltip=c;exports.default=q;
