diff --git a/index.umd.js b/index.umd.js index 875ab75..c3cafe7 100644 --- a/index.umd.js +++ b/index.umd.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("quill")):"function"==typeof define&&define.amd?define(["exports","quill"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TableUp={},t.Quill)}(this,(function(t,e){"use strict";const s={container:"table-up-container",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableBody:"table-up-body",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},o={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:"100",rowMinHeightPx:36},i={AFTER_TABLE_RESIZE:"after-table-resize"},n=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],l=(t,e="table-up")=>{const s=e?`${e}-`:"";return{b:()=>`${s}${t}`,be:e=>e?`${s}${t}__${e}`:"",bm:e=>e?`${s}${t}--${e}`:"",bem:(e,o)=>e&&o?`${s}${t}__${e}--${o}`:"",ns:t=>t?`${s}${t}`:"",bs:e=>e?`${s}${t}-${e}`:"",cv:t=>t?`--${s}${t}`:"",is:t=>`is-${t}`}},r=t=>"function"==typeof t,a=Array.isArray,c=t=>"string"==typeof t,d=t=>{const{type:e="default",content:s}=t||{},o=l("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(c(s)?i.textContent=s:i.appendChild(s)),i},h=function(t,e){return t=Math.min(e,Math.max(0,Number.parseFloat(`${t}`))),Math.abs(t-e)<1e-6?1:t%e/Number.parseFloat(e)},u=t=>({h:Math.min(360,Math.max(0,t.h)),s:Math.min(100,Math.max(0,t.s)),b:Math.min(100,Math.max(0,t.b)),a:Math.min(1,Math.max(0,t.a))}),p=t=>{let{r:e,g:s,b:o,a:i}=t;e=h(e,255),s=h(s,255),o=h(o,255);const n=Math.max(e,s,o),l=Math.min(e,s,o);let r;const a=n,c=n-l,d=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(s-o)/c+(s{let{h:e,s:s,b:o,a:i}=t;e=6*h(e,360),s=h(s,100),o=h(o,100);const n=Math.floor(e),l=e-n,r=o*(1-s),a=o*(1-l*s),c=o*(1-(1-l)*s),d=n%6,u=[o,a,r,r,c,o][d],p=[c,o,o,a,r,r][d],b=[r,r,c,o,o,a][d];return{r:Math.round(255*u),g:Math.round(255*p),b:Math.round(255*b),a:i}},m=t=>{const e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(const t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")},f=t=>m(b(t)),g=(t={})=>{const e=230,s=150,o=10;let i=p((n=(n=t.color||"#ff0000").startsWith("#")?n.slice(1):n,{r:Number.parseInt(n.slice(0,2),16),g:Number.parseInt(n.slice(2,4),16),b:Number.parseInt(n.slice(4,6),16),a:Number((Number.parseInt(n.slice(6,8)||"ff",16)/255).toFixed(2))}));var n;const r=l("color-picker"),a=document.createElement("div");a.classList.add(r.b());const c=document.createElement("div");c.classList.add(r.be("content"));const d=document.createElement("div");d.classList.add(r.be("selector"));const h=document.createElement("div");h.classList.add(r.be("background")),d.appendChild(h);const g=document.createElement("div");g.classList.add(r.be("background-handle")),h.appendChild(g);const w=document.createElement("div");w.classList.add(r.be("alpha"));const v=document.createElement("div");v.classList.add(r.be("alpha-bg"));const x=document.createElement("div");x.classList.add(r.be("alpha-handle")),w.appendChild(v),w.appendChild(x);const C=document.createElement("div");C.classList.add(r.be("hue"));const y=document.createElement("div");y.classList.add(r.be("hue-handle")),C.appendChild(y);const M=document.createElement("div");M.classList.add(r.be("action"));const[I,L,N,E]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(r.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(r.be("input")),o.addEventListener("input",(()=>{o.value=o.value.replaceAll(/[^0-9]/g,"")})),o.addEventListener("change",(()=>{let e=Math.round(Number(o.value));"a"===t&&(e/=100);z(u(p(Object.assign({},b(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));c.appendChild(C),c.appendChild(d),c.appendChild(w),a.appendChild(c),a.appendChild(M);let S=!1,T=!1,R=!1;function B(){const t=f(i);for(const[e,s]of[I,L,N].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));E.value=String((100*i.a).toFixed(0))}function k(){Object.assign(g.style,{left:`${Math.floor(e*i.s/100)}px`,top:`${Math.floor(s*(100-i.b)/100)}px`}),d.style.backgroundColor=`#${m(b({h:i.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*i.h/360)}px`,x.style.left=100*i.a+"%",function(){const{r:t,g:e,b:s}=b(i);v.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),B()}function z(e){i=u(Object.assign({},i,e)),B(),t.onChange&&t.onChange(`#${f(i)}`)}function O(t){const o=d.getBoundingClientRect(),i=o.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=o.left+document.body.scrollLeft;z({s:Math.floor(100*Math.max(0,Math.min(e,t.pageX-n))/e),b:Math.floor(100*(s-Math.max(0,Math.min(s,t.pageY-i)))/s)}),k()}function A(t){const e=C.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);z({h:Math.floor(360*(s-Math.max(0,Math.min(s,t.pageY-e)))/s)}),k()}function $(t){const{pageX:e}=t,s=w.getBoundingClientRect();let i=e-s.left;i=Math.max(o/2,i),i=Math.min(i,s.width-o/2),z({a:Math.round((i-5)/(s.width-10)*100)/100}),k()}function q(t){S&&(t.preventDefault(),O(t)),T&&(t.preventDefault(),A(t)),R&&(t.preventDefault(),$(t))}function W(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",W),S=!1}function H(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",H),T=!1}function D(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",D),R=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",W),S=!0,O(t)})),C.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",H),T=!0,A(t)})),w.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",D),R=!0,$(t)})),k(),a};let w=8e3;const v=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const o=l("dialog"),i=e,n=document.createElement("div");n.classList.add(o.b()),n.style.zIndex=String(w);const r=document.createElement("div");if(r.classList.add(o.be("overlay")),n.appendChild(r),t){const e=document.createElement("div");e.classList.add(o.be("content")),e.appendChild(t),r.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const a=getComputedStyle(i).overflow;i.style.overflow="hidden",i.appendChild(n);const c=()=>{s(),n.remove(),i.style.overflow=a};return n.addEventListener("click",c),w+=1,{dialog:n,close:c}},x=(t,e)=>{const s=l("input");e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,o.appendChild(e)}const i=document.createElement("div");i.classList.add(s.be("input"));const n=document.createElement("input");for(const t in e)n.setAttribute(t,e[t]);(e.max||e.min)&&n.addEventListener("blur",(()=>{e.max&&e.max<=Number(n.value)&&(n.value=String(e.max)),e.min&&e.min>=Number(n.value)&&(n.value=String(e.min))})),i.appendChild(n),o.appendChild(i),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:n,errorTip:t=>{let e;i.classList.contains("error")?e=i.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),i.appendChild(e)),e.textContent=t,i.classList.add("error");return{removeError:()=>{i.classList.remove("error"),e.remove()}}}}},C=(t={})=>{const e=l("select-box"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("block"));for(let s=0;s<(t.row||8);s++)for(let i=0;i<(t.col||8);i++){const t=document.createElement("div");t.classList.add(e.be("item")),t.dataset.row=String(s+1),t.dataset.col=String(i+1),o.appendChild(t)}const i=()=>{const{row:t,col:e}=s.dataset;for(const t of Array.from(o.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;const i=Array.from(o.children);for(let s=0;st&&n>e)return;o<=t&&n<=e?i[s].classList.add("active"):i[s].classList.remove("active")}};if(o.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:e,col:o}=t.target.dataset;e&&o&&(s.dataset.row=e,s.dataset.col=o,i())})),o.addEventListener("mouseleave",(()=>{s.removeAttribute("data-row"),s.removeAttribute("data-col"),i()})),o.addEventListener("click",(()=>{const{row:e,col:o}=s.dataset;e&&o&&t.onSelect&&t.onSelect(Number(e),Number(o))})),s.appendChild(o),t.customBtn){const o=t.texts||{},i=document.createElement("div");i.classList.add(e.be("custom")),i.textContent=o.customBtnText||"Custom",i.addEventListener("click",(async()=>{const e=await(async(t={})=>{const e=l("creator"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("input"));const{item:i,input:n,errorTip:r}=x(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:c,errorTip:h}=x(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(a),s.appendChild(o);const u=document.createElement("div");u.classList.add(e.be("control"));const p=d({type:"confirm",content:t.confirmText||"Confirm"}),b=d({type:"default",content:t.cancelText||"Cancel"});u.appendChild(p),u.appendChild(b),s.appendChild(u);const m=(e=Number(n.value),s=Number(c.value))=>{if(Number.isNaN(e)||e<=0)r(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(s)||s<=0))return{row:e,col:s};h(t.notPositiveNumberError||"Please enter a positive integer")}},f=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",f))};return new Promise(((t,e)=>{const{close:o}=v({child:s,beforeClose:e});n.focus();for(const e of[n,c])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=m();e&&(t(e),o())}}));p.addEventListener("click",(async()=>{const e=m();e&&(t(e),o())})),document.addEventListener("keydown",f),b.addEventListener("click",o)}))})(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s},y=Math.min,M=Math.max,I=Math.round,L=Math.floor,N=t=>({x:t,y:t}),E={left:"right",right:"left",bottom:"top",top:"bottom"},S={start:"end",end:"start"};function T(t,e,s){return M(t,y(e,s))}function R(t,e){return"function"==typeof t?t(e):t}function B(t){return t.split("-")[0]}function k(t){return t.split("-")[1]}function z(t){return"x"===t?"y":"x"}function O(t){return"y"===t?"height":"width"}function A(t){return["top","bottom"].includes(B(t))?"y":"x"}function $(t){return z(A(t))}function q(t){return t.replace(/start|end/g,(t=>S[t]))}function W(t){return t.replace(/left|right|bottom|top/g,(t=>E[t]))}function H(t){const{x:e,y:s,width:o,height:i}=t;return{width:o,height:i,top:s,left:e,right:e+o,bottom:s+i,x:e,y:s}}function D(t,e,s){let{reference:o,floating:i}=t;const n=A(e),l=$(e),r=O(l),a=B(e),c="y"===n,d=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,u=o[r]/2-i[r]/2;let p;switch(a){case"top":p={x:d,y:o.y-i.height};break;case"bottom":p={x:d,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:h};break;case"left":p={x:o.x-i.width,y:h};break;default:p={x:o.x,y:o.y}}switch(k(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function F(t,e){var s;void 0===e&&(e={});const{x:o,y:i,platform:n,rects:l,elements:r,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:u=!1,padding:p=0}=R(e,t),b=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),m=r[u?"floating"===h?"reference":"floating":h],f=H(await n.getClippingRect({element:null==(s=await(null==n.isElement?void 0:n.isElement(m)))||s?m:m.contextElement||await(null==n.getDocumentElement?void 0:n.getDocumentElement(r.floating)),boundary:c,rootBoundary:d,strategy:a})),g="floating"===h?{x:o,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(null==n.getOffsetParent?void 0:n.getOffsetParent(r.floating)),v=await(null==n.isElement?void 0:n.isElement(w))&&await(null==n.getScale?void 0:n.getScale(w))||{x:1,y:1},x=H(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-x.top+b.top)/v.y,bottom:(x.bottom-f.bottom+b.bottom)/v.y,left:(f.left-x.left+b.left)/v.x,right:(x.right-f.right+b.right)/v.x}}function j(){return"undefined"!=typeof window}function P(t){return Y(t)?(t.nodeName||"").toLowerCase():"#document"}function V(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function X(t){var e;return null==(e=(Y(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function Y(t){return!!j()&&(t instanceof Node||t instanceof V(t).Node)}function _(t){return!!j()&&(t instanceof Element||t instanceof V(t).Element)}function U(t){return!!j()&&(t instanceof HTMLElement||t instanceof V(t).HTMLElement)}function K(t){return!(!j()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof V(t).ShadowRoot)}function Z(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=st(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function G(t){return["table","td","th"].includes(P(t))}function Q(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function J(t){const e=tt(),s=_(t)?st(t):t;return"none"!==s.transform||"none"!==s.perspective||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function tt(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function et(t){return["html","body","#document"].includes(P(t))}function st(t){return V(t).getComputedStyle(t)}function ot(t){return _(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function it(t){if("html"===P(t))return t;const e=t.assignedSlot||t.parentNode||K(t)&&t.host||X(t);return K(e)?e.host:e}function nt(t){const e=it(t);return et(e)?t.ownerDocument?t.ownerDocument.body:t.body:U(e)&&Z(e)?e:nt(e)}function lt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=nt(t),n=i===(null==(o=t.ownerDocument)?void 0:o.body),l=V(i);if(n){const t=rt(l);return e.concat(l,l.visualViewport||[],Z(i)?i:[],t&&s?lt(t):[])}return e.concat(i,lt(i,[],s))}function rt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function at(t){const e=st(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=U(t),n=i?t.offsetWidth:s,l=i?t.offsetHeight:o,r=I(s)!==n||I(o)!==l;return r&&(s=n,o=l),{width:s,height:o,$:r}}function ct(t){return _(t)?t:t.contextElement}function dt(t){const e=ct(t);if(!U(e))return N(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:n}=at(e);let l=(n?I(s.width):s.width)/o,r=(n?I(s.height):s.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const ht=N(0);function ut(t){const e=V(t);return tt()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:ht}function pt(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),n=ct(t);let l=N(1);e&&(o?_(o)&&(l=dt(o)):l=dt(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==V(t))&&e}(n,s,o)?ut(n):N(0);let a=(i.left+r.x)/l.x,c=(i.top+r.y)/l.y,d=i.width/l.x,h=i.height/l.y;if(n){const t=V(n),e=o&&_(o)?V(o):o;let s=t,i=rt(s);for(;i&&o&&e!==s;){const t=dt(i),e=i.getBoundingClientRect(),o=st(i),n=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x,l=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;a*=t.x,c*=t.y,d*=t.x,h*=t.y,a+=n,c+=l,s=V(i),i=rt(s)}}return H({width:d,height:h,x:a,y:c})}function bt(t,e){const s=ot(t).scrollLeft;return e?e.left+s:pt(X(t)).left+s}function mt(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:bt(t,o)),y:o.top+e.scrollTop}}function ft(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=V(t),o=X(t),i=s.visualViewport;let n=o.clientWidth,l=o.clientHeight,r=0,a=0;if(i){n=i.width,l=i.height;const t=tt();(!t||t&&"fixed"===e)&&(r=i.offsetLeft,a=i.offsetTop)}return{width:n,height:l,x:r,y:a}}(t,s);else if("document"===e)o=function(t){const e=X(t),s=ot(t),o=t.ownerDocument.body,i=M(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),n=M(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-s.scrollLeft+bt(t);const r=-s.scrollTop;return"rtl"===st(o).direction&&(l+=M(e.clientWidth,o.clientWidth)-i),{width:i,height:n,x:l,y:r}}(X(t));else if(_(e))o=function(t,e){const s=pt(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,n=U(t)?dt(t):N(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:i*n.x,y:o*n.y}}(e,s);else{const s=ut(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return H(o)}function gt(t,e){const s=it(t);return!(s===e||!_(s)||et(s))&&("fixed"===st(s).position||gt(s,e))}function wt(t,e,s){const o=U(e),i=X(e),n="fixed"===s,l=pt(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=N(0);if(o||!o&&!n)if(("body"!==P(e)||Z(i))&&(r=ot(e)),o){const t=pt(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=bt(i));const c=!i||o||n?N(0):mt(i,r);return{x:l.left+r.scrollLeft-a.x-c.x,y:l.top+r.scrollTop-a.y-c.y,width:l.width,height:l.height}}function vt(t){return"static"===st(t).position}function xt(t,e){if(!U(t)||"fixed"===st(t).position)return null;if(e)return e(t);let s=t.offsetParent;return X(t)===s&&(s=s.ownerDocument.body),s}function Ct(t,e){const s=V(t);if(Q(t))return s;if(!U(t)){let e=it(t);for(;e&&!et(e);){if(_(e)&&!vt(e))return e;e=it(e)}return s}let o=xt(t,e);for(;o&&G(o)&&vt(o);)o=xt(o,e);return o&&et(o)&&vt(o)&&!J(o)?s:o||function(t){let e=it(t);for(;U(e)&&!et(e);){if(J(e))return e;if(Q(e))return null;e=it(e)}return null}(t)||s}const yt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const n="fixed"===i,l=X(o),r=!!e&&Q(e.floating);if(o===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=N(1);const d=N(0),h=U(o);if((h||!h&&!n)&&(("body"!==P(o)||Z(l))&&(a=ot(o)),U(o))){const t=pt(o);c=dt(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!l||h||n?N(0):mt(l,a,!0);return{width:s.width*c.x,height:s.height*c.y,x:s.x*c.x-a.scrollLeft*c.x+d.x+u.x,y:s.y*c.y-a.scrollTop*c.y+d.y+u.y}},getDocumentElement:X,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const n=[..."clippingAncestors"===s?Q(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=lt(t,[],!1).filter((t=>_(t)&&"body"!==P(t))),i=null;const n="fixed"===st(t).position;let l=n?it(t):t;for(;_(l)&&!et(l);){const e=st(l),s=J(l);s||"fixed"!==e.position||(i=null),(n?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||Z(l)&&!s&>(t,l))?o=o.filter((t=>t!==l)):i=e,l=it(l)}return e.set(t,o),o}(e,this._c):[].concat(s),o],l=n[0],r=n.reduce(((t,s)=>{const o=ft(e,s,i);return t.top=M(o.top,t.top),t.right=y(o.right,t.right),t.bottom=y(o.bottom,t.bottom),t.left=M(o.left,t.left),t}),ft(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:Ct,getElementRects:async function(t){const e=this.getOffsetParent||Ct,s=this.getDimensions,o=await s(t.floating);return{reference:wt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:s}=at(t);return{width:e,height:s}},getScale:dt,isElement:_,isRTL:function(t){return"rtl"===st(t).direction}};function Mt(t,e,s,o){void 0===o&&(o={});const{ancestorScroll:i=!0,ancestorResize:n=!0,elementResize:l="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=o,c=ct(t),d=i||n?[...c?lt(c):[],...lt(e)]:[];d.forEach((t=>{i&&t.addEventListener("scroll",s,{passive:!0}),n&&t.addEventListener("resize",s)}));const h=c&&r?function(t,e){let s,o=null;const i=X(t);function n(){var t;clearTimeout(s),null==(t=o)||t.disconnect(),o=null}return function l(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),n();const{left:c,top:d,width:h,height:u}=t.getBoundingClientRect();if(r||e(),!h||!u)return;const p={rootMargin:-L(d)+"px "+-L(i.clientWidth-(c+h))+"px "+-L(i.clientHeight-(d+u))+"px "+-L(c)+"px",threshold:M(0,y(1,a))||1};let b=!0;function m(t){const e=t[0].intersectionRatio;if(e!==a){if(!b)return l();e?l(!1,e):s=setTimeout((()=>{l(!1,1e-7)}),1e3)}b=!1}try{o=new IntersectionObserver(m,{...p,root:i.ownerDocument})}catch(t){o=new IntersectionObserver(m,p)}o.observe(t)}(!0),n}(c,s):null;let u,p=-1,b=null;l&&(b=new ResizeObserver((t=>{let[o]=t;o&&o.target===c&&b&&(b.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame((()=>{var t;null==(t=b)||t.observe(e)}))),s()})),c&&!a&&b.observe(c),b.observe(e));let m=a?pt(t):null;return a&&function e(){const o=pt(t);!m||o.x===m.x&&o.y===m.y&&o.width===m.width&&o.height===m.height||s();m=o,u=requestAnimationFrame(e)}(),s(),()=>{var t;d.forEach((t=>{i&&t.removeEventListener("scroll",s),n&&t.removeEventListener("resize",s)})),null==h||h(),null==(t=b)||t.disconnect(),b=null,a&&cancelAnimationFrame(u)}}const It=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var s,o;const{x:i,y:n,placement:l,middlewareData:r}=e,a=await async function(t,e){const{placement:s,platform:o,elements:i}=t,n=await(null==o.isRTL?void 0:o.isRTL(i.floating)),l=B(s),r=k(s),a="y"===A(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=R(e,t);let{mainAxis:u,crossAxis:p,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return r&&"number"==typeof b&&(p="end"===r?-1*b:b),a?{x:p*d,y:u*c}:{x:u*c,y:p*d}}(e,t);return l===(null==(s=r.offset)?void 0:s.placement)&&null!=(o=r.arrow)&&o.alignmentOffset?{}:{x:i+a.x,y:n+a.y,data:{...a,placement:l}}}}},Lt=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:s,y:o,placement:i}=e,{mainAxis:n=!0,crossAxis:l=!1,limiter:r={fn:t=>{let{x:e,y:s}=t;return{x:e,y:s}}},...a}=R(t,e),c={x:s,y:o},d=await F(e,a),h=A(B(i)),u=z(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=T(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=T(b+d["y"===h?"top":"left"],b,b-d[t])}const m=r.fn({...e,[u]:p,[h]:b});return{...m,data:{x:m.x-s,y:m.y-o,enabled:{[u]:n,[h]:l}}}}}},Nt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var s,o;const{placement:i,middlewareData:n,rects:l,initialPlacement:r,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:u,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:m=!0,...f}=R(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=B(i),w=A(r),v=B(r)===r,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),C=u||(v||!m?[W(r)]:function(t){const e=W(t);return[q(t),e,q(e)]}(r)),y="none"!==b;!u&&y&&C.push(...function(t,e,s,o){const i=k(t);let n=function(t,e,s){const o=["left","right"],i=["right","left"],n=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return s?e?i:o:e?o:i;case"left":case"right":return e?n:l;default:return[]}}(B(t),"start"===s,o);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map(q)))),n}(r,m,b,x));const M=[r,...C],I=await F(e,f),L=[];let N=(null==(o=n.flip)?void 0:o.overflows)||[];if(d&&L.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=k(t),i=$(t),n=O(i);let l="x"===i?o===(s?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=W(l)),[l,W(l)]}(i,l,x);L.push(I[t[0]],I[t[1]])}if(N=[...N,{placement:i,overflows:L}],!L.every((t=>t<=0))){var E,S;const t=((null==(E=n.flip)?void 0:E.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:N},reset:{placement:e}};let s=null==(S=N.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:S.placement;if(!s)switch(p){case"bestFit":{var T;const t=null==(T=N.filter((t=>{if(y){const e=A(t.placement);return e===w||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:T[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},Et=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:s,y:o,placement:i,rects:n,middlewareData:l}=e,{offset:r=0,mainAxis:a=!0,crossAxis:c=!0}=R(t,e),d={x:s,y:o},h=A(i),u=z(h);let p=d[u],b=d[h];const m=R(r,e),f="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const t="y"===u?"height":"width",e=n.reference[u]-n.floating[t]+f.mainAxis,s=n.reference[u]+n.reference[t]-f.mainAxis;ps&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(B(i)),s=n.reference[h]-n.floating[t]+(e&&(null==(g=l.offset)?void 0:g[h])||0)+(e?0:f.crossAxis),o=n.reference[h]+n.reference[t]+(e?0:(null==(w=l.offset)?void 0:w[h])||0)-(e?f.crossAxis:0);bo&&(b=o)}return{[u]:p,[h]:b}}}},St=(t,e,s)=>{const o=new Map,i={platform:yt,...s},n={...i.platform,_c:o};return(async(t,e,s)=>{const{placement:o="bottom",strategy:i="absolute",middleware:n=[],platform:l}=s,r=n.filter(Boolean),a=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:h}=D(c,o,a),u=o,p={},b=0;for(let s=0;s{const{msg:s="",delay:o=150,content:i,direction:n="bottom",type:r="hover",container:a,onOpen:c,onClose:d,closed:h,onDestroy:u}=e,p=l("tooltip");if(s||i){Tt||(Tt=document.createElement("div"),document.body.appendChild(Tt));const e=a||Tt,l=document.createElement("div");let b,m,f;l.classList.add(p.b(),"hidden","transparent"),i?l.appendChild(i):s&&(l.textContent=s);const g=()=>{f&&f(),St(t,l,{placement:n,middleware:[Nt(),Lt({limiter:Et()}),It(4)]}).then((({x:t,y:e})=>{Object.assign(l.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{l.classList.add("hidden"),e.contains(l)&&e.removeChild(l),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(c){const t=c(s);if(!s&&t)return}e.appendChild(l),l.removeEventListener("transitionend",w),l.classList.remove("hidden"),f=Mt(t,l,g),l.classList.remove("transparent")}),o)},x=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}l.addEventListener("transitionend",w,{once:!0}),l.classList.add("transparent")}),o)},C=()=>{const e=t=>{t.stopPropagation(),x(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{l.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{x(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,l],s=x.bind(void 0,!1),o=v.bind(void 0,!1);return{prepare:()=>{for(const t of e)t.addEventListener("mouseenter",o),t.addEventListener("mouseleave",s)},show:v,hide:x,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",o),t.removeEventListener("mouseleave",s)}}},click:C},{prepare:M,show:I,hide:L,destroy:N}=y[r]();M();const E=()=>{L(!0),u&&u(),N(),f&&f(),l.remove()};return{show:I,hide:L,destroy:E}}return null};function Bt(t,e,s=4){const{x:o,y:i,x1:n,y1:l}=t,{x:r,y:a,x1:c,y1:d}=e;return!(n<=r+s||o+s>=c||(l<=a+s||i+s>=d))}const kt=()=>Math.random().toString(36).slice(2),zt=(t,e)=>{let s;return function(...o){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,o)}),e)}};function Ot(t,e){let s=t.parent;for(;s&&s.statics.blotName!==e&&s!==t.scroll;)s=s.parent;if(s===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return s}function At(t,e){const s=new Array(e.length),o=new Map(e.map(((t,e)=>[t,e])));let i=t.parent;for(;i&&i!==t.scroll&&0!==o.size;){if(o.has(i.statics.blotName)){s[o.get(i.statics.blotName)]=i,o.delete(i.statics.blotName)}i=i.parent}if(o.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(o.keys()).join(", ")}`);return s}function $t(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}function qt(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)$t(s.prototype,t.prototype);return s}const Wt=t=>{let{left:e,top:s,width:o,height:i}=t;const{clientWidth:n,clientHeight:l}=document.documentElement;let r=!1,a=!1;return e+o>n?(e=n-o-8,r=!0):e<0&&(e=8,r=!0),s+i>l?(s=l-i-8,a=!0):s<0&&(s=8,a=!0),{left:e,top:s,leftLimited:r,topLimited:a}};function Ht(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Dt(){for(let t=0;t0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const Yt=e.import("parchment"),_t=e.import("blots/block");class Ut extends _t{replaceWith(t,e){const o="string"==typeof t?this.scroll.create(t,e):t;if(o instanceof Yt.ParentBlot){if(o.statics.blotName===s.tableCellInner){const t=this.parent;if(t.statics.blotName===s.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),this.parent.statics.blotName===s.tableCellInner&&this.prev){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.parent.remove();const e=t.parent.parent;e.statics.blotName===s.tableRow&&0===e.children.length&&e.remove()}}else null!=t&&t.insertBefore(o,this.next),o.appendChild(this);return o}this.moveChildren(o)}return null!=this.parent&&(this.parent.insertBefore(o,this.next||void 0),this.remove()),this.attributes.copy(o),o}format(t,e){if(t!==s.tableCellInner||this.parent.statics.blotName!==t||e)super.format(t,e);else{const[t,e,o]=At(this,[s.tableCell,s.tableRow,s.tableWrapper]),i=o.next;let n=e.next,l=t.next;for(o.parent.insertBefore(this,i);l;){const t=l.next;o.parent.insertBefore(l,i),l=t}for(;n;){const t=n.next;o.parent.insertBefore(n,i),n=t}}}}const Kt=e.import("formats/blockquote");class Zt extends(qt(Kt,[Ut])){}const Gt=e.import("formats/code-block");class Qt extends(qt(Gt,[Ut])){}const Jt=e.import("formats/header");class te extends(qt(Jt,[Ut])){}const ee=e.import("formats/list");class se extends(qt(ee,[Ut])){static register(){}}const oe=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},ie=e.import("blots/block"),ne=e.import("blots/block/embed");class le extends Xt{static blotName=s.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan"]);static defaultChild=ie;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=o,r.dataset.rowspan=String(oe(i)),r.dataset.colspan=String(oe(n)),l&&(r.dataset.style=l),r}static formats(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:n,style:l}=t.dataset,r={tableId:e,rowId:s,colId:o,rowspan:Number(oe(i)),colspan:Number(oe(n))};return l&&(r.style=l),r}setFormatValue(t,e,s=!1){if(s){if(!this.statics.isAllowStyle(t))return;this.parent&&(this.parent.setFormatValue(t,e),this.domNode.dataset.style=this.parent.domNode.style.cssText)}else{if(!this.statics.allowDataAttrs.has(t))return;const s=`data-${t}`;e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s),this.parent&&this.parent.setFormatValue(t,e)}const o=this.descendants(ie,0);for(const t of o)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(t){this.setFormatValue("row-id",t)}get colId(){return this.domNode.dataset.colId}set colId(t){this.setFormatValue("col-id",t)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(t){this.setFormatValue("rowspan",t)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(t){this.setFormatValue("colspan",t)}getColumnIndex(){return Ot(this,s.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,o){0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,o)}formats(){const t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:o}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===s&&i.rowspan===o}optimize(){const t=this.parent,e=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof ne){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==s.tableCell&&(this.wrap(s.tableCell,e),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,e){if(t.statics.blotName===this.statics.blotName){const o=t,i=this.statics.formats(o.domNode),n=this.statics.formats(this.domNode);if(Object.entries(n).every((([t,e])=>e===i[t])))return this.parent.insertBefore(o,this.next);{const[t,l]=At(this,[s.tableRow,s.tableCell]);if(e){const o=e.offset();if(o+1{e.appendChild(t)})),t.insertBefore(e.wrap(s.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(e){const s=e.offset(t);t.split(s)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(s.tableRow,i),r=this.scroll.create(s.tableCell,i);return r.appendChild(o),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(o.wrap(s.tableCell,i),e?l:l.next)}}super.insertBefore(t,e)}}const re=e.import("parchment"),ae=e.import("blots/scroll");class ce extends ae{createBlock(t,e){let o,i={};if(t[s.tableCellInner])o=s.tableCellInner;else for(const[e,s]of Object.entries(t)){null!=this.query(e,re.Scope.BLOCK&re.Scope.BLOT)?o=e:i[e]=s}o===s.tableCellInner&&(i={...t},delete i[o]);const n=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(n,e||void 0);let l=n.length();n instanceof le&&0===l&&(l+=1);for(const[t,e]of Object.entries(i))n.formatAt(0,l,t,e);return n}}class de extends Xt{static blotName=s.tableRow;static tagName="tr";static className="ql-table-row";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,e.dataset.rowId=t.rowId,e}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}insertCell(t,e){const o=[],i=this.children.iterator();let n,l=0;for(;(n=i())&&(l+=n.colspan,!(l>t));)if(1!==n.rowspan)for(let t=0;tt)break}return[s,o,e]}removeCell(t){if(t<0)return[];const e=this.getCellByColumIndex(t),[o,i]=e,n=e[2];if(!o)return n;if(i-o.colspan1){const[e]=o.descendants(le);if(1!==o.colspan&&t===i-o.colspan){const t=Ot(this,s.tableMain).getColIds();e.colId=t[t.indexOf(e.colId)+1]}1!==o.rowspan&&(n.skipRowNum=o.rowspan-1),e.colspan-=1}else o.remove();return n}foreachCellInner(t){const e=this.children.iterator();let s,o=0;for(;s=e();){const[e]=s.descendants(le);if(t(e,o++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const e=this.parent,{tableId:o}=this;null!==e&&e.statics.blotName!==s.tableBody&&this.wrap(s.tableBody,o),super.optimize(t)}}class he extends Xt{static blotName=s.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const e=Ot(this,s.tableMain);if(!e)return;const o=e.getColIds(),i=this.descendants(de),n=new Set(o);let l=0;for(const e of i){if(l===t)break;e.foreachCellInner((e=>{if(l+e.rowspan>t&&(e.rowspan+=1,n.delete(e.colId),1!==e.colspan)){const t=o.indexOf(e.colId);for(let s=0;s0&&(l.style=a.map((([t,e])=>`${t}:${e}`)).join(";")),l}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let s=t;this.statics.allowDataAttrs.has(t)&&(s=`data-${t}`),e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s)}else this.statics.isAllowStyle(t)&&Object.assign(this.domNode.style,{[t]:e})}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute("rowspan"))}get colspan(){return Number(this.domNode.getAttribute("colspan"))}getCellInner(){return this.children.head}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:o}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===s&&i.rowspan===o}optimize(t){const e=this.parent,{tableId:o,rowId:i}=this;null!==e&&e.statics.blotName!==s.tableRow&&this.wrap(s.tableRow,{tableId:o,rowId:i}),super.optimize(t)}}const pe=e.import("blots/block/embed");class be extends pe{scroll;domNode;static blotName=s.tableCol;static tagName="col";static validWidth(t,e){let s=Number.parseFloat(String(t));return Number.isNaN(s)&&(s=o[e?"colMinWidthPre":"colMinWidthPx"]),`${s}${e?"%":"px"}`}static create(t){const{width:e,tableId:s,colId:o,full:i,align:n}=t,l=super.create();return l.setAttribute("width",this.validWidth(e,!!i)),i&&(l.dataset.full=String(i)),n&&"left"!==n&&(l.dataset.align=n),l.dataset.tableId=s,l.dataset.colId=o,l}static value(t){const{tableId:e,colId:s}=t.dataset,i=t.getAttribute("width")||o.colDefaultWidth,n=t.dataset.align,l={tableId:e,colId:s,full:Object.hasOwn(t.dataset,"full")};return i&&(l.width=Number.parseFloat(i)),n&&(l.align=n),l}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){const e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:o[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=o[this.full?"colMinWidthPre":"colMinWidthPx"]),this.domNode.setAttribute("width",this.statics.validWidth(e,!!this.full))}get tableId(){return this.domNode.dataset.tableId}get colId(){return this.domNode.dataset.colId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){const t=this.next,{tableId:e,colId:s}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===s}optimize(t){const e=this.parent;if(null!=e&&e.statics.blotName!==s.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(s.tableColgroup,t)}Ot(this,s.tableColgroup).align=this.align,super.optimize(t)}insertAt(t,e,o){if(null!=o)return void super.insertAt(t,e,o);const i=e.split("\n"),n=i.pop(),l=i.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),r=this.split(t),[a,c]=At(this,[s.tableColgroup,s.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let h=c.parent.parent,u=c.parent.next;if(d){const t=d.descendants(le);if(t.length>0){const e=t[0],o=le.formats(e.domNode),i=this.scroll.create("block"),n=i.wrap(s.tableCellInner,o).wrap(s.tableCell,o).wrap(s.tableRow,o).wrap(s.tableBody,o.tableId);a.parent.insertBefore(n,a.next),h=i,u=i.next}}for(const t of l)h.insertBefore(t,u);n&&h.insertBefore(this.scroll.create("text",n),u)}}class me extends Xt{static blotName=s.tableMain;static tagName="table";static className="ql-table";static create(t){const e=super.create(),{tableId:s,full:o,align:i}=t;return e.dataset.tableId=s,"right"===i||"center"===i?e.dataset.align=i:e.removeAttribute("date-align"),o&&(e.dataset.full=String(o)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,s){super(t,e),this.updateAlign()}colWidthFillTable(){if(this.full)return;const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?null:(this.domNode.style.width=`${e}px`,e)}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align"),this.updateAlign()}cancelFull(){if(!this.full)return;const t=this.getCols(),e=this.domNode.getBoundingClientRect().width;for(const s of t)s.domNode.removeAttribute("data-full"),s.width=s.width/100*e;const o=this.children.head;o&&o.statics.blotName===s.tableColgroup&&(o.full=!1),this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}updateAlign(){const t={marginLeft:null,marginRight:null};switch(this.align){case"center":t.marginLeft="auto",t.marginRight="auto";break;case"":case"left":t.marginRight="auto";break;case"right":t.marginLeft="auto"}Object.assign(this.domNode.style,t)}getRows(){return this.descendants(de)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(be)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const e=this.parent;null!==e&&e.statics.blotName!==s.tableWrapper&&this.wrap(s.tableWrapper,this.tableId),super.optimize(t)}}class fe extends Xt{static blotName=s.tableColgroup;static tagName="colgroup";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full="true":this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let s,o=0;for(;(s=e())&&o!==t;)o++;return s}insertColByIndex(t,e){const i=this.parent;if(!(i instanceof me))throw new TypeError("TableColgroupFormat should be child of TableFormat");const n=this.findCol(t),l=this.scroll.create(s.tableCol,e);if(i.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=o.colMinWidthPre){e.width-=l.width;break}}this.insertBefore(l,n)}removeColByIndex(t){const e=this.parent;if(!(e instanceof me))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const s=this.findCol(t);s&&(e.full&&(s.next?s.next.width+=s.width:s.prev&&(s.prev.width+=s.width)),s.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof me&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent,{tableId:o,full:i,align:n}=this;null!=e&&e.statics.blotName!==s.tableMain&&this.wrap(s.tableMain,{tableId:o,full:i,align:n});Ot(this,s.tableMain).align=n,super.optimize(t)}}class ge extends Xt{static blotName=s.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){const e=super.create();return e.dataset.tableId=t,e.addEventListener("dragstart",(t=>{t.preventDefault(),t.stopPropagation()}),!0),e.addEventListener("drop",(t=>{t.preventDefault()})),e.addEventListener("dragover",(t=>{t.preventDefault(),t.dataTransfer.dropEffect="none"})),e}get tableId(){return this.domNode.dataset.tableId}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}deleteAt(t,e){super.deleteAt(t,e);const s=this.descendants(he),o=this.descendants(fe);0!==s.length&&0!==o.length||this.remove()}}const we="color-selector",ve=[{name:"InsertTop",icon:'',tip:"Insert row above",handle:t=>{t.appendRow(!1),t.hideTableTools()}},{name:"InsertRight",icon:'',tip:"Insert column right",handle:t=>{t.appendCol(!0),t.hideTableTools()}},{name:"InsertBottom",icon:'',tip:"Insert row below",handle:t=>{t.appendRow(!0),t.hideTableTools()}},{name:"InsertLeft",icon:'',tip:"Insert column Left",handle:t=>{t.appendCol(!1),t.hideTableTools()}},{name:"break"},{name:"MergeCell",icon:'',tip:"Merge Cell",handle:t=>{t.mergeCells(),t.hideTableTools()}},{name:"SplitCell",icon:'',tip:"Split Cell",handle:t=>{t.splitCell(),t.hideTableTools()}},{name:"break"},{name:"DeleteRow",icon:'',tip:"Delete Row",handle:t=>{t.removeRow(),t.hideTableTools()}},{name:"DeleteColumn",icon:'',tip:"Delete Column",handle:t=>{t.removeCol(),t.hideTableTools()}},{name:"DeleteTable",icon:'',tip:"Delete table",handle:t=>{t.deleteTable()}},{name:"break"},{name:"BackgroundColor",icon:'',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},{name:"BorderColor",icon:'',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}}],xe=new Set,Ce=l("color-map"),ye={selectWrapper:Ce.b(),used:Ce.bm("used"),item:Ce.be("item"),btn:Ce.be("btn"),map:Ce.be("content"),mapRow:Ce.be("content-row")};class Me{tableModule;quill;options;menu=null;updateUsedColor;tooltipItem=[];bem=l("menu");colorItemClass=`color-${kt()}`;colorChooseTooltipOption={direction:"top"};constructor(t,e,s){this.tableModule=t,this.quill=e,this.options=this.resolveOptions(s);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);a(e)||(e=[]),e.slice(-10).map((t=>xe.add(t)))}catch{}this.updateUsedColor=zt((t=>{if(!t)return;if(xe.add(t),xe.size>10){const t=Array.from(xe).slice(-10);xe.clear(),t.map((t=>xe.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(xe)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${ye.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${ye.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${ye.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3)}resolveOptions(t){return Object.assign({tipText:!0,tipTexts:{},tools:ve,localstorageKey:"__table-bg-used-color",defaultColorMap:n},t)}getUsedColors(){return xe}buildTools(){const t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:s,icon:o,handle:i,isColorChoose:n,key:l,tip:a=""}=e,c=document.createElement("span");if(c.classList.add(this.bem.be("item")),"break"===s)c.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),r(o)?t.appendChild(o(this.tableModule)):t.innerHTML=o,c.appendChild(t),n&&l){const t=this.createColorChoose(c,{name:s,icon:o,handle:i,isColorChoose:n,key:l,tip:a});this.tooltipItem.push(t),c.classList.add(we)}else r(i)&&c.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.options.tipTexts[s]||a;this.options.tipText&&e&&a&&this.createTipText(c,e)}t.appendChild(c)}return t}createColorChoose(t,{handle:e,key:s}){const o=document.createElement("div");if(o.classList.add(ye.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(ye.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(ye.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(ye.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(ye.btn,"transparent"),n.textContent=this.tableModule.options.texts.transparent,n.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),"transparent")}));const l=document.createElement("div");l.classList.add(ye.btn,"clear"),l.textContent=this.tableModule.options.texts.clear,l.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),null)}));const r=document.createElement("div");r.classList.add(ye.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=g({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Rt(r,{direction:"right",type:"click",content:a,container:r});if(i.appendChild(n),i.appendChild(l),i.appendChild(r),o.appendChild(i),xe.size>0){const t=document.createElement("div");t.classList.add(ye.used,this.colorItemClass);for(const e of xe){const s=document.createElement("div");s.classList.add(ye.item),s.style.backgroundColor=e,t.appendChild(s)}o.appendChild(t)}return o.addEventListener("click",(t=>{t.stopPropagation(),c();const e=t.target,o=e.style.backgroundColor,i=this.getSelectedTds();if(e&&o&&i.length>0){if(this.tableModule.setCellAttrs(i,s,o,!0),!e.closest(`.${ye.item}`))return;this.updateUsedColor(o)}})),Rt(t,{content:o,onClose(t){const e=o.contains(a);return t&&e&&c(),e},onDestroy(){d()},...this.colorChooseTooltipOption})}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Rt(t,{msg:e});s&&this.tooltipItem.push(s)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&Object.assign(this.menu.style,{display:"flex"})}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0)}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}const Ie=t=>!t.full&&"right"===t.align;class Le{tableModule;quill;colIndex=-1;tableMain;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=l("drag-line");constructor(t,e){this.tableModule=t,this.quill=e}findCurrentColIndex(t){return-1}colWidthChange(t,e,s){}async createConfirmDialog({message:t,confirm:e,cancel:s}){return new Promise((o=>{const i=document.createElement("div");Object.assign(i.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});const n=document.createElement("p");n.textContent=t;const l=document.createElement("div");Object.assign(l.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});const r=d({content:s}),a=d({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=v({child:i});r.addEventListener("click",(()=>{o(!1),c()})),a.addEventListener("click",(()=>{o(!0),c()}))}))}async handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0");let s=this.tableMain.full,n=!1;const l=[];if(s){let s=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(s(o+=e,t))));for(const[e,s]of t.entries())i.has(e)||(o+=s.width);if(o>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableMain.cancelFull(),s=!1;for(const[t,s]of l.entries()){const{width:o,index:i}=s;l[t]={index:i,width:o/100*e}}}}for(const{index:o,width:i}of l)t[o].width=`${Math.round(i)}${s?"%":"px"}`,this.colWidthChange(o,s?i/100*e:i,s)}this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),s=e[this.colIndex].domNode.getBoundingClientRect(),i=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=o.colMinWidthPre/100*i.width;let l=i.right;n>s.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,s.left+t));const r=s.x+t;n=Math.min(Math.max(n,r),l)}else Ie(this.tableMain)?s.right-n{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Ht.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:t,scrollTop:s}=this.quill.root,{offsetLeft:o,offsetTop:i}=this.container,{width:n,height:l}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=o,d=i;this.isVertical?c+=Math.min(n,r):d+=Math.min(l,a);const h=e.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-o),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?l:n}px`,transform:`translate(${c-t}px, ${d-s}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,s=t**2/this.container.scrollHeight,o=e**2/this.container.scrollWidth,i=Math.max(s,this.minSize),n=Math.max(o,this.minSize);this.ratioY=s/(t-s)/(i/(t-i)),this.ratioX=o/(e-o)/(n/(e-n)),this.sizeWidth=n+this.gap{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const s=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],o=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*s/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=o*this.container[this.propertyMap.scrollSize]/100},s=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",s),this.cursorLeave&&this.hideScrollbar()},o=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",e),document.addEventListener("mouseup",s),document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),o(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const i=[this.table,t];for(const t of i)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Ht.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){const e=t[this.propertyMap.offset]-this.gap;this.move=100*t[this.propertyMap.scrollDirection]/e*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=zt((()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?"block":"none",requestAnimationFrame((()=>{this.scrollbar.classList.remove(this.bem.is("transparent"))}))}),200);hideScrollbar=zt((()=>{this.cursorLeave=!0,this.cursorDown||(this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.addEventListener("transitionend",this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is("transparent")))}),200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?"block":"none"};destroy(){this.ob.disconnect(),Dt.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}const Ee=e.import("delta"),Se=e.import("blots/break"),Te=e.import("ui/icons"),Re=(t,{tableId:e,rowId:o,colId:i})=>{const n={tableId:e,rowId:o,colId:i,colspan:1,rowspan:1},l=t.create(s.tableCell,n),r=t.create(s.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l},Be=t=>{let e=Number.parseFloat(t.getAttribute("width")||o.colDefaultWidth);if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e},ke=new Set([s.tableCellInner]),ze=t=>{return!(!t||!t.parent)&&(e=t.parent,!!ke.has(e.statics.blotName)||ze(t.parent));var e};class Oe{static moduleName="table-up";static toolName=s.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,e){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof ge)return o.prev.remove(),!1;if(e.format[s.tableCellInner]){if(0===o.offset(Ot(o,s.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,e){const o=this.quill.getLine(t.index),i=o[0],n=o[1];if((i.next instanceof ge||i.next instanceof be)&&n===i.length()-1)return!1;if(e.format[s.tableCellInner]){if(i===Ot(i,s.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[s.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(t){const[o,i]=this.quill.getLine(t.index);if(this.quill.getFormat(t.index+i+1,1)[s.tableCellInner])return!0;let n=2,l=o;for(;null!==l&&l.length()<=1;)if(l=l.prev,n-=1,n<=0)return this.quill.insertText(t.index+1,"\n"),this.quill.setSelection(t.index+1,e.sources.SILENT),!1;return!0}}};static register(){ge.allowedChildren=[me],me.allowedChildren=[he,fe],me.requiredContainer=ge,fe.allowedChildren=[be],fe.requiredContainer=me,he.allowedChildren=[de],he.requiredContainer=me,de.allowedChildren=[ue],ue.requiredContainer=he,ue.allowedChildren=[le,Se],ue.requiredContainer=de,le.requiredContainer=ue,e.register({"blots/scroll":ce,"blots/block":Ut,[`blots/${s.container}`]:Xt,"formats/header":te,"formats/list":se,"formats/blockquote":Zt,"formats/code-block":Qt,[`formats/${s.tableCell}`]:ue,[`formats/${s.tableCellInner}`]:le,[`formats/${s.tableRow}`]:de,[`formats/${s.tableBody}`]:he,[`formats/${s.tableCol}`]:be,[`formats/${s.tableColgroup}`]:fe,[`formats/${s.tableMain}`]:me,[`formats/${s.tableWrapper}`]:ge},!0)}quill;options;toolBox;fixTableByLisenter=zt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(t,o){if(this.quill=t,this.options=this.resolveOptions(o||{}),!this.options.scrollbar){const t=l("scrollbar");this.quill.container.classList.add(t.bm("origin"))}const n=l("toolbox");this.toolBox=this.quill.addContainer(n.b());const r=this.quill.getModule("toolbar");if(r&&this.quill.theme.pickers){const[,t]=(r.controls||[]).find((([t])=>t===this.statics.toolName))||[];if(t&&"select"===t.tagName.toLocaleLowerCase()){const e=this.quill.theme.pickers.find((e=>e.select===t));e&&(e.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,e),e.label.addEventListener("mousedown",(()=>{if(!this.selector||!e)return;const t=this.selector.getBoundingClientRect(),{leftLimited:s}=Wt(t);if(s){const t=e.label.getBoundingClientRect();Object.assign(e.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(e.options.style,{transform:void 0})})))}}const a=this.quill.getModule("keyboard");for(const t of Object.values(Oe.keyboradHandler))t.bindInHead?a.bindings[t.key].unshift(t):a.addBinding(t.key,t);this.quill.root.addEventListener("click",(e=>{const s=e.composedPath();if(!s||s.length<=0)return;const o=s.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(o){if(this.table===o)return this.tableSelection&&this.tableSelection.show(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(o,t)}else this.table&&this.hideTableTools()}),!1),this.quill.on(e.events.EDITOR_CHANGE,((t,o,i)=>{if(t===e.events.SELECTION_CHANGE&&o){const[t]=this.quill.getLine(o.index),[e]=this.quill.getLine(o.index+o.length);let i,n;try{i=Ot(t,s.tableMain)}catch{}try{n=Ot(e,s.tableMain)}catch{}i&&n||this.hideTableTools()}})),this.quill.on(i.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hide()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if(c(t)){const e=document.createElement("div");for(const s of t.split(" "))e.classList.add(s);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!1,texts:this.resolveTexts(t.texts||{}),full:!1,fullSwitch:!0,icon:Te.table,selectionOptions:{},alignOptions:{},scrollbarOptions:{},resizeOptions:{},resizeScaleOptions:{}},t)}resolveTexts(t){return Object.assign({fullCheckboxText:"Insert full width table",customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer",custom:"Custom",clear:"Clear",transparent:"Transparent",perWidthInsufficient:"The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?"},t)}pasteTableHandler(){let t=kt(),e=kt(),i=[],n=[],l=0,r=0;const a=(t,e,o)=>{const i=this.quill.getSelection(!0),n=this.quill.getFormat(i)[s.tableCellInner];if(n)for(const t of e.ops)t.attributes||(t.attributes={}),t.attributes[s.tableCellInner]=n;return e};this.quill.clipboard.addMatcher(Node.TEXT_NODE,a),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,a),this.quill.clipboard.addMatcher("table",((e,a)=>{if(0===a.ops.length)return a;if(this.quill.getFormat()[s.tableCellInner])return new Ee;const c=[],d=[];for(let t=0;t{const s=new Array(e).fill(o.colDefaultWidth),i=Array.from(t.querySelectorAll("tr"));for(const t of i){const o=Array.from(t.querySelectorAll("td"));for(const[t,i]of o.entries()){if(!(t(d[n]?e.push(d[n]):e.push({insert:{[s.tableCol]:{tableId:t,colId:i[n],width:o,full:!1}}}),e)),[]);return c.unshift(...h),t=kt(),i=[],n=[],l=0,r=0,c.unshift({insert:"\n"}),c.push({insert:"\n"}),new Ee(c)})),this.quill.clipboard.addMatcher("colgroup",((t,e)=>{const o=[];for(let t=0;t{i[r]=kt();const o=(new Ee).insert({[s.tableCol]:Object.assign(be.value(e),{tableId:t,colId:i[r]})});return r+=1,o})),this.quill.clipboard.addMatcher("tr",((t,o)=>{e=kt(),l=0;for(const t of o.ops)if(t.attributes&&t.attributes.background&&t.attributes[s.tableCellInner]){const e=t.attributes[s.tableCellInner];e.style||(e.style=""),t.attributes[s.tableCellInner].style=`background:${t.attributes.background};${e.style}`}for(const[t,e]of n.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(n[t]={rowspan:0,colspan:0});return o}));const c=(o,r)=>{const a=o,c=ue.formats(a);if(!i[l]||!n[l])for(let t=l;t>=0;t--)i[t]||(i[t]=kt()),n[t]||(n[t]={rowspan:0,colspan:0});const{colspan:d}=n[l];l+=d,c.rowspan>1&&(n[l]={rowspan:c.rowspan,colspan:c.colspan});const h=i[l];l+=c.colspan;const u=Object.assign(c,{tableId:t,rowId:e,colId:h});"none"===a.style.border&&(u.style=u.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const p=[];for(const t of r.ops){const{insert:e,attributes:o}=t;if(t.insert){const t={...o};delete t[s.tableCell],p.push({insert:e,attributes:{...t,[s.tableCellInner]:u}})}}return new Ee(p)};this.quill.clipboard.addMatcher("td",c),this.quill.clipboard.addMatcher("th",c)}showTableTools(t,e){t&&(this.table=t,this.options.selection&&(this.tableSelection=new this.options.selection(this,t,e,this.options.selectionOptions)),this.options.align&&(this.tableAlign=new this.options.align(this,t,e,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,e,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,e,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,e,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection&&(this.tableSelection.destroy(),this.tableSelection=void 0),this.tableScrollbar&&(this.tableScrollbar.destroy(),this.tableScrollbar=void 0),this.tableAlign&&(this.tableAlign.destroy(),this.tableAlign=void 0),this.tableResize&&(this.tableResize.destroy(),this.tableResize=void 0),this.tableResizeScale&&this.tableResizeScale.destroy(),this.table=void 0}async buildCustomSelect(t,e){if(!t||!r(t))return;const s=document.createElement("div");if(s.classList.add("ql-custom-select"),this.selector=await t(this,e),s.appendChild(this.selector),this.options.fullSwitch){const t=l("creator"),e=document.createElement("label");e.classList.add(t.be("checkbox"));const o=document.createElement("input");o.type="checkbox",o.checked=this.options.full,o.addEventListener("change",(()=>{this.options.full=o.checked}));const i=document.createElement("div");i.classList.add(t.be("mark"));const n=document.createElement("span");n.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),e.appendChild(n),s.appendChild(e)}e.options.appendChild(s)}setCellAttrs(t,e,s,o=!1){if(0!==t.length)for(const i of t)i.setFormatValue(e,s,o)}insertTable(t,i){if(t>=30||i>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus();const n=this.quill.getSelection();if(null==n)return;const[l]=this.quill.getLeaf(n.index);if(!l)return;if(ze(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),a=getComputedStyle(this.quill.root),c=Number.parseInt(a.paddingLeft),d=Number.parseInt(a.paddingRight),h=Number.parseInt(a.width)-c-d-r,u=kt(),p=new Array(i).fill(0).map((()=>kt())),b=this.options.full?`${Math.max(1/i*100,o.colMinWidthPre)}%`:`${Math.max(Math.floor(h/i),o.colMinWidthPx)}px`,m=[{retain:n.index},{insert:"\n"}];for(let t=0;t\n \n \n \n \n \n \n `,e=document.createElement("div");e.className=ge.className,e.innerHTML=t,e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.visibility="hidden",this.quill.root.appendChild(e);const s=window.getComputedStyle(e.querySelector("td")),o=Number.parseFloat(s.borderWidth)||0;return this.quill.root.removeChild(e),o}fixUnusuaDeletelTable(t){const e=t.getRows(),s=t.getColIds();if(0===e.length)return t.remove();if(0===s.length)return;const o=new Array(e.length).fill(0).map((()=>new Array(s.length).fill(!1))),i=t.tableId;for(const[t,n]of e.entries()){let l=0,r=0;const a=o[t],c=n.descendants(ue);for(;r=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:i}=d;if(s>1)for(let t=1;t1)for(let e=t+1;e{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)))}))}deleteTable(){if(!this.tableSelection||0===this.tableSelection.selectedTds.length)return;const t=Ot(this.tableSelection.selectedTds[0],s.tableMain);t&&t.remove(),this.hideTableTools()}appendRow(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const o=e[t?e.length-1:0],[i,n,l]=At(o,[s.tableMain,s.tableBody,s.tableRow]),r=i.getRows().indexOf(l)+(t?o.rowspan:0);n.insertRow(r)}appendCol(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const[o]=e.reduce(((e,s)=>{const o=s.getColumnIndex();return(!t&&o<=e[1]||t&&o>=e[1])&&(e=[s,o]),e}),[e[0],e[0].getColumnIndex()]),i=o.getColumnIndex()+(t?o.colspan:0),n=Ot(o,s.tableMain),l=n.tableId,r=kt(),[a]=n.descendants(fe);a&&a.insertColByIndex(i,{tableId:l,colId:r,width:n.full?"6%":"160px",full:n.full});const c=n.getRows(),d=[];let h=0;for(const t of Object.values(c)){const e=d.shift()||0;if(h>0){h-=1;continue}const s=t.insertCell(i-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(h+=s.skipRowNum);for(const[t,e]of s.entries())d[t]=(d[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),s=t.getCols(),o=s.reduce(((t,e)=>(t[e.colId]=0,t)),{}),i=[...e].reverse(),n=[];for(const[t,s]of i.entries()){const i=e.length-t-1;s.children.length<=0?n.push(i):s.foreachCellInner((t=>{const e=n.reduce(((e,s)=>t.rowspan+i>s?e+1:e),0);t.rowspan-=e,o[t.colId]+=1}))}let l=0;for(const t of Object.values(o))if(0===t){const t=[];let s=0;for(const o of Object.values(e)){const e=t.shift()||0;let i=[];s>0?(i=o.getCellByColumIndex(l-e)[2],s-=1):(i=o.removeCell(l-e),i.skipRowNum&&(s+=i.skipRowNum));for(const[e,s]of i.entries())t[e]=(t[e]||0)+s}}else l+=1;for(const t of s)0===o[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=Ot(t[0],s.tableMain),o=e.getRows();let i=o.length,n=-1;for(const e of t){const t=Ot(e,s.tableRow),l=o.indexOf(t);ln&&(n=l+e.rowspan)}const l={};for(let t=i;t{e.rowspan+t>n&&(l[e.colId]={rowspan:e.rowspan+t-n,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(o[n]){const t=o[n],s=e.tableId;for(const[e,{colIndex:o,colspan:i,rowspan:n}]of Object.entries(l))t.insertCell(o,{tableId:s,rowId:t.rowId,colId:e,colspan:i,rowspan:n})}this.fixTableByRemove(e)}removeCol(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=t[0],o=Ot(e,s.tableMain),i={};for(const e of t)i[e.rowId]||(i[e.rowId]=0),i[e.rowId]+=e.colspan;const n=Math.max(...Object.values(i)),l=e.getColumnIndex(),r=o.descendants(de);for(let t=0;t0){e-=1;continue}const i=s.removeCell(l-o);i.skipRowNum&&(e+=i.skipRowNum);for(const[e,s]of i.entries())t[e]=(t[e]||0)+s}}const[a]=o.descendants(fe);if(a)for(let t=0;t{const o=e.colId;t[0][o]||(t[0][o]=0),t[0][o]+=e.rowspan;const i=e.rowId;return t[1][i]||(t[1][i]=0),t[1][i]+=e.colspan,0!==s&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),o=Math.max(...Object.values(e[0])),i=Math.max(...Object.values(e[1])),n=e[2];n.colspan=i,n.rowspan=o;const l=Ot(n,s.tableMain);this.fixTableByRemove(l)}splitCell(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(1!==t.length)return;const e=t[0];if(1===e.colspan&&1===e.rowspan)return;const[o,i]=At(e,[s.tableMain,s.tableRow]),n=o.tableId,l=e.getColumnIndex(),r=o.getColIds().slice(l,l+e.colspan).reverse();let a=i,c=e.rowspan;for(e.colspan=1,e.rowspan=1;a&&c>0;){for(const t of r)a===i&&t===e.colId||a.insertCell(l+(a===i?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}t.BlockOverride=Ut,t.BlockquoteOverride=Zt,t.CodeBlockOverride=Qt,t.ContainerFormat=Xt,t.HeaderOverride=te,t.ListItemOverride=se,t.ScrollOverride=ce,t.Scrollbar=Ne,t.TableAlign=class{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=l("align");resizeObserver=new ResizeObserver((()=>this.hide()));constructor(t,s,o){this.tableModule=t,this.table=s,this.quill=o,this.tableBlot=e.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const t=this.tableModule.addContainer(this.bem.b()),s=e.import("ui/icons"),o={left:s.align[""],center:s.align.center,right:s.align.right};for(const[s,i]of Object.entries(o)){const o=document.createElement("span");o.dataset.align=s,o.classList.add(this.bem.be("item")),o.innerHTML=`${i}`,o.addEventListener("click",(()=>{const t=o.dataset.align;t&&(this.setTableAlign(this.tableBlot,t),this.quill.once(e.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableResizeScale&&this.tableModule.tableResizeScale.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),t.appendChild(o)}return this.cleanup||(this.cleanup=Mt(this.tableWrapperBlot.domNode,t,(()=>this.update()))),t}setTableAlign(t,e){const s=t.getCols();for(const t of s)t.align=e}show(){this.alignBox&&(this.alignBox.classList.add(this.bem.bm("active")),this.resizeObserver.observe(this.table))}hide(){this.alignBox&&(this.alignBox.classList.remove(this.bem.bm("active")),this.cleanup&&(this.cleanup(),this.cleanup=void 0))}update(){this.alignBox&&(this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth?this.hide():(this.show(),St(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[Nt(),Lt({limiter:Et()}),It(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}},t.TableBodyFormat=he,t.TableCellFormat=ue,t.TableCellInnerFormat=le,t.TableColFormat=be,t.TableColgroupFormat=fe,t.TableMainFormat=me,t.TableMenuCommon=Me,t.TableMenuContextmenu=class extends Me{tableModule;quill;colorChooseTooltipOption={direction:"right"};constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),this.update({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hide()}),{once:!0})):this.hide()};buildTools(){const t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));const e=t.getElementsByClassName(we);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const s=document.createElement("span");s.textContent=e,t.appendChild(s)}update(t){if(!this.menu||!this.tableModule.tableSelection||!this.tableModule.tableSelection.boundary)return;super.update();const e={display:"flex",left:0,top:0};if(!t)return this.hide();const{x:s,y:o}=t;e.left=s,e.top=o,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const i=this.menu.getBoundingClientRect(),{left:n,top:l}=Wt(i);Object.assign(this.menu.style,{left:`${n+window.scrollX}px`,top:`${l+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy()}},t.TableMenuSelect=class extends Me{tableModule;quill;constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(super.update(),St(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[Nt(),Lt({limiter:Et()}),It(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}},t.TableResizeBox=class extends Le{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=l("resize-box");constructor(t,s,o){super(t,o),this.tableModule=t,this.table=s,this.tableMain=e.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer(this.bem.b()),this.resizeObserver=new ResizeObserver((()=>{this.show()})),this.resizeObserver.observe(this.table)))}handleResizerHeader(t,e){const{clientX:s,clientY:o}=e,i=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const n=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const l=[{x:t?i.left:s,y:t?o:i.top},{x:t?i.right:s,y:t?o:i.bottom}];this.lastHeaderSelect?(l[0]={x:Math.min(l[0].x,this.lastHeaderSelect[0].x),y:Math.min(l[0].y,this.lastHeaderSelect[0].y)},l[1]={x:Math.max(l[1].x,this.lastHeaderSelect[1].x),y:Math.max(l[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=l,n.selectedTds=n.computeSelectedTds(...l),n.show()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("col-separator"))).indexOf(t.target)}colWidthChange(t,e,s){Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[t].style.width=`${e}px`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.size+"px",left:`${e.left}px`,height:`${e.height+this.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));Ht.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!1));for(const t of e)t.addEventListener("mousedown",this.handleColMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}findCurrentRowIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("row-separator"))).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[t].style.height=`${e}px`}handleRowMouseDownFunc=function(t){const e=this.handleRowMouseDown(t);return e&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${e.top}px`,left:e.left-this.size+"px",width:`${e.width+this.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));Ht.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!0));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const[t]=this.tableMain.descendant(he,this.tableMain.length()-1);if(!t)return;const e=t.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:e.y-s.y+"px",left:e.x-s.x+"px"});const o=this.tableMain.domNode.getBoundingClientRect(),i=this.tableWrapper.domNode.getBoundingClientRect();let n=-1*this.size,l=-1*this.size;Ie(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),n=Math.min(i.width,o.width),l=Math.min(i.width,o.width)):this.root.classList.remove(this.bem.is("align-right")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${n}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const t=this.tableWrapper.domNode.getBoundingClientRect(),e=this.tableMain.domNode.getBoundingClientRect();if(this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener("click",(()=>{const t=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const e=this.tableModule.tableSelection;e.selectedTds=e.computeSelectedTds({x:t.x,y:t.y},{x:t.right,y:t.bottom}),e.show()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let s="";for(const[,t]of this.tableCols.entries()){const o=t.domNode.getBoundingClientRect().width;s+=`
\n
\n
`}const o=document.createElement("div");o.classList.add(this.bem.be("col"));const i=document.createElement("div");i.classList.add(this.bem.be("col-wrapper")),Object.assign(o.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=s,o.appendChild(i),this.root.appendChild(o),o.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=o,this.bindColEvents()}if(this.tableRows.length>0){let s="";for(const[,t]of this.tableRows.entries()){const o=`${t.domNode.getBoundingClientRect().height}px`;s+=`
\n
\n
`}const o=document.createElement("div");o.classList.add(this.bem.be("row"));const i=document.createElement("div");i.classList.add(this.bem.be("row-wrapper")),Object.assign(o.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${t.height}px`}),Object.assign(i.style,{height:`${e.height}px`}),i.innerHTML=s,o.appendChild(i),this.root.appendChild(o),o.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=o,this.bindRowEvents()}this.update(),Ht.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),Dt.call(this),this.resizeObserver.disconnect();for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}},t.TableResizeCommon=Le,t.TableResizeLine=class extends Le{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=l("resize-line");constructor(t,s,o){super(t,o),this.tableModule=t,this.table=s,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.table.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(e.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=t=>{if(this.dragging)return;const o=this.findTableCell(t);if(!o)return this.hide();const i=e.find(o);i&&this.currentTableCell!==o&&(this.show(),this.currentTableCell=o,this.tableCellBlot=i,this.tableMain=Ot(i,s.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hide()};findTableCell(t){for(const e of t.composedPath()){if(e instanceof HTMLElement&&"TD"===e.tagName)return e;if(e===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.colResizer),this.colResizer=this.tableModule.addContainer(this.bem.be("col"));const[e]=At(t,[s.tableBody]),o=e.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;Ie(this.tableMain)&&(l=i.left-n.x),Object.assign(this.colResizer.style,{top:o.y-n.y+"px",left:`${l}px`,height:`${o.height}px`});const r=this.tableMain.getCols();this.curColIndex=r.findIndex((e=>e.colId===t.colId)),this.colResizer.addEventListener("mousedown",this.handleColMouseDownFunc),this.colResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.rowResizer),this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));const e=t.parent;if(!(e instanceof de))return;const[o]=At(t,[s.tableBody]),i=o.domNode.getBoundingClientRect(),n=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:n.bottom-l.y+"px",left:i.x-l.x+"px",width:`${i.width}px`});const r=this.tableMain.getRows();this.curRowIndex=r.indexOf(e),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}show(){Object.assign(this.colResizer.style,{display:null}),Object.assign(this.rowResizer.style,{display:null})}hide(){this.currentTableCell=void 0,this.rowResizer.style.display="none",this.colResizer.style.display="none"}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer.remove(),this.rowResizer.remove(),this.table.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(e.events.TEXT_CHANGE,this.hideWhenTextChange)}},t.TableResizeScale=class{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=l("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(t,s,o,i){this.tableModule=t,this.table=s,this.quill=o,this.options=this.resolveOptions(i),this.tableMainBlot=e.find(s),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.buildResizer(),this.show())}resolveOptions(t){return Object.assign({blockSize:12},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.root.classList.add(this.bem.is("hidden")),this.block=document.createElement("div"),this.block.classList.add(this.bem.be("block")),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let t=[],e=[];const s=s=>{if(!this.tableMainBlot)return;const i=Ie(this.tableMainBlot)?-1:1,n=(s.clientX-this.startX)*i,l=s.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:s}of t)e.width=Math.max(s+r,o.colMinWidthPx);for(const{blot:t,height:s}of e)t.setHeight(`${Math.max(s+a,o.rowMinHeightPx)}px`)},i=()=>{t=[],e=[],document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",i)};this.block.addEventListener("mousedown",(o=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=o.clientX,this.startY=o.clientY,t=this.tableMainBlot.getCols().map((t=>({blot:t,width:Math.floor(t.width)}))),e=this.tableMainBlot.getRows().map((t=>({blot:t,height:Math.floor(t.domNode.getBoundingClientRect().height)}))),document.addEventListener("mousemove",s),document.addEventListener("mouseup",i))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),Ht.call(this,this.quill.root,(()=>this.update())),Ht.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect();if(t.width>e.width){for(const s of this.tableMainBlot.getCols())s.width=Math.floor(s.width/t.width*e.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),{scrollTop:o,scrollLeft:i}=this.tableWrapperBlot.domNode,n=2*this.options.blockSize,l=Math.min(t.width,e.width)+n,r=Math.min(t.height,e.height)+n;Object.assign(this.root.style,{width:`${l}px`,height:`${r}px`,left:Math.max(t.x,e.x)-s.x-this.options.blockSize+"px",top:Math.max(t.y,e.y)-s.y-this.options.blockSize+"px"});const a={left:t.width+n-i+"px",top:r-o+"px"};Ie(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),a.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,a)}show(){this.root&&(this.root.classList.remove(this.bem.is("hidden")),this.update())}hide(){this.root&&this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),this.root&&this.root.remove(),Dt.call(this)}},t.TableRowFormat=de,t.TableSelection=class{table;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];selectingHandler=this.mouseDownHandler.bind(this);tableMenu;resizeObserver;bem=l("selection");constructor(t,e,s,o={}){this.table=e,this.quill=s,this.options=this.resolveOptions(o),this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((()=>this.hide())),this.resizeObserver.observe(this.table),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(t,s,this.options.tableMenuOptions))}resolveOptions(t){return Object.assign({selectColor:"#0589f3",tableMenuOptions:{}},t)}helpLinesInitial(){const t=document.createElement("div");return t.classList.add(this.bem.be("line")),Object.assign(t.style,{"border-color":this.options.selectColor}),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(t,s){const o=e.find(this.table);if(!o)return[];const i=new Set(o.descendants(ue).map(((t,e)=>(t.index=e,t)))),{x:n,y:l}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=n,this.selectedTableScrollY=l,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=t.x-n+this.startScrollX,h=t.y-l+this.startScrollY;let u={x:Math.max(c.left,Math.min(s.x,d)),y:Math.max(c.top,Math.min(s.y,h)),x1:Math.min(c.right,Math.max(s.x,d)),y1:Math.min(c.bottom,Math.max(s.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of i){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:o,bottom:n}=t.__rect;if(Bt(u,{x:e,y:s,x1:o,y1:n},2)){p.add(t),i.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,s),x1:Math.max(u.x1,o),y1:Math.max(u.y1,n)},b=!0;break}if(e>u.x1&&s>u.y1)break}}for(const t of[...p,...i])delete t.__rect;return this.boundary=function(t,e){const s=e.getBoundingClientRect();return{x:t.x-s.x-e.scrollLeft,y:t.y-s.y-e.scrollTop,x1:t.x-s.x-e.scrollLeft+t.width,y1:t.y-s.y-e.scrollTop+t.height,width:t.width,height:t.height}}({...u,width:u.x1-u.x,height:u.y1-u.y},this.quill.root),Array.from(p).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler(t){const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n)return;const l=n.dataset.tableId,r={x:o,y:i},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.show(),this.tableMenu&&this.tableMenu.hide();const d=t=>{const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n||n.dataset.tableId!==l)return;this.dragging=!0;const a={x:o,y:i};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.update()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu&&this.tableMenu.update()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)}update(){if(0===this.selectedTds.length||!this.boundary)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:s,y:o}=this.getTableViewScroll(),i=this.table.parentElement.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),l=i.x-n.x,r=i.y-n.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-o-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${i.width+2}px`,height:`${i.height+2}px`}),!this.dragging&&this.tableMenu&&this.tableMenu.update()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}}show(){Dt.call(this),Object.assign(this.cellSelectWrap.style,{display:"block"}),this.update(),Ht.call(this,this.quill.root,(()=>{this.update()})),Ht.call(this,this.table.parentElement,(()=>{this.update()}))}hide(){this.boundary=null,this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.tableMenu&&this.tableMenu.hide(),Dt.call(this)}destroy(){return this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Dt.call(this),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),null}},t.TableUp=Oe,t.TableVirtualScrollbar=class{tableModule;table;quill;scrollbarContainer;scrollbar;bem=l("scrollbar");constructor(t,e,s){this.tableModule=t,this.table=e,this.quill=s,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Ne(s,!0,e,this.scrollbarContainer),new Ne(s,!1,e,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar)}hide(){for(const t of this.scrollbar)t.hideScrollbar()}show(){for(const t of this.scrollbar)t.showScrollbar()}update(){for(const t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}destroy(){this.scrollbarContainer.remove();for(const t of this.scrollbar)t.destroy();return null}},t.TableWrapperFormat=ge,t.blotName=s,t.createColorPicker=g,t.createSelectBox=C,t.createTooltip=Rt,t.default=Oe,t.defaultCustomSelect=function(t,e){return C({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})},t.findParentBlot=Ot,t.findParentBlots=At,t.isTableAlignRight=Ie,t.randomId=kt,t.tableCantInsert=ke,t.tableUpEvent=i,t.tableUpSize=o,t.updateTableConstants=function(t){ke.delete(s.tableCellInner),Object.assign(s,t.blotName||{}),Object.assign(o,t.tableUpSize||{}),Object.assign(i,t.tableUpEvent||{}),Oe.toolName=s.tableWrapper,Xt.blotName=s.container,ge.blotName=s.tableWrapper,me.blotName=s.tableMain,fe.blotName=s.tableColgroup,be.blotName=s.tableCol,he.blotName=s.tableBody,de.blotName=s.tableRow,ue.blotName=s.tableCell,le.blotName=s.tableCellInner},Object.defineProperty(t,"__esModule",{value:!0})})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("quill")):"function"==typeof define&&define.amd?define(["exports","quill"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TableUp={},t.Quill)}(this,(function(t,e){"use strict";const s={container:"table-up-container",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableBody:"table-up-body",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},o={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:"100",rowMinHeightPx:36},i={AFTER_TABLE_RESIZE:"after-table-resize"},n=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],l=(t,e="table-up")=>{const s=e?`${e}-`:"";return{b:()=>`${s}${t}`,be:e=>e?`${s}${t}__${e}`:"",bm:e=>e?`${s}${t}--${e}`:"",bem:(e,o)=>e&&o?`${s}${t}__${e}--${o}`:"",ns:t=>t?`${s}${t}`:"",bs:e=>e?`${s}${t}-${e}`:"",cv:t=>t?`--${s}${t}`:"",is:t=>`is-${t}`}},r=t=>"function"==typeof t,a=Array.isArray,c=t=>"string"==typeof t,d=t=>{const{type:e="default",content:s}=t||{},o=l("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(c(s)?i.textContent=s:i.appendChild(s)),i},h=function(t,e){return t=Math.min(e,Math.max(0,Number.parseFloat(`${t}`))),Math.abs(t-e)<1e-6?1:t%e/Number.parseFloat(e)},u=t=>({h:Math.min(360,Math.max(0,t.h)),s:Math.min(100,Math.max(0,t.s)),b:Math.min(100,Math.max(0,t.b)),a:Math.min(1,Math.max(0,t.a))}),p=t=>{let{r:e,g:s,b:o,a:i}=t;e=h(e,255),s=h(s,255),o=h(o,255);const n=Math.max(e,s,o),l=Math.min(e,s,o);let r;const a=n,c=n-l,d=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(s-o)/c+(s{let{h:e,s:s,b:o,a:i}=t;e=6*h(e,360),s=h(s,100),o=h(o,100);const n=Math.floor(e),l=e-n,r=o*(1-s),a=o*(1-l*s),c=o*(1-(1-l)*s),d=n%6,u=[o,a,r,r,c,o][d],p=[c,o,o,a,r,r][d],b=[r,r,c,o,o,a][d];return{r:Math.round(255*u),g:Math.round(255*p),b:Math.round(255*b),a:i}},m=t=>{const e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(const t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")},f=t=>m(b(t)),g=(t={})=>{const e=230,s=150,o=10;let i=p((n=(n=t.color||"#ff0000").startsWith("#")?n.slice(1):n,{r:Number.parseInt(n.slice(0,2),16),g:Number.parseInt(n.slice(2,4),16),b:Number.parseInt(n.slice(4,6),16),a:Number((Number.parseInt(n.slice(6,8)||"ff",16)/255).toFixed(2))}));var n;const r=l("color-picker"),a=document.createElement("div");a.classList.add(r.b());const c=document.createElement("div");c.classList.add(r.be("content"));const d=document.createElement("div");d.classList.add(r.be("selector"));const h=document.createElement("div");h.classList.add(r.be("background")),d.appendChild(h);const g=document.createElement("div");g.classList.add(r.be("background-handle")),h.appendChild(g);const w=document.createElement("div");w.classList.add(r.be("alpha"));const v=document.createElement("div");v.classList.add(r.be("alpha-bg"));const x=document.createElement("div");x.classList.add(r.be("alpha-handle")),w.appendChild(v),w.appendChild(x);const C=document.createElement("div");C.classList.add(r.be("hue"));const y=document.createElement("div");y.classList.add(r.be("hue-handle")),C.appendChild(y);const M=document.createElement("div");M.classList.add(r.be("action"));const[I,L,N,E]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(r.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(r.be("input")),o.addEventListener("input",(()=>{o.value=o.value.replaceAll(/[^0-9]/g,"")})),o.addEventListener("change",(()=>{let e=Math.round(Number(o.value));"a"===t&&(e/=100);z(u(p(Object.assign({},b(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));c.appendChild(C),c.appendChild(d),c.appendChild(w),a.appendChild(c),a.appendChild(M);let S=!1,T=!1,R=!1;function B(){const t=f(i);for(const[e,s]of[I,L,N].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));E.value=String((100*i.a).toFixed(0))}function k(){Object.assign(g.style,{left:`${Math.floor(e*i.s/100)}px`,top:`${Math.floor(s*(100-i.b)/100)}px`}),d.style.backgroundColor=`#${m(b({h:i.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*i.h/360)}px`,x.style.left=100*i.a+"%",function(){const{r:t,g:e,b:s}=b(i);v.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),B()}function z(e){i=u(Object.assign({},i,e)),B(),t.onChange&&t.onChange(`#${f(i)}`)}function O(t){const o=d.getBoundingClientRect(),i=o.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=o.left+document.body.scrollLeft;z({s:Math.floor(100*Math.max(0,Math.min(e,t.pageX-n))/e),b:Math.floor(100*(s-Math.max(0,Math.min(s,t.pageY-i)))/s)}),k()}function A(t){const e=C.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);z({h:Math.floor(360*(s-Math.max(0,Math.min(s,t.pageY-e)))/s)}),k()}function $(t){const{pageX:e}=t,s=w.getBoundingClientRect();let i=e-s.left;i=Math.max(o/2,i),i=Math.min(i,s.width-o/2),z({a:Math.round((i-5)/(s.width-10)*100)/100}),k()}function q(t){S&&(t.preventDefault(),O(t)),T&&(t.preventDefault(),A(t)),R&&(t.preventDefault(),$(t))}function W(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",W),S=!1}function H(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",H),T=!1}function D(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",D),R=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",W),S=!0,O(t)})),C.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",H),T=!0,A(t)})),w.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",D),R=!0,$(t)})),k(),a};let w=8e3;const v=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const o=l("dialog"),i=e,n=document.createElement("div");n.classList.add(o.b()),n.style.zIndex=String(w);const r=document.createElement("div");if(r.classList.add(o.be("overlay")),n.appendChild(r),t){const e=document.createElement("div");e.classList.add(o.be("content")),e.appendChild(t),r.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const a=getComputedStyle(i).overflow;i.style.overflow="hidden",i.appendChild(n);const c=()=>{s(),n.remove(),i.style.overflow=a};return n.addEventListener("click",c),w+=1,{dialog:n,close:c}},x=(t,e)=>{const s=l("input");e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,o.appendChild(e)}const i=document.createElement("div");i.classList.add(s.be("input"));const n=document.createElement("input");for(const t in e)n.setAttribute(t,e[t]);(e.max||e.min)&&n.addEventListener("blur",(()=>{e.max&&e.max<=Number(n.value)&&(n.value=String(e.max)),e.min&&e.min>=Number(n.value)&&(n.value=String(e.min))})),i.appendChild(n),o.appendChild(i),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:n,errorTip:t=>{let e;i.classList.contains("error")?e=i.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),i.appendChild(e)),e.textContent=t,i.classList.add("error");return{removeError:()=>{i.classList.remove("error"),e.remove()}}}}},C=(t={})=>{const e=l("select-box"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("block"));for(let s=0;s<(t.row||8);s++)for(let i=0;i<(t.col||8);i++){const t=document.createElement("div");t.classList.add(e.be("item")),t.dataset.row=String(s+1),t.dataset.col=String(i+1),o.appendChild(t)}const i=()=>{const{row:t,col:e}=s.dataset;for(const t of Array.from(o.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;const i=Array.from(o.children);for(let s=0;st&&n>e)return;o<=t&&n<=e?i[s].classList.add("active"):i[s].classList.remove("active")}};if(o.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:e,col:o}=t.target.dataset;e&&o&&(s.dataset.row=e,s.dataset.col=o,i())})),o.addEventListener("mouseleave",(()=>{s.removeAttribute("data-row"),s.removeAttribute("data-col"),i()})),o.addEventListener("click",(()=>{const{row:e,col:o}=s.dataset;e&&o&&t.onSelect&&t.onSelect(Number(e),Number(o))})),s.appendChild(o),t.customBtn){const o=t.texts||{},i=document.createElement("div");i.classList.add(e.be("custom")),i.textContent=o.customBtnText||"Custom",i.addEventListener("click",(async()=>{const e=await(async(t={})=>{const e=l("creator"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("input"));const{item:i,input:n,errorTip:r}=x(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:c,errorTip:h}=x(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(a),s.appendChild(o);const u=document.createElement("div");u.classList.add(e.be("control"));const p=d({type:"confirm",content:t.confirmText||"Confirm"}),b=d({type:"default",content:t.cancelText||"Cancel"});u.appendChild(p),u.appendChild(b),s.appendChild(u);const m=(e=Number(n.value),s=Number(c.value))=>{if(Number.isNaN(e)||e<=0)r(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(s)||s<=0))return{row:e,col:s};h(t.notPositiveNumberError||"Please enter a positive integer")}},f=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",f))};return new Promise(((t,e)=>{const{close:o}=v({child:s,beforeClose:e});n.focus();for(const e of[n,c])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=m();e&&(t(e),o())}}));p.addEventListener("click",(async()=>{const e=m();e&&(t(e),o())})),document.addEventListener("keydown",f),b.addEventListener("click",o)}))})(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s},y=Math.min,M=Math.max,I=Math.round,L=Math.floor,N=t=>({x:t,y:t}),E={left:"right",right:"left",bottom:"top",top:"bottom"},S={start:"end",end:"start"};function T(t,e,s){return M(t,y(e,s))}function R(t,e){return"function"==typeof t?t(e):t}function B(t){return t.split("-")[0]}function k(t){return t.split("-")[1]}function z(t){return"x"===t?"y":"x"}function O(t){return"y"===t?"height":"width"}function A(t){return["top","bottom"].includes(B(t))?"y":"x"}function $(t){return z(A(t))}function q(t){return t.replace(/start|end/g,(t=>S[t]))}function W(t){return t.replace(/left|right|bottom|top/g,(t=>E[t]))}function H(t){const{x:e,y:s,width:o,height:i}=t;return{width:o,height:i,top:s,left:e,right:e+o,bottom:s+i,x:e,y:s}}function D(t,e,s){let{reference:o,floating:i}=t;const n=A(e),l=$(e),r=O(l),a=B(e),c="y"===n,d=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,u=o[r]/2-i[r]/2;let p;switch(a){case"top":p={x:d,y:o.y-i.height};break;case"bottom":p={x:d,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:h};break;case"left":p={x:o.x-i.width,y:h};break;default:p={x:o.x,y:o.y}}switch(k(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function F(t,e){var s;void 0===e&&(e={});const{x:o,y:i,platform:n,rects:l,elements:r,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:u=!1,padding:p=0}=R(e,t),b=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),m=r[u?"floating"===h?"reference":"floating":h],f=H(await n.getClippingRect({element:null==(s=await(null==n.isElement?void 0:n.isElement(m)))||s?m:m.contextElement||await(null==n.getDocumentElement?void 0:n.getDocumentElement(r.floating)),boundary:c,rootBoundary:d,strategy:a})),g="floating"===h?{x:o,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(null==n.getOffsetParent?void 0:n.getOffsetParent(r.floating)),v=await(null==n.isElement?void 0:n.isElement(w))&&await(null==n.getScale?void 0:n.getScale(w))||{x:1,y:1},x=H(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-x.top+b.top)/v.y,bottom:(x.bottom-f.bottom+b.bottom)/v.y,left:(f.left-x.left+b.left)/v.x,right:(x.right-f.right+b.right)/v.x}}function j(){return"undefined"!=typeof window}function P(t){return Y(t)?(t.nodeName||"").toLowerCase():"#document"}function V(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function X(t){var e;return null==(e=(Y(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function Y(t){return!!j()&&(t instanceof Node||t instanceof V(t).Node)}function _(t){return!!j()&&(t instanceof Element||t instanceof V(t).Element)}function U(t){return!!j()&&(t instanceof HTMLElement||t instanceof V(t).HTMLElement)}function K(t){return!(!j()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof V(t).ShadowRoot)}function Z(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=st(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function G(t){return["table","td","th"].includes(P(t))}function Q(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function J(t){const e=tt(),s=_(t)?st(t):t;return"none"!==s.transform||"none"!==s.perspective||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function tt(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function et(t){return["html","body","#document"].includes(P(t))}function st(t){return V(t).getComputedStyle(t)}function ot(t){return _(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function it(t){if("html"===P(t))return t;const e=t.assignedSlot||t.parentNode||K(t)&&t.host||X(t);return K(e)?e.host:e}function nt(t){const e=it(t);return et(e)?t.ownerDocument?t.ownerDocument.body:t.body:U(e)&&Z(e)?e:nt(e)}function lt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=nt(t),n=i===(null==(o=t.ownerDocument)?void 0:o.body),l=V(i);if(n){const t=rt(l);return e.concat(l,l.visualViewport||[],Z(i)?i:[],t&&s?lt(t):[])}return e.concat(i,lt(i,[],s))}function rt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function at(t){const e=st(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=U(t),n=i?t.offsetWidth:s,l=i?t.offsetHeight:o,r=I(s)!==n||I(o)!==l;return r&&(s=n,o=l),{width:s,height:o,$:r}}function ct(t){return _(t)?t:t.contextElement}function dt(t){const e=ct(t);if(!U(e))return N(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:n}=at(e);let l=(n?I(s.width):s.width)/o,r=(n?I(s.height):s.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const ht=N(0);function ut(t){const e=V(t);return tt()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:ht}function pt(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),n=ct(t);let l=N(1);e&&(o?_(o)&&(l=dt(o)):l=dt(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==V(t))&&e}(n,s,o)?ut(n):N(0);let a=(i.left+r.x)/l.x,c=(i.top+r.y)/l.y,d=i.width/l.x,h=i.height/l.y;if(n){const t=V(n),e=o&&_(o)?V(o):o;let s=t,i=rt(s);for(;i&&o&&e!==s;){const t=dt(i),e=i.getBoundingClientRect(),o=st(i),n=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x,l=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;a*=t.x,c*=t.y,d*=t.x,h*=t.y,a+=n,c+=l,s=V(i),i=rt(s)}}return H({width:d,height:h,x:a,y:c})}function bt(t,e){const s=ot(t).scrollLeft;return e?e.left+s:pt(X(t)).left+s}function mt(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:bt(t,o)),y:o.top+e.scrollTop}}function ft(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=V(t),o=X(t),i=s.visualViewport;let n=o.clientWidth,l=o.clientHeight,r=0,a=0;if(i){n=i.width,l=i.height;const t=tt();(!t||t&&"fixed"===e)&&(r=i.offsetLeft,a=i.offsetTop)}return{width:n,height:l,x:r,y:a}}(t,s);else if("document"===e)o=function(t){const e=X(t),s=ot(t),o=t.ownerDocument.body,i=M(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),n=M(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-s.scrollLeft+bt(t);const r=-s.scrollTop;return"rtl"===st(o).direction&&(l+=M(e.clientWidth,o.clientWidth)-i),{width:i,height:n,x:l,y:r}}(X(t));else if(_(e))o=function(t,e){const s=pt(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,n=U(t)?dt(t):N(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:i*n.x,y:o*n.y}}(e,s);else{const s=ut(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return H(o)}function gt(t,e){const s=it(t);return!(s===e||!_(s)||et(s))&&("fixed"===st(s).position||gt(s,e))}function wt(t,e,s){const o=U(e),i=X(e),n="fixed"===s,l=pt(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=N(0);if(o||!o&&!n)if(("body"!==P(e)||Z(i))&&(r=ot(e)),o){const t=pt(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=bt(i));const c=!i||o||n?N(0):mt(i,r);return{x:l.left+r.scrollLeft-a.x-c.x,y:l.top+r.scrollTop-a.y-c.y,width:l.width,height:l.height}}function vt(t){return"static"===st(t).position}function xt(t,e){if(!U(t)||"fixed"===st(t).position)return null;if(e)return e(t);let s=t.offsetParent;return X(t)===s&&(s=s.ownerDocument.body),s}function Ct(t,e){const s=V(t);if(Q(t))return s;if(!U(t)){let e=it(t);for(;e&&!et(e);){if(_(e)&&!vt(e))return e;e=it(e)}return s}let o=xt(t,e);for(;o&&G(o)&&vt(o);)o=xt(o,e);return o&&et(o)&&vt(o)&&!J(o)?s:o||function(t){let e=it(t);for(;U(e)&&!et(e);){if(J(e))return e;if(Q(e))return null;e=it(e)}return null}(t)||s}const yt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const n="fixed"===i,l=X(o),r=!!e&&Q(e.floating);if(o===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=N(1);const d=N(0),h=U(o);if((h||!h&&!n)&&(("body"!==P(o)||Z(l))&&(a=ot(o)),U(o))){const t=pt(o);c=dt(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!l||h||n?N(0):mt(l,a,!0);return{width:s.width*c.x,height:s.height*c.y,x:s.x*c.x-a.scrollLeft*c.x+d.x+u.x,y:s.y*c.y-a.scrollTop*c.y+d.y+u.y}},getDocumentElement:X,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const n=[..."clippingAncestors"===s?Q(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=lt(t,[],!1).filter((t=>_(t)&&"body"!==P(t))),i=null;const n="fixed"===st(t).position;let l=n?it(t):t;for(;_(l)&&!et(l);){const e=st(l),s=J(l);s||"fixed"!==e.position||(i=null),(n?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||Z(l)&&!s&>(t,l))?o=o.filter((t=>t!==l)):i=e,l=it(l)}return e.set(t,o),o}(e,this._c):[].concat(s),o],l=n[0],r=n.reduce(((t,s)=>{const o=ft(e,s,i);return t.top=M(o.top,t.top),t.right=y(o.right,t.right),t.bottom=y(o.bottom,t.bottom),t.left=M(o.left,t.left),t}),ft(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:Ct,getElementRects:async function(t){const e=this.getOffsetParent||Ct,s=this.getDimensions,o=await s(t.floating);return{reference:wt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:s}=at(t);return{width:e,height:s}},getScale:dt,isElement:_,isRTL:function(t){return"rtl"===st(t).direction}};function Mt(t,e,s,o){void 0===o&&(o={});const{ancestorScroll:i=!0,ancestorResize:n=!0,elementResize:l="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=o,c=ct(t),d=i||n?[...c?lt(c):[],...lt(e)]:[];d.forEach((t=>{i&&t.addEventListener("scroll",s,{passive:!0}),n&&t.addEventListener("resize",s)}));const h=c&&r?function(t,e){let s,o=null;const i=X(t);function n(){var t;clearTimeout(s),null==(t=o)||t.disconnect(),o=null}return function l(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),n();const{left:c,top:d,width:h,height:u}=t.getBoundingClientRect();if(r||e(),!h||!u)return;const p={rootMargin:-L(d)+"px "+-L(i.clientWidth-(c+h))+"px "+-L(i.clientHeight-(d+u))+"px "+-L(c)+"px",threshold:M(0,y(1,a))||1};let b=!0;function m(t){const e=t[0].intersectionRatio;if(e!==a){if(!b)return l();e?l(!1,e):s=setTimeout((()=>{l(!1,1e-7)}),1e3)}b=!1}try{o=new IntersectionObserver(m,{...p,root:i.ownerDocument})}catch(t){o=new IntersectionObserver(m,p)}o.observe(t)}(!0),n}(c,s):null;let u,p=-1,b=null;l&&(b=new ResizeObserver((t=>{let[o]=t;o&&o.target===c&&b&&(b.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame((()=>{var t;null==(t=b)||t.observe(e)}))),s()})),c&&!a&&b.observe(c),b.observe(e));let m=a?pt(t):null;return a&&function e(){const o=pt(t);!m||o.x===m.x&&o.y===m.y&&o.width===m.width&&o.height===m.height||s();m=o,u=requestAnimationFrame(e)}(),s(),()=>{var t;d.forEach((t=>{i&&t.removeEventListener("scroll",s),n&&t.removeEventListener("resize",s)})),null==h||h(),null==(t=b)||t.disconnect(),b=null,a&&cancelAnimationFrame(u)}}const It=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var s,o;const{x:i,y:n,placement:l,middlewareData:r}=e,a=await async function(t,e){const{placement:s,platform:o,elements:i}=t,n=await(null==o.isRTL?void 0:o.isRTL(i.floating)),l=B(s),r=k(s),a="y"===A(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=R(e,t);let{mainAxis:u,crossAxis:p,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return r&&"number"==typeof b&&(p="end"===r?-1*b:b),a?{x:p*d,y:u*c}:{x:u*c,y:p*d}}(e,t);return l===(null==(s=r.offset)?void 0:s.placement)&&null!=(o=r.arrow)&&o.alignmentOffset?{}:{x:i+a.x,y:n+a.y,data:{...a,placement:l}}}}},Lt=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:s,y:o,placement:i}=e,{mainAxis:n=!0,crossAxis:l=!1,limiter:r={fn:t=>{let{x:e,y:s}=t;return{x:e,y:s}}},...a}=R(t,e),c={x:s,y:o},d=await F(e,a),h=A(B(i)),u=z(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=T(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=T(b+d["y"===h?"top":"left"],b,b-d[t])}const m=r.fn({...e,[u]:p,[h]:b});return{...m,data:{x:m.x-s,y:m.y-o,enabled:{[u]:n,[h]:l}}}}}},Nt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var s,o;const{placement:i,middlewareData:n,rects:l,initialPlacement:r,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:u,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:m=!0,...f}=R(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=B(i),w=A(r),v=B(r)===r,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),C=u||(v||!m?[W(r)]:function(t){const e=W(t);return[q(t),e,q(e)]}(r)),y="none"!==b;!u&&y&&C.push(...function(t,e,s,o){const i=k(t);let n=function(t,e,s){const o=["left","right"],i=["right","left"],n=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return s?e?i:o:e?o:i;case"left":case"right":return e?n:l;default:return[]}}(B(t),"start"===s,o);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map(q)))),n}(r,m,b,x));const M=[r,...C],I=await F(e,f),L=[];let N=(null==(o=n.flip)?void 0:o.overflows)||[];if(d&&L.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=k(t),i=$(t),n=O(i);let l="x"===i?o===(s?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=W(l)),[l,W(l)]}(i,l,x);L.push(I[t[0]],I[t[1]])}if(N=[...N,{placement:i,overflows:L}],!L.every((t=>t<=0))){var E,S;const t=((null==(E=n.flip)?void 0:E.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:N},reset:{placement:e}};let s=null==(S=N.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:S.placement;if(!s)switch(p){case"bestFit":{var T;const t=null==(T=N.filter((t=>{if(y){const e=A(t.placement);return e===w||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:T[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},Et=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:s,y:o,placement:i,rects:n,middlewareData:l}=e,{offset:r=0,mainAxis:a=!0,crossAxis:c=!0}=R(t,e),d={x:s,y:o},h=A(i),u=z(h);let p=d[u],b=d[h];const m=R(r,e),f="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const t="y"===u?"height":"width",e=n.reference[u]-n.floating[t]+f.mainAxis,s=n.reference[u]+n.reference[t]-f.mainAxis;ps&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(B(i)),s=n.reference[h]-n.floating[t]+(e&&(null==(g=l.offset)?void 0:g[h])||0)+(e?0:f.crossAxis),o=n.reference[h]+n.reference[t]+(e?0:(null==(w=l.offset)?void 0:w[h])||0)-(e?f.crossAxis:0);bo&&(b=o)}return{[u]:p,[h]:b}}}},St=(t,e,s)=>{const o=new Map,i={platform:yt,...s},n={...i.platform,_c:o};return(async(t,e,s)=>{const{placement:o="bottom",strategy:i="absolute",middleware:n=[],platform:l}=s,r=n.filter(Boolean),a=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:h}=D(c,o,a),u=o,p={},b=0;for(let s=0;s{const{msg:s="",delay:o=150,content:i,direction:n="bottom",type:r="hover",container:a,onOpen:c,onClose:d,closed:h,onDestroy:u}=e,p=l("tooltip");if(s||i){Tt||(Tt=document.createElement("div"),document.body.appendChild(Tt));const e=a||Tt,l=document.createElement("div");let b,m,f;l.classList.add(p.b(),"hidden","transparent"),i?l.appendChild(i):s&&(l.textContent=s);const g=()=>{f&&f(),St(t,l,{placement:n,middleware:[Nt(),Lt({limiter:Et()}),It(4)]}).then((({x:t,y:e})=>{Object.assign(l.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{l.classList.add("hidden"),e.contains(l)&&e.removeChild(l),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(c){const t=c(s);if(!s&&t)return}e.appendChild(l),l.removeEventListener("transitionend",w),l.classList.remove("hidden"),f=Mt(t,l,g),l.classList.remove("transparent")}),o)},x=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}l.addEventListener("transitionend",w,{once:!0}),l.classList.add("transparent")}),o)},C=()=>{const e=t=>{t.stopPropagation(),x(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{l.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{x(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,l],s=x.bind(void 0,!1),o=v.bind(void 0,!1);return{prepare:()=>{for(const t of e)t.addEventListener("mouseenter",o),t.addEventListener("mouseleave",s)},show:v,hide:x,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",o),t.removeEventListener("mouseleave",s)}}},click:C},{prepare:M,show:I,hide:L,destroy:N}=y[r]();M();const E=()=>{L(!0),u&&u(),N(),f&&f(),l.remove()};return{show:I,hide:L,destroy:E}}return null};function Bt(t,e,s=4){const{x:o,y:i,x1:n,y1:l}=t,{x:r,y:a,x1:c,y1:d}=e;return!(n<=r+s||o+s>=c||(l<=a+s||i+s>=d))}const kt=()=>Math.random().toString(36).slice(2),zt=(t,e)=>{let s;return function(...o){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,o)}),e)}};function Ot(t,e){let s=t.parent;for(;s&&s.statics.blotName!==e&&s!==t.scroll;)s=s.parent;if(s===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return s}function At(t,e){const s=new Array(e.length),o=new Map(e.map(((t,e)=>[t,e])));let i=t.parent;for(;i&&i!==t.scroll&&0!==o.size;){if(o.has(i.statics.blotName)){s[o.get(i.statics.blotName)]=i,o.delete(i.statics.blotName)}i=i.parent}if(o.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(o.keys()).join(", ")}`);return s}function $t(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}function qt(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)$t(s.prototype,t.prototype);return s}const Wt=t=>{let{left:e,top:s,width:o,height:i}=t;const{clientWidth:n,clientHeight:l}=document.documentElement;let r=!1,a=!1;return e+o>n?(e=n-o-8,r=!0):e<0&&(e=8,r=!0),s+i>l?(s=l-i-8,a=!0):s<0&&(s=8,a=!0),{left:e,top:s,leftLimited:r,topLimited:a}};function Ht(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Dt(){for(let t=0;t0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const Yt=e.import("parchment"),_t=e.import("blots/block");class Ut extends _t{replaceWith(t,e){const o="string"==typeof t?this.scroll.create(t,e):t;if(o instanceof Yt.ParentBlot){if(o.statics.blotName===s.tableCellInner){const t=this.parent;if(t.statics.blotName===s.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),this.parent.statics.blotName===s.tableCellInner&&this.prev){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.parent.remove();const e=t.parent.parent;e.statics.blotName===s.tableRow&&0===e.children.length&&e.remove()}}else null!=t&&t.insertBefore(o,this.next),o.appendChild(this);return o}this.moveChildren(o)}return null!=this.parent&&(this.parent.insertBefore(o,this.next||void 0),this.remove()),this.attributes.copy(o),o}format(t,e){if(t!==s.tableCellInner||this.parent.statics.blotName!==t||e)super.format(t,e);else{const[t,e,o]=At(this,[s.tableCell,s.tableRow,s.tableWrapper]),i=o.next;let n=e.next,l=t.next;for(o.parent.insertBefore(this,i);l;){const t=l.next;o.parent.insertBefore(l,i),l=t}for(;n;){const t=n.next;o.parent.insertBefore(n,i),n=t}}}}const Kt=e.import("formats/blockquote");class Zt extends(qt(Kt,[Ut])){}const Gt=e.import("formats/code-block");class Qt extends(qt(Gt,[Ut])){}const Jt=e.import("formats/header");class te extends(qt(Jt,[Ut])){}const ee=e.import("formats/list");class se extends(qt(ee,[Ut])){static register(){}}const oe=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},ie=e.import("blots/block"),ne=e.import("blots/block/embed");class le extends Xt{static blotName=s.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan"]);static defaultChild=ie;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=o,r.dataset.rowspan=String(oe(i)),r.dataset.colspan=String(oe(n)),l&&(r.dataset.style=l),r}static formats(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:n,style:l}=t.dataset,r={tableId:e,rowId:s,colId:o,rowspan:Number(oe(i)),colspan:Number(oe(n))};return l&&(r.style=l),r}setFormatValue(t,e,s=!1){if(s){if(!this.statics.isAllowStyle(t))return;this.parent&&(this.parent.setFormatValue(t,e),this.domNode.dataset.style=this.parent.domNode.style.cssText)}else{if(!this.statics.allowDataAttrs.has(t))return;const s=`data-${t}`;e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s),this.parent&&this.parent.setFormatValue(t,e)}const o=this.descendants(ie,0);for(const t of o)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(t){this.setFormatValue("row-id",t)}get colId(){return this.domNode.dataset.colId}set colId(t){this.setFormatValue("col-id",t)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(t){this.setFormatValue("rowspan",t)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(t){this.setFormatValue("colspan",t)}getColumnIndex(){return Ot(this,s.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,o){0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,o)}formats(){const t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:o}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===s&&i.rowspan===o}optimize(){const t=this.parent,e=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof ne){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==s.tableCell&&(this.wrap(s.tableCell,e),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,e){if(t.statics.blotName===this.statics.blotName){const o=t,i=this.statics.formats(o.domNode),n=this.statics.formats(this.domNode);if(Object.entries(n).every((([t,e])=>e===i[t])))return this.parent.insertBefore(o,this.next);{const[t,l]=At(this,[s.tableRow,s.tableCell]);if(e){const o=e.offset();if(o+1{e.appendChild(t)})),t.insertBefore(e.wrap(s.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(e){const s=e.offset(t);t.split(s)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(s.tableRow,i),r=this.scroll.create(s.tableCell,i);return r.appendChild(o),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(o.wrap(s.tableCell,i),e?l:l.next)}}super.insertBefore(t,e)}}const re=e.import("parchment"),ae=e.import("blots/scroll");class ce extends ae{createBlock(t,e){let o,i={};if(t[s.tableCellInner])o=s.tableCellInner;else for(const[e,s]of Object.entries(t)){null!=this.query(e,re.Scope.BLOCK&re.Scope.BLOT)?o=e:i[e]=s}o===s.tableCellInner&&(i={...t},delete i[o]);const n=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(n,e||void 0);let l=n.length();n instanceof le&&0===l&&(l+=1);for(const[t,e]of Object.entries(i))n.formatAt(0,l,t,e);return n}}class de extends Xt{static blotName=s.tableRow;static tagName="tr";static className="ql-table-row";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,e.dataset.rowId=t.rowId,e}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}insertCell(t,e){const o=[],i=this.children.iterator();let n,l=0;for(;(n=i())&&(l+=n.colspan,!(l>t));)if(1!==n.rowspan)for(let t=0;tt)break}return[s,o,e]}removeCell(t){if(t<0)return[];const e=this.getCellByColumIndex(t),[o,i]=e,n=e[2];if(!o)return n;if(i-o.colspan1){const[e]=o.descendants(le);if(1!==o.colspan&&t===i-o.colspan){const t=Ot(this,s.tableMain).getColIds();e.colId=t[t.indexOf(e.colId)+1]}1!==o.rowspan&&(n.skipRowNum=o.rowspan-1),e.colspan-=1}else o.remove();return n}foreachCellInner(t){const e=this.children.iterator();let s,o=0;for(;s=e();){const[e]=s.descendants(le);if(t(e,o++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const e=this.parent,{tableId:o}=this;null!==e&&e.statics.blotName!==s.tableBody&&this.wrap(s.tableBody,o),super.optimize(t)}}class he extends Xt{static blotName=s.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const e=Ot(this,s.tableMain);if(!e)return;const o=e.getColIds(),i=this.descendants(de),n=new Set(o);let l=0;for(const e of i){if(l===t)break;e.foreachCellInner((e=>{if(l+e.rowspan>t&&(e.rowspan+=1,n.delete(e.colId),1!==e.colspan)){const t=o.indexOf(e.colId);for(let s=0;s0&&(l.style=a.map((([t,e])=>`${t}:${e}`)).join(";")),l}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let s=t;this.statics.allowDataAttrs.has(t)&&(s=`data-${t}`),e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s)}else this.statics.isAllowStyle(t)&&Object.assign(this.domNode.style,{[t]:e})}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute("rowspan"))}get colspan(){return Number(this.domNode.getAttribute("colspan"))}getCellInner(){return this.children.head}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:o}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===s&&i.rowspan===o}optimize(t){const e=this.parent,{tableId:o,rowId:i}=this;null!==e&&e.statics.blotName!==s.tableRow&&this.wrap(s.tableRow,{tableId:o,rowId:i}),super.optimize(t)}}const pe=e.import("blots/block/embed");class be extends pe{scroll;domNode;static blotName=s.tableCol;static tagName="col";static validWidth(t,e){let s=Number.parseFloat(String(t));return Number.isNaN(s)&&(s=o[e?"colMinWidthPre":"colMinWidthPx"]),`${s}${e?"%":"px"}`}static create(t){const{width:e,tableId:s,colId:o,full:i,align:n}=t,l=super.create();return l.setAttribute("width",this.validWidth(e,!!i)),i&&(l.dataset.full=String(i)),n&&"left"!==n&&(l.dataset.align=n),l.dataset.tableId=s,l.dataset.colId=o,l}static value(t){const{tableId:e,colId:s}=t.dataset,i=t.getAttribute("width")||o.colDefaultWidth,n=t.dataset.align,l={tableId:e,colId:s,full:Object.hasOwn(t.dataset,"full")};return i&&(l.width=Number.parseFloat(i)),n&&(l.align=n),l}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){const e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:o[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=o[this.full?"colMinWidthPre":"colMinWidthPx"]),this.domNode.setAttribute("width",this.statics.validWidth(e,!!this.full))}get tableId(){return this.domNode.dataset.tableId}get colId(){return this.domNode.dataset.colId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){const t=this.next,{tableId:e,colId:s}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===s}optimize(t){const e=this.parent;if(null!=e&&e.statics.blotName!==s.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(s.tableColgroup,t)}Ot(this,s.tableColgroup).align=this.align,super.optimize(t)}insertAt(t,e,o){if(null!=o)return void super.insertAt(t,e,o);const i=e.split("\n"),n=i.pop(),l=i.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),r=this.split(t),[a,c]=At(this,[s.tableColgroup,s.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let h=c.parent.parent,u=c.parent.next;if(d){const t=d.descendants(le);if(t.length>0){const e=t[0],o=le.formats(e.domNode),i=this.scroll.create("block"),n=i.wrap(s.tableCellInner,o).wrap(s.tableCell,o).wrap(s.tableRow,o).wrap(s.tableBody,o.tableId);a.parent.insertBefore(n,a.next),h=i,u=i.next}}for(const t of l)h.insertBefore(t,u);n&&h.insertBefore(this.scroll.create("text",n),u)}}class me extends Xt{static blotName=s.tableMain;static tagName="table";static className="ql-table";static create(t){const e=super.create(),{tableId:s,full:o,align:i}=t;return e.dataset.tableId=s,"right"===i||"center"===i?e.dataset.align=i:e.removeAttribute("date-align"),o&&(e.dataset.full=String(o)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,s){super(t,e),this.updateAlign()}colWidthFillTable(){if(this.full)return;const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?null:(this.domNode.style.width=`${e}px`,e)}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align"),this.updateAlign()}cancelFull(){if(!this.full)return;const t=this.getCols(),e=this.domNode.getBoundingClientRect().width;for(const s of t)s.domNode.removeAttribute("data-full"),s.width=s.width/100*e;const o=this.children.head;o&&o.statics.blotName===s.tableColgroup&&(o.full=!1),this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}updateAlign(){const t={marginLeft:null,marginRight:null};switch(this.align){case"center":t.marginLeft="auto",t.marginRight="auto";break;case"":case"left":t.marginRight="auto";break;case"right":t.marginLeft="auto"}Object.assign(this.domNode.style,t)}getRows(){return this.descendants(de)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(be)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const e=this.parent;null!==e&&e.statics.blotName!==s.tableWrapper&&this.wrap(s.tableWrapper,this.tableId),super.optimize(t)}}class fe extends Xt{static blotName=s.tableColgroup;static tagName="colgroup";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full="true":this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let s,o=0;for(;(s=e())&&o!==t;)o++;return s}insertColByIndex(t,e){const i=this.parent;if(!(i instanceof me))throw new TypeError("TableColgroupFormat should be child of TableFormat");const n=this.findCol(t),l=this.scroll.create(s.tableCol,e);if(i.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=o.colMinWidthPre){e.width-=l.width;break}}this.insertBefore(l,n)}removeColByIndex(t){const e=this.parent;if(!(e instanceof me))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const s=this.findCol(t);s&&(e.full&&(s.next?s.next.width+=s.width:s.prev&&(s.prev.width+=s.width)),s.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof me&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent,{tableId:o,full:i,align:n}=this;null!=e&&e.statics.blotName!==s.tableMain&&this.wrap(s.tableMain,{tableId:o,full:i,align:n});Ot(this,s.tableMain).align=n,super.optimize(t)}}class ge extends Xt{static blotName=s.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){const e=super.create();return e.dataset.tableId=t,e.addEventListener("dragstart",(t=>{t.preventDefault(),t.stopPropagation()}),!0),e.addEventListener("drop",(t=>{t.preventDefault()})),e.addEventListener("dragover",(t=>{t.preventDefault(),t.dataTransfer.dropEffect="none"})),e}get tableId(){return this.domNode.dataset.tableId}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}deleteAt(t,e){super.deleteAt(t,e);const s=this.descendants(he),o=this.descendants(fe);0!==s.length&&0!==o.length||this.remove()}}const we="color-selector",ve=[{name:"InsertTop",icon:'',tip:"Insert row above",handle:t=>{t.appendRow(!1),t.hideTableTools()}},{name:"InsertRight",icon:'',tip:"Insert column right",handle:t=>{t.appendCol(!0),t.hideTableTools()}},{name:"InsertBottom",icon:'',tip:"Insert row below",handle:t=>{t.appendRow(!0),t.hideTableTools()}},{name:"InsertLeft",icon:'',tip:"Insert column Left",handle:t=>{t.appendCol(!1),t.hideTableTools()}},{name:"break"},{name:"MergeCell",icon:'',tip:"Merge Cell",handle:t=>{t.mergeCells(),t.hideTableTools()}},{name:"SplitCell",icon:'',tip:"Split Cell",handle:t=>{t.splitCell(),t.hideTableTools()}},{name:"break"},{name:"DeleteRow",icon:'',tip:"Delete Row",handle:t=>{t.removeRow(),t.hideTableTools()}},{name:"DeleteColumn",icon:'',tip:"Delete Column",handle:t=>{t.removeCol(),t.hideTableTools()}},{name:"DeleteTable",icon:'',tip:"Delete table",handle:t=>{t.deleteTable()}},{name:"break"},{name:"BackgroundColor",icon:'',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},{name:"BorderColor",icon:'',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}}],xe=new Set,Ce=l("color-map"),ye={selectWrapper:Ce.b(),used:Ce.bm("used"),item:Ce.be("item"),btn:Ce.be("btn"),map:Ce.be("content"),mapRow:Ce.be("content-row")};class Me{tableModule;quill;options;menu=null;updateUsedColor;tooltipItem=[];bem=l("menu");colorItemClass=`color-${kt()}`;colorChooseTooltipOption={direction:"top"};constructor(t,e,s){this.tableModule=t,this.quill=e,this.options=this.resolveOptions(s);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);a(e)||(e=[]),e.slice(-10).map((t=>xe.add(t)))}catch{}this.updateUsedColor=zt((t=>{if(!t)return;if(xe.add(t),xe.size>10){const t=Array.from(xe).slice(-10);xe.clear(),t.map((t=>xe.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(xe)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${ye.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${ye.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${ye.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3)}resolveOptions(t){return Object.assign({tipText:!0,tipTexts:{},tools:ve,localstorageKey:"__table-bg-used-color",defaultColorMap:n},t)}getUsedColors(){return xe}buildTools(){const t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:s,icon:o,handle:i,isColorChoose:n,key:l,tip:a=""}=e,c=document.createElement("span");if(c.classList.add(this.bem.be("item")),"break"===s)c.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),r(o)?t.appendChild(o(this.tableModule)):t.innerHTML=o,c.appendChild(t),n&&l){const t=this.createColorChoose(c,{name:s,icon:o,handle:i,isColorChoose:n,key:l,tip:a});this.tooltipItem.push(t),c.classList.add(we)}else r(i)&&c.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.options.tipTexts[s]||a;this.options.tipText&&e&&a&&this.createTipText(c,e)}t.appendChild(c)}return t}createColorChoose(t,{handle:e,key:s}){const o=document.createElement("div");if(o.classList.add(ye.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(ye.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(ye.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(ye.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(ye.btn,"transparent"),n.textContent=this.tableModule.options.texts.transparent,n.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),"transparent")}));const l=document.createElement("div");l.classList.add(ye.btn,"clear"),l.textContent=this.tableModule.options.texts.clear,l.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),null)}));const r=document.createElement("div");r.classList.add(ye.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=g({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Rt(r,{direction:"right",type:"click",content:a,container:r});if(i.appendChild(n),i.appendChild(l),i.appendChild(r),o.appendChild(i),xe.size>0){const t=document.createElement("div");t.classList.add(ye.used,this.colorItemClass);for(const e of xe){const s=document.createElement("div");s.classList.add(ye.item),s.style.backgroundColor=e,t.appendChild(s)}o.appendChild(t)}return o.addEventListener("click",(t=>{t.stopPropagation(),c();const e=t.target,o=e.style.backgroundColor,i=this.getSelectedTds();if(e&&o&&i.length>0){if(this.tableModule.setCellAttrs(i,s,o,!0),!e.closest(`.${ye.item}`))return;this.updateUsedColor(o)}})),Rt(t,{content:o,onClose(t){const e=o.contains(a);return t&&e&&c(),e},onDestroy(){d()},...this.colorChooseTooltipOption})}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Rt(t,{msg:e});s&&this.tooltipItem.push(s)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&Object.assign(this.menu.style,{display:"flex"})}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0)}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}const Ie=t=>!t.full&&"right"===t.align;class Le{tableModule;quill;colIndex=-1;tableMain;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=l("drag-line");constructor(t,e){this.tableModule=t,this.quill=e}findCurrentColIndex(t){return-1}colWidthChange(t,e,s){}async createConfirmDialog({message:t,confirm:e,cancel:s}){return new Promise((o=>{const i=document.createElement("div");Object.assign(i.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});const n=document.createElement("p");n.textContent=t;const l=document.createElement("div");Object.assign(l.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});const r=d({content:s}),a=d({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=v({child:i});r.addEventListener("click",(()=>{o(!1),c()})),a.addEventListener("click",(()=>{o(!0),c()}))}))}async handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0");let s=this.tableMain.full,n=!1;const l=[];if(s){let s=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(s(o+=e,t))));for(const[e,s]of t.entries())i.has(e)||(o+=s.width);if(o>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableMain.cancelFull(),s=!1;for(const[t,s]of l.entries()){const{width:o,index:i}=s;l[t]={index:i,width:o/100*e}}}}for(const{index:o,width:i}of l)t[o].width=`${Math.round(i)}${s?"%":"px"}`,this.colWidthChange(o,s?i/100*e:i,s)}this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),s=e[this.colIndex].domNode.getBoundingClientRect(),i=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=o.colMinWidthPre/100*i.width;let l=i.right;n>s.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,s.left+t));const r=s.x+t;n=Math.min(Math.max(n,r),l)}else Ie(this.tableMain)?s.right-n{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Ht.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:t,scrollTop:s}=this.quill.root,{offsetLeft:o,offsetTop:i}=this.container,{width:n,height:l}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=o,d=i;this.isVertical?c+=Math.min(n,r):d+=Math.min(l,a);const h=e.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-o),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?l:n}px`,transform:`translate(${c-t}px, ${d-s}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,s=t**2/this.container.scrollHeight,o=e**2/this.container.scrollWidth,i=Math.max(s,this.minSize),n=Math.max(o,this.minSize);this.ratioY=s/(t-s)/(i/(t-i)),this.ratioX=o/(e-o)/(n/(e-n)),this.sizeWidth=n+this.gap{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const s=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],o=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*s/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=o*this.container[this.propertyMap.scrollSize]/100},s=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",s),this.cursorLeave&&this.hideScrollbar()},o=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",e),document.addEventListener("mouseup",s),document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),o(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const i=[this.table,t];for(const t of i)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Ht.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){const e=t[this.propertyMap.offset]-this.gap;this.move=100*t[this.propertyMap.scrollDirection]/e*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=zt((()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?"block":"none",requestAnimationFrame((()=>{this.scrollbar.classList.remove(this.bem.is("transparent"))}))}),200);hideScrollbar=zt((()=>{this.cursorLeave=!0,this.cursorDown||(this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.addEventListener("transitionend",this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is("transparent")))}),200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?"block":"none"};destroy(){this.ob.disconnect(),Dt.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}const Ee=e.import("delta"),Se=e.import("blots/break"),Te=e.import("ui/icons"),Re=(t,{tableId:e,rowId:o,colId:i})=>{const n={tableId:e,rowId:o,colId:i,colspan:1,rowspan:1},l=t.create(s.tableCell,n),r=t.create(s.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l},Be=t=>{let e=Number.parseFloat(t.getAttribute("width")||o.colDefaultWidth);if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e},ke=new Set([s.tableCellInner]),ze=t=>{return!(!t||!t.parent)&&(e=t.parent,!!ke.has(e.statics.blotName)||ze(t.parent));var e};class Oe{static moduleName="table-up";static toolName=s.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,e){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof ge)return o.prev.remove(),!1;if(e.format[s.tableCellInner]){if(0===o.offset(Ot(o,s.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,e){const o=this.quill.getLine(t.index),i=o[0],n=o[1];if((i.next instanceof ge||i.next instanceof be)&&n===i.length()-1)return!1;if(e.format[s.tableCellInner]){if(i===Ot(i,s.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[s.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(t){const[o,i]=this.quill.getLine(t.index);if(this.quill.getFormat(t.index+i+1,1)[s.tableCellInner])return!0;let n=2,l=o;for(;null!==l&&l.length()<=1;)if(l=l.prev,n-=1,n<=0)return this.quill.insertText(t.index+1,"\n"),this.quill.setSelection(t.index+1,e.sources.SILENT),!1;return!0}}};static register(){ge.allowedChildren=[me],me.allowedChildren=[he,fe],me.requiredContainer=ge,fe.allowedChildren=[be],fe.requiredContainer=me,he.allowedChildren=[de],he.requiredContainer=me,de.allowedChildren=[ue],ue.requiredContainer=he,ue.allowedChildren=[le,Se],ue.requiredContainer=de,le.requiredContainer=ue,e.register({"blots/scroll":ce,"blots/block":Ut,[`blots/${s.container}`]:Xt,"formats/header":te,"formats/list":se,"formats/blockquote":Zt,"formats/code-block":Qt,[`formats/${s.tableCell}`]:ue,[`formats/${s.tableCellInner}`]:le,[`formats/${s.tableRow}`]:de,[`formats/${s.tableBody}`]:he,[`formats/${s.tableCol}`]:be,[`formats/${s.tableColgroup}`]:fe,[`formats/${s.tableMain}`]:me,[`formats/${s.tableWrapper}`]:ge},!0)}quill;options;toolBox;fixTableByLisenter=zt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(t,o){if(this.quill=t,this.options=this.resolveOptions(o||{}),!this.options.scrollbar){const t=l("scrollbar");this.quill.container.classList.add(t.bm("origin"))}const n=l("toolbox");this.toolBox=this.quill.addContainer(n.b());const r=this.quill.getModule("toolbar");if(r&&this.quill.theme.pickers){const[,t]=(r.controls||[]).find((([t])=>t===this.statics.toolName))||[];if(t&&"select"===t.tagName.toLocaleLowerCase()){const e=this.quill.theme.pickers.find((e=>e.select===t));e&&(e.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,e),e.label.addEventListener("mousedown",(()=>{if(!this.selector||!e)return;const t=this.selector.getBoundingClientRect(),{leftLimited:s}=Wt(t);if(s){const t=e.label.getBoundingClientRect();Object.assign(e.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(e.options.style,{transform:void 0})})))}}const a=this.quill.getModule("keyboard");for(const t of Object.values(Oe.keyboradHandler))t.bindInHead?a.bindings[t.key].unshift(t):a.addBinding(t.key,t);this.quill.root.addEventListener("click",(e=>{const s=e.composedPath();if(!s||s.length<=0)return;const o=s.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(o){if(this.table===o)return this.tableSelection&&this.tableSelection.show(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(o,t)}else this.table&&this.hideTableTools()}),!1),this.quill.on(e.events.EDITOR_CHANGE,((t,o,i)=>{if(t===e.events.SELECTION_CHANGE&&o){const[t]=this.quill.getLine(o.index),[e]=this.quill.getLine(o.index+o.length);let i,n;try{i=Ot(t,s.tableMain)}catch{}try{n=Ot(e,s.tableMain)}catch{}i&&n||this.hideTableTools()}})),this.quill.on(i.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hide()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if(c(t)){const e=document.createElement("div");for(const s of t.split(" "))e.classList.add(s);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!1,texts:this.resolveTexts(t.texts||{}),full:!1,fullSwitch:!0,icon:Te.table,selectionOptions:{},alignOptions:{},scrollbarOptions:{},resizeOptions:{},resizeScaleOptions:{}},t)}resolveTexts(t){return Object.assign({fullCheckboxText:"Insert full width table",customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer",custom:"Custom",clear:"Clear",transparent:"Transparent",perWidthInsufficient:"The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?"},t)}pasteTableHandler(){let t=kt(),e=kt(),i=[],n=[],l=0,r=0;const a=(t,e,o)=>{const i=this.quill.getSelection(!0),n=this.quill.getFormat(i)[s.tableCellInner];if(n)for(const t of e.ops)t.attributes||(t.attributes={}),t.attributes[s.tableCellInner]=n;return e};this.quill.clipboard.addMatcher(Node.TEXT_NODE,a),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,a),this.quill.clipboard.addMatcher("table",((e,a)=>{if(0===a.ops.length)return a;const c=this.quill.getFormat()[s.tableCellInner],d=[],h=[];for(let t=0;t{const s=new Array(e).fill(o.colDefaultWidth),i=Array.from(t.querySelectorAll("tr"));for(const t of i){const o=Array.from(t.querySelectorAll("td"));for(const[t,i]of o.entries()){if(!(t(h[n]?e.push(h[n]):e.push({insert:{[s.tableCol]:{tableId:t,colId:i[n],width:o,full:!1}}}),e)),[]);d.unshift(...n),d.unshift({insert:"\n"}),d.push({insert:"\n"})}return t=kt(),i=[],n=[],l=0,r=0,new Ee(d)})),this.quill.clipboard.addMatcher("colgroup",((t,e)=>{const o=[];for(let t=0;t{i[r]=kt();const o=(new Ee).insert({[s.tableCol]:Object.assign(be.value(e),{tableId:t,colId:i[r]})});return r+=1,o})),this.quill.clipboard.addMatcher("tr",((t,o)=>{e=kt(),l=0;for(const t of o.ops)if(t.attributes&&t.attributes.background&&t.attributes[s.tableCellInner]){const e=t.attributes[s.tableCellInner];e.style||(e.style=""),t.attributes[s.tableCellInner].style=`background:${t.attributes.background};${e.style}`}for(const[t,e]of n.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(n[t]={rowspan:0,colspan:0});return o}));const c=(o,r)=>{const a=o,c=ue.formats(a);if(!i[l]||!n[l])for(let t=l;t>=0;t--)i[t]||(i[t]=kt()),n[t]||(n[t]={rowspan:0,colspan:0});const{colspan:d}=n[l];l+=d,c.rowspan>1&&(n[l]={rowspan:c.rowspan,colspan:c.colspan});const h=i[l];l+=c.colspan;const u=Object.assign(c,{tableId:t,rowId:e,colId:h});"none"===a.style.border&&(u.style=u.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const p=[];for(const t of r.ops){const{insert:e,attributes:o}=t;if(t.insert){const t={...o};delete t[s.tableCell],p.push({insert:e,attributes:{...t,[s.tableCellInner]:u}})}}return new Ee(p)};this.quill.clipboard.addMatcher("td",c),this.quill.clipboard.addMatcher("th",c)}showTableTools(t,e){t&&(this.table=t,this.options.selection&&(this.tableSelection=new this.options.selection(this,t,e,this.options.selectionOptions)),this.options.align&&(this.tableAlign=new this.options.align(this,t,e,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,e,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,e,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,e,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection&&(this.tableSelection.destroy(),this.tableSelection=void 0),this.tableScrollbar&&(this.tableScrollbar.destroy(),this.tableScrollbar=void 0),this.tableAlign&&(this.tableAlign.destroy(),this.tableAlign=void 0),this.tableResize&&(this.tableResize.destroy(),this.tableResize=void 0),this.tableResizeScale&&this.tableResizeScale.destroy(),this.table=void 0}async buildCustomSelect(t,e){if(!t||!r(t))return;const s=document.createElement("div");if(s.classList.add("ql-custom-select"),this.selector=await t(this,e),s.appendChild(this.selector),this.options.fullSwitch){const t=l("creator"),e=document.createElement("label");e.classList.add(t.be("checkbox"));const o=document.createElement("input");o.type="checkbox",o.checked=this.options.full,o.addEventListener("change",(()=>{this.options.full=o.checked}));const i=document.createElement("div");i.classList.add(t.be("mark"));const n=document.createElement("span");n.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),e.appendChild(n),s.appendChild(e)}e.options.appendChild(s)}setCellAttrs(t,e,s,o=!1){if(0!==t.length)for(const i of t)i.setFormatValue(e,s,o)}insertTable(t,i){if(t>=30||i>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus();const n=this.quill.getSelection();if(null==n)return;const[l]=this.quill.getLeaf(n.index);if(!l)return;if(ze(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),a=getComputedStyle(this.quill.root),c=Number.parseInt(a.paddingLeft),d=Number.parseInt(a.paddingRight),h=Number.parseInt(a.width)-c-d-r,u=kt(),p=new Array(i).fill(0).map((()=>kt())),b=this.options.full?`${Math.max(1/i*100,o.colMinWidthPre)}%`:`${Math.max(Math.floor(h/i),o.colMinWidthPx)}px`,m=[{retain:n.index},{insert:"\n"}];for(let t=0;t\n \n \n \n \n \n \n `,e=document.createElement("div");e.className=ge.className,e.innerHTML=t,e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.visibility="hidden",this.quill.root.appendChild(e);const s=window.getComputedStyle(e.querySelector("td")),o=Number.parseFloat(s.borderWidth)||0;return this.quill.root.removeChild(e),o}fixUnusuaDeletelTable(t){const e=t.getRows(),s=t.getColIds();if(0===e.length)return t.remove();if(0===s.length)return;const o=new Array(e.length).fill(0).map((()=>new Array(s.length).fill(!1))),i=t.tableId;for(const[t,n]of e.entries()){let l=0,r=0;const a=o[t],c=n.descendants(ue);for(;r=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:i}=d;if(s>1)for(let t=1;t1)for(let e=t+1;e{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)))}))}deleteTable(){if(!this.tableSelection||0===this.tableSelection.selectedTds.length)return;const t=Ot(this.tableSelection.selectedTds[0],s.tableMain);t&&t.remove(),this.hideTableTools()}appendRow(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const o=e[t?e.length-1:0],[i,n,l]=At(o,[s.tableMain,s.tableBody,s.tableRow]),r=i.getRows().indexOf(l)+(t?o.rowspan:0);n.insertRow(r)}appendCol(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const[o]=e.reduce(((e,s)=>{const o=s.getColumnIndex();return(!t&&o<=e[1]||t&&o>=e[1])&&(e=[s,o]),e}),[e[0],e[0].getColumnIndex()]),i=o.getColumnIndex()+(t?o.colspan:0),n=Ot(o,s.tableMain),l=n.tableId,r=kt(),[a]=n.descendants(fe);a&&a.insertColByIndex(i,{tableId:l,colId:r,width:n.full?"6%":"160px",full:n.full});const c=n.getRows(),d=[];let h=0;for(const t of Object.values(c)){const e=d.shift()||0;if(h>0){h-=1;continue}const s=t.insertCell(i-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(h+=s.skipRowNum);for(const[t,e]of s.entries())d[t]=(d[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),s=t.getCols(),o=s.reduce(((t,e)=>(t[e.colId]=0,t)),{}),i=[...e].reverse(),n=[];for(const[t,s]of i.entries()){const i=e.length-t-1;s.children.length<=0?n.push(i):s.foreachCellInner((t=>{const e=n.reduce(((e,s)=>t.rowspan+i>s?e+1:e),0);t.rowspan-=e,o[t.colId]+=1}))}let l=0;for(const t of Object.values(o))if(0===t){const t=[];let s=0;for(const o of Object.values(e)){const e=t.shift()||0;let i=[];s>0?(i=o.getCellByColumIndex(l-e)[2],s-=1):(i=o.removeCell(l-e),i.skipRowNum&&(s+=i.skipRowNum));for(const[e,s]of i.entries())t[e]=(t[e]||0)+s}}else l+=1;for(const t of s)0===o[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=Ot(t[0],s.tableMain),o=e.getRows();let i=o.length,n=-1;for(const e of t){const t=Ot(e,s.tableRow),l=o.indexOf(t);ln&&(n=l+e.rowspan)}const l={};for(let t=i;t{e.rowspan+t>n&&(l[e.colId]={rowspan:e.rowspan+t-n,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(o[n]){const t=o[n],s=e.tableId;for(const[e,{colIndex:o,colspan:i,rowspan:n}]of Object.entries(l))t.insertCell(o,{tableId:s,rowId:t.rowId,colId:e,colspan:i,rowspan:n})}this.fixTableByRemove(e)}removeCol(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=t[0],o=Ot(e,s.tableMain),i={};for(const e of t)i[e.rowId]||(i[e.rowId]=0),i[e.rowId]+=e.colspan;const n=Math.max(...Object.values(i)),l=e.getColumnIndex(),r=o.descendants(de);for(let t=0;t0){e-=1;continue}const i=s.removeCell(l-o);i.skipRowNum&&(e+=i.skipRowNum);for(const[e,s]of i.entries())t[e]=(t[e]||0)+s}}const[a]=o.descendants(fe);if(a)for(let t=0;t{const o=e.colId;t[0][o]||(t[0][o]=0),t[0][o]+=e.rowspan;const i=e.rowId;return t[1][i]||(t[1][i]=0),t[1][i]+=e.colspan,0!==s&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),o=Math.max(...Object.values(e[0])),i=Math.max(...Object.values(e[1])),n=e[2];n.colspan=i,n.rowspan=o;const l=Ot(n,s.tableMain);this.fixTableByRemove(l)}splitCell(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(1!==t.length)return;const e=t[0];if(1===e.colspan&&1===e.rowspan)return;const[o,i]=At(e,[s.tableMain,s.tableRow]),n=o.tableId,l=e.getColumnIndex(),r=o.getColIds().slice(l,l+e.colspan).reverse();let a=i,c=e.rowspan;for(e.colspan=1,e.rowspan=1;a&&c>0;){for(const t of r)a===i&&t===e.colId||a.insertCell(l+(a===i?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}t.BlockOverride=Ut,t.BlockquoteOverride=Zt,t.CodeBlockOverride=Qt,t.ContainerFormat=Xt,t.HeaderOverride=te,t.ListItemOverride=se,t.ScrollOverride=ce,t.Scrollbar=Ne,t.TableAlign=class{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=l("align");resizeObserver=new ResizeObserver((()=>this.hide()));constructor(t,s,o){this.tableModule=t,this.table=s,this.quill=o,this.tableBlot=e.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const t=this.tableModule.addContainer(this.bem.b()),s=e.import("ui/icons"),o={left:s.align[""],center:s.align.center,right:s.align.right};for(const[s,i]of Object.entries(o)){const o=document.createElement("span");o.dataset.align=s,o.classList.add(this.bem.be("item")),o.innerHTML=`${i}`,o.addEventListener("click",(()=>{const t=o.dataset.align;t&&(this.setTableAlign(this.tableBlot,t),this.quill.once(e.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableResizeScale&&this.tableModule.tableResizeScale.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),t.appendChild(o)}return this.cleanup||(this.cleanup=Mt(this.tableWrapperBlot.domNode,t,(()=>this.update()))),t}setTableAlign(t,e){const s=t.getCols();for(const t of s)t.align=e}show(){this.alignBox&&(this.alignBox.classList.add(this.bem.bm("active")),this.resizeObserver.observe(this.table))}hide(){this.alignBox&&(this.alignBox.classList.remove(this.bem.bm("active")),this.cleanup&&(this.cleanup(),this.cleanup=void 0))}update(){this.alignBox&&(this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth?this.hide():(this.show(),St(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[Nt(),Lt({limiter:Et()}),It(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}},t.TableBodyFormat=he,t.TableCellFormat=ue,t.TableCellInnerFormat=le,t.TableColFormat=be,t.TableColgroupFormat=fe,t.TableMainFormat=me,t.TableMenuCommon=Me,t.TableMenuContextmenu=class extends Me{tableModule;quill;colorChooseTooltipOption={direction:"right"};constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),this.update({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hide()}),{once:!0})):this.hide()};buildTools(){const t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));const e=t.getElementsByClassName(we);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const s=document.createElement("span");s.textContent=e,t.appendChild(s)}update(t){if(!this.menu||!this.tableModule.tableSelection||!this.tableModule.tableSelection.boundary)return;super.update();const e={display:"flex",left:0,top:0};if(!t)return this.hide();const{x:s,y:o}=t;e.left=s,e.top=o,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const i=this.menu.getBoundingClientRect(),{left:n,top:l}=Wt(i);Object.assign(this.menu.style,{left:`${n+window.scrollX}px`,top:`${l+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy()}},t.TableMenuSelect=class extends Me{tableModule;quill;constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(super.update(),St(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[Nt(),Lt({limiter:Et()}),It(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}},t.TableResizeBox=class extends Le{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=l("resize-box");constructor(t,s,o){super(t,o),this.tableModule=t,this.table=s,this.tableMain=e.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer(this.bem.b()),this.resizeObserver=new ResizeObserver((()=>{this.show()})),this.resizeObserver.observe(this.table)))}handleResizerHeader(t,e){const{clientX:s,clientY:o}=e,i=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const n=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const l=[{x:t?i.left:s,y:t?o:i.top},{x:t?i.right:s,y:t?o:i.bottom}];this.lastHeaderSelect?(l[0]={x:Math.min(l[0].x,this.lastHeaderSelect[0].x),y:Math.min(l[0].y,this.lastHeaderSelect[0].y)},l[1]={x:Math.max(l[1].x,this.lastHeaderSelect[1].x),y:Math.max(l[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=l,n.selectedTds=n.computeSelectedTds(...l),n.show()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("col-separator"))).indexOf(t.target)}colWidthChange(t,e,s){Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[t].style.width=`${e}px`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.size+"px",left:`${e.left}px`,height:`${e.height+this.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));Ht.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!1));for(const t of e)t.addEventListener("mousedown",this.handleColMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}findCurrentRowIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("row-separator"))).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[t].style.height=`${e}px`}handleRowMouseDownFunc=function(t){const e=this.handleRowMouseDown(t);return e&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${e.top}px`,left:e.left-this.size+"px",width:`${e.width+this.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));Ht.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!0));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const[t]=this.tableMain.descendant(he,this.tableMain.length()-1);if(!t)return;const e=t.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:e.y-s.y+"px",left:e.x-s.x+"px"});const o=this.tableMain.domNode.getBoundingClientRect(),i=this.tableWrapper.domNode.getBoundingClientRect();let n=-1*this.size,l=-1*this.size;Ie(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),n=Math.min(i.width,o.width),l=Math.min(i.width,o.width)):this.root.classList.remove(this.bem.is("align-right")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${n}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const t=this.tableWrapper.domNode.getBoundingClientRect(),e=this.tableMain.domNode.getBoundingClientRect();if(this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener("click",(()=>{const t=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const e=this.tableModule.tableSelection;e.selectedTds=e.computeSelectedTds({x:t.x,y:t.y},{x:t.right,y:t.bottom}),e.show()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let s="";for(const[,t]of this.tableCols.entries()){const o=t.domNode.getBoundingClientRect().width;s+=`
\n
\n
`}const o=document.createElement("div");o.classList.add(this.bem.be("col"));const i=document.createElement("div");i.classList.add(this.bem.be("col-wrapper")),Object.assign(o.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=s,o.appendChild(i),this.root.appendChild(o),o.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=o,this.bindColEvents()}if(this.tableRows.length>0){let s="";for(const[,t]of this.tableRows.entries()){const o=`${t.domNode.getBoundingClientRect().height}px`;s+=`
\n
\n
`}const o=document.createElement("div");o.classList.add(this.bem.be("row"));const i=document.createElement("div");i.classList.add(this.bem.be("row-wrapper")),Object.assign(o.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${t.height}px`}),Object.assign(i.style,{height:`${e.height}px`}),i.innerHTML=s,o.appendChild(i),this.root.appendChild(o),o.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=o,this.bindRowEvents()}this.update(),Ht.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),Dt.call(this),this.resizeObserver.disconnect();for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}},t.TableResizeCommon=Le,t.TableResizeLine=class extends Le{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=l("resize-line");constructor(t,s,o){super(t,o),this.tableModule=t,this.table=s,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.table.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(e.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=t=>{if(this.dragging)return;const o=this.findTableCell(t);if(!o)return this.hide();const i=e.find(o);i&&this.currentTableCell!==o&&(this.show(),this.currentTableCell=o,this.tableCellBlot=i,this.tableMain=Ot(i,s.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hide()};findTableCell(t){for(const e of t.composedPath()){if(e instanceof HTMLElement&&"TD"===e.tagName)return e;if(e===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.colResizer),this.colResizer=this.tableModule.addContainer(this.bem.be("col"));const[e]=At(t,[s.tableBody]),o=e.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;Ie(this.tableMain)&&(l=i.left-n.x),Object.assign(this.colResizer.style,{top:o.y-n.y+"px",left:`${l}px`,height:`${o.height}px`});const r=this.tableMain.getCols();this.curColIndex=r.findIndex((e=>e.colId===t.colId)),this.colResizer.addEventListener("mousedown",this.handleColMouseDownFunc),this.colResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.rowResizer),this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));const e=t.parent;if(!(e instanceof de))return;const[o]=At(t,[s.tableBody]),i=o.domNode.getBoundingClientRect(),n=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:n.bottom-l.y+"px",left:i.x-l.x+"px",width:`${i.width}px`});const r=this.tableMain.getRows();this.curRowIndex=r.indexOf(e),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}show(){Object.assign(this.colResizer.style,{display:null}),Object.assign(this.rowResizer.style,{display:null})}hide(){this.currentTableCell=void 0,this.rowResizer.style.display="none",this.colResizer.style.display="none"}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer.remove(),this.rowResizer.remove(),this.table.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(e.events.TEXT_CHANGE,this.hideWhenTextChange)}},t.TableResizeScale=class{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=l("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(t,s,o,i){this.tableModule=t,this.table=s,this.quill=o,this.options=this.resolveOptions(i),this.tableMainBlot=e.find(s),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.buildResizer(),this.show())}resolveOptions(t){return Object.assign({blockSize:12},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.root.classList.add(this.bem.is("hidden")),this.block=document.createElement("div"),this.block.classList.add(this.bem.be("block")),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let t=[],e=[];const s=s=>{if(!this.tableMainBlot)return;const i=Ie(this.tableMainBlot)?-1:1,n=(s.clientX-this.startX)*i,l=s.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:s}of t)e.width=Math.max(s+r,o.colMinWidthPx);for(const{blot:t,height:s}of e)t.setHeight(`${Math.max(s+a,o.rowMinHeightPx)}px`)},i=()=>{t=[],e=[],document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",i)};this.block.addEventListener("mousedown",(o=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=o.clientX,this.startY=o.clientY,t=this.tableMainBlot.getCols().map((t=>({blot:t,width:Math.floor(t.width)}))),e=this.tableMainBlot.getRows().map((t=>({blot:t,height:Math.floor(t.domNode.getBoundingClientRect().height)}))),document.addEventListener("mousemove",s),document.addEventListener("mouseup",i))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),Ht.call(this,this.quill.root,(()=>this.update())),Ht.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect();if(t.width>e.width){for(const s of this.tableMainBlot.getCols())s.width=Math.floor(s.width/t.width*e.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),{scrollTop:o,scrollLeft:i}=this.tableWrapperBlot.domNode,n=2*this.options.blockSize,l=Math.min(t.width,e.width)+n,r=Math.min(t.height,e.height)+n;Object.assign(this.root.style,{width:`${l}px`,height:`${r}px`,left:Math.max(t.x,e.x)-s.x-this.options.blockSize+"px",top:Math.max(t.y,e.y)-s.y-this.options.blockSize+"px"});const a={left:t.width+n-i+"px",top:r-o+"px"};Ie(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),a.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,a)}show(){this.root&&(this.root.classList.remove(this.bem.is("hidden")),this.update())}hide(){this.root&&this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),this.root&&this.root.remove(),Dt.call(this)}},t.TableRowFormat=de,t.TableSelection=class{table;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];selectingHandler=this.mouseDownHandler.bind(this);tableMenu;resizeObserver;bem=l("selection");constructor(t,e,s,o={}){this.table=e,this.quill=s,this.options=this.resolveOptions(o),this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((()=>this.hide())),this.resizeObserver.observe(this.table),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(t,s,this.options.tableMenuOptions))}resolveOptions(t){return Object.assign({selectColor:"#0589f3",tableMenuOptions:{}},t)}helpLinesInitial(){const t=document.createElement("div");return t.classList.add(this.bem.be("line")),Object.assign(t.style,{"border-color":this.options.selectColor}),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(t,s){const o=e.find(this.table);if(!o)return[];const i=new Set(o.descendants(ue).map(((t,e)=>(t.index=e,t)))),{x:n,y:l}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=n,this.selectedTableScrollY=l,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=t.x-n+this.startScrollX,h=t.y-l+this.startScrollY;let u={x:Math.max(c.left,Math.min(s.x,d)),y:Math.max(c.top,Math.min(s.y,h)),x1:Math.min(c.right,Math.max(s.x,d)),y1:Math.min(c.bottom,Math.max(s.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of i){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:o,bottom:n}=t.__rect;if(Bt(u,{x:e,y:s,x1:o,y1:n},2)){p.add(t),i.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,s),x1:Math.max(u.x1,o),y1:Math.max(u.y1,n)},b=!0;break}if(e>u.x1&&s>u.y1)break}}for(const t of[...p,...i])delete t.__rect;return this.boundary=function(t,e){const s=e.getBoundingClientRect();return{x:t.x-s.x-e.scrollLeft,y:t.y-s.y-e.scrollTop,x1:t.x-s.x-e.scrollLeft+t.width,y1:t.y-s.y-e.scrollTop+t.height,width:t.width,height:t.height}}({...u,width:u.x1-u.x,height:u.y1-u.y},this.quill.root),Array.from(p).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler(t){const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n)return;const l=n.dataset.tableId,r={x:o,y:i},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.show(),this.tableMenu&&this.tableMenu.hide();const d=t=>{const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n||n.dataset.tableId!==l)return;this.dragging=!0;const a={x:o,y:i};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.update()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu&&this.tableMenu.update()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)}update(){if(0===this.selectedTds.length||!this.boundary)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:s,y:o}=this.getTableViewScroll(),i=this.table.parentElement.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),l=i.x-n.x,r=i.y-n.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-o-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${i.width+2}px`,height:`${i.height+2}px`}),!this.dragging&&this.tableMenu&&this.tableMenu.update()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}}show(){Dt.call(this),Object.assign(this.cellSelectWrap.style,{display:"block"}),this.update(),Ht.call(this,this.quill.root,(()=>{this.update()})),Ht.call(this,this.table.parentElement,(()=>{this.update()}))}hide(){this.boundary=null,this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.tableMenu&&this.tableMenu.hide(),Dt.call(this)}destroy(){return this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Dt.call(this),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),null}},t.TableUp=Oe,t.TableVirtualScrollbar=class{tableModule;table;quill;scrollbarContainer;scrollbar;bem=l("scrollbar");constructor(t,e,s){this.tableModule=t,this.table=e,this.quill=s,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Ne(s,!0,e,this.scrollbarContainer),new Ne(s,!1,e,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar)}hide(){for(const t of this.scrollbar)t.hideScrollbar()}show(){for(const t of this.scrollbar)t.showScrollbar()}update(){for(const t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}destroy(){this.scrollbarContainer.remove();for(const t of this.scrollbar)t.destroy();return null}},t.TableWrapperFormat=ge,t.blotName=s,t.createColorPicker=g,t.createSelectBox=C,t.createTooltip=Rt,t.default=Oe,t.defaultCustomSelect=function(t,e){return C({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})},t.findParentBlot=Ot,t.findParentBlots=At,t.isTableAlignRight=Ie,t.randomId=kt,t.tableCantInsert=ke,t.tableUpEvent=i,t.tableUpSize=o,t.updateTableConstants=function(t){ke.delete(s.tableCellInner),Object.assign(s,t.blotName||{}),Object.assign(o,t.tableUpSize||{}),Object.assign(i,t.tableUpEvent||{}),Oe.toolName=s.tableWrapper,Xt.blotName=s.container,ge.blotName=s.tableWrapper,me.blotName=s.tableMain,fe.blotName=s.tableColgroup,be.blotName=s.tableCol,he.blotName=s.tableBody,de.blotName=s.tableRow,ue.blotName=s.tableCell,le.blotName=s.tableCellInner},Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=index.umd.js.map diff --git a/index.umd.js.map b/index.umd.js.map index 64fb91a..0202ab0 100644 --- a/index.umd.js.map +++ b/index.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"index.umd.js","sources":["../src/utils/constants.ts","../src/utils/bem.ts","../src/utils/is.ts","../src/utils/components/button.ts","../src/utils/color.ts","../src/utils/components/color-picker.ts","../src/utils/components/dialog.ts","../src/utils/components/input.ts","../src/utils/components/table/select-box.ts","../src/utils/components/table/creator.ts","../node_modules/.pnpm/@floating-ui+utils@0.2.8/node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs","../node_modules/.pnpm/@floating-ui+core@1.6.8/node_modules/@floating-ui/core/dist/floating-ui.core.mjs","../node_modules/.pnpm/@floating-ui+utils@0.2.8/node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs","../node_modules/.pnpm/@floating-ui+dom@1.6.12/node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs","../src/utils/components/tooltip.ts","../src/utils/position.ts","../src/utils/utils.ts","../src/formats/container-format.ts","../src/formats/overrides/block.ts","../src/formats/overrides/blockquote.ts","../src/formats/overrides/code.ts","../src/formats/overrides/header.ts","../src/formats/overrides/list.ts","../src/formats/utils.ts","../src/formats/table-cell-inner-format.ts","../src/formats/overrides/scroll.ts","../src/formats/table-row-format.ts","../src/formats/table-body-format.ts","../src/formats/table-cell-format.ts","../src/formats/table-col-format.ts","../src/formats/table-main-format.ts","../src/formats/table-colgroup-format.ts","../src/formats/table-wrapper-format.ts","../src/modules/table-menu/constants.ts","../src/modules/table-menu/table-menu-common.ts","../src/modules/table-resize/utils.ts","../src/modules/table-resize/table-resize-common.ts","../src/modules/table-scrollbar.ts","../src/index.ts","../src/modules/table-align.ts","../src/modules/table-menu/table-menu-contextmenu.ts","../src/modules/table-menu/table-menu-select.ts","../src/modules/table-resize/table-resize-box.ts","../src/modules/table-resize/table-resize-line.ts","../src/modules/table-resize/table-resize-scale.ts","../src/modules/table-selection.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,"/**\n * Custom positioning reference element.\n * @see https://floating-ui.com/docs/virtual-elements\n */\n\nconst sides = ['top', 'right', 'bottom', 'left'];\nconst alignments = ['start', 'end'];\nconst placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + \"-\" + alignments[0], side + \"-\" + alignments[1]), []);\nconst min = Math.min;\nconst max = Math.max;\nconst round = Math.round;\nconst floor = Math.floor;\nconst createCoords = v => ({\n x: v,\n y: v\n});\nconst oppositeSideMap = {\n left: 'right',\n right: 'left',\n bottom: 'top',\n top: 'bottom'\n};\nconst oppositeAlignmentMap = {\n start: 'end',\n end: 'start'\n};\nfunction clamp(start, value, end) {\n return max(start, min(value, end));\n}\nfunction evaluate(value, param) {\n return typeof value === 'function' ? value(param) : value;\n}\nfunction getSide(placement) {\n return placement.split('-')[0];\n}\nfunction getAlignment(placement) {\n return placement.split('-')[1];\n}\nfunction getOppositeAxis(axis) {\n return axis === 'x' ? 'y' : 'x';\n}\nfunction getAxisLength(axis) {\n return axis === 'y' ? 'height' : 'width';\n}\nfunction getSideAxis(placement) {\n return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';\n}\nfunction getAlignmentAxis(placement) {\n return getOppositeAxis(getSideAxis(placement));\n}\nfunction getAlignmentSides(placement, rects, rtl) {\n if (rtl === void 0) {\n rtl = false;\n }\n const alignment = getAlignment(placement);\n const alignmentAxis = getAlignmentAxis(placement);\n const length = getAxisLength(alignmentAxis);\n let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';\n if (rects.reference[length] > rects.floating[length]) {\n mainAlignmentSide = getOppositePlacement(mainAlignmentSide);\n }\n return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];\n}\nfunction getExpandedPlacements(placement) {\n const oppositePlacement = getOppositePlacement(placement);\n return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];\n}\nfunction getOppositeAlignmentPlacement(placement) {\n return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);\n}\nfunction getSideList(side, isStart, rtl) {\n const lr = ['left', 'right'];\n const rl = ['right', 'left'];\n const tb = ['top', 'bottom'];\n const bt = ['bottom', 'top'];\n switch (side) {\n case 'top':\n case 'bottom':\n if (rtl) return isStart ? rl : lr;\n return isStart ? lr : rl;\n case 'left':\n case 'right':\n return isStart ? tb : bt;\n default:\n return [];\n }\n}\nfunction getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {\n const alignment = getAlignment(placement);\n let list = getSideList(getSide(placement), direction === 'start', rtl);\n if (alignment) {\n list = list.map(side => side + \"-\" + alignment);\n if (flipAlignment) {\n list = list.concat(list.map(getOppositeAlignmentPlacement));\n }\n }\n return list;\n}\nfunction getOppositePlacement(placement) {\n return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);\n}\nfunction expandPaddingObject(padding) {\n return {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n ...padding\n };\n}\nfunction getPaddingObject(padding) {\n return typeof padding !== 'number' ? expandPaddingObject(padding) : {\n top: padding,\n right: padding,\n bottom: padding,\n left: padding\n };\n}\nfunction rectToClientRect(rect) {\n const {\n x,\n y,\n width,\n height\n } = rect;\n return {\n width,\n height,\n top: y,\n left: x,\n right: x + width,\n bottom: y + height,\n x,\n y\n };\n}\n\nexport { alignments, clamp, createCoords, evaluate, expandPaddingObject, floor, getAlignment, getAlignmentAxis, getAlignmentSides, getAxisLength, getExpandedPlacements, getOppositeAlignmentPlacement, getOppositeAxis, getOppositeAxisPlacements, getOppositePlacement, getPaddingObject, getSide, getSideAxis, max, min, placements, rectToClientRect, round, sides };\n","import { getSideAxis, getAlignmentAxis, getAxisLength, getSide, getAlignment, evaluate, getPaddingObject, rectToClientRect, min, clamp, placements, getAlignmentSides, getOppositeAlignmentPlacement, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, sides, max, getOppositeAxis } from '@floating-ui/utils';\nexport { rectToClientRect } from '@floating-ui/utils';\n\nfunction computeCoordsFromPlacement(_ref, placement, rtl) {\n let {\n reference,\n floating\n } = _ref;\n const sideAxis = getSideAxis(placement);\n const alignmentAxis = getAlignmentAxis(placement);\n const alignLength = getAxisLength(alignmentAxis);\n const side = getSide(placement);\n const isVertical = sideAxis === 'y';\n const commonX = reference.x + reference.width / 2 - floating.width / 2;\n const commonY = reference.y + reference.height / 2 - floating.height / 2;\n const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;\n let coords;\n switch (side) {\n case 'top':\n coords = {\n x: commonX,\n y: reference.y - floating.height\n };\n break;\n case 'bottom':\n coords = {\n x: commonX,\n y: reference.y + reference.height\n };\n break;\n case 'right':\n coords = {\n x: reference.x + reference.width,\n y: commonY\n };\n break;\n case 'left':\n coords = {\n x: reference.x - floating.width,\n y: commonY\n };\n break;\n default:\n coords = {\n x: reference.x,\n y: reference.y\n };\n }\n switch (getAlignment(placement)) {\n case 'start':\n coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);\n break;\n case 'end':\n coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);\n break;\n }\n return coords;\n}\n\n/**\n * Computes the `x` and `y` coordinates that will place the floating element\n * next to a given reference element.\n *\n * This export does not have any `platform` interface logic. You will need to\n * write one for the platform you are using Floating UI with.\n */\nconst computePosition = async (reference, floating, config) => {\n const {\n placement = 'bottom',\n strategy = 'absolute',\n middleware = [],\n platform\n } = config;\n const validMiddleware = middleware.filter(Boolean);\n const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));\n let rects = await platform.getElementRects({\n reference,\n floating,\n strategy\n });\n let {\n x,\n y\n } = computeCoordsFromPlacement(rects, placement, rtl);\n let statefulPlacement = placement;\n let middlewareData = {};\n let resetCount = 0;\n for (let i = 0; i < validMiddleware.length; i++) {\n const {\n name,\n fn\n } = validMiddleware[i];\n const {\n x: nextX,\n y: nextY,\n data,\n reset\n } = await fn({\n x,\n y,\n initialPlacement: placement,\n placement: statefulPlacement,\n strategy,\n middlewareData,\n rects,\n platform,\n elements: {\n reference,\n floating\n }\n });\n x = nextX != null ? nextX : x;\n y = nextY != null ? nextY : y;\n middlewareData = {\n ...middlewareData,\n [name]: {\n ...middlewareData[name],\n ...data\n }\n };\n if (reset && resetCount <= 50) {\n resetCount++;\n if (typeof reset === 'object') {\n if (reset.placement) {\n statefulPlacement = reset.placement;\n }\n if (reset.rects) {\n rects = reset.rects === true ? await platform.getElementRects({\n reference,\n floating,\n strategy\n }) : reset.rects;\n }\n ({\n x,\n y\n } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));\n }\n i = -1;\n }\n }\n return {\n x,\n y,\n placement: statefulPlacement,\n strategy,\n middlewareData\n };\n};\n\n/**\n * Resolves with an object of overflow side offsets that determine how much the\n * element is overflowing a given clipping boundary on each side.\n * - positive = overflowing the boundary by that number of pixels\n * - negative = how many pixels left before it will overflow\n * - 0 = lies flush with the boundary\n * @see https://floating-ui.com/docs/detectOverflow\n */\nasync function detectOverflow(state, options) {\n var _await$platform$isEle;\n if (options === void 0) {\n options = {};\n }\n const {\n x,\n y,\n platform,\n rects,\n elements,\n strategy\n } = state;\n const {\n boundary = 'clippingAncestors',\n rootBoundary = 'viewport',\n elementContext = 'floating',\n altBoundary = false,\n padding = 0\n } = evaluate(options, state);\n const paddingObject = getPaddingObject(padding);\n const altContext = elementContext === 'floating' ? 'reference' : 'floating';\n const element = elements[altBoundary ? altContext : elementContext];\n const clippingClientRect = rectToClientRect(await platform.getClippingRect({\n element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),\n boundary,\n rootBoundary,\n strategy\n }));\n const rect = elementContext === 'floating' ? {\n x,\n y,\n width: rects.floating.width,\n height: rects.floating.height\n } : rects.reference;\n const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));\n const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {\n x: 1,\n y: 1\n } : {\n x: 1,\n y: 1\n };\n const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({\n elements,\n rect,\n offsetParent,\n strategy\n }) : rect);\n return {\n top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,\n bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,\n left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,\n right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x\n };\n}\n\n/**\n * Provides data to position an inner element of the floating element so that it\n * appears centered to the reference element.\n * @see https://floating-ui.com/docs/arrow\n */\nconst arrow = options => ({\n name: 'arrow',\n options,\n async fn(state) {\n const {\n x,\n y,\n placement,\n rects,\n platform,\n elements,\n middlewareData\n } = state;\n // Since `element` is required, we don't Partial<> the type.\n const {\n element,\n padding = 0\n } = evaluate(options, state) || {};\n if (element == null) {\n return {};\n }\n const paddingObject = getPaddingObject(padding);\n const coords = {\n x,\n y\n };\n const axis = getAlignmentAxis(placement);\n const length = getAxisLength(axis);\n const arrowDimensions = await platform.getDimensions(element);\n const isYAxis = axis === 'y';\n const minProp = isYAxis ? 'top' : 'left';\n const maxProp = isYAxis ? 'bottom' : 'right';\n const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';\n const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];\n const startDiff = coords[axis] - rects.reference[axis];\n const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));\n let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;\n\n // DOM platform can return `window` as the `offsetParent`.\n if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {\n clientSize = elements.floating[clientProp] || rects.floating[length];\n }\n const centerToReference = endDiff / 2 - startDiff / 2;\n\n // If the padding is large enough that it causes the arrow to no longer be\n // centered, modify the padding so that it is centered.\n const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;\n const minPadding = min(paddingObject[minProp], largestPossiblePadding);\n const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);\n\n // Make sure the arrow doesn't overflow the floating element if the center\n // point is outside the floating element's bounds.\n const min$1 = minPadding;\n const max = clientSize - arrowDimensions[length] - maxPadding;\n const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;\n const offset = clamp(min$1, center, max);\n\n // If the reference is small enough that the arrow's padding causes it to\n // to point to nothing for an aligned placement, adjust the offset of the\n // floating element itself. To ensure `shift()` continues to take action,\n // a single reset is performed when this is true.\n const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;\n const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;\n return {\n [axis]: coords[axis] + alignmentOffset,\n data: {\n [axis]: offset,\n centerOffset: center - offset - alignmentOffset,\n ...(shouldAddOffset && {\n alignmentOffset\n })\n },\n reset: shouldAddOffset\n };\n }\n});\n\nfunction getPlacementList(alignment, autoAlignment, allowedPlacements) {\n const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);\n return allowedPlacementsSortedByAlignment.filter(placement => {\n if (alignment) {\n return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);\n }\n return true;\n });\n}\n/**\n * Optimizes the visibility of the floating element by choosing the placement\n * that has the most space available automatically, without needing to specify a\n * preferred placement. Alternative to `flip`.\n * @see https://floating-ui.com/docs/autoPlacement\n */\nconst autoPlacement = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'autoPlacement',\n options,\n async fn(state) {\n var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;\n const {\n rects,\n middlewareData,\n placement,\n platform,\n elements\n } = state;\n const {\n crossAxis = false,\n alignment,\n allowedPlacements = placements,\n autoAlignment = true,\n ...detectOverflowOptions\n } = evaluate(options, state);\n const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;\n const overflow = await detectOverflow(state, detectOverflowOptions);\n const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;\n const currentPlacement = placements$1[currentIndex];\n if (currentPlacement == null) {\n return {};\n }\n const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));\n\n // Make `computeCoords` start from the right place.\n if (placement !== currentPlacement) {\n return {\n reset: {\n placement: placements$1[0]\n }\n };\n }\n const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];\n const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {\n placement: currentPlacement,\n overflows: currentOverflows\n }];\n const nextPlacement = placements$1[currentIndex + 1];\n\n // There are more placements to check.\n if (nextPlacement) {\n return {\n data: {\n index: currentIndex + 1,\n overflows: allOverflows\n },\n reset: {\n placement: nextPlacement\n }\n };\n }\n const placementsSortedByMostSpace = allOverflows.map(d => {\n const alignment = getAlignment(d.placement);\n return [d.placement, alignment && crossAxis ?\n // Check along the mainAxis and main crossAxis side.\n d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) :\n // Check only the mainAxis.\n d.overflows[0], d.overflows];\n }).sort((a, b) => a[1] - b[1]);\n const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter(d => d[2].slice(0,\n // Aligned placements should not check their opposite crossAxis\n // side.\n getAlignment(d[0]) ? 2 : 3).every(v => v <= 0));\n const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];\n if (resetPlacement !== placement) {\n return {\n data: {\n index: currentIndex + 1,\n overflows: allOverflows\n },\n reset: {\n placement: resetPlacement\n }\n };\n }\n return {};\n }\n };\n};\n\n/**\n * Optimizes the visibility of the floating element by flipping the `placement`\n * in order to keep it in view when the preferred placement(s) will overflow the\n * clipping boundary. Alternative to `autoPlacement`.\n * @see https://floating-ui.com/docs/flip\n */\nconst flip = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'flip',\n options,\n async fn(state) {\n var _middlewareData$arrow, _middlewareData$flip;\n const {\n placement,\n middlewareData,\n rects,\n initialPlacement,\n platform,\n elements\n } = state;\n const {\n mainAxis: checkMainAxis = true,\n crossAxis: checkCrossAxis = true,\n fallbackPlacements: specifiedFallbackPlacements,\n fallbackStrategy = 'bestFit',\n fallbackAxisSideDirection = 'none',\n flipAlignment = true,\n ...detectOverflowOptions\n } = evaluate(options, state);\n\n // If a reset by the arrow was caused due to an alignment offset being\n // added, we should skip any logic now since `flip()` has already done its\n // work.\n // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643\n if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {\n return {};\n }\n const side = getSide(placement);\n const initialSideAxis = getSideAxis(initialPlacement);\n const isBasePlacement = getSide(initialPlacement) === initialPlacement;\n const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));\n const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));\n const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';\n if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {\n fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));\n }\n const placements = [initialPlacement, ...fallbackPlacements];\n const overflow = await detectOverflow(state, detectOverflowOptions);\n const overflows = [];\n let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];\n if (checkMainAxis) {\n overflows.push(overflow[side]);\n }\n if (checkCrossAxis) {\n const sides = getAlignmentSides(placement, rects, rtl);\n overflows.push(overflow[sides[0]], overflow[sides[1]]);\n }\n overflowsData = [...overflowsData, {\n placement,\n overflows\n }];\n\n // One or more sides is overflowing.\n if (!overflows.every(side => side <= 0)) {\n var _middlewareData$flip2, _overflowsData$filter;\n const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;\n const nextPlacement = placements[nextIndex];\n if (nextPlacement) {\n // Try next placement and re-run the lifecycle.\n return {\n data: {\n index: nextIndex,\n overflows: overflowsData\n },\n reset: {\n placement: nextPlacement\n }\n };\n }\n\n // First, find the candidates that fit on the mainAxis side of overflow,\n // then find the placement that fits the best on the main crossAxis side.\n let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;\n\n // Otherwise fallback.\n if (!resetPlacement) {\n switch (fallbackStrategy) {\n case 'bestFit':\n {\n var _overflowsData$filter2;\n const placement = (_overflowsData$filter2 = overflowsData.filter(d => {\n if (hasFallbackAxisSideDirection) {\n const currentSideAxis = getSideAxis(d.placement);\n return currentSideAxis === initialSideAxis ||\n // Create a bias to the `y` side axis due to horizontal\n // reading directions favoring greater width.\n currentSideAxis === 'y';\n }\n return true;\n }).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];\n if (placement) {\n resetPlacement = placement;\n }\n break;\n }\n case 'initialPlacement':\n resetPlacement = initialPlacement;\n break;\n }\n }\n if (placement !== resetPlacement) {\n return {\n reset: {\n placement: resetPlacement\n }\n };\n }\n }\n return {};\n }\n };\n};\n\nfunction getSideOffsets(overflow, rect) {\n return {\n top: overflow.top - rect.height,\n right: overflow.right - rect.width,\n bottom: overflow.bottom - rect.height,\n left: overflow.left - rect.width\n };\n}\nfunction isAnySideFullyClipped(overflow) {\n return sides.some(side => overflow[side] >= 0);\n}\n/**\n * Provides data to hide the floating element in applicable situations, such as\n * when it is not in the same clipping context as the reference element.\n * @see https://floating-ui.com/docs/hide\n */\nconst hide = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'hide',\n options,\n async fn(state) {\n const {\n rects\n } = state;\n const {\n strategy = 'referenceHidden',\n ...detectOverflowOptions\n } = evaluate(options, state);\n switch (strategy) {\n case 'referenceHidden':\n {\n const overflow = await detectOverflow(state, {\n ...detectOverflowOptions,\n elementContext: 'reference'\n });\n const offsets = getSideOffsets(overflow, rects.reference);\n return {\n data: {\n referenceHiddenOffsets: offsets,\n referenceHidden: isAnySideFullyClipped(offsets)\n }\n };\n }\n case 'escaped':\n {\n const overflow = await detectOverflow(state, {\n ...detectOverflowOptions,\n altBoundary: true\n });\n const offsets = getSideOffsets(overflow, rects.floating);\n return {\n data: {\n escapedOffsets: offsets,\n escaped: isAnySideFullyClipped(offsets)\n }\n };\n }\n default:\n {\n return {};\n }\n }\n }\n };\n};\n\nfunction getBoundingRect(rects) {\n const minX = min(...rects.map(rect => rect.left));\n const minY = min(...rects.map(rect => rect.top));\n const maxX = max(...rects.map(rect => rect.right));\n const maxY = max(...rects.map(rect => rect.bottom));\n return {\n x: minX,\n y: minY,\n width: maxX - minX,\n height: maxY - minY\n };\n}\nfunction getRectsByLine(rects) {\n const sortedRects = rects.slice().sort((a, b) => a.y - b.y);\n const groups = [];\n let prevRect = null;\n for (let i = 0; i < sortedRects.length; i++) {\n const rect = sortedRects[i];\n if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {\n groups.push([rect]);\n } else {\n groups[groups.length - 1].push(rect);\n }\n prevRect = rect;\n }\n return groups.map(rect => rectToClientRect(getBoundingRect(rect)));\n}\n/**\n * Provides improved positioning for inline reference elements that can span\n * over multiple lines, such as hyperlinks or range selections.\n * @see https://floating-ui.com/docs/inline\n */\nconst inline = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'inline',\n options,\n async fn(state) {\n const {\n placement,\n elements,\n rects,\n platform,\n strategy\n } = state;\n // A MouseEvent's client{X,Y} coords can be up to 2 pixels off a\n // ClientRect's bounds, despite the event listener being triggered. A\n // padding of 2 seems to handle this issue.\n const {\n padding = 2,\n x,\n y\n } = evaluate(options, state);\n const nativeClientRects = Array.from((await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference))) || []);\n const clientRects = getRectsByLine(nativeClientRects);\n const fallback = rectToClientRect(getBoundingRect(nativeClientRects));\n const paddingObject = getPaddingObject(padding);\n function getBoundingClientRect() {\n // There are two rects and they are disjoined.\n if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {\n // Find the first rect in which the point is fully inside.\n return clientRects.find(rect => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom) || fallback;\n }\n\n // There are 2 or more connected rects.\n if (clientRects.length >= 2) {\n if (getSideAxis(placement) === 'y') {\n const firstRect = clientRects[0];\n const lastRect = clientRects[clientRects.length - 1];\n const isTop = getSide(placement) === 'top';\n const top = firstRect.top;\n const bottom = lastRect.bottom;\n const left = isTop ? firstRect.left : lastRect.left;\n const right = isTop ? firstRect.right : lastRect.right;\n const width = right - left;\n const height = bottom - top;\n return {\n top,\n bottom,\n left,\n right,\n width,\n height,\n x: left,\n y: top\n };\n }\n const isLeftSide = getSide(placement) === 'left';\n const maxRight = max(...clientRects.map(rect => rect.right));\n const minLeft = min(...clientRects.map(rect => rect.left));\n const measureRects = clientRects.filter(rect => isLeftSide ? rect.left === minLeft : rect.right === maxRight);\n const top = measureRects[0].top;\n const bottom = measureRects[measureRects.length - 1].bottom;\n const left = minLeft;\n const right = maxRight;\n const width = right - left;\n const height = bottom - top;\n return {\n top,\n bottom,\n left,\n right,\n width,\n height,\n x: left,\n y: top\n };\n }\n return fallback;\n }\n const resetRects = await platform.getElementRects({\n reference: {\n getBoundingClientRect\n },\n floating: elements.floating,\n strategy\n });\n if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {\n return {\n reset: {\n rects: resetRects\n }\n };\n }\n return {};\n }\n };\n};\n\n// For type backwards-compatibility, the `OffsetOptions` type was also\n// Derivable.\n\nasync function convertValueToCoords(state, options) {\n const {\n placement,\n platform,\n elements\n } = state;\n const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));\n const side = getSide(placement);\n const alignment = getAlignment(placement);\n const isVertical = getSideAxis(placement) === 'y';\n const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;\n const crossAxisMulti = rtl && isVertical ? -1 : 1;\n const rawValue = evaluate(options, state);\n\n // eslint-disable-next-line prefer-const\n let {\n mainAxis,\n crossAxis,\n alignmentAxis\n } = typeof rawValue === 'number' ? {\n mainAxis: rawValue,\n crossAxis: 0,\n alignmentAxis: null\n } : {\n mainAxis: rawValue.mainAxis || 0,\n crossAxis: rawValue.crossAxis || 0,\n alignmentAxis: rawValue.alignmentAxis\n };\n if (alignment && typeof alignmentAxis === 'number') {\n crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;\n }\n return isVertical ? {\n x: crossAxis * crossAxisMulti,\n y: mainAxis * mainAxisMulti\n } : {\n x: mainAxis * mainAxisMulti,\n y: crossAxis * crossAxisMulti\n };\n}\n\n/**\n * Modifies the placement by translating the floating element along the\n * specified axes.\n * A number (shorthand for `mainAxis` or distance), or an axes configuration\n * object may be passed.\n * @see https://floating-ui.com/docs/offset\n */\nconst offset = function (options) {\n if (options === void 0) {\n options = 0;\n }\n return {\n name: 'offset',\n options,\n async fn(state) {\n var _middlewareData$offse, _middlewareData$arrow;\n const {\n x,\n y,\n placement,\n middlewareData\n } = state;\n const diffCoords = await convertValueToCoords(state, options);\n\n // If the placement is the same and the arrow caused an alignment offset\n // then we don't need to change the positioning coordinates.\n if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {\n return {};\n }\n return {\n x: x + diffCoords.x,\n y: y + diffCoords.y,\n data: {\n ...diffCoords,\n placement\n }\n };\n }\n };\n};\n\n/**\n * Optimizes the visibility of the floating element by shifting it in order to\n * keep it in view when it will overflow the clipping boundary.\n * @see https://floating-ui.com/docs/shift\n */\nconst shift = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'shift',\n options,\n async fn(state) {\n const {\n x,\n y,\n placement\n } = state;\n const {\n mainAxis: checkMainAxis = true,\n crossAxis: checkCrossAxis = false,\n limiter = {\n fn: _ref => {\n let {\n x,\n y\n } = _ref;\n return {\n x,\n y\n };\n }\n },\n ...detectOverflowOptions\n } = evaluate(options, state);\n const coords = {\n x,\n y\n };\n const overflow = await detectOverflow(state, detectOverflowOptions);\n const crossAxis = getSideAxis(getSide(placement));\n const mainAxis = getOppositeAxis(crossAxis);\n let mainAxisCoord = coords[mainAxis];\n let crossAxisCoord = coords[crossAxis];\n if (checkMainAxis) {\n const minSide = mainAxis === 'y' ? 'top' : 'left';\n const maxSide = mainAxis === 'y' ? 'bottom' : 'right';\n const min = mainAxisCoord + overflow[minSide];\n const max = mainAxisCoord - overflow[maxSide];\n mainAxisCoord = clamp(min, mainAxisCoord, max);\n }\n if (checkCrossAxis) {\n const minSide = crossAxis === 'y' ? 'top' : 'left';\n const maxSide = crossAxis === 'y' ? 'bottom' : 'right';\n const min = crossAxisCoord + overflow[minSide];\n const max = crossAxisCoord - overflow[maxSide];\n crossAxisCoord = clamp(min, crossAxisCoord, max);\n }\n const limitedCoords = limiter.fn({\n ...state,\n [mainAxis]: mainAxisCoord,\n [crossAxis]: crossAxisCoord\n });\n return {\n ...limitedCoords,\n data: {\n x: limitedCoords.x - x,\n y: limitedCoords.y - y,\n enabled: {\n [mainAxis]: checkMainAxis,\n [crossAxis]: checkCrossAxis\n }\n }\n };\n }\n };\n};\n/**\n * Built-in `limiter` that will stop `shift()` at a certain point.\n */\nconst limitShift = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n options,\n fn(state) {\n const {\n x,\n y,\n placement,\n rects,\n middlewareData\n } = state;\n const {\n offset = 0,\n mainAxis: checkMainAxis = true,\n crossAxis: checkCrossAxis = true\n } = evaluate(options, state);\n const coords = {\n x,\n y\n };\n const crossAxis = getSideAxis(placement);\n const mainAxis = getOppositeAxis(crossAxis);\n let mainAxisCoord = coords[mainAxis];\n let crossAxisCoord = coords[crossAxis];\n const rawOffset = evaluate(offset, state);\n const computedOffset = typeof rawOffset === 'number' ? {\n mainAxis: rawOffset,\n crossAxis: 0\n } : {\n mainAxis: 0,\n crossAxis: 0,\n ...rawOffset\n };\n if (checkMainAxis) {\n const len = mainAxis === 'y' ? 'height' : 'width';\n const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;\n const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;\n if (mainAxisCoord < limitMin) {\n mainAxisCoord = limitMin;\n } else if (mainAxisCoord > limitMax) {\n mainAxisCoord = limitMax;\n }\n }\n if (checkCrossAxis) {\n var _middlewareData$offse, _middlewareData$offse2;\n const len = mainAxis === 'y' ? 'width' : 'height';\n const isOriginSide = ['top', 'left'].includes(getSide(placement));\n const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);\n const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);\n if (crossAxisCoord < limitMin) {\n crossAxisCoord = limitMin;\n } else if (crossAxisCoord > limitMax) {\n crossAxisCoord = limitMax;\n }\n }\n return {\n [mainAxis]: mainAxisCoord,\n [crossAxis]: crossAxisCoord\n };\n }\n };\n};\n\n/**\n * Provides data that allows you to change the size of the floating element —\n * for instance, prevent it from overflowing the clipping boundary or match the\n * width of the reference element.\n * @see https://floating-ui.com/docs/size\n */\nconst size = function (options) {\n if (options === void 0) {\n options = {};\n }\n return {\n name: 'size',\n options,\n async fn(state) {\n var _state$middlewareData, _state$middlewareData2;\n const {\n placement,\n rects,\n platform,\n elements\n } = state;\n const {\n apply = () => {},\n ...detectOverflowOptions\n } = evaluate(options, state);\n const overflow = await detectOverflow(state, detectOverflowOptions);\n const side = getSide(placement);\n const alignment = getAlignment(placement);\n const isYAxis = getSideAxis(placement) === 'y';\n const {\n width,\n height\n } = rects.floating;\n let heightSide;\n let widthSide;\n if (side === 'top' || side === 'bottom') {\n heightSide = side;\n widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';\n } else {\n widthSide = side;\n heightSide = alignment === 'end' ? 'top' : 'bottom';\n }\n const maximumClippingHeight = height - overflow.top - overflow.bottom;\n const maximumClippingWidth = width - overflow.left - overflow.right;\n const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);\n const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);\n const noShift = !state.middlewareData.shift;\n let availableHeight = overflowAvailableHeight;\n let availableWidth = overflowAvailableWidth;\n if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {\n availableWidth = maximumClippingWidth;\n }\n if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {\n availableHeight = maximumClippingHeight;\n }\n if (noShift && !alignment) {\n const xMin = max(overflow.left, 0);\n const xMax = max(overflow.right, 0);\n const yMin = max(overflow.top, 0);\n const yMax = max(overflow.bottom, 0);\n if (isYAxis) {\n availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));\n } else {\n availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));\n }\n }\n await apply({\n ...state,\n availableWidth,\n availableHeight\n });\n const nextDimensions = await platform.getDimensions(elements.floating);\n if (width !== nextDimensions.width || height !== nextDimensions.height) {\n return {\n reset: {\n rects: true\n }\n };\n }\n return {};\n }\n };\n};\n\nexport { arrow, autoPlacement, computePosition, detectOverflow, flip, hide, inline, limitShift, offset, shift, size };\n","function hasWindow() {\n return typeof window !== 'undefined';\n}\nfunction getNodeName(node) {\n if (isNode(node)) {\n return (node.nodeName || '').toLowerCase();\n }\n // Mocked nodes in testing environments may not be instances of Node. By\n // returning `#document` an infinite loop won't occur.\n // https://github.com/floating-ui/floating-ui/issues/2317\n return '#document';\n}\nfunction getWindow(node) {\n var _node$ownerDocument;\n return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;\n}\nfunction getDocumentElement(node) {\n var _ref;\n return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;\n}\nfunction isNode(value) {\n if (!hasWindow()) {\n return false;\n }\n return value instanceof Node || value instanceof getWindow(value).Node;\n}\nfunction isElement(value) {\n if (!hasWindow()) {\n return false;\n }\n return value instanceof Element || value instanceof getWindow(value).Element;\n}\nfunction isHTMLElement(value) {\n if (!hasWindow()) {\n return false;\n }\n return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;\n}\nfunction isShadowRoot(value) {\n if (!hasWindow() || typeof ShadowRoot === 'undefined') {\n return false;\n }\n return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;\n}\nfunction isOverflowElement(element) {\n const {\n overflow,\n overflowX,\n overflowY,\n display\n } = getComputedStyle(element);\n return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);\n}\nfunction isTableElement(element) {\n return ['table', 'td', 'th'].includes(getNodeName(element));\n}\nfunction isTopLayer(element) {\n return [':popover-open', ':modal'].some(selector => {\n try {\n return element.matches(selector);\n } catch (e) {\n return false;\n }\n });\n}\nfunction isContainingBlock(elementOrCss) {\n const webkit = isWebKit();\n const css = isElement(elementOrCss) ? getComputedStyle(elementOrCss) : elementOrCss;\n\n // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\n return css.transform !== 'none' || css.perspective !== 'none' || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));\n}\nfunction getContainingBlock(element) {\n let currentNode = getParentNode(element);\n while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {\n if (isContainingBlock(currentNode)) {\n return currentNode;\n } else if (isTopLayer(currentNode)) {\n return null;\n }\n currentNode = getParentNode(currentNode);\n }\n return null;\n}\nfunction isWebKit() {\n if (typeof CSS === 'undefined' || !CSS.supports) return false;\n return CSS.supports('-webkit-backdrop-filter', 'none');\n}\nfunction isLastTraversableNode(node) {\n return ['html', 'body', '#document'].includes(getNodeName(node));\n}\nfunction getComputedStyle(element) {\n return getWindow(element).getComputedStyle(element);\n}\nfunction getNodeScroll(element) {\n if (isElement(element)) {\n return {\n scrollLeft: element.scrollLeft,\n scrollTop: element.scrollTop\n };\n }\n return {\n scrollLeft: element.scrollX,\n scrollTop: element.scrollY\n };\n}\nfunction getParentNode(node) {\n if (getNodeName(node) === 'html') {\n return node;\n }\n const result =\n // Step into the shadow DOM of the parent of a slotted node.\n node.assignedSlot ||\n // DOM Element detected.\n node.parentNode ||\n // ShadowRoot detected.\n isShadowRoot(node) && node.host ||\n // Fallback.\n getDocumentElement(node);\n return isShadowRoot(result) ? result.host : result;\n}\nfunction getNearestOverflowAncestor(node) {\n const parentNode = getParentNode(node);\n if (isLastTraversableNode(parentNode)) {\n return node.ownerDocument ? node.ownerDocument.body : node.body;\n }\n if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {\n return parentNode;\n }\n return getNearestOverflowAncestor(parentNode);\n}\nfunction getOverflowAncestors(node, list, traverseIframes) {\n var _node$ownerDocument2;\n if (list === void 0) {\n list = [];\n }\n if (traverseIframes === void 0) {\n traverseIframes = true;\n }\n const scrollableAncestor = getNearestOverflowAncestor(node);\n const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);\n const win = getWindow(scrollableAncestor);\n if (isBody) {\n const frameElement = getFrameElement(win);\n return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);\n }\n return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));\n}\nfunction getFrameElement(win) {\n return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;\n}\n\nexport { getComputedStyle, getContainingBlock, getDocumentElement, getFrameElement, getNearestOverflowAncestor, getNodeName, getNodeScroll, getOverflowAncestors, getParentNode, getWindow, isContainingBlock, isElement, isHTMLElement, isLastTraversableNode, isNode, isOverflowElement, isShadowRoot, isTableElement, isTopLayer, isWebKit };\n","import { rectToClientRect, detectOverflow as detectOverflow$1, offset as offset$1, autoPlacement as autoPlacement$1, shift as shift$1, flip as flip$1, size as size$1, hide as hide$1, arrow as arrow$1, inline as inline$1, limitShift as limitShift$1, computePosition as computePosition$1 } from '@floating-ui/core';\nimport { round, createCoords, max, min, floor } from '@floating-ui/utils';\nimport { getComputedStyle, isHTMLElement, isElement, getWindow, isWebKit, getFrameElement, getNodeScroll, getDocumentElement, isTopLayer, getNodeName, isOverflowElement, getOverflowAncestors, getParentNode, isLastTraversableNode, isContainingBlock, isTableElement, getContainingBlock } from '@floating-ui/utils/dom';\nexport { getOverflowAncestors } from '@floating-ui/utils/dom';\n\nfunction getCssDimensions(element) {\n const css = getComputedStyle(element);\n // In testing environments, the `width` and `height` properties are empty\n // strings for SVG elements, returning NaN. Fallback to `0` in this case.\n let width = parseFloat(css.width) || 0;\n let height = parseFloat(css.height) || 0;\n const hasOffset = isHTMLElement(element);\n const offsetWidth = hasOffset ? element.offsetWidth : width;\n const offsetHeight = hasOffset ? element.offsetHeight : height;\n const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;\n if (shouldFallback) {\n width = offsetWidth;\n height = offsetHeight;\n }\n return {\n width,\n height,\n $: shouldFallback\n };\n}\n\nfunction unwrapElement(element) {\n return !isElement(element) ? element.contextElement : element;\n}\n\nfunction getScale(element) {\n const domElement = unwrapElement(element);\n if (!isHTMLElement(domElement)) {\n return createCoords(1);\n }\n const rect = domElement.getBoundingClientRect();\n const {\n width,\n height,\n $\n } = getCssDimensions(domElement);\n let x = ($ ? round(rect.width) : rect.width) / width;\n let y = ($ ? round(rect.height) : rect.height) / height;\n\n // 0, NaN, or Infinity should always fallback to 1.\n\n if (!x || !Number.isFinite(x)) {\n x = 1;\n }\n if (!y || !Number.isFinite(y)) {\n y = 1;\n }\n return {\n x,\n y\n };\n}\n\nconst noOffsets = /*#__PURE__*/createCoords(0);\nfunction getVisualOffsets(element) {\n const win = getWindow(element);\n if (!isWebKit() || !win.visualViewport) {\n return noOffsets;\n }\n return {\n x: win.visualViewport.offsetLeft,\n y: win.visualViewport.offsetTop\n };\n}\nfunction shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {\n if (isFixed === void 0) {\n isFixed = false;\n }\n if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {\n return false;\n }\n return isFixed;\n}\n\nfunction getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {\n if (includeScale === void 0) {\n includeScale = false;\n }\n if (isFixedStrategy === void 0) {\n isFixedStrategy = false;\n }\n const clientRect = element.getBoundingClientRect();\n const domElement = unwrapElement(element);\n let scale = createCoords(1);\n if (includeScale) {\n if (offsetParent) {\n if (isElement(offsetParent)) {\n scale = getScale(offsetParent);\n }\n } else {\n scale = getScale(element);\n }\n }\n const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);\n let x = (clientRect.left + visualOffsets.x) / scale.x;\n let y = (clientRect.top + visualOffsets.y) / scale.y;\n let width = clientRect.width / scale.x;\n let height = clientRect.height / scale.y;\n if (domElement) {\n const win = getWindow(domElement);\n const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;\n let currentWin = win;\n let currentIFrame = getFrameElement(currentWin);\n while (currentIFrame && offsetParent && offsetWin !== currentWin) {\n const iframeScale = getScale(currentIFrame);\n const iframeRect = currentIFrame.getBoundingClientRect();\n const css = getComputedStyle(currentIFrame);\n const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;\n const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;\n x *= iframeScale.x;\n y *= iframeScale.y;\n width *= iframeScale.x;\n height *= iframeScale.y;\n x += left;\n y += top;\n currentWin = getWindow(currentIFrame);\n currentIFrame = getFrameElement(currentWin);\n }\n }\n return rectToClientRect({\n width,\n height,\n x,\n y\n });\n}\n\n// If has a CSS width greater than the viewport, then this will be\n// incorrect for RTL.\nfunction getWindowScrollBarX(element, rect) {\n const leftScroll = getNodeScroll(element).scrollLeft;\n if (!rect) {\n return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;\n }\n return rect.left + leftScroll;\n}\n\nfunction getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {\n if (ignoreScrollbarX === void 0) {\n ignoreScrollbarX = false;\n }\n const htmlRect = documentElement.getBoundingClientRect();\n const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 :\n // RTL scrollbar.\n getWindowScrollBarX(documentElement, htmlRect));\n const y = htmlRect.top + scroll.scrollTop;\n return {\n x,\n y\n };\n}\n\nfunction convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {\n let {\n elements,\n rect,\n offsetParent,\n strategy\n } = _ref;\n const isFixed = strategy === 'fixed';\n const documentElement = getDocumentElement(offsetParent);\n const topLayer = elements ? isTopLayer(elements.floating) : false;\n if (offsetParent === documentElement || topLayer && isFixed) {\n return rect;\n }\n let scroll = {\n scrollLeft: 0,\n scrollTop: 0\n };\n let scale = createCoords(1);\n const offsets = createCoords(0);\n const isOffsetParentAnElement = isHTMLElement(offsetParent);\n if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {\n if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {\n scroll = getNodeScroll(offsetParent);\n }\n if (isHTMLElement(offsetParent)) {\n const offsetRect = getBoundingClientRect(offsetParent);\n scale = getScale(offsetParent);\n offsets.x = offsetRect.x + offsetParent.clientLeft;\n offsets.y = offsetRect.y + offsetParent.clientTop;\n }\n }\n const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);\n return {\n width: rect.width * scale.x,\n height: rect.height * scale.y,\n x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,\n y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y\n };\n}\n\nfunction getClientRects(element) {\n return Array.from(element.getClientRects());\n}\n\n// Gets the entire size of the scrollable document area, even extending outside\n// of the `` and `` rect bounds if horizontally scrollable.\nfunction getDocumentRect(element) {\n const html = getDocumentElement(element);\n const scroll = getNodeScroll(element);\n const body = element.ownerDocument.body;\n const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);\n const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);\n let x = -scroll.scrollLeft + getWindowScrollBarX(element);\n const y = -scroll.scrollTop;\n if (getComputedStyle(body).direction === 'rtl') {\n x += max(html.clientWidth, body.clientWidth) - width;\n }\n return {\n width,\n height,\n x,\n y\n };\n}\n\nfunction getViewportRect(element, strategy) {\n const win = getWindow(element);\n const html = getDocumentElement(element);\n const visualViewport = win.visualViewport;\n let width = html.clientWidth;\n let height = html.clientHeight;\n let x = 0;\n let y = 0;\n if (visualViewport) {\n width = visualViewport.width;\n height = visualViewport.height;\n const visualViewportBased = isWebKit();\n if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {\n x = visualViewport.offsetLeft;\n y = visualViewport.offsetTop;\n }\n }\n return {\n width,\n height,\n x,\n y\n };\n}\n\n// Returns the inner client rect, subtracting scrollbars if present.\nfunction getInnerBoundingClientRect(element, strategy) {\n const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');\n const top = clientRect.top + element.clientTop;\n const left = clientRect.left + element.clientLeft;\n const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);\n const width = element.clientWidth * scale.x;\n const height = element.clientHeight * scale.y;\n const x = left * scale.x;\n const y = top * scale.y;\n return {\n width,\n height,\n x,\n y\n };\n}\nfunction getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {\n let rect;\n if (clippingAncestor === 'viewport') {\n rect = getViewportRect(element, strategy);\n } else if (clippingAncestor === 'document') {\n rect = getDocumentRect(getDocumentElement(element));\n } else if (isElement(clippingAncestor)) {\n rect = getInnerBoundingClientRect(clippingAncestor, strategy);\n } else {\n const visualOffsets = getVisualOffsets(element);\n rect = {\n x: clippingAncestor.x - visualOffsets.x,\n y: clippingAncestor.y - visualOffsets.y,\n width: clippingAncestor.width,\n height: clippingAncestor.height\n };\n }\n return rectToClientRect(rect);\n}\nfunction hasFixedPositionAncestor(element, stopNode) {\n const parentNode = getParentNode(element);\n if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {\n return false;\n }\n return getComputedStyle(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);\n}\n\n// A \"clipping ancestor\" is an `overflow` element with the characteristic of\n// clipping (or hiding) child elements. This returns all clipping ancestors\n// of the given element up the tree.\nfunction getClippingElementAncestors(element, cache) {\n const cachedResult = cache.get(element);\n if (cachedResult) {\n return cachedResult;\n }\n let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');\n let currentContainingBlockComputedStyle = null;\n const elementIsFixed = getComputedStyle(element).position === 'fixed';\n let currentNode = elementIsFixed ? getParentNode(element) : element;\n\n // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block\n while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {\n const computedStyle = getComputedStyle(currentNode);\n const currentNodeIsContaining = isContainingBlock(currentNode);\n if (!currentNodeIsContaining && computedStyle.position === 'fixed') {\n currentContainingBlockComputedStyle = null;\n }\n const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);\n if (shouldDropCurrentNode) {\n // Drop non-containing blocks.\n result = result.filter(ancestor => ancestor !== currentNode);\n } else {\n // Record last containing block for next iteration.\n currentContainingBlockComputedStyle = computedStyle;\n }\n currentNode = getParentNode(currentNode);\n }\n cache.set(element, result);\n return result;\n}\n\n// Gets the maximum area that the element is visible in due to any number of\n// clipping ancestors.\nfunction getClippingRect(_ref) {\n let {\n element,\n boundary,\n rootBoundary,\n strategy\n } = _ref;\n const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);\n const clippingAncestors = [...elementClippingAncestors, rootBoundary];\n const firstClippingAncestor = clippingAncestors[0];\n const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {\n const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);\n accRect.top = max(rect.top, accRect.top);\n accRect.right = min(rect.right, accRect.right);\n accRect.bottom = min(rect.bottom, accRect.bottom);\n accRect.left = max(rect.left, accRect.left);\n return accRect;\n }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));\n return {\n width: clippingRect.right - clippingRect.left,\n height: clippingRect.bottom - clippingRect.top,\n x: clippingRect.left,\n y: clippingRect.top\n };\n}\n\nfunction getDimensions(element) {\n const {\n width,\n height\n } = getCssDimensions(element);\n return {\n width,\n height\n };\n}\n\nfunction getRectRelativeToOffsetParent(element, offsetParent, strategy) {\n const isOffsetParentAnElement = isHTMLElement(offsetParent);\n const documentElement = getDocumentElement(offsetParent);\n const isFixed = strategy === 'fixed';\n const rect = getBoundingClientRect(element, true, isFixed, offsetParent);\n let scroll = {\n scrollLeft: 0,\n scrollTop: 0\n };\n const offsets = createCoords(0);\n if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {\n if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {\n scroll = getNodeScroll(offsetParent);\n }\n if (isOffsetParentAnElement) {\n const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);\n offsets.x = offsetRect.x + offsetParent.clientLeft;\n offsets.y = offsetRect.y + offsetParent.clientTop;\n } else if (documentElement) {\n // If the scrollbar appears on the left (e.g. RTL systems). Use\n // Firefox with layout.scrollbar.side = 3 in about:config to test this.\n offsets.x = getWindowScrollBarX(documentElement);\n }\n }\n const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);\n const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;\n const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;\n return {\n x,\n y,\n width: rect.width,\n height: rect.height\n };\n}\n\nfunction isStaticPositioned(element) {\n return getComputedStyle(element).position === 'static';\n}\n\nfunction getTrueOffsetParent(element, polyfill) {\n if (!isHTMLElement(element) || getComputedStyle(element).position === 'fixed') {\n return null;\n }\n if (polyfill) {\n return polyfill(element);\n }\n let rawOffsetParent = element.offsetParent;\n\n // Firefox returns the element as the offsetParent if it's non-static,\n // while Chrome and Safari return the element. The element must\n // be used to perform the correct calculations even if the element is\n // non-static.\n if (getDocumentElement(element) === rawOffsetParent) {\n rawOffsetParent = rawOffsetParent.ownerDocument.body;\n }\n return rawOffsetParent;\n}\n\n// Gets the closest ancestor positioned element. Handles some edge cases,\n// such as table ancestors and cross browser bugs.\nfunction getOffsetParent(element, polyfill) {\n const win = getWindow(element);\n if (isTopLayer(element)) {\n return win;\n }\n if (!isHTMLElement(element)) {\n let svgOffsetParent = getParentNode(element);\n while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {\n if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {\n return svgOffsetParent;\n }\n svgOffsetParent = getParentNode(svgOffsetParent);\n }\n return win;\n }\n let offsetParent = getTrueOffsetParent(element, polyfill);\n while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {\n offsetParent = getTrueOffsetParent(offsetParent, polyfill);\n }\n if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {\n return win;\n }\n return offsetParent || getContainingBlock(element) || win;\n}\n\nconst getElementRects = async function (data) {\n const getOffsetParentFn = this.getOffsetParent || getOffsetParent;\n const getDimensionsFn = this.getDimensions;\n const floatingDimensions = await getDimensionsFn(data.floating);\n return {\n reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),\n floating: {\n x: 0,\n y: 0,\n width: floatingDimensions.width,\n height: floatingDimensions.height\n }\n };\n};\n\nfunction isRTL(element) {\n return getComputedStyle(element).direction === 'rtl';\n}\n\nconst platform = {\n convertOffsetParentRelativeRectToViewportRelativeRect,\n getDocumentElement,\n getClippingRect,\n getOffsetParent,\n getElementRects,\n getClientRects,\n getDimensions,\n getScale,\n isElement,\n isRTL\n};\n\n// https://samthor.au/2021/observing-dom/\nfunction observeMove(element, onMove) {\n let io = null;\n let timeoutId;\n const root = getDocumentElement(element);\n function cleanup() {\n var _io;\n clearTimeout(timeoutId);\n (_io = io) == null || _io.disconnect();\n io = null;\n }\n function refresh(skip, threshold) {\n if (skip === void 0) {\n skip = false;\n }\n if (threshold === void 0) {\n threshold = 1;\n }\n cleanup();\n const {\n left,\n top,\n width,\n height\n } = element.getBoundingClientRect();\n if (!skip) {\n onMove();\n }\n if (!width || !height) {\n return;\n }\n const insetTop = floor(top);\n const insetRight = floor(root.clientWidth - (left + width));\n const insetBottom = floor(root.clientHeight - (top + height));\n const insetLeft = floor(left);\n const rootMargin = -insetTop + \"px \" + -insetRight + \"px \" + -insetBottom + \"px \" + -insetLeft + \"px\";\n const options = {\n rootMargin,\n threshold: max(0, min(1, threshold)) || 1\n };\n let isFirstUpdate = true;\n function handleObserve(entries) {\n const ratio = entries[0].intersectionRatio;\n if (ratio !== threshold) {\n if (!isFirstUpdate) {\n return refresh();\n }\n if (!ratio) {\n // If the reference is clipped, the ratio is 0. Throttle the refresh\n // to prevent an infinite loop of updates.\n timeoutId = setTimeout(() => {\n refresh(false, 1e-7);\n }, 1000);\n } else {\n refresh(false, ratio);\n }\n }\n isFirstUpdate = false;\n }\n\n // Older browsers don't support a `document` as the root and will throw an\n // error.\n try {\n io = new IntersectionObserver(handleObserve, {\n ...options,\n // Handle