/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/quill-table-up@3.5.1/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import e from"quill";const t={container:"table-up-container",tableCaption:"table-up-caption",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableHead:"table-up-head",tableBody:"table-up-body",tableFoot:"table-up-foot",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},n={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},r={AFTER_TABLE_RESIZE:"after-table-resize",TABLE_SELECTION_DRAG_START:"table-selection-drag-start",TABLE_SELECTION_DRAG_END:"table-selection-drag-end",TABLE_SELECTION_CHANGE:"table-selection-change",TABLE_SELECTION_DISPLAY_CHANGE:"table-selection-display-change"},i={moduleName:"table-up",tableSelectionName:"table-selection"},a=[["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)"]],o=new Set([t.tableCellInner]),s=t=>o.has(t.statics.blotName);function c(t){return!!t?.parent&&(!!s(t.parent)||c(t.parent))}function l(t,e="table-up"){let l=e?`${e}-`:"";return{b:()=>`${l}${t}`,be:e=>e?`${l}${t}__${e}`:"",bm:e=>e?`${l}${t}--${e}`:"",bem:(e,i)=>e&&i?`${l}${t}__${e}--${i}`:"",ns:t=>t?`${l}${t}`:"",bs:e=>e?`${l}${t}-${e}`:"",cv:t=>t?`--${l}${t}`:"",is:t=>`is-${t}`}}function u(t,e){let l=t.parent;for(;l&&l.statics.blotName!==e&&l!==t.scroll;)l=l.parent;if(l===t.scroll)throw Error(`${t.statics.blotName} must be a child of ${e}`);return l}function d(t,e){let l=Array(e.length),i=new Map(e.map(((t,e)=>[t,e]))),o=t.parent;for(;o&&o!==t.scroll&&0!==i.size;){if(i.has(o.statics.blotName)){l[i.get(o.statics.blotName)]=o,i.delete(o.statics.blotName)}o=o.parent}if(i.size>0)throw Error(`${t.statics.blotName} must be a child of ${Array.from(i.keys()).join(", ")}`);return l}function f(t){let e=new Map,l=t;for(;l&&"scroll"!==l.statics.blotName;)e.set(l.statics.blotName,l),l=l.parent;return e}function p(t,e){let l=[],i=t.children.iterator(),o=null;for(;o=i();)o instanceof e&&l.push(o);return l}function m(t,e,l){for(let i of Object.getOwnPropertyNames(e))l?.test(i)||Object.defineProperty(t,i,Object.getOwnPropertyDescriptor(e,i));return t}function h(t,e){let l=class extends t{};for(let t of e)m(l.prototype,t.prototype,/^constructor$/);return l}function g(t,e){return t.prototype&&t.prototype instanceof e}function _(t,e){return t=Math.min(e,Math.max(0,Number.parseFloat(`${t}`))),Math.abs(t-e)<1e-6?1:t%e/Number.parseFloat(e)}function v(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 y(t){return t=t.startsWith("#")?t.slice(1):t,{r:Number.parseInt(t.slice(0,2),16),g:Number.parseInt(t.slice(2,4),16),b:Number.parseInt(t.slice(4,6),16),a:Number((Number.parseInt(t.slice(6,8)||"ff",16)/255).toFixed(2))}}function b(t){let{r:e,g:l,b:i,a:o}=t;e=_(e,255),l=_(l,255),i=_(i,255);let s,n=Math.max(e,l,i),r=Math.min(e,l,i),a=n,h=n-r,d=0===n?0:h/n;if(n===r)s=0;else{switch(n){case e:s=(l-i)/h+(l<i?6:0);break;case l:s=(i-e)/h+2;break;case i:s=(e-l)/h+4}s/=6}return{h:360*s,s:100*d,b:100*a,a:o}}function ee(t){let{h:e,s:l,b:i,a:o}=t;e=6*_(e,360),l=_(l,100),i=_(i,100);let s=Math.floor(e),n=e-s,r=i*(1-l),a=i*(1-n*l),h=i*(1-(1-n)*l),d=s%6,c=[i,a,r,r,h,i][d],u=[h,i,i,a,r,r][d],p=[r,r,h,i,i,a][d];return{r:Math.round(255*c),g:Math.round(255*u),b:Math.round(255*p),a:o}}function te(t){let e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(let t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")}const ne=t=>te(ee(t)),x=t=>"function"==typeof t,S=Array.isArray,C=t=>"string"==typeof t,re=t=>"number"==typeof t,ie=t=>"object"==typeof t&&!!t,ae=t=>void 0===t,oe=t=>!Number.isNaN(t)&&Number(t)>0,se=t=>S(t)?t:[t];function ce(t){let{type:e="default",content:i}=t||{},o=l("button"),s=document.createElement("button");return s.classList.add(o.b(),e),i&&(C(i)?s.textContent=i:s.appendChild(i)),s}function le(t={}){let e=b(y(t.color||"#ff0000")),i=l("color-picker"),o=document.createElement("div");o.classList.add(i.b());let s=document.createElement("div");s.classList.add(i.be("content"));let n=document.createElement("div");n.classList.add(i.be("selector"));let r=document.createElement("div");r.classList.add(i.be("background")),n.appendChild(r);let a=document.createElement("div");a.classList.add(i.be("background-handle")),r.appendChild(a);let h=document.createElement("div");h.classList.add(i.be("alpha"));let d=document.createElement("div");d.classList.add(i.be("alpha-bg"));let c=document.createElement("div");c.classList.add(i.be("alpha-handle")),h.appendChild(d),h.appendChild(c);let u=document.createElement("div");u.classList.add(i.be("hue"));let p=document.createElement("div");p.classList.add(i.be("hue-handle")),u.appendChild(p);let m=document.createElement("div");m.classList.add(i.be("action"));let[f,g,w,C]=["r","g","b","a"].map((t=>{let l=document.createElement("div");l.classList.add(i.be("action-item"),t);let o=document.createElement("label");o.textContent=t.toUpperCase();let s=document.createElement("input");return s.classList.add(i.be("input")),s.addEventListener("input",(()=>{s.value=s.value.replaceAll(/[^0-9]/g,"")})),s.addEventListener("change",(()=>{let l=Math.round(Number(s.value));"a"===t&&(l/=100),B(v(b(Object.assign({},ee(e),{[t]:l})))),N()})),l.appendChild(o),l.appendChild(s),m.appendChild(l),s}));s.appendChild(u),s.appendChild(n),s.appendChild(h),o.appendChild(s),o.appendChild(m);let x=!1,I=!1,T=!1;function S(){let t=ne(e);for(let[e,l]of[f,g,w].entries())l.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));C.value=String((100*e.a).toFixed(0))}function N(){Object.assign(a.style,{left:`${Math.floor(230*e.s/100)}px`,top:`${Math.floor(150*(100-e.b)/100)}px`}),n.style.backgroundColor=`#${te(ee({h:e.h,s:100,b:100,a:1}))}`,p.style.top=`${Math.floor(150-150*e.h/360)}px`,c.style.left=100*e.a+"%",function(){let{r:t,g:l,b:i}=ee(e);d.style.background=`linear-gradient(to right, rgba(${t}, ${l}, ${i}, 0) 0%, rgba(${t}, ${l}, ${i}, 1) 100%)`}(),S()}function B(l){e=v(Object.assign({},e,l)),S(),t.onChange&&t.onChange(`#${ne(e)}`)}function M(t){let e=n.getBoundingClientRect(),l=e.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),i=e.left+document.body.scrollLeft;B({s:Math.floor(100*Math.max(0,Math.min(230,t.pageX-i))/230),b:Math.floor(100*(150-Math.max(0,Math.min(150,t.pageY-l)))/150)}),N()}function E(t){let e=u.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);B({h:Math.floor(360*(150-Math.max(0,Math.min(150,t.pageY-e)))/150)}),N()}function R(t){let{pageX:e}=t,l=h.getBoundingClientRect(),i=e-l.left;i=Math.max(5,i),i=Math.min(i,l.width-5),B({a:Math.round((i-5)/(l.width-10)*100)/100}),N()}function L(t){x&&(t.preventDefault(),M(t)),I&&(t.preventDefault(),E(t)),T&&(t.preventDefault(),R(t))}function A(){document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",A),x=!1}function k(){document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",k),I=!1}function O(){document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",O),T=!1}return n.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",L),document.addEventListener("mouseup",A),x=!0,M(t)})),u.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",L),document.addEventListener("mouseup",k),I=!0,E(t)})),h.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",L),document.addEventListener("mouseup",O),T=!0,R(t)})),N(),o}let w=8e3;function ue({child:t,target:e=document.body,beforeClose:i=()=>{}}={}){let o=l("dialog"),s=e,n=document.createElement("div");n.classList.add(o.b()),n.style.zIndex=String(w);let r=document.createElement("div");if(r.classList.add(o.be("overlay")),n.appendChild(r),t){let e=document.createElement("div");e.classList.add(o.be("content")),e.appendChild(t),r.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}let a=getComputedStyle(s).overflow;s.style.overflow="hidden",s.appendChild(n);let h=()=>{i(),n.remove(),s.style.overflow=a};return n.addEventListener("click",h),w+=1,{dialog:n,close:h}}async function de({message:t,confirm:e,cancel:l}){return new Promise((i=>{let o=document.createElement("div");Object.assign(o.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});let s=document.createElement("p");s.textContent=t;let n=document.createElement("div");Object.assign(n.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});let r=ce({content:l}),a=ce({type:"confirm",content:e});n.appendChild(r),n.appendChild(a),o.appendChild(s),o.appendChild(n);let{close:h}=ue({child:o});r.addEventListener("click",(()=>{i(!1),h()})),a.addEventListener("click",(()=>{i(!0),h()}))}))}function fe(t,e){let i=l("input");e.type||="text",e.value||="";let o=document.createElement("div");if(o.classList.add(i.be("item")),t){let e=document.createElement("span");e.classList.add(i.be("label")),e.textContent=t,o.appendChild(e)}let s=document.createElement("div");s.classList.add(i.be("input"));let n=document.createElement("input");for(let t in e)n.setAttribute(t,e[t]);return(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))})),s.appendChild(n),o.appendChild(s),n.addEventListener("focus",(()=>{s.classList.add("focus")})),n.addEventListener("blur",(()=>{s.classList.remove("focus")})),{item:o,input:n,errorTip:t=>{let e;return s.classList.contains("error")?e=s.querySelector(`.${i.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(i.be("error-tip")),s.appendChild(e)),e.textContent=t,s.classList.add("error"),{removeError:()=>{s.classList.remove("error"),e.remove()}}}}}async function pe(t={}){let e=l("creator"),i=document.createElement("div");i.classList.add(e.b());let o=document.createElement("div");o.classList.add(e.be("input"));let{item:s,input:n,errorTip:r}=fe(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:h,errorTip:d}=fe(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(s),o.appendChild(a),i.appendChild(o);let c=document.createElement("div");c.classList.add(e.be("control"));let u=ce({type:"confirm",content:t.confirmText||"Confirm"}),p=ce({type:"default",content:t.cancelText||"Cancel"});c.appendChild(u),c.appendChild(p),i.appendChild(c);let m=(e=Number(n.value),l=Number(h.value))=>{if(Number.isNaN(e)||e<=0)r(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(l)||l<=0))return{row:e,col:l};d(t.notPositiveNumberError||"Please enter a positive integer")}},f=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",f))};return new Promise(((t,e)=>{let{close:l}=ue({child:i,beforeClose:e});n.focus();for(let e of[n,h])e.addEventListener("keydown",(e=>{if("Enter"===e.key){let e=m();e&&(t(e),l())}}));u.addEventListener("click",(()=>{let e=m();e&&(t(e),l())})),document.addEventListener("keydown",f),p.addEventListener("click",l)})).finally((()=>{document.removeEventListener("keydown",f)}))}function T(t={}){let e=l("select-box"),i=document.createElement("span");i.classList.add(e.b());let o=document.createElement("span");o.classList.add(e.be("block"));for(let l=0;l<(t.row||8);l++)for(let i=0;i<(t.col||8);i++){let t=document.createElement("span");t.classList.add(e.be("item")),t.dataset.row=String(l+1),t.dataset.col=String(i+1),o.appendChild(t)}let s=()=>{let{row:t,col:e}=i.dataset;for(let t of Array.from(o.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;let l=Array.from(o.children);for(let i of l){let{row:l,col:o}=i.dataset;if(l>t&&o>e)return;i.classList.toggle("active",l<=t&&o<=e)}};if(o.addEventListener("mousemove",(t=>{if(!t.target)return;let{row:e,col:l}=t.target.dataset;!e||!l||(i.dataset.row=e,i.dataset.col=l,s())})),o.addEventListener("mouseleave",(()=>{i.removeAttribute("data-row"),i.removeAttribute("data-col"),s()})),o.addEventListener("click",(()=>{let{row:e,col:l}=i.dataset;!e||!l||t.onSelect?.(Number(e),Number(l))})),i.appendChild(o),t.customBtn){let l=t.texts||{},o=document.createElement("span");o.classList.add(e.be("custom")),o.textContent=l.customBtnText||"Custom",o.addEventListener("click",(async()=>{let e=await pe(l);e&&t.onSelect?.(e.row,e.col)})),i.appendChild(o)}return i}const me=Math.min,E=Math.max,he=Math.round,ge=Math.floor,D=t=>({x:t,y:t}),_e={left:"right",right:"left",bottom:"top",top:"bottom"},ve={start:"end",end:"start"};function ye(t,e,l){return E(t,me(e,l))}function be(t,e){return"function"==typeof t?t(e):t}function O(t){return t.split("-")[0]}function xe(t){return t.split("-")[1]}function Se(t){return"x"===t?"y":"x"}function Ce(t){return"y"===t?"height":"width"}const we=new Set(["top","bottom"]);function k(t){return we.has(O(t))?"y":"x"}function Te(t){return Se(k(t))}function Ee(t,e,l){void 0===l&&(l=!1);let i=xe(t),o=Te(t),s=Ce(o),n="x"===o?i===(l?"end":"start")?"right":"left":"start"===i?"bottom":"top";return e.reference[s]>e.floating[s]&&(n=Fe(n)),[n,Fe(n)]}function De(t){let e=Fe(t);return[Oe(t),e,Oe(e)]}function Oe(t){return t.replace(/start|end/g,(t=>ve[t]))}const ke=["left","right"],Ae=["right","left"],je=["top","bottom"],Me=["bottom","top"];function Ne(t,e,l){switch(t){case"top":case"bottom":return l?e?Ae:ke:e?ke:Ae;case"left":case"right":return e?je:Me;default:return[]}}function Pe(t,e,l,i){let o=xe(t),s=Ne(O(t),"start"===l,i);return o&&(s=s.map((t=>t+"-"+o)),e&&(s=s.concat(s.map(Oe)))),s}function Fe(t){return t.replace(/left|right|bottom|top/g,(t=>_e[t]))}function Ie(t){return{top:0,right:0,bottom:0,left:0,...t}}function Le(t){return"number"==typeof t?{top:t,right:t,bottom:t,left:t}:Ie(t)}function Re(t){let{x:e,y:l,width:i,height:o}=t;return{width:i,height:o,top:l,left:e,right:e+i,bottom:l+o,x:e,y:l}}function ze(t,e,l){let i,{reference:o,floating:s}=t,n=k(e),r=Te(e),a=Ce(r),h=O(e),d="y"===n,c=o.x+o.width/2-s.width/2,u=o.y+o.height/2-s.height/2,p=o[a]/2-s[a]/2;switch(h){case"top":i={x:c,y:o.y-s.height};break;case"bottom":i={x:c,y:o.y+o.height};break;case"right":i={x:o.x+o.width,y:u};break;case"left":i={x:o.x-s.width,y:u};break;default:i={x:o.x,y:o.y}}switch(xe(e)){case"start":i[r]-=p*(l&&d?-1:1);break;case"end":i[r]+=p*(l&&d?-1:1)}return i}async function Be(t,e){void 0===e&&(e={});let{x:l,y:i,platform:o,rects:s,elements:n,strategy:r}=t,{boundary:a="clippingAncestors",rootBoundary:h="viewport",elementContext:d="floating",altBoundary:c=!1,padding:u=0}=be(e,t),p=Le(u),m=n[c?"floating"===d?"reference":"floating":d],f=Re(await o.getClippingRect({element:await(null==o.isElement?void 0:o.isElement(m))??1?m:m.contextElement||await(null==o.getDocumentElement?void 0:o.getDocumentElement(n.floating)),boundary:a,rootBoundary:h,strategy:r})),b="floating"===d?{x:l,y:i,width:s.floating.width,height:s.floating.height}:s.reference,g=await(null==o.getOffsetParent?void 0:o.getOffsetParent(n.floating)),w=await(null==o.isElement?void 0:o.isElement(g))&&await(null==o.getScale?void 0:o.getScale(g))||{x:1,y:1},C=Re(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:n,rect:b,offsetParent:g,strategy:r}):b);return{top:(f.top-C.top+p.top)/w.y,bottom:(C.bottom-f.bottom+p.bottom)/w.y,left:(f.left-C.left+p.left)/w.x,right:(C.right-f.right+p.right)/w.x}}const Ve=async(t,e,l)=>{let{placement:i="bottom",strategy:o="absolute",middleware:s=[],platform:n}=l,r=s.filter(Boolean),a=await(null==n.isRTL?void 0:n.isRTL(e)),h=await n.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:c}=ze(h,i,a),u=i,p={},m=0;for(let l=0;l<r.length;l++){let{name:s,fn:f}=r[l],{x:b,y:g,data:w,reset:C}=await f({x:d,y:c,initialPlacement:i,placement:u,strategy:o,middlewareData:p,rects:h,platform:{...n,detectOverflow:n.detectOverflow??Be},elements:{reference:t,floating:e}});d=b??d,c=g??c,p={...p,[s]:{...p[s],...w}},C&&m<=50&&(m++,"object"==typeof C&&(C.placement&&(u=C.placement),C.rects&&(h=!0===C.rects?await n.getElementRects({reference:t,floating:e,strategy:o}):C.rects),({x:d,y:c}=ze(h,u,a))),l=-1)}return{x:d,y:c,placement:u,strategy:o,middlewareData:p}},He=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var l;let{placement:i,middlewareData:o,rects:s,initialPlacement:n,platform:r,elements:a}=e,{mainAxis:h=!0,crossAxis:d=!0,fallbackPlacements:c,fallbackStrategy:u="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:m=!0,...f}=be(t,e);if(null!=(l=o.arrow)&&l.alignmentOffset)return{};let b=O(i),g=k(n),w=O(n)===n,C=await(null==r.isRTL?void 0:r.isRTL(a.floating)),x=c||(w||!m?[Fe(n)]:De(n)),v="none"!==p;!c&&v&&x.push(...Pe(n,m,p,C));let y=[n,...x],I=await r.detectOverflow(e,f),T=[],S=o.flip?.overflows||[];if(h&&T.push(I[b]),d){let t=Ee(i,s,C);T.push(I[t[0]],I[t[1]])}if(S=[...S,{placement:i,overflows:T}],!T.every((t=>t<=0))){let t=(o.flip?.index||0)+1,e=y[t];if(e&&("alignment"!==d||g===k(e)||S.every((t=>k(t.placement)!==g||t.overflows[0]>0))))return{data:{index:t,overflows:S},reset:{placement:e}};let l=S.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0]?.placement;if(!l)switch(u){case"bestFit":{let t=S.filter((t=>{if(v){let e=k(t.placement);return e===g||"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]?.[0];t&&(l=t);break}case"initialPlacement":l=n}if(i!==l)return{reset:{placement:l}}}return{}}}},Ue=new Set(["left","top"]);async function We(t,e){let{placement:l,platform:i,elements:o}=t,s=await(null==i.isRTL?void 0:i.isRTL(o.floating)),n=O(l),r=xe(l),a="y"===k(l),h=Ue.has(n)?-1:1,d=s&&a?-1:1,c=be(e,t),{mainAxis:u,crossAxis:p,alignmentAxis:m}="number"==typeof c?{mainAxis:c,crossAxis:0,alignmentAxis:null}:{mainAxis:c.mainAxis||0,crossAxis:c.crossAxis||0,alignmentAxis:c.alignmentAxis};return r&&"number"==typeof m&&(p="end"===r?-1*m:m),a?{x:p*d,y:u*h}:{x:u*h,y:p*d}}const Ge=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var l;let{x:i,y:o,placement:s,middlewareData:n}=e,r=await We(e,t);return s===n.offset?.placement&&null!=(l=n.arrow)&&l.alignmentOffset?{}:{x:i+r.x,y:o+r.y,data:{...r,placement:s}}}}},Ke=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){let{x:l,y:i,placement:o,platform:s}=e,{mainAxis:n=!0,crossAxis:r=!1,limiter:a={fn:t=>{let{x:e,y:l}=t;return{x:e,y:l}}},...h}=be(t,e),d={x:l,y:i},c=await s.detectOverflow(e,h),u=k(O(o)),p=Se(u),m=d[p],f=d[u];if(n){let t="y"===p?"bottom":"right";m=ye(m+c["y"===p?"top":"left"],m,m-c[t])}if(r){let t="y"===u?"bottom":"right";f=ye(f+c["y"===u?"top":"left"],f,f-c[t])}let b=a.fn({...e,[p]:m,[u]:f});return{...b,data:{x:b.x-l,y:b.y-i,enabled:{[p]:n,[u]:r}}}}}},qe=function(t){return void 0===t&&(t={}),{options:t,fn(e){let{x:l,y:i,placement:o,rects:s,middlewareData:n}=e,{offset:r=0,mainAxis:a=!0,crossAxis:h=!0}=be(t,e),d={x:l,y:i},c=k(o),u=Se(c),p=d[u],m=d[c],f=be(r,e),b="number"==typeof f?{mainAxis:f,crossAxis:0}:{mainAxis:0,crossAxis:0,...f};if(a){let t="y"===u?"height":"width",e=s.reference[u]-s.floating[t]+b.mainAxis,l=s.reference[u]+s.reference[t]-b.mainAxis;p<e?p=e:p>l&&(p=l)}if(h){let t="y"===u?"width":"height",e=Ue.has(O(o)),l=s.reference[c]-s.floating[t]+(e&&n.offset?.[c]||0)+(e?0:b.crossAxis),i=s.reference[c]+s.reference[t]+(e?0:n.offset?.[c]||0)-(e?b.crossAxis:0);m<l?m=l:m>i&&(m=i)}return{[u]:p,[c]:m}}}};function Je(){return typeof window<"u"}function Ye(t){return Xe(t)?(t.nodeName||"").toLowerCase():"#document"}function A(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function j(t){return((Xe(t)?t.ownerDocument:t.document)||window.document)?.documentElement}function Xe(t){return!!Je()&&(t instanceof Node||t instanceof A(t).Node)}function M(t){return!!Je()&&(t instanceof Element||t instanceof A(t).Element)}function N(t){return!!Je()&&(t instanceof HTMLElement||t instanceof A(t).HTMLElement)}function Ze(t){return!(!Je()||typeof ShadowRoot>"u")&&(t instanceof ShadowRoot||t instanceof A(t).ShadowRoot)}const Qe=new Set(["inline","contents"]);function $e(t){let{overflow:e,overflowX:l,overflowY:i,display:o}=P(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+l)&&!Qe.has(o)}const et=new Set(["table","td","th"]);function tt(t){return et.has(Ye(t))}const nt=[":popover-open",":modal"];function rt(t){return nt.some((e=>{try{return t.matches(e)}catch{return!1}}))}const it=["transform","translate","scale","rotate","perspective"],at=["transform","translate","scale","rotate","perspective","filter"],ot=["paint","layout","strict","content"];function st(t){let e=lt(),l=M(t)?P(t):t;return it.some((t=>!!l[t]&&"none"!==l[t]))||!!l.containerType&&"normal"!==l.containerType||!e&&!!l.backdropFilter&&"none"!==l.backdropFilter||!e&&!!l.filter&&"none"!==l.filter||at.some((t=>(l.willChange||"").includes(t)))||ot.some((t=>(l.contain||"").includes(t)))}function ct(t){let e=F(t);for(;N(e)&&!dt(e);){if(st(e))return e;if(rt(e))return null;e=F(e)}return null}function lt(){return!(typeof CSS>"u"||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}const ut=new Set(["html","body","#document"]);function dt(t){return ut.has(Ye(t))}function P(t){return A(t).getComputedStyle(t)}function ft(t){return M(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function F(t){if("html"===Ye(t))return t;let e=t.assignedSlot||t.parentNode||Ze(t)&&t.host||j(t);return Ze(e)?e.host:e}function pt(t){let e=F(t);return dt(e)?t.ownerDocument?t.ownerDocument.body:t.body:N(e)&&$e(e)?e:pt(e)}function mt(t,e,l){void 0===e&&(e=[]),void 0===l&&(l=!0);let i=pt(t),o=i===t.ownerDocument?.body,s=A(i);if(o){let t=ht(s);return e.concat(s,s.visualViewport||[],$e(i)?i:[],t&&l?mt(t):[])}return e.concat(i,mt(i,[],l))}function ht(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function gt(t){let e=P(t),l=parseFloat(e.width)||0,i=parseFloat(e.height)||0,o=N(t),s=o?t.offsetWidth:l,n=o?t.offsetHeight:i,r=he(l)!==s||he(i)!==n;return r&&(l=s,i=n),{width:l,height:i,$:r}}function _t(t){return M(t)?t:t.contextElement}function vt(t){let e=_t(t);if(!N(e))return D(1);let l=e.getBoundingClientRect(),{width:i,height:o,$:s}=gt(e),n=(s?he(l.width):l.width)/i,r=(s?he(l.height):l.height)/o;return(!n||!Number.isFinite(n))&&(n=1),(!r||!Number.isFinite(r))&&(r=1),{x:n,y:r}}const yt=D(0);function bt(t){let e=A(t);return lt()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:yt}function xt(t,e,l){return void 0===e&&(e=!1),!(!l||e&&l!==A(t))&&e}function St(t,e,l,i){void 0===e&&(e=!1),void 0===l&&(l=!1);let o=t.getBoundingClientRect(),s=_t(t),n=D(1);e&&(i?M(i)&&(n=vt(i)):n=vt(t));let r=xt(s,l,i)?bt(s):D(0),a=(o.left+r.x)/n.x,h=(o.top+r.y)/n.y,d=o.width/n.x,c=o.height/n.y;if(s){let t=A(s),e=i&&M(i)?A(i):i,l=t,o=ht(l);for(;o&&i&&e!==l;){let t=vt(o),e=o.getBoundingClientRect(),i=P(o),s=e.left+(o.clientLeft+parseFloat(i.paddingLeft))*t.x,n=e.top+(o.clientTop+parseFloat(i.paddingTop))*t.y;a*=t.x,h*=t.y,d*=t.x,c*=t.y,a+=s,h+=n,l=A(o),o=ht(l)}}return Re({width:d,height:c,x:a,y:h})}function Ct(t,e){let l=ft(t).scrollLeft;return e?e.left+l:St(j(t)).left+l}function wt(t,e){let l=t.getBoundingClientRect();return{x:l.left+e.scrollLeft-Ct(t,l),y:l.top+e.scrollTop}}function Tt(t){let{elements:e,rect:l,offsetParent:i,strategy:o}=t,s="fixed"===o,n=j(i),r=!!e&&rt(e.floating);if(i===n||r&&s)return l;let a={scrollLeft:0,scrollTop:0},h=D(1),d=D(0),c=N(i);if((c||!c&&!s)&&(("body"!==Ye(i)||$e(n))&&(a=ft(i)),N(i))){let t=St(i);h=vt(i),d.x=t.x+i.clientLeft,d.y=t.y+i.clientTop}let u=!n||c||s?D(0):wt(n,a);return{width:l.width*h.x,height:l.height*h.y,x:l.x*h.x-a.scrollLeft*h.x+d.x+u.x,y:l.y*h.y-a.scrollTop*h.y+d.y+u.y}}function Et(t){return Array.from(t.getClientRects())}function Dt(t){let e=j(t),l=ft(t),i=t.ownerDocument.body,o=E(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),s=E(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight),n=-l.scrollLeft+Ct(t),r=-l.scrollTop;return"rtl"===P(i).direction&&(n+=E(e.clientWidth,i.clientWidth)-o),{width:o,height:s,x:n,y:r}}function Ot(t,e){let l=A(t),i=j(t),o=l.visualViewport,s=i.clientWidth,n=i.clientHeight,r=0,a=0;if(o){s=o.width,n=o.height;let t=lt();(!t||t&&"fixed"===e)&&(r=o.offsetLeft,a=o.offsetTop)}let h=Ct(i);if(h<=0){let t=i.ownerDocument,e=t.body,l=getComputedStyle(e),o="CSS1Compat"===t.compatMode&&parseFloat(l.marginLeft)+parseFloat(l.marginRight)||0,n=Math.abs(i.clientWidth-e.clientWidth-o);n<=25&&(s-=n)}else h<=25&&(s+=h);return{width:s,height:n,x:r,y:a}}const kt=new Set(["absolute","fixed"]);function At(t,e){let l=St(t,!0,"fixed"===e),i=l.top+t.clientTop,o=l.left+t.clientLeft,s=N(t)?vt(t):D(1);return{width:t.clientWidth*s.x,height:t.clientHeight*s.y,x:o*s.x,y:i*s.y}}function jt(t,e,l){let i;if("viewport"===e)i=Ot(t,l);else if("document"===e)i=Dt(j(t));else if(M(e))i=At(e,l);else{let l=bt(t);i={x:e.x-l.x,y:e.y-l.y,width:e.width,height:e.height}}return Re(i)}function Mt(t,e){let l=F(t);return!(l===e||!M(l)||dt(l))&&("fixed"===P(l).position||Mt(l,e))}function Nt(t,e){let l=e.get(t);if(l)return l;let i=mt(t,[],!1).filter((t=>M(t)&&"body"!==Ye(t))),o=null,s="fixed"===P(t).position,n=s?F(t):t;for(;M(n)&&!dt(n);){let e=P(n),l=st(n);!l&&"fixed"===e.position&&(o=null),(s?!l&&!o:!l&&"static"===e.position&&o&&kt.has(o.position)||$e(n)&&!l&&Mt(t,n))?i=i.filter((t=>t!==n)):o=e,n=F(n)}return e.set(t,i),i}function Pt(t){let{element:e,boundary:l,rootBoundary:i,strategy:o}=t,s=[..."clippingAncestors"===l?rt(e)?[]:Nt(e,this._c):[].concat(l),i],n=s[0],r=s.reduce(((t,l)=>{let i=jt(e,l,o);return t.top=E(i.top,t.top),t.right=me(i.right,t.right),t.bottom=me(i.bottom,t.bottom),t.left=E(i.left,t.left),t}),jt(e,n,o));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}}function Ft(t){let{width:e,height:l}=gt(t);return{width:e,height:l}}function It(t,e,l){let i=N(e),o=j(e),s="fixed"===l,n=St(t,!0,s,e),r={scrollLeft:0,scrollTop:0},a=D(0);function h(){a.x=Ct(o)}if(i||!i&&!s)if(("body"!==Ye(e)||$e(o))&&(r=ft(e)),i){let t=St(e,!0,s,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else o&&h();s&&!i&&o&&h();let d=!o||i||s?D(0):wt(o,r);return{x:n.left+r.scrollLeft-a.x-d.x,y:n.top+r.scrollTop-a.y-d.y,width:n.width,height:n.height}}function Lt(t){return"static"===P(t).position}function Rt(t,e){if(!N(t)||"fixed"===P(t).position)return null;if(e)return e(t);let l=t.offsetParent;return j(t)===l&&(l=l.ownerDocument.body),l}function zt(t,e){let l=A(t);if(rt(t))return l;if(!N(t)){let e=F(t);for(;e&&!dt(e);){if(M(e)&&!Lt(e))return e;e=F(e)}return l}let i=Rt(t,e);for(;i&&tt(i)&&Lt(i);)i=Rt(i,e);return i&&dt(i)&&Lt(i)&&!st(i)?l:i||ct(t)||l}const Bt=async function(t){let e=this.getOffsetParent||zt,l=this.getDimensions,i=await l(t.floating);return{reference:It(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}};function Vt(t){return"rtl"===P(t).direction}const Ht={convertOffsetParentRelativeRectToViewportRelativeRect:Tt,getDocumentElement:j,getClippingRect:Pt,getOffsetParent:zt,getElementRects:Bt,getClientRects:Et,getDimensions:Ft,getScale:vt,isElement:M,isRTL:Vt};function Ut(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Wt(t,e){let l,i=null,o=j(t);function s(){var t;clearTimeout(l),null==(t=i)||t.disconnect(),i=null}return function n(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),s();let h=t.getBoundingClientRect(),{left:d,top:c,width:u,height:p}=h;if(r||e(),!u||!p)return;let m={rootMargin:-ge(c)+"px "+-ge(o.clientWidth-(d+u))+"px "+-ge(o.clientHeight-(c+p))+"px "+-ge(d)+"px",threshold:E(0,me(1,a))||1},f=!0;function b(e){let i=e[0].intersectionRatio;if(i!==a){if(!f)return n();i?n(!1,i):l=setTimeout((()=>{n(!1,1e-7)}),1e3)}1===i&&!Ut(h,t.getBoundingClientRect())&&n(),f=!1}try{i=new IntersectionObserver(b,{...m,root:o.ownerDocument})}catch{i=new IntersectionObserver(b,m)}i.observe(t)}(!0),s}function Gt(t,e,l,i){void 0===i&&(i={});let{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:n="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=i,h=_t(t),d=o||s?[...h?mt(h):[],...mt(e)]:[];d.forEach((t=>{o&&t.addEventListener("scroll",l,{passive:!0}),s&&t.addEventListener("resize",l)}));let c=h&&r?Wt(h,l):null,u=-1,p=null;n&&(p=new ResizeObserver((t=>{let[i]=t;i&&i.target===h&&p&&(p.unobserve(e),cancelAnimationFrame(u),u=requestAnimationFrame((()=>{var t;null==(t=p)||t.observe(e)}))),l()})),h&&!a&&p.observe(h),p.observe(e));let m,f=a?St(t):null;return a&&function e(){let i=St(t);f&&!Ut(f,i)&&l(),f=i,m=requestAnimationFrame(e)}(),l(),()=>{var t;d.forEach((t=>{o&&t.removeEventListener("scroll",l),s&&t.removeEventListener("resize",l)})),c?.(),null==(t=p)||t.disconnect(),p=null,a&&cancelAnimationFrame(m)}}const Kt=Ge,qt=Ke,Jt=He,Yt=qe,Xt=(t,e,l)=>{let i=new Map,o={platform:Ht,...l},s={...o.platform,_c:i};return Ve(t,e,{...o,platform:s})};function Zt(t,e,l,i,o){return o&&clearTimeout(o),t.addEventListener("transitionend",l,i),setTimeout((()=>{l()}),e)}function Qt(t,e={}){let{msg:i="",delay:o=150,content:s,direction:n="bottom",type:r="hover",container:a,onOpen:h,onClose:d,closed:c,onDestroy:u}=e,p=l("tooltip");if(i||s){let e=a||document.body,l=document.createElement("div");l.classList.add(p.b(),"hidden","transparent"),s?l.appendChild(s):i&&(l.textContent=i);let m,f,b,g=()=>{b&&b(),Xt(t,l,{placement:n,middleware:[Jt(),qt({limiter:Yt()}),Kt(4)]}).then((({x:t,y:e})=>{Object.assign(l.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{l.classList.add("hidden"),e.contains(l)&&e.removeChild(l),b&&b(),c&&c()},C=(i=!1)=>{f&&clearTimeout(f),m=setTimeout((()=>{if(h){let t=h(i);if(!i&&t)return}e.appendChild(l),l.removeEventListener("transitionend",w),l.classList.remove("hidden"),b=Gt(t,l,g),l.classList.remove("transparent")}),o)},x=(t=!1)=>{m&&clearTimeout(m),f=setTimeout((()=>{if(d){let e=d(t);if(!t&&e)return}Zt(l,150,w,{once:!0}),l.classList.add("transparent")}),o)},{prepare:v,show:y,hide:I,destroy:T}={hover:()=>{let e=[t,l],i=x.bind(void 0,!1),o=C.bind(void 0,!1);return{prepare:()=>{for(let t of e)t.addEventListener("mouseenter",o),t.addEventListener("mouseleave",i)},show:C,hide:x,destroy:()=>{for(let t of e)t.removeEventListener("mouseenter",o),t.removeEventListener("mouseleave",i)}}},click:()=>{let e=t=>{t.stopPropagation(),x(!1)},i=t=>{t.stopPropagation(),C(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{l.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",i)},show:C,hide:(t=!1)=>{x(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",i),document.removeEventListener("click",e)}}}}[r]();return v(),{show:y,hide:I,destroy:()=>{I(!0),u&&u(),T(),b&&b(),l.remove()}}}return null}function $t(t,e={}){let l,{axis:i="both",onMove:o=()=>{},onStart:s=()=>{},onEnd:n=()=>{},buttons:r=[0],container:a,draggingElement:h=document,exact:d=!0}=e,c={x:0,y:0},u={x:0,y:0};function p(e){if(!l)return;let o=t.getBoundingClientRect(),{x:s,y:n}=c;("x"===i||"both"===i)&&(s=e.clientX-l.x,a&&(s=Math.min(Math.max(0,s),a.scrollWidth-o.width))),("y"===i||"both"===i)&&(n=e.clientY-l.y,a&&(n=Math.min(Math.max(0,n),a.scrollHeight-o.height))),c={x:s,y:n}}function m(e){if(!r.includes(e.button)||d&&e.target!==t)return;h.addEventListener("pointerup",b),h.addEventListener("pointermove",f);let i=a?.getBoundingClientRect?.(),o=t.getBoundingClientRect(),n={x:e.clientX-(a?o.left-i.left+a.scrollLeft:o.left),y:e.clientY-(a?o.top-i.top+a.scrollTop:o.top)};u={x:e.clientX,y:e.clientY},!1!==s({position:c,startPosition:n,movePosition:{x:e.clientX-u.x,y:e.clientY-u.y}},e)&&(l=n,c=n)}function f(t){l&&(p(t),o({position:c,startPosition:l,movePosition:{x:t.clientX-u.x,y:t.clientY-u.y}},t))}function b(t){h.removeEventListener("pointermove",f),h.removeEventListener("pointerup",b),p(t),n({position:c,startPosition:l,movePosition:{x:t.clientX-u.x,y:t.clientY-u.y}},t),l=void 0,u={x:0,y:0},c={x:0,y:0}}return h.addEventListener("pointerdown",m),{stop:()=>{h.removeEventListener("pointerdown",m)}}}function en(t,e,l=0,i=!0){let o,s,{x:n,y:r,x1:a,y1:h}=t,{x:d,y:c,x1:u,y1:p}=e;return i?(o=a<d+l||n-l>u,s=h<c+l||r-l>p):(o=a<=d+l||n-l>=u,s=h<=c+l||r-l>=p),!(o||s)}function tn(t,e){let l=e.getBoundingClientRect();return{x:t.x-l.x-e.scrollLeft,y:t.y-l.y-e.scrollTop,x1:t.x-l.x-e.scrollLeft+t.width,y1:t.y-l.y-e.scrollTop+t.height,width:t.width,height:t.height}}function nn(t){let{left:e,top:l,width:i,height:o}=t,{clientWidth:s,clientHeight:n}=document.documentElement,r=!1,a=!1;return e+i>s?(e=s-i-8,r=!0):e<0&&(e=8,r=!0),l+o>n?(l=n-o-8,a=!0):l<0&&(l=8,a=!0),{left:e,top:l,leftLimited:r,topLimited:a}}function rn(t,e={}){let l=Symbol("ignoreFirstBind"),i=new Set,o=new ResizeObserver((i=>{e.ignoreFirstBind&&i.some((t=>{let e=t.target,i=e[l];return e[l]=!0,!i}))||t(i)})),s=o.observe.bind(o);o.observe=(t,e)=>{i.add(t),s(t,e)};let n=o.unobserve;o.unobserve=t=>{i.has(t)&&(i.delete(t),t[l]=void 0),n.call(o,t)};let r=o.disconnect;return o.disconnect=()=>{for(let t of i.values())t[l]=void 0;r.call(o)},o}function I(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function an(t,e){for(let l=0;l<this.scrollHandler.length;l++){let[i,o]=this.scrollHandler[l];if(i===t&&o===e){this.scrollHandler.splice(l,1);break}}}function L(){for(let[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.scrollHandler=[]}function on(t){return{y:t.scrollTop,x:t.scrollLeft}}function sn({target:t=document.body}={}){let e=document.createElement("div");Object.assign(e.style,{visibility:"hidden",width:"100px",height:"100%",overflow:"auto",position:"absolute",top:"-9999px"}),t.appendChild(e);let l=e.offsetWidth;e.style.overflow="scroll";let i=document.createElement("div");i.style.width="100%",e.appendChild(i);let o=i.offsetWidth;return e.parentNode?.removeChild(e),l-o}var cn=class{mouseY=0;mouseX=0;animationId=null;constructor(t=50,e=20,l=20){this.scrollThresholdX=t,this.scrollThresholdY=e,this.maxScrollSpeed=l}checkMinY(t){return this.mouseY<t.top+this.scrollThresholdY}checkMaxY(t){return this.mouseY>t.bottom-this.scrollThresholdY}checkMinX(t){return this.mouseX<t.left+this.scrollThresholdX}checkMaxX(t){return this.mouseX>t.right-this.scrollThresholdX}start(t,e){let l=t.getBoundingClientRect(),i=()=>{let o=!1,s=0,n=0;if(this.checkMinY(l)){let e=l.top+this.scrollThresholdY-this.mouseY,i=Math.min(e/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);t.scrollTop-=i,n=-1*i,o=!0}else if(this.checkMaxY(l)){let e=this.mouseY-(l.bottom-this.scrollThresholdY),i=Math.min(e/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);t.scrollTop+=i,n=i,o=!0}if(this.checkMinX(l)){let e=l.left+this.scrollThresholdX-this.mouseX,i=Math.min(e/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);t.scrollLeft-=i,s=-1*i,o=!0}else if(this.checkMaxX(l)){let e=this.mouseX-(l.right-this.scrollThresholdX),i=Math.min(e/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);t.scrollLeft+=i,s=i,o=!0}o&&e&&e(s,n),this.animationId=requestAnimationFrame(i)};this.animationId=requestAnimationFrame(i)}updateMousePosition(t,e){this.mouseX=t,this.mouseY=e}stop(){null!==this.animationId&&(cancelAnimationFrame(this.animationId),this.animationId=null)}};function ln(t){return t.replaceAll(/([A-Z])/g," $1").trim().split(" ").join("-").toLowerCase()}function un(t){return t.replaceAll(/-(\w)/g,((t,e)=>e.toUpperCase()))}function dn(t){let e={};if(!t.style.cssText)return e;let l=t.style.cssText.split(";").filter((t=>t.trim()));for(let t of l){let l=t.indexOf(":");-1!==l&&(e[t.slice(0,l).trim()]=t.slice(l+1).trim())}return e}function fn(t){let e={},l=t.trim().split(";");for(let t of l){let l=t.trim();if(!l)continue;let i=l.indexOf(":");if(-1===i)continue;let o=l.slice(0,Math.max(0,i)).trim(),s=l.slice(Math.max(0,i+1)).trim();e[un(o)]=s}return e}function pn(t){return Object.entries(t).map((([t,e])=>`${ln(t)}: ${e};`)).join(" ")}function mn(t){let e,l=[],i=t.replaceAll(/\/\*[\s\S]*?\*\//g,""),o=/([^{}]+)\{([^{}]*)\}/g;for(;null!==(e=o.exec(i));){let t=e[1].trim(),i=e[2].trim();if(t.startsWith("@"))continue;let o={};for(let t of i.split(";")){let e=t.indexOf(":");if(-1===e)continue;let l=t.slice(0,e).trim(),i=t.slice(e+1).trim();l&&i&&(o[l]=i)}Object.keys(o).length>0&&l.push({selector:t,styles:o})}return l}function hn(t){return!/[.#\[:]/.test(t)}function gn(t,e){let l=e?.includeDefaultTagStyle??!1,i=t.querySelectorAll("style");for(let e of Array.from(i)){let i=mn(e.textContent||"");for(let e of i){let i=e.selector.split(",").map((t=>t.trim())).filter(Boolean);for(let o of i){if(!l&&hn(o))continue;let i;try{i=t.querySelectorAll(o)}catch{continue}for(let t of Array.from(i)){let l=t;for(let[t,i]of Object.entries(e.styles))l.style.getPropertyValue(t)||l.style.setProperty(t,i)}}}}}const R=()=>Math.random().toString(36).slice(2);function _n(t,e){let l;return function(...i){l&&clearTimeout(l),l=setTimeout((()=>{t.apply(this,i)}),e)}}const vn=e.import("parchment"),yn=e.import("blots/container"),bn=e.import("blots/block"),xn=e.import("blots/block/embed");var z=class e extends yn{static tagName;static blotName=t.container;static scope=vn.Scope.BLOCK_BLOT;static allowedChildren=[bn,xn,yn];static requiredContainer;static defaultChild;static allowAttrs=new Set;static allowDataAttrs=new Set;static allowDataAttrsChangeHandler={};static create(t){let e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let l=t;this.statics.allowDataAttrs.has(t)&&(l=`data-${t}`),e?this.domNode.setAttribute(l,e):this.domNode.removeAttribute(l);let i=this.statics.allowDataAttrsChangeHandler[t];i&&x(this[i])&&this[i](e)}}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){let 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===vn.Scope.BLOCK_BLOT?(t.parent instanceof e?(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 vn.ParentBlot?t.unwrap():t.remove())}))}};const B=t=>oe(t)?t:1;function Sn(t,e){return Object.keys(t).every((l=>JSON.stringify(t[l])===JSON.stringify(e[l])))}const Cn=e.import("parchment"),wn=e.import("blots/block"),Tn=e.import("blots/block/embed"),En=e.import("blots/container");var Dn=class extends wn{replaceWith(e,l){let i=C(e)?this.scroll.create(e,l):e;if(i instanceof Cn.ParentBlot){if(i.statics.blotName===t.tableCellInner){let e=null;try{if(e=u(this,t.tableCellInner),Sn(e.formats(),i.formats()))return e}catch{}if(e)e.insertBefore(i,this),i.appendChild(this),0===e.children.length&&e.remove();else{let t=this,e=t;for(;t.parent!==this.scroll&&t.parent instanceof En;)e=t,t=t.parent;t===this.scroll&&(t=e);let l=this.offset(t),o=this.length(),s=t.isolate(l,o);s?.parent&&s.parent.insertBefore(i,s.next),i.appendChild(this)}return i}this.moveChildren(i)}return null!==this.parent&&(this.parent.insertBefore(i,this.next),this.remove()),this.attributes.copy(i),i}format(e,l){if(e!==t.tableCellInner||this.parent.statics.blotName!==e||l)super.format(e,l);else{if(this.prev&&this.prev instanceof Tn)return;try{u(this,t.tableCellInner).unwrap()}catch{console.error("unwrap TableCellInner error")}}}};const On=e.import("blots/block/embed");var kn=class extends On{delta(){let e=super.delta(),l=An(this);return l[t.tableCellInner]&&e.insert("\n",{[t.tableCellInner]:l[t.tableCellInner]}),e}length(){return An(this)[t.tableCellInner]?super.length()+1:super.length()}formatAt(e,l,i,o){if(i===t.tableCellInner)try{let e=u(this,t.tableCellInner),l=this.scroll.create(t.tableCellInner,o);e.insertBefore(l,this),l.appendChild(this),0===e.length()&&e.remove()}catch{}else this.format(i,o)}};function An(t,e={},l=!0){return null==t||("formats"in t&&"function"==typeof t.formats&&(e={...e,...t.formats()},l&&delete e["code-token"]),null==t.parent||"scroll"===t.parent.statics.blotName||t.parent.statics.scope!==t.statics.scope)?e:An(t.parent,e,l)}var V=class extends z{static blotName=t.tableBody;static tagName="tbody";static create(t){let e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(e){let l=this.parent;if(null!==l&&l.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}super.optimize(e)}convertBody(t){let e=this.descendants(H);for(let l of e)l.wrapTag=t}getRows(){return Array.from(this.domNode.querySelectorAll("tr")).map((t=>this.scroll.find(t))).filter(Boolean)}};const jn=e.import("blots/block"),Mn=e.import("blots/block/embed");var H=class extends z{static blotName=t.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan","empty-row","wrap-tag"]);static defaultChild=jn;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){let e=un(t);for(let t of this.allowStyle)if(e.startsWith(un(t)))return!0;return!1}static create(t){let{tableId:e,rowId:l,colId:i,rowspan:o,colspan:s,style:n,emptyRow:r,tag:a="td",wrapTag:h="tbody"}=t,d=super.create();d.dataset.tableId=e,d.dataset.rowId=l,d.dataset.colId=i,d.dataset.rowspan=String(B(o)),d.dataset.colspan=String(B(s)),d.dataset.tag=a,d.dataset.wrapTag=h,n&&(d.dataset.style=n);try{r&&(d.dataset.emptyRow=JSON.stringify(r))}catch{}return d}static formats(t){let{tableId:e,rowId:l,colId:i,rowspan:o,colspan:s,style:n,emptyRow:r,tag:a="td",wrapTag:h="tbody"}=t.dataset,d={tableId:String(e),rowId:String(l),colId:String(i),rowspan:Number(B(o)),colspan:Number(B(s)),tag:a,wrapTag:h};n&&(d.style=n);try{r&&(d.emptyRow=JSON.parse(r))}catch{}return d}constructor(t,e,l){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled()))}setFormatValue(e,l,i=!1){if(i){if(!this.statics.isAllowStyle(e))return}else super.setFormatValue(e,l);this.parent?.statics.blotName===t.tableCell&&this.parent.setFormatValue(e,l),this.clearCache()}clearCache(){let t=this.descendants(jn,0);for(let e of t)e.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)}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}set emptyRow(t){if(this.emptyRow.toString()!==t.toString())try{t.length>0?this.setFormatValue("empty-row",JSON.stringify(t),!1):this.setFormatValue("empty-row",null,!1)}catch{this.setFormatValue("empty-row",null,!1)}}set wrapTag(t){this.setFormatValue("wrap-tag",t)}get wrapTag(){return this.domNode.dataset.wrapTag||"tbody"}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getRowIndex(){return u(this,t.tableMain).getRowIds().indexOf(this.rowId)}getTableBody(){let t=this.parent;for(;t&&!(t instanceof V)&&t!==this.scroll;)t=t.parent;return t===this.scroll?null:t}getTableRow(){try{return u(this,t.tableRow)}catch{return null}}setStyleByString(t){let e=fn(t);for(let[t,l]of Object.entries(e))this.setFormatValue(t,l,!0)}convertTableCell(){this.parent.statics.blotName===t.tableCell&&(this.parent.convertTableCell(),this.clearCache())}formatAt(t,e,l,i){if(0===this.children.length){let t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t),e+=t.length()}super.formatAt(t,e,l,i),i?.style&&this.setStyleByString(i.style)}insertAt(t,e,l){let[i]=this.children.find(t);if(!i&&this.statics.defaultChild){let t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,l),(null==l?this.scroll.create("text",e):this.scroll.create(e,l))instanceof Mn&&i&&i.length()<=1&&i.remove()}formats(){let t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){let{colId:t,rowId:e,colspan:l,rowspan:i}=this,o=this.next;return null!==o&&o.statics.blotName===this.statics.blotName&&o.rowId===e&&o.colId===t&&o.colspan===l&&o.rowspan===i}optimize(){let e=this.parent,l=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof Mn){let t=this.prev;if(this.insertBefore(t,this.children.head),this.length()<=1){let e=this.scroll.create("block");this.insertBefore(e,t.next)}}let i=null!==e&&e.statics.blotName!==t.tableCell;if(i&&(this.wrap(t.tableCell,l),0===this.children.length)){let 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():this.domNode.dataset.style&&i&&e.domNode.style.cssText!==this.domNode.dataset.style&&this.setStyleByString(this.domNode.dataset.style)}insertBefore(e,l){if(e.statics.blotName===this.statics.blotName){let i=e,o=this.statics.formats(i.domNode),s=this.statics.formats(this.domNode);if(Sn(s,o)){let t=this.split(l?l.offset():0);return this.parent.insertBefore(i,t)}{let[e,n]=d(this,[t.tableRow,t.tableCell]),r=n;if(l){let i=l.offset(),o=this.length();if(0!==i&&i<o){let l=this.split(i).wrap(t.tableCell,s);e.insertBefore(l,n.next),r=l}}if(this.tableId!==i.tableId){let e=u(this,t.tableWrapper),l=this.offset(e),o=e.split(l);return e.parent.insertBefore(i,o)}if(this.rowId!==i.rowId){let s=e;if(l){let t=l.offset(e);s=e.split(t)}let n=this.scroll.create(t.tableRow,o),r=this.scroll.create(t.tableCell,o);return r.appendChild(i),n.appendChild(r),e.parent.insertBefore(n,s)}return e.insertBefore(i.wrap(t.tableCell,o),r)}}if(e.statics.blotName!==t.tableCol)super.insertBefore(e,l);else try{let l=u(this,t.tableBody),i=this.offset(l),o=l.split(i);l.parent.insertBefore(e,o),e.optimize({})}catch{console.warn("TableCellInner not in TableBody")}}};const Nn=e.import("parchment"),Pn=e.import("blots/scroll");var Fn=class extends Pn{enable(l=!0){let i=e.import(`formats/${t.tableCellInner}`),o=this.domNode.querySelectorAll(`.${i.className}`);for(let t of Array.from(o))t.setAttribute("contenteditable",String(!!l));let s=e.import(`formats/${t.tableCaption}`),n=this.domNode.querySelectorAll(`.${s.className}`);for(let t of Array.from(n))t.setAttribute("contenteditable",String(!!l));super.enable(l)}createBlock(e,l){let i,o={};if(e[t.tableCellInner])i=t.tableCellInner;else for(let[t,l]of Object.entries(e))null==this.query(t,Nn.Scope.BLOCK&Nn.Scope.BLOT)?o[t]=l:i=t;i===t.tableCellInner&&(o={...e},delete o[i]);let s=this.create(i||this.statics.defaultChild.blotName,i?e[i]:void 0);this.insertBefore(s,l||void 0);let n=s.length();s instanceof H&&0===n&&(n+=1);for(let[t,e]of Object.entries(o))s.formatAt(0,n,t,e);return s}},In='<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="M7 3v18m3-15L7 3L4 6m16 12l-3 3l-3-3m3 3V3"\n  />\n</svg>\n';const Ln=e.import("parchment"),Rn=e.import("blots/inline"),zn=e.import("blots/text");var Bn=class extends Dn{static blotName=t.tableCaption;static tagName="caption";static className="ql-table-caption";static allowedChildren=[Rn,zn];static create(t){let{tableId:e}=t,l=super.create();return l.dataset.tableId=e,"bottom"===t.side&&(l.style.captionSide="bottom"),l}static formats(t){let{tableId:e}=t.dataset;return{tableId:e,side:"bottom"===t.style.captionSide?"bottom":"top"}}constructor(t,e,l){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(){let t=document.createElement("i");return t.classList.add("ql-table-caption--switch"),t.innerHTML=In,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,Ln.Scope.BLOCK_BLOT)||t===this.statics.blotName)&&super.format(t,e)}checkMerge(){let t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(e){let l=this.parent;if(null!==l&&l.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}0===this.children.length?this.remove():(super.optimize(e),null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()))}},U=class e extends z{static blotName=t.tableRow;static tagName="tr";static className="ql-table-row";static allowDataAttrs=new Set(["table-id","row-id","wrap-tag"]);static allowDataAttrsChangeHandler={"wrap-tag":"wrapParentTag"};static create(t){let{tableId:e,rowId:l,wrapTag:i="tbody"}=t,o=super.create();return o.dataset.tableId=e,o.dataset.rowId=l,o.dataset.wrapTag=i,o}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}get wrapTag(){return this.domNode.dataset.wrapTag||"tbody"}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}getCellByColId(e,l){let i=u(this,t.tableMain).getColIds(),o=i.indexOf(e),s=this.children.iterator(),n=null;for(;n=s();){if(n.colId===e)return n;let t=i.indexOf(n.colId);if(t<o&&t+n.colspan>o)return n}return this[l]?.statics.blotName===t.tableRow?this[l].getCellByColId(e,l):null}insertCell(e,l){let i,o=[],s=this.children.iterator(),n=0;for(;(i=s())&&(n+=i.colspan,!(n>e));)if(1!==i.rowspan)for(let t=0;t<i.rowspan-1;t++)o[t]=(o[t]||0)+i.colspan;if(i&&n-i.colspan<e){i.getCellInner().colspan+=1,1!==i.rowspan&&(o.skipRowNum=i.rowspan-1)}else{let e=this.scroll.create(t.tableCell,l),o=this.scroll.create(t.tableCellInner,l),s=this.scroll.create("block");s.appendChild(this.scroll.create("break")),o.appendChild(s),e.appendChild(o),this.insertBefore(e,i)}return o}getCellByColumIndex(t){let e=[],l=null,i=0;if(t<0)return[l,i,e];let o=this.children.iterator();for(;l=o();){if(i+=l.colspan,1!==l.rowspan)for(let t=0;t<l.rowspan-1;t++)e[t]=(e[t]||0)+l.colspan;if(i>t)break}return[l,i,e]}removeCell(e){if(e<0)return[];let l=this.getCellByColumIndex(e),[i,o]=l,s=l[2];if(!i)return s;if(o-i.colspan<e||i.colspan>1){let[l]=i.descendants(H);if(1!==i.colspan&&e===o-i.colspan){let e=u(this,t.tableMain).getColIds();l.colId=e[e.indexOf(l.colId)+1]}1!==i.rowspan&&(s.skipRowNum=i.rowspan-1),--l.colspan}else i.remove();return s}foreachCellInner(t){let e,l=this.children.iterator(),i=0;for(;e=l();){let[l]=e.descendants(H);if(l&&t(l,i++))break}}checkMerge(){let t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}wrapParentTag(){let e={thead:t.tableHead,tbody:t.tableBody,tfoot:t.tableFoot},l=this.parent;if(null!==l&&l.statics.blotName!==e[this.wrapTag])if(Object.values(e).includes(l.statics.blotName)){let t=this.offset(this.parent),l=this.parent.split(t);l&&l.length()<=0&&l.remove();let i=this.parent.splitAfter(this);i&&i.length()<=0&&i.remove(),this.parent.replaceWith(e[this.wrapTag],this.tableId)}else this.wrap(e[this.wrapTag],this.tableId)}optimize(t){this.wrapParentTag(),this.enforceAllowedChildren(),this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}remove(){super.remove(),this.next&&this.next instanceof e&&this.next.length()<=0&&this.next.remove()}},W=class extends z{static blotName=t.tableCell;static tagName="td";static className="ql-table-cell";static allowAttrs=new Set(["rowspan","colspan"]);static allowDataAttrs=new Set(["table-id","row-id","col-id","empty-row","wrap-tag"]);static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){let e=un(t);for(let t of this.allowStyle)if(e.startsWith(un(t)))return!0;return!1}static create(t){let{tableId:e,rowId:l,colId:i,rowspan:o,colspan:s,style:n,emptyRow:r,tag:a="td",wrapTag:h="tbody"}=t,d=document.createElement(a);d.classList.add(...se(this.className)),d.dataset.tableId=e,d.dataset.rowId=l,d.dataset.colId=i,d.dataset.wrapTag=h,d.setAttribute("rowspan",String(B(o))),d.setAttribute("colspan",String(B(s))),n&&(d.style.cssText=n);try{r&&(d.dataset.emptyRow=JSON.stringify(r))}catch{}return d}static formats(t){let{tableId:e,rowId:l,colId:i,emptyRow:o,wrapTag:s="tbody"}=t.dataset,n=Number(t.getAttribute("rowspan")),r=Number(t.getAttribute("colspan")),a={tableId:e,rowId:l,colId:i,rowspan:B(n),colspan:B(r),tag:t.tagName.toLowerCase(),wrapTag:s},h=dn(t),d=Object.entries(h).filter((([,t])=>!["initial","inherit"].includes(t)));d.length>0&&(a.style=d.map((([t,e])=>`${t}: ${e}`)).join(";"));try{o&&(a.emptyRow=JSON.parse(o))}catch{}return a}isChildHeadTableCellInner(){return this.children.head?.statics.blotName===t.tableCellInner}setFormatValue(e,l){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let t=e;this.statics.allowDataAttrs.has(e)&&(t=`data-${e}`),l?this.domNode.setAttribute(t,l):this.domNode.removeAttribute(t)}else this.statics.isAllowStyle(e)&&(Object.assign(this.domNode.style,{[e]:l}),e.startsWith("border")&&this.setStyleBoder(e,l));let i=this.children.head;this.isChildHeadTableCellInner()&&this.domNode.style.cssText&&this.domNode.style.cssText!==i.domNode.dataset.style&&(i.domNode.dataset.style=this.domNode.style.cssText),this.parent?.statics.blotName===t.tableRow&&this.parent.setFormatValue(e,l)}setStyleBoder(t,e){let l=e||null;if(["left","right","top","bottom"].some((e=>t.includes(e)))||!t.startsWith("border-"))return;let i=this.getNearByCell("left").map((t=>t.descendant(H,0)[0])).filter(Boolean);for(let e of i)e.setFormatValue(t.replace("border-","border-right-"),l,!0);let o=this.getNearByCell("top").map((t=>t.descendant(H,0)[0])).filter(Boolean);for(let e of o)e.setFormatValue(t.replace("border-","border-bottom-"),l,!0)}getNearByCell(e){let l=[];try{let e=u(this,t.tableMain);l.push(...e.getColIds())}catch(e){console.error(`Cell is not in table! ${e}`)}if(0===l.length)return[];if("left"===e){let t=new Set,e=this.parent;for(let i=0;i<this.rowspan&&e instanceof U;i++){let i=e.children.iterator(),o=null;for(;o=i();){let e=l.indexOf(o.colId)+o.colspan;this.colId===l[e]&&t.add(o)}e=e.next}return Array.from(t)}if("top"===e){if(!(this.parent instanceof U&&this.parent.prev))return[];let t=new Set,e=this.getColumnIndex(),i=e+this.colspan,o=new Set(l.filter(((t,l)=>l>=e&&l<i))),s=1,n=this.parent.prev;for(;n;){let e=!1,i=n.children.iterator(),r=null,a=0;for(;r=i();)o.has(r.colId)&&r.rowspan>=s&&(t.add(r),o.delete(r.colId)),a+=r.colspan,r.rowspan>=s&&(e=!0);if(!e&&a===l.length)break;n=n.prev,s+=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"))}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}get wrapTag(){return this.domNode.dataset.wrapTag||"tbody"}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getCellInner(){return this.children.head}convertTableCell(){let e=this.statics.formats(this.domNode),l="td"===e.tag?"th":"td",i=this.children.head;this.isChildHeadTableCellInner()&&i.domNode.dataset.tag!==l&&(i.domNode.dataset.tag=l),this.replaceWith(t.tableCell,{...e,tag:l})}checkMerge(){let{colId:t,rowId:e,colspan:l,rowspan:i}=this,o=this.next;return null!==o&&o.statics.blotName===this.statics.blotName&&o.rowId===e&&o.colId===t&&o.colspan===l&&o.rowspan===i}optimize(e){let{tableId:l,rowId:i,wrapTag:o}=this;if(null!==this.parent&&this.parent.statics.blotName!==t.tableRow&&this.wrap(t.tableRow,{tableId:l,rowId:i,wrapTag:o}),this.parent.statics.blotName===t.tableRow&&this.parent.wrapTag!==o&&this.parent.setFormatValue("wrap-tag",o),this.emptyRow.length>0){let e=this.parent.parent;if(e instanceof V){let i=this.parent.next;for(let s of this.emptyRow){let n=this.scroll.create(t.tableRow,{tableId:l,rowId:s,wrapTag:o});e.insertBefore(n,i),i=n.next}}}super.optimize(e)}};const Vn=e.import("blots/block/embed");var G=class extends Vn{static blotName=t.tableCol;static tagName="col";static validWidth(t,e){let l=Number.parseFloat(String(t));return Number.isNaN(l)&&(l=n[e?"colMinWidthPre":"colMinWidthPx"]),e&&(l=Math.trunc(1e4*l)/1e4),`${l}${e?"%":"px"}`}static create(t){let{width:e,tableId:l,colId:i,full:o,align:s}=t,n=super.create();return n.setAttribute("width",this.validWidth(e,!!o)),o&&(n.dataset.full=String(o)),s&&"left"!==s&&(n.dataset.align=s),n.dataset.tableId=l,n.dataset.colId=i,n}static value(t){let{tableId:e,colId:l}=t.dataset,i=t.getAttribute("width")||String(n.colDefaultWidth),o=t.dataset.align,s=Object.hasOwn(t.dataset,"full"),r={tableId:String(e),colId:String(l),full:s,width:Number.parseFloat(i)};return o&&(r.align=o),r}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){let e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:n[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=n[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="true":this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){let t=this.next,{tableId:e,colId:l}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===l}optimize(e){let l=this.parent;if(null!=l&&l.statics.blotName!==t.tableColgroup){let e=this.statics.value(this.domNode);this.wrap(t.tableColgroup,e)}u(this,t.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(e);try{let e=u(this,t.tableColgroup),l=!0;e.children.forEach((t=>{l&&=t.full})),e.full=l}catch{}}insertAt(e,l,i){if(null==i)try{let e=u(this,t.tableWrapper),i=e.split(this.offset(e)),o=l.split("\n"),s=o.pop(),n=o.map((t=>{let e=this.scroll.create("block");return e.insertAt(0,t),e}));for(let t of n)i.parent.insertBefore(t,i);s&&i.parent.insertBefore(this.scroll.create("text",s),i)}catch{console.warn("TableCol not in TableColgroup")}else if(l===this.statics.blotName&&i.tableId!==this.tableId)try{let e=u(this,t.tableWrapper),o=e.split(this.offset(e)),s=this.scroll.create(l,i);o.parent.insertBefore(s,o)}catch{console.warn("TableCol not in TableColgroup")}else super.insertAt(e,l,i)}},K=class extends z{static blotName=t.tableMain;static tagName="table";static className="ql-table";static create(t){let e=super.create(),{tableId:l,full:i,align:o}=t;return e.dataset.tableId=l,"right"===o||"center"===o?e.dataset.align=o:e.removeAttribute("date-align"),i&&(e.dataset.full=String(i)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,l){super(t,e),this.scroll=t,this.updateAlign()}colWidthFillTable(){if(this.full)return void Object.assign(this.domNode.style,{width:null});let t=this.getCols();if(!t)return;let 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="true":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;let t=this.getCols();if(0===t.length)return;let e=Math.floor(this.domNode.getBoundingClientRect().width);for(let l of t){let t=l.width/e*100;l.full=!0,l.width=t}}cancelFull(){if(!this.full)return;let t=this.getCols();if(0===t.length)return;let e=Math.floor(this.domNode.getBoundingClientRect().width);for(let l of t)l.full=!1,l.width=Math.max(l.width/100*e,n.colMinWidthPx)}updateAlign(){let 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)}getBodys(){return Array.from(this.domNode.querySelectorAll("thead, tbody, tfoot")).map((t=>this.scroll.find(t))).filter(Boolean)}getRows(){return Array.from(this.domNode.querySelectorAll("tr")).map((t=>this.scroll.find(t))).filter(Boolean)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(G)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){let t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(e){let l=this.parent;null!==l&&l.statics.blotName!==t.tableWrapper&&this.wrap(t.tableWrapper,this.tableId),super.optimize(e),this.mergeRow()}mergeRow(){if(!this.parent)return;let t=this.getRows(),e={};for(let l of t)e[l.rowId]||(e[l.rowId]=[]),e[l.rowId].push(l);for(let t of Object.values(e))for(let e=1;e<t.length;e++){let l=t[e];l.moveChildren(t[0]),l.remove()}}checkEmptyCol(t){if(t){let t=this.getRows().length,e=this.getCols(),l=this.descendants(H);for(let i of l)if(i.colspan>1&&i.rowspan>=t){let t=e.findIndex((t=>t.colId===i.colId)),l=e[t];for(let o=t+1;o<t+i.colspan;o++)e[o].remove(),l.width+=e[o].width;i.colspan=1}}}checkEmptyRow(e){let l=this.getRows(),i=new Set(l.map((t=>t.rowId)));for(let o=l.length-1;o>=0;o--){let s=l[o];if(e){if(0===s.children.length){for(let t=1,e=o-1;e>=0;e--,t++)l[e].foreachCellInner((e=>{if(e.rowspan>t){--e.rowspan;let t=new Set(e.emptyRow);t.delete(s.rowId),e.emptyRow=Array.from(t)}}));s.remove()}}else{if(0===s.children.length&&s.prev){let t=s.prev;for(;0===t?.children.length;)t=t.prev;t.foreachCellInner((t=>{let e=new Set(t.emptyRow);e.has(s.rowId)||(t.emptyRow=[s.rowId,...e])}))}s.foreachCellInner((e=>{for(let l of e.emptyRow)i.has(l)||s.parent.insertBefore(this.scroll.create(t.tableRow,{tableId:this.tableId,rowId:l}),s.next)}))}}}sortMergeChildren(){let e={[t.tableCaption]:[],[t.tableColgroup]:[],[t.tableHead]:[],[t.tableBody]:[],[t.tableFoot]:[]};this.children.forEach((t=>{e[t.statics.blotName]&&e[t.statics.blotName].push(t)}));for(let t of Object.values(e))for(let e=1;e<t.length;e++)t[e].moveChildren(t[0]);let l=e[t.tableCaption][0],i=e[t.tableColgroup][0],o=e[t.tableHead][0],s=e[t.tableBody][0],n=e[t.tableFoot][0],r=l&&this.children.head!==l,a=i&&l&&l.next!==i,h=i&&!l&&this.children.head!==i,d=o&&!s&&!n&&this.children.tail!==o,c=s&&o&&s.prev!==o,u=s&&!n&&this.children.tail!==s,p=s&&n&&s.next!==n,m=n&&this.children.tail!==n;if(r||a||h||d||c||u||p||m){let t=this.clone();l&&t.appendChild(l),i&&t.appendChild(i),o&&t.appendChild(o),s&&t.appendChild(s),n&&t.appendChild(n),this.children.forEach((t=>t.remove())),t.moveChildren(this)}}insertRow(e){let l=this.getColIds(),i=this.descendants(U),o=new Set(l),s=0;for(let t of i){if(s===e)break;t.foreachCellInner((t=>{if(s+t.rowspan>e&&(t.rowspan+=1,o.delete(t.colId),1!==t.colspan)){let e=l.indexOf(t.colId);for(let i=0;i<t.colspan-1;i++)o.delete(l[e+i+1])}})),s+=1}let n=this.tableId,r=R(),a=this.scroll.create(t.tableRow,{tableId:n,rowId:r});for(let e of o){let l=this.scroll.create("break").wrap("block").wrap(t.tableCellInner,{tableId:n,rowId:r,colId:e,rowspan:1,colspan:1}).wrap(t.tableCell,{tableId:n,rowId:r,colId:e,rowspan:1,colspan:1});a.appendChild(l)}let h=i[e]||null;h?h.parent.insertBefore(a,h):i[i.length-1].parent.appendChild(a)}},q=class extends z{static blotName=t.tableColgroup;static tagName="colgroup";static create(t){let e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full="true":this.domNode.removeAttribute("data-full"),this.parent&&this.parent instanceof K&&(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){let e,l=this.children.iterator(),i=0;for(;(e=l())&&i!==t;)i++;return e}insertColByIndex(e,l){let i=this.parent;if(!(i instanceof K))throw TypeError("TableColgroupFormat should be child of TableFormat");let o=this.findCol(e),s=this.scroll.create(t.tableCol,l);if(i.full){let t,e=this.children.iterator();for(;t=e();)if(t.width-s.width>=n.colMinWidthPre){t.width-=s.width;break}}this.insertBefore(s,o)}removeColByIndex(t){let e=this.parent;if(!(e instanceof K))throw TypeError("TableColgroupFormat should be child of TableMainFormat");let l=this.findCol(t);l&&(e.full&&(l.next?l.next.width+=l.width:l.prev&&(l.prev.width+=l.width)),l.remove(),e.colWidthFillTable())}checkMerge(){let t=this.next,e=this.parent;return e instanceof K&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(e){let l=this.parent,{tableId:i,full:o,align:s}=this;null!=l&&l.statics.blotName!==t.tableMain&&this.wrap(t.tableMain,{tableId:i,full:o,align:s}),u(this,t.tableMain).align=s,super.optimize(e)}},Hn=class extends V{static blotName=t.tableFoot;static tagName="tfoot"},Un=class extends V{static blotName=t.tableHead;static tagName="thead"};const Wn=e.import("parchment");var J=class extends z{static blotName=t.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){let 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(t,l,i){super(t,l),this.scroll=t,this.scroll.emitter.on(e.events.TEXT_CHANGE,this.insertLineAround)}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){0!==this.length()?super.optimize(t):this.remove()}deleteAt(t,e){super.deleteAt(t,e);let l=this.descendants(V),i=this.descendants(q);0===l.length&&0===i.length&&this.remove()}remove(){super.remove(),this.scroll.emitter.off(e.events.TEXT_CHANGE,this.insertLineAround)}isBlockLine(t){return t instanceof Wn.BlockBlot||new Set(["list-container","code-block-container"]).has(t.statics.blotName)}insertLineAround=()=>{(!this.prev||!this.isBlockLine(this.prev))&&this.parent.insertBefore(this.scroll.create("block"),this),(!this.next||!this.isBlockLine(this.next))&&this.parent.insertBefore(this.scroll.create("block"),this.next)}};function Y(e){let l=new Set([t.tableHead,t.tableBody,t.tableFoot]),i=e.children.iterator(),o=null,s={};for(;o=i();)l.has(o.statics.blotName)&&(s[o.statics.blotName]=o);if(Object.values(s).length<=0)return{rect:null,head:null,body:null,foot:null};let n=Object.values(s).reduce(((t,e)=>{let l=e.domNode.getBoundingClientRect();return{...t,top:Math.min(t.top,l.top),bottom:Math.max(t.bottom,l.bottom),left:Math.min(t.left,l.left),right:Math.max(t.right,l.right)}}),{top:1/0,bottom:0,left:1/0,right:0,width:0,height:0,x:1/0,y:1/0});return n.width=n.right-n.left,n.height=n.bottom-n.top,n.x=n.left,n.y=n.top,{rect:n,head:s[t.tableHead]||null,body:s[t.tableBody]||null,foot:s[t.tableFoot]||null}}var Gn=class{table;tableSelectMouseDownHandler;constructor(t,e){this.tableModule=t,this.quill=e,this.tableSelectMouseDownHandler=this.tableSelectHandler.bind(this),this.quill.root.addEventListener("mousedown",this.tableSelectMouseDownHandler)}tableSelectHandler(t){let e=t.composedPath();if(0!==t.button||!e||e.length<=0)return;let l=e.find((t=>"TABLE"===t.tagName?.toUpperCase()));this.setSelectionTable(l)}setSelectionTable(t){this.table!==t&&(this.hide(),this.table=t,this.table&&this.show(),this.update())}hide(){}show(){}update(){}destroy(){this.quill.root.removeEventListener("mousedown",this.tableSelectMouseDownHandler),this.hide(),this.table=void 0}},Kn=class extends Gn{static moduleName="table-align";tableBlot;tableWrapperBlot;alignBox;cleanup;bem=l("align");resizeObserver;constructor(t,l,i){super(t,l),this.tableModule=t,this.quill=l,this.alignBox=this.buildTools(),this.hide(),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};buildTools(){let t=this.tableModule.addContainer(this.bem.b()),l=e.import("ui/icons"),i={left:l.align[""],center:l.align.center,right:l.align.right};for(let[e,l]of Object.entries(i)){let i=document.createElement("span");i.dataset.align=e,i.classList.add(this.bem.be("item")),i.innerHTML=`<i class="icon">${l}</i>`,i.addEventListener("click",this.handleAlignItemClick.bind(this)),t.appendChild(i)}return t}handleAlignItemClick(t){let e=t.currentTarget;if(!e)return;let l=e.dataset.align;l&&this.tableBlot&&this.setTableAlign(this.tableBlot,l)}setTableAlign(t,e){let l=t.getCols();for(let t of l)t.align=e}show(){!this.table||!this.alignBox||(this.tableBlot=e.find(this.table),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox.classList.remove(this.bem.is("hidden")),this.resizeObserver=rn((()=>this.update()),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.cleanup&&this.cleanup(),this.cleanup=Gt(this.tableWrapperBlot.domNode,this.alignBox,(()=>this.update())))}hide(){this.tableBlot=void 0,this.tableWrapperBlot=void 0,this.alignBox&&this.alignBox.classList.add(this.bem.is("hidden")),this.cleanup&&=void this.cleanup()}update(){if(this.alignBox&&this.tableBlot&&this.tableWrapperBlot){if(!this.table||this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth)return void this.hide();Xt(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[Jt(),qt({limiter:Yt()}),Kt(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))}}destroy(){super.destroy(),this.hide(),this.resizeObserver&&=void this.resizeObserver.disconnect(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&=(this.alignBox.remove(),null)}};const qn=e.import("delta");function Jn(t,e,l){let{rows:i,cols:o}=Yn(e),{rows:s,cols:n,cells:r}=Xn(l);i===s&&o===n?Qn(e,r,t):tr(t,e,r)}function Yn(t){return 0===t.length?{rows:0,cols:0}:Zn($n(t))}function Xn(e){let l=new Map;for(let i of e){let e=i.attributes;if(!e)continue;let o=e[t.tableCellInner];if(!o)continue;let s=`${o.rowId}-${o.colId}`;if(!l.has(s)){let t={rowId:o.rowId,colId:o.colId,rowspan:o.rowspan||1,colspan:o.colspan||1,deltaOps:[]};o.emptyRow&&o.emptyRow.length>0&&(t.emptyRow=o.emptyRow),l.set(s,t)}let n=l.get(s),{[t.tableCellInner]:r,...a}=e;n.deltaOps.push({insert:i.insert,attributes:{...a}})}let i=Array.from(l.values());return{...Zn($n(i)),cells:i}}function Zn(t){let e=1/0,l=-1/0,i=1/0,o=-1/0;for(let s of t){let{cell:t,rowIndex:n,colIndex:r}=s,a=t.colspan||1,h=t.rowspan||1;e=Math.min(e,n),l=Math.max(l,n+h-1),i=Math.min(i,r),o=Math.max(o,r+a-1)}return{rows:Math.max(l-e+1,0),cols:Math.max(o-i+1,0)}}function Qn(t,e,l){let i=$n(t),o=$n(e),s=new Map;for(let t of o)s.set(`${t.rowIndex}-${t.colIndex}`,t.cell);let n=[],r=new Set;for(let t of i){let e=t.cell;if(!e.domNode.isConnected||r.has(e))continue;let i=s.get(`${t.rowIndex}-${t.colIndex}`);if(i){let t=nr(l,e,i.deltaOps,{rowspan:i.rowspan,colspan:i.colspan,emptyRow:i.emptyRow});n.push(t),r.add(e)}}rr(l,n)}function $n(t){let e=[],l=er(t),i=-1,o=new Map;for(let[t,s]of l.entries()){o.has(t)||(i+=1,o.set(t,i));let l=0;for(let n of s){e.push({cell:n,rowIndex:o.get(t),colIndex:l}),l+=n.colspan||1;let s=n.emptyRow||[];for(let t of s)o.has(t)||(i+=1,o.set(t,i))}}return e}function er(t){let e=new Map;for(let l of t)e.has(l.rowId)||e.set(l.rowId,[]),e.get(l.rowId).push(l);return e}function tr(t,e,l){let i=er(l),o=Array.from(i.values()),s=Yn(e).cols,n=[];for(let l=0;l<e.length;l++){let i=e[l],r=l%s,a=o[Math.floor(l/s)%o.length],h=nr(t,i,a[r%a.length].deltaOps);n.push(h)}rr(t,n)}function nr(t,e,l,i){let{rowspan:o=1,colspan:s=1,emptyRow:n}=i||{};i&&(e.rowspan=o,e.colspan=s,n&&n.length>0&&(e.emptyRow=n));let r=e.formats(),a=new qn;for(let t of l)a.insert(t.insert,{...t.attributes,...r});return{offset:e.offset(t.quill.scroll),length:e.length(),insertDelta:a,cell:e,rowspan:o,colspan:s,emptyRow:n}}function rr(t,l){if(0===l.length)return;l.sort(((t,e)=>t.offset-e.offset));let i=new qn;for(let t=0;t<l.length;t++){let e=l[t],o=e.offset;if(0!==t){let i=l[t-1];o=e.offset-i.offset-i.length}i=i.retain(o).concat(e.insertDelta).delete(e.length)}for(let e of l)ir(t,e);t.quill.updateContents(i,e.sources.USER)}function ir(e,l){let{cell:i,rowspan:o=1,colspan:s=1}=l;if(1===o&&1===s)return;let n=u(i,t.tableMain);if(!n)return;let r=i.getTableRow();if(!r)return;let a=n.descendants(H),h=n.getRows(),d=h.indexOf(r),c=i.getColumnIndex(),p=[];for(let t of a){if(t===i)continue;let e=t.getTableRow();if(!e)continue;let l=h.indexOf(e),n=t.getColumnIndex();l>=d&&l<d+o&&(n>=c&&n<c+s)&&p.push(t)}let m=e.talbeModule.options.autoMergeCell;for(let t of p)if(t.domNode.isConnected){let e=t.getTableRow();t.remove(),!m&&e&&e.length()<=0&&e.remove()}}const ar=e.import("delta"),or=e.import("modules/clipboard");function sr(t){let e=t.trim().toLowerCase();return e?e.endsWith("%")?"percent":Number.isNaN(Number.parseFloat(e))?"unknown":"pixel":"unknown"}function cr(t){return t.getAttribute("width")||t.style.width||""}function lr(t,e){return e?100/t:n.colDefaultWidth}function ur(t){let e=[];for(let l of Array.from(t.querySelectorAll("col"))){let t=Number.parseInt(l.getAttribute("span")||"1",10);(Number.isNaN(t)||t<=0)&&(t=1);let i=cr(l),o=Number.parseFloat(i),s={unit:sr(i),width:Number.isNaN(o)?null:o};for(let l=0;l<t;l++)e.push(s)}return e}function dr(t){let e=0,l=0;for(let i of t)"percent"===i.unit&&null!=i.width?e+=i.width:"pixel"===i.unit&&null!=i.width&&(l+=i.width);return l<=0||e>=100?null:l/(1-e/100)}function fr(t,e){if(!t)return dr(e);let l=cr(t),i=Number.parseFloat(l);return l&&"pixel"===sr(l)&&!Number.isNaN(i)?i:t.offsetWidth>0?t.offsetWidth:dr(e)}function pr(t,e,l,i,o){let s=lr(o,l);return null==t||"unknown"===e?s:l?"percent"===e?t:null==i?s:t/i*100:"pixel"===e?t:null==i?s:t/100*i}var mr=class extends or{tableId=R();rowId=R();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(t,e){super(t,e),this.quill=t,this.addMatcher("table",this.matchTable.bind(this)),this.addMatcher("thead",this.matchThead.bind(this)),this.addMatcher("tbody",this.matchTbody.bind(this)),this.addMatcher("tfoot",this.matchTfoot.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))}normalizeHTML(t){super.normalizeHTML(t);let e=this.quill.getModule(i.moduleName)?.options??{};!1!==e.pasteStyleSheet&&gn(t,{includeDefaultTagStyle:e.pasteDefaultTagStyle})}getStyleBackgroundColor(e,l){let i=e.style.backgroundColor;if(i)for(let e of l.ops)if(e.attributes?.[t.tableCellInner]){let{style:l,...o}=e.attributes[t.tableCellInner],s=fn(l||"");s.backgroundColor||(s.backgroundColor=i,e.attributes[t.tableCellInner]={...o,style:pn(s)})}}getTargetFull(){return!!this.quill.getModule(i.moduleName)?.options.full}matchTable(e,l){if(0===l.ops.length)return l;let i=[],o=[],s=-1;for(let e=0;e<l.ops.length;e++){let{attributes:n,insert:r}=l.ops[e];if(!(ie(r)||n&&(n[t.tableCellInner]||n[t.tableCaption]))){l.ops.splice(e,1),--e;continue}let{table:a,[t.tableCell]:h,...d}=n||{},c=ie(r)&&r[t.tableCol];c?o.push({insert:r}):i.push({attributes:d,insert:r}),!d?.[t.tableCellInner]&&!d?.[t.tableCaption]&&!c&&C(r)&&r.trim().length>0&&(s=e)}let n=o.find((e=>e?.insert?.[t.tableCol])),r=n?n.insert[t.tableCol].full:this.getTargetFull(),a=lr(this.colIds.length,r),h=Array(this.colIds.length).fill(null).reduce(((e,l,i)=>(o[i]?e.push(o[i]):e.push({insert:{[t.tableCol]:{tableId:this.tableId,colId:this.colIds[i],width:a,full:r}}}),e)),[]);i.splice(s+1,0,...h);let d=new ar(i);return this.getStyleBackgroundColor(e,d),this.tableId=R(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,d}matchTbody(e,l){this.getStyleBackgroundColor(e,l);let i=[];for(let e=l.ops.length-1;e>=0;e--){let o=l.ops[e];if(o.attributes?.[t.tableCellInner]){if(o.attributes){let e=o.attributes[t.tableCellInner];1===e.rowspan?i=[]:i.length>0&&(e.emptyRow||=[],i.length>e.emptyRow.length&&e.emptyRow.push(...i.slice(e.emptyRow.length-i.length)))}}else{i=[];let t=o.insert?C(o.insert)?o.insert.split("\n").length-1:1:0;for(let e=0;e<t;e++)i.push(R())}}return this.rowspanCount=[],l}matchThead(e,l){let i=this.matchTbody(e,l);for(let e of i.ops)if(e.attributes?.[t.tableCellInner]){e.attributes[t.tableCellInner].wrapTag="thead"}return i}matchTfoot(e,l){let i=this.matchTbody(e,l);for(let e of i.ops)if(e.attributes?.[t.tableCellInner]){e.attributes[t.tableCellInner].wrapTag="tfoot"}return i}matchColgroup(e,l){let i=[];for(let e of l.ops)e&&ie(e.insert)&&e.insert[t.tableCol]&&i.push(e);if(i.length>0){let l=e,o=ur(l),s=o.some((t=>"percent"===t.unit)),n=o.some((t=>"pixel"===t.unit)),r=s&&n?this.getTargetFull():!!s||!n&&this.getTargetFull(),a=fr(l.closest("table"),o);for(let[e,l]of i.entries()){let s=o[e];l.insert[t.tableCol].full=r,l.insert[t.tableCol].width=pr(s?.width??null,s?.unit??"unknown",r,a,i.length)}}return new ar(i)}matchCol(e,l){let i=Number(e.getAttribute("span")||1);Number.isNaN(i)&&(i=1);let o=new ar;for(let l=0;l<i;l++)this.colIds[this.colCount]=R(),o.insert({[t.tableCol]:Object.assign(G.value(e),{tableId:this.tableId,colId:this.colIds[this.colCount]})}),this.colCount+=1;return o}matchTr(t,e){this.rowId=R(),this.cellCount=0;for(let[t,e]of this.rowspanCount.entries())e.rowspan>0&&--e.rowspan,e.rowspan<=0&&(this.rowspanCount[t]={rowspan:0,colspan:0});return this.getStyleBackgroundColor(t,e),0===e.ops.length?new ar([{insert:"\n"}]):e}matchTd(e,l){let i=e,o=W.formats(i);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let t=this.cellCount;t>=0;t--)this.colIds[t]||(this.colIds[t]=R()),this.rowspanCount[t]||(this.rowspanCount[t]={rowspan:0,colspan:0});for(let t=this.cellCount;t<this.rowspanCount.length;t++){let{rowspan:e,colspan:l}=this.rowspanCount[t];if(0===e)break;this.cellCount+=l}o.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:o.rowspan,colspan:o.colspan});let s=this.colIds[this.cellCount];this.cellCount+=o.colspan;let n=Object.assign(o,{tableId:this.tableId,rowId:this.rowId,colId:s});"none"===i.style.border&&(n.style=n.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));let r=[];for(let e of l.ops){let{attributes:l={},...i}=e,{[t.tableCell]:o,...s}=l;r.push({...i,attributes:{...s,[t.tableCellInner]:n}})}return(r.length<=0||!C(r[r.length-1].insert)||!r[r.length-1].insert.endsWith("\n"))&&r.push({insert:"\n",attributes:{[t.tableCellInner]:n}}),new ar(r)}matchTdAttributor(e,l){if("td"===e.tagName.toLocaleLowerCase()){let e=[];for(let i of l.ops){let{attributes:l,...o}=i,s=l?.[t.tableCellInner];if(l&&s?.style){let{background:t,...i}=l,n=document.createElement("div");n.style.background=t;let r=document.createElement("div");if(r.style.cssText=s.style,n.style.background===r.style.backgroundColor){e.push({...o,attributes:{...i}});continue}}e.push(i)}return new ar(e)}return l}convert({html:e,text:l},i={}){let o=super.convert({html:e,text:l},i);if(i[t.tableCellInner])for(let e of o.ops)ie(e.insert)&&e.insert[t.tableCol]?e.insert="":(e.attributes||={},e.attributes[t.tableCellInner]=i[t.tableCellInner]);return o}matchCaption(e,l){for(let e of l.ops){let{attributes:l}=e;l?.[t.tableCaption]&&(l[t.tableCaption].tableId=this.tableId,e.attributes=l)}return l}},hr='<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',gr='<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',_r='<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',vr='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n  \x3c!-- Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE --\x3e\n  <path\n    fill="currentColor"\n    d="M11 21V9H3V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm2-2h6v-4h-6zm0-6h6V9h-6zM5 7h14V5H5zM3 22v-2h2.55q-1.2-.575-1.937-1.7t-.738-2.55q0-1.975 1.388-3.363T7.625 11v2q-1.125 0-1.937.8t-.813 1.95q0 .975.6 1.725t1.525.95V16h2v6z"\n  />\n</svg>\n',yr='<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',br='<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',xr='<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',Sr='<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',Cr='<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',wr='<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',Tr='<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',Er='<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',Dr='<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',Or='<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',kr='<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',Ar='<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';const jr="color-selector";async function Mr(t,e,l=!1){let i=t.getTextByCell(e),o=t.getHTMLByCell(e,l),s=new ClipboardItem({"text/plain":new Blob([i],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});await navigator.clipboard.write([s])}const X={Break:{name:"break"},CopyCell:{name:"CopyCell",tip:"Copy cell",icon:yr,handle(t,e){Mr.call(this,t,e,!1)}},CutCell:{name:"CutCell",tip:"Cut cell",icon:br,handle(t,e){Mr.call(this,t,e,!0)}},InsertTop:{name:"InsertTop",icon:wr,tip:"Insert row above",handle(t,e){t.appendRow(e,!1)}},InsertRight:{name:"InsertRight",icon:Cr,tip:"Insert column right",handle(t,e){t.appendCol(e,!0)}},InsertBottom:{name:"InsertBottom",icon:xr,tip:"Insert row below",handle(t,e){t.appendRow(e,!0)}},InsertLeft:{name:"InsertLeft",icon:Sr,tip:"Insert column Left",handle(t,e){t.appendCol(e,!1)}},MergeCell:{name:"MergeCell",icon:Tr,tip:"Merge Cell",handle(t,e){t.mergeCells(e)}},SplitCell:{name:"SplitCell",icon:kr,tip:"Split Cell",handle(t,e){t.splitCell(e)}},DeleteRow:{name:"DeleteRow",icon:Dr,tip:"Delete Row",handle(t,e){t.removeRow(e)}},DeleteColumn:{name:"DeleteColumn",icon:Er,tip:"Delete Column",handle(t,e){t.removeCol(e)}},DeleteTable:{name:"DeleteTable",icon:Or,tip:"Delete table",handle(t,e){t.deleteTable(e)}},BackgroundColor:{name:"BackgroundColor",icon:gr,isColorChoose:!0,tip:"Set background color",key:"background-color",handle(t,e,l){t.setCellAttrs(e,"background-color",l,!0)}},BorderColor:{name:"BorderColor",icon:_r,isColorChoose:!0,tip:"Set border color",key:"border-color",handle(t,e,l){t.setCellAttrs(e,"border-color",l,!0)}},SwitchWidth:{name:"SwitchWidth",icon:hr,tip:"Switch table width",handle(){if(!this.table)return;let t=e.find(this.table);t&&(t.full?t.cancelFull():t.setFull())}},InsertCaption:{name:"InsertCaption",icon:Ar,tip:"Insert table caption",handle(){if(!this.table)return;let l=e.find(this.table);if(!l)return;let i=this.quill.scroll.create("text","Table Caption").wrap(t.tableCaption,{tableId:l.tableId});l.insertBefore(i,l.children.head)}},ToggleTdBetweenTh:{name:"ToggleTdBetweenTh",icon:vr,tip:"Toggle td between th",handle(t,e){for(let t of e)t.convertTableCell()}},ConvertTothead:{name:"ConvertTothead",icon:vr,tip:"Convert to thead",handle(t,l){if(!this.table)return;let i=e.find(this.table);i&&t.convertTableBodyByCells(i,l,"thead")}},ConvertTotfoot:{name:"ConvertTotfoot",icon:vr,tip:"Convert to tfoot",handle(t,l){if(!this.table)return;let i=e.find(this.table);i&&t.convertTableBodyByCells(i,l,"tfoot")}}},Nr=l("color-map"),Z={selectWrapper:Nr.b(),used:Nr.bm("used"),item:Nr.be("item"),btn:Nr.be("btn"),map:Nr.be("content"),mapRow:Nr.be("content-row")};var Pr=class extends Gn{static moduleName="table-menu";usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;tooltipItem=[];activeTooltip=null;bem=l("menu");colorItemClass=`color-${R()}`;colorChooseTooltipOption={direction:"top"};constructor(t,l,i){super(t,l),this.tableModule=t,this.quill=l,this.options=this.resolveOptions(i);try{let t=localStorage.getItem(this.options.localstorageKey)||"[]",e=JSON.parse(t);S(e)||(e=[]),e.slice(-10).map((t=>this.usedColors.add(t)))}catch{}this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart)}updateUsedColor=_n((t=>{if(!t)return;if(this.usedColors.add(t),this.usedColors.size>10){let 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)));let e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Z.used}`));for(let l of e){let e=document.createElement("div");e.classList.add(Z.item),e.style.backgroundColor=String(t),Array.from(l.querySelectorAll(`.${Z.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&l.appendChild(e);let i=Array.from(l.querySelectorAll(`.${Z.item}`)).slice(0,-10);for(let t of i)t.remove()}}),1e3);hideWhenSelectionDragStart=()=>{this.hide()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&this.isMenuDisplay&&this.update()};resolveOptions(t){return Object.assign({tipText:!0,tools:[X.InsertTop,X.InsertRight,X.InsertBottom,X.InsertLeft,X.Break,X.MergeCell,X.SplitCell,X.Break,X.DeleteRow,X.DeleteColumn,X.DeleteTable,X.Break,X.BackgroundColor,X.BorderColor],localstorageKey:"__table-bg-used-color",defaultColorMap:a},t)}buildTools(){let t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(let e of this.options.tools){let{name:l,icon:i,handle:o,isColorChoose:s,key:n,tip:r=""}=e,a=document.createElement("span");if(a.classList.add(this.bem.be("item")),"break"===l)a.classList.add(this.bem.is("break"));else{let t=document.createElement("i");if(t.classList.add("icon"),x(i)?t.appendChild(i(this.tableModule)):t.innerHTML=i,a.appendChild(t),s&&n){let t=this.createColorChoose(a,{name:l,icon:i,handle:o,isColorChoose:s,key:n,tip:r});this.tooltipItem.push(t),a.classList.add(jr)}else x(o)&&a.addEventListener("click",(t=>{this.quill.focus(),o.call(this,this.tableModule,this.getSelectedTds(),t)}),!1);let e=this.tableModule.options.texts[l]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose(t,{handle:e,key:l}){let o=document.createElement("div");if(o.classList.add(Z.selectWrapper),this.options.defaultColorMap.length>0){let t=document.createElement("div");t.classList.add(Z.map);for(let e of this.options.defaultColorMap){let l=document.createElement("div");l.classList.add(Z.mapRow);for(let t of e){let e=document.createElement("div");e.classList.add(Z.item),e.style.backgroundColor=t,l.appendChild(e)}t.appendChild(l)}o.appendChild(t)}let s=document.createElement("div");s.classList.add(Z.mapRow),Object.assign(s.style,{marginTop:"4px"});let n=document.createElement("div");n.classList.add(Z.btn,"transparent"),n.textContent=this.tableModule.options.texts.transparent,n.addEventListener("click",(()=>{e.call(this,this.tableModule,this.getSelectedTds(),"transparent")}));let r=document.createElement("div");r.classList.add(Z.btn,"clear"),r.textContent=this.tableModule.options.texts.clear,r.addEventListener("click",(()=>{e.call(this,this.tableModule,this.getSelectedTds(),null)}));let a=document.createElement("div");a.classList.add(Z.btn,"custom"),a.textContent=this.tableModule.options.texts.custom;let h=le({onChange:t=>{e.call(this,this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:d,destroy:c}=Qt(a,{direction:"right",type:"click",content:h,container:a});s.appendChild(n),s.appendChild(r),s.appendChild(a),o.appendChild(s);let u=document.createElement("div");u.classList.add(Z.used,this.colorItemClass);for(let t of this.usedColors){let e=document.createElement("div");e.classList.add(Z.item),e.style.backgroundColor=t,u.appendChild(e)}o.appendChild(u),o.addEventListener("click",(t=>{t.stopPropagation(),d();let e=t.target,i=e.style.backgroundColor,o=this.getSelectedTds();if(e&&i&&o.length>0){if(this.tableModule.setCellAttrs(o,l,i,!0),!e.closest(`.${Z.item}`))return;this.updateUsedColor(i)}}));let p=Qt(t,{...this.colorChooseTooltipOption,type:"click",content:o,container:this.quill.container,onOpen:()=>{let t=this.tableModule.getModule(i.tableSelectionName);return this.isMenuDisplay&&t&&t.hideDisplay(),this.setActiveTooltip(p),!1},onClose:()=>{let t=this.tableModule.getModule(i.tableSelectionName);return this.isMenuDisplay&&t&&(t.updateWithSelectedTds(),t.showDisplay()),o.contains(h)&&d(),this.activeTooltip===p&&(this.activeTooltip=null),!1},onDestroy:()=>{c(),this.activeTooltip===p&&(this.activeTooltip=null)}});return p.isColorPick=!0,p}setActiveTooltip(t){this.activeTooltip&&this.activeTooltip!==t&&this.activeTooltip.hide(!0),this.activeTooltip=t}getSelectedTds(){return this.tableModule.getModule(i.tableSelectionName)?.selectedTds||[]}createTipText(t,e){let l=Qt(t,{msg:e,container:this.quill.container});l&&this.tooltipItem.push(l)}show(){this.table&&(this.menu&&this.hide(),this.menu=this.buildTools())}update(){this.table&&!this.quill.root.contains(this.table)&&this.setSelectionTable(void 0)}hide(){this.menu&&=(this.menu.remove(),null);for(let t of this.tooltipItem)t.hide(!0);this.isMenuDisplay=!1}destroy(){super.destroy(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart),this.activeTooltip=null;for(let t of this.tooltipItem)t.destroy();this.tooltipItem=[],this.hide()}},Fr=class extends Pr{static moduleName="table-menu-contextmenu";scrollHandler=[];constructor(t,e,l){super(t,e,l),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}tableSelectioChange=t=>{t.selectedTds.length<=0&&this.hide()};listenContextmenu=t=>{let e=t.composedPath();if(!e||e.length<=0)return;let l=e.find((t=>"TABLE"===t.tagName?.toUpperCase()&&t.classList.contains("ql-table"))),o=this.tableModule.getModule(i.tableSelectionName);if(l&&o?.selectedTds?.length){t.preventDefault(),this.menu||=this.buildTools(),this.isMenuDisplay=!0,this.update({x:t.clientX,y:t.clientY});let e=()=>{this.hide(),L.call(this)};I.call(this,this.quill.root,e),document.addEventListener("click",e,{once:!0})}else this.hide()};buildTools(){let t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));let e=t.getElementsByClassName(jr);for(let t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return this.quill.container.appendChild(t),t}createTipText(t,e){let l=document.createElement("span");l.textContent=e,t.appendChild(l)}show(){}update(t){super.update();let e=this.tableModule.getModule(i.tableSelectionName);if(!this.table||!this.isMenuDisplay||!this.menu)return void this.hide();if(!t||!e?.isDisplaySelection)return;let l=this.quill.container.getBoundingClientRect();Object.assign(this.menu.style,{left:t.x-l.x+"px",top:t.y-l.y+"px"});let o=this.menu.getBoundingClientRect(),{left:s,top:n}=nn(o),r=o.left-s,a=o.top-n;Object.assign(this.menu.style,{left:t.x-l.x-r+"px",top:t.y-l.y-a+"px"})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy(),this.quill.off(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.off(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}},Ir=class extends Pr{static moduleName="table-menu-select";constructor(t,e,l){super(t,e,l),this.tableModule=t,this.quill=e,this.quill.on(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.on(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectionDisplayChange)}tableSelectionDragStart=()=>{this.hide()};tableSelectionDragEnd=t=>{t.selectedTds.length>0&&this.show()};tableSelectioChange=(t,e)=>{e.length<=0&&this.hide()};tableSelectionDisplayChange=t=>{t.dragging||this.update()};buildTools(){let t=super.buildTools();return this.quill.container.appendChild(t),t}show(){super.show(),this.update()}update(){if(super.update(),!this.menu&&this.table)return void this.show();let t=this.getSelectedTds();if(!this.menu||!this.table||0===t.length)return void((this.menu||!this.table)&&(this.isMenuDisplay=!1,this.menu?.classList.add(this.bem.is("hidden")),this.hide()));this.isMenuDisplay=!0,this.menu.classList.remove(this.bem.is("hidden"));let e=this.tableModule.getModule(i.tableSelectionName);e?.isDisplaySelection&&Xt(e.cellSelect,this.menu,{placement:"bottom",middleware:[Jt(),qt({limiter:Yt()}),Kt(20)]}).then((({x:t,y:e})=>{this.menu&&Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})}))}destroy(){super.destroy(),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.off(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd),this.quill.off(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.off(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectionDisplayChange)}};const Lr=t=>!t.full&&"right"===t.align;function Rr(t,e){if(e<0||e>=t.length)return null;let l=t[0].domNode.getBoundingClientRect().left;for(let i=0;i<e;i++){l+=t[i].domNode.getBoundingClientRect().width}let i=t[e].domNode.getBoundingClientRect().width;return{left:l,right:l+i,width:i}}function zr(t,e,l){if(t){let t=e.getCols().map((t=>t.colId)),i=new Set,o=new Map(t.map((t=>[t,0]))),s=new Set;for(let e of l){i.add(e.colId);let l=t.indexOf(e.colId);if(-1!==l){for(let i=l;i<l+e.colspan&&i<t.length;i++){s.add(i);let l=t[i];o.set(l,(o.get(l)||0)+e.rowspan)}s.add(Math.min(l+e.colspan,t.length))}}let n=e.getRows()?.length||0;for(let[t,e]of o.entries())e>=n&&i.delete(t);return{cellIndex:s,isSpan:i.size<=0}}{let t=e.getRows().map((t=>t.rowId)),i=new Set,o=new Map(t.map((t=>[t,0]))),s=new Set;for(let e of l){i.add(e.rowId);let l=t.indexOf(e.rowId);if(-1!==l){for(let i=l;i<l+e.rowspan&&i<t.length;i++){s.add(i);let l=t[i];o.set(l,(o.get(l)||0)+e.colspan)}s.add(Math.min(l+e.rowspan,t.length))}}let n=e.getCols()?.length||0;for(let[t,e]of o.entries())e>=n&&i.delete(t);return{cellIndex:s,isSpan:i.size<=0}}}var Br=class{maxRange=1/0;minRange=-1/0;startValue=0;dragBreak=null;tableModule;isX=!1;constructor(t,e){this.tableModule=t,this.isX=e}createBreak(){this.dragBreak&&this.dragBreak.remove();let t=l("drag");this.dragBreak=this.tableModule.addContainer(t.be("line")),this.dragBreak.classList.add(t.is(this.isX?"col":"row"))}getOffsetFromStart(t){let e=0;if(!t)return e;let{rect:l}=Y(t);return l&&(e=l[this.isX?"x":"y"]-this.startValue),e}limitRange(t,e,l=!0){let i=0;return l&&(i=this.getOffsetFromStart(t)),Math.min(this.maxRange+i,Math.max(e,this.minRange+i))}},Vr=class extends Gn{tableBlot;dragging=!1;colIndex=-1;rowIndex=-1;dragXCommon;dragYCommon;constructor(t,e){super(t,e),this.tableModule=t,this.quill=e,this.dragXCommon=new Br(t,!0),this.dragYCommon=new Br(t,!1)}findDragColIndex(t){return-1}calculateColDragRangeByFull(){if(!this.tableBlot)return;let{rect:t}=Y(this.tableBlot);if(!t)return;let e=this.tableBlot.getCols();if(this.colIndex=this.findDragColIndex(e),-1===this.colIndex)return;let l=Rr(e,this.colIndex),i=n.colMinWidthPre/100*t.width,o=t.right;e[this.colIndex+1]&&(o=Math.max(Rr(e,this.colIndex+1).right-i,l.left+i));let s=l.left+i;this.dragXCommon.minRange=s,this.dragXCommon.maxRange=o}calculateColDragRangeByFixed(){if(!this.tableBlot)return;let t=this.tableBlot.getCols();if(this.colIndex=this.findDragColIndex(t),-1===this.colIndex)return;let e=Rr(t,this.colIndex);this.dragXCommon.minRange=Lr(this.tableBlot)?e.right-n.colMinWidthPx:e.left+n.colMinWidthPx,this.dragXCommon.maxRange=1/0}calculateColDragRange(){this.tableBlot&&(this.tableBlot.full?this.calculateColDragRangeByFull():this.calculateColDragRangeByFixed())}async updateTableCol(t){if(!this.tableBlot||-1===this.colIndex)return;let e=this.dragXCommon.limitRange(this.tableBlot,t,!0),l=this.tableBlot.getCols(),i=Rr(l,this.colIndex),o=e-i.left;Lr(this.tableBlot)&&(o=i.right-e);let s=this.tableBlot.full,a=!1,h=[];if(s){let{rect:t}=Y(this.tableBlot),e=o/t.width*100,i=l[this.colIndex].width;if(e<i){if(e=Math.max(n.colMinWidthPre,e),l[this.colIndex+1]||l[this.colIndex-1]){let t=l[this.colIndex+1]?this.colIndex+1:this.colIndex-1;h.push({index:t,width:l[t].width+i-e})}else e=100;a=!0,h.push({index:this.colIndex,width:e})}else if(l[this.colIndex+1]){let t=i+l[this.colIndex+1].width;e=Math.min(t-n.colMinWidthPre,e),a=!0,h.push({index:this.colIndex,width:e},{index:this.colIndex+1,width:t-e})}}else this.tableBlot.domNode.style.width=`${Number.parseFloat(this.tableBlot.domNode.style.width)-l[this.colIndex].domNode.getBoundingClientRect().width+o}px`,a=!0,h.push({index:this.colIndex,width:o});if(a){let t=this.tableBlot.domNode.getBoundingClientRect().width;if(s){let e=0,i=new Set(h.map((({index:t,width:l})=>(e+=l,t))));for(let[t,o]of l.entries())i.has(t)||(e+=o.width);if(e>100){if(!await de({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableBlot.cancelFull(),s=!1;for(let[e,l]of h.entries()){let{width:i,index:o}=l;h[e]={index:o,width:i/100*t}}}}for(let{index:t,width:e}of h){let i=Number.parseFloat(e.toFixed(3));l[t].width=`${i}${s?"%":"px"}`}this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}}findDragRowIndex(t){return-1}calculateRowDragRange(){if(!this.tableBlot)return;let t=this.tableBlot.getRows();if(this.rowIndex=this.findDragRowIndex(t),-1===this.rowIndex)return;let e=t[this.rowIndex].domNode.getBoundingClientRect();this.dragYCommon.minRange=e.y+n.rowMinHeightPx,this.dragYCommon.maxRange=1/0}updateTableRow(t){if(!this.tableBlot||-1===this.rowIndex)return;let e=this.dragYCommon.limitRange(this.tableBlot,t,!0),l=this.tableBlot.getRows(),i=e-l[this.rowIndex].domNode.getBoundingClientRect().top;l[this.rowIndex].setHeight(`${i}px`),this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}removeBreak(){this.dragXCommon.dragBreak&&(this.dragXCommon.dragBreak.remove(),this.dragXCommon.dragBreak=null),this.dragYCommon.dragBreak&&(this.dragYCommon.dragBreak.remove(),this.dragYCommon.dragBreak=null)}};const Q=e.import("delta");var Hr=class extends cn{minusY=0;minusX=0;checkMinY(t){return this.mouseY+this.minusY<t.top+this.scrollThresholdY}checkMinX(t){return this.mouseX+this.minusX<t.left+this.scrollThresholdX}},Ur=class{startPosition=[];selectedIndex=new Set;moveToIndex=-1;tableModule;tableBlot;dragCommon;options;get isDragX(){return this.options.isDragX}constructor(t,e,l,i){this.tableModule=t,this.tableBlot=e,this.dragCommon=l,this.options=i}onStart(t,e,l){let o=this.tableModule.getModule(i.tableSelectionName);if(!o?.boundary||!this.tableBlot)return!1;let{isSpan:s,cellIndex:n}=zr(this.isDragX,this.tableBlot,o.selectedTds);if(!s)return!1;let{rect:r}=Y(this.tableBlot);if(!r)return!1;e.preventDefault(),this.dragCommon.startValue=this.isDragX?r.x:r.y,this.selectedIndex=n,l?.(this),this.recalculateStartPosition()}onMove(t,e,l){this.moveToIndex=this.findTheMovedToIndex(e),l?.(this)}onEnd(t,e,l){l?.(this),this.moveToIndex=-1,this.selectedIndex=new Set}recalculateStartPosition(){if(this.isDragX){if(this.startPosition=[],!this.tableBlot)return;let t=this.tableBlot.getCols(),e=t[0].domNode.getBoundingClientRect().left;for(let l=0;l<t.length;l++){let i=t[l].domNode.getBoundingClientRect();this.startPosition.push({size:i.width,position:e,index:l}),e+=i.width}}else{if(this.startPosition=[],!this.tableBlot)return;this.startPosition=this.tableBlot.getRows().map(((t,e)=>{let l=t.domNode.getBoundingClientRect();return{size:l.height,position:l.top,index:e}}))}}findTheMovedToIndex(t){let e=this.dragCommon.getOffsetFromStart(this.tableBlot),l=this.startPosition.find((({position:l,size:i})=>(this.isDragX?t.clientX:t.clientY)<l+i/2+e))?.index;return(ae(l)||l<0)&&(l=this.startPosition.length),l=Math.max(0,Math.min(l,this.startPosition.length)),this.selectedIndex.has(l)||this.options.allowMoveToIndex&&!this.options.allowMoveToIndex(l)?-1:l}updateTableStructure(t,e){let l=new Q;if(!this.tableBlot||this.moveToIndex<0)return l;let o=this.tableModule.getModule(i.tableSelectionName);if(!o)return l;if(this.isDragX){let i=this.tableBlot.getCols(),s=i.length-1,n=this.moveToIndex>s,r=new Set(o.selectedTds.map((t=>t.colId))),a=i.filter((t=>r.has(t.colId))).map((e=>{let l=e.length(),i=e.offset(e.scroll);return{offset:i,delta:t.slice(i,i+l),length:l}})),h=i[Math.min(s,this.moveToIndex)],d=h.offset(h.scroll)+(n?h.length():0),c=a.reduce(((t,e)=>t=t.concat(e.delta)),(new Q).retain(d)),u=a.reduce(((t,e,l)=>{let i=a[l-1],o=i?i.offset+i.length:0;return t=t.retain(e.offset-o).delete(e.length)}),new Q),p=e?u.compose(c):c.compose(u),m=o.selectedTds.map((e=>{let l=e.length(),i=e.offset(e.scroll);return{offset:i,delta:t.slice(i,i+l),length:l,rowId:e.rowId}})),{delta:f,insertDeltaInfo:b}=m.reduce((({delta:t,insertDeltaInfo:l},i,o)=>{let s=m[o-1],n=s?s.offset+s.length:0,r=0;return 0!==o&&!e&&(r=s.rowId===i.rowId?0:l[s.rowId]?.length()),t=t.retain(i.offset-n+r).delete(i.length),l[i.rowId]||(l[i.rowId]=new Q),l[i.rowId]=l[i.rowId].concat(i.delta),{delta:t,insertDeltaInfo:l}}),{delta:new Q,insertDeltaInfo:{}}),g=this.tableBlot.getRows(),{delta:w}=g.reduce((({delta:t,offset:l},i,o)=>{let r=i.getCellByColumIndex(Math.min(s,this.moveToIndex))[0];if(!r)return{delta:t,offset:l};let a=r.offset(r.scroll)+(n?r.length():0),h=a-l;if(0!==o&&e){let t=b[g[o-1].rowId];t&&(h-=t.length())}return t.retain(h),b[r.rowId]&&(t=t.concat(b[r.rowId])),{delta:t,offset:a}}),{delta:new Q,offset:0}),C=e?f.compose(w):w.compose(f);l=p.compose(C)}else{let i=this.tableBlot.getRows(),s=i.length-1,n=this.moveToIndex>s,r=i[Math.min(s,this.moveToIndex)],a=Array.from(o.selectedTds.reduce(((t,e)=>t.add(e.getTableRow())),new Set)).filter(Boolean),h=0,{delta:d,start:c,end:u}=a.reduce((({delta:t,start:e,end:l},i)=>{let o=i.offset(i.scroll),s=i.length();return t.retain(o-h).delete(s),h=o+s,{delta:t,start:Math.min(e,o),end:Math.max(l,o+s)}}),{delta:new Q,start:1/0,end:0}),p=r.offset(r.scroll)+(n?r.length():0),m=(new Q).retain(p).concat(t.slice(c,u));l=e?d.compose(m):m.compose(d)}return l}},Wr=class extends Vr{static moduleName="table-resize-box";options;root;tableWrapperBlot;resizeObserver;rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;bem=l("resize-box");draggingColIndex=-1;draggingRowIndex=-1;stopColDrag=[];stopRowDrag=[];dragWrapper=null;dragPlaceholder=null;markIndicator=null;dragTip=null;stopColMoveDrag=[];stopRowMoveDrag=[];autoScroller=null;updateContentDraggingPosition;cellSpanIndex=new Set;dragPlaceholderStartPosition={x:0,y:0};constructor(t,l,i){super(t,l),this.tableModule=t,this.quill=l,this.options=this.resolveOptions(i),this.updateContentDraggingPosition=()=>this.updateContentDraggerPosition(null),this.root=this.tableModule.addContainer(this.bem.b()),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_CHANGE,this.updateWrapperHead)}resolveOptions(t){return Object.assign({size:16,draggable:!0},t)}updateWrapperHead=()=>{if(!this.options.draggable)return;let t=this.tableModule.getModule(i.tableSelectionName);if(!t||!this.tableBlot)return;let{isSpan:e,cellIndex:l}=zr(!0,this.tableBlot,t.selectedTds),{isSpan:o,cellIndex:s}=zr(!1,this.tableBlot,t.selectedTds);if(e){let t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header")));for(let e of t)e.classList.remove(this.bem.is("selected"));if(!o)for(let e of Array.from(l).slice(0,-1))t[e].classList.add(this.bem.is("selected"))}if(o){let t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),l=[];for(let e of t)e.classList.remove(this.bem.is("selected")),l[Number(e.dataset.index)]=e;if(!e)for(let t of Array.from(s).slice(0,-1))l[t]&&l[t].classList.add(this.bem.is("selected"))}};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};setSelectionTable(t){if(this.table!==t){if(this.hide(),this.table=t,this.table){let t=e.find(this.table);t&&(this.tableBlot=t,this.tableWrapperBlot=this.tableBlot.parent),this.show()}this.update()}}handleResizerHeaderClick(t,e,l){if(!this.table)return;let{clientX:o,clientY:s}=l,n=this.table.getBoundingClientRect();l.shiftKey||(this.lastHeaderSelect=null);let r=[{x:t?n.left:o,y:t?s:n.top},{x:t?n.right:o,y:t?s:n.bottom}];if(this.lastHeaderSelect){let e,l;if(this.lastHeaderSelect.isX){let t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=Math.min(t.left,n.left),l=t.top+t.height/2}else{let t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=t.left+t.width/2,l=Math.min(t.top,n.top)}this.lastHeaderSelect.isX===t?t?(r[0].y=Math.min(r[0].y,l),r[1].y=Math.max(r[1].y,l)):(r[0].x=Math.min(r[0].x,e),r[1].x=Math.max(r[1].x,e)):(r[1]={x:Math.max(r[0].x,e),y:Math.max(r[0].y,l)},r[0]={x:Math.min(r[0].x,e),y:Math.min(r[0].y,l)})}else this.lastHeaderSelect={isX:t,index:e};let a=this.tableModule.getModule(i.tableSelectionName);a&&(a.table=this.table,a.setSelectedTds(a.computeSelectedTds(...r)),a.show())}findDragColIndex(){return this.draggingColIndex}findDragRowIndex(){return this.draggingRowIndex}updateContentDraggerPosition(t){if(!(t&&this.dragWrapper&&this.markIndicator&&this.tableBlot&&this.tableWrapperBlot))return;let{rect:e}=Y(this.tableBlot);if(!e||t.moveToIndex<0)return;let l=this.tableWrapperBlot.domNode.getBoundingClientRect(),i=this.quill.root.getBoundingClientRect();Object.assign(this.dragWrapper.style,{top:Math.max(e.y,l.y)-i.y+"px",left:Math.max(e.x,l.x)-i.x+"px"});let{position:o}=t.startPosition[t.moveToIndex]||{},s=this.dragXCommon.getOffsetFromStart(this.tableBlot),n=this.dragYCommon.getOffsetFromStart(this.tableBlot),r=t.isDragX?{top:Math.max(e.y,l.y)-i.y+"px",left:`${o-i.left+s}px`}:{top:`${o-i.top+n}px`,left:Math.max(e.x,l.x)-i.x+"px"};Object.assign(this.markIndicator.style,r)}createContentDragger(t,e,o){if(!this.tableBlot)return;let s=this.tableModule.getModule(i.tableSelectionName);if(!s||!this.tableWrapperBlot)return;s.updateWithSelectedTds();let n=s.boundary.width,r=s.boundary.height,a=this.quill.root.getBoundingClientRect(),h=this.tableWrapperBlot.domNode.getBoundingClientRect(),d=l("drag");this.dragWrapper=this.tableModule.addContainer(d.b());let c=h.x-a.x,u=h.y-a.y;Object.assign(this.dragWrapper.style,{left:`${c}px`,top:`${u}px`,width:`${h.width}px`,height:`${h.height}px`}),this.dragPlaceholder=document.createElement("div"),this.dragPlaceholder.classList.add(d.be("placeholder"),d.is("hidden")),this.dragWrapper.appendChild(this.dragPlaceholder),this.dragPlaceholderStartPosition={x:e?s.boundary.x-c:0,y:e?0:s.boundary.y-u},Object.assign(this.dragPlaceholder.style,{left:`${this.dragPlaceholderStartPosition.x}px`,top:`${this.dragPlaceholderStartPosition.y}px`,width:`${n}px`,height:`${r}px`}),this.markIndicator=this.tableModule.addContainer(d.be("indicator"));let p=e?{top:`${u}px`,height:`${Math.min(s.boundary.height,h.height)}px`}:{left:`${c}px`,width:`${Math.min(s.boundary.width,h.width)}px`};Object.assign(this.markIndicator.style,p),this.updateContentDraggingPosition=()=>this.updateContentDraggerPosition(o),I.call(this,this.quill.root,this.updateContentDraggingPosition),I.call(this,this.tableWrapperBlot.domNode,this.updateContentDraggingPosition),this.dragTip=this.tableModule.addContainer(d.be("tip"));let m=document.createElement("div");m.classList.add(d.be("tip-content")),this.dragTip.appendChild(m),e?(this.dragXCommon.minRange=0,this.dragXCommon.maxRange=h.width-n):(this.dragYCommon.minRange=0,this.dragYCommon.maxRange=h.height-r)}bindColEvents(){if(!this.tableWrapperBlot)return;let t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));if(I.call(this,this.tableWrapperBlot.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft})),this.stopColMoveDrag.length>0){for(let t of this.stopColMoveDrag)t();this.stopColMoveDrag=[]}let l=new Ur(this.tableModule,this.tableBlot,this.dragXCommon,{isDragX:!0,allowMoveToIndex:t=>this.allowMoveToIndex(t)});for(let[e,i]of t.entries())if(i.addEventListener("click",this.handleResizerHeaderClick.bind(this,!1,e)),this.options.draggable){let{stop:t}=$t(i,this.dragHeadOptions(!0,{index:e,dragHelper:l}));this.stopColMoveDrag.push(t)}if(this.stopColDrag.length>0){for(let t of this.stopColDrag)t();this.stopColDrag=[]}for(let[t,l]of e.entries()){let{stop:e}=$t(l,{axis:"x",onStart:(e,l)=>{if(this.dragging=!0,this.draggingColIndex=t,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let i=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:o}=Y(this.tableBlot);if(!o)return;this.dragXCommon.startValue=o.x;let s=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:Math.max(i.y,o.y)-s.y+"px",left:l.clientX-s.x+"px",height:`${Math.min(i.height,o.height)}px`})},onMove:({position:t})=>{if(!this.dragXCommon.dragBreak)return;let e=this.dragXCommon.limitRange(this.tableBlot,t.x,!0),l=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=e-l.x+"px"},onEnd:({position:t})=>{this.dragging=!1,this.updateTableCol(t.x),this.removeBreak()}});this.stopColDrag.push(e),l.addEventListener("dragstart",(t=>t.preventDefault()))}}bindRowEvents(){let t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));if(I.call(this,this.tableWrapperBlot.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapperBlot.domNode.scrollTop})),this.stopRowMoveDrag.length>0){for(let t of this.stopRowMoveDrag)t();this.stopRowMoveDrag=[]}let l=new Ur(this.tableModule,this.tableBlot,this.dragYCommon,{isDragX:!1,allowMoveToIndex:t=>this.allowMoveToIndex(t)});for(let[e,i]of t.entries()){let t=Number(i.dataset.index||e);if(i.addEventListener("click",this.handleResizerHeaderClick.bind(this,!0,e)),this.options.draggable){let{stop:e}=$t(i,this.dragHeadOptions(!1,{index:t,dragHelper:l}));this.stopRowMoveDrag.push(e)}}if(this.stopRowDrag.length>0){for(let t of this.stopRowDrag)t();this.stopRowDrag=[]}for(let[t,l]of e.entries()){let{stop:e}=$t(l,{axis:"y",onStart:(e,l)=>{if(this.dragging=!0,this.draggingRowIndex=t,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let i=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:o}=Y(this.tableBlot);if(!o)return;this.dragYCommon.startValue=o.y;let s=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:l.clientY-s.y+"px",left:Math.max(i.x,o.x)-s.x+"px",width:`${Math.min(i.width,o.width)}px`})},onMove:({position:t})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let e=this.dragYCommon.limitRange(this.tableBlot,t.y,!0),l=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=e-l.y+"px"},onEnd:({position:t})=>{this.dragging=!1,this.updateTableRow(t.y),this.removeBreak()}});this.stopRowDrag.push(e),l.addEventListener("dragstart",(t=>t.preventDefault()))}}allowMoveToIndex(t){return!this.cellSpanIndex.has(t)}recordCellSpan(t){let e=new Set;if(!this.tableBlot)return e;let l=this.tableBlot.descendants(H),i=t?this.tableBlot.getColIds():this.tableBlot.getRowIds(),o=t?"colspan":"rowspan";for(let s of l){if(s[o]<=1)continue;let l=i.indexOf(t?s.colId:s.rowId);if(-1!==l)for(let t=l+1;t<l+s[o]&&t<i.length;t++)e.add(t)}return e}dragHeadOptions(t,e){let{dragHelper:l,index:i}=e;return{axis:t?"x":"y",onStart:(e,o)=>{let s=!1;return l.onStart(e,o,(()=>{if(!this.tableBlot)return;let e=(t?this.tableBlot.getCols():this.tableBlot.getRows()).length;if(l.selectedIndex.size>e)return void(s=!1);let n=new Set(Array.from(l.selectedIndex).slice(0,-1));s=n.has(i),n.has(i)?(this.dragging=!0,t?this.draggingColIndex=i:this.draggingRowIndex=i,this.createContentDragger(o,t,l),this.cellSpanIndex=this.recordCellSpan(t),this.tableWrapperBlot&&(this.autoScroller=new Hr(50,40),this.autoScroller.minusY=this.options.size,this.autoScroller.minusX=this.options.size,this.autoScroller.updateMousePosition(o.clientX,o.clientY),this.autoScroller.start(this.tableWrapperBlot.domNode))):s=!1})),s},onMove:(e,i)=>{l.onMove(e,i,(l=>{let{movePosition:o}=e;if(this.autoScroller?.updateMousePosition(i.clientX,i.clientY),!(this.dragPlaceholder&&this.markIndicator&&this.dragTip&&this.tableWrapperBlot))return;this.dragPlaceholder.classList.remove(this.bem.is("hidden"));let s=l.dragCommon.limitRange(this.tableBlot,this.dragPlaceholderStartPosition[t?"x":"y"]+o[t?"x":"y"],!1);if(this.dragPlaceholder.style[t?"left":"top"]=`${s}px`,Object.assign(this.dragTip.style,{left:i.clientX-10+"px",top:i.clientY-10+"px"}),l.moveToIndex<0)return void Object.assign(this.markIndicator.style,{opacity:"0"});let n=this.quill.root.getBoundingClientRect(),r=l.moveToIndex>=l.startPosition.length,a=l.startPosition[r?l.moveToIndex-1:l.moveToIndex],h=a.position+(r?a.size:0),d=l.dragCommon.getOffsetFromStart(this.tableBlot);Object.assign(this.markIndicator.style,{opacity:"1",[t?"left":"top"]:`${h-(t?n.left:n.top)+d}px`})}))},onEnd:(e,i)=>{l.onEnd(e,i,(e=>{let l=e.updateTableStructure(this.quill.getContents(),(t?this.draggingColIndex:this.draggingRowIndex)>e.moveToIndex);this.quill.updateContents(l),this.dragging=!1,this.cellSpanIndex=new Set,this.autoScroller?.stop(),an.call(this,this.quill.root,this.updateContentDraggingPosition),an.call(this,this.tableWrapperBlot.domNode,this.updateContentDraggingPosition),this.dragWrapper&&=(this.dragWrapper.remove(),null),this.markIndicator&&=(this.markIndicator.remove(),null),this.dragTip&&=(this.dragTip.remove(),null)}))}}}update(){if(!this.tableBlot||!this.tableWrapperBlot)return;let{rect:t}=Y(this.tableBlot);if(!t)return;this.root.innerHTML="";let e=this.tableBlot.getCols(),l=this.tableBlot.getRows(),o=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();if(Object.assign(this.root.style,{top:Math.max(t.y,o.y)-s.y+"px",left:Math.max(t.x,o.x)-s.x+"px"}),e.length>0&&l.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.options.size}px`,height:`${this.options.size}px`}),this.corner.addEventListener("click",(()=>{let t=this.tableModule.getModule(i.tableSelectionName);t&&this.tableBlot&&(t.setSelectedTds(this.tableBlot.descendants(H)),t.show(),t.updateWithSelectedTds())})),this.root.appendChild(this.corner)),e.length>0){let l="";for(let i of e){let e=i.domNode.getBoundingClientRect().width;0===e&&(e=Number.parseInt(i.domNode.getAttribute("width"),10)),l+=`<div class="${this.bem.be("col-header")}" style="width: ${e}px">\n          <div class="${this.bem.be("col-separator")}" style="height: ${t.height+this.options.size-3}px"></div>\n        </div>`}let i=document.createElement("div");i.classList.add(this.bem.be("col"));let s=document.createElement("div");s.classList.add(this.bem.be("col-wrapper")),Object.assign(i.style,{transform:`translateY(-${this.options.size}px)`,maxWidth:`${o.width}px`,height:`${this.options.size}px`}),Object.assign(s.style,{width:`${t.width}px`}),s.innerHTML=l,i.appendChild(s),this.root.appendChild(i),i.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft,this.colHeadWrapper=i,this.bindColEvents()}if(l.length>0){let e="";for(let i=0;i<l.length;i++){let o=i,s=l[i],n=s.domNode.getBoundingClientRect().height;if(1===s.children.length&&(s.children.head?.emptyRow.length||0)>0){let t=s.children.head.emptyRow.length;for(let e=i+1;e<l.length&&e<=i+t;e++){n+=l[e].domNode.getBoundingClientRect().height}i+=t}e+=`<div class="${this.bem.be("row-header")}" data-index="${o}" style="height: ${n}px">\n          <div class="${this.bem.be("row-separator")}" style="width: ${t.width+this.options.size-3}px"></div>\n        </div>`}let i=document.createElement("div");i.classList.add(this.bem.be("row"));let s=document.createElement("div");s.classList.add(this.bem.be("row-wrapper")),Object.assign(i.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${o.height}px`}),Object.assign(s.style,{height:`${t.height}px`}),s.innerHTML=e,i.appendChild(s),this.root.appendChild(i),i.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}let[n]=p(this.tableBlot,Bn),r=!n||"top"!==n?.side;r?this.root.classList.remove(this.bem.is("caption-bottom")):this.root.classList.add(this.bem.is("caption-bottom"));let a=-1*this.options.size,h=-1*this.options.size;Lr(this.tableBlot)?(this.root.classList.add(this.bem.is("align-right")),a=Math.min(o.width,t.width),h=Math.min(o.width,t.width)):this.root.classList.remove(this.bem.is("align-right")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${a}px)`,top:`${r?0:t.height+this.options.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${h}px)`,maxHeight:`${o.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${r?0:t.height+this.options.size}px`,maxWidth:`${o.width}px`})}show(){!this.table||!this.tableBlot||(this.root.classList.remove(this.bem.is("hidden")),this.resizeObserver=rn((()=>this.update()),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),I.call(this,this.quill.root,(()=>{this.update()})))}hide(){this.root.classList.add(this.bem.is("hidden")),this.resizeObserver&&=void this.resizeObserver.disconnect()}destroy(){super.destroy(),this.hide(),L.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}},Gr=class extends Vr{static moduleName="table-resize-line";colResizer;rowResizer;currentTableCell;tableCellBlot;bem=l("resize-line");stopColDrag;stopRowDrag;scrollHandler=[];constructor(t,l){super(t,l),this.tableModule=t,this.quill=l,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}setSelectionTable(t){this.table!==t&&(this.hide(),this.table=t,this.table&&this.show())}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};findTableCell(t){for(let e of t.composedPath()){if(e instanceof HTMLElement&&["TD","TH"].includes(e.tagName))return e;if(e===document.body)return null}return null}pointermoveHandler=l=>{if(this.dragging||this.tableModule.getModule(i.tableSelectionName)?.dragging)return;let o=this.findTableCell(l);if(!o)return this.hide();let s=e.find(o);s&&this.currentTableCell!==o&&(this.show(),this.currentTableCell=o,this.tableCellBlot=s,this.tableBlot=u(s,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer(),I.call(this,this.quill.root,(()=>{this.dragging||this.hideResizer()})))};findDragColIndex(t){return this.tableCellBlot?t.findIndex((t=>t.colId===this.tableCellBlot.colId)):-1}updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;this.colResizer.remove();let{rect:t}=Y(this.tableBlot);if(!t)return;this.colResizer=this.tableModule.addContainer(this.bem.be("col"));let e=this.tableCellBlot.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect(),i=e.right-l.x;Lr(this.tableBlot)&&(i=e.left-l.x),Object.assign(this.colResizer.style,{top:t.y-l.y+"px",left:`${i}px`,height:`${t.height}px`});let{stop:o}=$t(this.colResizer,{axis:"x",onStart:(t,e)=>{if(this.dragging=!0,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let l=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:i}=Y(this.tableBlot);if(!i)return;this.dragXCommon.startValue=i.x;let o=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:Math.max(l.y,i.y)-o.y+"px",left:e.clientX-o.x+"px",height:`${Math.min(l.height,i.height)}px`})},onMove:({position:t})=>{if(!this.dragXCommon.dragBreak)return;let e=this.dragXCommon.limitRange(this.tableBlot,t.x,!0),l=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=e-l.x+"px"},onEnd:({position:t})=>{if(this.dragging=!1,this.colResizer){let e=this.dragXCommon.limitRange(this.tableBlot,t.x,!0),l=this.quill.root.getBoundingClientRect();this.colResizer.style.left=e-l.x+"px"}this.updateTableCol(t.x),this.removeBreak()}});this.stopColDrag&&this.stopColDrag(),this.stopColDrag=o,this.colResizer.addEventListener("dragstart",(t=>t.preventDefault()))}findDragRowIndex(t){if(!this.tableCellBlot)return-1;let e=this.tableCellBlot.parent;return e instanceof U?t.indexOf(e):-1}updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let t=this.tableCellBlot;this.rowResizer.remove();let{rect:e}=Y(this.tableBlot);if(!e)return;this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));let l=t.domNode.getBoundingClientRect(),i=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:l.bottom-i.y+"px",left:e.x-i.x+"px",width:`${e.width}px`});let{stop:o}=$t(this.rowResizer,{axis:"y",onStart:(t,e)=>{if(this.dragging=!0,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let l=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:i}=Y(this.tableBlot);if(!i)return;this.dragYCommon.startValue=i.y;let o=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:e.clientY-o.y+"px",left:Math.max(l.x,i.x)-o.x+"px",width:`${Math.min(l.width,i.width)}px`})},onMove:({position:t})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let e=this.dragYCommon.limitRange(this.tableBlot,t.y,!0),l=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=e-l.y+"px"},onEnd:({position:t})=>{if(this.dragging=!1,this.rowResizer){let e=this.dragYCommon.limitRange(this.tableBlot,t.y,!0),l=this.quill.root.getBoundingClientRect();this.rowResizer.style.left=e-l.y+"px"}this.updateTableRow(t.y),this.removeBreak()}});this.stopRowDrag&&this.stopRowDrag(),this.stopRowDrag=o,this.rowResizer.addEventListener("dragstart",(t=>t.preventDefault()))}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is("hidden")),this.colResizer.classList.remove(this.bem.is("hidden")),this.table.addEventListener("pointermove",this.pointermoveHandler))}hideResizer(){!this.rowResizer||!this.colResizer||(this.rowResizer.classList.add(this.bem.is("hidden")),this.colResizer.classList.add(this.bem.is("hidden")))}hide(){this.currentTableCell=void 0,L.call(this),this.hideResizer(),this.table&&this.table.removeEventListener("pointermove",this.pointermoveHandler)}destroy(){super.destroy(),this.colResizer&&=void this.colResizer.remove(),this.rowResizer&&=void this.rowResizer.remove(),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},Kr=class extends Gn{static moduleName="table-resize-scale";scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l("scale");options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(t,l,i){super(t,l),this.tableModule=t,this.quill=l,this.options=this.resolveOptions(i),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};resolveOptions(t){return Object.assign({blockSize:12,offset:6},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),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=[];$t(this.block,{onStart:()=>{this.tableMainBlot&&(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)}))))},onMove:({movePosition:l})=>{if(!this.tableMainBlot)return;let i=Lr(this.tableMainBlot)?-1:1,o=l.x*i,s=l.y,r=Math.floor(o/t.length),a=Math.floor(s/e.length);for(let{blot:e,width:l}of t)e.width=Math.max(l+r,n.colMinWidthPx);for(let{blot:t,height:l}of e)t.setHeight(`${Math.max(l+a,n.rowMinHeightPx)}px`)},onEnd:()=>{t=[],e=[]}}),this.block.addEventListener("dragstart",(t=>t.preventDefault()))}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return;if(this.tableMainBlot.full)return void this.hide();let{rect:t}=Y(this.tableMainBlot);if(!t)return;let e=this.tableWrapperBlot.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect(),{scrollTop:i,scrollLeft:o}=this.tableWrapperBlot.domNode,s=2*this.options.blockSize+this.options.offset,n=Math.min(t.width,e.width)+s,r=Math.min(t.height,e.height)+s;Object.assign(this.root.style,{width:`${n}px`,height:`${r}px`,left:Math.max(t.x,e.x)-l.x-this.options.blockSize+"px",top:Math.max(t.y,e.y)-l.y-this.options.blockSize+"px"});let a={left:t.width+s-o+"px",top:r-i+"px"};Lr(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),a.left=`${this.options.blockSize+-1*o}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,a)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),I.call(this,this.quill.root,(()=>this.update())),I.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0),L.call(this)}destroy(){super.destroy(),this.hide(),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect()}};const qr={size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"y",direction:"top",client:"clientY"},Jr={size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"x",direction:"left",client:"clientX"};var Yr=class{minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";bem=l("scrollbar");tableMainBlot;ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;thumbState={x:0,y:0};get isVertical(){return this.options.isVertical}constructor(t,l,i){this.quill=t,this.table=l,this.options=i,this.tableMainBlot=e.find(this.table),this.container=l.parentElement,this.propertyMap=this.isVertical?qr:Jr,this.calculateSize(),this.ob=new ResizeObserver((()=>this.update())),this.ob.observe(l),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),I.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:t,head:e,body:l,foot:i}=Y(this.tableMainBlot),o=e||l||i;if(!o||!t)return;let{scrollLeft:s,scrollTop:n,offsetLeft:r,offsetTop:a}=this.quill.root,{offsetLeft:h,offsetTop:d}=this.container,{offsetLeft:c,offsetTop:u}=o.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),f=h+c-r,b=d+u-a;this.isVertical?f+=Math.min(p,t.width):b+=Math.min(m,t.height),this.tableMainBlot&&"left"!==this.tableMainBlot.align&&(f+=this.table.offsetLeft-h),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,t.height):p}px`,transform:`translate(${f-s}px, ${b-n}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,l=t**2/this.container.scrollHeight,i=e**2/this.container.scrollWidth,o=Math.max(l,this.minSize),s=Math.max(i,this.minSize);this.ratioY=l/(t-l)/(o/(t-o)),this.ratioX=i/(e-i)/(s/(e-s)),this.sizeWidth=s+this.gap<e?`${s}px`:"",this.sizeHeight=o+this.gap<t?`${o}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let t=document.createElement("div");t.classList.add(this.bem.b(),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,l=t=>{if(!1===this.cursorDown)return;let e=this.thumbState[this.propertyMap.axis];if(!e)return;let l=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],i=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*l/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=i*this.container[this.propertyMap.scrollSize]/100},i=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",i),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=e},o=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",l),document.addEventListener("mouseup",i),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(),o(t);let e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));let s=[this.table,t];for(let t of s)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return I.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){let 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.toUpperCase()}(${this.move}%)`})}showScrollbar=_n((()=>{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=_n((()=>{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(),L.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}},Xr=class extends Gn{static moduleName="table-scrollbar";scrollbarContainer;scrollbar=[];bem=l("scrollbar");constructor(t,i,o){super(t,i),this.tableModule=t,this.quill=i;let s=l("scrollbar");this.quill.container.classList.add(s.bm("virtual")),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};hide(){for(let t of this.scrollbar)t.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=""}show(){if(this.table){this.scrollbar=[new Yr(this.quill,this.table,{isVertical:!0}),new Yr(this.quill,this.table,{isVertical:!1})];for(let t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar),t.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){super.destroy(),this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Zr=class extends Gn{static moduleName=i.tableSelectionName;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l("selection");autoScroller;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(t){this._dragging!==t&&(this._dragging=t,this.quill.emitter.emit(t?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,l,i={}){super(t,l),this.tableModule=t,this.quill=l,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=rn(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener("paste",this.handlePaste),document.addEventListener("selectionchange",this.selectionChangeHandler),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.autoScroller=new cn(50,40),this.hide()}handlePaste=e=>{if(!document.activeElement||!this.quill.root.contains(document.activeElement)||this.quill.getSelection())return;let l=e.clipboardData;if(!l)return;e.preventDefault();let i=this.selectedTds;if(i.length<=0)return;let o=l.getData("text/html"),s=this.quill.clipboard.convert({html:o}).ops.filter((e=>e.attributes?.[t.tableCellInner]));0!==s.length&&Jn({quill:this.quill,talbeModule:this.tableModule},i,s)};keyboardHandler=async t=>{if(t.ctrlKey)switch(t.key){case"c":case"x":await Mr(this.tableModule,this.selectedTds,"x"===t.key)}else("Backspace"===t.key||"Delete"===t.key)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let t of this.selectedTds)if(!t.domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),l=document.activeElement;if(!t&&this.quill.root.contains(l)){if(this.table){let t=e.find(this.table),l=t.descendants(H);if(this.selectedTds.length===l.length)return void t.remove()}for(let t of this.selectedTds){let e=t.clone();e.appendChild(t.scroll.create("block")),t.parent.insertBefore(e,t),t.remove()}}}setSelectedTds(t){let e=new Set(this.selectedTds),l=this.selectedTds.length===t.length&&t.every((t=>e.has(t)));this.selectedTds=t,l||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}quillSelectionChangeHandler=(l,i,o)=>{if(o!==e.sources.API&&l&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(l),[i]=this.quill.getLine(l.index),o=!!e[t.tableCellInner]&&!!i,s=i&&this.selectedTds.some((t=>t.domNode.contains(i.domNode)));if(o&&!s)try{let e=u(i,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else o&&s||this.hide()}};setSelectionData(t,e){let{anchorNode:l,anchorOffset:i,focusNode:o,focusOffset:s}=e;if(!l||!o)return;let n=document.createRange(),r=this.selectionDirectionUp(e);r?(n.setStart(l,i),n.setEnd(l,i)):(n.setStart(l,i),n.setEnd(o,s)),t.removeAllRanges(),t.addRange(n),r&&t.extend(o,s)}selectionDirectionUp(t){let{anchorNode:e,anchorOffset:l,focusNode:i,focusOffset:o}=t;if(!e||!i)return!1;if(e===i)return l>o;let s=e.compareDocumentPosition(i);return s&Node.DOCUMENT_POSITION_CONTAINS||s&Node.DOCUMENT_POSITION_CONTAINED_BY?!!(s&Node.DOCUMENT_POSITION_FOLLOWING):!!(s&Node.DOCUMENT_POSITION_PRECEDING)}resolveOptions(t){return Object.assign({selectColor:"#0589f340"},t)}getSelectedTdsFormat(){if(this.selectedTds.length<=0)return{};let t=[];for(let e of this.selectedTds){let l=e.offset(this.quill.scroll),i=e.length();t.push(this.quill.getFormat(l,i))}let e={},l=t[0];for(let[i,o]of Object.entries(l))t.every((t=>t[i]===o))&&(e[i]=o);return e}selectionChangeHandler=()=>{let l=window.getSelection();if(!l)return;let{anchorNode:i,focusNode:o,anchorOffset:s,focusOffset:n}=l;if(!i||!o)return;let r=e.find(i),a=e.find(o);if(!r||!a||r.scroll!==this.quill.scroll||a.scroll!==this.quill.scroll)return;let h=f(r),d=f(a),c=h.has(t.tableColgroup),u=d.has(t.tableColgroup);if(c||u){let e=i,r=s,a=o,p=n;if(c){let l=h.get(t.tableWrapper).descendants(H);l.length>0&&(e=l[0].domNode,r=0)}if(u){let e=d.get(t.tableWrapper).descendants(H);e.length>0&&(a=e[0].domNode,p=0)}return void this.setSelectionData(l,{anchorNode:e,anchorOffset:r,focusNode:a,focusOffset:p})}let p=h.has(t.tableCellInner),m=d.has(t.tableCellInner),b=p&&m;if(b){let e=h.get(t.tableCellInner),l=d.get(t.tableCellInner);b&&=e!==l}if(p&&m&&b||!p&&m||!m&&p)return this.setSelectionData(l,this.lastSelection),void(this.selectedTds.length>0&&this.hide());this.lastSelection={anchorNode:i,anchorOffset:s,focusNode:o,focusOffset:n}};helpLinesInitial(){this.cellSelectWrap.style.setProperty("--select-color",this.options.selectColor);let t=document.createElement("div");return t.classList.add(this.bem.be("line")),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(t,l){if(!this.table)return[];let i=e.find(this.table);if(!i)return[];let o=new Set(i.descendants(W).map(((t,e)=>(t.index=e,t)))),s=this.getScrollPositionDiff(),{rect:n}=Y(i);if(!n)return[];let r=t.x+s.x,a=t.y+s.y,h={x:Math.max(n.left,Math.min(l.x,r)),y:Math.max(n.top,Math.min(l.y,a)),x1:Math.min(n.right,Math.max(l.x,r)),y1:Math.min(n.bottom,Math.max(l.y,a))},d=new Set,c=!0;for(;c;){c=!1;for(let t of o){t.__rect||=t.domNode.getBoundingClientRect();let{x:e,y:l,right:i,bottom:s}=t.__rect;if(en({x:Math.floor(h.x),y:Math.floor(h.y),x1:Math.floor(h.x1),y1:Math.floor(h.y1)},{x:Math.floor(e),y:Math.floor(l),x1:Math.floor(i),y1:Math.floor(s)},0,!1)){d.add(t),o.delete(t),h={x:Math.min(h.x,e),y:Math.min(h.y,l),x1:Math.max(h.x1,i),y1:Math.max(h.y1,s)},c=!0;break}}}for(let t of[...d,...o])delete t.__rect;return this.boundary=tn({...h,width:h.x1-h.x,height:h.y1-h.y},this.quill.root),Array.from(d).toSorted(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}getScrollPositionDiff(){let{x:t,y:e}=this.getTableViewScroll(),{x:l,y:i}=on(this.quill.root);return this.selectedTableScrollX=t,this.selectedTableScrollY=e,this.selectedEditorScrollX=l,this.selectedEditorScrollY=i,this.startScrollRecordPosition.reduce(((t,{x:e,y:l},i)=>{let{x:o,y:s}=on(this.scrollRecordEls[i]);return t.x+=e-o,t.y+=l-s,t}),{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let t of this.scrollRecordEls)this.startScrollRecordPosition.push(on(t))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(t){let{button:l,target:i,clientX:o,clientY:s}=t,n=i.closest("table"),r=i.closest("caption");if(0!==l||!n||r)return;this.setSelectionTable(n);let a=n.dataset.tableId,h={x:o,y:s};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(h,h)),this.show();let d=t=>{this.dragging=!0;let{button:e,target:l,clientX:i,clientY:o}=t,s=l.closest(".ql-table"),n=l.closest("caption");if(0!==e||n||!s||s.dataset.tableId!==a)return;let r={x:i,y:o};this.setSelectedTds(this.computeSelectedTds(h,r)),this.selectedTds.length>1&&this.quill.blur(),this.update(),this.autoScroller.updateMousePosition(i,o)},c=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",c,!1),this.autoScroller.stop(),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",c,!1);let u=e.find(n);if(!u)return;let p=u.parent.domNode;this.autoScroller.updateMousePosition(o,s),this.autoScroller.start(p)}updateWithSelectedTds(){if(this.selectedTds.length<=0)return void this.hide();let t={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(let l of this.selectedTds){let i=l.parent.domNode.getBoundingClientRect();t.x=Math.min(t.x,i.left),t.y=Math.min(t.y,i.top),e.x=Math.max(e.x,i.right),e.y=Math.max(e.y,i.bottom)}this.setSelectedTds(this.computeSelectedTds(t,e)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table)return void this.hide();if(0===this.selectedTds.length||!this.boundary)return;let{x:t,y:e}=on(this.quill.root),{x:l,y:i}=this.getTableViewScroll(),o=this.table.parentElement.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),n=o.x-s.x,a=o.y-s.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-l-n+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-i-a+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${n}px`,top:`${a}px`,width:`${o.width}px`,height:`${o.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?on(this.table.parentElement):{x:0,y:0}}setSelectionTable(t){this.table!==t&&(this.table=t,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:"block"}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(L.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener("keydown",this.keyboardHandler),I.call(this,this.quill.root,(()=>{this.update()})),I.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(){L.call(this),this.quill.root.removeEventListener("keydown",this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){super.destroy(),this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),L.call(this),document.removeEventListener("paste",this.handlePaste),document.removeEventListener("selectionchange",this.selectionChangeHandler),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Qr=e.import("parchment"),$=e.import("delta"),$r=e.import("ui/icons"),ei=e.import("blots/break"),ti=e.import("blots/block"),ni=e.import("blots/block/embed");function ri(e,{tableId:l,rowId:i,colId:o}){let s={tableId:l,rowId:i,colId:o,colspan:1,rowspan:1},n=e.create(t.tableCell,s),r=e.create(t.tableCellInner,s),a=e.create("block");return a.appendChild(e.create("break")),r.appendChild(a),n.appendChild(r),n}function ii(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),si.moduleName=i.moduleName,si.toolName=t.tableWrapper,z.blotName=t.container,Bn.blotName=t.tableCaption,J.blotName=t.tableWrapper,K.blotName=t.tableMain,q.blotName=t.tableColgroup,G.blotName=t.tableCol,Un.blotName=t.tableHead,V.blotName=t.tableBody,Hn.blotName=t.tableFoot,U.blotName=t.tableRow,W.blotName=t.tableCell,H.blotName=t.tableCellInner,o.add(t.tableCellInner)}function ai(t,l){return T({onSelect:(i,o)=>{t.insertTable(i,o,e.sources.USER),l&&l.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function oi(l){return{bindInHead:!1,key:l?"ArrowUp":"ArrowDown",collapsed:!0,format:[t.tableCellInner],handler(i,o){let s=l?"prev":"next",n=l?"tail":"head";if(o.line[s])return!0;let r,a,h,c,u=this.quill.selection.getBounds(i.index),p=o.line.domNode.getBoundingClientRect();if(!u||!p)return!0;if(l){if(u.top-p.top>3)return!0}else if(p.bottom-u.bottom>3)return!0;try{[r,a,h,c]=d(o.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m,f=a.getColIds(),b=r.descendants(Bn,0)[0];if(b){let t=window.getComputedStyle(b.domNode);m="next"===s&&"bottom"===t.captionSide?b:"next"===s?r.next:b}else m=r[s];if(o.line[s]||!m)return!0;let g=h[s];if(g){let t=f.indexOf(c.colId),l=g.getCellByColId(f[t],s);if(!l)return!0;let i=l.children[n];i.children&&(i=i.children[n]);let r=i.offset(this.quill.scroll)+Math.min(o.offset,i.length()-1);this.quill.setSelection(r,0,e.sources.USER)}else{let t=m.offset(this.quill.scroll)+(l?m.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var si=class o{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(e,l){let i=this.quill.getLine(e.index)[0];return i.prev instanceof J?(i.prev.remove(),!1):!(l.format[t.tableCellInner]&&0===i.offset(u(i,t.tableCellInner)))}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(e,l){let i=this.quill.getLine(e.index),o=i[0],s=i[1];return!((o.next instanceof J||o.next instanceof G)&&s===o.length()-1||l.format[t.tableCellInner]&&o===u(o,t.tableCellInner).children.tail&&s===o.length()-1)}},"table up":oi(!0),"table down":oi(!1),"table caption break":{bindInHead:!0,key:"Enter",shiftKey:null,format:[t.tableCaption],handler:(t,e)=>!1}};static register(){J.allowedChildren=[K],K.allowedChildren=[q,Bn,Un,V,Hn],K.requiredContainer=J,Bn.requiredContainer=K,q.allowedChildren=[G],q.requiredContainer=K,Un.allowedChildren=[U],Un.requiredContainer=K,V.allowedChildren=[U],V.requiredContainer=K,Hn.allowedChildren=[U],Hn.requiredContainer=K,U.allowedChildren=[W],W.allowedChildren=[H,ei],W.requiredContainer=U,H.requiredContainer=W;let l=new Set(["table"]),i=Object.entries(e.imports).filter((([t,e])=>{let i=t.split("formats/")[1];return t.startsWith("formats/")&&!l.has(i)&&(g(e,ti)||g(e,ni))})).reduce(((t,[e,l])=>{let i=g(l,ni)?kn:Dn;return t[e]=class extends(h(l,[i])){static register(){}},t}),{});e.register({"blots/scroll":Fn,"blots/block":Dn,"blots/block/embed":kn,...i,[`blots/${t.container}`]:z,[`formats/${t.tableCell}`]:W,[`formats/${t.tableCellInner}`]:H,[`formats/${t.tableRow}`]:U,[`formats/${t.tableHead}`]:Un,[`formats/${t.tableBody}`]:V,[`formats/${t.tableFoot}`]:Hn,[`formats/${t.tableCol}`]:G,[`formats/${t.tableColgroup}`]:q,[`formats/${t.tableCaption}`]:Bn,[`formats/${t.tableMain}`]:K,[`formats/${t.tableWrapper}`]:J,"modules/clipboard":mr},!0)}quill;options;textOptionsInput;toolBox;fixTableByLisenter=_n(this.balanceTables,100);selector;resizeOb;editableObserver;modules={};get statics(){return this.constructor}constructor(t,e){this.quill=t,this.textOptionsInput=e?.texts,this.options=this.resolveOptions(e||{}),this.toolBox=this.initialContainer();let l=this.getToolbarPicker();l&&(l.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,l),l.label.addEventListener("mousedown",(()=>{if(!this.selector)return;let{leftLimited:t}=nn(this.selector.getBoundingClientRect());if(t){let t=l.label.getBoundingClientRect();Object.assign(l.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(l.options.style,{transform:void 0})})));let i=this.quill.getModule("keyboard");for(let t of Object.values(o.keyboradHandler))t.bindInHead?i.bindings[t.key].unshift(t):i.addBinding(t.key,t);this.initModules(),this.listenEditableChange(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let t=l("toolbox"),e=this.quill.addContainer(t.b());return this.resizeOb=new ResizeObserver((()=>{let t=this.quill.root.getBoundingClientRect(),{offsetLeft:l,offsetTop:i}=this.quill.root;Object.assign(e.style,{top:`${i}px`,left:`${l}px`,width:`${t.width}px`,height:`${t.height}px`})})),this.resizeOb.observe(this.quill.root),e}addContainer(t){if(C(t)){let e=document.createElement("div");for(let l of t.split(" "))e.classList.add(l);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}getToolbarPicker(){let t=this.quill.getModule("toolbar");if(!t||!this.quill.theme.pickers)return;let[,e]=(t.controls||[]).find((([t])=>t===this.statics.toolName))||[];return"select"===e?.tagName.toLocaleLowerCase()?this.quill.theme.pickers.find((t=>t.select===e)):void 0}resolveOptions(t){let{texts:e,...l}=t;return Object.assign({customBtn:!1,texts:this.resolveTexts(e),full:!1,fullSwitch:!0,icon:$r.table,autoMergeCell:!0,pasteStyleSheet:!1,pasteDefaultTagStyle:!1,modules:[]},l)}resolveTexts(t){let e={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"};if(x(t)){let l=t,i=this;return new Proxy(e,{get(t,e){if("string"!=typeof e)return Reflect.get(t,e);let o=l.call(i,e);return C(o)?o:t[e]}})}return Object.assign(e,t)}async refreshUI(){this.options.texts=this.resolveTexts(this.textOptionsInput);let t=this.getToolbarPicker();t&&(t.label.innerHTML=this.options.icon,await this.buildCustomSelect(this.options.customSelect,t));for(let t of Object.values(this.modules))t&&"function"==typeof t.hide&&t.hide()}initModules(){if(this.quill.isEnabled())for(let t of this.options.modules)this.modules[t.module.moduleName]=new t.module(this,this.quill,t.options)}listenEditableChange(){this.editableObserver=new MutationObserver((t=>{for(let e of t)if("attributes"===e.type&&"contenteditable"===e.attributeName){"false"===this.quill.root.getAttribute("contenteditable")?this.destroyModules():this.initModules();break}})),this.editableObserver.observe(this.quill.root,{attributes:!0,attributeFilter:["contenteditable"]})}destroyModules(){for(let[t,e]of Object.entries(this.modules))if(e&&"function"==typeof e.destroy)try{e.destroy()}catch(e){console.warn(`Failed to destroy module ${t}:`,e)}this.modules={}}getModule(t){return this.modules[t]}quillHack(){let l=this.quill.getSemanticHTML;this.quill.originGetSemanticHTML=l,this.quill.getSemanticHTML=(i=0,o)=>{let s=l.call(this.quill,i,o),n=e.import(`formats/${t.tableWrapper}`),r=(new DOMParser).parseFromString(s,"text/html");for(let t of Array.from(r.querySelectorAll(`.${n.className} caption[contenteditable], .${n.className} .${W.className} > [contenteditable]`)))t.removeAttribute("contenteditable");return r.body.innerHTML};let o=this.quill.format;this.quill.originFormat=o,this.quill.format=function(l,s,n=e.sources.API){if(!(this.scroll.query(l).prototype instanceof Qr.EmbedBlot)){let r=this.getModule(i.moduleName),a=this.getSelection(!0),h=this.getFormat(a),d=r.getModule(i.tableSelectionName);if(!h[t.tableCellInner]&&d&&d.selectedTds.length>1){let t=d.selectedTds[d.selectedTds.length-1],l=t.offset(this.scroll);this.setSelection(l+t.length()-1,0,e.sources.SILENT),a=this.getSelection(!0),h=this.getFormat(a)}if(!h[t.tableCellInner]||a.length>0||r&&d&&d.selectedTds.length<=1)return o.call(this,l,s,n);if(r&&d&&d.selectedTds.length>0){let t=d.selectedTds,e=d.getSelectedTdsFormat()[l]!==s&&s,i=new $,o=[];for(let e of t){let t=e.offset(this.scroll),l=e.length();o.push({index:t,length:l})}for(let[t,{index:s,length:n}]of o.entries()){let r=0===t?0:o[t-1].index+o[t-1].length;i.retain(s-r).retain(n,{[l]:e})}let r=this.updateContents(i,n);return this.blur(),r}}return o.call(this,l,s,n)};let s=this.quill.theme.modules.toolbar;if(s){let l=s.handlers?.indent;s.handlers.indent=function(t){let o=this.quill.getModule(i.moduleName).getModule(i.tableSelectionName);if(o&&o.selectedTds.length>1){let l=o.getSelectedTdsFormat(),i=Number.parseInt(l.indent||0,10),s=l.direction;if("+1"===t||"-1"===t){let l="+1"===t?1:-1;"rtl"===s&&(l*=-1),this.quill.format("indent",i+l,e.sources.USER)}}else if(l)return l.call(this,t)};let o=s.handlers?.clean;if(o){let l=(e,l,i=()=>"")=>{let o=this.quill.getText(e,l),[s,n]=this.quill.getLine(e+l),r=0,a=new $;null!=s&&(r=s.length()-n,a=s.delta().slice(n,n+r-1).insert("\n"));let h=this.quill.getContents(e,l+r),d=h.diff((new $).insert(o).concat(a)),c=0;return new $(d.ops.map((e=>{let{attributes:l,...o}=e;if(e.insert?c-=C(e.insert)?e.insert.length:1:e.retain?c+=re(e.retain)?e.retain:1:e.delete&&(c+=e.delete),l){let{[t.tableCellInner]:e,...s}=l;if(i){let e=h.slice(c-1,c).ops[0];if(e?.attributes?.[t.tableCellInner]){let{style:l,...n}=e.attributes[t.tableCellInner],r=i(l);return r?{...o,attributes:{...s,[t.tableCellInner]:{style:r,...n}}}:{...o,attributes:{...s,[t.tableCellInner]:n}}}}return{...o,attributes:{...s}}}return e})))};s.handlers.clean=function(s){let n=this.quill.getModule(i.moduleName),r=this.quill.getSelection();if(r&&r.length>0&&this.quill.getFormat(r)[t.tableCellInner]){let t=l(r.index,r.length,!1),i=(new $).retain(r.index).concat(t);return void this.quill.updateContents(i,e.sources.USER)}let a=n.getModule(i.tableSelectionName);if(n&&a&&a.selectedTds.length>0&&a.table){let t=e.find(a.table);if(!t)return void console.warn("TableMainFormat not found");let i=a.selectedTds,o=new Set,s=[];for(let t of i)if(t.parent instanceof W){for(let e of t.parent.getNearByCell("top"))o.has(e)||(o.add(e),s.push({td:e,cleanBorder:"bottom"}));for(let e of t.parent.getNearByCell("left"))o.has(e)||(o.add(e),s.push({td:e,cleanBorder:"right"}));o.add(t.parent),s.push({td:t.parent,cleanBorder:!0})}let n=t.descendants(W),r=new Map(n.map(((t,e)=>[t,e])));s.sort(((t,e)=>r.get(t.td)-r.get(e.td)));let h=new $,d=0;for(let{td:t,cleanBorder:e}of s){let i=t.getCellInner().offset(this.quill.scroll),o=t.getCellInner().length(),s=l(i,o-1,(t=>{if(!t||!0===e)return"";let l=fn(t);return pn(Object.keys(l).filter((t=>!t.startsWith(un(`border-${e}`)))).reduce(((t,e)=>(t[e]=l[e],t)),{}))})),n=(new $).retain(i-d).concat(s);h=h.concat(n),d=i+o}return this.quill.updateContents(h,e.sources.USER),void(i.length>1&&this.quill.blur())}return o.call(this,s)}}}}async buildCustomSelect(t,e){if(!t||!x(t))return;let i=document.createElement("span");if(i.classList.add("ql-custom-select"),this.selector=await t(this,e),i.appendChild(this.selector),this.options.fullSwitch){let t=l("creator"),e=document.createElement("label");e.classList.add(t.be("checkbox"));let o=document.createElement("input");o.type="checkbox",o.checked=this.options.full,o.addEventListener("change",(()=>{this.options.full=o.checked}));let s=document.createElement("span");s.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(s),i.appendChild(e)}e.options.innerHTML="",e.options.appendChild(i)}setCellAttrs(t,e,l,i=!1){if(0!==t.length)for(let o of t)o.setFormatValue(e,l,i)}getTextByCell(t){let e="";for(let l of t){let t=l.offset(this.quill.scroll),i=l.length();for(let l of this.quill.getContents(t,i).ops)C(l.insert)&&(e+=l.insert)}return e}getHTMLByCell(e,l=!1){if(0===e.length)return"";let i=null;try{for(let l of e){let e=u(l,t.tableMain);if(i||=e,e!==i)return console.error("tableMain is not same"),""}}catch{return console.error("tds must be in same tableMain"),""}if(!i)return"";let o=this.quill.getIndex(i),s=i.length(),n=this.quill.getSemanticHTML(o,s),r=(new DOMParser).parseFromString(n,"text/html"),a=Array.from(r.querySelectorAll("col")),h=a.map((t=>t.dataset.colId)),d=[],c=new Set,p=new Set;for(let t of e){c.add(t.colId);let e=t.colId,l=h.indexOf(e);for(let e=0;e<t.colspan;e++)c.add(h[l+e]);p.add(`${t.rowId}-${t.colId}`)}for(let t=0;t<a.length;t++){let e=a[t];c.has(e.dataset.colId)?d.push(e.getAttribute("width")):(e.remove(),a.splice(t--,1))}let m=0,f=null;for(let t of Array.from(r.querySelectorAll("td, th")))if(p.has(`${t.dataset.rowId}-${t.dataset.colId}`))f!==t.dataset.rowId&&(m+=1,f=t.dataset.rowId);else{let e=t.parentElement;t.remove(),e&&e.children.length<=0&&e.remove()}let b=a.map((t=>G.value(t)));if(i.full){let t=b.reduce(((t,e)=>e.width+t),0);for(let[e,l]of b.entries())l.width=Math.round(l.width/t*100),a[e].setAttribute("width",`${l.width}%`)}else{let t=0;for(let e of b)t+=e.width;r.querySelector("table").style.width=`${t}px`}if(l){if(m===i.getRows().length)this.removeCol(e);else for(let t of e)t.domNode.innerHTML="<p><br></p>"}return r.body.innerHTML}insertTable(l,i,o=e.sources.API){if(l>=30||i>=30)throw Error("Both rows and columns must be less than 30.");this.quill.focus();let s=this.quill.getSelection();if(null==s)return;let[r]=this.quill.getLeaf(s.index);if(!r)return;if(c(r))throw Error(`Not supported ${r.statics.blotName} insert into table.`);let a=R(),h=Array(i).fill(0).map((()=>R())),d=this.calculateTableCellBorderWidth(),u=getComputedStyle(this.quill.root),p=Number.parseInt(u.paddingLeft),m=Number.parseInt(u.paddingRight),f=this.quill.root.scrollHeight>this.quill.root.clientHeight?sn({target:this.quill.root}):0,b=Number.parseInt(u.width)-p-m-d-f,g=this.options.full?`${Math.max(1/i*100,n.colMinWidthPre)}%`:`${Math.max(Math.floor(b/i),n.colMinWidthPx)}px`,w=[{retain:s.index}],C=this.quill.getContents(s.index,1),[,x]=this.quill.getLine(s.index);"\n"!==C.ops[0].insert&&0!==x&&w.push({insert:"\n"});for(let e=0;e<i;e++)w.push({insert:{[t.tableCol]:{width:g,tableId:a,colId:h[e],full:this.options.full}}});for(let e=0;e<l;e++){let e=R();for(let l=0;l<i;l++)w.push({insert:"\n",attributes:{[t.tableCellInner]:{tableId:a,rowId:e,colId:h[l],rowspan:1,colspan:1}}})}this.quill.updateContents(new $(w),o),this.quill.setSelection(s.index+i,e.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){let t=`\n      <table class="${K.className}">\n        <tbody>\n          <tr>\n            <td class="${W.className}"></td>\n          </tr>\n        </tbody>\n      </table>\n    `,e=document.createElement("div");e.className=J.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);let l=window.getComputedStyle(e.querySelector("td")),i=Number.parseFloat(l.borderWidth)||0;return this.quill.root.removeChild(e),i}fixUnusuaDeletelTable(t){let e=t.getColIds();if(0===e.length)return void t.remove();let l=t.getBodys(),i=t.tableId;for(let t of l){let l=t.getRows();if(0===l.length){t.remove();continue}let o=Array(l.length).fill(0).map((()=>Array(e.length).fill(!1)));for(let[t,s]of l.entries()){let n=0,r=0,a=o[t],h=s.descendants(W);for(;r<e.length;){if(a[r]){r+=1;continue}let d=h[n];if(d?.colId!==e[r])s.insertBefore(ri(this.quill.scroll,{tableId:i,colId:e[r],rowId:s.rowId}),d);else{t+d.rowspan-1>=l.length&&(d.getCellInner().rowspan=l.length-t);let{colspan:e,rowspan:i}=d;if(e>1)for(let t=1;t<e;t++)a[r+t]=!0;if(i>1)for(let l=t+1;l<t+i;l++)for(let t=0;t<e;t++)o[l][r+t]=!0;n+=1}r+=1}if(n<h.length)for(let t=n;t<h.length;t++)h[t].remove()}}}balanceTables(){for(let t of this.quill.scroll.descendants(K))t.checkEmptyCol(this.options.autoMergeCell),t.checkEmptyRow(this.options.autoMergeCell),this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(e.events.SCROLL_OPTIMIZE,(t=>{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)));for(let l of t){let t=l.target;if("TABLE"===t.tagName){let l=e.find(t);if(l){l.sortMergeChildren();break}}}}))}deleteTable(e){0!==e.length&&u(e[0],t.tableMain)?.remove()}appendRow(e,l){if(e.length<=0)return;let i=e[l?e.length-1:0],[o,s]=d(i,[t.tableMain,t.tableRow]),n=o.getRows().indexOf(s)+(l?i.rowspan:0);o.insertRow(n)}appendCol(e,l){if(e.length<=0)return;let[i]=e.reduce(((t,e)=>{let i=e.getColumnIndex();return(!l&&i<=t[1]||l&&i>=t[1])&&(t=[e,i]),t}),[e[0],e[0].getColumnIndex()]),o=i.getColumnIndex()+(l?i.colspan:0),s=u(i,t.tableMain),n=s.tableId,r=R(),[a]=s.descendants(q);a&&a.insertColByIndex(o,{tableId:n,colId:r,width:s.full?6:160,full:s.full});let h=s.getRows(),d=[],c=0;for(let t of Object.values(h)){let e=d.shift()||0;if(c>0){--c;continue}let l=t.insertCell(o-e,{tableId:n,rowId:t.rowId,colId:r,rowspan:1,colspan:1});l.skipRowNum&&(c+=l.skipRowNum);for(let[t,e]of l.entries())d[t]=(d[t]||0)+e}}fixTableByRemove(t){if(!this.options.autoMergeCell)return;let e=t.getRows(),l=t.getCols(),i=l.reduce(((t,e)=>(t[e.colId]=0,t)),{}),o=e.toReversed(),s=[];for(let[t,l]of o.entries()){let o=e.length-t-1;l.children.length<=0?s.push(o):l.foreachCellInner((t=>{let e=s.reduce(((e,l)=>t.rowspan+o>l?e+1:e),0);t.rowspan-=e,i[t.colId]+=1}))}let n=0;for(let t of Object.values(i))if(0===t){let t=[],l=0;for(let i of Object.values(e)){let e=t.shift()||0,o=[];l>0?(o=i.getCellByColumIndex(n-e)[2],--l):(o=i.removeCell(n-e),o.skipRowNum&&(l+=o.skipRowNum));for(let[e,l]of o.entries())t[e]=(t[e]||0)+l}}else n+=1;for(let t of l)0===i[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(e){if(e.length<=0)return;let l=u(e[0],t.tableMain),i=l.getRows(),o=i.length,s=-1;for(let l of e){let e=u(l,t.tableRow),n=i.indexOf(e);n<o&&(o=n),n+l.rowspan>s&&(s=n+l.rowspan)}let n={};for(let t=o;t<Math.min(i.length,s);t++){let e=i[t];e.foreachCellInner((e=>{e.rowspan+t>s&&(n[e.colId]={rowspan:e.rowspan+t-s,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()})),0===e.length()&&e.remove()}if(i[s]){let t=i[s],e=l.tableId;for(let[l,{colIndex:i,colspan:o,rowspan:s}]of Object.entries(n))t.insertCell(i,{tableId:e,rowId:t.rowId,colId:l,colspan:o,rowspan:s})}this.fixTableByRemove(l)}removeCol(e){if(e.length<=0)return;let l=e[0],i=u(l,t.tableMain),o={};for(let t of e)o[t.rowId]||(o[t.rowId]=0),o[t.rowId]+=t.colspan;let s=Math.max(...Object.values(o)),n=l.getColumnIndex(),r=i.descendants(U);for(let t=0;t<s;t++){let t=[],e=0;for(let l of Object.values(r)){let i=t.shift()||0;if(e>0){--e;continue}let o=l.removeCell(n-i);o.skipRowNum&&(e+=o.skipRowNum);for(let[e,l]of o.entries())t[e]=(t[e]||0)+l}}let[a]=i.descendants(q);if(a)for(let t=0;t<s;t++)a.removeColByIndex(n);this.fixTableByRemove(i)}mergeCells(l){if(l.length<=1)return;let i=l[0],o=i.getTableBody(),s=i.getTableRow();if(!o||!s)return;for(let t=1;t<l.length;t++){let e=l[t],i=e.getTableBody();if(i&&i!==o){let t=e.getTableRow();t&&(s.parent.insertBefore(t,s.next),s=t)}}o.convertBody(i.wrapTag);let n=l.reduce(((t,e,l)=>{let i=e.colId;t[0][i]||(t[0][i]=0),t[0][i]+=e.rowspan;let o=e.rowId;return t[1][o]||(t[1][o]=0),t[1][o]+=e.colspan,0!==l&&(e.length()>1&&e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},i]),r=Math.max(...Object.values(n[0])),a=Math.max(...Object.values(n[1])),h=n[2];h.colspan=a,h.rowspan=r;let d=this.quill.getIndex(h);this.quill.setSelection({index:d,length:0},e.sources.SILENT);let c=u(h,t.tableMain);this.fixTableByRemove(c)}splitCell(e){if(1!==e.length)return;let l=e[0];if(1===l.colspan&&1===l.rowspan)return;let[i,o]=d(l,[t.tableMain,t.tableRow]),s=i.getRows(),n=i.tableId,r=l.getColumnIndex(),a=i.getColIds().slice(r,r+l.colspan).toReversed(),{emptyRow:h,...c}=l.formats()[t.tableCellInner],u=s.indexOf(o);if(-1===u)return;let p=s[u],m=l.rowspan;for(l.colspan=1,l.rowspan=1;p&&m>0;){for(let t of a)p===o&&t===l.colId||p.insertCell(r+(p===o?1:0),{...c,tableId:n,rowId:p.rowId,colId:t,rowspan:1,colspan:1});--m,u+=1,p=s[u]}}convertTableBodyByCells(t,e,l){let i,o,s=t.getRows();for(let t of e){let e=t.getTableRow();if(!e)continue;let l=s.indexOf(e);ae(i)&&(i=l),ae(o)&&(o=l),l<i?(o=i,i=l):l>o&&(o=l)}if(ae(i)||ae(o))return void console.warn("TableRow not found");let n=s[i],r=s[o];t.split(r.offset(t)+r.length());let a=t.split(n.offset(t)),h=a.getRows(),[d]=a.getBodys(),c=d.clone();a.appendChild(c);for(let t of h)t.length()>0&&c.appendChild(t);c.convertBody(l),d.remove()}},ci=si;export{kn as BlockEmbedOverride,Dn as BlockOverride,z as ContainerFormat,Fn as ScrollOverride,Yr as Scrollbar,Kn as TableAlign,V as TableBodyFormat,Bn as TableCaptionFormat,W as TableCellFormat,H as TableCellInnerFormat,mr as TableClipboard,G as TableColFormat,q as TableColgroupFormat,Gn as TableDomSelector,Hn as TableFootFormat,Un as TableHeadFormat,K as TableMainFormat,Pr as TableMenuCommon,Fr as TableMenuContextmenu,Ir as TableMenuSelect,Wr as TableResizeBox,Vr as TableResizeCommon,Br as TableResizeCommonHelper,Gr as TableResizeLine,Kr as TableResizeScale,U as TableRowFormat,Zr as TableSelection,si as TableUp,Xr as TableVirtualScrollbar,J as TableWrapperFormat,rr as applyCellUpdates,t as blotName,le as createColorPicker,T as createSelectBox,Qt as createTooltip,ci as default,ai as defaultCustomSelect,u as findParentBlot,d as findParentBlots,$n as getCellPositions,Rr as getColRect,Zn as getCountByPosition,Yn as getTableCellStructure,Y as getTableMainRect,er as groupCellByRow,zr as isCellsSpan,Lr as isTableAlignRight,Xn as parsePasteDelta,Jn as pasteCells,tr as pasteWithLoop,Qn as pasteWithStructure,nr as prepareCellUpdate,R as randomId,ir as removeOverlappingCells,X as tableMenuTools,r as tableUpEvent,i as tableUpInternal,n as tableUpSize,ii as updateTableConstants};
//# sourceMappingURL=/sm/a73d4877e05d9e9ae28eada09693741c3e03b7567fd23aa2a9341e5039750e2e.map