"use strict";var m=Object.defineProperty;var g=(l,t,e)=>t in l?m(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var n=(l,t,e)=>(g(l,typeof t!="symbol"?t+"":t,e),e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("../core/emitter.js"),r=require("./base.js"),d=require("../formats/link.js"),p=require("../core/selection.js"),c=require("../ui/icons.js"),v=require("../core/quill.js"),S=require("../../../../lodash-es@4.17.21/node_modules/lodash-es/merge.js"),b=[[{header:["1","2","3",!1]}],["bold","italic","underline","link"],[{list:"ordered"},{list:"bullet"}],["clean"]];class h extends r.BaseTooltip{constructor(){super(...arguments);n(this,"preview",this.root.querySelector("a.ql-preview"))}listen(){super.listen(),this.root.querySelector("a.ql-action").addEventListener("click",e=>{this.root.classList.contains("ql-editing")?this.save():this.edit("link",this.preview.textContent),e.preventDefault()}),this.root.querySelector("a.ql-remove").addEventListener("click",e=>{if(this.linkRange!=null){const i=this.linkRange;this.restoreFocus(),this.quill.formatText(i,"link",!1,o.default.sources.USER),delete this.linkRange}e.preventDefault(),this.hide()}),this.quill.on(o.default.events.SELECTION_CHANGE,(e,i,q)=>{if(e!=null){if(e.length===0&&q===o.default.sources.USER){const[s,k]=this.quill.scroll.descendant(d.default,e.index);if(s!=null){this.linkRange=new p.Range(e.index-k,s.length());const a=d.default.formats(s.domNode);this.preview.textContent=a,this.preview.setAttribute("href",a),this.show();const u=this.quill.getBounds(this.linkRange);u!=null&&this.position(u);return}}else delete this.linkRange;this.hide()}})}show(){super.show(),this.root.removeAttribute("data-mode")}}n(h,"TEMPLATE",['<a class="ql-preview" rel="noopener noreferrer" target="_blank" href="about:blank"></a>','<input type="text" data-formula="e=mc^2" data-link="https://quilljs.com" data-video="Embed URL">','<a class="ql-action"></a>','<a class="ql-remove"></a>'].join(""));class f extends r.default{constructor(t,e){e.modules.toolbar!=null&&e.modules.toolbar.container==null&&(e.modules.toolbar.container=b),super(t,e),this.quill.container.classList.add("ql-snow")}extendToolbar(t){t.container!=null&&(t.container.classList.add("ql-snow"),this.buildButtons(t.container.querySelectorAll("button"),c.default),this.buildPickers(t.container.querySelectorAll("select"),c.default),this.tooltip=new h(this.quill,this.options.bounds),t.container.querySelector(".ql-link")&&this.quill.keyboard.addBinding({key:"k",shortKey:!0},(e,i)=>{t.handlers.link.call(t,!i.format.link)}))}}f.DEFAULTS=S.default({},r.default.DEFAULTS,{modules:{toolbar:{handlers:{link(l){if(l){const t=this.quill.getSelection();if(t==null||t.length===0)return;let e=this.quill.getText(t);/^\S+@\S+\.\S+$/.test(e)&&e.indexOf("mailto:")!==0&&(e=`mailto:${e}`);const{tooltip:i}=this.quill.theme;i.edit("link",e)}else this.quill.format("link",!1,v.default.sources.USER)}}}}});exports.default=f;
