quill-table-up 2.2.3 → 2.2.4

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.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"quill";const e={container:"table-up-container",tableCaption:"table-up-caption",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={moduleName:"table-up"},n=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],l="table-up",r=new Set([e.tableCellInner]);function a(t){return!(!t||!t.parent)&&(e=t.parent,!!r.has(e.statics.blotName)||a(t.parent));var e}function c(t,e=l){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}`}}function d(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 h(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 u(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 p(t,e){const s=[],o=t.children.iterator();let i=null;for(;i=o();)i instanceof e&&s.push(i);return s}function b(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}function m(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)}function f(t){return{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))}}function g(t){let{r:e,g:s,b:o,a:i}=t;e=m(e,255),s=m(s,255),o=m(o,255);const n=Math.max(e,s,o),l=Math.min(e,s,o);let r;const a=n,c=n-l,d=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(s-o)/c+(s<o?6:0);break;case s:r=(o-e)/c+2;break;case o:r=(e-s)/c+4}r/=6}return{h:360*r,s:100*d,b:100*a,a:i}}function w(t){let{h:e,s:s,b:o,a:i}=t;e=6*m(e,360),s=m(s,100),o=m(o,100);const n=Math.floor(e),l=e-n,r=o*(1-s),a=o*(1-l*s),c=o*(1-(1-l)*s),d=n%6,h=[o,a,r,r,c,o][d],u=[c,o,o,a,r,r][d],p=[r,r,c,o,o,a][d];return{r:Math.round(255*h),g:Math.round(255*u),b:Math.round(255*p),a:i}}function v(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("")}const C=t=>v(w(t)),x=t=>"function"==typeof t,y=Array.isArray,M=t=>"string"==typeof t,I=t=>null!==t&&"object"==typeof t;function N(t){const{type:e="default",content:s}=t||{},o=c("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(M(s)?i.textContent=s:i.appendChild(s)),i}function T(t={}){const e=230,s=150,o=10;let i=g((n=(n=t.color||"#ff0000").startsWith("#")?n.slice(1):n,{r:Number.parseInt(n.slice(0,2),16),g:Number.parseInt(n.slice(2,4),16),b:Number.parseInt(n.slice(4,6),16),a:Number((Number.parseInt(n.slice(6,8)||"ff",16)/255).toFixed(2))}));var n;const l=c("color-picker"),r=document.createElement("div");r.classList.add(l.b());const a=document.createElement("div");a.classList.add(l.be("content"));const d=document.createElement("div");d.classList.add(l.be("selector"));const h=document.createElement("div");h.classList.add(l.be("background")),d.appendChild(h);const u=document.createElement("div");u.classList.add(l.be("background-handle")),h.appendChild(u);const p=document.createElement("div");p.classList.add(l.be("alpha"));const b=document.createElement("div");b.classList.add(l.be("alpha-bg"));const m=document.createElement("div");m.classList.add(l.be("alpha-handle")),p.appendChild(b),p.appendChild(m);const x=document.createElement("div");x.classList.add(l.be("hue"));const y=document.createElement("div");y.classList.add(l.be("hue-handle")),x.appendChild(y);const M=document.createElement("div");M.classList.add(l.be("action"));const[I,N,T,L]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(l.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(l.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(f(g(Object.assign({},w(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));a.appendChild(x),a.appendChild(d),a.appendChild(p),r.appendChild(a),r.appendChild(M);let E=!1,S=!1,B=!1;function R(){const t=C(i);for(const[e,s]of[I,N,T].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));L.value=String((100*i.a).toFixed(0))}function k(){Object.assign(u.style,{left:`${Math.floor(e*i.s/100)}px`,top:`${Math.floor(s*(100-i.b)/100)}px`}),d.style.backgroundColor=`#${v(w({h:i.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*i.h/360)}px`,m.style.left=100*i.a+"%",function(){const{r:t,g:e,b:s}=w(i);b.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),R()}function O(e){i=f(Object.assign({},i,e)),R(),t.onChange&&t.onChange(`#${C(i)}`)}function A(t){const o=d.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 z(t){const e=x.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 q(t){const{pageX:e}=t,s=p.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 $(t){E&&(t.preventDefault(),A(t)),S&&(t.preventDefault(),z(t)),B&&(t.preventDefault(),q(t))}function H(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",H),E=!1}function W(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",W),S=!1}function D(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",D),B=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",H),E=!0,A(t)})),x.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",W),S=!0,z(t)})),p.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",D),B=!0,q(t)})),k(),r}let L=8e3;function E({child:t,target:e=document.body,beforeClose:s=()=>{}}={}){const o=c("dialog"),i=e,n=document.createElement("div");n.classList.add(o.b()),n.style.zIndex=String(L);const l=document.createElement("div");if(l.classList.add(o.be("overlay")),n.appendChild(l),t){const e=document.createElement("div");e.classList.add(o.be("content")),e.appendChild(t),l.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const r=getComputedStyle(i).overflow;i.style.overflow="hidden",i.appendChild(n);const a=()=>{s(),n.remove(),i.style.overflow=r};return n.addEventListener("click",a),L+=1,{dialog:n,close:a}}function S(t,e){const s=c("input");e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,o.appendChild(e)}const i=document.createElement("div");i.classList.add(s.be("input"));const n=document.createElement("input");for(const t in e)n.setAttribute(t,e[t]);(e.max||e.min)&&n.addEventListener("blur",(()=>{e.max&&e.max<=Number(n.value)&&(n.value=String(e.max)),e.min&&e.min>=Number(n.value)&&(n.value=String(e.min))})),i.appendChild(n),o.appendChild(i),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:n,errorTip:t=>{let e;i.classList.contains("error")?e=i.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),i.appendChild(e)),e.textContent=t,i.classList.add("error");return{removeError:()=>{i.classList.remove("error"),e.remove()}}}}}function B(t={}){const e=c("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 function(t={}){const e=c("creator"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("input"));const{item:i,input:n,errorTip:l}=S(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:r,input:a,errorTip:d}=S(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(r),s.appendChild(o);const h=document.createElement("div");h.classList.add(e.be("control"));const u=N({type:"confirm",content:t.confirmText||"Confirm"}),p=N({type:"default",content:t.cancelText||"Cancel"});h.appendChild(u),h.appendChild(p),s.appendChild(h);const b=(e=Number(n.value),s=Number(a.value))=>{if(Number.isNaN(e)||e<=0)l(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")}},m=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",m))};return new Promise(((t,e)=>{const{close:o}=E({child:s,beforeClose:e});n.focus();for(const e of[n,a])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",m),p.addEventListener("click",o)}))}(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s}const R=Math.min,k=Math.max,O=Math.round,A=Math.floor,z=t=>({x:t,y:t}),q={left:"right",right:"left",bottom:"top",top:"bottom"},$={start:"end",end:"start"};function H(t,e,s){return k(t,R(e,s))}function W(t,e){return"function"==typeof t?t(e):t}function D(t){return t.split("-")[0]}function F(t){return t.split("-")[1]}function j(t){return"x"===t?"y":"x"}function P(t){return"y"===t?"height":"width"}function V(t){return["top","bottom"].includes(D(t))?"y":"x"}function _(t){return j(V(t))}function X(t){return t.replace(/start|end/g,(t=>$[t]))}function U(t){return t.replace(/left|right|bottom|top/g,(t=>q[t]))}function Y(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 G(t,e,s){let{reference:o,floating:i}=t;const n=V(e),l=_(e),r=P(l),a=D(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(F(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function K(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}=W(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=Y(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},C=Y(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-C.top+b.top)/v.y,bottom:(C.bottom-f.bottom+b.bottom)/v.y,left:(f.left-C.left+b.left)/v.x,right:(C.right-f.right+b.right)/v.x}}function Z(){return"undefined"!=typeof window}function Q(t){return et(t)?(t.nodeName||"").toLowerCase():"#document"}function J(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function tt(t){var e;return null==(e=(et(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function et(t){return!!Z()&&(t instanceof Node||t instanceof J(t).Node)}function st(t){return!!Z()&&(t instanceof Element||t instanceof J(t).Element)}function ot(t){return!!Z()&&(t instanceof HTMLElement||t instanceof J(t).HTMLElement)}function it(t){return!(!Z()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof J(t).ShadowRoot)}function nt(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=ht(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function lt(t){return["table","td","th"].includes(Q(t))}function rt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function at(t){const e=ct(),s=st(t)?ht(t):t;return["transform","translate","scale","rotate","perspective"].some((t=>!!s[t]&&"none"!==s[t]))||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","translate","scale","rotate","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function ct(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function dt(t){return["html","body","#document"].includes(Q(t))}function ht(t){return J(t).getComputedStyle(t)}function ut(t){return st(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function pt(t){if("html"===Q(t))return t;const e=t.assignedSlot||t.parentNode||it(t)&&t.host||tt(t);return it(e)?e.host:e}function bt(t){const e=pt(t);return dt(e)?t.ownerDocument?t.ownerDocument.body:t.body:ot(e)&&nt(e)?e:bt(e)}function mt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=bt(t),n=i===(null==(o=t.ownerDocument)?void 0:o.body),l=J(i);if(n){const t=ft(l);return e.concat(l,l.visualViewport||[],nt(i)?i:[],t&&s?mt(t):[])}return e.concat(i,mt(i,[],s))}function ft(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function gt(t){const e=ht(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=ot(t),n=i?t.offsetWidth:s,l=i?t.offsetHeight:o,r=O(s)!==n||O(o)!==l;return r&&(s=n,o=l),{width:s,height:o,$:r}}function wt(t){return st(t)?t:t.contextElement}function vt(t){const e=wt(t);if(!ot(e))return z(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:n}=gt(e);let l=(n?O(s.width):s.width)/o,r=(n?O(s.height):s.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const Ct=z(0);function xt(t){const e=J(t);return ct()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:Ct}function yt(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),n=wt(t);let l=z(1);e&&(o?st(o)&&(l=vt(o)):l=vt(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==J(t))&&e}(n,s,o)?xt(n):z(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=J(n),e=o&&st(o)?J(o):o;let s=t,i=ft(s);for(;i&&o&&e!==s;){const t=vt(i),e=i.getBoundingClientRect(),o=ht(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=J(i),i=ft(s)}}return Y({width:d,height:h,x:a,y:c})}function Mt(t,e){const s=ut(t).scrollLeft;return e?e.left+s:yt(tt(t)).left+s}function It(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:Mt(t,o)),y:o.top+e.scrollTop}}function Nt(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=J(t),o=tt(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=ct();(!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=tt(t),s=ut(t),o=t.ownerDocument.body,i=k(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),n=k(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-s.scrollLeft+Mt(t);const r=-s.scrollTop;return"rtl"===ht(o).direction&&(l+=k(e.clientWidth,o.clientWidth)-i),{width:i,height:n,x:l,y:r}}(tt(t));else if(st(e))o=function(t,e){const s=yt(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,n=ot(t)?vt(t):z(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=xt(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return Y(o)}function Tt(t,e){const s=pt(t);return!(s===e||!st(s)||dt(s))&&("fixed"===ht(s).position||Tt(s,e))}function Lt(t,e,s){const o=ot(e),i=tt(e),n="fixed"===s,l=yt(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=z(0);if(o||!o&&!n)if(("body"!==Q(e)||nt(i))&&(r=ut(e)),o){const t=yt(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=Mt(i));const c=!i||o||n?z(0):It(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 Et(t){return"static"===ht(t).position}function St(t,e){if(!ot(t)||"fixed"===ht(t).position)return null;if(e)return e(t);let s=t.offsetParent;return tt(t)===s&&(s=s.ownerDocument.body),s}function Bt(t,e){const s=J(t);if(rt(t))return s;if(!ot(t)){let e=pt(t);for(;e&&!dt(e);){if(st(e)&&!Et(e))return e;e=pt(e)}return s}let o=St(t,e);for(;o&&lt(o)&&Et(o);)o=St(o,e);return o&&dt(o)&&Et(o)&&!at(o)?s:o||function(t){let e=pt(t);for(;ot(e)&&!dt(e);){if(at(e))return e;if(rt(e))return null;e=pt(e)}return null}(t)||s}const Rt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const n="fixed"===i,l=tt(o),r=!!e&&rt(e.floating);if(o===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=z(1);const d=z(0),h=ot(o);if((h||!h&&!n)&&(("body"!==Q(o)||nt(l))&&(a=ut(o)),ot(o))){const t=yt(o);c=vt(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!l||h||n?z(0):It(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:tt,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const n=[..."clippingAncestors"===s?rt(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=mt(t,[],!1).filter((t=>st(t)&&"body"!==Q(t))),i=null;const n="fixed"===ht(t).position;let l=n?pt(t):t;for(;st(l)&&!dt(l);){const e=ht(l),s=at(l);s||"fixed"!==e.position||(i=null),(n?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||nt(l)&&!s&&Tt(t,l))?o=o.filter((t=>t!==l)):i=e,l=pt(l)}return e.set(t,o),o}(e,this._c):[].concat(s),o],l=n[0],r=n.reduce(((t,s)=>{const o=Nt(e,s,i);return t.top=k(o.top,t.top),t.right=R(o.right,t.right),t.bottom=R(o.bottom,t.bottom),t.left=k(o.left,t.left),t}),Nt(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:Bt,getElementRects:async function(t){const e=this.getOffsetParent||Bt,s=this.getDimensions,o=await s(t.floating);return{reference:Lt(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}=gt(t);return{width:e,height:s}},getScale:vt,isElement:st,isRTL:function(t){return"rtl"===ht(t).direction}};function kt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Ot(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=wt(t),d=i||n?[...c?mt(c):[],...mt(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=tt(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 c=t.getBoundingClientRect(),{left:d,top:h,width:u,height:p}=c;if(r||e(),!u||!p)return;const b={rootMargin:-A(h)+"px "+-A(i.clientWidth-(d+u))+"px "+-A(i.clientHeight-(h+p))+"px "+-A(d)+"px",threshold:k(0,R(1,a))||1};let m=!0;function f(e){const o=e[0].intersectionRatio;if(o!==a){if(!m)return l();o?l(!1,o):s=setTimeout((()=>{l(!1,1e-7)}),1e3)}1!==o||kt(c,t.getBoundingClientRect())||l(),m=!1}try{o=new IntersectionObserver(f,{...b,root:i.ownerDocument})}catch(t){o=new IntersectionObserver(f,b)}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?yt(t):null;return a&&function e(){const o=yt(t);m&&!kt(m,o)&&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 At=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=D(s),r=F(s),a="y"===V(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=W(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}}}}},zt=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}=W(t,e),c={x:s,y:o},d=await K(e,a),h=V(D(i)),u=j(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=H(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=H(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}}}}}},qt=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}=W(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=D(i),w=V(r),v=D(r)===r,C=await(null==a.isRTL?void 0:a.isRTL(c.floating)),x=u||(v||!m?[U(r)]:function(t){const e=U(t);return[X(t),e,X(e)]}(r)),y="none"!==b;!u&&y&&x.push(...function(t,e,s,o){const i=F(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[]}}(D(t),"start"===s,o);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map(X)))),n}(r,m,b,C));const M=[r,...x],I=await K(e,f),N=[];let T=(null==(o=n.flip)?void 0:o.overflows)||[];if(d&&N.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=F(t),i=_(t),n=P(i);let l="x"===i?o===(s?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=U(l)),[l,U(l)]}(i,l,C);N.push(I[t[0]],I[t[1]])}if(T=[...T,{placement:i,overflows:N}],!N.every((t=>t<=0))){var L,E;const t=((null==(L=n.flip)?void 0:L.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:T},reset:{placement:e}};let s=null==(E=T.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:E.placement;if(!s)switch(p){case"bestFit":{var S;const t=null==(S=T.filter((t=>{if(y){const e=V(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:S[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},$t=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}=W(t,e),d={x:s,y:o},h=V(i),u=j(h);let p=d[u],b=d[h];const m=W(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(D(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}}}},Ht=(t,e,s)=>{const o=new Map,i={platform:Rt,...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}=G(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}=G(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:n})};let Wt;function Dt(t,e={}){const{msg:s="",delay:o=150,content:i,direction:n="bottom",type:l="hover",container:r,onOpen:a,onClose:d,closed:h,onDestroy:u}=e,p=c("tooltip");if(s||i){Wt||(Wt=document.createElement("div"),document.body.appendChild(Wt));const e=r||Wt,c=document.createElement("div");let b,m,f;c.classList.add(p.b(),"hidden","transparent"),i?c.appendChild(i):s&&(c.textContent=s);const g=()=>{f&&f(),Ht(t,c,{placement:n,middleware:[qt(),zt({limiter:$t()}),At(4)]}).then((({x:t,y:e})=>{Object.assign(c.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{c.classList.add("hidden"),e.contains(c)&&e.removeChild(c),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(a){const t=a(s);if(!s&&t)return}e.appendChild(c),c.removeEventListener("transitionend",w),c.classList.remove("hidden"),f=Ot(t,c,g),c.classList.remove("transparent")}),o)},C=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}!function(t,e,s,o,i){t.addEventListener("transitionend",s,o),setTimeout((()=>{s()}),e)}(c,150,w,{once:!0}),c.classList.add("transparent")}),o)},x=()=>{const e=t=>{t.stopPropagation(),C(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{c.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{C(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,c],s=C.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:C,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",o),t.removeEventListener("mouseleave",s)}}},click:x},{prepare:M,show:I,hide:N,destroy:T}=y[l]();M();const L=()=>{N(!0),u&&u(),T(),f&&f(),c.remove()};return{show:I,hide:N,destroy:L}}return null}function Ft(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)}function jt(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 Pt(t,e={}){const s=Symbol("ignoreFirstBind"),o=new Set,i=new ResizeObserver((o=>{e.ignoreFirstBind&&o.some((t=>{const e=t.target,o=e[s];return e[s]=!0,!o}))||t(o)})),n=i.observe;i.observe=(t,e)=>{o.add(t),n.call(i,t,e)};const l=i.unobserve;i.unobserve=t=>{o.has(t)&&(o.delete(t),t[s]=void 0),l.call(i,t)};const r=i.disconnect;return i.disconnect=()=>{for(const t of o.values())t[s]=void 0;r.call(i)},i}function Vt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function _t(){for(let t=0;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}function Xt(t){const e={},s=t.trim().split(";");for(let t=0;t<s.length;t++){const o=s[t].trim();if(!o)continue;const i=o.indexOf(":");if(-1===i)continue;const n=o.slice(0,Math.max(0,i)).trim(),l=o.slice(Math.max(0,i+1)).trim();e[Yt(n)]=l}return e}function Ut(t){return Object.entries(t).map((([t,e])=>`${function(t){const e=t.replaceAll(/([A-Z])/g," $1").trim();return e.split(" ").join("-").toLowerCase()}(t)}: ${e};`)).join(" ")}function Yt(t){return t.replaceAll(/-(\w)/g,((t,e)=>e.toUpperCase()))}const Gt=()=>Math.random().toString(36).slice(2);function Kt(t,e){let s;return function(...o){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,o)}),e)}}const Zt=t.import("parchment"),Qt=t.import("blots/container"),Jt=t.import("blots/block"),te=t.import("blots/block/embed");class ee extends Qt{static tagName;static blotName=e.container;static scope=Zt.Scope.BLOCK_BLOT;static allowedChildren=[Jt,te,Qt];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())}enforceAllowedChildren(){this.children.forEach((t=>{this.statics.allowedChildren.some((e=>t instanceof e))||(t.statics.scope===Zt.Scope.BLOCK_BLOT?(t.parent instanceof ee?(null!=t.next&&t.parent.splitAfter(t),null!=t.prev&&t.parent.splitAfter(t.prev)):(null!=t.next&&this.splitAfter(t),null!=t.prev&&this.splitAfter(t.prev)),t.parent.unwrap()):t instanceof Zt.ParentBlot?t.unwrap():t.remove())}))}}const se=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},oe=t.import("blots/block"),ie=t.import("blots/block/embed");class ne extends ee{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=oe;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(se(i)),r.dataset.colspan=String(se(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:String(e),rowId:String(s),colId:String(o),rowspan:Number(se(i)),colspan:Number(se(n))};return l&&(r.style=l),r}constructor(t,e,s){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled()))}setFormatValue(t,s,o=!1){if(o){if(!this.statics.isAllowStyle(t))return;this.parent&&this.parent.statics.blotName===e.tableCell&&this.parent.setFormatValue(t,s)}else{if(!this.statics.allowDataAttrs.has(t))return;const o=`data-${t}`;s?this.domNode.setAttribute(o,s):this.domNode.removeAttribute(o),this.parent&&this.parent.statics.blotName===e.tableCell&&this.parent.setFormatValue(t,s)}const i=this.descendants(oe,0);for(const t of i)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 d(this,e.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,o){if(0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,o),o&&o.style){const t=Xt(o.style);for(const[e,s]of Object.entries(t))this.setFormatValue(e,s,!0)}}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 ie){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]=h(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)}}class le extends ee{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)}))}getCellByColId(t,s){const o=d(this,e.tableMain).getColIds(),i=o.indexOf(t),n=this.children.iterator();let l=null;for(;l=n();){if(l.colId===t)return l;const e=o.indexOf(l.colId);if(e<i&&e+l.colspan>i)return l}return this[s]&&this[s].statics.blotName===e.tableRow?this[s].getCellByColId(t,s):null}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(ne);if(1!==o.colspan&&t===i-o.colspan){const t=d(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(ne);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 re extends ee{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=d(this,e.tableMain);if(!s)return;const o=s.getColIds(),i=this.descendants(le),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=Gt(),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)}}const ae=t.import("parchment"),ce=t.import("blots/block");class de extends ce{replaceWith(t,s){const o="string"==typeof t?this.scroll.create(t,s):t;if(o instanceof ae.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),t.statics.blotName===e.tableCellInner){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.remove(),t.parent.statics.blotName===e.tableCell&&0===t.parent.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 try{d(this,e.tableCellInner).unwrap()}catch{console.error("unwrap TableCellInner error")}}}const he=t.import("parchment"),ue=t.import("blots/scroll");class pe extends ue{enable(s=!0){const o=t.import(`formats/${e.tableCellInner}`),i=this.domNode.querySelectorAll(`.${o.className}`);for(const t of Array.from(i))t.setAttribute("contenteditable",String(!!s));const n=t.import(`formats/${e.tableCaption}`),l=this.domNode.querySelectorAll(`.${n.className}`);for(const t of Array.from(l))t.setAttribute("contenteditable",String(!!s));super.enable(s)}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,he.Scope.BLOCK&he.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 ne&&0===l&&(l+=1);for(const[t,e]of Object.entries(i))n.formatAt(0,l,t,e);return n}}const be=t.import("parchment"),me=t.import("blots/inline"),fe=t.import("blots/text");class ge extends de{static blotName=e.tableCaption;static tagName="caption";static className="ql-table-caption";static allowedChildren=[me,fe];static create(t){const{tableId:e}=t,s=super.create();return s.dataset.tableId=e,"bottom"===t.side&&(s.style.captionSide="bottom"),s}static formats(t){const{tableId:e}=t.dataset;return{tableId:String(e),side:"bottom"===t.style.captionSide?"bottom":"top"}}constructor(t,e,s){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled())),this.attachUI(this.createUI()),this.domNode.addEventListener("mouseenter",(()=>{this.scroll.isEnabled()&&(this.uiNode.style.display="flex")})),this.domNode.addEventListener("mouseleave",(()=>{this.scroll.isEnabled()&&(this.uiNode.style.display="none")})),this.uiNode.style.display="none"}createUI(){const t=document.createElement("i");return t.classList.add("ql-table-caption--switch"),t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\r\n \x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e\r\n <path\r\n fill="none"\r\n stroke="currentColor"\r\n stroke-linecap="round"\r\n stroke-linejoin="round"\r\n stroke-width="2"\r\n d="M7 3v18m3-15L7 3L4 6m16 12l-3 3l-3-3m3 3V3"\r\n />\r\n</svg>\r\n',t.addEventListener("click",(()=>{this.scroll.isEnabled()&&(this.side="top"===this.side?"bottom":"top")})),t}get tableId(){return this.domNode.dataset.tableId}set side(t){this.domNode.style.captionSide="bottom"===t?"bottom":"top"}get side(){return"bottom"===this.domNode.style.captionSide?"bottom":"top"}format(t,e){this.scroll.query(t,be.Scope.BLOCK_BLOT)&&t!==this.statics.blotName||super.format(t,e)}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})}0===this.children.length?this.remove():(super.optimize(t),null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()))}}class we extends ee{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(se(i))),r.setAttribute("colspan",String(se(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:se(i),colspan:se(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,s){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let e=t;this.statics.allowDataAttrs.has(t)&&(e=`data-${t}`),s?this.domNode.setAttribute(e,s):this.domNode.removeAttribute(e)}else this.statics.isAllowStyle(t)&&(Object.assign(this.domNode.style,{[t]:s}),t.startsWith("border")&&this.setStyleBoder(t,s));this.children.head&&this.children.head.statics.blotName===e.tableCellInner&&this.domNode.style.cssText&&(this.children.head.domNode.dataset.style=this.domNode.style.cssText)}setStyleBoder(t,e){const s=Boolean(e)?e:null;if(!(!["left","right","top","bottom"].some((e=>t.includes(e)))&&t.startsWith("border-")))return;const o=this.getNearByCell("left").map((t=>t.descendant(ne,0)[0])).filter(Boolean);for(const e of o)e.setFormatValue(t.replace("border-","border-right-"),s,!0);const i=this.getNearByCell("top").map((t=>t.descendant(ne,0)[0])).filter(Boolean);for(const e of i)e.setFormatValue(t.replace("border-","border-bottom-"),s,!0)}getNearByCell(t){const s=[];try{const t=d(this,e.tableMain);s.push(...t.getColIds())}catch(t){console.error(`Cell is not in table! ${t}`)}if(0===s.length)return[];if("left"===t){const t=new Set;let e=this.parent;for(let o=0;o<this.rowspan&&e instanceof le;o++){const o=e.children.iterator();let i=null;for(;i=o();){const e=s.indexOf(i.colId)+i.colspan;this.colId===s[e]&&t.add(i)}e=e.next}return Array.from(t)}if("top"===t){if(!(this.parent instanceof le&&this.parent.prev))return[];const t=new Set,e=this.getColumnIndex(),o=e+this.colspan,i=new Set(s.filter(((t,s)=>s>=e&&s<o)));let n=1,l=this.parent.prev;for(;l;){let e=!1;const o=l.children.iterator();let r=null,a=0;for(;r=o();)i.has(r.colId)&&r.rowspan>=n&&(t.add(r),i.delete(r.colId)),a+=r.colspan,r.rowspan>=n&&(e=!0);if(!e&&a===s.length)break;l=l.prev,n+=1}return Array.from(t)}return[]}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"))}getColumnIndex(){return d(this,e.tableMain).getColIds().indexOf(this.colId)}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 ve=t.import("blots/block/embed");class Ce extends ve{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")||String(s.colDefaultWidth),n=t.dataset.align,l=Object.hasOwn(t.dataset,"full"),r={tableId:String(e),colId:String(o),full:l,width:Number.parseFloat(i)};return n&&(r.align=n),r}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")}set full(t){t?this.domNode.dataset.full=String(!0):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")}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)}d(this,e.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(t);try{const t=d(this,e.tableColgroup);let s=!0;t.children.forEach((t=>{s&&=t.full})),t.full=s}catch{}}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]=h(this,[e.tableColgroup,e.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let u=c.parent.parent,p=c.parent.next;if(d){const t=d.descendants(ne);if(t.length>0){const s=t[0],o=ne.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),u=i,p=i.next}}for(const t of l)u.insertBefore(t,p);n&&u.insertBefore(this.scroll.create("text",n),p)}}class xe extends ee{scroll;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.scroll=t,this.updateAlign()}colWidthFillTable(){if(this.full)return void Object.assign(this.domNode.style,{width:null});const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?void 0:(this.domNode.style.width=`${e}px`,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=String(!0):this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}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()}setFull(){if(this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const s of t){const t=s.width/e*100;s.full=!0,s.width=t}}cancelFull(){if(!this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const o of t)o.full=!1,o.width=Math.max(o.width/100*e,s.colMinWidthPx)}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(le)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(Ce)}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)}sortMergeChildren(){const t={[e.tableCaption]:[],[e.tableColgroup]:[],[e.tableBody]:[]};this.children.forEach((e=>{t[e.statics.blotName]&&t[e.statics.blotName].push(e)}));for(const e of Object.values(t))for(let t=1;t<e.length;t++)e[t].moveChildren(e[0]);const s=t[e.tableCaption][0],o=t[e.tableColgroup][0],i=t[e.tableBody][0],n=s&&this.children.head!==s,l=o&&s&&s.next!==o,r=o&&!s&&this.children.head!==o,a=i&&this.children.tail!==i;if(n||l||r||a){const t=this.clone();s&&t.appendChild(s),o&&t.appendChild(o),i&&t.appendChild(i),this.children.forEach((t=>t.remove())),t.moveChildren(this)}}}class ye extends ee{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=String(!0):this.domNode.removeAttribute("data-full"),this.parent&&this.parent instanceof xe&&(this.parent.full=t)}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 xe))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 xe))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 xe&&!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});d(this,e.tableMain).align=n,super.optimize(t)}}const Me=t.import("parchment");class Ie extends ee{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.setAttribute("contenteditable","false"),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(re),o=this.descendants(ye);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 Me.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this),this.next&&this.next instanceof Me.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this.next)}}function Ne(t){const[e]=p(t,re);return{body:e,rect:e.domNode.getBoundingClientRect()}}class Te{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=c("align");resizeObserver=Pt((()=>this.update()),{ignoreFirstBind:!0});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(),this.resizeObserver.observe(this.table),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.show()}updateWhenTextChange=()=>{this.update()};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=Ot(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.update())}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():Ht(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[qt(),zt({limiter:$t()}),At(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})})))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}}const Le=t.import("delta"),Ee=t.import("modules/clipboard");function Se(t){let e=Number.parseFloat(t.getAttribute("width")||String(s.colDefaultWidth));if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e}class Be extends Ee{quill;tableId=Gt();rowId=Gt();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(t,e){super(t,e),this.quill=t,this.addMatcher("table",this.matchTable.bind(this)),this.addMatcher("tbody",this.matchTbody.bind(this)),this.addMatcher("colgroup",this.matchColgroup.bind(this)),this.addMatcher("col",this.matchCol.bind(this)),this.addMatcher("tr",this.matchTr.bind(this)),this.addMatcher("td",this.matchTd.bind(this)),this.addMatcher("th",this.matchTd.bind(this)),this.addMatcher("caption",this.matchCaption.bind(this)),this.addMatcher(Node.ELEMENT_NODE,this.matchTdAttributor.bind(this))}matchTable(t,o){if(0===o.ops.length)return o;const i=[],n=[];let l=-1;for(let t=0;t<o.ops.length;t++){const{attributes:s,insert:r}=o.ops[t],{table:a,[e.tableCell]:c,...d}=s||{},h=I(r)&&r[e.tableCol];h?n.push({insert:r}):i.push({attributes:d,insert:r}),!d?.[e.tableCellInner]&&!d?.[e.tableCaption]&&!h&&M(r)&&r.trim().length>0&&(l=t)}const r=function(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=Se(i);o[t]=e||o[t]}}}return o}(t,this.colIds.length).reduce(((t,s,o)=>(n[o]?t.push(n[o]):t.push({insert:{[e.tableCol]:{tableId:this.tableId,colId:this.colIds[o],width:s,full:!1}}}),t)),[]);return i.splice(l+1,0,...r),this.tableId=Gt(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,new Le(i)}matchTbody(t,s){const o=t.style.backgroundColor;if(o)for(const t of s.ops)if(t.attributes?.[e.tableCellInner]){const{style:s,...i}=t.attributes[e.tableCellInner],n=Xt(s||"");n.backgroundColor||(n.backgroundColor=o,t.attributes[e.tableCellInner]={...i,style:Ut(n)})}return s}matchColgroup(t,s){const o=[];for(let t=0;t<s.ops.length;t++){const i=s.ops[t];i&&I(i.insert)&&i.insert[e.tableCol]&&o.push(i)}return new Le(o)}matchCol(t){this.colIds[this.colCount]=Gt();const s=(new Le).insert({[e.tableCol]:Object.assign(Ce.value(t),{tableId:this.tableId,colId:this.colIds[this.colCount]})});return this.colCount+=1,s}matchTr(t,s){this.rowId=Gt(),this.cellCount=0;for(const[t,e]of this.rowspanCount.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(this.rowspanCount[t]={rowspan:0,colspan:0});for(const t of s.ops)if(t.attributes){const{background:s,[e.tableCellInner]:o}=t.attributes;if(o&&s){const{style:i=""}=o,n=Xt(i);n.backgroundColor=s,t.attributes[e.tableCellInner].style=Ut(n)}}return s}matchTd(t,s){const o=t,i=we.formats(o);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let t=this.cellCount;t>=0;t--)this.colIds[t]||(this.colIds[t]=Gt()),this.rowspanCount[t]||(this.rowspanCount[t]={rowspan:0,colspan:0});for(let t=this.cellCount;t<this.rowspanCount.length;t++){const{rowspan:e,colspan:s}=this.rowspanCount[t];if(0===e)break;this.cellCount+=s}i.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:i.rowspan,colspan:i.colspan});const n=this.colIds[this.cellCount];this.cellCount+=i.colspan;const l=Object.assign(i,{tableId:this.tableId,rowId:this.rowId,colId:n});"none"===o.style.border&&(l.style=l.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const r=[];for(const t of s.ops){const{attributes:s={},...o}=t,{[e.tableCell]:i,...n}=s;r.push({...o,attributes:{...n,[e.tableCellInner]:l}})}return(r.length<=0||!M(r[r.length-1].insert)||!r[r.length-1].insert.endsWith("\n"))&&r.push({insert:"\n",attributes:{[e.tableCellInner]:l}}),new Le(r)}matchTdAttributor(t,s){if("td"===t.tagName.toLocaleLowerCase()){const t=[];for(const o of s.ops){const{attributes:s,...i}=o,n=s?.[e.tableCellInner];if(s&&n&&n.style){const{background:e,...o}=s,l=document.createElement("div");l.style.background=e;const r=document.createElement("div");if(r.style.cssText=n.style,l.style.background===r.style.backgroundColor){t.push({...i,attributes:{...o}});continue}}t.push(o)}return new Le(t)}return s}convert({html:t,text:s},o={}){const i=super.convert({html:t,text:s},o);if(o[e.tableCellInner])for(const t of i.ops)I(t.insert)&&t.insert[e.tableCol]?t.insert="":(t.attributes||(t.attributes={}),t.attributes[e.tableCellInner]=o[e.tableCellInner]);return i}matchCaption(t,s){for(let t=0;t<s.ops.length;t++){const o=s.ops[t],{attributes:i}=o;i&&i[e.tableCaption]&&(i[e.tableCaption].tableId=this.tableId,o.attributes=i)}return s}}const Re="color-selector",ke={Break:{name:"break"},CopyCell:{name:"CopyCell",tip:"Copy cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256">\n <g fill="currentColor">\n <path d="M216 40v128h-48V88H88V40Z" opacity=".2" />\n <path\n 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"\n />\n </g>\n</svg>\n',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()}},CutCell:{name:"CutCell",tip:"Cut cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32">\n <path\n fill="currentColor"\n 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"\n />\n <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" />\n</svg>\n',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()}},InsertTop:{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert row above",handle:(t,e)=>{t.appendRow(e,!1),t.hideTableTools()}},InsertRight:{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert column right",handle:(t,e)=>{t.appendCol(e,!0),t.hideTableTools()}},InsertBottom:{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert row below",handle:(t,e)=>{t.appendRow(e,!0),t.hideTableTools()}},InsertLeft:{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert column Left",handle:(t,e)=>{t.appendCol(e,!1),t.hideTableTools()}},MergeCell:{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"\n />\n</svg>\n',tip:"Merge Cell",handle:(t,e)=>{t.mergeCells(e),t.hideTableTools()}},SplitCell:{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"\n />\n</svg>\n',tip:"Split Cell",handle:(t,e)=>{t.splitCell(e),t.hideTableTools()}},DeleteRow:{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Delete Row",handle:(t,e)=>{t.removeRow(e),t.hideTableTools()}},DeleteColumn:{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Delete Column",handle:(t,e)=>{t.removeCol(e),t.hideTableTools()}},DeleteTable:{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Delete table",handle:(t,e)=>{t.deleteTable(e)}},BackgroundColor:{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="2"\n d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"\n />\n</svg>\n',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},BorderColor:{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="1.5"\n 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"\n />\n</svg>\n',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}},SwitchWidth:{name:"SwitchWidth",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n \x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="2"\n d="M4 12V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v6m-10 6H3m18 0h-7m-8-3l-3 3l3 3m12-6l3 3l-3 3"\n />\n</svg>\n',tip:"Switch table width",handle:e=>{if(!e.table)return;const s=t.find(e.table);s&&(s.full?s.cancelFull():s.setFull())}},InsertCaption:{name:"InsertCaption",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n \x3c!-- Icon from TDesign Icons by TDesign - https://github.com/Tencent/tdesign-icons/blob/main/LICENSE --\x3e\n <path fill="currentColor" d="M21 10v12h-2V12H5v10H3V10zm0-8v6H3V2zm-2 2H5v2h14z" />\n</svg>\n',tip:"Insert table caption",handle(s){if(!s.table)return;const o=t.find(s.table);if(!o)return;const i=s.quill.scroll.create("text","Table Caption").wrap(e.tableCaption,{tableId:o.tableId});o.insertBefore(i,o.children.head)}}},Oe=c("color-map"),Ae={selectWrapper:Oe.b(),used:Oe.bm("used"),item:Oe.be("item"),btn:Oe.be("btn"),map:Oe.be("content"),mapRow:Oe.be("content-row")};class ze{tableModule;quill;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;updateUsedColor;tooltipItem=[];activeTooltip=null;bem=c("menu");colorItemClass=`color-${Gt()}`;colorChooseTooltipOption={direction:"top"};constructor(e,s,o){this.tableModule=e,this.quill=s,this.options=this.resolveOptions(o);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);y(e)||(e=[]),e.slice(-10).map((t=>this.usedColors.add(t)))}catch{}this.updateUsedColor=Kt((t=>{if(!t)return;if(this.usedColors.add(t),this.usedColors.size>10){const t=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),t.map((t=>this.usedColors.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Ae.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(Ae.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${Ae.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${Ae.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.isMenuDisplay&&this.update()};resolveOptions(t){return Object.assign({tipText:!0,tools:[ke.InsertTop,ke.InsertRight,ke.InsertBottom,ke.InsertLeft,ke.Break,ke.MergeCell,ke.SplitCell,ke.Break,ke.DeleteRow,ke.DeleteColumn,ke.DeleteTable,ke.Break,ke.BackgroundColor,ke.BorderColor],localstorageKey:"__table-bg-used-color",defaultColorMap:n},t)}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"),x(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(Re)}else x(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(Ae.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(Ae.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(Ae.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(Ae.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(Ae.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(Ae.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(Ae.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(Ae.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=T({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Dt(r,{direction:"right",type:"click",content:a,container:r});i.appendChild(n),i.appendChild(l),i.appendChild(r),o.appendChild(i);const h=document.createElement("div");h.classList.add(Ae.used,this.colorItemClass);for(const t of this.usedColors){const e=document.createElement("div");e.classList.add(Ae.item),e.style.backgroundColor=t,h.appendChild(e)}o.appendChild(h),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(`.${Ae.item}`))return;this.updateUsedColor(o)}}));const u=Dt(t,{type:"click",content:o,onOpen:()=>(this.isMenuDisplay&&this.tableModule.tableSelection&&this.tableModule.tableSelection.hideDisplay(),this.setActiveTooltip(u),!1),onClose:()=>{this.isMenuDisplay&&this.tableModule.tableSelection&&(this.tableModule.tableSelection.updateWithSelectedTds(),this.tableModule.tableSelection.showDisplay());return o.contains(a)&&c(),this.activeTooltip===u&&(this.activeTooltip=null),!1},onDestroy:()=>{d(),this.activeTooltip===u&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return u.isColorPick=!0,u}setActiveTooltip(t){this.activeTooltip&&this.activeTooltip!==t&&this.activeTooltip.hide(!0),this.activeTooltip=t}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Dt(t,{msg:e});s&&this.tooltipItem.push(s)}show(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,this.update())}update(){}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.activeTooltip=null;for(const t of this.tooltipItem)t.destroy();this.menu&&(this.hide(),this.menu.remove(),this.menu=null)}}class qe extends ze{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()),Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,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(Re);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)}show(){}update(t){if(!(this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection))return;if(!t)return;super.update();const e={display:"flex",left:0,top:0},{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}=jt(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 $e extends ze{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),this.show(),this.update()}update(){this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection&&(super.update(),Ht(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[qt(),zt({limiter:$t()}),At(20)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}}const He=t=>!t.full&&"right"===t.align;class We{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=c("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=N({content:s}),a=N({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=E({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 He(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 He(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{rect:e,body:s}=Ne(this.tableMain);if(!s)return;const o=this.tableMain.getCols();if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=o[this.colIndex].width,n=this.tableMain.full?i/100*e.width: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:e.y,left:t.clientX,height:e.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 De extends We{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=c("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),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)))}updateWhenTextChange=()=>{this.update()};handleResizerHeader(t,e,s){const{clientX:o,clientY:i}=s,n=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const l=this.tableModule.tableSelection;s.shiftKey||(this.lastHeaderSelect=null);const r=[{x:t?n.left:o,y:t?i:n.top},{x:t?n.right:o,y:t?i:n.bottom}];if(this.lastHeaderSelect){let e,s;if(this.lastHeaderSelect.isX){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=Math.min(t.left,n.left),s=t.top+t.height/2}else{const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=t.left+t.width/2,s=Math.min(t.top,n.top)}this.lastHeaderSelect.isX!==t?(r[1]={x:Math.max(r[0].x,e),y:Math.max(r[0].y,s)},r[0]={x:Math.min(r[0].x,e),y:Math.min(r[0].y,s)}):t?(r[0].y=Math.min(r[0].y,s),r[1].y=Math.max(r[1].y,s)):(r[0].x=Math.min(r[0].x,e),r[1].x=Math.max(r[1].x,e))}else this.lastHeaderSelect={isX:t,index:e};l.table=this.table,l.selectedTds=l.computeSelectedTds(...r),l.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);if(e&&this.dragColBreak){const[t]=p(this.tableMain,ge),s=t&&"top"===t.side?0:this.size;Object.assign(this.dragColBreak.style,{top:e.top-s+"px",left:`${e.left}px`,height:`${e.height+this.size}px`})}return 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")));Vt.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const[e,s]of t.entries())s.addEventListener("click",this.handleResizerHeader.bind(this,!1,e));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")));Vt.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const[e,s]of t.entries())s.addEventListener("click",this.handleResizerHeader.bind(this,!0,e));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const{rect:t,body:e}=Ne(this.tableMain);if(!e)return;const s=this.tableWrapper.domNode.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:Math.max(t.y,s.y)-o.y+"px",left:Math.max(t.x,s.x)-o.x+"px"});let i=-1*this.size,n=-1*this.size;He(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),i=Math.min(s.width,t.width),n=Math.min(s.width,t.width)):this.root.classList.remove(this.bem.is("align-right"));const[l]=p(this.tableMain,ge),r=!l||!(l&&"top"===l.side);r?this.root.classList.remove(this.bem.is("caption-bottom")):this.root.classList.add(this.bem.is("caption-bottom")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${i}px)`,top:`${r?0:t.height+this.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${n}px)`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${r?0:t.height+this.size}px`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const{rect:t,body:e}=Ne(this.tableMain);if(!e)return;const s=this.tableWrapper.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(ne),e=this.tableModule.tableSelection;e.selectedTds=t,e.show(),e.updateWithSelectedTds()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let e="";for(const[,s]of this.tableCols.entries()){const o=s.domNode.getBoundingClientRect().width;e+=`<div class="${this.bem.be("col-header")}" style="width: ${o}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${t.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:`${s.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${t.width}px`}),i.innerHTML=e,o.appendChild(i),this.root.appendChild(o),o.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=o,this.bindColEvents()}if(this.tableRows.length>0){let e="";for(const[,s]of this.tableRows.entries()){const o=`${s.domNode.getBoundingClientRect().height}px`;e+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(o)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${t.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:`${s.height}px`}),Object.assign(i.style,{height:`${t.height}px`}),i.innerHTML=e,o.appendChild(i),this.root.appendChild(o),o.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=o,this.bindRowEvents()}this.update(),Vt.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),_t.call(this),this.resizeObserver.disconnect(),this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange);for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}}class Fe extends We{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=c("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=d(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]=h(t,[e.tableBody]),o=s.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;He(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 le))return;const[o]=h(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(){this.rowResizer.classList.remove(this.bem.is("hidden")),this.colResizer.classList.remove(this.bem.is("hidden"))}hide(){this.currentTableCell=void 0,this.rowResizer.classList.add(this.bem.is("hidden")),this.colResizer.classList.add(this.bem.is("hidden"))}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 je{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=c("scale");startX=0;startY=0;offset=6;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()),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};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=He(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),Vt.call(this,this.quill.root,(()=>this.update())),Vt.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;if(this.tableMainBlot.full)return void this.hide();const{rect:t,body:e}=Ne(this.tableMainBlot);if(!e)return;const s=this.tableWrapperBlot.domNode.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),{scrollTop:i,scrollLeft:n}=this.tableWrapperBlot.domNode,l=2*this.options.blockSize+this.offset,r=Math.min(t.width,s.width)+l,a=Math.min(t.height,s.height)+l;Object.assign(this.root.style,{width:`${r}px`,height:`${a}px`,left:Math.max(t.x,s.x)-o.x-this.options.blockSize+"px",top:Math.max(t.y,s.y)-o.y-this.options.blockSize+"px"});const c={left:t.width+l-n+"px",top:a-i+"px"};He(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),c.left=`${this.options.blockSize+-1*n}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,c)}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.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.root&&this.root.remove(),_t.call(this)}}class Pe{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=c("scrollbar");tableMainBlot;constructor(e,s,o,i){this.quill=e,this.isVertical=s,this.table=o,this.scrollbarContainer=i,this.tableMainBlot=t.find(this.table),this.container=o.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(o),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Vt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{rect:{width:t,height:e},body:s}=Ne(this.tableMainBlot);if(!s)return;const{scrollLeft:o,scrollTop:i,offsetLeft:n,offsetTop:l}=this.quill.root,{offsetLeft:r,offsetTop:a}=this.container,{offsetLeft:c,offsetTop:d}=s.domNode,{width:h,height:u}=this.container.getBoundingClientRect();let p=r+c-n,b=a+d-l;this.isVertical?p+=Math.min(h,t):b+=Math.min(u,e),this.tableMainBlot&&"left"!==this.tableMainBlot.align&&(p+=this.table.offsetLeft-r),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(u,e):h}px`,transform:`translate(${p-o}px, ${b-i}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"));let e=null;const s=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},o=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",o),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=e},i=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",s),document.addEventListener("mouseup",o),e=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),i(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 n=[this.table,t];for(const t of n)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Vt.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(),_t.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}class Ve{tableModule;table;quill;scrollbarContainer;scrollbar;bem=c("scrollbar");constructor(e,s,o){this.tableModule=e,this.table=s,this.quill=o,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Pe(o,!0,s,this.scrollbarContainer),new Pe(o,!1,s,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar);this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};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(),this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange);for(const t of this.scrollbar)t.destroy()}}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=c("selection");lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};constructor(e,s,i={}){this.tableModule=e,this.quill=s,this.options=this.resolveOptions(i),this.cellSelectWrap=e.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=Pt((()=>this.updateAfterEvent()),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.mouseDownHandler,{passive:!1}),document.addEventListener("selectionchange",this.selectionChangeHandler,{passive:!1}),this.quill.on(o.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(t.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(t.events.TEXT_CHANGE,this.updateAfterEvent),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(e,s,this.options.tableMenuOptions)),this.hide()}updateAfterEvent=()=>{this.updateWithSelectedTds()};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=(s,o,i)=>{if(i!==t.sources.API&&s&&this.selectedTds.length>0){const t=this.quill.getFormat(s),[o]=this.quill.getLine(s.index),i=!!t[e.tableCellInner]&&!!o,n=this.selectedTds.some((t=>t.children.contains(o)));if(i&&!n)try{const t=d(o,e.tableCellInner);this.selectedTds=[t],this.updateWithSelectedTds()}catch{}else i&&n||this.hide()}};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();if(!s)return;const{anchorNode:o,focusNode:i,anchorOffset:n,focusOffset:l}=s;if(!o||!i)return;const r=t.find(o),a=t.find(i);if(!r||!a||r.scroll!==this.quill.scroll||a.scroll!==this.quill.scroll)return;const c=u(r),d=u(a),h=c.has(e.tableColgroup),p=d.has(e.tableColgroup);if(h||p){let t=o,r=n,a=i,u=l;if(h){const s=c.get(e.tableWrapper).descendants(ne);s.length>0&&(t=s[0].domNode,r=0)}if(p){const t=d.get(e.tableWrapper).descendants(ne);t.length>0&&(a=t[0].domNode,u=0)}return void this.setSelectionData(s,{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:u})}const b=c.has(e.tableCellInner),m=d.has(e.tableCellInner);let f=b&&m;if(f){const t=c.get(e.tableCellInner),s=d.get(e.tableCellInner);f&&=t!==s}if(b&&m&&f||!b&&m||!m&&b)return this.setSelectionData(s,this.lastSelection),void(this.selectedTds.length>0&&this.hide());this.lastSelection={anchorNode:o,anchorOffset:n,focusNode:i,focusOffset:l}};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=o.descendants(re)[0];if(!i)return[];const n=new Set(i.descendants(we).map(((t,e)=>(t.index=e,t)))),{x:l,y:r}=this.getTableViewScroll(),{x:a,y:c}=this.getQuillViewScroll();this.selectedTableScrollX=l,this.selectedTableScrollY=r,this.selectedEditorScrollX=a,this.selectedEditorScrollY=c;const{rect:d}=Ne(o),h=e.x-l+this.startScrollX,u=e.y-r+this.startScrollY;let p={x:Math.max(d.left,Math.min(s.x,h)),y:Math.max(d.top,Math.min(s.y,u)),x1:Math.min(d.right,Math.max(s.x,h)),y1:Math.min(d.bottom,Math.max(s.y,u))};const b=new Set;let m=!0;for(;m;){m=!1;for(const t of n){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:o,bottom:i}=t.__rect;if(Ft({x:Math.floor(p.x),y:Math.floor(p.y),x1:Math.floor(p.x1),y1:Math.floor(p.y1)},{x:Math.floor(e),y:Math.floor(s),x1:Math.floor(o),y1:Math.floor(i)},0,0===b.size)){b.add(t),n.delete(t),p={x:Math.min(p.x,e),y:Math.min(p.y,s),x1:Math.max(p.x1,o),y1:Math.max(p.y1,i)},m=!0;break}}}for(const t of[...b,...n])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}}({...p,width:p.x1-p.x,height:p.y1-p.y},this.quill.root),Array.from(b).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler=t=>{const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table"),l=s.closest("tbody");if(0!==e||!n||!l)return;this.setSelectionTable(n);const r=n.dataset.tableId,a={x:o,y:i};this.selectedTds=this.computeSelectedTds(a,a),this.dragging=!0,this.show();const c=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("tbody");if(0!==e||!n||n.dataset.tableId!==r)return;const l={x:o,y:i};this.selectedTds=this.computeSelectedTds(a,l),this.selectedTds.length>1&&this.quill.blur(),this.update()},d=()=>{document.body.removeEventListener("mousemove",c,!1),document.body.removeEventListener("mouseup",d,!1),this.dragging=!1,this.tableMenu&&this.selectedTds.length>0&&this.tableMenu.show()};document.body.addEventListener("mousemove",c,!1),document.body.addEventListener("mouseup",d,!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.update():this.hide()}update(){if(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;this.startScrollX=s,this.startScrollY=o,Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-o-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${i.width}px`,height:`${i.height}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=t)}removeCell=e=>{if(!(this.quill.getSelection()||"Backspace"!==e.key&&"Delete"!==e.key)){for(const t of this.selectedTds)t.deleteAt(0,t.length()-1);if(this.table){const e=t.find(this.table),s=e.descendants(ne);this.selectedTds.length===s.length&&e.remove()}}};showDisplay(){Object.assign(this.cellSelectWrap.style,{display:"block"}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(_t.call(this),this.update(),this.showDisplay(),document.addEventListener("keydown",this.removeCell),Vt.call(this,this.quill.root,(()=>{this.update()})),Vt.call(this,this.table.parentElement,(()=>{this.update()})))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:"none"}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){_t.call(this),document.removeEventListener("keydown",this.removeCell),this.hideDisplay(),this.boundary=null,this.selectedTds=[],this.setSelectionTable(void 0),this.tableMenu&&this.tableMenu.hide()}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),_t.call(this),this.quill.root.removeEventListener("mousedown",this.mouseDownHandler),document.removeEventListener("selectionchange",this.selectionChangeHandler),this.quill.off(t.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.off(t.events.TEXT_CHANGE,this.updateAfterEvent),this.quill.on(o.AFTER_TABLE_RESIZE,this.updateAfterEvent)}}const Xe=t.import("parchment"),Ue=t.import("delta"),Ye=t.import("blots/break"),Ge=t.import("ui/icons");function Ke(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}function Ze(t){r.delete(e.tableCellInner),Object.assign(e,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(o,t.tableUpEvent||{}),Object.assign(i,t.tableUpInternal||{}),ts.moduleName=i.moduleName,ts.toolName=e.tableWrapper,ee.blotName=e.container,Ie.blotName=e.tableWrapper,xe.blotName=e.tableMain,ye.blotName=e.tableColgroup,Ce.blotName=e.tableCol,re.blotName=e.tableBody,le.blotName=e.tableRow,we.blotName=e.tableCell,ne.blotName=e.tableCellInner,r.add(e.tableCellInner)}function Qe(t,e){return B({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Je(s){return{bindInHead:!1,key:s?"ArrowUp":"ArrowDown",collapsed:!0,format:[e.tableCellInner],handler(o,i){let n,l,r,a;try{[n,l,r,a]=h(i.line,[e.tableWrapper,e.tableMain,e.tableRow,e.tableCell])}catch{return!0}const c=l.getColIds(),d=s?"prev":"next",u=s?"tail":"head",p=n.descendants(ge,0)[0];let b;if(p){const t=window.getComputedStyle(p.domNode);b="next"===d&&"bottom"===t.captionSide?p:"next"===d?n.next:p}else b=n[d];if(i.line[d]||!b)return!0;const m=r[d];if(m){const e=c.indexOf(a.colId),s=m.getCellByColId(c[e],d);if(!s)return!0;let o=s.children[u];o.children&&(o=o.children[u]);const n=o.offset(this.quill.scroll)+Math.min(i.offset,o.length()-1);this.quill.setSelection(n,0,t.sources.USER)}else{const e=b.offset(this.quill.scroll)+(s?b.length()-1:0);this.quill.setSelection(e,0,t.sources.USER)}return!1}}}class ts{static moduleName=i.moduleName;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 Ie)return o.prev.remove(),!1;if(s.format[e.tableCellInner]){if(0===o.offset(d(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 Ie||i.next instanceof Ce)&&n===i.length()-1)return!1;if(s.format[e.tableCellInner]){if(i===d(i,e.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"table up":Je(!0),"table down":Je(!1),"table caption break":{bindInHead:!0,key:"Enter",shiftKey:null,format:[e.tableCaption],handler:(t,e)=>!1}};static register(){Ie.allowedChildren=[xe],xe.allowedChildren=[re,ye,ge],xe.requiredContainer=Ie,ge.requiredContainer=xe,ye.allowedChildren=[Ce],ye.requiredContainer=xe,re.allowedChildren=[le],re.requiredContainer=xe,le.allowedChildren=[we],we.requiredContainer=re,we.allowedChildren=[ne,Ye],we.requiredContainer=le,ne.requiredContainer=we;const s=["header","list","blockquote","code-block"].reduce(((e,s)=>{const o=`formats/${s}`,i=t.import(o);return e[o]=class extends(function(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)b(s.prototype,t.prototype);return s}(i,[de])){static register(){}},e}),{});t.register({"blots/scroll":pe,"blots/block":de,...s,[`blots/${e.container}`]:ee,[`formats/${e.tableCell}`]:we,[`formats/${e.tableCellInner}`]:ne,[`formats/${e.tableRow}`]:le,[`formats/${e.tableBody}`]:re,[`formats/${e.tableCol}`]:Ce,[`formats/${e.tableColgroup}`]:ye,[`formats/${e.tableCaption}`]:ge,[`formats/${e.tableMain}`]:xe,[`formats/${e.tableWrapper}`]:Ie,"modules/clipboard":Be},!0)}quill;options;toolBox;fixTableByLisenter=Kt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;resizeOb;get statics(){return this.constructor}constructor(t,e){if(this.quill=t,this.options=this.resolveOptions(e||{}),this.toolBox=this.initialContainer(),!this.options.scrollbar){const t=c("scrollbar");this.quill.container.classList.add(t.bm("origin"))}this.options.selection&&(this.tableSelection=new this.options.selection(this,this.quill,this.options.selectionOptions));const s=this.quill.getModule("toolbar");if(s&&this.quill.theme.pickers){const[,t]=(s.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}=jt(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 o=this.quill.getModule("keyboard");for(const t of Object.values(ts.keyboradHandler))t.bindInHead?o.bindings[t.key].unshift(t):o.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(),this.tableAlign&&this.tableAlign.update(),this.tableResize&&this.tableResize.update(),void(this.tableScrollbar&&this.tableScrollbar.update());this.table&&this.hideTableTools(),this.showTableTools(s)}else this.table&&this.hideTableTools()}),!1),this.quillHack(),this.listenBalanceCells()}initialContainer(){const t=c("toolbox"),e=this.quill.addContainer(t.b());return this.resizeOb=new ResizeObserver((()=>{const t=this.quill.root.getBoundingClientRect(),{offsetLeft:s,offsetTop:o}=this.quill.root;Object.assign(e.style,{top:`${o}px`,left:`${s}px`,width:`${t.width}px`,height:`${t.height}px`})})),this.resizeOb.observe(this.quill.root),e}addContainer(t){if(M(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:Ge.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)}quillHack(){const s=this.quill.getSemanticHTML;this.quill.getSemanticHTML=(o=0,i)=>{const n=s.call(this.quill,o,i),l=t.import(`formats/${e.tableWrapper}`),r=(new DOMParser).parseFromString(n,"text/html");for(const t of Array.from(r.querySelectorAll(`.${l.className} caption[contenteditable], .${l.className} td > [contenteditable]`)))t.removeAttribute("contenteditable");return r.body.innerHTML};const o=this.quill.format;this.quill.format=function(s,n,l=t.sources.API){if(!(this.scroll.query(s).prototype instanceof Xe.EmbedBlot)){const t=this.getModule(i.moduleName),r=this.getSelection();if(r&&r.length>0){if(this.getFormat(r)[e.tableCellInner])return o.call(this,s,n,l)}if(t&&t.tableSelection&&t.tableSelection.selectedTds.length>0){const e=t.tableSelection.selectedTds;let o=!1;const i=[];for(const t of e){const e=t.offset(this.scroll),l=t.length();i.push({index:e,length:l});this.getFormat(e,l)[s]!==n&&(o=!0)}const r=!!o&&n,a=new Ue;for(const[t,{index:e,length:o}]of i.entries()){const n=0===t?0:i[t-1].index+i[t-1].length;a.retain(e-n).retain(o,{[s]:r})}const c=this.updateContents(a,l);return this.blur(),c}}return o.call(this,s,n,l)};const n=this.quill.theme.modules.toolbar;if(n){const s=n.handlers?.clean;if(s){const o=(t,s,o=()=>"")=>{const i=this.quill.getText(t,s),[n,l]=this.quill.getLine(t+s);let r=0,a=new Ue;null!=n&&(r=n.length()-l,a=n.delta().slice(l,l+r-1).insert("\n"));const c=this.quill.getContents(t,s+r),d=c.diff((new Ue).insert(i).concat(a));let h=0;const u=d.ops.map((t=>{const{attributes:s,...i}=t;if(t.insert?h-=M(t.insert)?t.insert.length:1:t.retain?h+="number"==typeof t.retain?t.retain:1:t.delete&&(h+=t.delete),s){const{[e.tableCellInner]:t,...n}=s;if(o){const t=c.slice(h-1,h).ops[0];if(t&&t.attributes&&t.attributes[e.tableCellInner]){const s=t.attributes[e.tableCellInner],{style:l,...r}=s,a=o(l);return a?{...i,attributes:{...n,[e.tableCellInner]:{style:a,...r}}}:{...i,attributes:{...n,[e.tableCellInner]:r}}}}return{...i,attributes:{...n}}}return t}));return new Ue(u)};n.handlers.clean=function(n){const l=this.quill.getModule(i.moduleName),r=this.quill.getSelection();if(r&&r.length>0){if(this.quill.getFormat(r)[e.tableCellInner]){const e=o(r.index,r.length,!1),s=(new Ue).retain(r.index).concat(e);return void this.quill.updateContents(s,t.sources.USER)}}if(l&&l.tableSelection&&l.tableSelection.selectedTds.length>0&&l.tableSelection.table){const e=t.find(l.tableSelection.table);if(!e)return void console.warn("TableMainFormat not found");const s=l.tableSelection.selectedTds,i=new Set,n=[];for(const t of s)if(t.parent instanceof we){for(const e of t.parent.getNearByCell("top"))i.has(e)||(i.add(e),n.push({td:e,cleanBorder:"bottom"}));for(const e of t.parent.getNearByCell("left"))i.has(e)||(i.add(e),n.push({td:e,cleanBorder:"right"}));i.add(t.parent),n.push({td:t.parent,cleanBorder:!0})}const r=e.descendants(we),a=new Map(r.map(((t,e)=>[t,e])));n.sort(((t,e)=>a.get(t.td)-a.get(e.td)));let c=new Ue,d=0;for(const{td:t,cleanBorder:e}of n){const s=t.getCellInner().offset(this.quill.scroll),i=t.getCellInner().length(),n=o(s,i-1,(t=>{if(!t||!0===e)return"";const s=Xt(t);return Ut(Object.keys(s).filter((t=>!t.startsWith(Yt(`border-${e}`)))).reduce(((t,e)=>(t[e]=s[e],t)),{}))})),l=(new Ue).retain(s-d).concat(n);c=c.concat(l),d=s+i}return this.quill.updateContents(c,t.sources.USER),void(s.length>1&&this.quill.blur())}return s.call(this,n)}}}}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||!x(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=c("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("span");i.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),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)M(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=d(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"),""}if(!o)return"";const i=this.quill.getIndex(o),n=o.length(),l=this.quill.getSemanticHTML(i,n),r=(new DOMParser).parseFromString(l,"text/html"),a=[],c=new Set,h=new Set;for(const e of t)c.add(e.colId),h.add(`${e.rowId}-${e.colId}`);for(const t of Array.from(r.querySelectorAll("col")))c.has(t.dataset.colId)?a.push(t.getAttribute("width")):t.remove();let u=0,p=null;for(const t of Array.from(r.querySelectorAll("td")))if(h.has(`${t.dataset.rowId}-${t.dataset.colId}`))p!==t.dataset.rowId&&(u+=1,p=t.dataset.rowId);else{const e=t.parentElement;t.remove(),e&&e.children.length<=0&&e.remove()}const b=Array.from(r.querySelectorAll("col")),m=b.map((t=>Ce.value(t)));if(o.full){const t=m.reduce(((t,e)=>e.width+t),0);for(const[e,s]of m.entries())s.width=Math.round(s.width/t*100),b[e].setAttribute("width",`${s.width}%`)}else{let t=0;for(const e of m)t+=e.width;r.querySelector("table").style.width=`${t}px`}if(s){if(u===o.getRows().length)this.removeCol(t);else for(const e of t)e.domNode.innerHTML="<p><br></p>"}return r.body.innerHTML}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(a(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),c=getComputedStyle(this.quill.root),d=Number.parseInt(c.paddingLeft),h=Number.parseInt(c.paddingRight),u=Number.parseInt(c.width)-d-h-r,p=Gt(),b=new Array(i).fill(0).map((()=>Gt())),m=this.options.full?`${Math.max(1/i*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(u/i),s.colMinWidthPx)}px`,f=[{retain:n.index},{insert:"\n"}];for(let t=0;t<i;t++)f.push({insert:{[e.tableCol]:{width:m,tableId:p,colId:b[t],full:this.options.full}}});for(let t=0;t<o;t++){const t=Gt();for(let s=0;s<i;s++)f.push({insert:"\n",attributes:{[e.tableCellInner]:{tableId:p,rowId:t,colId:b[s],rowspan:1,colspan:1}}})}this.quill.updateContents(new Ue(f),t.sources.USER),this.quill.setSelection(n.index+i+i*o+1,t.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${xe.className}">\n <tbody>\n <tr>\n <td class="${we.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=Ie.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(we);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(Ke(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(xe))this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(t.events.SCROLL_OPTIMIZE,(e=>{e.some((e=>{const s=e.target;if("TABLE"===s.tagName){const e=t.find(s);if(e)return e.sortMergeChildren(),!0}return!1}))})),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=d(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]=h(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=d(o,e.tableMain),l=n.tableId,r=Gt(),[a]=n.descendants(ye);a&&a.insertColByIndex(i,{tableId:l,colId:r,width:n.full?6:160,full:n.full});const c=n.getRows(),h=[];let u=0;for(const t of Object.values(c)){const e=h.shift()||0;if(u>0){u-=1;continue}const s=t.insertCell(i-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(u+=s.skipRowNum);for(const[t,e]of s.entries())h[t]=(h[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=d(t[0],e.tableMain),o=s.getRows();let i=o.length,n=-1;for(const s of t){const t=d(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=d(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(le);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(ye);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=d(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]=h(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}}}export{de as BlockOverride,ee as ContainerFormat,pe as ScrollOverride,Pe as Scrollbar,Te as TableAlign,re as TableBodyFormat,ge as TableCaptionFormat,we as TableCellFormat,ne as TableCellInnerFormat,Be as TableClipboard,Ce as TableColFormat,ye as TableColgroupFormat,xe as TableMainFormat,ze as TableMenuCommon,qe as TableMenuContextmenu,$e as TableMenuSelect,De as TableResizeBox,We as TableResizeCommon,Fe as TableResizeLine,je as TableResizeScale,le as TableRowFormat,_e as TableSelection,ts as TableUp,Ve as TableVirtualScrollbar,Ie as TableWrapperFormat,e as blotName,T as createColorPicker,B as createSelectBox,Dt as createTooltip,ts as default,Qe as defaultCustomSelect,d as findParentBlot,h as findParentBlots,Ne as getTableMainRect,He as isTableAlignRight,Gt as randomId,ke as tableMenuTools,o as tableUpEvent,i as tableUpInternal,s as tableUpSize,Ze as updateTableConstants};
1
+ import t from"quill";const e={container:"table-up-container",tableCaption:"table-up-caption",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={moduleName:"table-up"},n=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],l="table-up",r=new Set([e.tableCellInner]);function a(t){return!(!t||!t.parent)&&(e=t.parent,!!r.has(e.statics.blotName)||a(t.parent));var e}function c(t,e=l){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}`}}function d(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 h(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 u(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 p(t,e){const s=[],o=t.children.iterator();let i=null;for(;i=o();)i instanceof e&&s.push(i);return s}function b(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}function m(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)}function f(t){return{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))}}function g(t){let{r:e,g:s,b:o,a:i}=t;e=m(e,255),s=m(s,255),o=m(o,255);const n=Math.max(e,s,o),l=Math.min(e,s,o);let r;const a=n,c=n-l,d=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(s-o)/c+(s<o?6:0);break;case s:r=(o-e)/c+2;break;case o:r=(e-s)/c+4}r/=6}return{h:360*r,s:100*d,b:100*a,a:i}}function w(t){let{h:e,s:s,b:o,a:i}=t;e=6*m(e,360),s=m(s,100),o=m(o,100);const n=Math.floor(e),l=e-n,r=o*(1-s),a=o*(1-l*s),c=o*(1-(1-l)*s),d=n%6,h=[o,a,r,r,c,o][d],u=[c,o,o,a,r,r][d],p=[r,r,c,o,o,a][d];return{r:Math.round(255*h),g:Math.round(255*u),b:Math.round(255*p),a:i}}function v(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("")}const C=t=>v(w(t)),x=t=>"function"==typeof t,y=Array.isArray,M=t=>"string"==typeof t,I=t=>null!==t&&"object"==typeof t;function N(t){const{type:e="default",content:s}=t||{},o=c("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(M(s)?i.textContent=s:i.appendChild(s)),i}function T(t={}){const e=230,s=150,o=10;let i=g((n=(n=t.color||"#ff0000").startsWith("#")?n.slice(1):n,{r:Number.parseInt(n.slice(0,2),16),g:Number.parseInt(n.slice(2,4),16),b:Number.parseInt(n.slice(4,6),16),a:Number((Number.parseInt(n.slice(6,8)||"ff",16)/255).toFixed(2))}));var n;const l=c("color-picker"),r=document.createElement("div");r.classList.add(l.b());const a=document.createElement("div");a.classList.add(l.be("content"));const d=document.createElement("div");d.classList.add(l.be("selector"));const h=document.createElement("div");h.classList.add(l.be("background")),d.appendChild(h);const u=document.createElement("div");u.classList.add(l.be("background-handle")),h.appendChild(u);const p=document.createElement("div");p.classList.add(l.be("alpha"));const b=document.createElement("div");b.classList.add(l.be("alpha-bg"));const m=document.createElement("div");m.classList.add(l.be("alpha-handle")),p.appendChild(b),p.appendChild(m);const x=document.createElement("div");x.classList.add(l.be("hue"));const y=document.createElement("div");y.classList.add(l.be("hue-handle")),x.appendChild(y);const M=document.createElement("div");M.classList.add(l.be("action"));const[I,N,T,L]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(l.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(l.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);A(f(g(Object.assign({},w(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));a.appendChild(x),a.appendChild(d),a.appendChild(p),r.appendChild(a),r.appendChild(M);let E=!1,S=!1,B=!1;function R(){const t=C(i);for(const[e,s]of[I,N,T].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));L.value=String((100*i.a).toFixed(0))}function k(){Object.assign(u.style,{left:`${Math.floor(e*i.s/100)}px`,top:`${Math.floor(s*(100-i.b)/100)}px`}),d.style.backgroundColor=`#${v(w({h:i.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*i.h/360)}px`,m.style.left=100*i.a+"%",function(){const{r:t,g:e,b:s}=w(i);b.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),R()}function A(e){i=f(Object.assign({},i,e)),R(),t.onChange&&t.onChange(`#${C(i)}`)}function O(t){const o=d.getBoundingClientRect(),i=o.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=o.left+document.body.scrollLeft;A({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 z(t){const e=x.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);A({h:Math.floor(360*(s-Math.max(0,Math.min(s,t.pageY-e)))/s)}),k()}function q(t){const{pageX:e}=t,s=p.getBoundingClientRect();let i=e-s.left;i=Math.max(o/2,i),i=Math.min(i,s.width-o/2),A({a:Math.round((i-5)/(s.width-10)*100)/100}),k()}function $(t){E&&(t.preventDefault(),O(t)),S&&(t.preventDefault(),z(t)),B&&(t.preventDefault(),q(t))}function H(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",H),E=!1}function W(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",W),S=!1}function D(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",D),B=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",H),E=!0,O(t)})),x.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",W),S=!0,z(t)})),p.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",D),B=!0,q(t)})),k(),r}let L=8e3;function E({child:t,target:e=document.body,beforeClose:s=()=>{}}={}){const o=c("dialog"),i=e,n=document.createElement("div");n.classList.add(o.b()),n.style.zIndex=String(L);const l=document.createElement("div");if(l.classList.add(o.be("overlay")),n.appendChild(l),t){const e=document.createElement("div");e.classList.add(o.be("content")),e.appendChild(t),l.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const r=getComputedStyle(i).overflow;i.style.overflow="hidden",i.appendChild(n);const a=()=>{s(),n.remove(),i.style.overflow=r};return n.addEventListener("click",a),L+=1,{dialog:n,close:a}}function S(t,e){const s=c("input");e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,o.appendChild(e)}const i=document.createElement("div");i.classList.add(s.be("input"));const n=document.createElement("input");for(const t in e)n.setAttribute(t,e[t]);(e.max||e.min)&&n.addEventListener("blur",(()=>{e.max&&e.max<=Number(n.value)&&(n.value=String(e.max)),e.min&&e.min>=Number(n.value)&&(n.value=String(e.min))})),i.appendChild(n),o.appendChild(i),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:n,errorTip:t=>{let e;i.classList.contains("error")?e=i.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),i.appendChild(e)),e.textContent=t,i.classList.add("error");return{removeError:()=>{i.classList.remove("error"),e.remove()}}}}}function B(t={}){const e=c("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 function(t={}){const e=c("creator"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("input"));const{item:i,input:n,errorTip:l}=S(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:r,input:a,errorTip:d}=S(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(r),s.appendChild(o);const h=document.createElement("div");h.classList.add(e.be("control"));const u=N({type:"confirm",content:t.confirmText||"Confirm"}),p=N({type:"default",content:t.cancelText||"Cancel"});h.appendChild(u),h.appendChild(p),s.appendChild(h);const b=(e=Number(n.value),s=Number(a.value))=>{if(Number.isNaN(e)||e<=0)l(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")}},m=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",m))};return new Promise(((t,e)=>{const{close:o}=E({child:s,beforeClose:e});n.focus();for(const e of[n,a])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",m),p.addEventListener("click",o)}))}(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s}const R=Math.min,k=Math.max,A=Math.round,O=Math.floor,z=t=>({x:t,y:t}),q={left:"right",right:"left",bottom:"top",top:"bottom"},$={start:"end",end:"start"};function H(t,e,s){return k(t,R(e,s))}function W(t,e){return"function"==typeof t?t(e):t}function D(t){return t.split("-")[0]}function F(t){return t.split("-")[1]}function j(t){return"x"===t?"y":"x"}function P(t){return"y"===t?"height":"width"}function V(t){return["top","bottom"].includes(D(t))?"y":"x"}function _(t){return j(V(t))}function X(t){return t.replace(/start|end/g,(t=>$[t]))}function U(t){return t.replace(/left|right|bottom|top/g,(t=>q[t]))}function Y(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 G(t,e,s){let{reference:o,floating:i}=t;const n=V(e),l=_(e),r=P(l),a=D(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(F(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function K(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}=W(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=Y(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},C=Y(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-C.top+b.top)/v.y,bottom:(C.bottom-f.bottom+b.bottom)/v.y,left:(f.left-C.left+b.left)/v.x,right:(C.right-f.right+b.right)/v.x}}function Z(){return"undefined"!=typeof window}function Q(t){return et(t)?(t.nodeName||"").toLowerCase():"#document"}function J(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function tt(t){var e;return null==(e=(et(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function et(t){return!!Z()&&(t instanceof Node||t instanceof J(t).Node)}function st(t){return!!Z()&&(t instanceof Element||t instanceof J(t).Element)}function ot(t){return!!Z()&&(t instanceof HTMLElement||t instanceof J(t).HTMLElement)}function it(t){return!(!Z()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof J(t).ShadowRoot)}function nt(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=ht(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function lt(t){return["table","td","th"].includes(Q(t))}function rt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function at(t){const e=ct(),s=st(t)?ht(t):t;return["transform","translate","scale","rotate","perspective"].some((t=>!!s[t]&&"none"!==s[t]))||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","translate","scale","rotate","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function ct(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function dt(t){return["html","body","#document"].includes(Q(t))}function ht(t){return J(t).getComputedStyle(t)}function ut(t){return st(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function pt(t){if("html"===Q(t))return t;const e=t.assignedSlot||t.parentNode||it(t)&&t.host||tt(t);return it(e)?e.host:e}function bt(t){const e=pt(t);return dt(e)?t.ownerDocument?t.ownerDocument.body:t.body:ot(e)&&nt(e)?e:bt(e)}function mt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=bt(t),n=i===(null==(o=t.ownerDocument)?void 0:o.body),l=J(i);if(n){const t=ft(l);return e.concat(l,l.visualViewport||[],nt(i)?i:[],t&&s?mt(t):[])}return e.concat(i,mt(i,[],s))}function ft(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function gt(t){const e=ht(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=ot(t),n=i?t.offsetWidth:s,l=i?t.offsetHeight:o,r=A(s)!==n||A(o)!==l;return r&&(s=n,o=l),{width:s,height:o,$:r}}function wt(t){return st(t)?t:t.contextElement}function vt(t){const e=wt(t);if(!ot(e))return z(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:n}=gt(e);let l=(n?A(s.width):s.width)/o,r=(n?A(s.height):s.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const Ct=z(0);function xt(t){const e=J(t);return ct()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:Ct}function yt(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),n=wt(t);let l=z(1);e&&(o?st(o)&&(l=vt(o)):l=vt(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==J(t))&&e}(n,s,o)?xt(n):z(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=J(n),e=o&&st(o)?J(o):o;let s=t,i=ft(s);for(;i&&o&&e!==s;){const t=vt(i),e=i.getBoundingClientRect(),o=ht(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=J(i),i=ft(s)}}return Y({width:d,height:h,x:a,y:c})}function Mt(t,e){const s=ut(t).scrollLeft;return e?e.left+s:yt(tt(t)).left+s}function It(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:Mt(t,o)),y:o.top+e.scrollTop}}function Nt(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=J(t),o=tt(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=ct();(!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=tt(t),s=ut(t),o=t.ownerDocument.body,i=k(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),n=k(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let l=-s.scrollLeft+Mt(t);const r=-s.scrollTop;return"rtl"===ht(o).direction&&(l+=k(e.clientWidth,o.clientWidth)-i),{width:i,height:n,x:l,y:r}}(tt(t));else if(st(e))o=function(t,e){const s=yt(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,n=ot(t)?vt(t):z(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=xt(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return Y(o)}function Tt(t,e){const s=pt(t);return!(s===e||!st(s)||dt(s))&&("fixed"===ht(s).position||Tt(s,e))}function Lt(t,e,s){const o=ot(e),i=tt(e),n="fixed"===s,l=yt(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=z(0);if(o||!o&&!n)if(("body"!==Q(e)||nt(i))&&(r=ut(e)),o){const t=yt(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=Mt(i));const c=!i||o||n?z(0):It(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 Et(t){return"static"===ht(t).position}function St(t,e){if(!ot(t)||"fixed"===ht(t).position)return null;if(e)return e(t);let s=t.offsetParent;return tt(t)===s&&(s=s.ownerDocument.body),s}function Bt(t,e){const s=J(t);if(rt(t))return s;if(!ot(t)){let e=pt(t);for(;e&&!dt(e);){if(st(e)&&!Et(e))return e;e=pt(e)}return s}let o=St(t,e);for(;o&&lt(o)&&Et(o);)o=St(o,e);return o&&dt(o)&&Et(o)&&!at(o)?s:o||function(t){let e=pt(t);for(;ot(e)&&!dt(e);){if(at(e))return e;if(rt(e))return null;e=pt(e)}return null}(t)||s}const Rt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const n="fixed"===i,l=tt(o),r=!!e&&rt(e.floating);if(o===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=z(1);const d=z(0),h=ot(o);if((h||!h&&!n)&&(("body"!==Q(o)||nt(l))&&(a=ut(o)),ot(o))){const t=yt(o);c=vt(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!l||h||n?z(0):It(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:tt,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const n=[..."clippingAncestors"===s?rt(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=mt(t,[],!1).filter((t=>st(t)&&"body"!==Q(t))),i=null;const n="fixed"===ht(t).position;let l=n?pt(t):t;for(;st(l)&&!dt(l);){const e=ht(l),s=at(l);s||"fixed"!==e.position||(i=null),(n?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||nt(l)&&!s&&Tt(t,l))?o=o.filter((t=>t!==l)):i=e,l=pt(l)}return e.set(t,o),o}(e,this._c):[].concat(s),o],l=n[0],r=n.reduce(((t,s)=>{const o=Nt(e,s,i);return t.top=k(o.top,t.top),t.right=R(o.right,t.right),t.bottom=R(o.bottom,t.bottom),t.left=k(o.left,t.left),t}),Nt(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:Bt,getElementRects:async function(t){const e=this.getOffsetParent||Bt,s=this.getDimensions,o=await s(t.floating);return{reference:Lt(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}=gt(t);return{width:e,height:s}},getScale:vt,isElement:st,isRTL:function(t){return"rtl"===ht(t).direction}};function kt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function At(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=wt(t),d=i||n?[...c?mt(c):[],...mt(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=tt(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 c=t.getBoundingClientRect(),{left:d,top:h,width:u,height:p}=c;if(r||e(),!u||!p)return;const b={rootMargin:-O(h)+"px "+-O(i.clientWidth-(d+u))+"px "+-O(i.clientHeight-(h+p))+"px "+-O(d)+"px",threshold:k(0,R(1,a))||1};let m=!0;function f(e){const o=e[0].intersectionRatio;if(o!==a){if(!m)return l();o?l(!1,o):s=setTimeout((()=>{l(!1,1e-7)}),1e3)}1!==o||kt(c,t.getBoundingClientRect())||l(),m=!1}try{o=new IntersectionObserver(f,{...b,root:i.ownerDocument})}catch(t){o=new IntersectionObserver(f,b)}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?yt(t):null;return a&&function e(){const o=yt(t);m&&!kt(m,o)&&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 Ot=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=D(s),r=F(s),a="y"===V(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=W(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}}}}},zt=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}=W(t,e),c={x:s,y:o},d=await K(e,a),h=V(D(i)),u=j(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=H(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=H(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}}}}}},qt=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}=W(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=D(i),w=V(r),v=D(r)===r,C=await(null==a.isRTL?void 0:a.isRTL(c.floating)),x=u||(v||!m?[U(r)]:function(t){const e=U(t);return[X(t),e,X(e)]}(r)),y="none"!==b;!u&&y&&x.push(...function(t,e,s,o){const i=F(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[]}}(D(t),"start"===s,o);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map(X)))),n}(r,m,b,C));const M=[r,...x],I=await K(e,f),N=[];let T=(null==(o=n.flip)?void 0:o.overflows)||[];if(d&&N.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=F(t),i=_(t),n=P(i);let l="x"===i?o===(s?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=U(l)),[l,U(l)]}(i,l,C);N.push(I[t[0]],I[t[1]])}if(T=[...T,{placement:i,overflows:N}],!N.every((t=>t<=0))){var L,E;const t=((null==(L=n.flip)?void 0:L.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:T},reset:{placement:e}};let s=null==(E=T.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:E.placement;if(!s)switch(p){case"bestFit":{var S;const t=null==(S=T.filter((t=>{if(y){const e=V(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:S[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},$t=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}=W(t,e),d={x:s,y:o},h=V(i),u=j(h);let p=d[u],b=d[h];const m=W(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(D(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}}}},Ht=(t,e,s)=>{const o=new Map,i={platform:Rt,...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}=G(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}=G(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:n})};let Wt;function Dt(t,e={}){const{msg:s="",delay:o=150,content:i,direction:n="bottom",type:l="hover",container:r,onOpen:a,onClose:d,closed:h,onDestroy:u}=e,p=c("tooltip");if(s||i){Wt||(Wt=document.createElement("div"),document.body.appendChild(Wt));const e=r||Wt,c=document.createElement("div");let b,m,f;c.classList.add(p.b(),"hidden","transparent"),i?c.appendChild(i):s&&(c.textContent=s);const g=()=>{f&&f(),Ht(t,c,{placement:n,middleware:[qt(),zt({limiter:$t()}),Ot(4)]}).then((({x:t,y:e})=>{Object.assign(c.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{c.classList.add("hidden"),e.contains(c)&&e.removeChild(c),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(a){const t=a(s);if(!s&&t)return}e.appendChild(c),c.removeEventListener("transitionend",w),c.classList.remove("hidden"),f=At(t,c,g),c.classList.remove("transparent")}),o)},C=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}!function(t,e,s,o,i){t.addEventListener("transitionend",s,o),setTimeout((()=>{s()}),e)}(c,150,w,{once:!0}),c.classList.add("transparent")}),o)},x=()=>{const e=t=>{t.stopPropagation(),C(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{c.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{C(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,c],s=C.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:C,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",o),t.removeEventListener("mouseleave",s)}}},click:x},{prepare:M,show:I,hide:N,destroy:T}=y[l]();M();const L=()=>{N(!0),u&&u(),T(),f&&f(),c.remove()};return{show:I,hide:N,destroy:L}}return null}function Ft(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)}function jt(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 Pt(t,e={}){const s=Symbol("ignoreFirstBind"),o=new Set,i=new ResizeObserver((o=>{e.ignoreFirstBind&&o.some((t=>{const e=t.target,o=e[s];return e[s]=!0,!o}))||t(o)})),n=i.observe;i.observe=(t,e)=>{o.add(t),n.call(i,t,e)};const l=i.unobserve;i.unobserve=t=>{o.has(t)&&(o.delete(t),t[s]=void 0),l.call(i,t)};const r=i.disconnect;return i.disconnect=()=>{for(const t of o.values())t[s]=void 0;r.call(i)},i}function Vt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function _t(){for(let t=0;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}function Xt(t){const e={},s=t.trim().split(";");for(let t=0;t<s.length;t++){const o=s[t].trim();if(!o)continue;const i=o.indexOf(":");if(-1===i)continue;const n=o.slice(0,Math.max(0,i)).trim(),l=o.slice(Math.max(0,i+1)).trim();e[Yt(n)]=l}return e}function Ut(t){return Object.entries(t).map((([t,e])=>`${function(t){const e=t.replaceAll(/([A-Z])/g," $1").trim();return e.split(" ").join("-").toLowerCase()}(t)}: ${e};`)).join(" ")}function Yt(t){return t.replaceAll(/-(\w)/g,((t,e)=>e.toUpperCase()))}const Gt=()=>Math.random().toString(36).slice(2);function Kt(t,e){let s;return function(...o){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,o)}),e)}}const Zt=t.import("parchment"),Qt=t.import("blots/container"),Jt=t.import("blots/block"),te=t.import("blots/block/embed");class ee extends Qt{static tagName;static blotName=e.container;static scope=Zt.Scope.BLOCK_BLOT;static allowedChildren=[Jt,te,Qt];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())}enforceAllowedChildren(){this.children.forEach((t=>{this.statics.allowedChildren.some((e=>t instanceof e))||(t.statics.scope===Zt.Scope.BLOCK_BLOT?(t.parent instanceof ee?(null!=t.next&&t.parent.splitAfter(t),null!=t.prev&&t.parent.splitAfter(t.prev)):(null!=t.next&&this.splitAfter(t),null!=t.prev&&this.splitAfter(t.prev)),t.parent.unwrap()):t instanceof Zt.ParentBlot?t.unwrap():t.remove())}))}}const se=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},oe=t.import("blots/block"),ie=t.import("blots/block/embed");class ne extends ee{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=oe;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(se(i)),r.dataset.colspan=String(se(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:String(e),rowId:String(s),colId:String(o),rowspan:Number(se(i)),colspan:Number(se(n))};return l&&(r.style=l),r}constructor(t,e,s){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled()))}setFormatValue(t,s,o=!1){if(o){if(!this.statics.isAllowStyle(t))return;this.parent&&this.parent.statics.blotName===e.tableCell&&this.parent.setFormatValue(t,s)}else{if(!this.statics.allowDataAttrs.has(t))return;const o=`data-${t}`;s?this.domNode.setAttribute(o,s):this.domNode.removeAttribute(o),this.parent&&this.parent.statics.blotName===e.tableCell&&this.parent.setFormatValue(t,s)}const i=this.descendants(oe,0);for(const t of i)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 d(this,e.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,o){if(0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,o),o&&o.style){const t=Xt(o.style);for(const[e,s]of Object.entries(t))this.setFormatValue(e,s,!0)}}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 ie){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]=h(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)}}class le extends ee{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)}))}getCellByColId(t,s){const o=d(this,e.tableMain).getColIds(),i=o.indexOf(t),n=this.children.iterator();let l=null;for(;l=n();){if(l.colId===t)return l;const e=o.indexOf(l.colId);if(e<i&&e+l.colspan>i)return l}return this[s]&&this[s].statics.blotName===e.tableRow?this[s].getCellByColId(t,s):null}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(ne);if(1!==o.colspan&&t===i-o.colspan){const t=d(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(ne);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 re extends ee{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=d(this,e.tableMain);if(!s)return;const o=s.getColIds(),i=this.descendants(le),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=Gt(),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)}}const ae=t.import("parchment"),ce=t.import("blots/block");class de extends ce{replaceWith(t,s){const o="string"==typeof t?this.scroll.create(t,s):t;if(o instanceof ae.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),t.statics.blotName===e.tableCellInner){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.remove(),t.parent.statics.blotName===e.tableCell&&0===t.parent.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 try{d(this,e.tableCellInner).unwrap()}catch{console.error("unwrap TableCellInner error")}}}const he=t.import("parchment"),ue=t.import("blots/scroll");class pe extends ue{enable(s=!0){const o=t.import(`formats/${e.tableCellInner}`),i=this.domNode.querySelectorAll(`.${o.className}`);for(const t of Array.from(i))t.setAttribute("contenteditable",String(!!s));const n=t.import(`formats/${e.tableCaption}`),l=this.domNode.querySelectorAll(`.${n.className}`);for(const t of Array.from(l))t.setAttribute("contenteditable",String(!!s));super.enable(s)}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,he.Scope.BLOCK&he.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 ne&&0===l&&(l+=1);for(const[t,e]of Object.entries(i))n.formatAt(0,l,t,e);return n}}const be=t.import("parchment"),me=t.import("blots/inline"),fe=t.import("blots/text");class ge extends de{static blotName=e.tableCaption;static tagName="caption";static className="ql-table-caption";static allowedChildren=[me,fe];static create(t){const{tableId:e}=t,s=super.create();return s.dataset.tableId=e,"bottom"===t.side&&(s.style.captionSide="bottom"),s}static formats(t){const{tableId:e}=t.dataset;return{tableId:String(e),side:"bottom"===t.style.captionSide?"bottom":"top"}}constructor(t,e,s){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled())),this.attachUI(this.createUI()),this.domNode.addEventListener("mouseenter",(()=>{this.scroll.isEnabled()&&(this.uiNode.style.display="flex")})),this.domNode.addEventListener("mouseleave",(()=>{this.scroll.isEnabled()&&(this.uiNode.style.display="none")})),this.uiNode.style.display="none"}createUI(){const t=document.createElement("i");return t.classList.add("ql-table-caption--switch"),t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\r\n \x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e\r\n <path\r\n fill="none"\r\n stroke="currentColor"\r\n stroke-linecap="round"\r\n stroke-linejoin="round"\r\n stroke-width="2"\r\n d="M7 3v18m3-15L7 3L4 6m16 12l-3 3l-3-3m3 3V3"\r\n />\r\n</svg>\r\n',t.addEventListener("click",(()=>{this.scroll.isEnabled()&&(this.side="top"===this.side?"bottom":"top")})),t}get tableId(){return this.domNode.dataset.tableId}set side(t){this.domNode.style.captionSide="bottom"===t?"bottom":"top"}get side(){return"bottom"===this.domNode.style.captionSide?"bottom":"top"}format(t,e){this.scroll.query(t,be.Scope.BLOCK_BLOT)&&t!==this.statics.blotName||super.format(t,e)}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})}0===this.children.length?this.remove():(super.optimize(t),null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()))}}class we extends ee{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(se(i))),r.setAttribute("colspan",String(se(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:se(i),colspan:se(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,s){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let e=t;this.statics.allowDataAttrs.has(t)&&(e=`data-${t}`),s?this.domNode.setAttribute(e,s):this.domNode.removeAttribute(e)}else this.statics.isAllowStyle(t)&&(Object.assign(this.domNode.style,{[t]:s}),t.startsWith("border")&&this.setStyleBoder(t,s));this.children.head&&this.children.head.statics.blotName===e.tableCellInner&&this.domNode.style.cssText&&(this.children.head.domNode.dataset.style=this.domNode.style.cssText)}setStyleBoder(t,e){const s=Boolean(e)?e:null;if(!(!["left","right","top","bottom"].some((e=>t.includes(e)))&&t.startsWith("border-")))return;const o=this.getNearByCell("left").map((t=>t.descendant(ne,0)[0])).filter(Boolean);for(const e of o)e.setFormatValue(t.replace("border-","border-right-"),s,!0);const i=this.getNearByCell("top").map((t=>t.descendant(ne,0)[0])).filter(Boolean);for(const e of i)e.setFormatValue(t.replace("border-","border-bottom-"),s,!0)}getNearByCell(t){const s=[];try{const t=d(this,e.tableMain);s.push(...t.getColIds())}catch(t){console.error(`Cell is not in table! ${t}`)}if(0===s.length)return[];if("left"===t){const t=new Set;let e=this.parent;for(let o=0;o<this.rowspan&&e instanceof le;o++){const o=e.children.iterator();let i=null;for(;i=o();){const e=s.indexOf(i.colId)+i.colspan;this.colId===s[e]&&t.add(i)}e=e.next}return Array.from(t)}if("top"===t){if(!(this.parent instanceof le&&this.parent.prev))return[];const t=new Set,e=this.getColumnIndex(),o=e+this.colspan,i=new Set(s.filter(((t,s)=>s>=e&&s<o)));let n=1,l=this.parent.prev;for(;l;){let e=!1;const o=l.children.iterator();let r=null,a=0;for(;r=o();)i.has(r.colId)&&r.rowspan>=n&&(t.add(r),i.delete(r.colId)),a+=r.colspan,r.rowspan>=n&&(e=!0);if(!e&&a===s.length)break;l=l.prev,n+=1}return Array.from(t)}return[]}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"))}getColumnIndex(){return d(this,e.tableMain).getColIds().indexOf(this.colId)}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 ve=t.import("blots/block/embed");class Ce extends ve{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")||String(s.colDefaultWidth),n=t.dataset.align,l=Object.hasOwn(t.dataset,"full"),r={tableId:String(e),colId:String(o),full:l,width:Number.parseFloat(i)};return n&&(r.align=n),r}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")}set full(t){t?this.domNode.dataset.full=String(!0):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")}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)}d(this,e.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(t);try{const t=d(this,e.tableColgroup);let s=!0;t.children.forEach((t=>{s&&=t.full})),t.full=s}catch{}}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]=h(this,[e.tableColgroup,e.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let u=c.parent.parent,p=c.parent.next;if(d){const t=d.descendants(ne);if(t.length>0){const s=t[0],o=ne.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),u=i,p=i.next}}for(const t of l)u.insertBefore(t,p);n&&u.insertBefore(this.scroll.create("text",n),p)}}class xe extends ee{scroll;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.scroll=t,this.updateAlign()}colWidthFillTable(){if(this.full)return void Object.assign(this.domNode.style,{width:null});const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?void 0:(this.domNode.style.width=`${e}px`,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=String(!0):this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}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()}setFull(){if(this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const s of t){const t=s.width/e*100;s.full=!0,s.width=t}}cancelFull(){if(!this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const o of t)o.full=!1,o.width=Math.max(o.width/100*e,s.colMinWidthPx)}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(le)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(Ce)}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)}sortMergeChildren(){const t={[e.tableCaption]:[],[e.tableColgroup]:[],[e.tableBody]:[]};this.children.forEach((e=>{t[e.statics.blotName]&&t[e.statics.blotName].push(e)}));for(const e of Object.values(t))for(let t=1;t<e.length;t++)e[t].moveChildren(e[0]);const s=t[e.tableCaption][0],o=t[e.tableColgroup][0],i=t[e.tableBody][0],n=s&&this.children.head!==s,l=o&&s&&s.next!==o,r=o&&!s&&this.children.head!==o,a=i&&this.children.tail!==i;if(n||l||r||a){const t=this.clone();s&&t.appendChild(s),o&&t.appendChild(o),i&&t.appendChild(i),this.children.forEach((t=>t.remove())),t.moveChildren(this)}}}class ye extends ee{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=String(!0):this.domNode.removeAttribute("data-full"),this.parent&&this.parent instanceof xe&&(this.parent.full=t)}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 xe))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 xe))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 xe&&!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});d(this,e.tableMain).align=n,super.optimize(t)}}const Me=t.import("parchment");class Ie extends ee{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.setAttribute("contenteditable","false"),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(re),o=this.descendants(ye);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 Me.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this),this.next&&this.next instanceof Me.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this.next)}}function Ne(t){const[e]=p(t,re);return{body:e,rect:e.domNode.getBoundingClientRect()}}class Te{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=c("align");resizeObserver=Pt((()=>this.update()),{ignoreFirstBind:!0});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(),this.resizeObserver.observe(this.table),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.show()}updateWhenTextChange=()=>{this.update()};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=At(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.update())}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():Ht(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[qt(),zt({limiter:$t()}),Ot(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})})))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}}const Le=t.import("delta"),Ee=t.import("modules/clipboard");function Se(t){let e=Number.parseFloat(t.getAttribute("width")||String(s.colDefaultWidth));if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e}class Be extends Ee{quill;tableId=Gt();rowId=Gt();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(t,e){super(t,e),this.quill=t,this.addMatcher("table",this.matchTable.bind(this)),this.addMatcher("tbody",this.matchTbody.bind(this)),this.addMatcher("colgroup",this.matchColgroup.bind(this)),this.addMatcher("col",this.matchCol.bind(this)),this.addMatcher("tr",this.matchTr.bind(this)),this.addMatcher("td",this.matchTd.bind(this)),this.addMatcher("th",this.matchTd.bind(this)),this.addMatcher("caption",this.matchCaption.bind(this)),this.addMatcher(Node.ELEMENT_NODE,this.matchTdAttributor.bind(this))}matchTable(t,o){if(0===o.ops.length)return o;const i=[],n=[];let l=-1;for(let t=0;t<o.ops.length;t++){const{attributes:s,insert:r}=o.ops[t],{table:a,[e.tableCell]:c,...d}=s||{},h=I(r)&&r[e.tableCol];h?n.push({insert:r}):i.push({attributes:d,insert:r}),!d?.[e.tableCellInner]&&!d?.[e.tableCaption]&&!h&&M(r)&&r.trim().length>0&&(l=t)}const r=function(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=Se(i);o[t]=e||o[t]}}}return o}(t,this.colIds.length).reduce(((t,s,o)=>(n[o]?t.push(n[o]):t.push({insert:{[e.tableCol]:{tableId:this.tableId,colId:this.colIds[o],width:s,full:!1}}}),t)),[]);return i.splice(l+1,0,...r),this.tableId=Gt(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,new Le(i)}matchTbody(t,s){const o=t.style.backgroundColor;if(o)for(const t of s.ops)if(t.attributes?.[e.tableCellInner]){const{style:s,...i}=t.attributes[e.tableCellInner],n=Xt(s||"");n.backgroundColor||(n.backgroundColor=o,t.attributes[e.tableCellInner]={...i,style:Ut(n)})}return s}matchColgroup(t,s){const o=[];for(let t=0;t<s.ops.length;t++){const i=s.ops[t];i&&I(i.insert)&&i.insert[e.tableCol]&&o.push(i)}return new Le(o)}matchCol(t){this.colIds[this.colCount]=Gt();const s=(new Le).insert({[e.tableCol]:Object.assign(Ce.value(t),{tableId:this.tableId,colId:this.colIds[this.colCount]})});return this.colCount+=1,s}matchTr(t,s){this.rowId=Gt(),this.cellCount=0;for(const[t,e]of this.rowspanCount.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(this.rowspanCount[t]={rowspan:0,colspan:0});for(const t of s.ops)if(t.attributes){const{background:s,[e.tableCellInner]:o}=t.attributes;if(o&&s){const{style:i=""}=o,n=Xt(i);n.backgroundColor=s,t.attributes[e.tableCellInner].style=Ut(n)}}return s}matchTd(t,s){const o=t,i=we.formats(o);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let t=this.cellCount;t>=0;t--)this.colIds[t]||(this.colIds[t]=Gt()),this.rowspanCount[t]||(this.rowspanCount[t]={rowspan:0,colspan:0});for(let t=this.cellCount;t<this.rowspanCount.length;t++){const{rowspan:e,colspan:s}=this.rowspanCount[t];if(0===e)break;this.cellCount+=s}i.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:i.rowspan,colspan:i.colspan});const n=this.colIds[this.cellCount];this.cellCount+=i.colspan;const l=Object.assign(i,{tableId:this.tableId,rowId:this.rowId,colId:n});"none"===o.style.border&&(l.style=l.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const r=[];for(const t of s.ops){const{attributes:s={},...o}=t,{[e.tableCell]:i,...n}=s;r.push({...o,attributes:{...n,[e.tableCellInner]:l}})}return(r.length<=0||!M(r[r.length-1].insert)||!r[r.length-1].insert.endsWith("\n"))&&r.push({insert:"\n",attributes:{[e.tableCellInner]:l}}),new Le(r)}matchTdAttributor(t,s){if("td"===t.tagName.toLocaleLowerCase()){const t=[];for(const o of s.ops){const{attributes:s,...i}=o,n=s?.[e.tableCellInner];if(s&&n&&n.style){const{background:e,...o}=s,l=document.createElement("div");l.style.background=e;const r=document.createElement("div");if(r.style.cssText=n.style,l.style.background===r.style.backgroundColor){t.push({...i,attributes:{...o}});continue}}t.push(o)}return new Le(t)}return s}convert({html:t,text:s},o={}){const i=super.convert({html:t,text:s},o);if(o[e.tableCellInner])for(const t of i.ops)I(t.insert)&&t.insert[e.tableCol]?t.insert="":(t.attributes||(t.attributes={}),t.attributes[e.tableCellInner]=o[e.tableCellInner]);return i}matchCaption(t,s){for(let t=0;t<s.ops.length;t++){const o=s.ops[t],{attributes:i}=o;i&&i[e.tableCaption]&&(i[e.tableCaption].tableId=this.tableId,o.attributes=i)}return s}}const Re="color-selector",ke={Break:{name:"break"},CopyCell:{name:"CopyCell",tip:"Copy cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256">\n <g fill="currentColor">\n <path d="M216 40v128h-48V88H88V40Z" opacity=".2" />\n <path\n 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"\n />\n </g>\n</svg>\n',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()}},CutCell:{name:"CutCell",tip:"Cut cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32">\n <path\n fill="currentColor"\n 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"\n />\n <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" />\n</svg>\n',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()}},InsertTop:{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert row above",handle:(t,e)=>{t.appendRow(e,!1),t.hideTableTools()}},InsertRight:{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert column right",handle:(t,e)=>{t.appendCol(e,!0),t.hideTableTools()}},InsertBottom:{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert row below",handle:(t,e)=>{t.appendRow(e,!0),t.hideTableTools()}},InsertLeft:{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Insert column Left",handle:(t,e)=>{t.appendCol(e,!1),t.hideTableTools()}},MergeCell:{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"\n />\n</svg>\n',tip:"Merge Cell",handle:(t,e)=>{t.mergeCells(e),t.hideTableTools()}},SplitCell:{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"\n />\n</svg>\n',tip:"Split Cell",handle:(t,e)=>{t.splitCell(e),t.hideTableTools()}},DeleteRow:{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Delete Row",handle:(t,e)=>{t.removeRow(e),t.hideTableTools()}},DeleteColumn:{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Delete Column",handle:(t,e)=>{t.removeCol(e),t.hideTableTools()}},DeleteTable:{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n 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"\n />\n</svg>\n',tip:"Delete table",handle:(t,e)=>{t.deleteTable(e)}},BackgroundColor:{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="2"\n d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"\n />\n</svg>\n',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},BorderColor:{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="1.5"\n 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"\n />\n</svg>\n',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}},SwitchWidth:{name:"SwitchWidth",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n \x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="2"\n d="M4 12V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v6m-10 6H3m18 0h-7m-8-3l-3 3l3 3m12-6l3 3l-3 3"\n />\n</svg>\n',tip:"Switch table width",handle:e=>{if(!e.table)return;const s=t.find(e.table);s&&(s.full?s.cancelFull():s.setFull())}},InsertCaption:{name:"InsertCaption",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n \x3c!-- Icon from TDesign Icons by TDesign - https://github.com/Tencent/tdesign-icons/blob/main/LICENSE --\x3e\n <path fill="currentColor" d="M21 10v12h-2V12H5v10H3V10zm0-8v6H3V2zm-2 2H5v2h14z" />\n</svg>\n',tip:"Insert table caption",handle(s){if(!s.table)return;const o=t.find(s.table);if(!o)return;const i=s.quill.scroll.create("text","Table Caption").wrap(e.tableCaption,{tableId:o.tableId});o.insertBefore(i,o.children.head)}}},Ae=c("color-map"),Oe={selectWrapper:Ae.b(),used:Ae.bm("used"),item:Ae.be("item"),btn:Ae.be("btn"),map:Ae.be("content"),mapRow:Ae.be("content-row")};class ze{tableModule;quill;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;updateUsedColor;tooltipItem=[];activeTooltip=null;bem=c("menu");colorItemClass=`color-${Gt()}`;colorChooseTooltipOption={direction:"top"};constructor(e,s,o){this.tableModule=e,this.quill=s,this.options=this.resolveOptions(o);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);y(e)||(e=[]),e.slice(-10).map((t=>this.usedColors.add(t)))}catch{}this.updateUsedColor=Kt((t=>{if(!t)return;if(this.usedColors.add(t),this.usedColors.size>10){const t=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),t.map((t=>this.usedColors.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Oe.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(Oe.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${Oe.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${Oe.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.isMenuDisplay&&this.update()};resolveOptions(t){return Object.assign({tipText:!0,tools:[ke.InsertTop,ke.InsertRight,ke.InsertBottom,ke.InsertLeft,ke.Break,ke.MergeCell,ke.SplitCell,ke.Break,ke.DeleteRow,ke.DeleteColumn,ke.DeleteTable,ke.Break,ke.BackgroundColor,ke.BorderColor],localstorageKey:"__table-bg-used-color",defaultColorMap:n},t)}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"),x(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(Re)}else x(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(Oe.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(Oe.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(Oe.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(Oe.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(Oe.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(Oe.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(Oe.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(Oe.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=T({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Dt(r,{direction:"right",type:"click",content:a,container:r});i.appendChild(n),i.appendChild(l),i.appendChild(r),o.appendChild(i);const h=document.createElement("div");h.classList.add(Oe.used,this.colorItemClass);for(const t of this.usedColors){const e=document.createElement("div");e.classList.add(Oe.item),e.style.backgroundColor=t,h.appendChild(e)}o.appendChild(h),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(`.${Oe.item}`))return;this.updateUsedColor(o)}}));const u=Dt(t,{type:"click",content:o,onOpen:()=>(this.isMenuDisplay&&this.tableModule.tableSelection&&this.tableModule.tableSelection.hideDisplay(),this.setActiveTooltip(u),!1),onClose:()=>{this.isMenuDisplay&&this.tableModule.tableSelection&&(this.tableModule.tableSelection.updateWithSelectedTds(),this.tableModule.tableSelection.showDisplay());return o.contains(a)&&c(),this.activeTooltip===u&&(this.activeTooltip=null),!1},onDestroy:()=>{d(),this.activeTooltip===u&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return u.isColorPick=!0,u}setActiveTooltip(t){this.activeTooltip&&this.activeTooltip!==t&&this.activeTooltip.hide(!0),this.activeTooltip=t}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Dt(t,{msg:e});s&&this.tooltipItem.push(s)}show(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,this.update())}update(){}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.activeTooltip=null;for(const t of this.tooltipItem)t.destroy();this.menu&&(this.hide(),this.menu.remove(),this.menu=null)}}class qe extends ze{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()),Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,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(Re);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)}show(){}update(t){if(!(this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection))return;if(!t)return;super.update();const e={display:"flex",left:0,top:0},{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}=jt(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 $e extends ze{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),this.show(),this.update()}update(){this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection&&(super.update(),Ht(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[qt(),zt({limiter:$t()}),Ot(20)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}}const He=t=>!t.full&&"right"===t.align;class We{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=c("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=N({content:s}),a=N({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=E({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 He(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 He(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{rect:e,body:s}=Ne(this.tableMain);if(!s)return;const o=this.tableMain.getCols();if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=o[this.colIndex].width,n=this.tableMain.full?i/100*e.width: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:e.y,left:t.clientX,height:e.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 De extends We{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=c("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),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)))}updateWhenTextChange=()=>{this.update()};handleResizerHeader(t,e,s){const{clientX:o,clientY:i}=s,n=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const l=this.tableModule.tableSelection;s.shiftKey||(this.lastHeaderSelect=null);const r=[{x:t?n.left:o,y:t?i:n.top},{x:t?n.right:o,y:t?i:n.bottom}];if(this.lastHeaderSelect){let e,s;if(this.lastHeaderSelect.isX){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=Math.min(t.left,n.left),s=t.top+t.height/2}else{const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=t.left+t.width/2,s=Math.min(t.top,n.top)}this.lastHeaderSelect.isX!==t?(r[1]={x:Math.max(r[0].x,e),y:Math.max(r[0].y,s)},r[0]={x:Math.min(r[0].x,e),y:Math.min(r[0].y,s)}):t?(r[0].y=Math.min(r[0].y,s),r[1].y=Math.max(r[1].y,s)):(r[0].x=Math.min(r[0].x,e),r[1].x=Math.max(r[1].x,e))}else this.lastHeaderSelect={isX:t,index:e};l.table=this.table,l.selectedTds=l.computeSelectedTds(...r),l.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);if(e&&this.dragColBreak){const[t]=p(this.tableMain,ge),s=t&&"top"===t.side?0:this.size;Object.assign(this.dragColBreak.style,{top:e.top-s+"px",left:`${e.left}px`,height:`${e.height+this.size}px`})}return 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")));Vt.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const[e,s]of t.entries())s.addEventListener("click",this.handleResizerHeader.bind(this,!1,e));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")));Vt.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const[e,s]of t.entries())s.addEventListener("click",this.handleResizerHeader.bind(this,!0,e));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const{rect:t,body:e}=Ne(this.tableMain);if(!e)return;const s=this.tableWrapper.domNode.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:Math.max(t.y,s.y)-o.y+"px",left:Math.max(t.x,s.x)-o.x+"px"});let i=-1*this.size,n=-1*this.size;He(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),i=Math.min(s.width,t.width),n=Math.min(s.width,t.width)):this.root.classList.remove(this.bem.is("align-right"));const[l]=p(this.tableMain,ge),r=!l||!(l&&"top"===l.side);r?this.root.classList.remove(this.bem.is("caption-bottom")):this.root.classList.add(this.bem.is("caption-bottom")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${i}px)`,top:`${r?0:t.height+this.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${n}px)`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${r?0:t.height+this.size}px`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const{rect:t,body:e}=Ne(this.tableMain);if(!e)return;const s=this.tableWrapper.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(ne),e=this.tableModule.tableSelection;e.selectedTds=t,e.show(),e.updateWithSelectedTds()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let e="";for(const[,s]of this.tableCols.entries()){const o=s.domNode.getBoundingClientRect().width;e+=`<div class="${this.bem.be("col-header")}" style="width: ${o}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${t.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:`${s.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${t.width}px`}),i.innerHTML=e,o.appendChild(i),this.root.appendChild(o),o.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=o,this.bindColEvents()}if(this.tableRows.length>0){let e="";for(const[,s]of this.tableRows.entries()){const o=`${s.domNode.getBoundingClientRect().height}px`;e+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(o)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${t.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:`${s.height}px`}),Object.assign(i.style,{height:`${t.height}px`}),i.innerHTML=e,o.appendChild(i),this.root.appendChild(o),o.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=o,this.bindRowEvents()}this.update(),Vt.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),_t.call(this),this.resizeObserver.disconnect(),this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange);for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}}class Fe extends We{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=c("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=d(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]=h(t,[e.tableBody]),o=s.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;He(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 le))return;const[o]=h(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(){this.rowResizer.classList.remove(this.bem.is("hidden")),this.colResizer.classList.remove(this.bem.is("hidden"))}hide(){this.currentTableCell=void 0,this.rowResizer.classList.add(this.bem.is("hidden")),this.colResizer.classList.add(this.bem.is("hidden"))}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 je{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=c("scale");startX=0;startY=0;offset=6;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()),this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};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=He(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),Vt.call(this,this.quill.root,(()=>this.update())),Vt.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;if(this.tableMainBlot.full)return void this.hide();const{rect:t,body:e}=Ne(this.tableMainBlot);if(!e)return;const s=this.tableWrapperBlot.domNode.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),{scrollTop:i,scrollLeft:n}=this.tableWrapperBlot.domNode,l=2*this.options.blockSize+this.offset,r=Math.min(t.width,s.width)+l,a=Math.min(t.height,s.height)+l;Object.assign(this.root.style,{width:`${r}px`,height:`${a}px`,left:Math.max(t.x,s.x)-o.x-this.options.blockSize+"px",top:Math.max(t.y,s.y)-o.y-this.options.blockSize+"px"});const c={left:t.width+l-n+"px",top:a-i+"px"};He(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),c.left=`${this.options.blockSize+-1*n}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,c)}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.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect(),this.root&&this.root.remove(),_t.call(this)}}class Pe{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=c("scrollbar");tableMainBlot;constructor(e,s,o,i){this.quill=e,this.isVertical=s,this.table=o,this.scrollbarContainer=i,this.tableMainBlot=t.find(this.table),this.container=o.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(o),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Vt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{rect:{width:t,height:e},body:s}=Ne(this.tableMainBlot);if(!s)return;const{scrollLeft:o,scrollTop:i,offsetLeft:n,offsetTop:l}=this.quill.root,{offsetLeft:r,offsetTop:a}=this.container,{offsetLeft:c,offsetTop:d}=s.domNode,{width:h,height:u}=this.container.getBoundingClientRect();let p=r+c-n,b=a+d-l;this.isVertical?p+=Math.min(h,t):b+=Math.min(u,e),this.tableMainBlot&&"left"!==this.tableMainBlot.align&&(p+=this.table.offsetLeft-r),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(u,e):h}px`,transform:`translate(${p-o}px, ${b-i}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"));let e=null;const s=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},o=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",o),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=e},i=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",s),document.addEventListener("mouseup",o),e=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),i(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 n=[this.table,t];for(const t of n)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Vt.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(),_t.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}class Ve{tableModule;table;quill;scrollbarContainer;scrollbar;bem=c("scrollbar");constructor(e,s,o){this.tableModule=e,this.table=s,this.quill=o,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Pe(o,!0,s,this.scrollbarContainer),new Pe(o,!1,s,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar);this.quill.on(t.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};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(),this.quill.off(t.events.TEXT_CHANGE,this.updateWhenTextChange);for(const t of this.scrollbar)t.destroy()}}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=c("selection");lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};constructor(e,s,i={}){this.tableModule=e,this.quill=s,this.options=this.resolveOptions(i),this.cellSelectWrap=e.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=Pt((()=>this.updateAfterEvent()),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.mouseDownHandler,{passive:!1}),document.addEventListener("selectionchange",this.selectionChangeHandler,{passive:!1}),this.quill.on(o.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(t.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(t.events.TEXT_CHANGE,this.updateAfterEvent),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(e,s,this.options.tableMenuOptions)),this.hide()}updateAfterEvent=()=>{this.updateWithSelectedTds()};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=(s,o,i)=>{if(i!==t.sources.API&&s&&this.selectedTds.length>0){const t=this.quill.getFormat(s),[o]=this.quill.getLine(s.index),i=!!t[e.tableCellInner]&&!!o,n=this.selectedTds.some((t=>t.children.contains(o)));if(i&&!n)try{const t=d(o,e.tableCellInner);this.selectedTds=[t],this.updateWithSelectedTds()}catch{}else i&&n||this.hide()}};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();if(!s)return;const{anchorNode:o,focusNode:i,anchorOffset:n,focusOffset:l}=s;if(!o||!i)return;const r=t.find(o),a=t.find(i);if(!r||!a||r.scroll!==this.quill.scroll||a.scroll!==this.quill.scroll)return;const c=u(r),d=u(a),h=c.has(e.tableColgroup),p=d.has(e.tableColgroup);if(h||p){let t=o,r=n,a=i,u=l;if(h){const s=c.get(e.tableWrapper).descendants(ne);s.length>0&&(t=s[0].domNode,r=0)}if(p){const t=d.get(e.tableWrapper).descendants(ne);t.length>0&&(a=t[0].domNode,u=0)}return void this.setSelectionData(s,{anchorNode:t,anchorOffset:r,focusNode:a,focusOffset:u})}const b=c.has(e.tableCellInner),m=d.has(e.tableCellInner);let f=b&&m;if(f){const t=c.get(e.tableCellInner),s=d.get(e.tableCellInner);f&&=t!==s}if(b&&m&&f||!b&&m||!m&&b)return this.setSelectionData(s,this.lastSelection),void(this.selectedTds.length>0&&this.hide());this.lastSelection={anchorNode:o,anchorOffset:n,focusNode:i,focusOffset:l}};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=o.descendants(re)[0];if(!i)return[];const n=new Set(i.descendants(we).map(((t,e)=>(t.index=e,t)))),{x:l,y:r}=this.getTableViewScroll(),{x:a,y:c}=this.getQuillViewScroll();this.selectedTableScrollX=l,this.selectedTableScrollY=r,this.selectedEditorScrollX=a,this.selectedEditorScrollY=c;const{rect:d}=Ne(o),h=e.x-l+this.startScrollX,u=e.y-r+this.startScrollY;let p={x:Math.max(d.left,Math.min(s.x,h)),y:Math.max(d.top,Math.min(s.y,u)),x1:Math.min(d.right,Math.max(s.x,h)),y1:Math.min(d.bottom,Math.max(s.y,u))};const b=new Set;let m=!0;for(;m;){m=!1;for(const t of n){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:o,bottom:i}=t.__rect;if(Ft({x:Math.floor(p.x),y:Math.floor(p.y),x1:Math.floor(p.x1),y1:Math.floor(p.y1)},{x:Math.floor(e),y:Math.floor(s),x1:Math.floor(o),y1:Math.floor(i)},0,0===b.size)){b.add(t),n.delete(t),p={x:Math.min(p.x,e),y:Math.min(p.y,s),x1:Math.max(p.x1,o),y1:Math.max(p.y1,i)},m=!0;break}}}for(const t of[...b,...n])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}}({...p,width:p.x1-p.x,height:p.y1-p.y},this.quill.root),Array.from(b).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler=t=>{const{button:e,target:s,clientX:o,clientY:i}=t,n=s.closest(".ql-table"),l=s.closest("tbody");if(0!==e||!n||!l)return;this.setSelectionTable(n);const r=n.dataset.tableId,a={x:o,y:i};this.selectedTds=this.computeSelectedTds(a,a),this.dragging=!0,this.show();const c=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("tbody");if(0!==e||!n||n.dataset.tableId!==r)return;const l={x:o,y:i};this.selectedTds=this.computeSelectedTds(a,l),this.selectedTds.length>1&&this.quill.blur(),this.update()},d=()=>{document.body.removeEventListener("mousemove",c,!1),document.body.removeEventListener("mouseup",d,!1),this.dragging=!1,this.tableMenu&&this.selectedTds.length>0&&this.tableMenu.show()};document.body.addEventListener("mousemove",c,!1),document.body.addEventListener("mouseup",d,!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.update():this.hide()}update(){if(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;this.startScrollX=s,this.startScrollY=o,Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-o-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${i.width}px`,height:`${i.height}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=t)}removeCell=e=>{if(!(this.quill.getSelection()||"Backspace"!==e.key&&"Delete"!==e.key)){for(const t of this.selectedTds)t.deleteAt(0,t.length()-1);if(this.table){const e=t.find(this.table),s=e.descendants(ne);this.selectedTds.length===s.length&&e.remove()}}};showDisplay(){Object.assign(this.cellSelectWrap.style,{display:"block"}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(_t.call(this),this.update(),this.showDisplay(),document.addEventListener("keydown",this.removeCell),Vt.call(this,this.quill.root,(()=>{this.update()})),Vt.call(this,this.table.parentElement,(()=>{this.update()})))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:"none"}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){_t.call(this),document.removeEventListener("keydown",this.removeCell),this.hideDisplay(),this.boundary=null,this.selectedTds=[],this.setSelectionTable(void 0),this.tableMenu&&this.tableMenu.hide()}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),_t.call(this),this.quill.root.removeEventListener("mousedown",this.mouseDownHandler),document.removeEventListener("selectionchange",this.selectionChangeHandler),this.quill.off(t.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.off(t.events.TEXT_CHANGE,this.updateAfterEvent),this.quill.on(o.AFTER_TABLE_RESIZE,this.updateAfterEvent)}}const Xe=t.import("parchment"),Ue=t.import("delta"),Ye=t.import("blots/break"),Ge=t.import("ui/icons");function Ke(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}function Ze(t){r.delete(e.tableCellInner),Object.assign(e,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(o,t.tableUpEvent||{}),Object.assign(i,t.tableUpInternal||{}),ts.moduleName=i.moduleName,ts.toolName=e.tableWrapper,ee.blotName=e.container,Ie.blotName=e.tableWrapper,xe.blotName=e.tableMain,ye.blotName=e.tableColgroup,Ce.blotName=e.tableCol,re.blotName=e.tableBody,le.blotName=e.tableRow,we.blotName=e.tableCell,ne.blotName=e.tableCellInner,r.add(e.tableCellInner)}function Qe(t,e){return B({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Je(s){return{bindInHead:!1,key:s?"ArrowUp":"ArrowDown",collapsed:!0,format:[e.tableCellInner],handler(o,i){let n,l,r,a;try{[n,l,r,a]=h(i.line,[e.tableWrapper,e.tableMain,e.tableRow,e.tableCell])}catch{return!0}const c=l.getColIds(),d=s?"prev":"next",u=s?"tail":"head",p=n.descendants(ge,0)[0];let b;if(p){const t=window.getComputedStyle(p.domNode);b="next"===d&&"bottom"===t.captionSide?p:"next"===d?n.next:p}else b=n[d];if(i.line[d]||!b)return!0;const m=r[d];if(m){const e=c.indexOf(a.colId),s=m.getCellByColId(c[e],d);if(!s)return!0;let o=s.children[u];o.children&&(o=o.children[u]);const n=o.offset(this.quill.scroll)+Math.min(i.offset,o.length()-1);this.quill.setSelection(n,0,t.sources.USER)}else{const e=b.offset(this.quill.scroll)+(s?b.length()-1:0);this.quill.setSelection(e,0,t.sources.USER)}return!1}}}class ts{static moduleName=i.moduleName;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 Ie)return o.prev.remove(),!1;if(s.format[e.tableCellInner]){if(0===o.offset(d(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 Ie||i.next instanceof Ce)&&n===i.length()-1)return!1;if(s.format[e.tableCellInner]){if(i===d(i,e.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"table up":Je(!0),"table down":Je(!1),"table caption break":{bindInHead:!0,key:"Enter",shiftKey:null,format:[e.tableCaption],handler:(t,e)=>!1}};static register(){Ie.allowedChildren=[xe],xe.allowedChildren=[re,ye,ge],xe.requiredContainer=Ie,ge.requiredContainer=xe,ye.allowedChildren=[Ce],ye.requiredContainer=xe,re.allowedChildren=[le],re.requiredContainer=xe,le.allowedChildren=[we],we.requiredContainer=re,we.allowedChildren=[ne,Ye],we.requiredContainer=le,ne.requiredContainer=we;const s=["header","list","blockquote","code-block"].reduce(((e,s)=>{const o=`formats/${s}`,i=t.import(o);return e[o]=class extends(function(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)b(s.prototype,t.prototype);return s}(i,[de])){static register(){}},e}),{});t.register({"blots/scroll":pe,"blots/block":de,...s,[`blots/${e.container}`]:ee,[`formats/${e.tableCell}`]:we,[`formats/${e.tableCellInner}`]:ne,[`formats/${e.tableRow}`]:le,[`formats/${e.tableBody}`]:re,[`formats/${e.tableCol}`]:Ce,[`formats/${e.tableColgroup}`]:ye,[`formats/${e.tableCaption}`]:ge,[`formats/${e.tableMain}`]:xe,[`formats/${e.tableWrapper}`]:Ie,"modules/clipboard":Be},!0)}quill;options;toolBox;fixTableByLisenter=Kt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;resizeOb;get statics(){return this.constructor}constructor(e,s){if(this.quill=e,this.options=this.resolveOptions(s||{}),this.toolBox=this.initialContainer(),!this.options.scrollbar){const t=c("scrollbar");this.quill.container.classList.add(t.bm("origin"))}this.options.selection&&(this.tableSelection=new this.options.selection(this,this.quill,this.options.selectionOptions));const o=this.quill.getModule("toolbar");if(o&&this.quill.theme.pickers){const[,t]=(o.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}=jt(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 i=this.quill.getModule("keyboard");for(const t of Object.values(ts.keyboradHandler))t.bindInHead?i.bindings[t.key].unshift(t):i.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(),this.tableAlign&&this.tableAlign.update(),this.tableResize&&this.tableResize.update(),void(this.tableScrollbar&&this.tableScrollbar.update());this.table&&this.hideTableTools(),this.showTableTools(s)}else this.table&&this.hideTableTools()}),!1),this.quill.on(t.events.EDITOR_CHANGE,(e=>{e!==t.events.TEXT_CHANGE||this.table&&this.quill.root.contains(this.table)||this.hideTableTools()})),this.quillHack(),this.listenBalanceCells()}initialContainer(){const t=c("toolbox"),e=this.quill.addContainer(t.b());return this.resizeOb=new ResizeObserver((()=>{const t=this.quill.root.getBoundingClientRect(),{offsetLeft:s,offsetTop:o}=this.quill.root;Object.assign(e.style,{top:`${o}px`,left:`${s}px`,width:`${t.width}px`,height:`${t.height}px`})})),this.resizeOb.observe(this.quill.root),e}addContainer(t){if(M(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:Ge.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)}quillHack(){const s=this.quill.getSemanticHTML;this.quill.getSemanticHTML=(o=0,i)=>{const n=s.call(this.quill,o,i),l=t.import(`formats/${e.tableWrapper}`),r=(new DOMParser).parseFromString(n,"text/html");for(const t of Array.from(r.querySelectorAll(`.${l.className} caption[contenteditable], .${l.className} td > [contenteditable]`)))t.removeAttribute("contenteditable");return r.body.innerHTML};const o=this.quill.format;this.quill.format=function(s,n,l=t.sources.API){if(!(this.scroll.query(s).prototype instanceof Xe.EmbedBlot)){const t=this.getModule(i.moduleName),r=this.getSelection();if(r&&r.length>0){if(this.getFormat(r)[e.tableCellInner])return o.call(this,s,n,l)}if(t&&t.tableSelection&&t.tableSelection.selectedTds.length>0){const e=t.tableSelection.selectedTds;let o=!1;const i=[];for(const t of e){const e=t.offset(this.scroll),l=t.length();i.push({index:e,length:l});this.getFormat(e,l)[s]!==n&&(o=!0)}const r=!!o&&n,a=new Ue;for(const[t,{index:e,length:o}]of i.entries()){const n=0===t?0:i[t-1].index+i[t-1].length;a.retain(e-n).retain(o,{[s]:r})}const c=this.updateContents(a,l);return this.blur(),c}}return o.call(this,s,n,l)};const n=this.quill.theme.modules.toolbar;if(n){const s=n.handlers?.clean;if(s){const o=(t,s,o=()=>"")=>{const i=this.quill.getText(t,s),[n,l]=this.quill.getLine(t+s);let r=0,a=new Ue;null!=n&&(r=n.length()-l,a=n.delta().slice(l,l+r-1).insert("\n"));const c=this.quill.getContents(t,s+r),d=c.diff((new Ue).insert(i).concat(a));let h=0;const u=d.ops.map((t=>{const{attributes:s,...i}=t;if(t.insert?h-=M(t.insert)?t.insert.length:1:t.retain?h+="number"==typeof t.retain?t.retain:1:t.delete&&(h+=t.delete),s){const{[e.tableCellInner]:t,...n}=s;if(o){const t=c.slice(h-1,h).ops[0];if(t&&t.attributes&&t.attributes[e.tableCellInner]){const s=t.attributes[e.tableCellInner],{style:l,...r}=s,a=o(l);return a?{...i,attributes:{...n,[e.tableCellInner]:{style:a,...r}}}:{...i,attributes:{...n,[e.tableCellInner]:r}}}}return{...i,attributes:{...n}}}return t}));return new Ue(u)};n.handlers.clean=function(n){const l=this.quill.getModule(i.moduleName),r=this.quill.getSelection();if(r&&r.length>0){if(this.quill.getFormat(r)[e.tableCellInner]){const e=o(r.index,r.length,!1),s=(new Ue).retain(r.index).concat(e);return void this.quill.updateContents(s,t.sources.USER)}}if(l&&l.tableSelection&&l.tableSelection.selectedTds.length>0&&l.tableSelection.table){const e=t.find(l.tableSelection.table);if(!e)return void console.warn("TableMainFormat not found");const s=l.tableSelection.selectedTds,i=new Set,n=[];for(const t of s)if(t.parent instanceof we){for(const e of t.parent.getNearByCell("top"))i.has(e)||(i.add(e),n.push({td:e,cleanBorder:"bottom"}));for(const e of t.parent.getNearByCell("left"))i.has(e)||(i.add(e),n.push({td:e,cleanBorder:"right"}));i.add(t.parent),n.push({td:t.parent,cleanBorder:!0})}const r=e.descendants(we),a=new Map(r.map(((t,e)=>[t,e])));n.sort(((t,e)=>a.get(t.td)-a.get(e.td)));let c=new Ue,d=0;for(const{td:t,cleanBorder:e}of n){const s=t.getCellInner().offset(this.quill.scroll),i=t.getCellInner().length(),n=o(s,i-1,(t=>{if(!t||!0===e)return"";const s=Xt(t);return Ut(Object.keys(s).filter((t=>!t.startsWith(Yt(`border-${e}`)))).reduce(((t,e)=>(t[e]=s[e],t)),{}))})),l=(new Ue).retain(s-d).concat(n);c=c.concat(l),d=s+i}return this.quill.updateContents(c,t.sources.USER),void(s.length>1&&this.quill.blur())}return s.call(this,n)}}}}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||!x(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=c("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("span");i.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),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)M(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=d(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"),""}if(!o)return"";const i=this.quill.getIndex(o),n=o.length(),l=this.quill.getSemanticHTML(i,n),r=(new DOMParser).parseFromString(l,"text/html"),a=[],c=new Set,h=new Set;for(const e of t)c.add(e.colId),h.add(`${e.rowId}-${e.colId}`);for(const t of Array.from(r.querySelectorAll("col")))c.has(t.dataset.colId)?a.push(t.getAttribute("width")):t.remove();let u=0,p=null;for(const t of Array.from(r.querySelectorAll("td")))if(h.has(`${t.dataset.rowId}-${t.dataset.colId}`))p!==t.dataset.rowId&&(u+=1,p=t.dataset.rowId);else{const e=t.parentElement;t.remove(),e&&e.children.length<=0&&e.remove()}const b=Array.from(r.querySelectorAll("col")),m=b.map((t=>Ce.value(t)));if(o.full){const t=m.reduce(((t,e)=>e.width+t),0);for(const[e,s]of m.entries())s.width=Math.round(s.width/t*100),b[e].setAttribute("width",`${s.width}%`)}else{let t=0;for(const e of m)t+=e.width;r.querySelector("table").style.width=`${t}px`}if(s){if(u===o.getRows().length)this.removeCol(t);else for(const e of t)e.domNode.innerHTML="<p><br></p>"}return r.body.innerHTML}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(a(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),c=getComputedStyle(this.quill.root),d=Number.parseInt(c.paddingLeft),h=Number.parseInt(c.paddingRight),u=Number.parseInt(c.width)-d-h-r,p=Gt(),b=new Array(i).fill(0).map((()=>Gt())),m=this.options.full?`${Math.max(1/i*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(u/i),s.colMinWidthPx)}px`,f=[{retain:n.index},{insert:"\n"}];for(let t=0;t<i;t++)f.push({insert:{[e.tableCol]:{width:m,tableId:p,colId:b[t],full:this.options.full}}});for(let t=0;t<o;t++){const t=Gt();for(let s=0;s<i;s++)f.push({insert:"\n",attributes:{[e.tableCellInner]:{tableId:p,rowId:t,colId:b[s],rowspan:1,colspan:1}}})}this.quill.updateContents(new Ue(f),t.sources.USER),this.quill.setSelection(n.index+i+i*o+1,t.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${xe.className}">\n <tbody>\n <tr>\n <td class="${we.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=Ie.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(we);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(Ke(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(xe))this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(t.events.SCROLL_OPTIMIZE,(e=>{e.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)));for(const s of e){const e=s.target;if("TABLE"===e.tagName){const s=t.find(e);if(s){s.sortMergeChildren();break}}}}))}deleteTable(t){if(0===t.length)return;const s=d(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]=h(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=d(o,e.tableMain),l=n.tableId,r=Gt(),[a]=n.descendants(ye);a&&a.insertColByIndex(i,{tableId:l,colId:r,width:n.full?6:160,full:n.full});const c=n.getRows(),h=[];let u=0;for(const t of Object.values(c)){const e=h.shift()||0;if(u>0){u-=1;continue}const s=t.insertCell(i-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(u+=s.skipRowNum);for(const[t,e]of s.entries())h[t]=(h[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=d(t[0],e.tableMain),o=s.getRows();let i=o.length,n=-1;for(const s of t){const t=d(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=d(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(le);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(ye);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=d(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]=h(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}}}export{de as BlockOverride,ee as ContainerFormat,pe as ScrollOverride,Pe as Scrollbar,Te as TableAlign,re as TableBodyFormat,ge as TableCaptionFormat,we as TableCellFormat,ne as TableCellInnerFormat,Be as TableClipboard,Ce as TableColFormat,ye as TableColgroupFormat,xe as TableMainFormat,ze as TableMenuCommon,qe as TableMenuContextmenu,$e as TableMenuSelect,De as TableResizeBox,We as TableResizeCommon,Fe as TableResizeLine,je as TableResizeScale,le as TableRowFormat,_e as TableSelection,ts as TableUp,Ve as TableVirtualScrollbar,Ie as TableWrapperFormat,e as blotName,T as createColorPicker,B as createSelectBox,Dt as createTooltip,ts as default,Qe as defaultCustomSelect,d as findParentBlot,h as findParentBlots,Ne as getTableMainRect,He as isTableAlignRight,Gt as randomId,ke as tableMenuTools,o as tableUpEvent,i as tableUpInternal,s as tableUpSize,Ze as updateTableConstants};
2
2
  //# sourceMappingURL=index.js.map