quill-table-up 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +23 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/unit/utils.ts +1 -1
- package/src/index.ts +19 -5
- package/src/modules/table-menu/table-menu-common.ts +2 -2
- package/src/modules/table-resize/table-resize-box.ts +5 -4
- package/src/modules/table-resize/table-resize-common.ts +17 -6
- package/src/modules/table-selection.ts +45 -36
- package/src/utils/color.ts +2 -2
- package/src/utils/components/button.ts +1 -1
- package/src/utils/components/color-picker.ts +1 -1
- package/src/utils/components/input.ts +1 -1
- package/src/utils/components/tooltip.ts +1 -1
- package/src/utils/types.ts +7 -7
- package/src/utils/utils.ts +4 -4
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"quill";const e={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"},s={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:"100",rowMinHeightPx:36},o={AFTER_TABLE_RESIZE:"after-table-resize"},i=[["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)"]],n=(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}`}},l=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)},r=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))}),a=t=>{let{r:e,g:s,b:o,a:i}=t;e=l(e,255),s=l(s,255),o=l(o,255);const n=Math.max(e,s,o),r=Math.min(e,s,o);let a;const c=n,d=n-r,h=0===n?0:d/n;if(n===r)a=0;else{switch(n){case e:a=(s-o)/d+(s<o?6:0);break;case s:a=(o-e)/d+2;break;case o:a=(e-s)/d+4}a/=6}return{h:360*a,s:100*h,b:100*c,a:i}},c=t=>{let{h:e,s:s,b:o,a:i}=t;e=6*l(e,360),s=l(s,100),o=l(o,100);const n=Math.floor(e),r=e-n,a=o*(1-s),c=o*(1-r*s),d=o*(1-(1-r)*s),h=n%6,u=[o,c,a,a,d,o][h],p=[d,o,o,c,a,a][h],b=[a,a,d,o,o,c][h];return{r:Math.round(255*u),g:Math.round(255*p),b:Math.round(255*b),a:i}},d=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("")},h=t=>d(c(t)),u=t=>"function"==typeof t,p=Array.isArray,b=t=>"string"==typeof t,m=t=>{const{type:e="default",content:s}=t||{},o=n("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(b(s)?i.textContent=s:i.appendChild(s)),i},f=(t={})=>{const e=230,s=150,o=10;let i=a((l=(l=t.color||"#ff0000").startsWith("#")?l.slice(1):l,{r:Number.parseInt(l.slice(0,2),16),g:Number.parseInt(l.slice(2,4),16),b:Number.parseInt(l.slice(4,6),16),a:Number((Number.parseInt(l.slice(6,8)||"ff",16)/255).toFixed(2))}));var l;const u=n("color-picker"),p=document.createElement("div");p.classList.add(u.b());const b=document.createElement("div");b.classList.add(u.be("content"));const m=document.createElement("div");m.classList.add(u.be("selector"));const f=document.createElement("div");f.classList.add(u.be("background")),m.appendChild(f);const g=document.createElement("div");g.classList.add(u.be("background-handle")),f.appendChild(g);const w=document.createElement("div");w.classList.add(u.be("alpha"));const v=document.createElement("div");v.classList.add(u.be("alpha-bg"));const x=document.createElement("div");x.classList.add(u.be("alpha-handle")),w.appendChild(v),w.appendChild(x);const C=document.createElement("div");C.classList.add(u.be("hue"));const y=document.createElement("div");y.classList.add(u.be("hue-handle")),C.appendChild(y);const M=document.createElement("div");M.classList.add(u.be("action"));const[N,I,L,E]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(u.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(u.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);O(r(a(Object.assign({},c(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));b.appendChild(C),b.appendChild(m),b.appendChild(w),p.appendChild(b),p.appendChild(M);let T=!1,S=!1,R=!1;function B(){const t=h(i);for(const[e,s]of[N,I,L].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`}),m.style.backgroundColor=`#${d(c({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}=c(i);v.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),B()}function O(e){i=r(Object.assign({},i,e)),B(),t.onChange&&t.onChange(`#${h(i)}`)}function z(t){const o=m.getBoundingClientRect(),i=o.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=o.left+document.body.scrollLeft;O({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);O({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),O({a:Math.round((i-5)/(s.width-10)*100)/100}),k()}function q(t){T&&(t.preventDefault(),z(t)),S&&(t.preventDefault(),A(t)),R&&(t.preventDefault(),$(t))}function W(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",W),T=!1}function H(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",H),S=!1}function D(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",D),R=!1}return m.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",W),T=!0,z(t)})),C.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",H),S=!0,A(t)})),w.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",D),R=!0,$(t)})),k(),p};let g=8e3;const w=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const o=n("dialog"),i=e,l=document.createElement("div");l.classList.add(o.b()),l.style.zIndex=String(g);const r=document.createElement("div");if(r.classList.add(o.be("overlay")),l.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(l);const c=()=>{s(),l.remove(),i.style.overflow=a};return l.addEventListener("click",c),g+=1,{dialog:l,close:c}},v=(t,e)=>{const s=n("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 l=document.createElement("input");for(const t in e)l.setAttribute(t,e[t]);(e.max||e.min)&&l.addEventListener("blur",(()=>{e.max&&e.max<=Number(l.value)&&(l.value=String(e.max)),e.min&&e.min>=Number(l.value)&&(l.value=String(e.min))})),i.appendChild(l),o.appendChild(i),l.addEventListener("focus",(()=>{i.classList.add("focus")})),l.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:l,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()}}}}},x=(t={})=>{const e=n("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;s<i.length;s++){const{row:o,col:n}=i[s].dataset;if(o>t&&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=n("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:l,errorTip:r}=v(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:c,errorTip:d}=v(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(a),s.appendChild(o);const h=document.createElement("div");h.classList.add(e.be("control"));const u=m({type:"confirm",content:t.confirmText||"Confirm"}),p=m({type:"default",content:t.cancelText||"Cancel"});h.appendChild(u),h.appendChild(p),s.appendChild(h);const b=(e=Number(l.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};d(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}=w({child:s,beforeClose:e});l.focus();for(const e of[l,c])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=b();e&&(t(e),o())}}));u.addEventListener("click",(async()=>{const e=b();e&&(t(e),o())})),document.addEventListener("keydown",f),p.addEventListener("click",o)}))})(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s},C=Math.min,y=Math.max,M=Math.round,N=Math.floor,I=t=>({x:t,y:t}),L={left:"right",right:"left",bottom:"top",top:"bottom"},E={start:"end",end:"start"};function T(t,e,s){return y(t,C(e,s))}function S(t,e){return"function"==typeof t?t(e):t}function R(t){return t.split("-")[0]}function B(t){return t.split("-")[1]}function k(t){return"x"===t?"y":"x"}function O(t){return"y"===t?"height":"width"}function z(t){return["top","bottom"].includes(R(t))?"y":"x"}function A(t){return k(z(t))}function $(t){return t.replace(/start|end/g,(t=>E[t]))}function q(t){return t.replace(/left|right|bottom|top/g,(t=>L[t]))}function W(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 H(t,e,s){let{reference:o,floating:i}=t;const n=z(e),l=A(e),r=O(l),a=R(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(B(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function D(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}=S(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=W(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=W(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 F(){return"undefined"!=typeof window}function j(t){return X(t)?(t.nodeName||"").toLowerCase():"#document"}function P(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function V(t){var e;return null==(e=(X(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function X(t){return!!F()&&(t instanceof Node||t instanceof P(t).Node)}function _(t){return!!F()&&(t instanceof Element||t instanceof P(t).Element)}function Y(t){return!!F()&&(t instanceof HTMLElement||t instanceof P(t).HTMLElement)}function U(t){return!(!F()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof P(t).ShadowRoot)}function K(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=et(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function Z(t){return["table","td","th"].includes(j(t))}function G(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function Q(t){const e=J(),s=_(t)?et(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 J(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function tt(t){return["html","body","#document"].includes(j(t))}function et(t){return P(t).getComputedStyle(t)}function st(t){return _(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function ot(t){if("html"===j(t))return t;const e=t.assignedSlot||t.parentNode||U(t)&&t.host||V(t);return U(e)?e.host:e}function it(t){const e=ot(t);return tt(e)?t.ownerDocument?t.ownerDocument.body:t.body:Y(e)&&K(e)?e:it(e)}function nt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=it(t),n=i===(null==(o=t.ownerDocument)?void 0:o.body),l=P(i);if(n){const t=lt(l);return e.concat(l,l.visualViewport||[],K(i)?i:[],t&&s?nt(t):[])}return e.concat(i,nt(i,[],s))}function lt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function rt(t){const e=et(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=Y(t),n=i?t.offsetWidth:s,l=i?t.offsetHeight:o,r=M(s)!==n||M(o)!==l;return r&&(s=n,o=l),{width:s,height:o,$:r}}function at(t){return _(t)?t:t.contextElement}function ct(t){const e=at(t);if(!Y(e))return I(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:n}=rt(e);let l=(n?M(s.width):s.width)/o,r=(n?M(s.height):s.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const dt=I(0);function ht(t){const e=P(t);return J()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:dt}function ut(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),n=at(t);let l=I(1);e&&(o?_(o)&&(l=ct(o)):l=ct(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==P(t))&&e}(n,s,o)?ht(n):I(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=P(n),e=o&&_(o)?P(o):o;let s=t,i=lt(s);for(;i&&o&&e!==s;){const t=ct(i),e=i.getBoundingClientRect(),o=et(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=P(i),i=lt(s)}}return W({width:d,height:h,x:a,y:c})}function pt(t,e){const s=st(t).scrollLeft;return e?e.left+s:ut(V(t)).left+s}function bt(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:pt(t,o)),y:o.top+e.scrollTop}}function mt(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=P(t),o=V(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=J();(!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=V(t),s=st(t),o=t.ownerDocument.body,i=y(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),n=y(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-s.scrollLeft+pt(t);const r=-s.scrollTop;return"rtl"===et(o).direction&&(l+=y(e.clientWidth,o.clientWidth)-i),{width:i,height:n,x:l,y:r}}(V(t));else if(_(e))o=function(t,e){const s=ut(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,n=Y(t)?ct(t):I(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=ht(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return W(o)}function ft(t,e){const s=ot(t);return!(s===e||!_(s)||tt(s))&&("fixed"===et(s).position||ft(s,e))}function gt(t,e,s){const o=Y(e),i=V(e),n="fixed"===s,l=ut(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=I(0);if(o||!o&&!n)if(("body"!==j(e)||K(i))&&(r=st(e)),o){const t=ut(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=pt(i));const c=!i||o||n?I(0):bt(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 wt(t){return"static"===et(t).position}function vt(t,e){if(!Y(t)||"fixed"===et(t).position)return null;if(e)return e(t);let s=t.offsetParent;return V(t)===s&&(s=s.ownerDocument.body),s}function xt(t,e){const s=P(t);if(G(t))return s;if(!Y(t)){let e=ot(t);for(;e&&!tt(e);){if(_(e)&&!wt(e))return e;e=ot(e)}return s}let o=vt(t,e);for(;o&&Z(o)&&wt(o);)o=vt(o,e);return o&&tt(o)&&wt(o)&&!Q(o)?s:o||function(t){let e=ot(t);for(;Y(e)&&!tt(e);){if(Q(e))return e;if(G(e))return null;e=ot(e)}return null}(t)||s}const Ct={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const n="fixed"===i,l=V(o),r=!!e&&G(e.floating);if(o===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=I(1);const d=I(0),h=Y(o);if((h||!h&&!n)&&(("body"!==j(o)||K(l))&&(a=st(o)),Y(o))){const t=ut(o);c=ct(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!l||h||n?I(0):bt(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:V,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const n=[..."clippingAncestors"===s?G(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=nt(t,[],!1).filter((t=>_(t)&&"body"!==j(t))),i=null;const n="fixed"===et(t).position;let l=n?ot(t):t;for(;_(l)&&!tt(l);){const e=et(l),s=Q(l);s||"fixed"!==e.position||(i=null),(n?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||K(l)&&!s&&ft(t,l))?o=o.filter((t=>t!==l)):i=e,l=ot(l)}return e.set(t,o),o}(e,this._c):[].concat(s),o],l=n[0],r=n.reduce(((t,s)=>{const o=mt(e,s,i);return t.top=y(o.top,t.top),t.right=C(o.right,t.right),t.bottom=C(o.bottom,t.bottom),t.left=y(o.left,t.left),t}),mt(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:xt,getElementRects:async function(t){const e=this.getOffsetParent||xt,s=this.getDimensions,o=await s(t.floating);return{reference:gt(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}=rt(t);return{width:e,height:s}},getScale:ct,isElement:_,isRTL:function(t){return"rtl"===et(t).direction}};function yt(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=at(t),d=i||n?[...c?nt(c):[],...nt(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=V(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:-N(d)+"px "+-N(i.clientWidth-(c+h))+"px "+-N(i.clientHeight-(d+u))+"px "+-N(c)+"px",threshold:y(0,C(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?ut(t):null;return a&&function e(){const o=ut(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 Mt=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=R(s),r=B(s),a="y"===z(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=S(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}}}}},Nt=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}=S(t,e),c={x:s,y:o},d=await D(e,a),h=z(R(i)),u=k(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}}}}}},It=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}=S(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=R(i),w=z(r),v=R(r)===r,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),C=u||(v||!m?[q(r)]:function(t){const e=q(t);return[$(t),e,$(e)]}(r)),y="none"!==b;!u&&y&&C.push(...function(t,e,s,o){const i=B(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[]}}(R(t),"start"===s,o);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map($)))),n}(r,m,b,x));const M=[r,...C],N=await D(e,f),I=[];let L=(null==(o=n.flip)?void 0:o.overflows)||[];if(d&&I.push(N[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=B(t),i=A(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=q(l)),[l,q(l)]}(i,l,x);I.push(N[t[0]],N[t[1]])}if(L=[...L,{placement:i,overflows:I}],!I.every((t=>t<=0))){var E,T;const t=((null==(E=n.flip)?void 0:E.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:L},reset:{placement:e}};let s=null==(T=L.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:T.placement;if(!s)switch(p){case"bestFit":{var k;const t=null==(k=L.filter((t=>{if(y){const e=z(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:k[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},Lt=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}=S(t,e),d={x:s,y:o},h=z(i),u=k(h);let p=d[u],b=d[h];const m=S(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;p<e?p=e:p>s&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(R(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);b<s?b=s:b>o&&(b=o)}return{[u]:p,[h]:b}}}},Et=(t,e,s)=>{const o=new Map,i={platform:Ct,...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}=H(c,o,a),u=o,p={},b=0;for(let s=0;s<r.length;s++){const{name:n,fn:m}=r[s],{x:f,y:g,data:w,reset:v}=await m({x:d,y:h,initialPlacement:o,placement:u,strategy:i,middlewareData:p,rects:c,platform:l,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[n]:{...p[n],...w}},v&&b<=50&&(b++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(c=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:d,y:h}=H(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:n})};let Tt;const St=(t,e={})=>{const{msg:s="",delay:o=150,content:i,direction:l="bottom",type:r="hover",container:a,onOpen:c,onClose:d,closed:h,onDestroy:u}=e,p=n("tooltip");if(s||i){Tt||(Tt=document.createElement("div"),document.body.appendChild(Tt));const e=a||Tt,n=document.createElement("div");let b,m,f;n.classList.add(p.b(),"hidden","transparent"),i?n.appendChild(i):s&&(n.textContent=s);const g=()=>{f&&f(),Et(t,n,{placement:l,middleware:[It(),Nt({limiter:Lt()}),Mt(4)]}).then((({x:t,y:e})=>{Object.assign(n.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{n.classList.add("hidden"),e.contains(n)&&e.removeChild(n),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(c){const t=c(s);if(!s&&t)return}e.appendChild(n),n.removeEventListener("transitionend",w),n.classList.remove("hidden"),f=yt(t,n,g),n.classList.remove("transparent")}),o)},x=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}n.addEventListener("transitionend",w,{once:!0}),n.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:()=>{n.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,n],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:N,hide:I,destroy:L}=y[r]();M();const E=()=>{I(!0),u&&u(),L(),f&&f(),n.remove()};return{show:N,hide:I,destroy:E}}return null};function Rt(t,e,s=0,o=!0){const{x:i,y:n,x1:l,y1:r}=t,{x:a,y:c,x1:d,y1:h}=e;let u,p;return o?(u=l<a+s||i-s>d,p=r<c+s||n-s>h):(u=l<=a+s||i-s>=d,p=r<=c+s||n-s>=h),!(u||p)}const Bt=()=>Math.random().toString(36).slice(2),kt=(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 zt(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 At(t){const e=new Map;let s=t;for(;s&&"scroll"!==s.statics.blotName;)e.set(s.statics.blotName,s),s=s.parent;return e}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;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}const Ft=t.import("parchment"),jt=t.import("blots/container"),Pt=t.import("blots/block"),Vt=t.import("blots/block/embed");class Xt extends jt{static tagName;static blotName=e.container;static scope=Ft.Scope.BLOCK_BLOT;static allowedChildren=[Pt,Vt,jt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,s){const[o]=this.children.find(t);if(!o){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,s)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const _t=t.import("parchment"),Yt=t.import("blots/block");class Ut extends Yt{replaceWith(t,s){const o="string"==typeof t?this.scroll.create(t,s):t;if(o instanceof _t.ParentBlot){if(o.statics.blotName===e.tableCellInner){const t=this.parent;if(t.statics.blotName===e.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),this.parent.statics.blotName===e.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 s=t.parent.parent;s.statics.blotName===e.tableRow&&0===s.children.length&&s.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,s){if(t!==e.tableCellInner||this.parent.statics.blotName!==t||s)super.format(t,s);else{const[t,s,o]=zt(this,[e.tableCell,e.tableRow,e.tableWrapper]),i=o.next;let n=s.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=t.import("formats/blockquote");class Zt extends(qt(Kt,[Ut])){}const Gt=t.import("formats/code-block");class Qt extends(qt(Gt,[Ut])){}const Jt=t.import("formats/header");class te extends(qt(Jt,[Ut])){}const ee=t.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=t.import("blots/block"),ne=t.import("blots/block/embed");class le extends Xt{static blotName=e.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,e.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,s=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!==e.tableCell&&(this.wrap(e.tableCell,s),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,s){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]=zt(this,[e.tableRow,e.tableCell]);if(s){const o=s.offset();if(o+1<this.length()){const s=this.scroll.create(e.tableCellInner,n);this.children.forEachAt(o+1,this.length(),(t=>{s.appendChild(t)})),t.insertBefore(s.wrap(e.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(s){const e=s.offset(t);t.split(e)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(e.tableRow,i),r=this.scroll.create(e.tableCell,i);return r.appendChild(o),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(o.wrap(e.tableCell,i),s?l:l.next)}}super.insertBefore(t,s)}}const re=t.import("parchment"),ae=t.import("blots/scroll");class ce extends ae{createBlock(t,s){let o,i={};if(t[e.tableCellInner])o=e.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===e.tableCellInner&&(i={...t},delete i[o]);const n=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(n,s||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=e.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,s){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;t<n.rowspan-1;t++)o[t]=(o[t]||0)+n.colspan;if(n&&l-n.colspan<t){n.getCellInner().colspan+=1,1!==n.rowspan&&(o.skipRowNum=n.rowspan-1)}else{const t=this.scroll.create(e.tableCell,s),o=this.scroll.create(e.tableCellInner,s),i=this.scroll.create("block");i.appendChild(this.scroll.create("break")),o.appendChild(i),t.appendChild(o),this.insertBefore(t,n)}return o}getCellByColumIndex(t){const e=[];let s=null,o=0;if(t<0)return[s,o,e];const i=this.children.iterator();for(;s=i();){if(o+=s.colspan,1!==s.rowspan)for(let t=0;t<s.rowspan-1;t++)e[t]=(e[t]||0)+s.colspan;if(o>t)break}return[s,o,e]}removeCell(t){if(t<0)return[];const s=this.getCellByColumIndex(t),[o,i]=s,n=s[2];if(!o)return n;if(i-o.colspan<t||o.colspan>1){const[s]=o.descendants(le);if(1!==o.colspan&&t===i-o.colspan){const t=Ot(this,e.tableMain).getColIds();s.colId=t[t.indexOf(s.colId)+1]}1!==o.rowspan&&(n.skipRowNum=o.rowspan-1),s.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 s=this.parent,{tableId:o}=this;null!==s&&s.statics.blotName!==e.tableBody&&this.wrap(e.tableBody,o),super.optimize(t)}}class he extends Xt{static blotName=e.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 s=Ot(this,e.tableMain);if(!s)return;const o=s.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;s<e.colspan-1;s++)n.delete(o[t+s+1])}})),l+=1}const r=s.tableId,a=Bt(),c=this.scroll.create(e.tableRow,{tableId:r,rowId:a});for(const t of n){const s=this.scroll.create("break").wrap("block").wrap(e.tableCellInner,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1}).wrap(e.tableCell,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1});c.appendChild(s)}this.insertBefore(c,i[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const s=this.parent;if(null!==s&&s.statics.blotName!==e.tableMain){const{tableId:t}=this;this.wrap(e.tableMain,{tableId:t})}super.optimize(t)}}class ue extends Xt{static blotName=e.tableCell;static tagName="td";static className="ql-table-cell";static allowDataAttrs=new Set(["table-id","row-id","col-id"]);static allowAttrs=new Set(["rowspan","colspan"]);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.setAttribute("rowspan",String(oe(i))),r.setAttribute("colspan",String(oe(n))),l&&(r.style.cssText=l),r}static formats(t){const{tableId:e,rowId:s,colId:o}=t.dataset,i=Number(t.getAttribute("rowspan")),n=Number(t.getAttribute("colspan")),l={tableId:e,rowId:s,colId:o,rowspan:oe(i),colspan:oe(n)},r={};for(let e=0;e<t.style.length;e++){const s=t.style[e],o=t.style[s];this.isAllowStyle(String(s))&&!["initial","inherit"].includes(o)&&(r[s]=o)}const a=Object.entries(r);return a.length>0&&(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 s=this.parent,{tableId:o,rowId:i}=this;null!==s&&s.statics.blotName!==e.tableRow&&this.wrap(e.tableRow,{tableId:o,rowId:i}),super.optimize(t)}}const pe=t.import("blots/block/embed");class be extends pe{scroll;domNode;static blotName=e.tableCol;static tagName="col";static validWidth(t,e){let o=Number.parseFloat(String(t));return Number.isNaN(o)&&(o=s[e?"colMinWidthPre":"colMinWidthPx"]),`${o}${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:o}=t.dataset,i=t.getAttribute("width")||s.colDefaultWidth,n=t.dataset.align,l={tableId:e,colId:o,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:s[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=s[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 s=this.parent;if(null!=s&&s.statics.blotName!==e.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(e.tableColgroup,t)}Ot(this,e.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(t)}insertAt(t,s,o){if(null!=o)return void super.insertAt(t,s,o);const i=s.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]=zt(this,[e.tableColgroup,e.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 s=t[0],o=le.formats(s.domNode),i=this.scroll.create("block"),n=i.wrap(e.tableCellInner,o).wrap(e.tableCell,o).wrap(e.tableRow,o).wrap(e.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=e.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(),s=this.domNode.getBoundingClientRect().width;for(const e of t)e.domNode.removeAttribute("data-full"),e.width=e.width/100*s;const o=this.children.head;o&&o.statics.blotName===e.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 s=this.parent;null!==s&&s.statics.blotName!==e.tableWrapper&&this.wrap(e.tableWrapper,this.tableId),super.optimize(t)}}class fe extends Xt{static blotName=e.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,o){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(e.tableCol,o);if(i.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=s.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 s=this.parent,{tableId:o,full:i,align:n}=this;null!=s&&s.statics.blotName!==e.tableMain&&this.wrap(e.tableMain,{tableId:o,full:i,align:n});Ot(this,e.tableMain).align=n,super.optimize(t)}}const ge=t.import("parchment");class we extends Xt{scroll;static blotName=e.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}constructor(e,s,o){super(e,s),this.scroll=e,this.scroll.emitter.on(t.events.TEXT_CHANGE,this.insertLineAround)}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()}remove(){super.remove(),this.scroll.emitter.off(t.events.TEXT_CHANGE,this.insertLineAround)}insertLineAround=()=>{this.prev&&this.prev instanceof ge.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this),this.next&&this.next instanceof ge.BlockBlot||this.parent.appendChild(this.scroll.create("block"))}}class ve{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=n("align");resizeObserver=new ResizeObserver((()=>this.hide()));constructor(e,s,o){this.tableModule=e,this.table=s,this.quill=o,this.tableBlot=t.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const e=this.tableModule.addContainer(this.bem.b()),s=t.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 class="icon">${i}</i>`,o.addEventListener("click",(()=>{const e=o.dataset.align;e&&(this.setTableAlign(this.tableBlot,e),this.quill.once(t.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()})))})),e.appendChild(o)}return this.cleanup||(this.cleanup=yt(this.tableWrapperBlot.domNode,e,(()=>this.update()))),e}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(),Et(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[It(),Nt({limiter:Lt()}),Mt(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)}}const xe="color-selector",Ce=[{name:"CopyCell",tip:"Copy cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256"><g fill="currentColor"><path d="M216 40v128h-48V88H88V40Z" opacity=".2"/><path d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8m-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z"/></g></svg>',handle:(t,e)=>{const s=t.getTextByCell(e),o=t.getHTMLByCell(e),i=new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},{name:"CutCell",tip:"Cut cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32"><path fill="currentColor" d="m19.05 13.733l-1-1.733l-10.122 5.846l-.997-.576a3 3 0 0 0 .667-.769A3 3 0 1 0 3.5 17.599L5.928 19L3.5 20.402a3.034 3.034 0 1 0 3.44.323l.988-.57L14.59 24l1-1.73L9.928 19zM4.034 15.26a1 1 0 1 1 .466.607a1 1 0 0 1-.466-.607M5 22a1 1 0 1 1-.865 1.5A1 1 0 0 1 5 22m12 4h4v2h-4zm-7 0h4v2h-4z"/><path fill="currentColor" d="M28 28h-4v-2h4V4H7v4H5V4a2 2 0 0 1 2-2h21a2 2 0 0 1 2 2v22a2 2 0 0 1-2 2"/></svg>',handle:(t,e)=>{const s=t.getTextByCell(e),o=t.getHTMLByCell(e,!0),i=new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},{name:"break"},{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm17.94 4.5h-2v4h-2v-4h-2l3-3z"/></svg>',tip:"Insert row above",handle:(t,e)=>{t.appendRow(e,!1),t.hideTableTools()}},{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm15.44 8v-2h-4v-2h4v-2l3 3z"/></svg>',tip:"Insert column right",handle:(t,e)=>{t.appendCol(e,!0),t.hideTableTools()}},{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm11.94 5.5h2v-4h2v4h2l-3 3z"/></svg>',tip:"Insert row below",handle:(t,e)=>{t.appendRow(e,!0),t.hideTableTools()}},{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm14.44 2v2h4v2h-4v2l-3-3z"/></svg>',tip:"Insert column Left",handle:(t,e)=>{t.appendCol(e,!1),t.hideTableTools()}},{name:"break"},{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"/></svg>',tip:"Merge Cell",handle:(t,e)=>{t.mergeCells(e),t.hideTableTools()}},{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"/></svg>',tip:"Split Cell",handle:(t,e)=>{t.splitCell(e),t.hideTableTools()}},{name:"break"},{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41zM22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2zM4 9h4V6H4zm6 0h4V6h-4zm6 0h4V6h-4z"/></svg>',tip:"Delete Row",handle:(t,e)=>{t.removeRow(e),t.hideTableTools()}},{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4zm0 6v4h7v-4zM4 4v4h7V4zm13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59z"/></svg>',tip:"Delete Column",handle:(t,e)=>{t.removeCol(e),t.hideTableTools()}},{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="m15.46 15.88l1.42-1.42L19 16.59l2.12-2.13l1.42 1.42L20.41 18l2.13 2.12l-1.42 1.42L19 19.41l-2.12 2.13l-1.42-1.42L17.59 18zM4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4z"/></svg>',tip:"Delete table",handle:(t,e)=>{t.deleteTable(e)}},{name:"break"},{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"/></svg>',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m12.01 16l-.01.011M12.01 12l-.01.011M12.01 8l-.01.011M8.01 12l-.01.011M16.01 12l-.01.011M21 3.6v16.8a.6.6 0 0 1-.6.6H3.6a.6.6 0 0 1-.6-.6V3.6a.6.6 0 0 1 .6-.6h16.8a.6.6 0 0 1 .6.6"/></svg>',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}}],ye=new Set,Me=n("color-map"),Ne={selectWrapper:Me.b(),used:Me.bm("used"),item:Me.be("item"),btn:Me.be("btn"),map:Me.be("content"),mapRow:Me.be("content-row")};class Ie{tableModule;quill;options;menu=null;updateUsedColor;tooltipItem=[];bem=n("menu");colorItemClass=`color-${Bt()}`;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);p(e)||(e=[]),e.slice(-10).map((t=>ye.add(t)))}catch{}this.updateUsedColor=kt((t=>{if(!t)return;if(ye.add(t),ye.size>10){const t=Array.from(ye).slice(-10);ye.clear(),t.map((t=>ye.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(ye)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Ne.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(Ne.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${Ne.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${Ne.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3)}resolveOptions(t){return Object.assign({tipText:!0,tools:Ce,localstorageKey:"__table-bg-used-color",defaultColorMap:i},t)}getUsedColors(){return ye}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:r=""}=e,a=document.createElement("span");if(a.classList.add(this.bem.be("item")),"break"===s)a.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),u(o)?t.appendChild(o(this.tableModule)):t.innerHTML=o,a.appendChild(t),n&&l){const t=this.createColorChoose(a,{name:s,icon:o,handle:i,isColorChoose:n,key:l,tip:r});this.tooltipItem.push(t),a.classList.add(xe)}else u(i)&&a.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.tableModule.options.texts[s]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose(t,{handle:e,key:s}){const o=document.createElement("div");if(o.classList.add(Ne.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(Ne.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(Ne.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(Ne.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(Ne.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(Ne.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(Ne.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(Ne.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=f({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=St(r,{direction:"right",type:"click",content:a,container:r});if(i.appendChild(n),i.appendChild(l),i.appendChild(r),o.appendChild(i),ye.size>0){const t=document.createElement("div");t.classList.add(Ne.used,this.colorItemClass);for(const e of ye){const s=document.createElement("div");s.classList.add(Ne.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(`.${Ne.item}`))return;this.updateUsedColor(o)}})),St(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=St(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)}}class Le extends Ie{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(xe);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()}}class Ee extends Ie{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(),Et(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[It(),Nt({limiter:Lt()}),Mt(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}}const Te=t=>!t.full&&"right"===t.align;class Se{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=n("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=m({content:s}),a=m({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=w({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 i=this.tableMain.full,n=!1;const l=[];if(i){let o=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(o<i){if(o=Math.max(s.colMinWidthPre,o),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1;l.push({index:e,width:t[e].width+i-o})}else o=100;n=!0,l.push({index:this.colIndex,width:o})}else if(t[this.colIndex+1]){const e=i+t[this.colIndex+1].width;o=Math.min(e-s.colMinWidthPre,o),n=!0,l.push({index:this.colIndex,width:o},{index:this.colIndex+1,width:e-o})}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,n=!0,l.push({index:this.colIndex,width:e});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,n){const e=this.tableMain.domNode.getBoundingClientRect().width;if(i){let s=0;const o=new Set(l.map((({index:t,width:e})=>(s+=e,t))));for(const[e,i]of t.entries())o.has(e)||(s+=i.width);if(s>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(),i=!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:s,width:o}of l)t[s].width=`${Math.round(o)}${i?"%":"px"}`,this.colWidthChange(s,i?o/100*e:o,i)}this.quill.emitter.emit(o.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),o=e[this.colIndex].domNode.getBoundingClientRect(),i=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=s.colMinWidthPre/100*i.width;let l=i.right;n>o.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,o.left+t));const r=o.x+t;n=Math.min(Math.max(n,r),l)}else Te(this.tableMain)?o.right-n<s.colMinWidthPx&&(n=o.right-s.colMinWidthPx):n-o.x<s.colMinWidthPx&&(n=o.x+s.colMinWidthPx);let l=n-o.x;return Te(this.tableMain)&&(l=o.right-n),this.dragColBreak.style.left=`${n}px`,this.dragColBreak.dataset.w=String(l),{left:n,width:l}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),s=this.tableMain.domNode.getBoundingClientRect(),o=s.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=e[this.colIndex].width,n=this.tableMain.full?i/100*o:i;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const l=document.createElement("div");l.classList.add(this.dragBEM.b()),l.classList.add(this.dragBEM.is("col")),l.dataset.w=String(n);const r={top:s.y,left:t.clientX,height:s.height};Object.assign(l.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(l),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=l,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(o.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let o=t.clientY;return o-e.y<s.rowMinHeightPx&&(o=e.y+s.rowMinHeightPx),this.dragRowBreak.style.top=`${o}px`,this.dragRowBreak.dataset.h=String(o-e.y),{top:o,height:o-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,s=this.tableMain.domNode.getBoundingClientRect(),o=document.createElement("div");o.classList.add(this.dragBEM.b()),o.classList.add(this.dragBEM.is("row")),o.dataset.h=String(e);const i={top:t.clientY,left:s.x,width:s.width};Object.assign(o.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});const n=document.body;return n.appendChild(o),this.dragRowBreak&&n.removeChild(this.dragRowBreak),this.dragRowBreak=o,i}update(){}destroy(){}}class Re extends Se{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=n("resize-box");constructor(e,s,o){super(e,o),this.tableModule=e,this.table=s,this.tableMain=t.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;Te(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",(()=>{if(this.tableModule.tableSelection){const t=this.tableMain.descendants(le),e=this.tableModule.tableSelection;e.selectedTds=t,e.updateWithSelectedTds()}})),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+=`<div class="${this.bem.be("col-header")}" style="width: ${o}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${e.height+this.size-3}px"></div>\n </div>`}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+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(o)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${e.width+this.size-3}px"></div>\n </div>`}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()}}class Be extends Se{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=n("resize-line");constructor(e,s,o){super(e,o),this.tableModule=e,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(t.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=s=>{if(this.dragging)return;if(this.tableModule.tableSelection&&this.tableModule.tableSelection.dragging)return;const o=this.findTableCell(s);if(!o)return this.hide();const i=t.find(o);i&&this.currentTableCell!==o&&(this.show(),this.currentTableCell=o,this.tableCellBlot=i,this.tableMain=Ot(i,e.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[s]=zt(t,[e.tableBody]),o=s.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;Te(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 s=t.parent;if(!(s instanceof de))return;const[o]=zt(t,[e.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(s),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(t.events.TEXT_CHANGE,this.hideWhenTextChange)}}class ke{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=n("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(e,s,o,i){this.tableModule=e,this.table=s,this.quill=o,this.options=this.resolveOptions(i),this.tableMainBlot=t.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 o=o=>{if(!this.tableMainBlot)return;const i=Te(this.tableMainBlot)?-1:1,n=(o.clientX-this.startX)*i,l=o.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:o}of t)e.width=Math.max(o+r,s.colMinWidthPx);for(const{blot:t,height:o}of e)t.setHeight(`${Math.max(o+a,s.rowMinHeightPx)}px`)},i=()=>{t=[],e=[],document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",i)};this.block.addEventListener("mousedown",(s=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=s.clientX,this.startY=s.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",o),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"};Te(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)}}class Oe{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;bem=n("scrollbar");constructor(t,e,s,o){this.quill=t,this.isVertical=e,this.table=s,this.scrollbarContainer=o,this.container=s.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{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:e,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=t.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-e}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<e?`${n}px`:"",this.sizeHeight=i+this.gap<t?`${i}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){const t=document.createElement("div");t.classList.add(this.bem.b()),t.classList.add(this.isVertical?this.bem.is("vertical"):this.bem.is("horizontal"),this.bem.is("transparent")),Object.assign(t.style,{display:"none"}),this.thumb.classList.add(this.bem.be("thumb"));const e=t=>{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=kt((()=>{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=kt((()=>{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)}}class ze{tableModule;table;quill;scrollbarContainer;scrollbar;bem=n("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 Oe(s,!0,e,this.scrollbarContainer),new Oe(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()}}const Ae=Symbol("IsFirstResizeObserve");class $e{tableModule;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];tableMenu;resizeObserver;table;isDisplaySelection=!1;bem=n("selection");shiftKeyDown=!1;keySelectionChange=!1;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};constructor(s,o,i={}){this.tableModule=s,this.quill=o,this.options=this.resolveOptions(i),this.cellSelectWrap=s.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((t=>{t.some((t=>{const e=t.target[Ae];return t.target[Ae]=!1,e}))||this.hide()})),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.mouseDownHandler,!1),this.quill.root.addEventListener("keydown",(t=>{const e=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","End","Home","PageDown","PageUp"]);t.shiftKey&&(this.shiftKeyDown=!0,e.has(t.key)&&(this.keySelectionChange=!0))})),this.quill.root.addEventListener("keyup",(t=>{"Shift"===t.key&&(this.shiftKeyDown=!1)})),document.addEventListener("selectionchange",this.selectionChangeHandler),this.quill.on(t.events.SELECTION_CHANGE,(t=>{if(t&&this.isDisplaySelection){const s=this.quill.getFormat(t),[o]=this.quill.getLine(t.index);let i=!!s[e.tableCellInner]&&!!o;i&&(i&&=this.selectedTds.some((t=>t.children.contains(o)))),i||this.hide()}})),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(s,o,this.options.tableMenuOptions)),this.hide()}getFirstTextNode(t){for(const e of Array.from(t.childNodes))if(e.nodeType===Node.TEXT_NODE)return e;return t}getLastTextNode(t){for(let e=t.childNodes.length-1;e>=0;e--){const s=t.childNodes[e];if(s.nodeType===Node.TEXT_NODE)return s}return t}getNodeTailOffset(t){const e=document.createRange();return e.selectNodeContents(t),e.collapse(!1),e.startOffset}setSelectionData(t,e){const{anchorNode:s,anchorOffset:o,focusNode:i,focusOffset:n}=e;if(!s||!i)return;const l=document.createRange(),r=this.selectionDirectionUp(e);r?(l.setStart(s,o),l.setEnd(s,o)):(l.setStart(s,o),l.setEnd(i,n)),t.removeAllRanges(),t.addRange(l),r&&t.extend(i,n)}selectionDirectionUp(t){const{anchorNode:e,anchorOffset:s,focusNode:o,focusOffset:i}=t;if(!e||!o)return!1;if(e===o)return s>i;const n=e.compareDocumentPosition(o);return n&Node.DOCUMENT_POSITION_CONTAINS||n&Node.DOCUMENT_POSITION_CONTAINED_BY?!!(n&Node.DOCUMENT_POSITION_FOLLOWING):!!(n&Node.DOCUMENT_POSITION_PRECEDING)}findWrapSelection(t){let e=null,s=0,o=null,i=0;for(const{node:n,offset:l}of t)n&&(e&&!this.selectionDirectionUp({anchorNode:e,anchorOffset:s,focusNode:n,focusOffset:l})||(e=n,s=l),o&&!this.selectionDirectionUp({anchorNode:n,anchorOffset:l,focusNode:o,focusOffset:i})||(o=n,i=l));return{startNode:e,startOffset:s,endNode:o,endOffset:i}}resolveOptions(t){return Object.assign({selectColor:"#0589f340",tableMenuOptions:{}},t)}selectionChangeHandler=()=>{const s=window.getSelection(),o=this.keySelectionChange;if(this.keySelectionChange=!1,!s)return;const{anchorNode:i,focusNode:n,anchorOffset:l,focusOffset:r}=s;if(!i||!n)return;const a=t.find(i),c=t.find(n);if(!a||!c||a.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;const d=At(a),h=At(c);if(a&&a.statics.blotName===e.tableWrapper&&c&&c.statics.blotName===e.tableWrapper){const t=document.createRange();t.setStart(i,l),t.setEnd(n,r);const e=t.collapsed;if(0===l&&e){const t=this.getFirstTextNode(a.prev.domNode),e=this.getNodeTailOffset(t);return this.setSelectionData(s,{anchorNode:t,anchorOffset:e,focusNode:t,focusOffset:e})}return this.quill.blur()}const u=d.has(e.tableColgroup),p=h.has(e.tableColgroup);if(u||p){let t=i,o=l,a=n,c=r;if(u){t=d.get(e.tableWrapper).descendants(le)[0].domNode,o=0}if(p){a=h.get(e.tableWrapper).descendants(le)[0].domNode,c=0}return void this.setSelectionData(s,{anchorNode:t,anchorOffset:o,focusNode:a,focusOffset:c})}const b=d.has(e.tableCellInner),m=h.has(e.tableCellInner);let f=b&&m;if(f){const t=d.get(e.tableCellInner),s=h.get(e.tableCellInner);f&&=t!==s}if(b&&m&&f||!b&&m||!m&&b){if(o)this.setSelectionData(s,this.lastSelection);else{const t=this.selectionDirectionUp(s),o=b?d.get(e.tableWrapper):h.get(e.tableWrapper),a=this.getLastTextNode(o.next.domNode),c=this.getFirstTextNode(o.prev.domNode);let{startNode:u,startOffset:p,endNode:m,endOffset:f}=this.findWrapSelection([{node:c,offset:this.getNodeTailOffset(c)},{node:a,offset:0},{node:i,offset:l},{node:n,offset:r}]);t&&([u,p,m,f]=[m,f,u,p]),this.lastSelection={anchorNode:u,anchorOffset:p,focusNode:m,focusOffset:f},this.setSelectionData(s,this.lastSelection)}this.selectedTds.length>0&&this.hide()}else this.lastSelection={anchorNode:i,anchorOffset:l,focusNode:n,focusOffset:r}};helpLinesInitial(){this.cellSelectWrap.style.setProperty("--select-color",this.options.selectColor);const t=document.createElement("div");return t.classList.add(this.bem.be("line")),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(e,s){if(!this.table)return[];const o=t.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=e.x-n+this.startScrollX,h=e.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(Rt({x:Math.floor(u.x),y:Math.floor(u.y),x1:Math.floor(u.x1),y1:Math.floor(u.y1)},{x:Math.floor(e),y:Math.floor(s),x1:Math.floor(o),y1:Math.floor(n)},0,0===p.size)){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}}}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=>{if(this.shiftKeyDown)return;const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n)return;this.setSelectionTable(n);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.dragging=!0,this.show(),this.tableMenu&&this.tableMenu.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.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;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.selectedTds.length>0&&this.tableMenu.update()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)};updateWithSelectedTds(){if(this.selectedTds.length<=0)return;const t={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(const s of this.selectedTds){const o=s.domNode.getBoundingClientRect();t.x=Math.min(t.x,o.left),t.y=Math.min(t.y,o.top),e.x=Math.max(e.x,o.right),e.y=Math.max(e.y,o.bottom)}this.selectedTds=this.computeSelectedTds(t,e),this.selectedTds.length>0&&(this.show(),this.update())}update(){this.quill.scroll.observer.disconnect();for(const t of Array.from(this.quill.root.querySelectorAll(`.ql-table .${this.bem.bm("selected")}`)))t.classList.remove(`${this.bem.bm("selected")}`);for(const t of this.selectedTds)t.domNode.classList.add(`${this.bem.bm("selected")}`);if(this.quill.scroll.observer.observe(this.quill.scroll.domNode,{attributes:!0,characterData:!0,characterDataOldValue:!0,childList:!0,subtree:!0}),0===this.selectedTds.length||!this.boundary||!this.table)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,{display:"block",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 this.table?{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}:{x:0,y:0}}setSelectionTable(t){this.table!==t&&(this.table&&(this.table[Ae]=void 0,this.resizeObserver.unobserve(this.table)),this.table=t,this.table&&(this.table[Ae]=!0,this.resizeObserver.observe(this.table)))}show(){this.table&&(Dt.call(this),this.isDisplaySelection=!0,this.update(),Ht.call(this,this.quill.root,(()=>{this.update()})),Ht.call(this,this.table.parentElement,(()=>{this.update()})))}hide(){this.boundary=null;for(const t of this.selectedTds)t.domNode.classList.remove(`${this.bem.bm("selected")}`);this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.setSelectionTable(void 0),this.tableMenu&&this.tableMenu.hide()}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Dt.call(this),this.quill.root.removeEventListener("mousedown",this.mouseDownHandler,!1),document.removeEventListener("selectionchange",this.selectionChangeHandler)}}const qe=t.import("delta"),We=t.import("blots/break"),He=t.import("ui/icons"),De=(t,{tableId:s,rowId:o,colId:i})=>{const n={tableId:s,rowId:o,colId:i,colspan:1,rowspan:1},l=t.create(e.tableCell,n),r=t.create(e.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l},Fe=t=>{let e=Number.parseFloat(t.getAttribute("width")||s.colDefaultWidth);if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e},je=new Set([e.tableCellInner]),Pe=t=>{return!(!t||!t.parent)&&(e=t.parent,!!je.has(e.statics.blotName)||Pe(t.parent));var e};class Ve{static moduleName="table-up";static toolName=e.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,s){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof we)return o.prev.remove(),!1;if(s.format[e.tableCellInner]){if(0===o.offset(Ot(o,e.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,s){const o=this.quill.getLine(t.index),i=o[0],n=o[1];if((i.next instanceof we||i.next instanceof be)&&n===i.length()-1)return!1;if(s.format[e.tableCellInner]){if(i===Ot(i,e.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[e.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(s){const[o,i]=this.quill.getLine(s.index);if(this.quill.getFormat(s.index+i+1,1)[e.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(s.index+1,"\n"),this.quill.setSelection(s.index+1,t.sources.SILENT),!1;return!0}}};static register(){we.allowedChildren=[me],me.allowedChildren=[he,fe],me.requiredContainer=we,fe.allowedChildren=[be],fe.requiredContainer=me,he.allowedChildren=[de],he.requiredContainer=me,de.allowedChildren=[ue],ue.requiredContainer=he,ue.allowedChildren=[le,We],ue.requiredContainer=de,le.requiredContainer=ue,t.register({"blots/scroll":ce,"blots/block":Ut,[`blots/${e.container}`]:Xt,"formats/header":te,"formats/list":se,"formats/blockquote":Zt,"formats/code-block":Qt,[`formats/${e.tableCell}`]:ue,[`formats/${e.tableCellInner}`]:le,[`formats/${e.tableRow}`]:de,[`formats/${e.tableBody}`]:he,[`formats/${e.tableCol}`]:be,[`formats/${e.tableColgroup}`]:fe,[`formats/${e.tableMain}`]:me,[`formats/${e.tableWrapper}`]:we},!0)}quill;options;toolBox;fixTableByLisenter=kt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(t,e){if(this.quill=t,this.options=this.resolveOptions(e||{}),!this.options.scrollbar){const t=n("scrollbar");this.quill.container.classList.add(t.bm("origin"))}const s=n("toolbox");this.toolBox=this.quill.addContainer(s.b()),this.options.selection&&(this.tableSelection=new this.options.selection(this,this.quill,this.options.selectionOptions));const i=this.quill.getModule("toolbar");if(i&&this.quill.theme.pickers){const[,t]=(i.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 l=this.quill.getModule("keyboard");for(const t of Object.values(Ve.keyboradHandler))t.bindInHead?l.bindings[t.key].unshift(t):l.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const e=t.composedPath();if(!e||e.length<=0)return;const s=e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(s){if(this.table===s)return this.tableSelection&&this.tableSelection.show(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(s)}else this.table&&this.hideTableTools()}),!1),this.quill.on(o.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hide()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if(b(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:He.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=Bt(),o=Bt(),i=[],n=[],l=0,r=0;const a=(t,s,o)=>{const i=this.quill.getSelection(!0),n=this.quill.getFormat(i)[e.tableCellInner];if(n)for(const t of s.ops)t.attributes||(t.attributes={}),t.attributes[e.tableCellInner]=n;return s};this.quill.clipboard.addMatcher(Node.TEXT_NODE,a),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,a),this.quill.clipboard.addMatcher("table",((o,a)=>{if(0===a.ops.length)return a;const c=this.quill.getFormat()[e.tableCellInner],d=[],h=[];for(let t=0;t<a.ops.length;t++){const{attributes:s,insert:o}=a.ops[t],{table:i,[e.tableCell]:n,...l}=s||{},r=o&&o[e.tableCol];if(c){if(r)continue;const{[e.tableCellInner]:t,...s}=l;d.push({attributes:{...s,[e.tableCellInner]:c},insert:o})}else r?h.push({insert:o}):d.push({attributes:l,insert:o})}if(!c){const n=((t,e)=>{const o=new Array(e).fill(s.colDefaultWidth),i=Array.from(t.querySelectorAll("tr"));for(const t of i){const s=Array.from(t.querySelectorAll("td"));for(const[t,i]of s.entries()){if(!(t<e))break;{const e=Fe(i);o[t]=e||o[t]}}}return o})(o,i.length).reduce(((s,o,n)=>(h[n]?s.push(h[n]):s.push({insert:{[e.tableCol]:{tableId:t,colId:i[n],width:o,full:!1}}}),s)),[]);d.unshift(...n),d.unshift({insert:"\n"}),d.push({insert:"\n"})}return t=Bt(),i=[],n=[],l=0,r=0,new qe(d)})),this.quill.clipboard.addMatcher("colgroup",((t,s)=>{const o=[];for(let t=0;t<s.ops.length;t++){const n=s.ops[t];n&&(null!==(i=n.insert)&&"object"==typeof i)&&n.insert[e.tableCol]&&o.push(n)}var i;return new qe(o)})),this.quill.clipboard.addMatcher("col",(s=>{i[r]=Bt();const o=(new qe).insert({[e.tableCol]:Object.assign(be.value(s),{tableId:t,colId:i[r]})});return r+=1,o})),this.quill.clipboard.addMatcher("tr",((t,s)=>{o=Bt(),l=0;for(const t of s.ops)if(t.attributes&&t.attributes.background&&t.attributes[e.tableCellInner]){const s=t.attributes[e.tableCellInner];s.style||(s.style=""),t.attributes[e.tableCellInner].style=`background:${t.attributes.background};${s.style}`}for(const[t,e]of n.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(n[t]={rowspan:0,colspan:0});return s}));const c=(s,r)=>{const a=s,c=ue.formats(a);if(!i[l]||!n[l])for(let t=l;t>=0;t--)i[t]||(i[t]=Bt()),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:o,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:s,attributes:o}=t;if(t.insert){const t={...o};delete t[e.tableCell],p.push({insert:s,attributes:{...t,[e.tableCellInner]:u}})}}return new qe(p)};this.quill.clipboard.addMatcher("td",c),this.quill.clipboard.addMatcher("th",c)}showTableTools(t){t&&(this.table=t,this.tableSelection?.show(),this.options.align&&(this.tableAlign=new this.options.align(this,t,this.quill,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,this.quill,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,this.quill,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,this.quill,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection?.hide(),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||!u(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=n("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 l=document.createElement("span");l.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),e.appendChild(l),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)}getTextByCell(t){let e="";for(const s of t){const t=s.offset(this.quill.scroll),o=s.length();for(const s of this.quill.getContents(t,o).ops)b(s.insert)&&(e+=s.insert)}return e}getHTMLByCell(t,s=!1){if(0===t.length)return"";let o=null;try{for(const s of t){const t=Ot(s,e.tableMain);if(o||(o=t),t!==o)return console.error("tableMain is not same"),""}}catch{return console.error("tds must be in same tableMain"),""}const i=o.children.head,n=o.children.tail;if(!n||!i)return console.error("tableMain has no tbody or colgroup"),"";function l(t){const e=t.tagName.toLowerCase(),s=Array.from(t.attributes).map((t=>`${t.name}="${t.value}"`)).join(" ");return{startTag:`<${e}${s?` ${s}`:""}>`,endTag:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(e)?"":`</${e}>`}}let r="";const a=new Set;let c=null,d=0;for(const e of t){if(!c||c!==e.parent.parent){if(c){const{endTag:t}=l(c.domNode);""!==r&&(r+=t)}d+=1,c=e.parent.parent;const{startTag:t}=l(c.domNode);r=`${r}${t}`}r+=e.parent.domNode.outerHTML,a.add(e.colId)}r+=`</${c?c.domNode.tagName.toLocaleLowerCase():""}>`;const{startTag:h,endTag:u}=l(n.domNode);r=`${h}${r}${u}`;const p=o.getCols(),{startTag:b,endTag:m}=l(i.domNode);let f="",g=0,w=!1;for(const t of p.filter((t=>a.has(t.colId)))){const{startTag:e}=l(t.domNode);f+=e,g+=t.width,w&&=t.full}r=b+f+m+r;const v=o.domNode.cloneNode();v.style.width=`${g}${w?"%":"px"}`;const{startTag:x,endTag:C}=l(v);r=x+r+C;const{startTag:y,endTag:M}=l(o.parent.domNode);if(r=y+r+M,s){if(d===o.getRows().length)this.removeCol(t);else for(const e of t)e.domNode.innerHTML="<p><br></p>"}return r}insertTable(o,i){if(o>=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(Pe(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=Bt(),p=new Array(i).fill(0).map((()=>Bt())),b=this.options.full?`${Math.max(1/i*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(h/i),s.colMinWidthPx)}px`,m=[{retain:n.index},{insert:"\n"}];for(let t=0;t<i;t++)m.push({insert:{[e.tableCol]:{width:b,tableId:u,colId:p[t],full:this.options.full}}});for(let t=0;t<o;t++){const t=Bt();for(let s=0;s<i;s++)m.push({insert:"\n",attributes:{[e.tableCellInner]:{tableId:u,rowId:t,colId:p[s],rowspan:1,colspan:1}}})}this.quill.updateContents(new qe(m),t.sources.USER),this.quill.setSelection(n.index+i+i*o+1,t.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${me.className}">\n <tbody>\n <tr>\n <td class="${ue.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=we.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<s.length;){if(a[r]){r+=1;continue}const d=c[l];if(d&&d.colId===s[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:i}=d;if(s>1)for(let t=1;t<s;t++)a[r+t]=!0;if(i>1)for(let e=t+1;e<t+i;e++)for(let t=0;t<s;t++)o[e][r+t]=!0;l+=1}else n.insertBefore(De(this.quill.scroll,{tableId:i,colId:s[r],rowId:n.rowId}),d);r+=1}if(l<c.length)for(let t=l;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(me))this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(t.events.SCROLL_OPTIMIZE,(t=>{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)))}))}deleteTable(t){if(0===t.length)return;const s=Ot(t[0],e.tableMain);s&&s.remove(),this.hideTableTools()}appendRow(t,s){if(t.length<=0)return;const o=t[s?t.length-1:0],[i,n,l]=zt(o,[e.tableMain,e.tableBody,e.tableRow]),r=i.getRows().indexOf(l)+(s?o.rowspan:0);n.insertRow(r)}appendCol(t,s){if(t.length<=0)return;const[o]=t.reduce(((t,e)=>{const o=e.getColumnIndex();return(!s&&o<=t[1]||s&&o>=t[1])&&(t=[e,o]),t}),[t[0],t[0].getColumnIndex()]),i=o.getColumnIndex()+(s?o.colspan:0),n=Ot(o,e.tableMain),l=n.tableId,r=Bt(),[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(t){if(t.length<=0)return;const s=Ot(t[0],e.tableMain),o=s.getRows();let i=o.length,n=-1;for(const s of t){const t=Ot(s,e.tableRow),l=o.indexOf(t);l<i&&(i=l),l+s.rowspan>n&&(n=l+s.rowspan)}const l={};for(let t=i;t<Math.min(o.length,n);t++){o[t].foreachCellInner((e=>{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],e=s.tableId;for(const[s,{colIndex:o,colspan:i,rowspan:n}]of Object.entries(l))t.insertCell(o,{tableId:e,rowId:t.rowId,colId:s,colspan:i,rowspan:n})}this.fixTableByRemove(s)}removeCol(t){if(t.length<=0)return;const s=t[0],o=Ot(s,e.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=s.getColumnIndex(),r=o.descendants(de);for(let t=0;t<n;t++){const t=[];let e=0;for(const s of Object.values(r)){const o=t.shift()||0;if(e>0){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<n;t++)a.removeColByIndex(l);this.fixTableByRemove(o)}mergeCells(t){if(t.length<=1)return;const s=t.reduce(((t,e,s)=>{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(s[0])),i=Math.max(...Object.values(s[1])),n=s[2];n.colspan=i,n.rowspan=o;const l=Ot(n,e.tableMain);this.fixTableByRemove(l)}splitCell(t){if(1!==t.length)return;const s=t[0];if(1===s.colspan&&1===s.rowspan)return;const[o,i]=zt(s,[e.tableMain,e.tableRow]),n=o.tableId,l=s.getColumnIndex(),r=o.getColIds().slice(l,l+s.colspan).reverse();let a=i,c=s.rowspan;for(s.colspan=1,s.rowspan=1;a&&c>0;){for(const t of r)a===i&&t===s.colId||a.insertCell(l+(a===i?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}function Xe(t){je.delete(e.tableCellInner),Object.assign(e,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(o,t.tableUpEvent||{}),Ve.toolName=e.tableWrapper,Xt.blotName=e.container,we.blotName=e.tableWrapper,me.blotName=e.tableMain,fe.blotName=e.tableColgroup,be.blotName=e.tableCol,he.blotName=e.tableBody,de.blotName=e.tableRow,ue.blotName=e.tableCell,le.blotName=e.tableCellInner}function _e(t,e){return x({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})}export{Ut as BlockOverride,Zt as BlockquoteOverride,Qt as CodeBlockOverride,Xt as ContainerFormat,te as HeaderOverride,se as ListItemOverride,ce as ScrollOverride,Oe as Scrollbar,ve as TableAlign,he as TableBodyFormat,ue as TableCellFormat,le as TableCellInnerFormat,be as TableColFormat,fe as TableColgroupFormat,me as TableMainFormat,Ie as TableMenuCommon,Le as TableMenuContextmenu,Ee as TableMenuSelect,Re as TableResizeBox,Se as TableResizeCommon,Be as TableResizeLine,ke as TableResizeScale,de as TableRowFormat,$e as TableSelection,Ve as TableUp,ze as TableVirtualScrollbar,we as TableWrapperFormat,e as blotName,f as createColorPicker,x as createSelectBox,St as createTooltip,Ve as default,_e as defaultCustomSelect,Ot as findParentBlot,zt as findParentBlots,Te as isTableAlignRight,Bt as randomId,je as tableCantInsert,o as tableUpEvent,s as tableUpSize,Xe as updateTableConstants};
|
|
1
|
+
import t from"quill";const e={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"},s={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:"100",rowMinHeightPx:36},o={AFTER_TABLE_RESIZE:"after-table-resize"},i=[["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)"]],n=(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}`}},l=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)},r=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))}),a=t=>{let{r:e,g:s,b:o,a:i}=t;e=l(e,255),s=l(s,255),o=l(o,255);const n=Math.max(e,s,o),r=Math.min(e,s,o);let a;const c=n,d=n-r,h=0===n?0:d/n;if(n===r)a=0;else{switch(n){case e:a=(s-o)/d+(s<o?6:0);break;case s:a=(o-e)/d+2;break;case o:a=(e-s)/d+4}a/=6}return{h:360*a,s:100*h,b:100*c,a:i}},c=t=>{let{h:e,s:s,b:o,a:i}=t;e=6*l(e,360),s=l(s,100),o=l(o,100);const n=Math.floor(e),r=e-n,a=o*(1-s),c=o*(1-r*s),d=o*(1-(1-r)*s),h=n%6,u=[o,c,a,a,d,o][h],p=[d,o,o,c,a,a][h],b=[a,a,d,o,o,c][h];return{r:Math.round(255*u),g:Math.round(255*p),b:Math.round(255*b),a:i}},d=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("")},h=t=>d(c(t)),u=t=>"function"==typeof t,p=Array.isArray,b=t=>"string"==typeof t,m=t=>{const{type:e="default",content:s}=t||{},o=n("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(b(s)?i.textContent=s:i.appendChild(s)),i},f=(t={})=>{const e=230,s=150,o=10;let i=a((l=(l=t.color||"#ff0000").startsWith("#")?l.slice(1):l,{r:Number.parseInt(l.slice(0,2),16),g:Number.parseInt(l.slice(2,4),16),b:Number.parseInt(l.slice(4,6),16),a:Number((Number.parseInt(l.slice(6,8)||"ff",16)/255).toFixed(2))}));var l;const u=n("color-picker"),p=document.createElement("div");p.classList.add(u.b());const b=document.createElement("div");b.classList.add(u.be("content"));const m=document.createElement("div");m.classList.add(u.be("selector"));const f=document.createElement("div");f.classList.add(u.be("background")),m.appendChild(f);const g=document.createElement("div");g.classList.add(u.be("background-handle")),f.appendChild(g);const w=document.createElement("div");w.classList.add(u.be("alpha"));const v=document.createElement("div");v.classList.add(u.be("alpha-bg"));const x=document.createElement("div");x.classList.add(u.be("alpha-handle")),w.appendChild(v),w.appendChild(x);const C=document.createElement("div");C.classList.add(u.be("hue"));const y=document.createElement("div");y.classList.add(u.be("hue-handle")),C.appendChild(y);const M=document.createElement("div");M.classList.add(u.be("action"));const[N,I,L,E]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(u.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(u.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);O(r(a(Object.assign({},c(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));b.appendChild(C),b.appendChild(m),b.appendChild(w),p.appendChild(b),p.appendChild(M);let T=!1,S=!1,R=!1;function B(){const t=h(i);for(const[e,s]of[N,I,L].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`}),m.style.backgroundColor=`#${d(c({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}=c(i);v.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),B()}function O(e){i=r(Object.assign({},i,e)),B(),t.onChange&&t.onChange(`#${h(i)}`)}function z(t){const o=m.getBoundingClientRect(),i=o.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=o.left+document.body.scrollLeft;O({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);O({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),O({a:Math.round((i-5)/(s.width-10)*100)/100}),k()}function q(t){T&&(t.preventDefault(),z(t)),S&&(t.preventDefault(),A(t)),R&&(t.preventDefault(),$(t))}function H(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",H),T=!1}function W(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",W),S=!1}function D(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",D),R=!1}return m.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",H),T=!0,z(t)})),C.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",W),S=!0,A(t)})),w.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",D),R=!0,$(t)})),k(),p};let g=8e3;const w=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const o=n("dialog"),i=e,l=document.createElement("div");l.classList.add(o.b()),l.style.zIndex=String(g);const r=document.createElement("div");if(r.classList.add(o.be("overlay")),l.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(l);const c=()=>{s(),l.remove(),i.style.overflow=a};return l.addEventListener("click",c),g+=1,{dialog:l,close:c}},v=(t,e)=>{const s=n("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 l=document.createElement("input");for(const t in e)l.setAttribute(t,e[t]);(e.max||e.min)&&l.addEventListener("blur",(()=>{e.max&&e.max<=Number(l.value)&&(l.value=String(e.max)),e.min&&e.min>=Number(l.value)&&(l.value=String(e.min))})),i.appendChild(l),o.appendChild(i),l.addEventListener("focus",(()=>{i.classList.add("focus")})),l.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:l,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()}}}}},x=(t={})=>{const e=n("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;s<i.length;s++){const{row:o,col:n}=i[s].dataset;if(o>t&&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=n("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:l,errorTip:r}=v(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:c,errorTip:d}=v(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(a),s.appendChild(o);const h=document.createElement("div");h.classList.add(e.be("control"));const u=m({type:"confirm",content:t.confirmText||"Confirm"}),p=m({type:"default",content:t.cancelText||"Cancel"});h.appendChild(u),h.appendChild(p),s.appendChild(h);const b=(e=Number(l.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};d(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}=w({child:s,beforeClose:e});l.focus();for(const e of[l,c])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=b();e&&(t(e),o())}}));u.addEventListener("click",(async()=>{const e=b();e&&(t(e),o())})),document.addEventListener("keydown",f),p.addEventListener("click",o)}))})(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s},C=Math.min,y=Math.max,M=Math.round,N=Math.floor,I=t=>({x:t,y:t}),L={left:"right",right:"left",bottom:"top",top:"bottom"},E={start:"end",end:"start"};function T(t,e,s){return y(t,C(e,s))}function S(t,e){return"function"==typeof t?t(e):t}function R(t){return t.split("-")[0]}function B(t){return t.split("-")[1]}function k(t){return"x"===t?"y":"x"}function O(t){return"y"===t?"height":"width"}function z(t){return["top","bottom"].includes(R(t))?"y":"x"}function A(t){return k(z(t))}function $(t){return t.replace(/start|end/g,(t=>E[t]))}function q(t){return t.replace(/left|right|bottom|top/g,(t=>L[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 W(t,e,s){let{reference:o,floating:i}=t;const n=z(e),l=A(e),r=O(l),a=R(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(B(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function D(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}=S(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 F(){return"undefined"!=typeof window}function j(t){return _(t)?(t.nodeName||"").toLowerCase():"#document"}function P(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function V(t){var e;return null==(e=(_(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function _(t){return!!F()&&(t instanceof Node||t instanceof P(t).Node)}function X(t){return!!F()&&(t instanceof Element||t instanceof P(t).Element)}function Y(t){return!!F()&&(t instanceof HTMLElement||t instanceof P(t).HTMLElement)}function U(t){return!(!F()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof P(t).ShadowRoot)}function K(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=et(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function Z(t){return["table","td","th"].includes(j(t))}function G(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function Q(t){const e=J(),s=X(t)?et(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 J(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function tt(t){return["html","body","#document"].includes(j(t))}function et(t){return P(t).getComputedStyle(t)}function st(t){return X(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function ot(t){if("html"===j(t))return t;const e=t.assignedSlot||t.parentNode||U(t)&&t.host||V(t);return U(e)?e.host:e}function it(t){const e=ot(t);return tt(e)?t.ownerDocument?t.ownerDocument.body:t.body:Y(e)&&K(e)?e:it(e)}function nt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=it(t),n=i===(null==(o=t.ownerDocument)?void 0:o.body),l=P(i);if(n){const t=lt(l);return e.concat(l,l.visualViewport||[],K(i)?i:[],t&&s?nt(t):[])}return e.concat(i,nt(i,[],s))}function lt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function rt(t){const e=et(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=Y(t),n=i?t.offsetWidth:s,l=i?t.offsetHeight:o,r=M(s)!==n||M(o)!==l;return r&&(s=n,o=l),{width:s,height:o,$:r}}function at(t){return X(t)?t:t.contextElement}function ct(t){const e=at(t);if(!Y(e))return I(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:n}=rt(e);let l=(n?M(s.width):s.width)/o,r=(n?M(s.height):s.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const dt=I(0);function ht(t){const e=P(t);return J()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:dt}function ut(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),n=at(t);let l=I(1);e&&(o?X(o)&&(l=ct(o)):l=ct(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==P(t))&&e}(n,s,o)?ht(n):I(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=P(n),e=o&&X(o)?P(o):o;let s=t,i=lt(s);for(;i&&o&&e!==s;){const t=ct(i),e=i.getBoundingClientRect(),o=et(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=P(i),i=lt(s)}}return H({width:d,height:h,x:a,y:c})}function pt(t,e){const s=st(t).scrollLeft;return e?e.left+s:ut(V(t)).left+s}function bt(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:pt(t,o)),y:o.top+e.scrollTop}}function mt(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=P(t),o=V(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=J();(!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=V(t),s=st(t),o=t.ownerDocument.body,i=y(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),n=y(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-s.scrollLeft+pt(t);const r=-s.scrollTop;return"rtl"===et(o).direction&&(l+=y(e.clientWidth,o.clientWidth)-i),{width:i,height:n,x:l,y:r}}(V(t));else if(X(e))o=function(t,e){const s=ut(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,n=Y(t)?ct(t):I(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=ht(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return H(o)}function ft(t,e){const s=ot(t);return!(s===e||!X(s)||tt(s))&&("fixed"===et(s).position||ft(s,e))}function gt(t,e,s){const o=Y(e),i=V(e),n="fixed"===s,l=ut(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=I(0);if(o||!o&&!n)if(("body"!==j(e)||K(i))&&(r=st(e)),o){const t=ut(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=pt(i));const c=!i||o||n?I(0):bt(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 wt(t){return"static"===et(t).position}function vt(t,e){if(!Y(t)||"fixed"===et(t).position)return null;if(e)return e(t);let s=t.offsetParent;return V(t)===s&&(s=s.ownerDocument.body),s}function xt(t,e){const s=P(t);if(G(t))return s;if(!Y(t)){let e=ot(t);for(;e&&!tt(e);){if(X(e)&&!wt(e))return e;e=ot(e)}return s}let o=vt(t,e);for(;o&&Z(o)&&wt(o);)o=vt(o,e);return o&&tt(o)&&wt(o)&&!Q(o)?s:o||function(t){let e=ot(t);for(;Y(e)&&!tt(e);){if(Q(e))return e;if(G(e))return null;e=ot(e)}return null}(t)||s}const Ct={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const n="fixed"===i,l=V(o),r=!!e&&G(e.floating);if(o===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=I(1);const d=I(0),h=Y(o);if((h||!h&&!n)&&(("body"!==j(o)||K(l))&&(a=st(o)),Y(o))){const t=ut(o);c=ct(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!l||h||n?I(0):bt(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:V,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const n=[..."clippingAncestors"===s?G(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=nt(t,[],!1).filter((t=>X(t)&&"body"!==j(t))),i=null;const n="fixed"===et(t).position;let l=n?ot(t):t;for(;X(l)&&!tt(l);){const e=et(l),s=Q(l);s||"fixed"!==e.position||(i=null),(n?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||K(l)&&!s&&ft(t,l))?o=o.filter((t=>t!==l)):i=e,l=ot(l)}return e.set(t,o),o}(e,this._c):[].concat(s),o],l=n[0],r=n.reduce(((t,s)=>{const o=mt(e,s,i);return t.top=y(o.top,t.top),t.right=C(o.right,t.right),t.bottom=C(o.bottom,t.bottom),t.left=y(o.left,t.left),t}),mt(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:xt,getElementRects:async function(t){const e=this.getOffsetParent||xt,s=this.getDimensions,o=await s(t.floating);return{reference:gt(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}=rt(t);return{width:e,height:s}},getScale:ct,isElement:X,isRTL:function(t){return"rtl"===et(t).direction}};function yt(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=at(t),d=i||n?[...c?nt(c):[],...nt(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=V(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:-N(d)+"px "+-N(i.clientWidth-(c+h))+"px "+-N(i.clientHeight-(d+u))+"px "+-N(c)+"px",threshold:y(0,C(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?ut(t):null;return a&&function e(){const o=ut(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 Mt=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=R(s),r=B(s),a="y"===z(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=S(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}}}}},Nt=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}=S(t,e),c={x:s,y:o},d=await D(e,a),h=z(R(i)),u=k(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}}}}}},It=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}=S(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=R(i),w=z(r),v=R(r)===r,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),C=u||(v||!m?[q(r)]:function(t){const e=q(t);return[$(t),e,$(e)]}(r)),y="none"!==b;!u&&y&&C.push(...function(t,e,s,o){const i=B(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[]}}(R(t),"start"===s,o);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map($)))),n}(r,m,b,x));const M=[r,...C],N=await D(e,f),I=[];let L=(null==(o=n.flip)?void 0:o.overflows)||[];if(d&&I.push(N[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=B(t),i=A(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=q(l)),[l,q(l)]}(i,l,x);I.push(N[t[0]],N[t[1]])}if(L=[...L,{placement:i,overflows:I}],!I.every((t=>t<=0))){var E,T;const t=((null==(E=n.flip)?void 0:E.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:L},reset:{placement:e}};let s=null==(T=L.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:T.placement;if(!s)switch(p){case"bestFit":{var k;const t=null==(k=L.filter((t=>{if(y){const e=z(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:k[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},Lt=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}=S(t,e),d={x:s,y:o},h=z(i),u=k(h);let p=d[u],b=d[h];const m=S(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;p<e?p=e:p>s&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(R(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);b<s?b=s:b>o&&(b=o)}return{[u]:p,[h]:b}}}},Et=(t,e,s)=>{const o=new Map,i={platform:Ct,...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}=W(c,o,a),u=o,p={},b=0;for(let s=0;s<r.length;s++){const{name:n,fn:m}=r[s],{x:f,y:g,data:w,reset:v}=await m({x:d,y:h,initialPlacement:o,placement:u,strategy:i,middlewareData:p,rects:c,platform:l,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[n]:{...p[n],...w}},v&&b<=50&&(b++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(c=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:d,y:h}=W(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:n})};let Tt;const St=(t,e={})=>{const{msg:s="",delay:o=150,content:i,direction:l="bottom",type:r="hover",container:a,onOpen:c,onClose:d,closed:h,onDestroy:u}=e,p=n("tooltip");if(s||i){Tt||(Tt=document.createElement("div"),document.body.appendChild(Tt));const e=a||Tt,n=document.createElement("div");let b,m,f;n.classList.add(p.b(),"hidden","transparent"),i?n.appendChild(i):s&&(n.textContent=s);const g=()=>{f&&f(),Et(t,n,{placement:l,middleware:[It(),Nt({limiter:Lt()}),Mt(4)]}).then((({x:t,y:e})=>{Object.assign(n.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{n.classList.add("hidden"),e.contains(n)&&e.removeChild(n),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(c){const t=c(s);if(!s&&t)return}e.appendChild(n),n.removeEventListener("transitionend",w),n.classList.remove("hidden"),f=yt(t,n,g),n.classList.remove("transparent")}),o)},x=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}n.addEventListener("transitionend",w,{once:!0}),n.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:()=>{n.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,n],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:N,hide:I,destroy:L}=y[r]();M();const E=()=>{I(!0),u&&u(),L(),f&&f(),n.remove()};return{show:N,hide:I,destroy:E}}return null};function Rt(t,e,s=0,o=!0){const{x:i,y:n,x1:l,y1:r}=t,{x:a,y:c,x1:d,y1:h}=e;let u,p;return o?(u=l<a+s||i-s>d,p=r<c+s||n-s>h):(u=l<=a+s||i-s>=d,p=r<=c+s||n-s>=h),!(u||p)}const Bt=()=>Math.random().toString(36).slice(2),kt=(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 zt(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 At(t){const e=new Map;let s=t;for(;s&&"scroll"!==s.statics.blotName;)e.set(s.statics.blotName,s),s=s.parent;return e}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 Ht=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 Wt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Dt(){for(let t=0;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}const Ft=t.import("parchment"),jt=t.import("blots/container"),Pt=t.import("blots/block"),Vt=t.import("blots/block/embed");class _t extends jt{static tagName;static blotName=e.container;static scope=Ft.Scope.BLOCK_BLOT;static allowedChildren=[Pt,Vt,jt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,s){const[o]=this.children.find(t);if(!o){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,s)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const Xt=t.import("parchment"),Yt=t.import("blots/block");class Ut extends Yt{replaceWith(t,s){const o="string"==typeof t?this.scroll.create(t,s):t;if(o instanceof Xt.ParentBlot){if(o.statics.blotName===e.tableCellInner){const t=this.parent;if(t.statics.blotName===e.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),this.parent.statics.blotName===e.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 s=t.parent.parent;s.statics.blotName===e.tableRow&&0===s.children.length&&s.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,s){if(t!==e.tableCellInner||this.parent.statics.blotName!==t||s)super.format(t,s);else{const[t,s,o]=zt(this,[e.tableCell,e.tableRow,e.tableWrapper]),i=o.next;let n=s.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=t.import("formats/blockquote");class Zt extends(qt(Kt,[Ut])){}const Gt=t.import("formats/code-block");class Qt extends(qt(Gt,[Ut])){}const Jt=t.import("formats/header");class te extends(qt(Jt,[Ut])){}const ee=t.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=t.import("blots/block"),ne=t.import("blots/block/embed");class le extends _t{static blotName=e.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,e.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,s=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!==e.tableCell&&(this.wrap(e.tableCell,s),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,s){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]=zt(this,[e.tableRow,e.tableCell]);if(s){const o=s.offset();if(o+1<this.length()){const s=this.scroll.create(e.tableCellInner,n);this.children.forEachAt(o+1,this.length(),(t=>{s.appendChild(t)})),t.insertBefore(s.wrap(e.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(s){const e=s.offset(t);t.split(e)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(e.tableRow,i),r=this.scroll.create(e.tableCell,i);return r.appendChild(o),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(o.wrap(e.tableCell,i),s?l:l.next)}}super.insertBefore(t,s)}}const re=t.import("parchment"),ae=t.import("blots/scroll");class ce extends ae{createBlock(t,s){let o,i={};if(t[e.tableCellInner])o=e.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===e.tableCellInner&&(i={...t},delete i[o]);const n=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(n,s||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 _t{static blotName=e.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,s){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;t<n.rowspan-1;t++)o[t]=(o[t]||0)+n.colspan;if(n&&l-n.colspan<t){n.getCellInner().colspan+=1,1!==n.rowspan&&(o.skipRowNum=n.rowspan-1)}else{const t=this.scroll.create(e.tableCell,s),o=this.scroll.create(e.tableCellInner,s),i=this.scroll.create("block");i.appendChild(this.scroll.create("break")),o.appendChild(i),t.appendChild(o),this.insertBefore(t,n)}return o}getCellByColumIndex(t){const e=[];let s=null,o=0;if(t<0)return[s,o,e];const i=this.children.iterator();for(;s=i();){if(o+=s.colspan,1!==s.rowspan)for(let t=0;t<s.rowspan-1;t++)e[t]=(e[t]||0)+s.colspan;if(o>t)break}return[s,o,e]}removeCell(t){if(t<0)return[];const s=this.getCellByColumIndex(t),[o,i]=s,n=s[2];if(!o)return n;if(i-o.colspan<t||o.colspan>1){const[s]=o.descendants(le);if(1!==o.colspan&&t===i-o.colspan){const t=Ot(this,e.tableMain).getColIds();s.colId=t[t.indexOf(s.colId)+1]}1!==o.rowspan&&(n.skipRowNum=o.rowspan-1),s.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 s=this.parent,{tableId:o}=this;null!==s&&s.statics.blotName!==e.tableBody&&this.wrap(e.tableBody,o),super.optimize(t)}}class he extends _t{static blotName=e.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 s=Ot(this,e.tableMain);if(!s)return;const o=s.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;s<e.colspan-1;s++)n.delete(o[t+s+1])}})),l+=1}const r=s.tableId,a=Bt(),c=this.scroll.create(e.tableRow,{tableId:r,rowId:a});for(const t of n){const s=this.scroll.create("break").wrap("block").wrap(e.tableCellInner,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1}).wrap(e.tableCell,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1});c.appendChild(s)}this.insertBefore(c,i[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const s=this.parent;if(null!==s&&s.statics.blotName!==e.tableMain){const{tableId:t}=this;this.wrap(e.tableMain,{tableId:t})}super.optimize(t)}}class ue extends _t{static blotName=e.tableCell;static tagName="td";static className="ql-table-cell";static allowDataAttrs=new Set(["table-id","row-id","col-id"]);static allowAttrs=new Set(["rowspan","colspan"]);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.setAttribute("rowspan",String(oe(i))),r.setAttribute("colspan",String(oe(n))),l&&(r.style.cssText=l),r}static formats(t){const{tableId:e,rowId:s,colId:o}=t.dataset,i=Number(t.getAttribute("rowspan")),n=Number(t.getAttribute("colspan")),l={tableId:e,rowId:s,colId:o,rowspan:oe(i),colspan:oe(n)},r={};for(let e=0;e<t.style.length;e++){const s=t.style[e],o=t.style[s];this.isAllowStyle(String(s))&&!["initial","inherit"].includes(o)&&(r[s]=o)}const a=Object.entries(r);return a.length>0&&(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 s=this.parent,{tableId:o,rowId:i}=this;null!==s&&s.statics.blotName!==e.tableRow&&this.wrap(e.tableRow,{tableId:o,rowId:i}),super.optimize(t)}}const pe=t.import("blots/block/embed");class be extends pe{scroll;domNode;static blotName=e.tableCol;static tagName="col";static validWidth(t,e){let o=Number.parseFloat(String(t));return Number.isNaN(o)&&(o=s[e?"colMinWidthPre":"colMinWidthPx"]),`${o}${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:o}=t.dataset,i=t.getAttribute("width")||s.colDefaultWidth,n=t.dataset.align,l={tableId:e,colId:o,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:s[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=s[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 s=this.parent;if(null!=s&&s.statics.blotName!==e.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(e.tableColgroup,t)}Ot(this,e.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(t)}insertAt(t,s,o){if(null!=o)return void super.insertAt(t,s,o);const i=s.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]=zt(this,[e.tableColgroup,e.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 s=t[0],o=le.formats(s.domNode),i=this.scroll.create("block"),n=i.wrap(e.tableCellInner,o).wrap(e.tableCell,o).wrap(e.tableRow,o).wrap(e.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 _t{static blotName=e.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(),s=this.domNode.getBoundingClientRect().width;for(const e of t)e.domNode.removeAttribute("data-full"),e.width=e.width/100*s;const o=this.children.head;o&&o.statics.blotName===e.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 s=this.parent;null!==s&&s.statics.blotName!==e.tableWrapper&&this.wrap(e.tableWrapper,this.tableId),super.optimize(t)}}class fe extends _t{static blotName=e.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,o){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(e.tableCol,o);if(i.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=s.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 s=this.parent,{tableId:o,full:i,align:n}=this;null!=s&&s.statics.blotName!==e.tableMain&&this.wrap(e.tableMain,{tableId:o,full:i,align:n});Ot(this,e.tableMain).align=n,super.optimize(t)}}const ge=t.import("parchment");class we extends _t{scroll;static blotName=e.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}constructor(e,s,o){super(e,s),this.scroll=e,this.scroll.emitter.on(t.events.TEXT_CHANGE,this.insertLineAround)}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()}remove(){super.remove(),this.scroll.emitter.off(t.events.TEXT_CHANGE,this.insertLineAround)}insertLineAround=()=>{this.prev&&this.prev instanceof ge.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this),this.next&&this.next instanceof ge.BlockBlot||this.parent.appendChild(this.scroll.create("block"))}}class ve{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=n("align");resizeObserver=new ResizeObserver((()=>this.hide()));constructor(e,s,o){this.tableModule=e,this.table=s,this.quill=o,this.tableBlot=t.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const e=this.tableModule.addContainer(this.bem.b()),s=t.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 class="icon">${i}</i>`,o.addEventListener("click",(()=>{const e=o.dataset.align;e&&(this.setTableAlign(this.tableBlot,e),this.quill.once(t.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()})))})),e.appendChild(o)}return this.cleanup||(this.cleanup=yt(this.tableWrapperBlot.domNode,e,(()=>this.update()))),e}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(),Et(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[It(),Nt({limiter:Lt()}),Mt(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)}}const xe="color-selector",Ce=[{name:"CopyCell",tip:"Copy cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256"><g fill="currentColor"><path d="M216 40v128h-48V88H88V40Z" opacity=".2"/><path d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8m-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z"/></g></svg>',handle:(t,e)=>{const s=t.getTextByCell(e),o=t.getHTMLByCell(e),i=new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},{name:"CutCell",tip:"Cut cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32"><path fill="currentColor" d="m19.05 13.733l-1-1.733l-10.122 5.846l-.997-.576a3 3 0 0 0 .667-.769A3 3 0 1 0 3.5 17.599L5.928 19L3.5 20.402a3.034 3.034 0 1 0 3.44.323l.988-.57L14.59 24l1-1.73L9.928 19zM4.034 15.26a1 1 0 1 1 .466.607a1 1 0 0 1-.466-.607M5 22a1 1 0 1 1-.865 1.5A1 1 0 0 1 5 22m12 4h4v2h-4zm-7 0h4v2h-4z"/><path fill="currentColor" d="M28 28h-4v-2h4V4H7v4H5V4a2 2 0 0 1 2-2h21a2 2 0 0 1 2 2v22a2 2 0 0 1-2 2"/></svg>',handle:(t,e)=>{const s=t.getTextByCell(e),o=t.getHTMLByCell(e,!0),i=new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},{name:"break"},{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm17.94 4.5h-2v4h-2v-4h-2l3-3z"/></svg>',tip:"Insert row above",handle:(t,e)=>{t.appendRow(e,!1),t.hideTableTools()}},{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm15.44 8v-2h-4v-2h4v-2l3 3z"/></svg>',tip:"Insert column right",handle:(t,e)=>{t.appendCol(e,!0),t.hideTableTools()}},{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm11.94 5.5h2v-4h2v4h2l-3 3z"/></svg>',tip:"Insert row below",handle:(t,e)=>{t.appendRow(e,!0),t.hideTableTools()}},{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm14.44 2v2h4v2h-4v2l-3-3z"/></svg>',tip:"Insert column Left",handle:(t,e)=>{t.appendCol(e,!1),t.hideTableTools()}},{name:"break"},{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"/></svg>',tip:"Merge Cell",handle:(t,e)=>{t.mergeCells(e),t.hideTableTools()}},{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"/></svg>',tip:"Split Cell",handle:(t,e)=>{t.splitCell(e),t.hideTableTools()}},{name:"break"},{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41zM22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2zM4 9h4V6H4zm6 0h4V6h-4zm6 0h4V6h-4z"/></svg>',tip:"Delete Row",handle:(t,e)=>{t.removeRow(e),t.hideTableTools()}},{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4zm0 6v4h7v-4zM4 4v4h7V4zm13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59z"/></svg>',tip:"Delete Column",handle:(t,e)=>{t.removeCol(e),t.hideTableTools()}},{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="m15.46 15.88l1.42-1.42L19 16.59l2.12-2.13l1.42 1.42L20.41 18l2.13 2.12l-1.42 1.42L19 19.41l-2.12 2.13l-1.42-1.42L17.59 18zM4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4z"/></svg>',tip:"Delete table",handle:(t,e)=>{t.deleteTable(e)}},{name:"break"},{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"/></svg>',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m12.01 16l-.01.011M12.01 12l-.01.011M12.01 8l-.01.011M8.01 12l-.01.011M16.01 12l-.01.011M21 3.6v16.8a.6.6 0 0 1-.6.6H3.6a.6.6 0 0 1-.6-.6V3.6a.6.6 0 0 1 .6-.6h16.8a.6.6 0 0 1 .6.6"/></svg>',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}}],ye=new Set,Me=n("color-map"),Ne={selectWrapper:Me.b(),used:Me.bm("used"),item:Me.be("item"),btn:Me.be("btn"),map:Me.be("content"),mapRow:Me.be("content-row")};class Ie{tableModule;quill;options;menu=null;updateUsedColor;tooltipItem=[];bem=n("menu");colorItemClass=`color-${Bt()}`;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);p(e)||(e=[]),e.slice(-10).map((t=>ye.add(t)))}catch{}this.updateUsedColor=kt((t=>{if(!t)return;if(ye.add(t),ye.size>10){const t=Array.from(ye).slice(-10);ye.clear(),t.map((t=>ye.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(ye)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Ne.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(Ne.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${Ne.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${Ne.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3)}resolveOptions(t){return Object.assign({tipText:!0,tools:Ce,localstorageKey:"__table-bg-used-color",defaultColorMap:i},t)}getUsedColors(){return ye}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:r=""}=e,a=document.createElement("span");if(a.classList.add(this.bem.be("item")),"break"===s)a.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),u(o)?t.appendChild(o(this.tableModule)):t.innerHTML=o,a.appendChild(t),n&&l){const t=this.createColorChoose(a,{name:s,icon:o,handle:i,isColorChoose:n,key:l,tip:r});this.tooltipItem.push(t),a.classList.add(xe)}else u(i)&&a.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.tableModule.options.texts[s]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose(t,{handle:e,key:s}){const o=document.createElement("div");if(o.classList.add(Ne.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(Ne.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(Ne.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(Ne.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(Ne.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(Ne.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(Ne.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(Ne.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=f({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=St(r,{direction:"right",type:"click",content:a,container:r});if(i.appendChild(n),i.appendChild(l),i.appendChild(r),o.appendChild(i),ye.size>0){const t=document.createElement("div");t.classList.add(Ne.used,this.colorItemClass);for(const e of ye){const s=document.createElement("div");s.classList.add(Ne.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(`.${Ne.item}`))return;this.updateUsedColor(o)}})),St(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=St(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)}}class Le extends Ie{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(xe);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}=Ht(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()}}class Ee extends Ie{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(),Et(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[It(),Nt({limiter:Lt()}),Mt(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}}const Te=t=>!t.full&&"right"===t.align;class Se{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=n("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=m({content:s}),a=m({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=w({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 i=this.tableMain.full,n=!1;const l=[];if(i){let o=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(o<i){if(o=Math.max(s.colMinWidthPre,o),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1;l.push({index:e,width:t[e].width+i-o})}else o=100;n=!0,l.push({index:this.colIndex,width:o})}else if(t[this.colIndex+1]){const e=i+t[this.colIndex+1].width;o=Math.min(e-s.colMinWidthPre,o),n=!0,l.push({index:this.colIndex,width:o},{index:this.colIndex+1,width:e-o})}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,n=!0,l.push({index:this.colIndex,width:e});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,n){const e=this.tableMain.domNode.getBoundingClientRect().width;if(i){let s=0;const o=new Set(l.map((({index:t,width:e})=>(s+=e,t))));for(const[e,i]of t.entries())o.has(e)||(s+=i.width);if(s>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(),i=!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:s,width:o}of l)t[s].width=`${Math.round(o)}${i?"%":"px"}`,this.colWidthChange(s,{px:Math.round(o/100*e),pre:Math.round(o)},i)}this.quill.emitter.emit(o.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),o=e[this.colIndex].domNode.getBoundingClientRect(),i=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=s.colMinWidthPre/100*i.width;let l=i.right;n>o.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,o.left+t));const r=o.x+t;n=Math.min(Math.max(n,r),l)}else Te(this.tableMain)?o.right-n<s.colMinWidthPx&&(n=o.right-s.colMinWidthPx):n-o.x<s.colMinWidthPx&&(n=o.x+s.colMinWidthPx);let l=n-o.x;return Te(this.tableMain)&&(l=o.right-n),this.dragColBreak.style.left=`${n}px`,this.dragColBreak.dataset.w=String(l),{left:n,width:l}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),s=this.tableMain.domNode.getBoundingClientRect(),o=s.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=e[this.colIndex].width,n=this.tableMain.full?i/100*o:i;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const l=document.createElement("div");l.classList.add(this.dragBEM.b()),l.classList.add(this.dragBEM.is("col")),l.dataset.w=String(n);const r={top:s.y,left:t.clientX,height:s.height};Object.assign(l.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(l),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=l,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(o.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let o=t.clientY;return o-e.y<s.rowMinHeightPx&&(o=e.y+s.rowMinHeightPx),this.dragRowBreak.style.top=`${o}px`,this.dragRowBreak.dataset.h=String(o-e.y),{top:o,height:o-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,s=this.tableMain.domNode.getBoundingClientRect(),o=document.createElement("div");o.classList.add(this.dragBEM.b()),o.classList.add(this.dragBEM.is("row")),o.dataset.h=String(e);const i={top:t.clientY,left:s.x,width:s.width};Object.assign(o.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});const n=document.body;return n.appendChild(o),this.dragRowBreak&&n.removeChild(this.dragRowBreak),this.dragRowBreak=o,i}update(){}destroy(){}}class Re extends Se{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=n("resize-box");constructor(e,s,o){super(e,o),this.tableModule=e,this.table=s,this.tableMain=t.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=s?`${e.pre}%`:`${e.px}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")));Wt.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")));Wt.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;Te(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",(()=>{if(this.tableModule.tableSelection){const t=this.tableMain.descendants(le),e=this.tableModule.tableSelection;e.selectedTds=t,e.updateWithSelectedTds()}})),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+=`<div class="${this.bem.be("col-header")}" style="width: ${o}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${e.height+this.size-3}px"></div>\n </div>`}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+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(o)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${e.width+this.size-3}px"></div>\n </div>`}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(),Wt.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()}}class Be extends Se{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=n("resize-line");constructor(e,s,o){super(e,o),this.tableModule=e,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(t.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=s=>{if(this.dragging)return;if(this.tableModule.tableSelection&&this.tableModule.tableSelection.dragging)return;const o=this.findTableCell(s);if(!o)return this.hide();const i=t.find(o);i&&this.currentTableCell!==o&&(this.show(),this.currentTableCell=o,this.tableCellBlot=i,this.tableMain=Ot(i,e.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[s]=zt(t,[e.tableBody]),o=s.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;Te(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 s=t.parent;if(!(s instanceof de))return;const[o]=zt(t,[e.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(s),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(t.events.TEXT_CHANGE,this.hideWhenTextChange)}}class ke{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=n("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(e,s,o,i){this.tableModule=e,this.table=s,this.quill=o,this.options=this.resolveOptions(i),this.tableMainBlot=t.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 o=o=>{if(!this.tableMainBlot)return;const i=Te(this.tableMainBlot)?-1:1,n=(o.clientX-this.startX)*i,l=o.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:o}of t)e.width=Math.max(o+r,s.colMinWidthPx);for(const{blot:t,height:o}of e)t.setHeight(`${Math.max(o+a,s.rowMinHeightPx)}px`)},i=()=>{t=[],e=[],document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",i)};this.block.addEventListener("mousedown",(s=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=s.clientX,this.startY=s.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",o),document.addEventListener("mouseup",i))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),Wt.call(this,this.quill.root,(()=>this.update())),Wt.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"};Te(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)}}class Oe{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;bem=n("scrollbar");constructor(t,e,s,o){this.quill=t,this.isVertical=e,this.table=s,this.scrollbarContainer=o,this.container=s.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Wt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:e,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=t.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-e}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<e?`${n}px`:"",this.sizeHeight=i+this.gap<t?`${i}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){const t=document.createElement("div");t.classList.add(this.bem.b()),t.classList.add(this.isVertical?this.bem.is("vertical"):this.bem.is("horizontal"),this.bem.is("transparent")),Object.assign(t.style,{display:"none"}),this.thumb.classList.add(this.bem.be("thumb"));const e=t=>{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 Wt.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=kt((()=>{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=kt((()=>{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)}}class ze{tableModule;table;quill;scrollbarContainer;scrollbar;bem=n("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 Oe(s,!0,e,this.scrollbarContainer),new Oe(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()}}const Ae=Symbol("IsFirstResizeObserve");class $e{tableModule;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];tableMenu;resizeObserver;table;isDisplaySelection=!1;bem=n("selection");shiftKeyDown=!1;keySelectionChange=!1;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};constructor(e,s,o={}){this.tableModule=e,this.quill=s,this.options=this.resolveOptions(o),this.cellSelectWrap=e.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((t=>{t.some((t=>{const e=t.target[Ae];return t.target[Ae]=!1,e}))||this.hide()})),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.mouseDownHandler,{passive:!1}),this.quill.root.addEventListener("keydown",this.keydownHandler,{passive:!1}),this.quill.root.addEventListener("keyup",this.keyupHandler,{passive:!1}),document.addEventListener("selectionchange",this.selectionChangeHandler,{passive:!1}),this.quill.on(t.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(e,s,this.options.tableMenuOptions)),this.hide()}getFirstTextNode(t){for(const e of Array.from(t.childNodes))if(e.nodeType===Node.TEXT_NODE)return e;return t}getLastTextNode(t){for(let e=t.childNodes.length-1;e>=0;e--){const s=t.childNodes[e];if(s.nodeType===Node.TEXT_NODE)return s}return t}getNodeTailOffset(t){const e=document.createRange();return e.selectNodeContents(t),e.collapse(!1),e.startOffset}quillSelectionChangeHandler=t=>{if(t&&this.isDisplaySelection){const s=this.quill.getFormat(t),[o]=this.quill.getLine(t.index);let i=!!s[e.tableCellInner]&&!!o;i&&(i&&=this.selectedTds.some((t=>t.children.contains(o)))),i||this.hide()}};keyupHandler=t=>{"Shift"===t.key&&(this.shiftKeyDown=!1)};keydownHandler=t=>{const e=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","End","Home","PageDown","PageUp"]);t.shiftKey&&(this.shiftKeyDown=!0,e.has(t.key)&&(this.keySelectionChange=!0))};setSelectionData(t,e){const{anchorNode:s,anchorOffset:o,focusNode:i,focusOffset:n}=e;if(!s||!i)return;const l=document.createRange(),r=this.selectionDirectionUp(e);r?(l.setStart(s,o),l.setEnd(s,o)):(l.setStart(s,o),l.setEnd(i,n)),t.removeAllRanges(),t.addRange(l),r&&t.extend(i,n)}selectionDirectionUp(t){const{anchorNode:e,anchorOffset:s,focusNode:o,focusOffset:i}=t;if(!e||!o)return!1;if(e===o)return s>i;const n=e.compareDocumentPosition(o);return n&Node.DOCUMENT_POSITION_CONTAINS||n&Node.DOCUMENT_POSITION_CONTAINED_BY?!!(n&Node.DOCUMENT_POSITION_FOLLOWING):!!(n&Node.DOCUMENT_POSITION_PRECEDING)}findWrapSelection(t){let e=null,s=0,o=null,i=0;for(const{node:n,offset:l}of t)n&&(e&&!this.selectionDirectionUp({anchorNode:e,anchorOffset:s,focusNode:n,focusOffset:l})||(e=n,s=l),o&&!this.selectionDirectionUp({anchorNode:n,anchorOffset:l,focusNode:o,focusOffset:i})||(o=n,i=l));return{startNode:e,startOffset:s,endNode:o,endOffset:i}}resolveOptions(t){return Object.assign({selectColor:"#0589f340",tableMenuOptions:{}},t)}selectionChangeHandler=()=>{const s=window.getSelection(),o=this.keySelectionChange;if(this.keySelectionChange=!1,!s)return;const{anchorNode:i,focusNode:n,anchorOffset:l,focusOffset:r}=s;if(!i||!n)return;const a=t.find(i),c=t.find(n);if(!a||!c||a.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;const d=At(a),h=At(c);if(a&&a.statics.blotName===e.tableWrapper&&c&&c.statics.blotName===e.tableWrapper){const t=document.createRange();t.setStart(i,l),t.setEnd(n,r);const e=t.collapsed;if(0===l&&e){const t=this.getFirstTextNode(a.prev.domNode),e=this.getNodeTailOffset(t);return this.setSelectionData(s,{anchorNode:t,anchorOffset:e,focusNode:t,focusOffset:e})}return this.quill.blur()}const u=d.has(e.tableColgroup),p=h.has(e.tableColgroup);if(u||p){let t=i,o=l,a=n,c=r;if(u){t=d.get(e.tableWrapper).descendants(le)[0].domNode,o=0}if(p){a=h.get(e.tableWrapper).descendants(le)[0].domNode,c=0}return void this.setSelectionData(s,{anchorNode:t,anchorOffset:o,focusNode:a,focusOffset:c})}const b=d.has(e.tableCellInner),m=h.has(e.tableCellInner);let f=b&&m;if(f){const t=d.get(e.tableCellInner),s=h.get(e.tableCellInner);f&&=t!==s}if(b&&m&&f||!b&&m||!m&&b){if(o)this.setSelectionData(s,this.lastSelection);else{const t=this.selectionDirectionUp(s),o=b?d.get(e.tableWrapper):h.get(e.tableWrapper),a=this.getLastTextNode(o.next.domNode),c=this.getFirstTextNode(o.prev.domNode);let{startNode:u,startOffset:p,endNode:m,endOffset:f}=this.findWrapSelection([{node:c,offset:this.getNodeTailOffset(c)},{node:a,offset:0},{node:i,offset:l},{node:n,offset:r}]);t&&([u,p,m,f]=[m,f,u,p]),this.lastSelection={anchorNode:u,anchorOffset:p,focusNode:m,focusOffset:f},this.setSelectionData(s,this.lastSelection)}this.selectedTds.length>0&&this.hide()}else this.lastSelection={anchorNode:i,anchorOffset:l,focusNode:n,focusOffset:r}};helpLinesInitial(){this.cellSelectWrap.style.setProperty("--select-color",this.options.selectColor);const t=document.createElement("div");return t.classList.add(this.bem.be("line")),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(e,s){if(!this.table)return[];const o=t.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=e.x-n+this.startScrollX,h=e.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(Rt({x:Math.floor(u.x),y:Math.floor(u.y),x1:Math.floor(u.x1),y1:Math.floor(u.y1)},{x:Math.floor(e),y:Math.floor(s),x1:Math.floor(o),y1:Math.floor(n)},0,0===p.size)){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}}}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=>{if(this.shiftKeyDown)return;const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n)return;this.setSelectionTable(n);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.dragging=!0,this.show();const d=t=>{this.tableMenu&&this.tableMenu.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.hide();const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table");if(0!==e||!n||n.dataset.tableId!==l)return;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.selectedTds.length>0&&this.tableMenu.update()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)};updateWithSelectedTds(){if(this.selectedTds.length<=0)return;const t={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(const s of this.selectedTds){const o=s.domNode.getBoundingClientRect();t.x=Math.min(t.x,o.left),t.y=Math.min(t.y,o.top),e.x=Math.max(e.x,o.right),e.y=Math.max(e.y,o.bottom)}this.selectedTds=this.computeSelectedTds(t,e),this.selectedTds.length>0&&(this.show(),this.update())}update(){this.quill.scroll.observer.disconnect();for(const t of Array.from(this.quill.root.querySelectorAll(`.ql-table .${this.bem.bm("selected")}`)))t.classList.remove(`${this.bem.bm("selected")}`);for(const t of this.selectedTds)t.domNode.classList.add(`${this.bem.bm("selected")}`);if(this.quill.scroll.observer.observe(this.quill.scroll.domNode,{attributes:!0,characterData:!0,characterDataOldValue:!0,childList:!0,subtree:!0}),0===this.selectedTds.length||!this.boundary||!this.table)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,{display:"block",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 this.table?{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}:{x:0,y:0}}setSelectionTable(t){this.table!==t&&(this.table&&(this.table[Ae]=void 0,this.resizeObserver.unobserve(this.table)),this.table=t,this.table&&(this.table[Ae]=!0,this.resizeObserver.observe(this.table)))}show(){this.table&&(Dt.call(this),this.isDisplaySelection=!0,this.update(),Wt.call(this,this.quill.root,(()=>{this.update()})),Wt.call(this,this.table.parentElement,(()=>{this.update()})))}hide(){this.boundary=null;for(const t of this.selectedTds)t.domNode.classList.remove(`${this.bem.bm("selected")}`);this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.setSelectionTable(void 0),this.tableMenu&&this.tableMenu.hide()}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Dt.call(this),this.quill.root.removeEventListener("mousedown",this.mouseDownHandler),this.quill.root.removeEventListener("keydown",this.keydownHandler),this.quill.root.removeEventListener("keyup",this.keyupHandler),document.removeEventListener("selectionchange",this.selectionChangeHandler),this.quill.off(t.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}}const qe=t.import("delta"),He=t.import("blots/break"),We=t.import("ui/icons"),De=(t,{tableId:s,rowId:o,colId:i})=>{const n={tableId:s,rowId:o,colId:i,colspan:1,rowspan:1},l=t.create(e.tableCell,n),r=t.create(e.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l},Fe=t=>{let e=Number.parseFloat(t.getAttribute("width")||s.colDefaultWidth);if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e},je=new Set([e.tableCellInner]),Pe=t=>{return!(!t||!t.parent)&&(e=t.parent,!!je.has(e.statics.blotName)||Pe(t.parent));var e};class Ve{static moduleName="table-up";static toolName=e.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,s){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof we)return o.prev.remove(),!1;if(s.format[e.tableCellInner]){if(0===o.offset(Ot(o,e.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,s){const o=this.quill.getLine(t.index),i=o[0],n=o[1];if((i.next instanceof we||i.next instanceof be)&&n===i.length()-1)return!1;if(s.format[e.tableCellInner]){if(i===Ot(i,e.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[e.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(s){const[o,i]=this.quill.getLine(s.index);if(this.quill.getFormat(s.index+i+1,1)[e.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(s.index+1,"\n"),this.quill.setSelection(s.index+1,t.sources.SILENT),!1;return!0}}};static register(){we.allowedChildren=[me],me.allowedChildren=[he,fe],me.requiredContainer=we,fe.allowedChildren=[be],fe.requiredContainer=me,he.allowedChildren=[de],he.requiredContainer=me,de.allowedChildren=[ue],ue.requiredContainer=he,ue.allowedChildren=[le,He],ue.requiredContainer=de,le.requiredContainer=ue,t.register({"blots/scroll":ce,"blots/block":Ut,[`blots/${e.container}`]:_t,"formats/header":te,"formats/list":se,"formats/blockquote":Zt,"formats/code-block":Qt,[`formats/${e.tableCell}`]:ue,[`formats/${e.tableCellInner}`]:le,[`formats/${e.tableRow}`]:de,[`formats/${e.tableBody}`]:he,[`formats/${e.tableCol}`]:be,[`formats/${e.tableColgroup}`]:fe,[`formats/${e.tableMain}`]:me,[`formats/${e.tableWrapper}`]:we},!0)}quill;options;toolBox;fixTableByLisenter=kt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(t,e){if(this.quill=t,this.options=this.resolveOptions(e||{}),!this.options.scrollbar){const t=n("scrollbar");this.quill.container.classList.add(t.bm("origin"))}const s=n("toolbox");this.toolBox=this.quill.addContainer(s.b()),this.options.selection&&(this.tableSelection=new this.options.selection(this,this.quill,this.options.selectionOptions));const i=this.quill.getModule("toolbar");if(i&&this.quill.theme.pickers){const[,t]=(i.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}=Ht(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 l=this.quill.getModule("keyboard");for(const t of Object.values(Ve.keyboradHandler))t.bindInHead?l.bindings[t.key].unshift(t):l.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const e=t.composedPath();if(!e||e.length<=0)return;const s=e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(s){if(this.table===s)return this.tableSelection&&this.tableSelection.show(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(s)}else this.table&&this.hideTableTools()}),!1),this.quill.on(o.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.updateWithSelectedTds()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if(b(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:We.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?",CopyCell:"Copy cell",CutCell:"Cut cell",InsertTop:"Insert row above",InsertRight:"Insert column right",InsertBottom:"Insert row below",InsertLeft:"Insert column Left",MergeCell:"Merge Cell",SplitCell:"Split Cell",DeleteRow:"Delete Row",DeleteColumn:"Delete Column",DeleteTable:"Delete table",BackgroundColor:"Set background color",BorderColor:"Set border color"},t)}pasteTableHandler(){let t=Bt(),o=Bt(),i=[],n=[],l=0,r=0;const a=(t,s,o)=>{const i=this.quill.getSelection(!0),n=this.quill.getFormat(i)[e.tableCellInner];if(n)for(const t of s.ops)t.attributes||(t.attributes={}),t.attributes[e.tableCellInner]=n;return s};this.quill.clipboard.addMatcher(Node.TEXT_NODE,a),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,a),this.quill.clipboard.addMatcher("table",((o,a)=>{if(0===a.ops.length)return a;const c=this.quill.getFormat()[e.tableCellInner],d=[],h=[];for(let t=0;t<a.ops.length;t++){const{attributes:s,insert:o}=a.ops[t],{table:i,[e.tableCell]:n,...l}=s||{},r=o&&o[e.tableCol];if(c){if(r)continue;const{[e.tableCellInner]:t,...s}=l;d.push({attributes:{...s,[e.tableCellInner]:c},insert:o})}else r?h.push({insert:o}):d.push({attributes:l,insert:o})}if(!c){const n=((t,e)=>{const o=new Array(e).fill(s.colDefaultWidth),i=Array.from(t.querySelectorAll("tr"));for(const t of i){const s=Array.from(t.querySelectorAll("td"));for(const[t,i]of s.entries()){if(!(t<e))break;{const e=Fe(i);o[t]=e||o[t]}}}return o})(o,i.length).reduce(((s,o,n)=>(h[n]?s.push(h[n]):s.push({insert:{[e.tableCol]:{tableId:t,colId:i[n],width:o,full:!1}}}),s)),[]);d.unshift(...n),d.unshift({insert:"\n"}),d.push({insert:"\n"})}return t=Bt(),i=[],n=[],l=0,r=0,new qe(d)})),this.quill.clipboard.addMatcher("colgroup",((t,s)=>{const o=[];for(let t=0;t<s.ops.length;t++){const n=s.ops[t];n&&(null!==(i=n.insert)&&"object"==typeof i)&&n.insert[e.tableCol]&&o.push(n)}var i;return new qe(o)})),this.quill.clipboard.addMatcher("col",(s=>{i[r]=Bt();const o=(new qe).insert({[e.tableCol]:Object.assign(be.value(s),{tableId:t,colId:i[r]})});return r+=1,o})),this.quill.clipboard.addMatcher("tr",((t,s)=>{o=Bt(),l=0;for(const t of s.ops)if(t.attributes&&t.attributes.background&&t.attributes[e.tableCellInner]){const s=t.attributes[e.tableCellInner];s.style||(s.style=""),t.attributes[e.tableCellInner].style=`background:${t.attributes.background};${s.style}`}for(const[t,e]of n.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(n[t]={rowspan:0,colspan:0});return s}));const c=(s,r)=>{const a=s,c=ue.formats(a);if(!i[l]||!n[l])for(let t=l;t>=0;t--)i[t]||(i[t]=Bt()),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:o,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:s,attributes:o}=t;if(t.insert){const t={...o};delete t[e.tableCell],p.push({insert:s,attributes:{...t,[e.tableCellInner]:u}})}}return new qe(p)};this.quill.clipboard.addMatcher("td",c),this.quill.clipboard.addMatcher("th",c)}showTableTools(t){t&&(this.table=t,this.tableSelection?.show(),this.options.align&&(this.tableAlign=new this.options.align(this,t,this.quill,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,this.quill,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,this.quill,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,this.quill,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection?.hide(),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||!u(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=n("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 l=document.createElement("span");l.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),e.appendChild(l),s.appendChild(e)}e.options.innerHTML="",e.options.appendChild(s)}setCellAttrs(t,e,s,o=!1){if(0!==t.length)for(const i of t)i.setFormatValue(e,s,o)}getTextByCell(t){let e="";for(const s of t){const t=s.offset(this.quill.scroll),o=s.length();for(const s of this.quill.getContents(t,o).ops)b(s.insert)&&(e+=s.insert)}return e}getHTMLByCell(t,s=!1){if(0===t.length)return"";let o=null;try{for(const s of t){const t=Ot(s,e.tableMain);if(o||(o=t),t!==o)return console.error("tableMain is not same"),""}}catch{return console.error("tds must be in same tableMain"),""}const i=o.children.head,n=o.children.tail;if(!n||!i)return console.error("tableMain has no tbody or colgroup"),"";function l(t){const e=t.tagName.toLowerCase(),s=Array.from(t.attributes).map((t=>`${t.name}="${t.value}"`)).join(" ");return{startTag:`<${e}${s?` ${s}`:""}>`,endTag:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(e)?"":`</${e}>`}}let r="";const a=new Set;let c=null,d=0;for(const e of t){if(!c||c!==e.parent.parent){if(c){const{endTag:t}=l(c.domNode);""!==r&&(r+=t)}d+=1,c=e.parent.parent;const{startTag:t}=l(c.domNode);r=`${r}${t}`}r+=e.parent.domNode.outerHTML,a.add(e.colId)}r+=`</${c?c.domNode.tagName.toLocaleLowerCase():""}>`;const{startTag:h,endTag:u}=l(n.domNode);r=`${h}${r}${u}`;const p=o.getCols(),{startTag:b,endTag:m}=l(i.domNode);let f="",g=0,w=!1;for(const t of p.filter((t=>a.has(t.colId)))){const{startTag:e}=l(t.domNode);f+=e,g+=t.width,w&&=t.full}r=b+f+m+r;const v=o.domNode.cloneNode();v.style.width=`${g}${w?"%":"px"}`;const{startTag:x,endTag:C}=l(v);r=x+r+C;const{startTag:y,endTag:M}=l(o.parent.domNode);if(r=y+r+M,s){if(d===o.getRows().length)this.removeCol(t);else for(const e of t)e.domNode.innerHTML="<p><br></p>"}return r}insertTable(o,i){if(o>=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(Pe(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=Bt(),p=new Array(i).fill(0).map((()=>Bt())),b=this.options.full?`${Math.max(1/i*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(h/i),s.colMinWidthPx)}px`,m=[{retain:n.index},{insert:"\n"}];for(let t=0;t<i;t++)m.push({insert:{[e.tableCol]:{width:b,tableId:u,colId:p[t],full:this.options.full}}});for(let t=0;t<o;t++){const t=Bt();for(let s=0;s<i;s++)m.push({insert:"\n",attributes:{[e.tableCellInner]:{tableId:u,rowId:t,colId:p[s],rowspan:1,colspan:1}}})}this.quill.updateContents(new qe(m),t.sources.USER),this.quill.setSelection(n.index+i+i*o+1,t.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${me.className}">\n <tbody>\n <tr>\n <td class="${ue.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=we.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<s.length;){if(a[r]){r+=1;continue}const d=c[l];if(d&&d.colId===s[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:i}=d;if(s>1)for(let t=1;t<s;t++)a[r+t]=!0;if(i>1)for(let e=t+1;e<t+i;e++)for(let t=0;t<s;t++)o[e][r+t]=!0;l+=1}else n.insertBefore(De(this.quill.scroll,{tableId:i,colId:s[r],rowId:n.rowId}),d);r+=1}if(l<c.length)for(let t=l;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(me))this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(t.events.SCROLL_OPTIMIZE,(t=>{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)))}))}deleteTable(t){if(0===t.length)return;const s=Ot(t[0],e.tableMain);s&&s.remove(),this.hideTableTools()}appendRow(t,s){if(t.length<=0)return;const o=t[s?t.length-1:0],[i,n,l]=zt(o,[e.tableMain,e.tableBody,e.tableRow]),r=i.getRows().indexOf(l)+(s?o.rowspan:0);n.insertRow(r)}appendCol(t,s){if(t.length<=0)return;const[o]=t.reduce(((t,e)=>{const o=e.getColumnIndex();return(!s&&o<=t[1]||s&&o>=t[1])&&(t=[e,o]),t}),[t[0],t[0].getColumnIndex()]),i=o.getColumnIndex()+(s?o.colspan:0),n=Ot(o,e.tableMain),l=n.tableId,r=Bt(),[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(t){if(t.length<=0)return;const s=Ot(t[0],e.tableMain),o=s.getRows();let i=o.length,n=-1;for(const s of t){const t=Ot(s,e.tableRow),l=o.indexOf(t);l<i&&(i=l),l+s.rowspan>n&&(n=l+s.rowspan)}const l={};for(let t=i;t<Math.min(o.length,n);t++){o[t].foreachCellInner((e=>{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],e=s.tableId;for(const[s,{colIndex:o,colspan:i,rowspan:n}]of Object.entries(l))t.insertCell(o,{tableId:e,rowId:t.rowId,colId:s,colspan:i,rowspan:n})}this.fixTableByRemove(s)}removeCol(t){if(t.length<=0)return;const s=t[0],o=Ot(s,e.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=s.getColumnIndex(),r=o.descendants(de);for(let t=0;t<n;t++){const t=[];let e=0;for(const s of Object.values(r)){const o=t.shift()||0;if(e>0){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<n;t++)a.removeColByIndex(l);this.fixTableByRemove(o)}mergeCells(t){if(t.length<=1)return;const s=t.reduce(((t,e,s)=>{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(s[0])),i=Math.max(...Object.values(s[1])),n=s[2];n.colspan=i,n.rowspan=o;const l=Ot(n,e.tableMain);this.fixTableByRemove(l)}splitCell(t){if(1!==t.length)return;const s=t[0];if(1===s.colspan&&1===s.rowspan)return;const[o,i]=zt(s,[e.tableMain,e.tableRow]),n=o.tableId,l=s.getColumnIndex(),r=o.getColIds().slice(l,l+s.colspan).reverse();let a=i,c=s.rowspan;for(s.colspan=1,s.rowspan=1;a&&c>0;){for(const t of r)a===i&&t===s.colId||a.insertCell(l+(a===i?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}function _e(t){je.delete(e.tableCellInner),Object.assign(e,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(o,t.tableUpEvent||{}),Ve.toolName=e.tableWrapper,_t.blotName=e.container,we.blotName=e.tableWrapper,me.blotName=e.tableMain,fe.blotName=e.tableColgroup,be.blotName=e.tableCol,he.blotName=e.tableBody,de.blotName=e.tableRow,ue.blotName=e.tableCell,le.blotName=e.tableCellInner}function Xe(t,e){return x({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})}export{Ut as BlockOverride,Zt as BlockquoteOverride,Qt as CodeBlockOverride,_t as ContainerFormat,te as HeaderOverride,se as ListItemOverride,ce as ScrollOverride,Oe as Scrollbar,ve as TableAlign,he as TableBodyFormat,ue as TableCellFormat,le as TableCellInnerFormat,be as TableColFormat,fe as TableColgroupFormat,me as TableMainFormat,Ie as TableMenuCommon,Le as TableMenuContextmenu,Ee as TableMenuSelect,Re as TableResizeBox,Se as TableResizeCommon,Be as TableResizeLine,ke as TableResizeScale,de as TableRowFormat,$e as TableSelection,Ve as TableUp,ze as TableVirtualScrollbar,we as TableWrapperFormat,e as blotName,f as createColorPicker,x as createSelectBox,St as createTooltip,Ve as default,Xe as defaultCustomSelect,Ot as findParentBlot,zt as findParentBlots,Te as isTableAlignRight,Bt as randomId,je as tableCantInsert,o as tableUpEvent,s as tableUpSize,_e as updateTableConstants};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|