quill-table-up 2.1.9 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +41 -34
  2. package/dist/index.css +1 -1
  3. package/dist/index.d.ts +53 -17
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.umd.js +1 -1
  7. package/dist/index.umd.js.map +1 -1
  8. package/package.json +16 -16
  9. package/src/__tests__/e2e/editor-page.ts +6 -0
  10. package/src/__tests__/e2e/table-blots.test.ts +52 -0
  11. package/src/__tests__/e2e/table-caption.test.ts +93 -0
  12. package/src/__tests__/e2e/table-hack.test.ts +43 -0
  13. package/src/__tests__/e2e/table-resize.test.ts +136 -5
  14. package/src/__tests__/e2e/table-selection.test.ts +7 -10
  15. package/src/__tests__/e2e/utils.ts +2 -2
  16. package/src/__tests__/unit/table-blots.test.ts +223 -0
  17. package/src/__tests__/unit/table-caption.test.ts +237 -0
  18. package/src/__tests__/unit/table-clipboard.test.ts +6 -6
  19. package/src/__tests__/unit/table-hack.test.ts +137 -63
  20. package/src/__tests__/unit/table-insert.test.ts +4 -4
  21. package/src/__tests__/unit/table-redo-undo.test.ts +252 -3
  22. package/src/__tests__/unit/utils.test.ts +2 -2
  23. package/src/__tests__/unit/utils.ts +44 -25
  24. package/src/__tests__/unit/vitest.d.ts +0 -1
  25. package/src/formats/index.ts +1 -0
  26. package/src/formats/overrides/scroll.ts +6 -0
  27. package/src/formats/table-caption-format.ts +115 -0
  28. package/src/formats/table-cell-format.ts +63 -33
  29. package/src/formats/table-cell-inner-format.ts +3 -3
  30. package/src/formats/table-col-format.ts +16 -12
  31. package/src/formats/table-colgroup-format.ts +2 -2
  32. package/src/formats/table-main-format.ts +0 -9
  33. package/src/formats/table-wrapper-format.ts +2 -2
  34. package/src/modules/table-clipboard.ts +21 -3
  35. package/src/modules/table-menu/constants.ts +18 -2
  36. package/src/modules/table-menu/table-menu-common.ts +0 -5
  37. package/src/modules/table-resize/table-resize-box.ts +74 -31
  38. package/src/modules/table-resize/table-resize-common.ts +8 -7
  39. package/src/modules/table-resize/table-resize-scale.ts +12 -5
  40. package/src/modules/table-scrollbar.ts +12 -7
  41. package/src/modules/table-selection.ts +16 -19
  42. package/src/style/color-picker.less +4 -2
  43. package/src/style/index.less +19 -0
  44. package/src/style/table-resize.less +16 -1
  45. package/src/svg/arrow-up-down.svg +11 -0
  46. package/src/svg/auto-full.svg +11 -1
  47. package/src/svg/background.svg +10 -1
  48. package/src/svg/border.svg +10 -1
  49. package/src/svg/color.svg +10 -1
  50. package/src/svg/copy.svg +8 -1
  51. package/src/svg/cut.svg +7 -1
  52. package/src/svg/insert-bottom.svg +6 -1
  53. package/src/svg/insert-left.svg +6 -1
  54. package/src/svg/insert-right.svg +6 -1
  55. package/src/svg/insert-top.svg +6 -1
  56. package/src/svg/merge-cell.svg +6 -1
  57. package/src/svg/remove-column.svg +6 -1
  58. package/src/svg/remove-row.svg +6 -1
  59. package/src/svg/remove-table.svg +6 -1
  60. package/src/svg/split-cell.svg +6 -1
  61. package/src/svg/table-head.svg +4 -0
  62. package/src/table-up.ts +149 -112
  63. package/src/utils/bem.ts +2 -2
  64. package/src/utils/blot-helper.ts +12 -0
  65. package/src/utils/color.ts +12 -12
  66. package/src/utils/components/button.ts +2 -2
  67. package/src/utils/components/color-picker.ts +2 -2
  68. package/src/utils/components/dialog.ts +2 -2
  69. package/src/utils/components/input.ts +2 -2
  70. package/src/utils/components/table/creator.ts +2 -2
  71. package/src/utils/components/table/select-box.ts +2 -2
  72. package/src/utils/components/tooltip.ts +2 -2
  73. package/src/utils/constants.ts +5 -3
  74. package/src/utils/position.ts +2 -2
  75. package/src/utils/resize-observer-helper.ts +2 -2
  76. package/src/utils/transformer.ts +5 -0
  77. package/src/utils/transition-event-helper.ts +2 -2
  78. package/src/utils/types.ts +5 -1
  79. package/src/utils/utils.ts +2 -2
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("quill")):"function"==typeof define&&define.amd?define(["exports","quill"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TableUp={},t.Quill)}(this,(function(t,e){"use strict";const s={container:"table-up-container",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableBody:"table-up-body",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},o={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},i={AFTER_TABLE_RESIZE:"after-table-resize"},l={moduleName:"table-up"},n=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],r=new Set([s.tableCellInner]),a=t=>{return!(!t||!t.parent)&&(e=t.parent,!!r.has(e.statics.blotName)||a(t.parent));var e},c=(t,e="table-up")=>{const s=e?`${e}-`:"";return{b:()=>`${s}${t}`,be:e=>e?`${s}${t}__${e}`:"",bm:e=>e?`${s}${t}--${e}`:"",bem:(e,o)=>e&&o?`${s}${t}__${e}--${o}`:"",ns:t=>t?`${s}${t}`:"",bs:e=>e?`${s}${t}-${e}`:"",cv:t=>t?`--${s}${t}`:"",is:t=>`is-${t}`}};function d(t,e){let s=t.parent;for(;s&&s.statics.blotName!==e&&s!==t.scroll;)s=s.parent;if(s===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return s}function h(t,e){const s=new Array(e.length),o=new Map(e.map(((t,e)=>[t,e])));let i=t.parent;for(;i&&i!==t.scroll&&0!==o.size;){if(o.has(i.statics.blotName)){s[o.get(i.statics.blotName)]=i,o.delete(i.statics.blotName)}i=i.parent}if(o.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(o.keys()).join(", ")}`);return s}function u(t){const e=new Map;let s=t;for(;s&&"scroll"!==s.statics.blotName;)e.set(s.statics.blotName,s),s=s.parent;return e}function p(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}const b=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)},m=t=>({h:Math.min(360,Math.max(0,t.h)),s:Math.min(100,Math.max(0,t.s)),b:Math.min(100,Math.max(0,t.b)),a:Math.min(1,Math.max(0,t.a))}),f=t=>{let{r:e,g:s,b:o,a:i}=t;e=b(e,255),s=b(s,255),o=b(o,255);const l=Math.max(e,s,o),n=Math.min(e,s,o);let r;const a=l,c=l-n,d=0===l?0:c/l;if(l===n)r=0;else{switch(l){case e:r=(s-o)/c+(s<o?6:0);break;case s:r=(o-e)/c+2;break;case o:r=(e-s)/c+4}r/=6}return{h:360*r,s:100*d,b:100*a,a:i}},g=t=>{let{h:e,s:s,b:o,a:i}=t;e=6*b(e,360),s=b(s,100),o=b(o,100);const l=Math.floor(e),n=e-l,r=o*(1-s),a=o*(1-n*s),c=o*(1-(1-n)*s),d=l%6,h=[o,a,r,r,c,o][d],u=[c,o,o,a,r,r][d],p=[r,r,c,o,o,a][d];return{r:Math.round(255*h),g:Math.round(255*u),b:Math.round(255*p),a:i}},w=t=>{const e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(const t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")},v=t=>w(g(t)),C=t=>"function"==typeof t,x=Array.isArray,y=t=>"string"==typeof t,M=t=>null!==t&&"object"==typeof t,I=t=>{const{type:e="default",content:s}=t||{},o=c("button"),i=document.createElement("button");return i.classList.add(o.b(),e),s&&(y(s)?i.textContent=s:i.appendChild(s)),i},T=(t={})=>{const e=230,s=150,o=10;let i=f((l=(l=t.color||"#ff0000").startsWith("#")?l.slice(1):l,{r:Number.parseInt(l.slice(0,2),16),g:Number.parseInt(l.slice(2,4),16),b:Number.parseInt(l.slice(4,6),16),a:Number((Number.parseInt(l.slice(6,8)||"ff",16)/255).toFixed(2))}));var l;const n=c("color-picker"),r=document.createElement("div");r.classList.add(n.b());const a=document.createElement("div");a.classList.add(n.be("content"));const d=document.createElement("div");d.classList.add(n.be("selector"));const h=document.createElement("div");h.classList.add(n.be("background")),d.appendChild(h);const u=document.createElement("div");u.classList.add(n.be("background-handle")),h.appendChild(u);const p=document.createElement("div");p.classList.add(n.be("alpha"));const b=document.createElement("div");b.classList.add(n.be("alpha-bg"));const C=document.createElement("div");C.classList.add(n.be("alpha-handle")),p.appendChild(b),p.appendChild(C);const x=document.createElement("div");x.classList.add(n.be("hue"));const y=document.createElement("div");y.classList.add(n.be("hue-handle")),x.appendChild(y);const M=document.createElement("div");M.classList.add(n.be("action"));const[I,T,N,L]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(n.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const o=document.createElement("input");return o.classList.add(n.be("input")),o.addEventListener("input",(()=>{o.value=o.value.replaceAll(/[^0-9]/g,"")})),o.addEventListener("change",(()=>{let e=Math.round(Number(o.value));"a"===t&&(e/=100);O(m(f(Object.assign({},g(i),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(o),M.appendChild(e),o}));a.appendChild(x),a.appendChild(d),a.appendChild(p),r.appendChild(a),r.appendChild(M);let E=!1,S=!1,B=!1;function R(){const t=v(i);for(const[e,s]of[I,T,N].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));L.value=String((100*i.a).toFixed(0))}function k(){Object.assign(u.style,{left:`${Math.floor(e*i.s/100)}px`,top:`${Math.floor(s*(100-i.b)/100)}px`}),d.style.backgroundColor=`#${w(g({h:i.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*i.h/360)}px`,C.style.left=100*i.a+"%",function(){const{r:t,g:e,b:s}=g(i);b.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),R()}function O(e){i=m(Object.assign({},i,e)),R(),t.onChange&&t.onChange(`#${v(i)}`)}function A(t){const o=d.getBoundingClientRect(),i=o.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),l=o.left+document.body.scrollLeft;O({s:Math.floor(100*Math.max(0,Math.min(e,t.pageX-l))/e),b:Math.floor(100*(s-Math.max(0,Math.min(s,t.pageY-i)))/s)}),k()}function z(t){const e=x.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);O({h:Math.floor(360*(s-Math.max(0,Math.min(s,t.pageY-e)))/s)}),k()}function q(t){const{pageX:e}=t,s=p.getBoundingClientRect();let i=e-s.left;i=Math.max(o/2,i),i=Math.min(i,s.width-o/2),O({a:Math.round((i-5)/(s.width-10)*100)/100}),k()}function $(t){E&&(t.preventDefault(),A(t)),S&&(t.preventDefault(),z(t)),B&&(t.preventDefault(),q(t))}function W(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",W),E=!1}function H(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",H),S=!1}function D(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",D),B=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",W),E=!0,A(t)})),x.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",H),S=!0,z(t)})),p.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",D),B=!0,q(t)})),k(),r};let N=8e3;const L=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const o=c("dialog"),i=e,l=document.createElement("div");l.classList.add(o.b()),l.style.zIndex=String(N);const n=document.createElement("div");if(n.classList.add(o.be("overlay")),l.appendChild(n),t){const e=document.createElement("div");e.classList.add(o.be("content")),e.appendChild(t),n.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const r=getComputedStyle(i).overflow;i.style.overflow="hidden",i.appendChild(l);const a=()=>{s(),l.remove(),i.style.overflow=r};return l.addEventListener("click",a),N+=1,{dialog:l,close:a}},E=(t,e)=>{const s=c("input");e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,o.appendChild(e)}const i=document.createElement("div");i.classList.add(s.be("input"));const l=document.createElement("input");for(const t in e)l.setAttribute(t,e[t]);(e.max||e.min)&&l.addEventListener("blur",(()=>{e.max&&e.max<=Number(l.value)&&(l.value=String(e.max)),e.min&&e.min>=Number(l.value)&&(l.value=String(e.min))})),i.appendChild(l),o.appendChild(i),l.addEventListener("focus",(()=>{i.classList.add("focus")})),l.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:o,input:l,errorTip:t=>{let e;i.classList.contains("error")?e=i.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),i.appendChild(e)),e.textContent=t,i.classList.add("error");return{removeError:()=>{i.classList.remove("error"),e.remove()}}}}},S=(t={})=>{const e=c("select-box"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("block"));for(let s=0;s<(t.row||8);s++)for(let i=0;i<(t.col||8);i++){const t=document.createElement("div");t.classList.add(e.be("item")),t.dataset.row=String(s+1),t.dataset.col=String(i+1),o.appendChild(t)}const i=()=>{const{row:t,col:e}=s.dataset;for(const t of Array.from(o.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;const i=Array.from(o.children);for(let s=0;s<i.length;s++){const{row:o,col:l}=i[s].dataset;if(o>t&&l>e)return;o<=t&&l<=e?i[s].classList.add("active"):i[s].classList.remove("active")}};if(o.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:e,col:o}=t.target.dataset;e&&o&&(s.dataset.row=e,s.dataset.col=o,i())})),o.addEventListener("mouseleave",(()=>{s.removeAttribute("data-row"),s.removeAttribute("data-col"),i()})),o.addEventListener("click",(()=>{const{row:e,col:o}=s.dataset;e&&o&&t.onSelect&&t.onSelect(Number(e),Number(o))})),s.appendChild(o),t.customBtn){const o=t.texts||{},i=document.createElement("div");i.classList.add(e.be("custom")),i.textContent=o.customBtnText||"Custom",i.addEventListener("click",(async()=>{const e=await(async(t={})=>{const e=c("creator"),s=document.createElement("div");s.classList.add(e.b());const o=document.createElement("div");o.classList.add(e.be("input"));const{item:i,input:l,errorTip:n}=E(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:r,input:a,errorTip:d}=E(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});o.appendChild(i),o.appendChild(r),s.appendChild(o);const h=document.createElement("div");h.classList.add(e.be("control"));const u=I({type:"confirm",content:t.confirmText||"Confirm"}),p=I({type:"default",content:t.cancelText||"Cancel"});h.appendChild(u),h.appendChild(p),s.appendChild(h);const b=(e=Number(l.value),s=Number(a.value))=>{if(Number.isNaN(e)||e<=0)n(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(s)||s<=0))return{row:e,col:s};d(t.notPositiveNumberError||"Please enter a positive integer")}},m=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",m))};return new Promise(((t,e)=>{const{close:o}=L({child:s,beforeClose:e});l.focus();for(const e of[l,a])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=b();e&&(t(e),o())}}));u.addEventListener("click",(async()=>{const e=b();e&&(t(e),o())})),document.addEventListener("keydown",m),p.addEventListener("click",o)}))})(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(i)}return s},B=Math.min,R=Math.max,k=Math.round,O=Math.floor,A=t=>({x:t,y:t}),z={left:"right",right:"left",bottom:"top",top:"bottom"},q={start:"end",end:"start"};function $(t,e,s){return R(t,B(e,s))}function W(t,e){return"function"==typeof t?t(e):t}function H(t){return t.split("-")[0]}function D(t){return t.split("-")[1]}function F(t){return"x"===t?"y":"x"}function j(t){return"y"===t?"height":"width"}function P(t){return["top","bottom"].includes(H(t))?"y":"x"}function V(t){return F(P(t))}function _(t){return t.replace(/start|end/g,(t=>q[t]))}function X(t){return t.replace(/left|right|bottom|top/g,(t=>z[t]))}function U(t){const{x:e,y:s,width:o,height:i}=t;return{width:o,height:i,top:s,left:e,right:e+o,bottom:s+i,x:e,y:s}}function Y(t,e,s){let{reference:o,floating:i}=t;const l=P(e),n=V(e),r=j(n),a=H(e),c="y"===l,d=o.x+o.width/2-i.width/2,h=o.y+o.height/2-i.height/2,u=o[r]/2-i[r]/2;let p;switch(a){case"top":p={x:d,y:o.y-i.height};break;case"bottom":p={x:d,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:h};break;case"left":p={x:o.x-i.width,y:h};break;default:p={x:o.x,y:o.y}}switch(D(e)){case"start":p[n]-=u*(s&&c?-1:1);break;case"end":p[n]+=u*(s&&c?-1:1)}return p}async function G(t,e){var s;void 0===e&&(e={});const{x:o,y:i,platform:l,rects:n,elements:r,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:u=!1,padding:p=0}=W(e,t),b=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),m=r[u?"floating"===h?"reference":"floating":h],f=U(await l.getClippingRect({element:null==(s=await(null==l.isElement?void 0:l.isElement(m)))||s?m:m.contextElement||await(null==l.getDocumentElement?void 0:l.getDocumentElement(r.floating)),boundary:c,rootBoundary:d,strategy:a})),g="floating"===h?{x:o,y:i,width:n.floating.width,height:n.floating.height}:n.reference,w=await(null==l.getOffsetParent?void 0:l.getOffsetParent(r.floating)),v=await(null==l.isElement?void 0:l.isElement(w))&&await(null==l.getScale?void 0:l.getScale(w))||{x:1,y:1},C=U(l.convertOffsetParentRelativeRectToViewportRelativeRect?await l.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-C.top+b.top)/v.y,bottom:(C.bottom-f.bottom+b.bottom)/v.y,left:(f.left-C.left+b.left)/v.x,right:(C.right-f.right+b.right)/v.x}}function Z(){return"undefined"!=typeof window}function K(t){return tt(t)?(t.nodeName||"").toLowerCase():"#document"}function Q(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function J(t){var e;return null==(e=(tt(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function tt(t){return!!Z()&&(t instanceof Node||t instanceof Q(t).Node)}function et(t){return!!Z()&&(t instanceof Element||t instanceof Q(t).Element)}function st(t){return!!Z()&&(t instanceof HTMLElement||t instanceof Q(t).HTMLElement)}function ot(t){return!(!Z()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof Q(t).ShadowRoot)}function it(t){const{overflow:e,overflowX:s,overflowY:o,display:i}=dt(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+s)&&!["inline","contents"].includes(i)}function lt(t){return["table","td","th"].includes(K(t))}function nt(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function rt(t){const e=at(),s=et(t)?dt(t):t;return["transform","translate","scale","rotate","perspective"].some((t=>!!s[t]&&"none"!==s[t]))||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","translate","scale","rotate","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function at(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function ct(t){return["html","body","#document"].includes(K(t))}function dt(t){return Q(t).getComputedStyle(t)}function ht(t){return et(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function ut(t){if("html"===K(t))return t;const e=t.assignedSlot||t.parentNode||ot(t)&&t.host||J(t);return ot(e)?e.host:e}function pt(t){const e=ut(t);return ct(e)?t.ownerDocument?t.ownerDocument.body:t.body:st(e)&&it(e)?e:pt(e)}function bt(t,e,s){var o;void 0===e&&(e=[]),void 0===s&&(s=!0);const i=pt(t),l=i===(null==(o=t.ownerDocument)?void 0:o.body),n=Q(i);if(l){const t=mt(n);return e.concat(n,n.visualViewport||[],it(i)?i:[],t&&s?bt(t):[])}return e.concat(i,bt(i,[],s))}function mt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function ft(t){const e=dt(t);let s=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const i=st(t),l=i?t.offsetWidth:s,n=i?t.offsetHeight:o,r=k(s)!==l||k(o)!==n;return r&&(s=l,o=n),{width:s,height:o,$:r}}function gt(t){return et(t)?t:t.contextElement}function wt(t){const e=gt(t);if(!st(e))return A(1);const s=e.getBoundingClientRect(),{width:o,height:i,$:l}=ft(e);let n=(l?k(s.width):s.width)/o,r=(l?k(s.height):s.height)/i;return n&&Number.isFinite(n)||(n=1),r&&Number.isFinite(r)||(r=1),{x:n,y:r}}const vt=A(0);function Ct(t){const e=Q(t);return at()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:vt}function xt(t,e,s,o){void 0===e&&(e=!1),void 0===s&&(s=!1);const i=t.getBoundingClientRect(),l=gt(t);let n=A(1);e&&(o?et(o)&&(n=wt(o)):n=wt(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==Q(t))&&e}(l,s,o)?Ct(l):A(0);let a=(i.left+r.x)/n.x,c=(i.top+r.y)/n.y,d=i.width/n.x,h=i.height/n.y;if(l){const t=Q(l),e=o&&et(o)?Q(o):o;let s=t,i=mt(s);for(;i&&o&&e!==s;){const t=wt(i),e=i.getBoundingClientRect(),o=dt(i),l=e.left+(i.clientLeft+parseFloat(o.paddingLeft))*t.x,n=e.top+(i.clientTop+parseFloat(o.paddingTop))*t.y;a*=t.x,c*=t.y,d*=t.x,h*=t.y,a+=l,c+=n,s=Q(i),i=mt(s)}}return U({width:d,height:h,x:a,y:c})}function yt(t,e){const s=ht(t).scrollLeft;return e?e.left+s:xt(J(t)).left+s}function Mt(t,e,s){void 0===s&&(s=!1);const o=t.getBoundingClientRect();return{x:o.left+e.scrollLeft-(s?0:yt(t,o)),y:o.top+e.scrollTop}}function It(t,e,s){let o;if("viewport"===e)o=function(t,e){const s=Q(t),o=J(t),i=s.visualViewport;let l=o.clientWidth,n=o.clientHeight,r=0,a=0;if(i){l=i.width,n=i.height;const t=at();(!t||t&&"fixed"===e)&&(r=i.offsetLeft,a=i.offsetTop)}return{width:l,height:n,x:r,y:a}}(t,s);else if("document"===e)o=function(t){const e=J(t),s=ht(t),o=t.ownerDocument.body,i=R(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),l=R(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let n=-s.scrollLeft+yt(t);const r=-s.scrollTop;return"rtl"===dt(o).direction&&(n+=R(e.clientWidth,o.clientWidth)-i),{width:i,height:l,x:n,y:r}}(J(t));else if(et(e))o=function(t,e){const s=xt(t,!0,"fixed"===e),o=s.top+t.clientTop,i=s.left+t.clientLeft,l=st(t)?wt(t):A(1);return{width:t.clientWidth*l.x,height:t.clientHeight*l.y,x:i*l.x,y:o*l.y}}(e,s);else{const s=Ct(t);o={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return U(o)}function Tt(t,e){const s=ut(t);return!(s===e||!et(s)||ct(s))&&("fixed"===dt(s).position||Tt(s,e))}function Nt(t,e,s){const o=st(e),i=J(e),l="fixed"===s,n=xt(t,!0,l,e);let r={scrollLeft:0,scrollTop:0};const a=A(0);if(o||!o&&!l)if(("body"!==K(e)||it(i))&&(r=ht(e)),o){const t=xt(e,!0,l,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=yt(i));const c=!i||o||l?A(0):Mt(i,r);return{x:n.left+r.scrollLeft-a.x-c.x,y:n.top+r.scrollTop-a.y-c.y,width:n.width,height:n.height}}function Lt(t){return"static"===dt(t).position}function Et(t,e){if(!st(t)||"fixed"===dt(t).position)return null;if(e)return e(t);let s=t.offsetParent;return J(t)===s&&(s=s.ownerDocument.body),s}function St(t,e){const s=Q(t);if(nt(t))return s;if(!st(t)){let e=ut(t);for(;e&&!ct(e);){if(et(e)&&!Lt(e))return e;e=ut(e)}return s}let o=Et(t,e);for(;o&&lt(o)&&Lt(o);)o=Et(o,e);return o&&ct(o)&&Lt(o)&&!rt(o)?s:o||function(t){let e=ut(t);for(;st(e)&&!ct(e);){if(rt(e))return e;if(nt(e))return null;e=ut(e)}return null}(t)||s}const Bt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:o,strategy:i}=t;const l="fixed"===i,n=J(o),r=!!e&&nt(e.floating);if(o===n||r&&l)return s;let a={scrollLeft:0,scrollTop:0},c=A(1);const d=A(0),h=st(o);if((h||!h&&!l)&&(("body"!==K(o)||it(n))&&(a=ht(o)),st(o))){const t=xt(o);c=wt(o),d.x=t.x+o.clientLeft,d.y=t.y+o.clientTop}const u=!n||h||l?A(0):Mt(n,a,!0);return{width:s.width*c.x,height:s.height*c.y,x:s.x*c.x-a.scrollLeft*c.x+d.x+u.x,y:s.y*c.y-a.scrollTop*c.y+d.y+u.y}},getDocumentElement:J,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:o,strategy:i}=t;const l=[..."clippingAncestors"===s?nt(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let o=bt(t,[],!1).filter((t=>et(t)&&"body"!==K(t))),i=null;const l="fixed"===dt(t).position;let n=l?ut(t):t;for(;et(n)&&!ct(n);){const e=dt(n),s=rt(n);s||"fixed"!==e.position||(i=null),(l?!s&&!i:!s&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||it(n)&&!s&&Tt(t,n))?o=o.filter((t=>t!==n)):i=e,n=ut(n)}return e.set(t,o),o}(e,this._c):[].concat(s),o],n=l[0],r=l.reduce(((t,s)=>{const o=It(e,s,i);return t.top=R(o.top,t.top),t.right=B(o.right,t.right),t.bottom=B(o.bottom,t.bottom),t.left=R(o.left,t.left),t}),It(e,n,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:St,getElementRects:async function(t){const e=this.getOffsetParent||St,s=this.getDimensions,o=await s(t.floating);return{reference:Nt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:s}=ft(t);return{width:e,height:s}},getScale:wt,isElement:et,isRTL:function(t){return"rtl"===dt(t).direction}};function Rt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function kt(t,e,s,o){void 0===o&&(o={});const{ancestorScroll:i=!0,ancestorResize:l=!0,elementResize:n="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=o,c=gt(t),d=i||l?[...c?bt(c):[],...bt(e)]:[];d.forEach((t=>{i&&t.addEventListener("scroll",s,{passive:!0}),l&&t.addEventListener("resize",s)}));const h=c&&r?function(t,e){let s,o=null;const i=J(t);function l(){var t;clearTimeout(s),null==(t=o)||t.disconnect(),o=null}return function n(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),l();const c=t.getBoundingClientRect(),{left:d,top:h,width:u,height:p}=c;if(r||e(),!u||!p)return;const b={rootMargin:-O(h)+"px "+-O(i.clientWidth-(d+u))+"px "+-O(i.clientHeight-(h+p))+"px "+-O(d)+"px",threshold:R(0,B(1,a))||1};let m=!0;function f(e){const o=e[0].intersectionRatio;if(o!==a){if(!m)return n();o?n(!1,o):s=setTimeout((()=>{n(!1,1e-7)}),1e3)}1!==o||Rt(c,t.getBoundingClientRect())||n(),m=!1}try{o=new IntersectionObserver(f,{...b,root:i.ownerDocument})}catch(t){o=new IntersectionObserver(f,b)}o.observe(t)}(!0),l}(c,s):null;let u,p=-1,b=null;n&&(b=new ResizeObserver((t=>{let[o]=t;o&&o.target===c&&b&&(b.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame((()=>{var t;null==(t=b)||t.observe(e)}))),s()})),c&&!a&&b.observe(c),b.observe(e));let m=a?xt(t):null;return a&&function e(){const o=xt(t);m&&!Rt(m,o)&&s();m=o,u=requestAnimationFrame(e)}(),s(),()=>{var t;d.forEach((t=>{i&&t.removeEventListener("scroll",s),l&&t.removeEventListener("resize",s)})),null==h||h(),null==(t=b)||t.disconnect(),b=null,a&&cancelAnimationFrame(u)}}const Ot=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var s,o;const{x:i,y:l,placement:n,middlewareData:r}=e,a=await async function(t,e){const{placement:s,platform:o,elements:i}=t,l=await(null==o.isRTL?void 0:o.isRTL(i.floating)),n=H(s),r=D(s),a="y"===P(s),c=["left","top"].includes(n)?-1:1,d=l&&a?-1:1,h=W(e,t);let{mainAxis:u,crossAxis:p,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return r&&"number"==typeof b&&(p="end"===r?-1*b:b),a?{x:p*d,y:u*c}:{x:u*c,y:p*d}}(e,t);return n===(null==(s=r.offset)?void 0:s.placement)&&null!=(o=r.arrow)&&o.alignmentOffset?{}:{x:i+a.x,y:l+a.y,data:{...a,placement:n}}}}},At=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:s,y:o,placement:i}=e,{mainAxis:l=!0,crossAxis:n=!1,limiter:r={fn:t=>{let{x:e,y:s}=t;return{x:e,y:s}}},...a}=W(t,e),c={x:s,y:o},d=await G(e,a),h=P(H(i)),u=F(h);let p=c[u],b=c[h];if(l){const t="y"===u?"bottom":"right";p=$(p+d["y"===u?"top":"left"],p,p-d[t])}if(n){const t="y"===h?"bottom":"right";b=$(b+d["y"===h?"top":"left"],b,b-d[t])}const m=r.fn({...e,[u]:p,[h]:b});return{...m,data:{x:m.x-s,y:m.y-o,enabled:{[u]:l,[h]:n}}}}}},zt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var s,o;const{placement:i,middlewareData:l,rects:n,initialPlacement:r,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:u,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:m=!0,...f}=W(t,e);if(null!=(s=l.arrow)&&s.alignmentOffset)return{};const g=H(i),w=P(r),v=H(r)===r,C=await(null==a.isRTL?void 0:a.isRTL(c.floating)),x=u||(v||!m?[X(r)]:function(t){const e=X(t);return[_(t),e,_(e)]}(r)),y="none"!==b;!u&&y&&x.push(...function(t,e,s,o){const i=D(t);let l=function(t,e,s){const o=["left","right"],i=["right","left"],l=["top","bottom"],n=["bottom","top"];switch(t){case"top":case"bottom":return s?e?i:o:e?o:i;case"left":case"right":return e?l:n;default:return[]}}(H(t),"start"===s,o);return i&&(l=l.map((t=>t+"-"+i)),e&&(l=l.concat(l.map(_)))),l}(r,m,b,C));const M=[r,...x],I=await G(e,f),T=[];let N=(null==(o=l.flip)?void 0:o.overflows)||[];if(d&&T.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const o=D(t),i=V(t),l=j(i);let n="x"===i?o===(s?"end":"start")?"right":"left":"start"===o?"bottom":"top";return e.reference[l]>e.floating[l]&&(n=X(n)),[n,X(n)]}(i,n,C);T.push(I[t[0]],I[t[1]])}if(N=[...N,{placement:i,overflows:T}],!T.every((t=>t<=0))){var L,E;const t=((null==(L=l.flip)?void 0:L.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:N},reset:{placement:e}};let s=null==(E=N.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:E.placement;if(!s)switch(p){case"bestFit":{var S;const t=null==(S=N.filter((t=>{if(y){const e=P(t.placement);return e===w||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:S[0];t&&(s=t);break}case"initialPlacement":s=r}if(i!==s)return{reset:{placement:s}}}return{}}}},qt=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:s,y:o,placement:i,rects:l,middlewareData:n}=e,{offset:r=0,mainAxis:a=!0,crossAxis:c=!0}=W(t,e),d={x:s,y:o},h=P(i),u=F(h);let p=d[u],b=d[h];const m=W(r,e),f="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const t="y"===u?"height":"width",e=l.reference[u]-l.floating[t]+f.mainAxis,s=l.reference[u]+l.reference[t]-f.mainAxis;p<e?p=e:p>s&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(H(i)),s=l.reference[h]-l.floating[t]+(e&&(null==(g=n.offset)?void 0:g[h])||0)+(e?0:f.crossAxis),o=l.reference[h]+l.reference[t]+(e?0:(null==(w=n.offset)?void 0:w[h])||0)-(e?f.crossAxis:0);b<s?b=s:b>o&&(b=o)}return{[u]:p,[h]:b}}}},$t=(t,e,s)=>{const o=new Map,i={platform:Bt,...s},l={...i.platform,_c:o};return(async(t,e,s)=>{const{placement:o="bottom",strategy:i="absolute",middleware:l=[],platform:n}=s,r=l.filter(Boolean),a=await(null==n.isRTL?void 0:n.isRTL(e));let c=await n.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:h}=Y(c,o,a),u=o,p={},b=0;for(let s=0;s<r.length;s++){const{name:l,fn:m}=r[s],{x:f,y:g,data:w,reset:v}=await m({x:d,y:h,initialPlacement:o,placement:u,strategy:i,middlewareData:p,rects:c,platform:n,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[l]:{...p[l],...w}},v&&b<=50&&(b++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(c=!0===v.rects?await n.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:d,y:h}=Y(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:l})};let Wt;const Ht=(t,e={})=>{const{msg:s="",delay:o=150,content:i,direction:l="bottom",type:n="hover",container:r,onOpen:a,onClose:d,closed:h,onDestroy:u}=e,p=c("tooltip");if(s||i){Wt||(Wt=document.createElement("div"),document.body.appendChild(Wt));const e=r||Wt,c=document.createElement("div");let b,m,f;c.classList.add(p.b(),"hidden","transparent"),i?c.appendChild(i):s&&(c.textContent=s);const g=()=>{f&&f(),$t(t,c,{placement:l,middleware:[zt(),At({limiter:qt()}),Ot(4)]}).then((({x:t,y:e})=>{Object.assign(c.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{c.classList.add("hidden"),e.contains(c)&&e.removeChild(c),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(a){const t=a(s);if(!s&&t)return}e.appendChild(c),c.removeEventListener("transitionend",w),c.classList.remove("hidden"),f=kt(t,c,g),c.classList.remove("transparent")}),o)},C=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}((t,e,s,o,i)=>{t.addEventListener("transitionend",s,o),setTimeout((()=>{s()}),e)})(c,150,w,{once:!0}),c.classList.add("transparent")}),o)},x=()=>{const e=t=>{t.stopPropagation(),C(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{c.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{C(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,c],s=C.bind(void 0,!1),o=v.bind(void 0,!1);return{prepare:()=>{for(const t of e)t.addEventListener("mouseenter",o),t.addEventListener("mouseleave",s)},show:v,hide:C,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",o),t.removeEventListener("mouseleave",s)}}},click:x},{prepare:M,show:I,hide:T,destroy:N}=y[n]();M();const L=()=>{T(!0),u&&u(),N(),f&&f(),c.remove()};return{show:I,hide:T,destroy:L}}return null};function Dt(t,e,s=0,o=!0){const{x:i,y:l,x1:n,y1:r}=t,{x:a,y:c,x1:d,y1:h}=e;let u,p;return o?(u=n<a+s||i-s>d,p=r<c+s||l-s>h):(u=n<=a+s||i-s>=d,p=r<=c+s||l-s>=h),!(u||p)}const Ft=t=>{let{left:e,top:s,width:o,height:i}=t;const{clientWidth:l,clientHeight:n}=document.documentElement;let r=!1,a=!1;return e+o>l?(e=l-o-8,r=!0):e<0&&(e=8,r=!0),s+i>n?(s=n-i-8,a=!0):s<0&&(s=8,a=!0),{left:e,top:s,leftLimited:r,topLimited:a}},jt=(t,e={})=>{const s=Symbol("ignoreFirstBind"),o=new Set,i=new ResizeObserver((o=>{e.ignoreFirstBind&&o.some((t=>{const e=t.target,o=e[s];return e[s]=!0,!o}))||t(o)})),l=i.observe;i.observe=(t,e)=>{o.add(t),l.call(i,t,e)};const n=i.unobserve;i.unobserve=t=>{o.has(t)&&(o.delete(t),t[s]=void 0),n.call(i,t)};const r=i.disconnect;return i.disconnect=()=>{for(const t of o.values())t[s]=void 0;r.call(i)},i};function Pt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Vt(){for(let t=0;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}const _t=()=>Math.random().toString(36).slice(2),Xt=(t,e)=>{let s;return function(...o){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,o)}),e)}},Ut=e.import("parchment"),Yt=e.import("blots/container"),Gt=e.import("blots/block"),Zt=e.import("blots/block/embed");class Kt extends Yt{static tagName;static blotName=s.container;static scope=Ut.Scope.BLOCK_BLOT;static allowedChildren=[Gt,Zt,Yt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,s){const[o]=this.children.find(t);if(!o){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,s)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}enforceAllowedChildren(){this.children.forEach((t=>{this.statics.allowedChildren.some((e=>t instanceof e))||(t.statics.scope===Ut.Scope.BLOCK_BLOT?(t.parent instanceof Kt?(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 Ut.ParentBlot?t.unwrap():t.remove())}))}}const Qt=e.import("parchment"),Jt=e.import("blots/block");class te extends Jt{replaceWith(t,e){const o="string"==typeof t?this.scroll.create(t,e):t;if(o instanceof Qt.ParentBlot){if(o.statics.blotName===s.tableCellInner){const t=this.parent;if(t.statics.blotName===s.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),t.statics.blotName===s.tableCellInner){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.remove(),t.parent.statics.blotName===s.tableCell&&0===t.parent.length()&&t.parent.remove();const e=t.parent.parent;e.statics.blotName===s.tableRow&&0===e.children.length&&e.remove()}}else null!=t&&t.insertBefore(o,this.next),o.appendChild(this);return o}this.moveChildren(o)}return null!=this.parent&&(this.parent.insertBefore(o,this.next||void 0),this.remove()),this.attributes.copy(o),o}format(t,e){if(t!==s.tableCellInner||this.parent.statics.blotName!==t||e)super.format(t,e);else try{d(this,s.tableCellInner).unwrap()}catch{console.error("unwrap TableCellInner error")}}}const ee=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},se=e.import("blots/block"),oe=e.import("blots/block/embed");class ie extends Kt{static blotName=s.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan"]);static defaultChild=se;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:l,style:n}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=o,r.dataset.rowspan=String(ee(i)),r.dataset.colspan=String(ee(l)),n&&(r.dataset.style=n),r}static formats(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:l,style:n}=t.dataset,r={tableId:e,rowId:s,colId:o,rowspan:Number(ee(i)),colspan:Number(ee(l))};return n&&(r.style=n),r}constructor(t,e,s){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled()))}setFormatValue(t,e,o=!1){if(o){if(!this.statics.isAllowStyle(t))return;this.parent&&this.parent.statics.blotName===s.tableCell&&this.parent.setFormatValue(t,e)}else{if(!this.statics.allowDataAttrs.has(t))return;const o=`data-${t}`;e?this.domNode.setAttribute(o,e):this.domNode.removeAttribute(o),this.parent&&this.parent.statics.blotName===s.tableCell&&this.parent.setFormatValue(t,e)}const i=this.descendants(se,0);for(const t of i)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(t){this.setFormatValue("row-id",t)}get colId(){return this.domNode.dataset.colId}set colId(t){this.setFormatValue("col-id",t)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(t){this.setFormatValue("rowspan",t)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(t){this.setFormatValue("colspan",t)}getColumnIndex(){return d(this,s.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,o){if(0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,o),o&&o.style){const t=function(t){const e={},s=t.trim().split(";");for(let t=0;t<s.length;t++){const o=s[t].trim();if(!o)continue;const i=o.indexOf(":");if(-1===i)continue;const l=o.slice(0,Math.max(0,i)).trim(),n=o.slice(Math.max(0,i+1)).trim();e[l]=n}return e}(o.style);for(const[e,s]of Object.entries(t))this.setFormatValue(e,s,!0)}}formats(){const t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:o}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===s&&i.rowspan===o}optimize(){const t=this.parent,e=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof oe){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==s.tableCell&&(this.wrap(s.tableCell,e),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,e){if(t.statics.blotName===this.statics.blotName){const o=t,i=this.statics.formats(o.domNode),l=this.statics.formats(this.domNode);if(Object.entries(l).every((([t,e])=>e===i[t])))return this.parent.insertBefore(o,this.next);{const[t,n]=h(this,[s.tableRow,s.tableCell]);if(e){const o=e.offset();if(o+1<this.length()){const e=this.scroll.create(s.tableCellInner,l);this.children.forEachAt(o+1,this.length(),(t=>{e.appendChild(t)})),t.insertBefore(e.wrap(s.tableCell,l),n.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(e){const s=e.offset(t);t.split(s)}else if(n.next){const e=n.next.offset(t);t.split(e)}const l=this.scroll.create(s.tableRow,i),r=this.scroll.create(s.tableCell,i);return r.appendChild(o),l.appendChild(r),t.parent.insertBefore(l,t.next)}return t.insertBefore(o.wrap(s.tableCell,i),e?n:n.next)}}super.insertBefore(t,e)}}const le=e.import("parchment"),ne=e.import("blots/scroll");class re extends ne{enable(t=!0){const o=e.import(`formats/${s.tableCellInner}`),i=this.domNode.querySelectorAll(`.${o.className}`);for(const e of Array.from(i))e.setAttribute("contenteditable",String(!!t));super.enable(t)}createBlock(t,e){let o,i={};if(t[s.tableCellInner])o=s.tableCellInner;else for(const[e,s]of Object.entries(t)){null!=this.query(e,le.Scope.BLOCK&le.Scope.BLOT)?o=e:i[e]=s}o===s.tableCellInner&&(i={...t},delete i[o]);const l=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(l,e||void 0);let n=l.length();l instanceof ie&&0===n&&(n+=1);for(const[t,e]of Object.entries(i))l.formatAt(0,n,t,e);return l}}class ae extends Kt{static blotName=s.tableRow;static tagName="tr";static className="ql-table-row";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,e.dataset.rowId=t.rowId,e}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}getCellByColId(t,e){const o=d(this,s.tableMain).getColIds(),i=o.indexOf(t),l=this.children.iterator();let n=null;for(;n=l();){if(n.colId===t)return n;const e=o.indexOf(n.colId);if(e<i&&e+n.colspan>i)return n}return this[e]&&this[e].statics.blotName===s.tableRow?this[e].getCellByColId(t,e):null}insertCell(t,e){const o=[],i=this.children.iterator();let l,n=0;for(;(l=i())&&(n+=l.colspan,!(n>t));)if(1!==l.rowspan)for(let t=0;t<l.rowspan-1;t++)o[t]=(o[t]||0)+l.colspan;if(l&&n-l.colspan<t){l.getCellInner().colspan+=1,1!==l.rowspan&&(o.skipRowNum=l.rowspan-1)}else{const t=this.scroll.create(s.tableCell,e),o=this.scroll.create(s.tableCellInner,e),i=this.scroll.create("block");i.appendChild(this.scroll.create("break")),o.appendChild(i),t.appendChild(o),this.insertBefore(t,l)}return o}getCellByColumIndex(t){const e=[];let s=null,o=0;if(t<0)return[s,o,e];const i=this.children.iterator();for(;s=i();){if(o+=s.colspan,1!==s.rowspan)for(let t=0;t<s.rowspan-1;t++)e[t]=(e[t]||0)+s.colspan;if(o>t)break}return[s,o,e]}removeCell(t){if(t<0)return[];const e=this.getCellByColumIndex(t),[o,i]=e,l=e[2];if(!o)return l;if(i-o.colspan<t||o.colspan>1){const[e]=o.descendants(ie);if(1!==o.colspan&&t===i-o.colspan){const t=d(this,s.tableMain).getColIds();e.colId=t[t.indexOf(e.colId)+1]}1!==o.rowspan&&(l.skipRowNum=o.rowspan-1),e.colspan-=1}else o.remove();return l}foreachCellInner(t){const e=this.children.iterator();let s,o=0;for(;s=e();){const[e]=s.descendants(ie);if(t(e,o++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const e=this.parent,{tableId:o}=this;null!==e&&e.statics.blotName!==s.tableBody&&this.wrap(s.tableBody,o),super.optimize(t)}}class ce extends Kt{static blotName=s.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const e=d(this,s.tableMain);if(!e)return;const o=e.getColIds(),i=this.descendants(ae),l=new Set(o);let n=0;for(const e of i){if(n===t)break;e.foreachCellInner((e=>{if(n+e.rowspan>t&&(e.rowspan+=1,l.delete(e.colId),1!==e.colspan)){const t=o.indexOf(e.colId);for(let s=0;s<e.colspan-1;s++)l.delete(o[t+s+1])}})),n+=1}const r=e.tableId,a=_t(),c=this.scroll.create(s.tableRow,{tableId:r,rowId:a});for(const t of l){const e=this.scroll.create("break").wrap("block").wrap(s.tableCellInner,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1}).wrap(s.tableCell,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1});c.appendChild(e)}this.insertBefore(c,i[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent;if(null!==e&&e.statics.blotName!==s.tableMain){const{tableId:t}=this;this.wrap(s.tableMain,{tableId:t})}super.optimize(t)}}class de extends Kt{static blotName=s.tableCell;static tagName="td";static className="ql-table-cell";static allowDataAttrs=new Set(["table-id","row-id","col-id"]);static allowAttrs=new Set(["rowspan","colspan"]);static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:o,rowspan:i,colspan:l,style:n}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=o,r.setAttribute("rowspan",String(ee(i))),r.setAttribute("colspan",String(ee(l))),n&&(r.style.cssText=n),r}static formats(t){const{tableId:e,rowId:s,colId:o}=t.dataset,i=Number(t.getAttribute("rowspan")),l=Number(t.getAttribute("colspan")),n={tableId:e,rowId:s,colId:o,rowspan:ee(i),colspan:ee(l)},r={};for(let e=0;e<t.style.length;e++){const s=t.style[e],o=t.style[s];this.isAllowStyle(String(s))&&!["initial","inherit"].includes(o)&&(r[s]=o)}const a=Object.entries(r);return a.length>0&&(n.style=a.map((([t,e])=>`${t}:${e}`)).join(";")),n}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let s=t;this.statics.allowDataAttrs.has(t)&&(s=`data-${t}`),e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s)}else this.statics.isAllowStyle(t)&&(Object.assign(this.domNode.style,{[t]:e}),t.startsWith("border")&&this.setStyleBoder(t,e));this.children.head&&this.children.head.statics.blotName===s.tableCellInner&&this.domNode.style.cssText&&(this.children.head.domNode.dataset.style=this.domNode.style.cssText)}setStyleBoder(t,e){const o=Boolean(e)?e:null;if(!["left","right","top","bottom"].some((e=>t.includes(e)))&&t.startsWith("border-")){if(this.prev&&this.prev instanceof de){const[e]=this.prev.descendant(ie,0);e&&e.setFormatValue(t.replace("border-","border-right-"),o,!0)}if(this.parent.prev)try{const e=d(this,s.tableMain).getColIds(),i=this.getColumnIndex(),l=i+this.colspan,n=new Set(e.filter(((t,e)=>e>=i&&e<l)));let r=1,a=this.parent.prev;for(;a;){let e=!1;if(a.foreachCellInner((s=>{n.has(s.colId)&&s.rowspan>=r&&(s.setFormatValue(t.replace("border-","border-bottom-"),o,!0),n.delete(s.colId)),s.rowspan>=r&&(e=!0)})),!e)break;a=a.prev,r+=1}}catch(t){console.error(t)}}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute("rowspan"))}get colspan(){return Number(this.domNode.getAttribute("colspan"))}getColumnIndex(){return d(this,s.tableMain).getColIds().indexOf(this.colId)}getCellInner(){return this.children.head}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:o}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===s&&i.rowspan===o}optimize(t){const e=this.parent,{tableId:o,rowId:i}=this;null!==e&&e.statics.blotName!==s.tableRow&&this.wrap(s.tableRow,{tableId:o,rowId:i}),super.optimize(t)}}const he=e.import("blots/block/embed");class ue extends he{scroll;domNode;static blotName=s.tableCol;static tagName="col";static validWidth(t,e){let s=Number.parseFloat(String(t));return Number.isNaN(s)&&(s=o[e?"colMinWidthPre":"colMinWidthPx"]),`${s}${e?"%":"px"}`}static create(t){const{width:e,tableId:s,colId:o,full:i,align:l}=t,n=super.create();return n.setAttribute("width",this.validWidth(e,!!i)),i&&(n.dataset.full=String(i)),l&&"left"!==l&&(n.dataset.align=l),n.dataset.tableId=s,n.dataset.colId=o,n}static value(t){const{tableId:e,colId:s}=t.dataset,i=t.getAttribute("width")||String(o.colDefaultWidth),l=t.dataset.align,n={tableId:e,colId:s,full:Object.hasOwn(t.dataset,"full")};return i&&(n.width=Number.parseFloat(i)),l&&(n.align=l),n}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){const e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:o[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=o[this.full?"colMinWidthPre":"colMinWidthPx"]),this.domNode.setAttribute("width",this.statics.validWidth(e,!!this.full))}get tableId(){return this.domNode.dataset.tableId}get colId(){return this.domNode.dataset.colId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full=String(t):this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){const t=this.next,{tableId:e,colId:s}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===s}optimize(t){const e=this.parent;if(null!=e&&e.statics.blotName!==s.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(s.tableColgroup,t)}d(this,s.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(t)}insertAt(t,e,o){if(null!=o)return void super.insertAt(t,e,o);const i=e.split("\n"),l=i.pop(),n=i.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),r=this.split(t),[a,c]=h(this,[s.tableColgroup,s.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let u=c.parent.parent,p=c.parent.next;if(d){const t=d.descendants(ie);if(t.length>0){const e=t[0],o=ie.formats(e.domNode),i=this.scroll.create("block"),l=i.wrap(s.tableCellInner,o).wrap(s.tableCell,o).wrap(s.tableRow,o).wrap(s.tableBody,o.tableId);a.parent.insertBefore(l,a.next),u=i,p=i.next}}for(const t of n)u.insertBefore(t,p);l&&u.insertBefore(this.scroll.create("text",l),p)}}class pe extends Kt{static blotName=s.tableMain;static tagName="table";static className="ql-table";static create(t){const e=super.create(),{tableId:s,full:o,align:i}=t;return e.dataset.tableId=s,"right"===i||"center"===i?e.dataset.align=i:e.removeAttribute("date-align"),o&&(e.dataset.full=String(o)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,s){super(t,e),this.updateAlign()}colWidthFillTable(){if(this.full)return void Object.assign(this.domNode.style,{width:null});const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?void 0:(this.domNode.style.width=`${e}px`,e)}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full=String(!0):this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align"),this.updateAlign()}setFull(){if(this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const s of t){const t=s.width/e*100;s.full=!0,s.width=t}const o=t[0].parent;o&&o.statics.blotName===s.tableColgroup&&(o.full=!0)}cancelFull(){if(!this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const s of t)s.full=!1,s.width=Math.max(s.width/100*e,o.colMinWidthPx);const i=t[0].parent;i&&i.statics.blotName===s.tableColgroup&&(i.full=!1)}updateAlign(){const t={marginLeft:null,marginRight:null};switch(this.align){case"center":t.marginLeft="auto",t.marginRight="auto";break;case"":case"left":t.marginRight="auto";break;case"right":t.marginLeft="auto"}Object.assign(this.domNode.style,t)}getRows(){return this.descendants(ae)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(ue)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const e=this.parent;null!==e&&e.statics.blotName!==s.tableWrapper&&this.wrap(s.tableWrapper,this.tableId),super.optimize(t)}}class be extends Kt{static blotName=s.tableColgroup;static tagName="colgroup";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full=String(!0):this.domNode.removeAttribute("data-full"),this.parent&&this.parent.statics.blotName===s.tableMain&&(this.parent.full=t)}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let s,o=0;for(;(s=e())&&o!==t;)o++;return s}insertColByIndex(t,e){const i=this.parent;if(!(i instanceof pe))throw new TypeError("TableColgroupFormat should be child of TableFormat");const l=this.findCol(t),n=this.scroll.create(s.tableCol,e);if(i.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-n.width>=o.colMinWidthPre){e.width-=n.width;break}}this.insertBefore(n,l)}removeColByIndex(t){const e=this.parent;if(!(e instanceof pe))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const s=this.findCol(t);s&&(e.full&&(s.next?s.next.width+=s.width:s.prev&&(s.prev.width+=s.width)),s.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof pe&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent,{tableId:o,full:i,align:l}=this;null!=e&&e.statics.blotName!==s.tableMain&&this.wrap(s.tableMain,{tableId:o,full:i,align:l});d(this,s.tableMain).align=l,super.optimize(t)}}const me=e.import("parchment");class fe extends Kt{scroll;static blotName=s.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){const e=super.create();return e.dataset.tableId=t,e.addEventListener("dragstart",(t=>{t.preventDefault(),t.stopPropagation()}),!0),e.addEventListener("drop",(t=>{t.preventDefault()})),e.addEventListener("dragover",(t=>{t.preventDefault(),t.dataTransfer.dropEffect="none"})),e.setAttribute("contenteditable","false"),e}constructor(t,s,o){super(t,s),this.scroll=t,this.scroll.emitter.on(e.events.TEXT_CHANGE,this.insertLineAround)}get tableId(){return this.domNode.dataset.tableId}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}deleteAt(t,e){super.deleteAt(t,e);const s=this.descendants(ce),o=this.descendants(be);0!==s.length&&0!==o.length||this.remove()}remove(){super.remove(),this.scroll.emitter.off(e.events.TEXT_CHANGE,this.insertLineAround)}insertLineAround=()=>{this.prev&&this.prev instanceof me.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this),this.next&&this.next instanceof me.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this.next)}}const ge=e.import("delta"),we=e.import("modules/clipboard");function ve(t){let e=Number.parseFloat(t.getAttribute("width")||String(o.colDefaultWidth));if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e}class Ce extends we{quill;tableId=_t();rowId=_t();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(t,e){super(t,e),this.quill=t,this.addMatcher("table",this.matchTable.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(Node.ELEMENT_NODE,this.matchTdAttributor.bind(this))}matchTable(t,e){if(0===e.ops.length)return e;const i=[],l=[];for(let t=0;t<e.ops.length;t++){const{attributes:o,insert:n}=e.ops[t],{table:r,[s.tableCell]:a,...c}=o||{};M(n)&&n[s.tableCol]?l.push({insert:n}):i.push({attributes:c,insert:n})}const n=function(t,e){const s=new Array(e).fill(o.colDefaultWidth),i=Array.from(t.querySelectorAll("tr"));for(const t of i){const o=Array.from(t.querySelectorAll("td"));for(const[t,i]of o.entries()){if(!(t<e))break;{const e=ve(i);s[t]=e||s[t]}}}return s}(t,this.colIds.length).reduce(((t,e,o)=>(l[o]?t.push(l[o]):t.push({insert:{[s.tableCol]:{tableId:this.tableId,colId:this.colIds[o],width:e,full:!1}}}),t)),[]);return i.unshift(...n),this.tableId=_t(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,new ge(i)}matchColgroup(t,e){const o=[];for(let t=0;t<e.ops.length;t++){const i=e.ops[t];i&&M(i.insert)&&i.insert[s.tableCol]&&o.push(i)}return new ge(o)}matchCol(t){this.colIds[this.colCount]=_t();const e=(new ge).insert({[s.tableCol]:Object.assign(ue.value(t),{tableId:this.tableId,colId:this.colIds[this.colCount]})});return this.colCount+=1,e}matchTr(t,e){this.rowId=_t(),this.cellCount=0;for(const[t,e]of this.rowspanCount.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(this.rowspanCount[t]={rowspan:0,colspan:0});return e}matchTd(t,e){const o=t,i=de.formats(o);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let t=this.cellCount;t>=0;t--)this.colIds[t]||(this.colIds[t]=_t()),this.rowspanCount[t]||(this.rowspanCount[t]={rowspan:0,colspan:0});const{colspan:l}=this.rowspanCount[this.cellCount];this.cellCount+=l,i.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:i.rowspan,colspan:i.colspan});const n=this.colIds[this.cellCount];this.cellCount+=i.colspan;const r=Object.assign(i,{tableId:this.tableId,rowId:this.rowId,colId:n});"none"===o.style.border&&(r.style=r.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const a=[];for(const t of e.ops){const{attributes:e={},...o}=t,{[s.tableCell]:i,...l}=e;a.push({...o,attributes:{...l,[s.tableCellInner]:r}})}return(a.length<=0||!y(a[a.length-1].insert)||!a[a.length-1].insert.endsWith("\n"))&&a.push({insert:"\n",attributes:{[s.tableCellInner]:r}}),new ge(a)}matchTdAttributor(t,e){if("td"===t.tagName.toLocaleLowerCase()){const t=[];for(const o of e.ops){const{attributes:e,...i}=o,l=e?.[s.tableCellInner];if(e&&l&&l.style){const{background:s,...o}=e,n=document.createElement("div");n.style.background=s;const r=document.createElement("div");if(r.style.cssText=l.style,n.style.background===r.style.backgroundColor){t.push({...i,attributes:{...o}});continue}}t.push(o)}return new ge(t)}return e}convert({html:t,text:e},o={}){const i=super.convert({html:t,text:e},o);if(o[s.tableCellInner])for(const t of i.ops)M(t.insert)&&t.insert[s.tableCol]?t.insert="":(t.attributes||(t.attributes={}),t.attributes[s.tableCellInner]=o[s.tableCellInner]);return i}}const xe="color-selector",ye={Break:{name:"break"},CopyCell:{name:"CopyCell",tip:"Copy cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256"><g fill="currentColor"><path d="M216 40v128h-48V88H88V40Z" opacity=".2"/><path d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8m-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z"/></g></svg>',handle:(t,e)=>{const s=t.getTextByCell(e),o=t.getHTMLByCell(e),i=new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},CutCell:{name:"CutCell",tip:"Cut cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32"><path fill="currentColor" d="m19.05 13.733l-1-1.733l-10.122 5.846l-.997-.576a3 3 0 0 0 .667-.769A3 3 0 1 0 3.5 17.599L5.928 19L3.5 20.402a3.034 3.034 0 1 0 3.44.323l.988-.57L14.59 24l1-1.73L9.928 19zM4.034 15.26a1 1 0 1 1 .466.607a1 1 0 0 1-.466-.607M5 22a1 1 0 1 1-.865 1.5A1 1 0 0 1 5 22m12 4h4v2h-4zm-7 0h4v2h-4z"/><path fill="currentColor" d="M28 28h-4v-2h4V4H7v4H5V4a2 2 0 0 1 2-2h21a2 2 0 0 1 2 2v22a2 2 0 0 1-2 2"/></svg>',handle:(t,e)=>{const s=t.getTextByCell(e),o=t.getHTMLByCell(e,!0),i=new ClipboardItem({"text/plain":new Blob([s],{type:"text/plain"}),"text/html":new Blob([o],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},InsertTop:{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm17.94 4.5h-2v4h-2v-4h-2l3-3z"/></svg>',tip:"Insert row above",handle:(t,e)=>{t.appendRow(e,!1),t.hideTableTools()}},InsertRight:{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm15.44 8v-2h-4v-2h4v-2l3 3z"/></svg>',tip:"Insert column right",handle:(t,e)=>{t.appendCol(e,!0),t.hideTableTools()}},InsertBottom:{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm11.94 5.5h2v-4h2v4h2l-3 3z"/></svg>',tip:"Insert row below",handle:(t,e)=>{t.appendRow(e,!0),t.hideTableTools()}},InsertLeft:{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm14.44 2v2h4v2h-4v2l-3-3z"/></svg>',tip:"Insert column Left",handle:(t,e)=>{t.appendCol(e,!1),t.hideTableTools()}},MergeCell:{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"/></svg>',tip:"Merge Cell",handle:(t,e)=>{t.mergeCells(e),t.hideTableTools()}},SplitCell:{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"/></svg>',tip:"Split Cell",handle:(t,e)=>{t.splitCell(e),t.hideTableTools()}},DeleteRow:{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41zM22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2zM4 9h4V6H4zm6 0h4V6h-4zm6 0h4V6h-4z"/></svg>',tip:"Delete Row",handle:(t,e)=>{t.removeRow(e),t.hideTableTools()}},DeleteColumn:{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4zm0 6v4h7v-4zM4 4v4h7V4zm13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59z"/></svg>',tip:"Delete Column",handle:(t,e)=>{t.removeCol(e),t.hideTableTools()}},DeleteTable:{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="m15.46 15.88l1.42-1.42L19 16.59l2.12-2.13l1.42 1.42L20.41 18l2.13 2.12l-1.42 1.42L19 19.41l-2.12 2.13l-1.42-1.42L17.59 18zM4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4z"/></svg>',tip:"Delete table",handle:(t,e)=>{t.deleteTable(e)}},BackgroundColor:{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"/></svg>',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},BorderColor:{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m12.01 16l-.01.011M12.01 12l-.01.011M12.01 8l-.01.011M8.01 12l-.01.011M16.01 12l-.01.011M21 3.6v16.8a.6.6 0 0 1-.6.6H3.6a.6.6 0 0 1-.6-.6V3.6a.6.6 0 0 1 .6-.6h16.8a.6.6 0 0 1 .6.6"/></svg>',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}},SwitchWidth:{name:"SwitchWidth",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" 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"/></svg>',tip:"Switch table width",handle:t=>{if(!t.table)return;const s=e.find(t.table);s&&(s.full?s.cancelFull():s.setFull())}}},Me=c("color-map"),Ie={selectWrapper:Me.b(),used:Me.bm("used"),item:Me.be("item"),btn:Me.be("btn"),map:Me.be("content"),mapRow:Me.be("content-row")};class Te{tableModule;quill;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;updateUsedColor;tooltipItem=[];activeTooltip=null;bem=c("menu");colorItemClass=`color-${_t()}`;colorChooseTooltipOption={direction:"top"};constructor(t,s,o){this.tableModule=t,this.quill=s,this.options=this.resolveOptions(o);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);x(e)||(e=[]),e.slice(-10).map((t=>this.usedColors.add(t)))}catch{}this.updateUsedColor=Xt((t=>{if(!t)return;if(this.usedColors.add(t),this.usedColors.size>10){const t=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),t.map((t=>this.usedColors.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Ie.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(Ie.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${Ie.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const o=Array.from(s.querySelectorAll(`.${Ie.item}`)).slice(0,-10);for(const t of o)t.remove()}}),1e3),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.isMenuDisplay&&this.update()};resolveOptions(t){return Object.assign({tipText:!0,tools:[ye.InsertTop,ye.InsertRight,ye.InsertBottom,ye.InsertLeft,ye.Break,ye.MergeCell,ye.SplitCell,ye.Break,ye.DeleteRow,ye.DeleteColumn,ye.DeleteTable,ye.Break,ye.BackgroundColor,ye.BorderColor,ye.Break,ye.CopyCell,ye.CutCell,ye.Break,ye.SwitchWidth],localstorageKey:"__table-bg-used-color",defaultColorMap:n},t)}buildTools(){const t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:s,icon:o,handle:i,isColorChoose:l,key:n,tip:r=""}=e,a=document.createElement("span");if(a.classList.add(this.bem.be("item")),"break"===s)a.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),C(o)?t.appendChild(o(this.tableModule)):t.innerHTML=o,a.appendChild(t),l&&n){const t=this.createColorChoose(a,{name:s,icon:o,handle:i,isColorChoose:l,key:n,tip:r});this.tooltipItem.push(t),a.classList.add(xe)}else C(i)&&a.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.tableModule.options.texts[s]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose(t,{handle:e,key:s}){const o=document.createElement("div");if(o.classList.add(Ie.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(Ie.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(Ie.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(Ie.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}o.appendChild(t)}const i=document.createElement("div");i.classList.add(Ie.mapRow),Object.assign(i.style,{marginTop:"4px"});const l=document.createElement("div");l.classList.add(Ie.btn,"transparent"),l.textContent=this.tableModule.options.texts.transparent,l.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),"transparent")}));const n=document.createElement("div");n.classList.add(Ie.btn,"clear"),n.textContent=this.tableModule.options.texts.clear,n.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),null)}));const r=document.createElement("div");r.classList.add(Ie.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=T({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Ht(r,{direction:"right",type:"click",content:a,container:r});i.appendChild(l),i.appendChild(n),i.appendChild(r),o.appendChild(i);const h=document.createElement("div");h.classList.add(Ie.used,this.colorItemClass);for(const t of this.usedColors){const e=document.createElement("div");e.classList.add(Ie.item),e.style.backgroundColor=t,h.appendChild(e)}o.appendChild(h),o.addEventListener("click",(t=>{t.stopPropagation(),c();const e=t.target,o=e.style.backgroundColor,i=this.getSelectedTds();if(e&&o&&i.length>0){if(this.tableModule.setCellAttrs(i,s,o,!0),!e.closest(`.${Ie.item}`))return;this.updateUsedColor(o)}}));const u=Ht(t,{type:"click",content:o,onOpen:()=>(this.isMenuDisplay&&this.tableModule.tableSelection&&this.tableModule.tableSelection.hideDisplay(),this.setActiveTooltip(u),!1),onClose:()=>{this.isMenuDisplay&&this.tableModule.tableSelection&&(this.tableModule.tableSelection.updateWithSelectedTds(),this.tableModule.tableSelection.showDisplay());return o.contains(a)&&c(),this.activeTooltip===u&&(this.activeTooltip=null),!1},onDestroy:()=>{d(),this.activeTooltip===u&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return u.isColorPick=!0,u}setActiveTooltip(t){this.activeTooltip&&this.activeTooltip!==t&&this.activeTooltip.hide(!0),this.activeTooltip=t}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Ht(t,{msg:e});s&&this.tooltipItem.push(s)}show(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,this.update())}update(){}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.activeTooltip=null;for(const t of this.tooltipItem)t.destroy();this.menu&&(this.hide(),this.menu.remove(),this.menu=null)}}const Ne=t=>!t.full&&"right"===t.align;class Le{tableModule;quill;colIndex=-1;tableMain;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=c("drag-line");constructor(t,e){this.tableModule=t,this.quill=e}findCurrentColIndex(t){return-1}colWidthChange(t,e,s){}async createConfirmDialog({message:t,confirm:e,cancel:s}){return new Promise((o=>{const i=document.createElement("div");Object.assign(i.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});const l=document.createElement("p");l.textContent=t;const n=document.createElement("div");Object.assign(n.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});const r=I({content:s}),a=I({type:"confirm",content:e});n.appendChild(r),n.appendChild(a),i.appendChild(l),i.appendChild(n);const{close:c}=L({child:i});r.addEventListener("click",(()=>{o(!1),c()})),a.addEventListener("click",(()=>{o(!0),c()}))}))}async handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0");let s=this.tableMain.full,l=!1;const n=[];if(s){let s=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(s<i){if(s=Math.max(o.colMinWidthPre,s),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1;n.push({index:e,width:t[e].width+i-s})}else s=100;l=!0,n.push({index:this.colIndex,width:s})}else if(t[this.colIndex+1]){const e=i+t[this.colIndex+1].width;s=Math.min(e-o.colMinWidthPre,s),l=!0,n.push({index:this.colIndex,width:s},{index:this.colIndex+1,width:e-s})}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,l=!0,n.push({index:this.colIndex,width:e});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,l){const e=this.tableMain.domNode.getBoundingClientRect().width;if(s){let o=0;const i=new Set(n.map((({index:t,width:e})=>(o+=e,t))));for(const[e,s]of t.entries())i.has(e)||(o+=s.width);if(o>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableMain.cancelFull(),s=!1;for(const[t,s]of n.entries()){const{width:o,index:i}=s;n[t]={index:i,width:o/100*e}}}}for(const{index:o,width:i}of n)t[o].width=`${Math.round(i)}${s?"%":"px"}`,this.colWidthChange(o,{px:Math.round(i/100*e),pre:Math.round(i)},s)}this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),s=e[this.colIndex].domNode.getBoundingClientRect(),i=this.tableMain.domNode.getBoundingClientRect();let l=t.clientX;if(this.tableMain.full){const t=o.colMinWidthPre/100*i.width;let n=i.right;l>s.right&&e[this.colIndex+1]&&(n=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,s.left+t));const r=s.x+t;l=Math.min(Math.max(l,r),n)}else Ne(this.tableMain)?s.right-l<o.colMinWidthPx&&(l=s.right-o.colMinWidthPx):l-s.x<o.colMinWidthPx&&(l=s.x+o.colMinWidthPx);let n=l-s.x;return Ne(this.tableMain)&&(n=s.right-l),this.dragColBreak.style.left=`${l}px`,this.dragColBreak.dataset.w=String(n),{left:l,width:n}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),s=this.tableMain.domNode.getBoundingClientRect(),o=s.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=e[this.colIndex].width,l=this.tableMain.full?i/100*o:i;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const n=document.createElement("div");n.classList.add(this.dragBEM.b()),n.classList.add(this.dragBEM.is("col")),n.dataset.w=String(l);const r={top:s.y,left:t.clientX,height:s.height};Object.assign(n.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(n),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=n,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let s=t.clientY;return s-e.y<o.rowMinHeightPx&&(s=e.y+o.rowMinHeightPx),this.dragRowBreak.style.top=`${s}px`,this.dragRowBreak.dataset.h=String(s-e.y),{top:s,height:s-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,s=this.tableMain.domNode.getBoundingClientRect(),o=document.createElement("div");o.classList.add(this.dragBEM.b()),o.classList.add(this.dragBEM.is("row")),o.dataset.h=String(e);const i={top:t.clientY,left:s.x,width:s.width};Object.assign(o.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});const l=document.body;return l.appendChild(o),this.dragRowBreak&&l.removeChild(this.dragRowBreak),this.dragRowBreak=o,i}update(){}destroy(){}}class Ee{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;bem=c("scrollbar");constructor(t,e,s,o){this.quill=t,this.isVertical=e,this.table=s,this.scrollbarContainer=o,this.container=s.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Pt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:t,scrollTop:s}=this.quill.root,{offsetLeft:o,offsetTop:i}=this.container,{width:l,height:n}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=o,d=i;this.isVertical?c+=Math.min(l,r):d+=Math.min(n,a);const h=e.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-o),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?n:l}px`,transform:`translate(${c-t}px, ${d-s}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,s=t**2/this.container.scrollHeight,o=e**2/this.container.scrollWidth,i=Math.max(s,this.minSize),l=Math.max(o,this.minSize);this.ratioY=s/(t-s)/(i/(t-i)),this.ratioX=o/(e-o)/(l/(e-l)),this.sizeWidth=l+this.gap<e?`${l}px`:"",this.sizeHeight=i+this.gap<t?`${i}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){const t=document.createElement("div");t.classList.add(this.bem.b()),t.classList.add(this.isVertical?this.bem.is("vertical"):this.bem.is("horizontal"),this.bem.is("transparent")),Object.assign(t.style,{display:"none"}),this.thumb.classList.add(this.bem.be("thumb"));let e=null;const s=t=>{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const s=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],o=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*s/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=o*this.container[this.propertyMap.scrollSize]/100},o=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",o),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=e},i=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",s),document.addEventListener("mouseup",o),e=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),i(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const l=[this.table,t];for(const t of l)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Pt.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){const e=t[this.propertyMap.offset]-this.gap;this.move=100*t[this.propertyMap.scrollDirection]/e*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=Xt((()=>{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=Xt((()=>{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(),Vt.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}const Se=e.import("parchment"),Be=e.import("delta"),Re=e.import("blots/break"),ke=e.import("ui/icons");function Oe(t,{tableId:e,rowId:o,colId:i}){const l={tableId:e,rowId:o,colId:i,colspan:1,rowspan:1},n=t.create(s.tableCell,l),r=t.create(s.tableCellInner,l),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),n.appendChild(r),n}function Ae(t){return{key:t?"ArrowUp":"ArrowDown",collapsed:!0,format:[s.tableCellInner],bindInHead:!1,handler(o,i){let l,n,r,a;try{[l,n,r,a]=h(i.line,[s.tableWrapper,s.tableMain,s.tableRow,s.tableCell])}catch{return!0}const c=n.getColIds(),d=t?"prev":"next",u=t?"tail":"head",p=l[d];if(i.line[d]||!p)return!0;const b=r[d];if(b){const t=c.indexOf(a.colId),s=b.getCellByColId(c[t],d);if(!s)return!0;let o=s.children[u];o.children&&(o=o.children[u]);const l=o.offset(this.quill.scroll)+Math.min(i.offset,o.length()-1);this.quill.setSelection(l,0,e.sources.USER)}else{const s=p.offset(this.quill.scroll)+(t?p.length()-1:0);this.quill.setSelection(s,0,e.sources.USER)}return!1}}}class ze{static moduleName=l.moduleName;static toolName=s.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,e){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof fe)return o.prev.remove(),!1;if(e.format[s.tableCellInner]){if(0===o.offset(d(o,s.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,e){const o=this.quill.getLine(t.index),i=o[0],l=o[1];if((i.next instanceof fe||i.next instanceof ue)&&l===i.length()-1)return!1;if(e.format[s.tableCellInner]){if(i===d(i,s.tableCellInner).children.tail&&l===i.length()-1)return!1}return!0}},"table up":Ae(!0),"table down":Ae(!1)};static register(){fe.allowedChildren=[pe],pe.allowedChildren=[ce,be],pe.requiredContainer=fe,be.allowedChildren=[ue],be.requiredContainer=pe,ce.allowedChildren=[ae],ce.requiredContainer=pe,ae.allowedChildren=[de],de.requiredContainer=ce,de.allowedChildren=[ie,Re],de.requiredContainer=ae,ie.requiredContainer=de;const t=["header","list","blockquote","code-block"].reduce(((t,s)=>{const o=`formats/${s}`,i=e.import(o);return t[o]=class extends(function(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)p(s.prototype,t.prototype);return s}(i,[te])){static register(){}},t}),{});e.register({"blots/scroll":re,"blots/block":te,...t,[`blots/${s.container}`]:Kt,[`formats/${s.tableCell}`]:de,[`formats/${s.tableCellInner}`]:ie,[`formats/${s.tableRow}`]:ae,[`formats/${s.tableBody}`]:ce,[`formats/${s.tableCol}`]:ue,[`formats/${s.tableColgroup}`]:be,[`formats/${s.tableMain}`]:pe,[`formats/${s.tableWrapper}`]:fe,"modules/clipboard":Ce},!0)}quill;options;toolBox;fixTableByLisenter=Xt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(t,e){this.quill=t,this.options=this.resolveOptions(e||{});const s=c("toolbox");if(this.toolBox=this.quill.addContainer(s.b()),!this.options.scrollbar){const t=c("scrollbar");this.quill.container.classList.add(t.bm("origin"))}this.options.selection&&(this.tableSelection=new this.options.selection(this,this.quill,this.options.selectionOptions));const o=this.quill.getModule("toolbar");if(o&&this.quill.theme.pickers){const[,t]=(o.controls||[]).find((([t])=>t===this.statics.toolName))||[];if(t&&"select"===t.tagName.toLocaleLowerCase()){const e=this.quill.theme.pickers.find((e=>e.select===t));e&&(e.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,e),e.label.addEventListener("mousedown",(()=>{if(!this.selector||!e)return;const t=this.selector.getBoundingClientRect(),{leftLimited:s}=Ft(t);if(s){const t=e.label.getBoundingClientRect();Object.assign(e.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(e.options.style,{transform:void 0})})))}}const i=this.quill.getModule("keyboard");for(const t of Object.values(ze.keyboradHandler))t.bindInHead?i.bindings[t.key].unshift(t):i.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const e=t.composedPath();if(!e||e.length<=0)return;const s=e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(s){if(this.table===s)return this.tableSelection&&this.tableSelection.show(),this.tableAlign&&this.tableAlign.update(),this.tableResize&&this.tableResize.update(),void(this.tableScrollbar&&this.tableScrollbar.update());this.table&&this.hideTableTools(),this.showTableTools(s)}else this.table&&this.hideTableTools()}),!1),this.quillHack(),this.listenBalanceCells()}addContainer(t){if(y(t)){const e=document.createElement("div");for(const s of t.split(" "))e.classList.add(s);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!1,texts:this.resolveTexts(t.texts||{}),full:!1,fullSwitch:!0,icon:ke.table,selectionOptions:{},alignOptions:{},scrollbarOptions:{},resizeOptions:{},resizeScaleOptions:{}},t)}resolveTexts(t){return Object.assign({fullCheckboxText:"Insert full width table",customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer",custom:"Custom",clear:"Clear",transparent:"Transparent",perWidthInsufficient:"The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?",CopyCell:"Copy cell",CutCell:"Cut cell",InsertTop:"Insert row above",InsertRight:"Insert column right",InsertBottom:"Insert row below",InsertLeft:"Insert column Left",MergeCell:"Merge Cell",SplitCell:"Split Cell",DeleteRow:"Delete Row",DeleteColumn:"Delete Column",DeleteTable:"Delete table",BackgroundColor:"Set background color",BorderColor:"Set border color"},t)}quillHack(){const t=this.quill.getSemanticHTML;this.quill.getSemanticHTML=(o=0,i)=>{const l=e.import(`formats/${s.tableCellInner}`),n=this.quill.scroll.domNode.querySelectorAll(`.${l.className}`);for(const t of Array.from(n))t.setAttribute("contenteditable",String(!1));const r=t.call(this.quill,o,i),a=this.quill.isEnabled();for(const t of Array.from(n))t.setAttribute("contenteditable",String(a));return r};const o=this.quill.format;this.quill.format=function(t,i,n=e.sources.API){if(!(this.scroll.query(t).prototype instanceof Se.EmbedBlot)){const e=this.getModule(l.moduleName),r=this.getSelection();if(r&&r.length>0){if(this.getFormat(r)[s.tableCellInner])return o.call(this,t,i,n)}if(e&&e.tableSelection&&e.tableSelection.selectedTds.length>0){const s=e.tableSelection.selectedTds;let o=!1;const l=[];for(const e of s){const s=e.offset(this.scroll),n=e.length();l.push({index:s,length:n});this.getFormat(s,n)[t]!==i&&(o=!0)}const r=!!o&&i,a=new Be;for(const[e,{index:s,length:o}]of l.entries()){const i=0===e?0:l[e-1].index+l[e-1].length;a.retain(s-i).retain(o,{[t]:r})}const c=this.updateContents(a,n);return this.blur(),c}}return o.call(this,t,i,n)};const i=this.quill.theme.modules.toolbar;if(i){const t=i.handlers?.clean;if(t){const o=(t,e,o=!0)=>{const i=this.quill.getText(t,e),[l,n]=this.quill.getLine(t+e);let r=0,a=new Be;null!=l&&(r=l.length()-n,a=l.delta().slice(n,n+r-1).insert("\n"));const c=this.quill.getContents(t,e+r),d=c.diff((new Be).insert(i).concat(a));let h=0;const u=d.ops.map((t=>{const{attributes:e,...i}=t;if(t.insert?h-=y(t.insert)?t.insert.length:1:t.retain?h+="number"==typeof t.retain?t.retain:1:t.delete&&(h+=t.delete),e){const{[s.tableCellInner]:t,...l}=e;if(o){const t=c.slice(h-1,h).ops[0];if(t&&t.attributes&&t.attributes[s.tableCellInner]){const e=t.attributes[s.tableCellInner],{style:o,...n}=e;return{...i,attributes:{...l,[s.tableCellInner]:n}}}}return{...i,attributes:{...l}}}return t}));return new Be(u)};i.handlers.clean=function(i){const n=this.quill.getModule(l.moduleName),r=this.quill.getSelection();if(r&&r.length>0){if(this.quill.getFormat(r)[s.tableCellInner]){const t=o(r.index,r.length,!1),s=(new Be).retain(r.index).concat(t);return void this.quill.updateContents(s,e.sources.USER)}}if(n&&n.tableSelection&&n.tableSelection.selectedTds.length>0){const t=n.tableSelection.selectedTds;let s=new Be,i=0;for(const e of t){const t=e.offset(this.quill.scroll),l=e.length(),n=o(t,l-1),r=(new Be).retain(t-i).concat(n);s=s.concat(r),i=t+l}return this.quill.updateContents(s,e.sources.USER),void(t.length>1&&this.quill.blur())}return t.call(this,i)}}}}showTableTools(t){t&&(this.table=t,this.tableSelection?.show(),this.options.align&&(this.tableAlign=new this.options.align(this,t,this.quill,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,this.quill,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,this.quill,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,this.quill,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection?.hide(),this.tableScrollbar&&(this.tableScrollbar.destroy(),this.tableScrollbar=void 0),this.tableAlign&&(this.tableAlign.destroy(),this.tableAlign=void 0),this.tableResize&&(this.tableResize.destroy(),this.tableResize=void 0),this.tableResizeScale&&this.tableResizeScale.destroy(),this.table=void 0}async buildCustomSelect(t,e){if(!t||!C(t))return;const s=document.createElement("div");if(s.classList.add("ql-custom-select"),this.selector=await t(this,e),s.appendChild(this.selector),this.options.fullSwitch){const t=c("creator"),e=document.createElement("label");e.classList.add(t.be("checkbox"));const o=document.createElement("input");o.type="checkbox",o.checked=this.options.full,o.addEventListener("change",(()=>{this.options.full=o.checked}));const i=document.createElement("span");i.textContent=this.options.texts.fullCheckboxText,e.appendChild(o),e.appendChild(i),s.appendChild(e)}e.options.innerHTML="",e.options.appendChild(s)}setCellAttrs(t,e,s,o=!1){if(0!==t.length)for(const i of t)i.setFormatValue(e,s,o)}getTextByCell(t){let e="";for(const s of t){const t=s.offset(this.quill.scroll),o=s.length();for(const s of this.quill.getContents(t,o).ops)y(s.insert)&&(e+=s.insert)}return e}getHTMLByCell(t,e=!1){if(0===t.length)return"";let o=null;try{for(const e of t){const t=d(e,s.tableMain);if(o||(o=t),t!==o)return console.error("tableMain is not same"),""}}catch{return console.error("tds must be in same tableMain"),""}if(!o)return"";const i=o.children.head,l=o.children.tail;if(!l||!i)return console.error("tableMain has no tbody or colgroup"),"";function n(t){const e=t.tagName.toLowerCase(),s=Array.from(t.attributes).map((t=>`${t.name}="${t.value}"`)).join(" ");return{startTag:`<${e}${s?` ${s}`:""}>`,endTag:["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(e)?"":`</${e}>`}}let r="";const a=new Set;let c=0,h=null;for(const e of t){const t=this.quill.getIndex(e),s=e.length(),o=this.quill.getSemanticHTML(t,s),i=(new DOMParser).parseFromString(o,"text/html");for(const t of Array.from(i.querySelectorAll("td > div[contenteditable]")))t.removeAttribute("contenteditable");const l=i.querySelector("tr");if(e.rowId!==h){c+=1;const{startTag:t,endTag:e}=n(l);r+=`${r?e:""}${t}${l.innerHTML}`}else r+=l.innerHTML;h=e.rowId,a.add(e.colId)}r+="</tr>";const{startTag:u,endTag:p}=n(l.domNode);r=`${u}${r}${p}`;const b=o.getCols(),{startTag:m,endTag:f}=n(i.domNode);let g="",w=0;const v=b.filter((t=>a.has(t.colId))).map((t=>t.clone()));if(o.full){const t=v.reduce(((t,e)=>t+e.width),0),e=(100-t)/t;for(const t of v)t.width+=Math.round(t.width*e)}for(const t of v){const{startTag:e}=n(t.domNode);g+=e,w+=t.width}r=m+g+f+r;const C=o.domNode.cloneNode();o.full||(C.style.width=`${w}px`);const{startTag:x,endTag:y}=n(C);r=x+r+y;const{startTag:M,endTag:I}=n(o.parent.domNode);if(r=M+r+I,e){if(c===o.getRows().length)this.removeCol(t);else for(const e of t)e.domNode.innerHTML="<p><br></p>"}return r}insertTable(t,i){if(t>=30||i>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus();const l=this.quill.getSelection();if(null==l)return;const[n]=this.quill.getLeaf(l.index);if(!n)return;if(a(n))throw new Error(`Not supported ${n.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),c=getComputedStyle(this.quill.root),d=Number.parseInt(c.paddingLeft),h=Number.parseInt(c.paddingRight),u=Number.parseInt(c.width)-d-h-r,p=_t(),b=new Array(i).fill(0).map((()=>_t())),m=this.options.full?`${Math.max(1/i*100,o.colMinWidthPre)}%`:`${Math.max(Math.floor(u/i),o.colMinWidthPx)}px`,f=[{retain:l.index},{insert:"\n"}];for(let t=0;t<i;t++)f.push({insert:{[s.tableCol]:{width:m,tableId:p,colId:b[t],full:this.options.full}}});for(let e=0;e<t;e++){const t=_t();for(let e=0;e<i;e++)f.push({insert:"\n",attributes:{[s.tableCellInner]:{tableId:p,rowId:t,colId:b[e],rowspan:1,colspan:1}}})}this.quill.updateContents(new Be(f),e.sources.USER),this.quill.setSelection(l.index+i+i*t+1,e.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${pe.className}">\n <tbody>\n <tr>\n <td class="${de.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=fe.className,e.innerHTML=t,e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.visibility="hidden",this.quill.root.appendChild(e);const s=window.getComputedStyle(e.querySelector("td")),o=Number.parseFloat(s.borderWidth)||0;return this.quill.root.removeChild(e),o}fixUnusuaDeletelTable(t){const e=t.getRows(),s=t.getColIds();if(0===e.length)return t.remove();if(0===s.length)return;const o=new Array(e.length).fill(0).map((()=>new Array(s.length).fill(!1))),i=t.tableId;for(const[t,l]of e.entries()){let n=0,r=0;const a=o[t],c=l.descendants(de);for(;r<s.length;){if(a[r]){r+=1;continue}const d=c[n];if(d&&d.colId===s[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:i}=d;if(s>1)for(let t=1;t<s;t++)a[r+t]=!0;if(i>1)for(let e=t+1;e<t+i;e++)for(let t=0;t<s;t++)o[e][r+t]=!0;n+=1}else l.insertBefore(Oe(this.quill.scroll,{tableId:i,colId:s[r],rowId:l.rowId}),d);r+=1}if(n<c.length)for(let t=n;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(pe))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)))}))}deleteTable(t){if(0===t.length)return;const e=d(t[0],s.tableMain);e&&e.remove(),this.hideTableTools()}appendRow(t,e){if(t.length<=0)return;const o=t[e?t.length-1:0],[i,l,n]=h(o,[s.tableMain,s.tableBody,s.tableRow]),r=i.getRows().indexOf(n)+(e?o.rowspan:0);l.insertRow(r)}appendCol(t,e){if(t.length<=0)return;const[o]=t.reduce(((t,s)=>{const o=s.getColumnIndex();return(!e&&o<=t[1]||e&&o>=t[1])&&(t=[s,o]),t}),[t[0],t[0].getColumnIndex()]),i=o.getColumnIndex()+(e?o.colspan:0),l=d(o,s.tableMain),n=l.tableId,r=_t(),[a]=l.descendants(be);a&&a.insertColByIndex(i,{tableId:n,colId:r,width:l.full?"6%":"160px",full:l.full});const c=l.getRows(),h=[];let u=0;for(const t of Object.values(c)){const e=h.shift()||0;if(u>0){u-=1;continue}const s=t.insertCell(i-e,{tableId:n,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(u+=s.skipRowNum);for(const[t,e]of s.entries())h[t]=(h[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),s=t.getCols(),o=s.reduce(((t,e)=>(t[e.colId]=0,t)),{}),i=[...e].reverse(),l=[];for(const[t,s]of i.entries()){const i=e.length-t-1;s.children.length<=0?l.push(i):s.foreachCellInner((t=>{const e=l.reduce(((e,s)=>t.rowspan+i>s?e+1:e),0);t.rowspan-=e,o[t.colId]+=1}))}let n=0;for(const t of Object.values(o))if(0===t){const t=[];let s=0;for(const o of Object.values(e)){const e=t.shift()||0;let i=[];s>0?(i=o.getCellByColumIndex(n-e)[2],s-=1):(i=o.removeCell(n-e),i.skipRowNum&&(s+=i.skipRowNum));for(const[e,s]of i.entries())t[e]=(t[e]||0)+s}}else n+=1;for(const t of s)0===o[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(t){if(t.length<=0)return;const e=d(t[0],s.tableMain),o=e.getRows();let i=o.length,l=-1;for(const e of t){const t=d(e,s.tableRow),n=o.indexOf(t);n<i&&(i=n),n+e.rowspan>l&&(l=n+e.rowspan)}const n={};for(let t=i;t<Math.min(o.length,l);t++){o[t].foreachCellInner((e=>{e.rowspan+t>l&&(n[e.colId]={rowspan:e.rowspan+t-l,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(o[l]){const t=o[l],s=e.tableId;for(const[e,{colIndex:o,colspan:i,rowspan:l}]of Object.entries(n))t.insertCell(o,{tableId:s,rowId:t.rowId,colId:e,colspan:i,rowspan:l})}this.fixTableByRemove(e)}removeCol(t){if(t.length<=0)return;const e=t[0],o=d(e,s.tableMain),i={};for(const e of t)i[e.rowId]||(i[e.rowId]=0),i[e.rowId]+=e.colspan;const l=Math.max(...Object.values(i)),n=e.getColumnIndex(),r=o.descendants(ae);for(let t=0;t<l;t++){const t=[];let e=0;for(const s of Object.values(r)){const o=t.shift()||0;if(e>0){e-=1;continue}const i=s.removeCell(n-o);i.skipRowNum&&(e+=i.skipRowNum);for(const[e,s]of i.entries())t[e]=(t[e]||0)+s}}const[a]=o.descendants(be);if(a)for(let t=0;t<l;t++)a.removeColByIndex(n);this.fixTableByRemove(o)}mergeCells(t){if(t.length<=1)return;const e=t.reduce(((t,e,s)=>{const o=e.colId;t[0][o]||(t[0][o]=0),t[0][o]+=e.rowspan;const i=e.rowId;return t[1][i]||(t[1][i]=0),t[1][i]+=e.colspan,0!==s&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),o=Math.max(...Object.values(e[0])),i=Math.max(...Object.values(e[1])),l=e[2];l.colspan=i,l.rowspan=o;const n=d(l,s.tableMain);this.fixTableByRemove(n)}splitCell(t){if(1!==t.length)return;const e=t[0];if(1===e.colspan&&1===e.rowspan)return;const[o,i]=h(e,[s.tableMain,s.tableRow]),l=o.tableId,n=e.getColumnIndex(),r=o.getColIds().slice(n,n+e.colspan).reverse();let a=i,c=e.rowspan;for(e.colspan=1,e.rowspan=1;a&&c>0;){for(const t of r)a===i&&t===e.colId||a.insertCell(n+(a===i?1:0),{tableId:l,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}t.BlockOverride=te,t.ContainerFormat=Kt,t.ScrollOverride=re,t.Scrollbar=Ee,t.TableAlign=class{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=c("align");resizeObserver=jt((()=>this.update()),{ignoreFirstBind:!0});constructor(t,s,o){this.tableModule=t,this.table=s,this.quill=o,this.tableBlot=e.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool(),this.resizeObserver.observe(this.table),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.show()}updateWhenTextChange=()=>{this.update()};buildTool(){const t=this.tableModule.addContainer(this.bem.b()),s=e.import("ui/icons"),o={left:s.align[""],center:s.align.center,right:s.align.right};for(const[s,i]of Object.entries(o)){const o=document.createElement("span");o.dataset.align=s,o.classList.add(this.bem.be("item")),o.innerHTML=`<i class="icon">${i}</i>`,o.addEventListener("click",(()=>{const t=o.dataset.align;t&&(this.setTableAlign(this.tableBlot,t),this.quill.once(e.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableResizeScale&&this.tableModule.tableResizeScale.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),t.appendChild(o)}return this.cleanup||(this.cleanup=kt(this.tableWrapperBlot.domNode,t,(()=>this.update()))),t}setTableAlign(t,e){const s=t.getCols();for(const t of s)t.align=e}show(){this.alignBox&&(this.alignBox.classList.add(this.bem.bm("active")),this.update())}hide(){this.alignBox&&(this.alignBox.classList.remove(this.bem.bm("active")),this.cleanup&&(this.cleanup(),this.cleanup=void 0))}update(){this.alignBox&&(this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth?this.hide():$t(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[zt(),At({limiter:qt()}),Ot(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})})))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}},t.TableBodyFormat=ce,t.TableCellFormat=de,t.TableCellInnerFormat=ie,t.TableClipboard=Ce,t.TableColFormat=ue,t.TableColgroupFormat=be,t.TableMainFormat=pe,t.TableMenuCommon=Te,t.TableMenuContextmenu=class extends Te{tableModule;quill;colorChooseTooltipOption={direction:"right"};constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,this.update({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hide()}),{once:!0})):this.hide()};buildTools(){const t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));const e=t.getElementsByClassName(xe);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const s=document.createElement("span");s.textContent=e,t.appendChild(s)}show(){}update(t){if(!(this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection))return;if(!t)return;super.update();const e={display:"flex",left:0,top:0},{x:s,y:o}=t;e.left=s,e.top=o,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const i=this.menu.getBoundingClientRect(),{left:l,top:n}=Ft(i);Object.assign(this.menu.style,{left:`${l+window.scrollX}px`,top:`${n+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy()}},t.TableMenuSelect=class extends Te{tableModule;quill;constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu),this.show(),this.update()}update(){this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection&&(super.update(),$t(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[zt(),At({limiter:qt()}),Ot(20)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}},t.TableResizeBox=class extends Le{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=c("resize-box");constructor(t,s,o){super(t,o),this.tableModule=t,this.table=s,this.tableMain=e.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer(this.bem.b()),this.resizeObserver=new ResizeObserver((()=>{this.show()})),this.resizeObserver.observe(this.table),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)))}updateWhenTextChange=()=>{this.update()};handleResizerHeader(t,e){const{clientX:s,clientY:o}=e,i=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const l=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const n=[{x:t?i.left:s,y:t?o:i.top},{x:t?i.right:s,y:t?o:i.bottom}];this.lastHeaderSelect?(n[0]={x:Math.min(n[0].x,this.lastHeaderSelect[0].x),y:Math.min(n[0].y,this.lastHeaderSelect[0].y)},n[1]={x:Math.max(n[1].x,this.lastHeaderSelect[1].x),y:Math.max(n[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=n,l.table=this.table,l.selectedTds=l.computeSelectedTds(...n),l.show()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("col-separator"))).indexOf(t.target)}colWidthChange(t,e,s){Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[t].style.width=s?`${e.pre}%`:`${e.px}px`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.size+"px",left:`${e.left}px`,height:`${e.height+this.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));Pt.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!1));for(const t of e)t.addEventListener("mousedown",this.handleColMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}findCurrentRowIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("row-separator"))).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[t].style.height=`${e}px`}handleRowMouseDownFunc=function(t){const e=this.handleRowMouseDown(t);return e&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${e.top}px`,left:e.left-this.size+"px",width:`${e.width+this.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));Pt.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!0));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const[t]=this.tableMain.descendant(ce,this.tableMain.length()-1);if(!t)return;const e=t.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:e.y-s.y+"px",left:e.x-s.x+"px"});const o=this.tableMain.domNode.getBoundingClientRect(),i=this.tableWrapper.domNode.getBoundingClientRect();let l=-1*this.size,n=-1*this.size;Ne(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),l=Math.min(i.width,o.width),n=Math.min(i.width,o.width)):this.root.classList.remove(this.bem.is("align-right")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${l}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${n}px)`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const t=this.tableWrapper.domNode.getBoundingClientRect(),e=this.tableMain.domNode.getBoundingClientRect();if(this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener("click",(()=>{if(this.tableModule.tableSelection){const t=this.tableMain.descendants(ie),e=this.tableModule.tableSelection;e.selectedTds=t,e.show(),e.updateWithSelectedTds()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let s="";for(const[,t]of this.tableCols.entries()){const o=t.domNode.getBoundingClientRect().width;s+=`<div class="${this.bem.be("col-header")}" style="width: ${o}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${e.height+this.size-3}px"></div>\n </div>`}const o=document.createElement("div");o.classList.add(this.bem.be("col"));const i=document.createElement("div");i.classList.add(this.bem.be("col-wrapper")),Object.assign(o.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=s,o.appendChild(i),this.root.appendChild(o),o.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=o,this.bindColEvents()}if(this.tableRows.length>0){let s="";for(const[,t]of this.tableRows.entries()){const o=`${t.domNode.getBoundingClientRect().height}px`;s+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(o)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${e.width+this.size-3}px"></div>\n </div>`}const o=document.createElement("div");o.classList.add(this.bem.be("row"));const i=document.createElement("div");i.classList.add(this.bem.be("row-wrapper")),Object.assign(o.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${t.height}px`}),Object.assign(i.style,{height:`${e.height}px`}),i.innerHTML=s,o.appendChild(i),this.root.appendChild(o),o.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=o,this.bindRowEvents()}this.update(),Pt.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),Vt.call(this),this.resizeObserver.disconnect(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange);for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}},t.TableResizeCommon=Le,t.TableResizeLine=class extends Le{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=c("resize-line");constructor(t,s,o){super(t,o),this.tableModule=t,this.table=s,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.table.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(e.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=t=>{if(this.dragging)return;if(this.tableModule.tableSelection&&this.tableModule.tableSelection.dragging)return;const o=this.findTableCell(t);if(!o)return this.hide();const i=e.find(o);i&&this.currentTableCell!==o&&(this.show(),this.currentTableCell=o,this.tableCellBlot=i,this.tableMain=d(i,s.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hide()};findTableCell(t){for(const e of t.composedPath()){if(e instanceof HTMLElement&&"TD"===e.tagName)return e;if(e===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.colResizer),this.colResizer=this.tableModule.addContainer(this.bem.be("col"));const[e]=h(t,[s.tableBody]),o=e.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();let n=i.right-l.x;Ne(this.tableMain)&&(n=i.left-l.x),Object.assign(this.colResizer.style,{top:o.y-l.y+"px",left:`${n}px`,height:`${o.height}px`});const r=this.tableMain.getCols();this.curColIndex=r.findIndex((e=>e.colId===t.colId)),this.colResizer.addEventListener("mousedown",this.handleColMouseDownFunc),this.colResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.rowResizer),this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));const e=t.parent;if(!(e instanceof ae))return;const[o]=h(t,[s.tableBody]),i=o.domNode.getBoundingClientRect(),l=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:l.bottom-n.y+"px",left:i.x-n.x+"px",width:`${i.width}px`});const r=this.tableMain.getRows();this.curRowIndex=r.indexOf(e),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}show(){this.rowResizer.classList.remove(this.bem.is("hidden")),this.colResizer.classList.remove(this.bem.is("hidden"))}hide(){this.currentTableCell=void 0,this.rowResizer.classList.add(this.bem.is("hidden")),this.colResizer.classList.add(this.bem.is("hidden"))}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer.remove(),this.rowResizer.remove(),this.table.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(e.events.TEXT_CHANGE,this.hideWhenTextChange)}},t.TableResizeScale=class{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=c("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(t,s,o,i){this.tableModule=t,this.table=s,this.quill=o,this.options=this.resolveOptions(i),this.tableMainBlot=e.find(s),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.buildResizer(),this.show()),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};resolveOptions(t){return Object.assign({blockSize:12},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.root.classList.add(this.bem.is("hidden")),this.block=document.createElement("div"),this.block.classList.add(this.bem.be("block")),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let t=[],e=[];const s=s=>{if(!this.tableMainBlot)return;const i=Ne(this.tableMainBlot)?-1:1,l=(s.clientX-this.startX)*i,n=s.clientY-this.startY,r=Math.floor(l/t.length),a=Math.floor(n/e.length);for(const{blot:e,width:s}of t)e.width=Math.max(s+r,o.colMinWidthPx);for(const{blot:t,height:s}of e)t.setHeight(`${Math.max(s+a,o.rowMinHeightPx)}px`)},i=()=>{t=[],e=[],document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",i)};this.block.addEventListener("mousedown",(o=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=o.clientX,this.startY=o.clientY,t=this.tableMainBlot.getCols().map((t=>({blot:t,width:Math.floor(t.width)}))),e=this.tableMainBlot.getRows().map((t=>({blot:t,height:Math.floor(t.domNode.getBoundingClientRect().height)}))),document.addEventListener("mousemove",s),document.addEventListener("mouseup",i))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),Pt.call(this,this.quill.root,(()=>this.update())),Pt.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect();if(t.width>e.width){for(const s of this.tableMainBlot.getCols())s.width=Math.floor(s.width/t.width*e.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),{scrollTop:o,scrollLeft:i}=this.tableWrapperBlot.domNode,l=2*this.options.blockSize,n=Math.min(t.width,e.width)+l,r=Math.min(t.height,e.height)+l;Object.assign(this.root.style,{width:`${n}px`,height:`${r}px`,left:Math.max(t.x,e.x)-s.x-this.options.blockSize+"px",top:Math.max(t.y,e.y)-s.y-this.options.blockSize+"px"});const a={left:t.width+l-i+"px",top:r-o+"px"};Ne(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),a.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,a)}show(){this.root&&(this.root.classList.remove(this.bem.is("hidden")),this.update())}hide(){this.root&&this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.root&&this.root.remove(),Vt.call(this)}},t.TableRowFormat=ae,t.TableSelection=class{tableModule;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];tableMenu;resizeObserver;table;isDisplaySelection=!1;bem=c("selection");lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};constructor(t,s,o={}){this.tableModule=t,this.quill=s,this.options=this.resolveOptions(o),this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=jt((()=>this.updateAfterEvent()),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.mouseDownHandler,{passive:!1}),document.addEventListener("selectionchange",this.selectionChangeHandler,{passive:!1}),this.quill.on(i.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.TEXT_CHANGE,this.updateAfterEvent),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(t,s,this.options.tableMenuOptions)),this.hide()}updateAfterEvent=()=>{this.updateWithSelectedTds()};getFirstTextNode(t){for(const e of Array.from(t.childNodes))if(e.nodeType===Node.TEXT_NODE)return e;return t}getLastTextNode(t){for(let e=t.childNodes.length-1;e>=0;e--){const s=t.childNodes[e];if(s.nodeType===Node.TEXT_NODE)return s}return t}getNodeTailOffset(t){const e=document.createRange();return e.selectNodeContents(t),e.collapse(!1),e.startOffset}quillSelectionChangeHandler=(t,o,i)=>{if(i!==e.sources.API&&t&&this.selectedTds.length>0){const e=this.quill.getFormat(t),[o]=this.quill.getLine(t.index),i=!!e[s.tableCellInner]&&!!o,l=this.selectedTds.some((t=>t.children.contains(o)));if(i&&!l)try{const t=d(o,s.tableCellInner);this.selectedTds=[t],this.updateWithSelectedTds()}catch{}else i&&l||this.hide()}};setSelectionData(t,e){const{anchorNode:s,anchorOffset:o,focusNode:i,focusOffset:l}=e;if(!s||!i)return;const n=document.createRange(),r=this.selectionDirectionUp(e);r?(n.setStart(s,o),n.setEnd(s,o)):(n.setStart(s,o),n.setEnd(i,l)),t.removeAllRanges(),t.addRange(n),r&&t.extend(i,l)}selectionDirectionUp(t){const{anchorNode:e,anchorOffset:s,focusNode:o,focusOffset:i}=t;if(!e||!o)return!1;if(e===o)return s>i;const l=e.compareDocumentPosition(o);return l&Node.DOCUMENT_POSITION_CONTAINS||l&Node.DOCUMENT_POSITION_CONTAINED_BY?!!(l&Node.DOCUMENT_POSITION_FOLLOWING):!!(l&Node.DOCUMENT_POSITION_PRECEDING)}findWrapSelection(t){let e=null,s=0,o=null,i=0;for(const{node:l,offset:n}of t)l&&(e&&!this.selectionDirectionUp({anchorNode:e,anchorOffset:s,focusNode:l,focusOffset:n})||(e=l,s=n),o&&!this.selectionDirectionUp({anchorNode:l,anchorOffset:n,focusNode:o,focusOffset:i})||(o=l,i=n));return{startNode:e,startOffset:s,endNode:o,endOffset:i}}resolveOptions(t){return Object.assign({selectColor:"#0589f340",tableMenuOptions:{}},t)}selectionChangeHandler=()=>{const t=window.getSelection();if(!t)return;const{anchorNode:o,focusNode:i,anchorOffset:l,focusOffset:n}=t;if(!o||!i)return;const r=e.find(o),a=e.find(i);if(!r||!a||r.scroll!==this.quill.scroll||a.scroll!==this.quill.scroll)return;const c=u(r),d=u(a),h=c.has(s.tableColgroup),p=d.has(s.tableColgroup);if(h||p){let e=o,r=l,a=i,u=n;if(h){const t=c.get(s.tableWrapper).descendants(ie);t.length>0&&(e=t[0].domNode,r=0)}if(p){const t=d.get(s.tableWrapper).descendants(ie);t.length>0&&(a=t[0].domNode,u=0)}return void this.setSelectionData(t,{anchorNode:e,anchorOffset:r,focusNode:a,focusOffset:u})}const b=c.has(s.tableCellInner),m=d.has(s.tableCellInner);let f=b&&m;if(f){const t=c.get(s.tableCellInner),e=d.get(s.tableCellInner);f&&=t!==e}if(b&&m&&f||!b&&m||!m&&b)return this.setSelectionData(t,this.lastSelection),void(this.selectedTds.length>0&&this.hide());this.lastSelection={anchorNode:o,anchorOffset:l,focusNode:i,focusOffset:n}};helpLinesInitial(){this.cellSelectWrap.style.setProperty("--select-color",this.options.selectColor);const t=document.createElement("div");return t.classList.add(this.bem.be("line")),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(t,s){if(!this.table)return[];const o=e.find(this.table);if(!o)return[];const i=new Set(o.descendants(de).map(((t,e)=>(t.index=e,t)))),{x:l,y:n}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=l,this.selectedTableScrollY=n,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=t.x-l+this.startScrollX,h=t.y-n+this.startScrollY;let u={x:Math.max(c.left,Math.min(s.x,d)),y:Math.max(c.top,Math.min(s.y,h)),x1:Math.min(c.right,Math.max(s.x,d)),y1:Math.min(c.bottom,Math.max(s.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of i){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:o,bottom:l}=t.__rect;if(Dt({x:Math.floor(u.x),y:Math.floor(u.y),x1:Math.floor(u.x1),y1:Math.floor(u.y1)},{x:Math.floor(e),y:Math.floor(s),x1:Math.floor(o),y1:Math.floor(l)},0,0===p.size)){p.add(t),i.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,s),x1:Math.max(u.x1,o),y1:Math.max(u.y1,l)},b=!0;break}}}for(const t of[...p,...i])delete t.__rect;return this.boundary=function(t,e){const s=e.getBoundingClientRect();return{x:t.x-s.x-e.scrollLeft,y:t.y-s.y-e.scrollTop,x1:t.x-s.x-e.scrollLeft+t.width,y1:t.y-s.y-e.scrollTop+t.height,width:t.width,height:t.height}}({...u,width:u.x1-u.x,height:u.y1-u.y},this.quill.root),Array.from(p).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler=t=>{const{button:e,target:s,clientX:o,clientY:i}=t,l=s.closest(".ql-table");if(0!==e||!l)return;this.setSelectionTable(l);const n=l.dataset.tableId,r={x:o,y:i},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.dragging=!0,this.show();const d=t=>{this.tableMenu&&this.tableMenu.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.hide();const{button:e,target:s,clientX:o,clientY:i}=t,l=s.closest(".ql-table");if(0!==e||!l||l.dataset.tableId!==n)return;const a={x:o,y:i};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.update()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu&&this.selectedTds.length>0&&this.tableMenu.show()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)};updateWithSelectedTds(){if(this.selectedTds.length<=0)return;const t={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(const s of this.selectedTds){const o=s.domNode.getBoundingClientRect();t.x=Math.min(t.x,o.left),t.y=Math.min(t.y,o.top),e.x=Math.max(e.x,o.right),e.y=Math.max(e.y,o.bottom)}this.selectedTds=this.computeSelectedTds(t,e),this.selectedTds.length>0?this.update():this.hide()}update(){if(0===this.selectedTds.length||!this.boundary||!this.table)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:s,y:o}=this.getTableViewScroll(),i=this.table.parentElement.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect(),n=i.x-l.x,r=i.y-l.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-n+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-o-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${n}px`,top:`${r}px`,width:`${i.width+2}px`,height:`${i.height+2}px`}),!this.dragging&&this.tableMenu&&this.tableMenu.update()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return this.table?{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}:{x:0,y:0}}setSelectionTable(t){this.table!==t&&(this.table=t)}removeCell=t=>{if(!(this.quill.getSelection()||"Backspace"!==t.key&&"Delete"!==t.key)){for(const t of this.selectedTds)t.deleteAt(0,t.length()-1);if(this.table){const t=e.find(this.table),s=t.descendants(ie);this.selectedTds.length===s.length&&t.remove()}}};showDisplay(){Object.assign(this.cellSelectWrap.style,{display:"block"}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(Vt.call(this),this.update(),this.showDisplay(),document.addEventListener("keydown",this.removeCell),Pt.call(this,this.quill.root,(()=>{this.update()})),Pt.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(){Vt.call(this),document.removeEventListener("keydown",this.removeCell),this.hideDisplay(),this.boundary=null,this.selectedTds=[],this.setSelectionTable(void 0),this.tableMenu&&this.tableMenu.hide()}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Vt.call(this),this.quill.root.removeEventListener("mousedown",this.mouseDownHandler),document.removeEventListener("selectionchange",this.selectionChangeHandler),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.off(e.events.TEXT_CHANGE,this.updateAfterEvent),this.quill.on(i.AFTER_TABLE_RESIZE,this.updateAfterEvent)}},t.TableUp=ze,t.TableVirtualScrollbar=class{tableModule;table;quill;scrollbarContainer;scrollbar;bem=c("scrollbar");constructor(t,s,o){this.tableModule=t,this.table=s,this.quill=o,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Ee(o,!0,s,this.scrollbarContainer),new Ee(o,!1,s,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar);this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};hide(){for(const t of this.scrollbar)t.hideScrollbar()}show(){for(const t of this.scrollbar)t.showScrollbar()}update(){for(const t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}destroy(){this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange);for(const t of this.scrollbar)t.destroy()}},t.TableWrapperFormat=fe,t.blotName=s,t.createColorPicker=T,t.createSelectBox=S,t.createTooltip=Ht,t.default=ze,t.defaultCustomSelect=function(t,e){return S({onSelect:(s,o)=>{t.insertTable(s,o),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})},t.findParentBlot=d,t.findParentBlots=h,t.isTableAlignRight=Ne,t.randomId=_t,t.tableMenuTools=ye,t.tableUpEvent=i,t.tableUpInternal=l,t.tableUpSize=o,t.updateTableConstants=function(t){r.delete(s.tableCellInner),Object.assign(s,t.blotName||{}),Object.assign(o,t.tableUpSize||{}),Object.assign(i,t.tableUpEvent||{}),Object.assign(l,t.tableUpInternal||{}),ze.moduleName=l.moduleName,ze.toolName=s.tableWrapper,Kt.blotName=s.container,fe.blotName=s.tableWrapper,pe.blotName=s.tableMain,be.blotName=s.tableColgroup,ue.blotName=s.tableCol,ce.blotName=s.tableBody,ae.blotName=s.tableRow,de.blotName=s.tableCell,ie.blotName=s.tableCellInner,r.add(s.tableCellInner)},Object.defineProperty(t,"__esModule",{value:!0})}));
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("quill")):"function"==typeof define&&define.amd?define(["exports","quill"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TableUp={},t.Quill)}(this,(function(t,e){"use strict";const o={container:"table-up-container",tableCaption:"table-up-caption",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableBody:"table-up-body",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},s={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},i={AFTER_TABLE_RESIZE:"after-table-resize"},n={moduleName:"table-up"},l=[["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)"]],r="table-up",a=new Set([o.tableCellInner]);function c(t){return!(!t||!t.parent)&&(e=t.parent,!!a.has(e.statics.blotName)||c(t.parent));var e}function d(t,e=r){const o=e?`${e}-`:"";return{b:()=>`${o}${t}`,be:e=>e?`${o}${t}__${e}`:"",bm:e=>e?`${o}${t}--${e}`:"",bem:(e,s)=>e&&s?`${o}${t}__${e}--${s}`:"",ns:t=>t?`${o}${t}`:"",bs:e=>e?`${o}${t}-${e}`:"",cv:t=>t?`--${o}${t}`:"",is:t=>`is-${t}`}}function h(t,e){let o=t.parent;for(;o&&o.statics.blotName!==e&&o!==t.scroll;)o=o.parent;if(o===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return o}function u(t,e){const o=new Array(e.length),s=new Map(e.map(((t,e)=>[t,e])));let i=t.parent;for(;i&&i!==t.scroll&&0!==s.size;){if(s.has(i.statics.blotName)){o[s.get(i.statics.blotName)]=i,s.delete(i.statics.blotName)}i=i.parent}if(s.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(s.keys()).join(", ")}`);return o}function p(t){const e=new Map;let o=t;for(;o&&"scroll"!==o.statics.blotName;)e.set(o.statics.blotName,o),o=o.parent;return e}function b(t,e){const o=[],s=t.children.iterator();let i=null;for(;i=s();)i instanceof e&&o.push(i);return o}function m(t,e){for(const o of Object.getOwnPropertyNames(e))/^constructor$/.test(o)||Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(e,o));return t}function f(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 g(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 w(t){let{r:e,g:o,b:s,a:i}=t;e=f(e,255),o=f(o,255),s=f(s,255);const n=Math.max(e,o,s),l=Math.min(e,o,s);let r;const a=n,c=n-l,d=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(o-s)/c+(o<s?6:0);break;case o:r=(s-e)/c+2;break;case s:r=(e-o)/c+4}r/=6}return{h:360*r,s:100*d,b:100*a,a:i}}function v(t){let{h:e,s:o,b:s,a:i}=t;e=6*f(e,360),o=f(o,100),s=f(s,100);const n=Math.floor(e),l=e-n,r=s*(1-o),a=s*(1-l*o),c=s*(1-(1-l)*o),d=n%6,h=[s,a,r,r,c,s][d],u=[c,s,s,a,r,r][d],p=[r,r,c,s,s,a][d];return{r:Math.round(255*h),g:Math.round(255*u),b:Math.round(255*p),a:i}}function C(t){const e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(const t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")}const x=t=>C(v(t)),y=t=>"function"==typeof t,M=Array.isArray,I=t=>"string"==typeof t,N=t=>null!==t&&"object"==typeof t;function T(t){const{type:e="default",content:o}=t||{},s=d("button"),i=document.createElement("button");return i.classList.add(s.b(),e),o&&(I(o)?i.textContent=o:i.appendChild(o)),i}function L(t={}){const e=230,o=150,s=10;let i=w((n=(n=t.color||"#ff0000").startsWith("#")?n.slice(1):n,{r:Number.parseInt(n.slice(0,2),16),g:Number.parseInt(n.slice(2,4),16),b:Number.parseInt(n.slice(4,6),16),a:Number((Number.parseInt(n.slice(6,8)||"ff",16)/255).toFixed(2))}));var n;const l=d("color-picker"),r=document.createElement("div");r.classList.add(l.b());const a=document.createElement("div");a.classList.add(l.be("content"));const c=document.createElement("div");c.classList.add(l.be("selector"));const h=document.createElement("div");h.classList.add(l.be("background")),c.appendChild(h);const u=document.createElement("div");u.classList.add(l.be("background-handle")),h.appendChild(u);const p=document.createElement("div");p.classList.add(l.be("alpha"));const b=document.createElement("div");b.classList.add(l.be("alpha-bg"));const m=document.createElement("div");m.classList.add(l.be("alpha-handle")),p.appendChild(b),p.appendChild(m);const f=document.createElement("div");f.classList.add(l.be("hue"));const y=document.createElement("div");y.classList.add(l.be("hue-handle")),f.appendChild(y);const M=document.createElement("div");M.classList.add(l.be("action"));const[I,N,T,L]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(l.be("action-item"),t);const o=document.createElement("label");o.textContent=t.toUpperCase();const s=document.createElement("input");return s.classList.add(l.be("input")),s.addEventListener("input",(()=>{s.value=s.value.replaceAll(/[^0-9]/g,"")})),s.addEventListener("change",(()=>{let e=Math.round(Number(s.value));"a"===t&&(e/=100);A(g(w(Object.assign({},v(i),{[t]:e})))),k()})),e.appendChild(o),e.appendChild(s),M.appendChild(e),s}));a.appendChild(f),a.appendChild(c),a.appendChild(p),r.appendChild(a),r.appendChild(M);let S=!1,E=!1,B=!1;function R(){const t=x(i);for(const[e,o]of[I,N,T].entries())o.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));L.value=String((100*i.a).toFixed(0))}function k(){Object.assign(u.style,{left:`${Math.floor(e*i.s/100)}px`,top:`${Math.floor(o*(100-i.b)/100)}px`}),c.style.backgroundColor=`#${C(v({h:i.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(o-o*i.h/360)}px`,m.style.left=100*i.a+"%",function(){const{r:t,g:e,b:o}=v(i);b.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${o}, 0) 0%, rgba(${t}, ${e}, ${o}, 1) 100%)`}(),R()}function A(e){i=g(Object.assign({},i,e)),R(),t.onChange&&t.onChange(`#${x(i)}`)}function O(t){const s=c.getBoundingClientRect(),i=s.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=s.left+document.body.scrollLeft;A({s:Math.floor(100*Math.max(0,Math.min(e,t.pageX-n))/e),b:Math.floor(100*(o-Math.max(0,Math.min(o,t.pageY-i)))/o)}),k()}function z(t){const e=f.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);A({h:Math.floor(360*(o-Math.max(0,Math.min(o,t.pageY-e)))/o)}),k()}function q(t){const{pageX:e}=t,o=p.getBoundingClientRect();let i=e-o.left;i=Math.max(s/2,i),i=Math.min(i,o.width-s/2),A({a:Math.round((i-5)/(o.width-10)*100)/100}),k()}function $(t){S&&(t.preventDefault(),O(t)),E&&(t.preventDefault(),z(t)),B&&(t.preventDefault(),q(t))}function W(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",W),S=!1}function H(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",H),E=!1}function D(){document.removeEventListener("mousemove",$),document.removeEventListener("mouseup",D),B=!1}return c.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",W),S=!0,O(t)})),f.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",H),E=!0,z(t)})),p.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",$),document.addEventListener("mouseup",D),B=!0,q(t)})),k(),r}let S=8e3;function E({child:t,target:e=document.body,beforeClose:o=()=>{}}={}){const s=d("dialog"),i=e,n=document.createElement("div");n.classList.add(s.b()),n.style.zIndex=String(S);const l=document.createElement("div");if(l.classList.add(s.be("overlay")),n.appendChild(l),t){const e=document.createElement("div");e.classList.add(s.be("content")),e.appendChild(t),l.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const r=getComputedStyle(i).overflow;i.style.overflow="hidden",i.appendChild(n);const a=()=>{o(),n.remove(),i.style.overflow=r};return n.addEventListener("click",a),S+=1,{dialog:n,close:a}}function B(t,e){const o=d("input");e.type||(e.type="text"),e.value||(e.value="");const s=document.createElement("div");if(s.classList.add(o.be("item")),t){const e=document.createElement("span");e.classList.add(o.be("label")),e.textContent=t,s.appendChild(e)}const i=document.createElement("div");i.classList.add(o.be("input"));const n=document.createElement("input");for(const t in e)n.setAttribute(t,e[t]);(e.max||e.min)&&n.addEventListener("blur",(()=>{e.max&&e.max<=Number(n.value)&&(n.value=String(e.max)),e.min&&e.min>=Number(n.value)&&(n.value=String(e.min))})),i.appendChild(n),s.appendChild(i),n.addEventListener("focus",(()=>{i.classList.add("focus")})),n.addEventListener("blur",(()=>{i.classList.remove("focus")}));return{item:s,input:n,errorTip:t=>{let e;i.classList.contains("error")?e=i.querySelector(`.${o.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(o.be("error-tip")),i.appendChild(e)),e.textContent=t,i.classList.add("error");return{removeError:()=>{i.classList.remove("error"),e.remove()}}}}}function R(t={}){const e=d("select-box"),o=document.createElement("div");o.classList.add(e.b());const s=document.createElement("div");s.classList.add(e.be("block"));for(let o=0;o<(t.row||8);o++)for(let i=0;i<(t.col||8);i++){const t=document.createElement("div");t.classList.add(e.be("item")),t.dataset.row=String(o+1),t.dataset.col=String(i+1),s.appendChild(t)}const i=()=>{const{row:t,col:e}=o.dataset;for(const t of Array.from(s.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;const i=Array.from(s.children);for(let o=0;o<i.length;o++){const{row:s,col:n}=i[o].dataset;if(s>t&&n>e)return;s<=t&&n<=e?i[o].classList.add("active"):i[o].classList.remove("active")}};if(s.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:e,col:s}=t.target.dataset;e&&s&&(o.dataset.row=e,o.dataset.col=s,i())})),s.addEventListener("mouseleave",(()=>{o.removeAttribute("data-row"),o.removeAttribute("data-col"),i()})),s.addEventListener("click",(()=>{const{row:e,col:s}=o.dataset;e&&s&&t.onSelect&&t.onSelect(Number(e),Number(s))})),o.appendChild(s),t.customBtn){const s=t.texts||{},i=document.createElement("div");i.classList.add(e.be("custom")),i.textContent=s.customBtnText||"Custom",i.addEventListener("click",(async()=>{const e=await async function(t={}){const e=d("creator"),o=document.createElement("div");o.classList.add(e.b());const s=document.createElement("div");s.classList.add(e.be("input"));const{item:i,input:n,errorTip:l}=B(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:r,input:a,errorTip:c}=B(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});s.appendChild(i),s.appendChild(r),o.appendChild(s);const h=document.createElement("div");h.classList.add(e.be("control"));const u=T({type:"confirm",content:t.confirmText||"Confirm"}),p=T({type:"default",content:t.cancelText||"Cancel"});h.appendChild(u),h.appendChild(p),o.appendChild(h);const b=(e=Number(n.value),o=Number(a.value))=>{if(Number.isNaN(e)||e<=0)l(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(o)||o<=0))return{row:e,col:o};c(t.notPositiveNumberError||"Please enter a positive integer")}},m=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",m))};return new Promise(((t,e)=>{const{close:s}=E({child:o,beforeClose:e});n.focus();for(const e of[n,a])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=b();e&&(t(e),s())}}));u.addEventListener("click",(async()=>{const e=b();e&&(t(e),s())})),document.addEventListener("keydown",m),p.addEventListener("click",s)}))}(s);e&&t.onSelect&&t.onSelect(e.row,e.col)})),o.appendChild(i)}return o}const k=Math.min,A=Math.max,O=Math.round,z=Math.floor,q=t=>({x:t,y:t}),$={left:"right",right:"left",bottom:"top",top:"bottom"},W={start:"end",end:"start"};function H(t,e,o){return A(t,k(e,o))}function D(t,e){return"function"==typeof t?t(e):t}function F(t){return t.split("-")[0]}function j(t){return t.split("-")[1]}function P(t){return"x"===t?"y":"x"}function V(t){return"y"===t?"height":"width"}function _(t){return["top","bottom"].includes(F(t))?"y":"x"}function X(t){return P(_(t))}function U(t){return t.replace(/start|end/g,(t=>W[t]))}function Y(t){return t.replace(/left|right|bottom|top/g,(t=>$[t]))}function G(t){const{x:e,y:o,width:s,height:i}=t;return{width:s,height:i,top:o,left:e,right:e+s,bottom:o+i,x:e,y:o}}function K(t,e,o){let{reference:s,floating:i}=t;const n=_(e),l=X(e),r=V(l),a=F(e),c="y"===n,d=s.x+s.width/2-i.width/2,h=s.y+s.height/2-i.height/2,u=s[r]/2-i[r]/2;let p;switch(a){case"top":p={x:d,y:s.y-i.height};break;case"bottom":p={x:d,y:s.y+s.height};break;case"right":p={x:s.x+s.width,y:h};break;case"left":p={x:s.x-i.width,y:h};break;default:p={x:s.x,y:s.y}}switch(j(e)){case"start":p[l]-=u*(o&&c?-1:1);break;case"end":p[l]+=u*(o&&c?-1:1)}return p}async function Z(t,e){var o;void 0===e&&(e={});const{x:s,y:i,platform:n,rects:l,elements:r,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:u=!1,padding:p=0}=D(e,t),b=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),m=r[u?"floating"===h?"reference":"floating":h],f=G(await n.getClippingRect({element:null==(o=await(null==n.isElement?void 0:n.isElement(m)))||o?m:m.contextElement||await(null==n.getDocumentElement?void 0:n.getDocumentElement(r.floating)),boundary:c,rootBoundary:d,strategy:a})),g="floating"===h?{x:s,y:i,width:l.floating.width,height:l.floating.height}:l.reference,w=await(null==n.getOffsetParent?void 0:n.getOffsetParent(r.floating)),v=await(null==n.isElement?void 0:n.isElement(w))&&await(null==n.getScale?void 0:n.getScale(w))||{x:1,y:1},C=G(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-C.top+b.top)/v.y,bottom:(C.bottom-f.bottom+b.bottom)/v.y,left:(f.left-C.left+b.left)/v.x,right:(C.right-f.right+b.right)/v.x}}function Q(){return"undefined"!=typeof window}function J(t){return ot(t)?(t.nodeName||"").toLowerCase():"#document"}function tt(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function et(t){var e;return null==(e=(ot(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function ot(t){return!!Q()&&(t instanceof Node||t instanceof tt(t).Node)}function st(t){return!!Q()&&(t instanceof Element||t instanceof tt(t).Element)}function it(t){return!!Q()&&(t instanceof HTMLElement||t instanceof tt(t).HTMLElement)}function nt(t){return!(!Q()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof tt(t).ShadowRoot)}function lt(t){const{overflow:e,overflowX:o,overflowY:s,display:i}=ut(t);return/auto|scroll|overlay|hidden|clip/.test(e+s+o)&&!["inline","contents"].includes(i)}function rt(t){return["table","td","th"].includes(J(t))}function at(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function ct(t){const e=dt(),o=st(t)?ut(t):t;return["transform","translate","scale","rotate","perspective"].some((t=>!!o[t]&&"none"!==o[t]))||!!o.containerType&&"normal"!==o.containerType||!e&&!!o.backdropFilter&&"none"!==o.backdropFilter||!e&&!!o.filter&&"none"!==o.filter||["transform","translate","scale","rotate","perspective","filter"].some((t=>(o.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(o.contain||"").includes(t)))}function dt(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function ht(t){return["html","body","#document"].includes(J(t))}function ut(t){return tt(t).getComputedStyle(t)}function pt(t){return st(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function bt(t){if("html"===J(t))return t;const e=t.assignedSlot||t.parentNode||nt(t)&&t.host||et(t);return nt(e)?e.host:e}function mt(t){const e=bt(t);return ht(e)?t.ownerDocument?t.ownerDocument.body:t.body:it(e)&&lt(e)?e:mt(e)}function ft(t,e,o){var s;void 0===e&&(e=[]),void 0===o&&(o=!0);const i=mt(t),n=i===(null==(s=t.ownerDocument)?void 0:s.body),l=tt(i);if(n){const t=gt(l);return e.concat(l,l.visualViewport||[],lt(i)?i:[],t&&o?ft(t):[])}return e.concat(i,ft(i,[],o))}function gt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function wt(t){const e=ut(t);let o=parseFloat(e.width)||0,s=parseFloat(e.height)||0;const i=it(t),n=i?t.offsetWidth:o,l=i?t.offsetHeight:s,r=O(o)!==n||O(s)!==l;return r&&(o=n,s=l),{width:o,height:s,$:r}}function vt(t){return st(t)?t:t.contextElement}function Ct(t){const e=vt(t);if(!it(e))return q(1);const o=e.getBoundingClientRect(),{width:s,height:i,$:n}=wt(e);let l=(n?O(o.width):o.width)/s,r=(n?O(o.height):o.height)/i;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const xt=q(0);function yt(t){const e=tt(t);return dt()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:xt}function Mt(t,e,o,s){void 0===e&&(e=!1),void 0===o&&(o=!1);const i=t.getBoundingClientRect(),n=vt(t);let l=q(1);e&&(s?st(s)&&(l=Ct(s)):l=Ct(t));const r=function(t,e,o){return void 0===e&&(e=!1),!(!o||e&&o!==tt(t))&&e}(n,o,s)?yt(n):q(0);let a=(i.left+r.x)/l.x,c=(i.top+r.y)/l.y,d=i.width/l.x,h=i.height/l.y;if(n){const t=tt(n),e=s&&st(s)?tt(s):s;let o=t,i=gt(o);for(;i&&s&&e!==o;){const t=Ct(i),e=i.getBoundingClientRect(),s=ut(i),n=e.left+(i.clientLeft+parseFloat(s.paddingLeft))*t.x,l=e.top+(i.clientTop+parseFloat(s.paddingTop))*t.y;a*=t.x,c*=t.y,d*=t.x,h*=t.y,a+=n,c+=l,o=tt(i),i=gt(o)}}return G({width:d,height:h,x:a,y:c})}function It(t,e){const o=pt(t).scrollLeft;return e?e.left+o:Mt(et(t)).left+o}function Nt(t,e,o){void 0===o&&(o=!1);const s=t.getBoundingClientRect();return{x:s.left+e.scrollLeft-(o?0:It(t,s)),y:s.top+e.scrollTop}}function Tt(t,e,o){let s;if("viewport"===e)s=function(t,e){const o=tt(t),s=et(t),i=o.visualViewport;let n=s.clientWidth,l=s.clientHeight,r=0,a=0;if(i){n=i.width,l=i.height;const t=dt();(!t||t&&"fixed"===e)&&(r=i.offsetLeft,a=i.offsetTop)}return{width:n,height:l,x:r,y:a}}(t,o);else if("document"===e)s=function(t){const e=et(t),o=pt(t),s=t.ownerDocument.body,i=A(e.scrollWidth,e.clientWidth,s.scrollWidth,s.clientWidth),n=A(e.scrollHeight,e.clientHeight,s.scrollHeight,s.clientHeight);let l=-o.scrollLeft+It(t);const r=-o.scrollTop;return"rtl"===ut(s).direction&&(l+=A(e.clientWidth,s.clientWidth)-i),{width:i,height:n,x:l,y:r}}(et(t));else if(st(e))s=function(t,e){const o=Mt(t,!0,"fixed"===e),s=o.top+t.clientTop,i=o.left+t.clientLeft,n=it(t)?Ct(t):q(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:i*n.x,y:s*n.y}}(e,o);else{const o=yt(t);s={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return G(s)}function Lt(t,e){const o=bt(t);return!(o===e||!st(o)||ht(o))&&("fixed"===ut(o).position||Lt(o,e))}function St(t,e,o){const s=it(e),i=et(e),n="fixed"===o,l=Mt(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=q(0);if(s||!s&&!n)if(("body"!==J(e)||lt(i))&&(r=pt(e)),s){const t=Mt(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else i&&(a.x=It(i));const c=!i||s||n?q(0):Nt(i,r);return{x:l.left+r.scrollLeft-a.x-c.x,y:l.top+r.scrollTop-a.y-c.y,width:l.width,height:l.height}}function Et(t){return"static"===ut(t).position}function Bt(t,e){if(!it(t)||"fixed"===ut(t).position)return null;if(e)return e(t);let o=t.offsetParent;return et(t)===o&&(o=o.ownerDocument.body),o}function Rt(t,e){const o=tt(t);if(at(t))return o;if(!it(t)){let e=bt(t);for(;e&&!ht(e);){if(st(e)&&!Et(e))return e;e=bt(e)}return o}let s=Bt(t,e);for(;s&&rt(s)&&Et(s);)s=Bt(s,e);return s&&ht(s)&&Et(s)&&!ct(s)?o:s||function(t){let e=bt(t);for(;it(e)&&!ht(e);){if(ct(e))return e;if(at(e))return null;e=bt(e)}return null}(t)||o}const kt={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:o,offsetParent:s,strategy:i}=t;const n="fixed"===i,l=et(s),r=!!e&&at(e.floating);if(s===l||r&&n)return o;let a={scrollLeft:0,scrollTop:0},c=q(1);const d=q(0),h=it(s);if((h||!h&&!n)&&(("body"!==J(s)||lt(l))&&(a=pt(s)),it(s))){const t=Mt(s);c=Ct(s),d.x=t.x+s.clientLeft,d.y=t.y+s.clientTop}const u=!l||h||n?q(0):Nt(l,a,!0);return{width:o.width*c.x,height:o.height*c.y,x:o.x*c.x-a.scrollLeft*c.x+d.x+u.x,y:o.y*c.y-a.scrollTop*c.y+d.y+u.y}},getDocumentElement:et,getClippingRect:function(t){let{element:e,boundary:o,rootBoundary:s,strategy:i}=t;const n=[..."clippingAncestors"===o?at(e)?[]:function(t,e){const o=e.get(t);if(o)return o;let s=ft(t,[],!1).filter((t=>st(t)&&"body"!==J(t))),i=null;const n="fixed"===ut(t).position;let l=n?bt(t):t;for(;st(l)&&!ht(l);){const e=ut(l),o=ct(l);o||"fixed"!==e.position||(i=null),(n?!o&&!i:!o&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||lt(l)&&!o&&Lt(t,l))?s=s.filter((t=>t!==l)):i=e,l=bt(l)}return e.set(t,s),s}(e,this._c):[].concat(o),s],l=n[0],r=n.reduce(((t,o)=>{const s=Tt(e,o,i);return t.top=A(s.top,t.top),t.right=k(s.right,t.right),t.bottom=k(s.bottom,t.bottom),t.left=A(s.left,t.left),t}),Tt(e,l,i));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:Rt,getElementRects:async function(t){const e=this.getOffsetParent||Rt,o=this.getDimensions,s=await o(t.floating);return{reference:St(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:s.width,height:s.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:o}=wt(t);return{width:e,height:o}},getScale:Ct,isElement:st,isRTL:function(t){return"rtl"===ut(t).direction}};function At(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Ot(t,e,o,s){void 0===s&&(s={});const{ancestorScroll:i=!0,ancestorResize:n=!0,elementResize:l="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=s,c=vt(t),d=i||n?[...c?ft(c):[],...ft(e)]:[];d.forEach((t=>{i&&t.addEventListener("scroll",o,{passive:!0}),n&&t.addEventListener("resize",o)}));const h=c&&r?function(t,e){let o,s=null;const i=et(t);function n(){var t;clearTimeout(o),null==(t=s)||t.disconnect(),s=null}return function l(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),n();const c=t.getBoundingClientRect(),{left:d,top:h,width:u,height:p}=c;if(r||e(),!u||!p)return;const b={rootMargin:-z(h)+"px "+-z(i.clientWidth-(d+u))+"px "+-z(i.clientHeight-(h+p))+"px "+-z(d)+"px",threshold:A(0,k(1,a))||1};let m=!0;function f(e){const s=e[0].intersectionRatio;if(s!==a){if(!m)return l();s?l(!1,s):o=setTimeout((()=>{l(!1,1e-7)}),1e3)}1!==s||At(c,t.getBoundingClientRect())||l(),m=!1}try{s=new IntersectionObserver(f,{...b,root:i.ownerDocument})}catch(t){s=new IntersectionObserver(f,b)}s.observe(t)}(!0),n}(c,o):null;let u,p=-1,b=null;l&&(b=new ResizeObserver((t=>{let[s]=t;s&&s.target===c&&b&&(b.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame((()=>{var t;null==(t=b)||t.observe(e)}))),o()})),c&&!a&&b.observe(c),b.observe(e));let m=a?Mt(t):null;return a&&function e(){const s=Mt(t);m&&!At(m,s)&&o();m=s,u=requestAnimationFrame(e)}(),o(),()=>{var t;d.forEach((t=>{i&&t.removeEventListener("scroll",o),n&&t.removeEventListener("resize",o)})),null==h||h(),null==(t=b)||t.disconnect(),b=null,a&&cancelAnimationFrame(u)}}const zt=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var o,s;const{x:i,y:n,placement:l,middlewareData:r}=e,a=await async function(t,e){const{placement:o,platform:s,elements:i}=t,n=await(null==s.isRTL?void 0:s.isRTL(i.floating)),l=F(o),r=j(o),a="y"===_(o),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=D(e,t);let{mainAxis:u,crossAxis:p,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return r&&"number"==typeof b&&(p="end"===r?-1*b:b),a?{x:p*d,y:u*c}:{x:u*c,y:p*d}}(e,t);return l===(null==(o=r.offset)?void 0:o.placement)&&null!=(s=r.arrow)&&s.alignmentOffset?{}:{x:i+a.x,y:n+a.y,data:{...a,placement:l}}}}},qt=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:o,y:s,placement:i}=e,{mainAxis:n=!0,crossAxis:l=!1,limiter:r={fn:t=>{let{x:e,y:o}=t;return{x:e,y:o}}},...a}=D(t,e),c={x:o,y:s},d=await Z(e,a),h=_(F(i)),u=P(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=H(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=H(b+d["y"===h?"top":"left"],b,b-d[t])}const m=r.fn({...e,[u]:p,[h]:b});return{...m,data:{x:m.x-o,y:m.y-s,enabled:{[u]:n,[h]:l}}}}}},$t=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var o,s;const{placement:i,middlewareData:n,rects:l,initialPlacement:r,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:u,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:m=!0,...f}=D(t,e);if(null!=(o=n.arrow)&&o.alignmentOffset)return{};const g=F(i),w=_(r),v=F(r)===r,C=await(null==a.isRTL?void 0:a.isRTL(c.floating)),x=u||(v||!m?[Y(r)]:function(t){const e=Y(t);return[U(t),e,U(e)]}(r)),y="none"!==b;!u&&y&&x.push(...function(t,e,o,s){const i=j(t);let n=function(t,e,o){const s=["left","right"],i=["right","left"],n=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return o?e?i:s:e?s:i;case"left":case"right":return e?n:l;default:return[]}}(F(t),"start"===o,s);return i&&(n=n.map((t=>t+"-"+i)),e&&(n=n.concat(n.map(U)))),n}(r,m,b,C));const M=[r,...x],I=await Z(e,f),N=[];let T=(null==(s=n.flip)?void 0:s.overflows)||[];if(d&&N.push(I[g]),h){const t=function(t,e,o){void 0===o&&(o=!1);const s=j(t),i=X(t),n=V(i);let l="x"===i?s===(o?"end":"start")?"right":"left":"start"===s?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=Y(l)),[l,Y(l)]}(i,l,C);N.push(I[t[0]],I[t[1]])}if(T=[...T,{placement:i,overflows:N}],!N.every((t=>t<=0))){var L,S;const t=((null==(L=n.flip)?void 0:L.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:T},reset:{placement:e}};let o=null==(S=T.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:S.placement;if(!o)switch(p){case"bestFit":{var E;const t=null==(E=T.filter((t=>{if(y){const e=_(t.placement);return e===w||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:E[0];t&&(o=t);break}case"initialPlacement":o=r}if(i!==o)return{reset:{placement:o}}}return{}}}},Wt=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:o,y:s,placement:i,rects:n,middlewareData:l}=e,{offset:r=0,mainAxis:a=!0,crossAxis:c=!0}=D(t,e),d={x:o,y:s},h=_(i),u=P(h);let p=d[u],b=d[h];const m=D(r,e),f="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const t="y"===u?"height":"width",e=n.reference[u]-n.floating[t]+f.mainAxis,o=n.reference[u]+n.reference[t]-f.mainAxis;p<e?p=e:p>o&&(p=o)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(F(i)),o=n.reference[h]-n.floating[t]+(e&&(null==(g=l.offset)?void 0:g[h])||0)+(e?0:f.crossAxis),s=n.reference[h]+n.reference[t]+(e?0:(null==(w=l.offset)?void 0:w[h])||0)-(e?f.crossAxis:0);b<o?b=o:b>s&&(b=s)}return{[u]:p,[h]:b}}}},Ht=(t,e,o)=>{const s=new Map,i={platform:kt,...o},n={...i.platform,_c:s};return(async(t,e,o)=>{const{placement:s="bottom",strategy:i="absolute",middleware:n=[],platform:l}=o,r=n.filter(Boolean),a=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:h}=K(c,s,a),u=s,p={},b=0;for(let o=0;o<r.length;o++){const{name:n,fn:m}=r[o],{x:f,y:g,data:w,reset:v}=await m({x:d,y:h,initialPlacement:s,placement:u,strategy:i,middlewareData:p,rects:c,platform:l,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[n]:{...p[n],...w}},v&&b<=50&&(b++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(c=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:i}):v.rects),({x:d,y:h}=K(c,u,a))),o=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:n})};let Dt;function Ft(t,e={}){const{msg:o="",delay:s=150,content:i,direction:n="bottom",type:l="hover",container:r,onOpen:a,onClose:c,closed:h,onDestroy:u}=e,p=d("tooltip");if(o||i){Dt||(Dt=document.createElement("div"),document.body.appendChild(Dt));const e=r||Dt,d=document.createElement("div");let b,m,f;d.classList.add(p.b(),"hidden","transparent"),i?d.appendChild(i):o&&(d.textContent=o);const g=()=>{f&&f(),Ht(t,d,{placement:n,middleware:[$t(),qt({limiter:Wt()}),zt(4)]}).then((({x:t,y:e})=>{Object.assign(d.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{d.classList.add("hidden"),e.contains(d)&&e.removeChild(d),f&&f(),h&&h()},v=(o=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(a){const t=a(o);if(!o&&t)return}e.appendChild(d),d.removeEventListener("transitionend",w),d.classList.remove("hidden"),f=Ot(t,d,g),d.classList.remove("transparent")}),s)},C=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(c){const e=c(t);if(!t&&e)return}!function(t,e,o,s,i){t.addEventListener("transitionend",o,s),setTimeout((()=>{o()}),e)}(d,150,w,{once:!0}),d.classList.add("transparent")}),s)},x=()=>{const e=t=>{t.stopPropagation(),C(!1)},o=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{d.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",o)},show:v,hide:(t=!1)=>{C(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",o),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,d],o=C.bind(void 0,!1),s=v.bind(void 0,!1);return{prepare:()=>{for(const t of e)t.addEventListener("mouseenter",s),t.addEventListener("mouseleave",o)},show:v,hide:C,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",s),t.removeEventListener("mouseleave",o)}}},click:x},{prepare:M,show:I,hide:N,destroy:T}=y[l]();M();const L=()=>{N(!0),u&&u(),T(),f&&f(),d.remove()};return{show:I,hide:N,destroy:L}}return null}function jt(t,e,o=0,s=!0){const{x:i,y:n,x1:l,y1:r}=t,{x:a,y:c,x1:d,y1:h}=e;let u,p;return s?(u=l<a+o||i-o>d,p=r<c+o||n-o>h):(u=l<=a+o||i-o>=d,p=r<=c+o||n-o>=h),!(u||p)}function Pt(t){let{left:e,top:o,width:s,height:i}=t;const{clientWidth:n,clientHeight:l}=document.documentElement;let r=!1,a=!1;return e+s>n?(e=n-s-8,r=!0):e<0&&(e=8,r=!0),o+i>l?(o=l-i-8,a=!0):o<0&&(o=8,a=!0),{left:e,top:o,leftLimited:r,topLimited:a}}function Vt(t,e={}){const o=Symbol("ignoreFirstBind"),s=new Set,i=new ResizeObserver((s=>{e.ignoreFirstBind&&s.some((t=>{const e=t.target,s=e[o];return e[o]=!0,!s}))||t(s)})),n=i.observe;i.observe=(t,e)=>{s.add(t),n.call(i,t,e)};const l=i.unobserve;i.unobserve=t=>{s.has(t)&&(s.delete(t),t[o]=void 0),l.call(i,t)};const r=i.disconnect;return i.disconnect=()=>{for(const t of s.values())t[o]=void 0;r.call(i)},i}function _t(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Xt(){for(let t=0;t<this.scrollHandler.length;t++){const[e,o]=this.scrollHandler[t];e.removeEventListener("scroll",o)}this.scrollHandler=[]}function Ut(t){const e={},o=t.trim().split(";");for(let t=0;t<o.length;t++){const s=o[t].trim();if(!s)continue;const i=s.indexOf(":");if(-1===i)continue;const n=s.slice(0,Math.max(0,i)).trim(),l=s.slice(Math.max(0,i+1)).trim();e[n]=l}return e}const Yt=()=>Math.random().toString(36).slice(2);function Gt(t,e){let o;return function(...s){o&&clearTimeout(o),o=setTimeout((()=>{t.apply(this,s)}),e)}}const Kt=e.import("parchment"),Zt=e.import("blots/container"),Qt=e.import("blots/block"),Jt=e.import("blots/block/embed");class te extends Zt{static tagName;static blotName=o.container;static scope=Kt.Scope.BLOCK_BLOT;static allowedChildren=[Qt,Jt,Zt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,o){const[s]=this.children.find(t);if(!s){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,o)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}enforceAllowedChildren(){this.children.forEach((t=>{this.statics.allowedChildren.some((e=>t instanceof e))||(t.statics.scope===Kt.Scope.BLOCK_BLOT?(t.parent instanceof te?(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 Kt.ParentBlot?t.unwrap():t.remove())}))}}const ee=e.import("parchment"),oe=e.import("blots/block");class se extends oe{replaceWith(t,e){const s="string"==typeof t?this.scroll.create(t,e):t;if(s instanceof ee.ParentBlot){if(s.statics.blotName===o.tableCellInner){const t=this.parent;if(t.statics.blotName===o.tableCellInner){if(null!=t&&t.insertBefore(s,this.prev?null:this.next),t.statics.blotName===o.tableCellInner){let t=this;for(;t;){const e=t.next;s.appendChild(t),t=e}}else s.appendChild(this);if(t&&0===t.length()){t.remove(),t.parent.statics.blotName===o.tableCell&&0===t.parent.length()&&t.parent.remove();const e=t.parent.parent;e.statics.blotName===o.tableRow&&0===e.children.length&&e.remove()}}else null!=t&&t.insertBefore(s,this.next),s.appendChild(this);return s}this.moveChildren(s)}return null!=this.parent&&(this.parent.insertBefore(s,this.next||void 0),this.remove()),this.attributes.copy(s),s}format(t,e){if(t!==o.tableCellInner||this.parent.statics.blotName!==t||e)super.format(t,e);else try{h(this,o.tableCellInner).unwrap()}catch{console.error("unwrap TableCellInner error")}}}const ie=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},ne=e.import("blots/block"),le=e.import("blots/block/embed");class re extends te{static blotName=o.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan"]);static defaultChild=ne;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:o,colId:s,rowspan:i,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=o,r.dataset.colId=s,r.dataset.rowspan=String(ie(i)),r.dataset.colspan=String(ie(n)),l&&(r.dataset.style=l),r}static formats(t){const{tableId:e,rowId:o,colId:s,rowspan:i,colspan:n,style:l}=t.dataset,r={tableId:String(e),rowId:String(o),colId:String(s),rowspan:Number(ie(i)),colspan:Number(ie(n))};return l&&(r.style=l),r}constructor(t,e,o){super(t,e),e.setAttribute("contenteditable",String(t.isEnabled()))}setFormatValue(t,e,s=!1){if(s){if(!this.statics.isAllowStyle(t))return;this.parent&&this.parent.statics.blotName===o.tableCell&&this.parent.setFormatValue(t,e)}else{if(!this.statics.allowDataAttrs.has(t))return;const s=`data-${t}`;e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s),this.parent&&this.parent.statics.blotName===o.tableCell&&this.parent.setFormatValue(t,e)}const i=this.descendants(ne,0);for(const t of i)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(t){this.setFormatValue("row-id",t)}get colId(){return this.domNode.dataset.colId}set colId(t){this.setFormatValue("col-id",t)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(t){this.setFormatValue("rowspan",t)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(t){this.setFormatValue("colspan",t)}getColumnIndex(){return h(this,o.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,o,s){if(0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,o,s),s&&s.style){const t=Ut(s.style);for(const[e,o]of Object.entries(t))this.setFormatValue(e,o,!0)}}formats(){const t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:o,rowspan:s}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===o&&i.rowspan===s}optimize(){const t=this.parent,e=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof le){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==o.tableCell&&(this.wrap(o.tableCell,e),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,e){if(t.statics.blotName===this.statics.blotName){const s=t,i=this.statics.formats(s.domNode),n=this.statics.formats(this.domNode);if(Object.entries(n).every((([t,e])=>e===i[t])))return this.parent.insertBefore(s,this.next);{const[t,l]=u(this,[o.tableRow,o.tableCell]);if(e){const s=e.offset();if(s+1<this.length()){const e=this.scroll.create(o.tableCellInner,n);this.children.forEachAt(s+1,this.length(),(t=>{e.appendChild(t)})),t.insertBefore(e.wrap(o.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==s.rowId){if(e){const o=e.offset(t);t.split(o)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(o.tableRow,i),r=this.scroll.create(o.tableCell,i);return r.appendChild(s),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(s.wrap(o.tableCell,i),e?l:l.next)}}super.insertBefore(t,e)}}const ae=e.import("parchment"),ce=e.import("blots/scroll");class de extends ce{enable(t=!0){const s=e.import(`formats/${o.tableCellInner}`),i=this.domNode.querySelectorAll(`.${s.className}`);for(const e of Array.from(i))e.setAttribute("contenteditable",String(!!t));const n=e.import(`formats/${o.tableCaption}`),l=this.domNode.querySelectorAll(`.${n.className}`);for(const e of Array.from(l))e.setAttribute("contenteditable",String(!!t));super.enable(t)}createBlock(t,e){let s,i={};if(t[o.tableCellInner])s=o.tableCellInner;else for(const[e,o]of Object.entries(t)){null!=this.query(e,ae.Scope.BLOCK&ae.Scope.BLOT)?s=e:i[e]=o}s===o.tableCellInner&&(i={...t},delete i[s]);const n=this.create(s||this.statics.defaultChild.blotName,s?t[s]:void 0);this.insertBefore(n,e||void 0);let l=n.length();n instanceof re&&0===l&&(l+=1);for(const[t,e]of Object.entries(i))n.formatAt(0,l,t,e);return n}}class he extends te{static blotName=o.tableRow;static tagName="tr";static className="ql-table-row";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,e.dataset.rowId=t.rowId,e}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}getCellByColId(t,e){const s=h(this,o.tableMain).getColIds(),i=s.indexOf(t),n=this.children.iterator();let l=null;for(;l=n();){if(l.colId===t)return l;const e=s.indexOf(l.colId);if(e<i&&e+l.colspan>i)return l}return this[e]&&this[e].statics.blotName===o.tableRow?this[e].getCellByColId(t,e):null}insertCell(t,e){const s=[],i=this.children.iterator();let n,l=0;for(;(n=i())&&(l+=n.colspan,!(l>t));)if(1!==n.rowspan)for(let t=0;t<n.rowspan-1;t++)s[t]=(s[t]||0)+n.colspan;if(n&&l-n.colspan<t){n.getCellInner().colspan+=1,1!==n.rowspan&&(s.skipRowNum=n.rowspan-1)}else{const t=this.scroll.create(o.tableCell,e),s=this.scroll.create(o.tableCellInner,e),i=this.scroll.create("block");i.appendChild(this.scroll.create("break")),s.appendChild(i),t.appendChild(s),this.insertBefore(t,n)}return s}getCellByColumIndex(t){const e=[];let o=null,s=0;if(t<0)return[o,s,e];const i=this.children.iterator();for(;o=i();){if(s+=o.colspan,1!==o.rowspan)for(let t=0;t<o.rowspan-1;t++)e[t]=(e[t]||0)+o.colspan;if(s>t)break}return[o,s,e]}removeCell(t){if(t<0)return[];const e=this.getCellByColumIndex(t),[s,i]=e,n=e[2];if(!s)return n;if(i-s.colspan<t||s.colspan>1){const[e]=s.descendants(re);if(1!==s.colspan&&t===i-s.colspan){const t=h(this,o.tableMain).getColIds();e.colId=t[t.indexOf(e.colId)+1]}1!==s.rowspan&&(n.skipRowNum=s.rowspan-1),e.colspan-=1}else s.remove();return n}foreachCellInner(t){const e=this.children.iterator();let o,s=0;for(;o=e();){const[e]=o.descendants(re);if(t(e,s++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const e=this.parent,{tableId:s}=this;null!==e&&e.statics.blotName!==o.tableBody&&this.wrap(o.tableBody,s),super.optimize(t)}}class ue extends te{static blotName=o.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const e=h(this,o.tableMain);if(!e)return;const s=e.getColIds(),i=this.descendants(he),n=new Set(s);let l=0;for(const e of i){if(l===t)break;e.foreachCellInner((e=>{if(l+e.rowspan>t&&(e.rowspan+=1,n.delete(e.colId),1!==e.colspan)){const t=s.indexOf(e.colId);for(let o=0;o<e.colspan-1;o++)n.delete(s[t+o+1])}})),l+=1}const r=e.tableId,a=Yt(),c=this.scroll.create(o.tableRow,{tableId:r,rowId:a});for(const t of n){const e=this.scroll.create("break").wrap("block").wrap(o.tableCellInner,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1}).wrap(o.tableCell,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1});c.appendChild(e)}this.insertBefore(c,i[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent;if(null!==e&&e.statics.blotName!==o.tableMain){const{tableId:t}=this;this.wrap(o.tableMain,{tableId:t})}super.optimize(t)}}const pe=e.import("parchment"),be=e.import("blots/inline"),me=e.import("blots/text");class fe extends se{static blotName=o.tableCaption;static tagName="caption";static className="ql-table-caption";static allowedChildren=[be,me];static create(t){const{tableId:e}=t,o=super.create();return o.dataset.tableId=e,"bottom"===t.side&&(o.style.captionSide="bottom"),o}static formats(t){const{tableId:e}=t.dataset;return{tableId:String(e),side:"bottom"===t.style.captionSide?"bottom":"top"}}constructor(t,e,o){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")}))}createUI(){const t=document.createElement("i");return t.classList.add("ql-table-caption--switch"),t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\r\n \x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e\r\n <path\r\n fill="none"\r\n stroke="currentColor"\r\n stroke-linecap="round"\r\n stroke-linejoin="round"\r\n stroke-width="2"\r\n d="M7 3v18m3-15L7 3L4 6m16 12l-3 3l-3-3m3 3V3"\r\n />\r\n</svg>\r\n',t.addEventListener("click",(()=>{this.scroll.isEnabled()&&(this.side="top"===this.side?"bottom":"top")})),t}get tableId(){return this.domNode.dataset.tableId}set side(t){this.domNode.style.captionSide="bottom"===t?"bottom":"top"}get side(){return"bottom"===this.domNode.style.captionSide?"bottom":"top"}format(t,e){this.scroll.query(t,pe.Scope.BLOCK_BLOT)&&t!==this.statics.blotName||super.format(t,e)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent;if(null!==e&&e.statics.blotName!==o.tableMain){const{tableId:t}=this;this.wrap(o.tableMain,{tableId:t})}0===this.children.length?this.remove():(super.optimize(t),null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()))}}class ge extends te{static blotName=o.tableCell;static tagName="td";static className="ql-table-cell";static allowDataAttrs=new Set(["table-id","row-id","col-id"]);static allowAttrs=new Set(["rowspan","colspan"]);static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:o,colId:s,rowspan:i,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=o,r.dataset.colId=s,r.setAttribute("rowspan",String(ie(i))),r.setAttribute("colspan",String(ie(n))),l&&(r.style.cssText=l),r}static formats(t){const{tableId:e,rowId:o,colId:s}=t.dataset,i=Number(t.getAttribute("rowspan")),n=Number(t.getAttribute("colspan")),l={tableId:e,rowId:o,colId:s,rowspan:ie(i),colspan:ie(n)},r={};for(let e=0;e<t.style.length;e++){const o=t.style[e],s=t.style[o];this.isAllowStyle(String(o))&&!["initial","inherit"].includes(s)&&(r[o]=s)}const a=Object.entries(r);return a.length>0&&(l.style=a.map((([t,e])=>`${t}:${e}`)).join(";")),l}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let o=t;this.statics.allowDataAttrs.has(t)&&(o=`data-${t}`),e?this.domNode.setAttribute(o,e):this.domNode.removeAttribute(o)}else this.statics.isAllowStyle(t)&&(Object.assign(this.domNode.style,{[t]:e}),t.startsWith("border")&&this.setStyleBoder(t,e));this.children.head&&this.children.head.statics.blotName===o.tableCellInner&&this.domNode.style.cssText&&(this.children.head.domNode.dataset.style=this.domNode.style.cssText)}setStyleBoder(t,e){const o=Boolean(e)?e:null;if(!(!["left","right","top","bottom"].some((e=>t.includes(e)))&&t.startsWith("border-")))return;const s=this.getNearByCell("left").map((t=>t.descendant(re,0)[0])).filter(Boolean);for(const e of s)e.setFormatValue(t.replace("border-","border-right-"),o,!0);const i=this.getNearByCell("top").map((t=>t.descendant(re,0)[0])).filter(Boolean);for(const e of i)e.setFormatValue(t.replace("border-","border-bottom-"),o,!0)}getNearByCell(t){const e=[];try{const t=h(this,o.tableMain);e.push(...t.getColIds())}catch(t){console.error(`Cell is not in table! ${t}`)}if(0===e.length)return[];if("left"===t){const t=new Set;let o=this.parent;for(let s=0;s<this.rowspan&&o instanceof he;s++){const s=o.children.iterator();let i=null;for(;i=s();){const o=e.indexOf(i.colId)+i.colspan;this.colId===e[o]&&t.add(i)}o=o.next}return Array.from(t)}if("top"===t){if(!(this.parent instanceof he&&this.parent.prev))return[];const t=new Set,o=this.getColumnIndex(),s=o+this.colspan,i=new Set(e.filter(((t,e)=>e>=o&&e<s)));let n=1,l=this.parent.prev;for(;l;){let o=!1;const s=l.children.iterator();let r=null,a=0;for(;r=s();)i.has(r.colId)&&r.rowspan>=n&&(t.add(r),i.delete(r.colId)),a+=r.colspan,r.rowspan>=n&&(o=!0);if(!o&&a===e.length)break;l=l.prev,n+=1}return Array.from(t)}return[]}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute("rowspan"))}get colspan(){return Number(this.domNode.getAttribute("colspan"))}getColumnIndex(){return h(this,o.tableMain).getColIds().indexOf(this.colId)}getCellInner(){return this.children.head}checkMerge(){const{colId:t,rowId:e,colspan:o,rowspan:s}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===o&&i.rowspan===s}optimize(t){const e=this.parent,{tableId:s,rowId:i}=this;null!==e&&e.statics.blotName!==o.tableRow&&this.wrap(o.tableRow,{tableId:s,rowId:i}),super.optimize(t)}}const we=e.import("blots/block/embed");class ve extends we{static blotName=o.tableCol;static tagName="col";static validWidth(t,e){let o=Number.parseFloat(String(t));return Number.isNaN(o)&&(o=s[e?"colMinWidthPre":"colMinWidthPx"]),`${o}${e?"%":"px"}`}static create(t){const{width:e,tableId:o,colId:s,full:i,align:n}=t,l=super.create();return l.setAttribute("width",this.validWidth(e,!!i)),i&&(l.dataset.full=String(i)),n&&"left"!==n&&(l.dataset.align=n),l.dataset.tableId=o,l.dataset.colId=s,l}static value(t){const{tableId:e,colId:o}=t.dataset,i=t.getAttribute("width")||String(s.colDefaultWidth),n=t.dataset.align,l=Object.hasOwn(t.dataset,"full"),r={tableId:String(e),colId:String(o),full:l,width:Number.parseFloat(i)};return n&&(r.align=n),r}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){const e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:s[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=s[this.full?"colMinWidthPre":"colMinWidthPx"]),this.domNode.setAttribute("width",this.statics.validWidth(e,!!this.full))}get tableId(){return this.domNode.dataset.tableId}get colId(){return this.domNode.dataset.colId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full=String(!0):this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){const t=this.next,{tableId:e,colId:o}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===o}optimize(t){const e=this.parent;if(null!=e&&e.statics.blotName!==o.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(o.tableColgroup,t)}h(this,o.tableColgroup).align=this.align,null!=this.next&&this.checkMerge()&&this.next.remove(),super.optimize(t);try{const t=h(this,o.tableColgroup);let e=!0;t.children.forEach((t=>{e&&=t.full})),t.full=e}catch{}}insertAt(t,e,s){if(null!=s)return void super.insertAt(t,e,s);const i=e.split("\n"),n=i.pop(),l=i.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),r=this.split(t),[a,c]=u(this,[o.tableColgroup,o.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let h=c.parent.parent,p=c.parent.next;if(d){const t=d.descendants(re);if(t.length>0){const e=t[0],s=re.formats(e.domNode),i=this.scroll.create("block"),n=i.wrap(o.tableCellInner,s).wrap(o.tableCell,s).wrap(o.tableRow,s).wrap(o.tableBody,s.tableId);a.parent.insertBefore(n,a.next),h=i,p=i.next}}for(const t of l)h.insertBefore(t,p);n&&h.insertBefore(this.scroll.create("text",n),p)}}class Ce extends te{static blotName=o.tableMain;static tagName="table";static className="ql-table";static create(t){const e=super.create(),{tableId:o,full:s,align:i}=t;return e.dataset.tableId=o,"right"===i||"center"===i?e.dataset.align=i:e.removeAttribute("date-align"),s&&(e.dataset.full=String(s)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,o){super(t,e),this.updateAlign()}colWidthFillTable(){if(this.full)return void Object.assign(this.domNode.style,{width:null});const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?void 0:(this.domNode.style.width=`${e}px`,e)}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full=String(!0):this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align"),this.updateAlign()}setFull(){if(this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const o of t){const t=o.width/e*100;o.full=!0,o.width=t}}cancelFull(){if(!this.full)return;const t=this.getCols();if(0===t.length)return;const e=Math.floor(this.domNode.getBoundingClientRect().width);for(const o of t)o.full=!1,o.width=Math.max(o.width/100*e,s.colMinWidthPx)}updateAlign(){const t={marginLeft:null,marginRight:null};switch(this.align){case"center":t.marginLeft="auto",t.marginRight="auto";break;case"":case"left":t.marginRight="auto";break;case"right":t.marginLeft="auto"}Object.assign(this.domNode.style,t)}getRows(){return this.descendants(he)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(ve)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const e=this.parent;null!==e&&e.statics.blotName!==o.tableWrapper&&this.wrap(o.tableWrapper,this.tableId),super.optimize(t)}}class xe extends te{static blotName=o.tableColgroup;static tagName="colgroup";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full=String(!0):this.domNode.removeAttribute("data-full"),this.parent&&this.parent instanceof Ce&&(this.parent.full=t)}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let o,s=0;for(;(o=e())&&s!==t;)s++;return o}insertColByIndex(t,e){const i=this.parent;if(!(i instanceof Ce))throw new TypeError("TableColgroupFormat should be child of TableFormat");const n=this.findCol(t),l=this.scroll.create(o.tableCol,e);if(i.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=s.colMinWidthPre){e.width-=l.width;break}}this.insertBefore(l,n)}removeColByIndex(t){const e=this.parent;if(!(e instanceof Ce))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const o=this.findCol(t);o&&(e.full&&(o.next?o.next.width+=o.width:o.prev&&(o.prev.width+=o.width)),o.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof Ce&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent,{tableId:s,full:i,align:n}=this;null!=e&&e.statics.blotName!==o.tableMain&&this.wrap(o.tableMain,{tableId:s,full:i,align:n});h(this,o.tableMain).align=n,super.optimize(t)}}const ye=e.import("parchment");class Me extends te{scroll;static blotName=o.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){const e=super.create();return e.dataset.tableId=t,e.addEventListener("dragstart",(t=>{t.preventDefault(),t.stopPropagation()}),!0),e.addEventListener("drop",(t=>{t.preventDefault()})),e.addEventListener("dragover",(t=>{t.preventDefault(),t.dataTransfer.dropEffect="none"})),e.setAttribute("contenteditable","false"),e}constructor(t,o,s){super(t,o),this.scroll=t,this.scroll.emitter.on(e.events.TEXT_CHANGE,this.insertLineAround)}get tableId(){return this.domNode.dataset.tableId}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}deleteAt(t,e){super.deleteAt(t,e);const o=this.descendants(ue),s=this.descendants(xe);0!==o.length&&0!==s.length||this.remove()}remove(){super.remove(),this.scroll.emitter.off(e.events.TEXT_CHANGE,this.insertLineAround)}insertLineAround=()=>{this.prev&&this.prev instanceof ye.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this),this.next&&this.next instanceof ye.BlockBlot||this.parent.insertBefore(this.scroll.create("block"),this.next)}}const Ie=e.import("delta"),Ne=e.import("modules/clipboard");function Te(t){let e=Number.parseFloat(t.getAttribute("width")||String(s.colDefaultWidth));if(Number.isNaN(e)){const o=t.style.width;e=o?Number.parseFloat(o):t.offsetWidth}return e}class Le extends Ne{quill;tableId=Yt();rowId=Yt();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(t,e){super(t,e),this.quill=t,this.addMatcher("table",this.matchTable.bind(this)),this.addMatcher("colgroup",this.matchColgroup.bind(this)),this.addMatcher("col",this.matchCol.bind(this)),this.addMatcher("tr",this.matchTr.bind(this)),this.addMatcher("td",this.matchTd.bind(this)),this.addMatcher("th",this.matchTd.bind(this)),this.addMatcher("caption",this.matchCaption.bind(this)),this.addMatcher(Node.ELEMENT_NODE,this.matchTdAttributor.bind(this))}matchTable(t,e){if(0===e.ops.length)return e;const i=[],n=[];let l=-1;for(let t=0;t<e.ops.length;t++){const{attributes:s,insert:r}=e.ops[t],{table:a,[o.tableCell]:c,...d}=s||{},h=N(r)&&r[o.tableCol];h?n.push({insert:r}):i.push({attributes:d,insert:r}),d?.[o.tableCellInner]||h||(l=t)}const r=function(t,e){const o=new Array(e).fill(s.colDefaultWidth),i=Array.from(t.querySelectorAll("tr"));for(const t of i){const s=Array.from(t.querySelectorAll("td"));for(const[t,i]of s.entries()){if(!(t<e))break;{const e=Te(i);o[t]=e||o[t]}}}return o}(t,this.colIds.length).reduce(((t,e,s)=>(n[s]?t.push(n[s]):t.push({insert:{[o.tableCol]:{tableId:this.tableId,colId:this.colIds[s],width:e,full:!1}}}),t)),[]);return i.splice(l+1,0,...r),this.tableId=Yt(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,new Ie(i)}matchColgroup(t,e){const s=[];for(let t=0;t<e.ops.length;t++){const i=e.ops[t];i&&N(i.insert)&&i.insert[o.tableCol]&&s.push(i)}return new Ie(s)}matchCol(t){this.colIds[this.colCount]=Yt();const e=(new Ie).insert({[o.tableCol]:Object.assign(ve.value(t),{tableId:this.tableId,colId:this.colIds[this.colCount]})});return this.colCount+=1,e}matchTr(t,e){this.rowId=Yt(),this.cellCount=0;for(const[t,e]of this.rowspanCount.entries())e.rowspan>0&&(e.rowspan-=1),e.rowspan<=0&&(this.rowspanCount[t]={rowspan:0,colspan:0});return e}matchTd(t,e){const s=t,i=ge.formats(s);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let t=this.cellCount;t>=0;t--)this.colIds[t]||(this.colIds[t]=Yt()),this.rowspanCount[t]||(this.rowspanCount[t]={rowspan:0,colspan:0});const{colspan:n}=this.rowspanCount[this.cellCount];this.cellCount+=n,i.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:i.rowspan,colspan:i.colspan});const l=this.colIds[this.cellCount];this.cellCount+=i.colspan;const r=Object.assign(i,{tableId:this.tableId,rowId:this.rowId,colId:l});"none"===s.style.border&&(r.style=r.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const a=[];for(const t of e.ops){const{attributes:e={},...s}=t,{[o.tableCell]:i,...n}=e;a.push({...s,attributes:{...n,[o.tableCellInner]:r}})}return(a.length<=0||!I(a[a.length-1].insert)||!a[a.length-1].insert.endsWith("\n"))&&a.push({insert:"\n",attributes:{[o.tableCellInner]:r}}),new Ie(a)}matchTdAttributor(t,e){if("td"===t.tagName.toLocaleLowerCase()){const t=[];for(const s of e.ops){const{attributes:e,...i}=s,n=e?.[o.tableCellInner];if(e&&n&&n.style){const{background:o,...s}=e,l=document.createElement("div");l.style.background=o;const r=document.createElement("div");if(r.style.cssText=n.style,l.style.background===r.style.backgroundColor){t.push({...i,attributes:{...s}});continue}}t.push(s)}return new Ie(t)}return e}convert({html:t,text:e},s={}){const i=super.convert({html:t,text:e},s);if(s[o.tableCellInner])for(const t of i.ops)N(t.insert)&&t.insert[o.tableCol]?t.insert="":(t.attributes||(t.attributes={}),t.attributes[o.tableCellInner]=s[o.tableCellInner]);return i}matchCaption(t,e){for(let t=0;t<e.ops.length;t++){const s=e.ops[t],{attributes:i}=s;i&&i[o.tableCaption]&&(i[o.tableCaption].tableId=this.tableId,s.attributes=i)}return e}}const Se="color-selector",Ee={Break:{name:"break"},CopyCell:{name:"CopyCell",tip:"Copy cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256">\n <g fill="currentColor">\n <path d="M216 40v128h-48V88H88V40Z" opacity=".2" />\n <path\n d="M216 32H88a8 8 0 0 0-8 8v40H40a8 8 0 0 0-8 8v128a8 8 0 0 0 8 8h128a8 8 0 0 0 8-8v-40h40a8 8 0 0 0 8-8V40a8 8 0 0 0-8-8m-56 176H48V96h112Zm48-48h-32V88a8 8 0 0 0-8-8H96V48h112Z"\n />\n </g>\n</svg>\n',handle:(t,e)=>{const o=t.getTextByCell(e),s=t.getHTMLByCell(e),i=new ClipboardItem({"text/plain":new Blob([o],{type:"text/plain"}),"text/html":new Blob([s],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},CutCell:{name:"CutCell",tip:"Cut cell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32">\n <path\n fill="currentColor"\n d="m19.05 13.733l-1-1.733l-10.122 5.846l-.997-.576a3 3 0 0 0 .667-.769A3 3 0 1 0 3.5 17.599L5.928 19L3.5 20.402a3.034 3.034 0 1 0 3.44.323l.988-.57L14.59 24l1-1.73L9.928 19zM4.034 15.26a1 1 0 1 1 .466.607a1 1 0 0 1-.466-.607M5 22a1 1 0 1 1-.865 1.5A1 1 0 0 1 5 22m12 4h4v2h-4zm-7 0h4v2h-4z"\n />\n <path fill="currentColor" d="M28 28h-4v-2h4V4H7v4H5V4a2 2 0 0 1 2-2h21a2 2 0 0 1 2 2v22a2 2 0 0 1-2 2" />\n</svg>\n',handle:(t,e)=>{const o=t.getTextByCell(e),s=t.getHTMLByCell(e,!0),i=new ClipboardItem({"text/plain":new Blob([o],{type:"text/plain"}),"text/html":new Blob([s],{type:"text/html"})});navigator.clipboard.write([i]),t.hideTableTools()}},InsertTop:{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm17.94 4.5h-2v4h-2v-4h-2l3-3z"\n />\n</svg>\n',tip:"Insert row above",handle:(t,e)=>{t.appendRow(e,!1),t.hideTableTools()}},InsertRight:{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm15.44 8v-2h-4v-2h4v-2l3 3z"\n />\n</svg>\n',tip:"Insert column right",handle:(t,e)=>{t.appendCol(e,!0),t.hideTableTools()}},InsertBottom:{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm11.94 5.5h2v-4h2v4h2l-3 3z"\n />\n</svg>\n',tip:"Insert row below",handle:(t,e)=>{t.appendRow(e,!0),t.hideTableTools()}},InsertLeft:{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm14.44 2v2h4v2h-4v2l-3-3z"\n />\n</svg>\n',tip:"Insert column Left",handle:(t,e)=>{t.appendCol(e,!1),t.hideTableTools()}},MergeCell:{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"\n />\n</svg>\n',tip:"Merge Cell",handle:(t,e)=>{t.mergeCells(e),t.hideTableTools()}},SplitCell:{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"\n />\n</svg>\n',tip:"Split Cell",handle:(t,e)=>{t.splitCell(e),t.hideTableTools()}},DeleteRow:{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41zM22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2zM4 9h4V6H4zm6 0h4V6h-4zm6 0h4V6h-4z"\n />\n</svg>\n',tip:"Delete Row",handle:(t,e)=>{t.removeRow(e),t.hideTableTools()}},DeleteColumn:{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4zm0 6v4h7v-4zM4 4v4h7V4zm13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59z"\n />\n</svg>\n',tip:"Delete Column",handle:(t,e)=>{t.removeCol(e),t.hideTableTools()}},DeleteTable:{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="currentColor"\n d="m15.46 15.88l1.42-1.42L19 16.59l2.12-2.13l1.42 1.42L20.41 18l2.13 2.12l-1.42 1.42L19 19.41l-2.12 2.13l-1.42-1.42L17.59 18zM4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4z"\n />\n</svg>\n',tip:"Delete table",handle:(t,e)=>{t.deleteTable(e)}},BackgroundColor:{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="2"\n d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"\n />\n</svg>\n',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,o)=>{t.setCellAttrs(e,"background-color",o,!0)}},BorderColor:{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="1.5"\n d="m12.01 16l-.01.011M12.01 12l-.01.011M12.01 8l-.01.011M8.01 12l-.01.011M16.01 12l-.01.011M21 3.6v16.8a.6.6 0 0 1-.6.6H3.6a.6.6 0 0 1-.6-.6V3.6a.6.6 0 0 1 .6-.6h16.8a.6.6 0 0 1 .6.6"\n />\n</svg>\n',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,o)=>{t.setCellAttrs(e,"border-color",o,!0)}},SwitchWidth:{name:"SwitchWidth",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n \x3c!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --\x3e\n <path\n fill="none"\n stroke="currentColor"\n stroke-linecap="round"\n stroke-linejoin="round"\n stroke-width="2"\n d="M4 12V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v6m-10 6H3m18 0h-7m-8-3l-3 3l3 3m12-6l3 3l-3 3"\n />\n</svg>\n',tip:"Switch table width",handle:t=>{if(!t.table)return;const o=e.find(t.table);o&&(o.full?o.cancelFull():o.setFull())}},InsertCaption:{name:"InsertCaption",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\n \x3c!-- Icon from TDesign Icons by TDesign - https://github.com/Tencent/tdesign-icons/blob/main/LICENSE --\x3e\n <path fill="currentColor" d="M21 10v12h-2V12H5v10H3V10zm0-8v6H3V2zm-2 2H5v2h14z" />\n</svg>\n',tip:"Insert table caption",handle(t){if(!t.table)return;const s=e.find(t.table);if(!s)return;const i=t.quill.scroll.create("text","Table Caption").wrap(o.tableCaption,{tableId:s.tableId});s.insertBefore(i,s.children.head)}}},Be=d("color-map"),Re={selectWrapper:Be.b(),used:Be.bm("used"),item:Be.be("item"),btn:Be.be("btn"),map:Be.be("content"),mapRow:Be.be("content-row")};class ke{tableModule;quill;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;updateUsedColor;tooltipItem=[];activeTooltip=null;bem=d("menu");colorItemClass=`color-${Yt()}`;colorChooseTooltipOption={direction:"top"};constructor(t,o,s){this.tableModule=t,this.quill=o,this.options=this.resolveOptions(s);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);M(e)||(e=[]),e.slice(-10).map((t=>this.usedColors.add(t)))}catch{}this.updateUsedColor=Gt((t=>{if(!t)return;if(this.usedColors.add(t),this.usedColors.size>10){const t=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),t.map((t=>this.usedColors.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Re.used}`));for(const o of e){const e=document.createElement("div");e.classList.add(Re.item),e.style.backgroundColor=String(t);Array.from(o.querySelectorAll(`.${Re.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&o.appendChild(e);const s=Array.from(o.querySelectorAll(`.${Re.item}`)).slice(0,-10);for(const t of s)t.remove()}}),1e3),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.isMenuDisplay&&this.update()};resolveOptions(t){return Object.assign({tipText:!0,tools:[Ee.InsertTop,Ee.InsertRight,Ee.InsertBottom,Ee.InsertLeft,Ee.Break,Ee.MergeCell,Ee.SplitCell,Ee.Break,Ee.DeleteRow,Ee.DeleteColumn,Ee.DeleteTable,Ee.Break,Ee.BackgroundColor,Ee.BorderColor],localstorageKey:"__table-bg-used-color",defaultColorMap:l},t)}buildTools(){const t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:o,icon:s,handle:i,isColorChoose:n,key:l,tip:r=""}=e,a=document.createElement("span");if(a.classList.add(this.bem.be("item")),"break"===o)a.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),y(s)?t.appendChild(s(this.tableModule)):t.innerHTML=s,a.appendChild(t),n&&l){const t=this.createColorChoose(a,{name:o,icon:s,handle:i,isColorChoose:n,key:l,tip:r});this.tooltipItem.push(t),a.classList.add(Se)}else y(i)&&a.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.tableModule.options.texts[o]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose(t,{handle:e,key:o}){const s=document.createElement("div");if(s.classList.add(Re.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(Re.map);for(const e of this.options.defaultColorMap){const o=document.createElement("div");o.classList.add(Re.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(Re.item),e.style.backgroundColor=t,o.appendChild(e)}t.appendChild(o)}s.appendChild(t)}const i=document.createElement("div");i.classList.add(Re.mapRow),Object.assign(i.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(Re.btn,"transparent"),n.textContent=this.tableModule.options.texts.transparent,n.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),"transparent")}));const l=document.createElement("div");l.classList.add(Re.btn,"clear"),l.textContent=this.tableModule.options.texts.clear,l.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),null)}));const r=document.createElement("div");r.classList.add(Re.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=L({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Ft(r,{direction:"right",type:"click",content:a,container:r});i.appendChild(n),i.appendChild(l),i.appendChild(r),s.appendChild(i);const h=document.createElement("div");h.classList.add(Re.used,this.colorItemClass);for(const t of this.usedColors){const e=document.createElement("div");e.classList.add(Re.item),e.style.backgroundColor=t,h.appendChild(e)}s.appendChild(h),s.addEventListener("click",(t=>{t.stopPropagation(),c();const e=t.target,s=e.style.backgroundColor,i=this.getSelectedTds();if(e&&s&&i.length>0){if(this.tableModule.setCellAttrs(i,o,s,!0),!e.closest(`.${Re.item}`))return;this.updateUsedColor(s)}}));const u=Ft(t,{type:"click",content:s,onOpen:()=>(this.isMenuDisplay&&this.tableModule.tableSelection&&this.tableModule.tableSelection.hideDisplay(),this.setActiveTooltip(u),!1),onClose:()=>{this.isMenuDisplay&&this.tableModule.tableSelection&&(this.tableModule.tableSelection.updateWithSelectedTds(),this.tableModule.tableSelection.showDisplay());return s.contains(a)&&c(),this.activeTooltip===u&&(this.activeTooltip=null),!1},onDestroy:()=>{d(),this.activeTooltip===u&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return u.isColorPick=!0,u}setActiveTooltip(t){this.activeTooltip&&this.activeTooltip!==t&&this.activeTooltip.hide(!0),this.activeTooltip=t}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const o=Ft(t,{msg:e});o&&this.tooltipItem.push(o)}show(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,this.update())}update(){}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.activeTooltip=null;for(const t of this.tooltipItem)t.destroy();this.menu&&(this.hide(),this.menu.remove(),this.menu=null)}}const Ae=t=>!t.full&&"right"===t.align;class Oe{tableModule;quill;colIndex=-1;tableMain;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=d("drag-line");constructor(t,e){this.tableModule=t,this.quill=e}findCurrentColIndex(t){return-1}colWidthChange(t,e,o){}async createConfirmDialog({message:t,confirm:e,cancel:o}){return new Promise((s=>{const i=document.createElement("div");Object.assign(i.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});const n=document.createElement("p");n.textContent=t;const l=document.createElement("div");Object.assign(l.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});const r=T({content:o}),a=T({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),i.appendChild(n),i.appendChild(l);const{close:c}=E({child:i});r.addEventListener("click",(()=>{s(!1),c()})),a.addEventListener("click",(()=>{s(!0),c()}))}))}async handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0");let o=this.tableMain.full,n=!1;const l=[];if(o){let o=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(o<i){if(o=Math.max(s.colMinWidthPre,o),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1;l.push({index:e,width:t[e].width+i-o})}else o=100;n=!0,l.push({index:this.colIndex,width:o})}else if(t[this.colIndex+1]){const e=i+t[this.colIndex+1].width;o=Math.min(e-s.colMinWidthPre,o),n=!0,l.push({index:this.colIndex,width:o},{index:this.colIndex+1,width:e-o})}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,n=!0,l.push({index:this.colIndex,width:e});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,n){const e=this.tableMain.domNode.getBoundingClientRect().width;if(o){let s=0;const i=new Set(l.map((({index:t,width:e})=>(s+=e,t))));for(const[e,o]of t.entries())i.has(e)||(s+=o.width);if(s>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableMain.cancelFull(),o=!1;for(const[t,o]of l.entries()){const{width:s,index:i}=o;l[t]={index:i,width:s/100*e}}}}for(const{index:s,width:i}of l)t[s].width=`${Math.round(i)}${o?"%":"px"}`,this.colWidthChange(s,{px:Math.round(i/100*e),pre:Math.round(i)},o)}this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),o=e[this.colIndex].domNode.getBoundingClientRect(),i=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=s.colMinWidthPre/100*i.width;let l=i.right;n>o.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,o.left+t));const r=o.x+t;n=Math.min(Math.max(n,r),l)}else Ae(this.tableMain)?o.right-n<s.colMinWidthPx&&(n=o.right-s.colMinWidthPx):n-o.x<s.colMinWidthPx&&(n=o.x+s.colMinWidthPx);let l=n-o.x;return Ae(this.tableMain)&&(l=o.right-n),this.dragColBreak.style.left=`${n}px`,this.dragColBreak.dataset.w=String(l),{left:n,width:l}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const[e]=b(this.tableMain,ue);if(!e)return;const o=this.tableMain.getCols(),s=e.domNode.getBoundingClientRect();if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=o[this.colIndex].width,n=this.tableMain.full?i/100*s.width:i;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const l=document.createElement("div");l.classList.add(this.dragBEM.b()),l.classList.add(this.dragBEM.is("col")),l.dataset.w=String(n);const r={top:s.y,left:t.clientX,height:s.height};Object.assign(l.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(l),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=l,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let o=t.clientY;return o-e.y<s.rowMinHeightPx&&(o=e.y+s.rowMinHeightPx),this.dragRowBreak.style.top=`${o}px`,this.dragRowBreak.dataset.h=String(o-e.y),{top:o,height:o-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,o=this.tableMain.domNode.getBoundingClientRect(),s=document.createElement("div");s.classList.add(this.dragBEM.b()),s.classList.add(this.dragBEM.is("row")),s.dataset.h=String(e);const i={top:t.clientY,left:o.x,width:o.width};Object.assign(s.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});const n=document.body;return n.appendChild(s),this.dragRowBreak&&n.removeChild(this.dragRowBreak),this.dragRowBreak=s,i}update(){}destroy(){}}class ze{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;bem=d("scrollbar");tableMainBlot;constructor(t,o,s,i){this.quill=t,this.isVertical=o,this.table=s,this.scrollbarContainer=i,this.tableMainBlot=e.find(this.table),this.container=s.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),_t.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const[t]=b(this.tableMainBlot,ue);if(!t)return;const{scrollLeft:e,scrollTop:o}=this.quill.root,{offsetLeft:s,offsetTop:i}=this.container,{offsetLeft:n,offsetTop:l}=t.domNode,{width:r,height:a}=this.container.getBoundingClientRect(),{width:c,height:d}=t.domNode.getBoundingClientRect();let h=s+n,u=i+l;this.isVertical?h+=Math.min(r,c):u+=Math.min(a,d),this.tableMainBlot&&"left"!==this.tableMainBlot.align&&(h+=this.table.offsetLeft-s),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(a,d):r}px`,transform:`translate(${h-e}px, ${u-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,o=t**2/this.container.scrollHeight,s=e**2/this.container.scrollWidth,i=Math.max(o,this.minSize),n=Math.max(s,this.minSize);this.ratioY=o/(t-o)/(i/(t-i)),this.ratioX=s/(e-s)/(n/(e-n)),this.sizeWidth=n+this.gap<e?`${n}px`:"",this.sizeHeight=i+this.gap<t?`${i}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){const t=document.createElement("div");t.classList.add(this.bem.b()),t.classList.add(this.isVertical?this.bem.is("vertical"):this.bem.is("horizontal"),this.bem.is("transparent")),Object.assign(t.style,{display:"none"}),this.thumb.classList.add(this.bem.be("thumb"));let e=null;const o=t=>{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const o=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],s=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*o/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=s*this.container[this.propertyMap.scrollSize]/100},s=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",s),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=e},i=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",o),document.addEventListener("mouseup",s),e=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),i(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const n=[this.table,t];for(const t of n)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return _t.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){const e=t[this.propertyMap.offset]-this.gap;this.move=100*t[this.propertyMap.scrollDirection]/e*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=Gt((()=>{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=Gt((()=>{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(),Xt.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}const qe=e.import("parchment"),$e=e.import("delta"),We=e.import("blots/break"),He=e.import("ui/icons");function De(t,{tableId:e,rowId:s,colId:i}){const n={tableId:e,rowId:s,colId:i,colspan:1,rowspan:1},l=t.create(o.tableCell,n),r=t.create(o.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l}function Fe(t){return{bindInHead:!1,key:t?"ArrowUp":"ArrowDown",collapsed:!0,format:[o.tableCellInner],handler(s,i){let n,l,r,a;try{[n,l,r,a]=u(i.line,[o.tableWrapper,o.tableMain,o.tableRow,o.tableCell])}catch{return!0}const c=l.getColIds(),d=t?"prev":"next",h=t?"tail":"head",p=n.descendants(fe,0)[0];let b;if(p){const t=window.getComputedStyle(p.domNode);b="next"===d&&"bottom"===t.captionSide?p:"next"===d?n.next:p}else b=n[d];if(i.line[d]||!b)return!0;const m=r[d];if(m){const t=c.indexOf(a.colId),o=m.getCellByColId(c[t],d);if(!o)return!0;let s=o.children[h];s.children&&(s=s.children[h]);const n=s.offset(this.quill.scroll)+Math.min(i.offset,s.length()-1);this.quill.setSelection(n,0,e.sources.USER)}else{const o=b.offset(this.quill.scroll)+(t?b.length()-1:0);this.quill.setSelection(o,0,e.sources.USER)}return!1}}}class je{static moduleName=n.moduleName;static toolName=o.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,e){const s=this.quill.getLine(t.index)[0];if(s.prev instanceof Me)return s.prev.remove(),!1;if(e.format[o.tableCellInner]){if(0===s.offset(h(s,o.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,e){const s=this.quill.getLine(t.index),i=s[0],n=s[1];if((i.next instanceof Me||i.next instanceof ve)&&n===i.length()-1)return!1;if(e.format[o.tableCellInner]){if(i===h(i,o.tableCellInner).children.tail&&n===i.length()-1)return!1}return!0}},"table up":Fe(!0),"table down":Fe(!1),"table caption break":{bindInHead:!0,key:"Enter",shiftKey:null,format:[o.tableCaption],handler:(t,e)=>!1}};static register(){Me.allowedChildren=[Ce],Ce.allowedChildren=[ue,xe,fe],Ce.requiredContainer=Me,fe.requiredContainer=Ce,xe.allowedChildren=[ve],xe.requiredContainer=Ce,ue.allowedChildren=[he],ue.requiredContainer=Ce,he.allowedChildren=[ge],ge.requiredContainer=ue,ge.allowedChildren=[re,We],ge.requiredContainer=he,re.requiredContainer=ge;const t=["header","list","blockquote","code-block"].reduce(((t,o)=>{const s=`formats/${o}`,i=e.import(s);return t[s]=class extends(function(t,e){const o=class extends t{constructor(...t){super(...t)}};for(const t of e)m(o.prototype,t.prototype);return o}(i,[se])){static register(){}},t}),{});e.register({"blots/scroll":de,"blots/block":se,...t,[`blots/${o.container}`]:te,[`formats/${o.tableCell}`]:ge,[`formats/${o.tableCellInner}`]:re,[`formats/${o.tableRow}`]:he,[`formats/${o.tableBody}`]:ue,[`formats/${o.tableCol}`]:ve,[`formats/${o.tableColgroup}`]:xe,[`formats/${o.tableCaption}`]:fe,[`formats/${o.tableMain}`]:Ce,[`formats/${o.tableWrapper}`]:Me,"modules/clipboard":Le},!0)}quill;options;toolBox;fixTableByLisenter=Gt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(t,e){this.quill=t,this.options=this.resolveOptions(e||{});const o=d("toolbox");if(this.toolBox=this.quill.addContainer(o.b()),!this.options.scrollbar){const t=d("scrollbar");this.quill.container.classList.add(t.bm("origin"))}this.options.selection&&(this.tableSelection=new this.options.selection(this,this.quill,this.options.selectionOptions));const s=this.quill.getModule("toolbar");if(s&&this.quill.theme.pickers){const[,t]=(s.controls||[]).find((([t])=>t===this.statics.toolName))||[];if(t&&"select"===t.tagName.toLocaleLowerCase()){const e=this.quill.theme.pickers.find((e=>e.select===t));e&&(e.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,e),e.label.addEventListener("mousedown",(()=>{if(!this.selector||!e)return;const t=this.selector.getBoundingClientRect(),{leftLimited:o}=Pt(t);if(o){const t=e.label.getBoundingClientRect();Object.assign(e.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(e.options.style,{transform:void 0})})))}}const i=this.quill.getModule("keyboard");for(const t of Object.values(je.keyboradHandler))t.bindInHead?i.bindings[t.key].unshift(t):i.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const e=t.composedPath();if(!e||e.length<=0)return;const o=e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(o){if(this.table===o)return this.tableSelection&&this.tableSelection.show(),this.tableAlign&&this.tableAlign.update(),this.tableResize&&this.tableResize.update(),void(this.tableScrollbar&&this.tableScrollbar.update());this.table&&this.hideTableTools(),this.showTableTools(o)}else this.table&&this.hideTableTools()}),!1),this.quillHack(),this.listenBalanceCells()}addContainer(t){if(I(t)){const e=document.createElement("div");for(const o of t.split(" "))e.classList.add(o);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!1,texts:this.resolveTexts(t.texts||{}),full:!1,fullSwitch:!0,icon:He.table,selectionOptions:{},alignOptions:{},scrollbarOptions:{},resizeOptions:{},resizeScaleOptions:{}},t)}resolveTexts(t){return Object.assign({fullCheckboxText:"Insert full width table",customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer",custom:"Custom",clear:"Clear",transparent:"Transparent",perWidthInsufficient:"The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?",CopyCell:"Copy cell",CutCell:"Cut cell",InsertTop:"Insert row above",InsertRight:"Insert column right",InsertBottom:"Insert row below",InsertLeft:"Insert column Left",MergeCell:"Merge Cell",SplitCell:"Split Cell",DeleteRow:"Delete Row",DeleteColumn:"Delete Column",DeleteTable:"Delete table",BackgroundColor:"Set background color",BorderColor:"Set border color"},t)}quillHack(){const t=this.quill.getSemanticHTML;this.quill.getSemanticHTML=(s=0,i)=>{const n=t.call(this.quill,s,i),l=e.import(`formats/${o.tableWrapper}`),r=(new DOMParser).parseFromString(n,"text/html");for(const t of Array.from(r.querySelectorAll(`.${l.className} caption[contenteditable], .${l.className} td > [contenteditable]`)))t.removeAttribute("contenteditable");return r.body.innerHTML};const s=this.quill.format;this.quill.format=function(t,i,l=e.sources.API){if(!(this.scroll.query(t).prototype instanceof qe.EmbedBlot)){const e=this.getModule(n.moduleName),r=this.getSelection();if(r&&r.length>0){if(this.getFormat(r)[o.tableCellInner])return s.call(this,t,i,l)}if(e&&e.tableSelection&&e.tableSelection.selectedTds.length>0){const o=e.tableSelection.selectedTds;let s=!1;const n=[];for(const e of o){const o=e.offset(this.scroll),l=e.length();n.push({index:o,length:l});this.getFormat(o,l)[t]!==i&&(s=!0)}const r=!!s&&i,a=new $e;for(const[e,{index:o,length:s}]of n.entries()){const i=0===e?0:n[e-1].index+n[e-1].length;a.retain(o-i).retain(s,{[t]:r})}const c=this.updateContents(a,l);return this.blur(),c}}return s.call(this,t,i,l)};const i=this.quill.theme.modules.toolbar;if(i){const t=i.handlers?.clean;if(t){const s=(t,e,s=()=>"")=>{const i=this.quill.getText(t,e),[n,l]=this.quill.getLine(t+e);let r=0,a=new $e;null!=n&&(r=n.length()-l,a=n.delta().slice(l,l+r-1).insert("\n"));const c=this.quill.getContents(t,e+r),d=c.diff((new $e).insert(i).concat(a));let h=0;const u=d.ops.map((t=>{const{attributes:e,...i}=t;if(t.insert?h-=I(t.insert)?t.insert.length:1:t.retain?h+="number"==typeof t.retain?t.retain:1:t.delete&&(h+=t.delete),e){const{[o.tableCellInner]:t,...n}=e;if(s){const t=c.slice(h-1,h).ops[0];if(t&&t.attributes&&t.attributes[o.tableCellInner]){const e=t.attributes[o.tableCellInner],{style:l,...r}=e,a=s(l);return a?{...i,attributes:{...n,[o.tableCellInner]:{style:a,...r}}}:{...i,attributes:{...n,[o.tableCellInner]:r}}}}return{...i,attributes:{...n}}}return t}));return new $e(u)};i.handlers.clean=function(i){const l=this.quill.getModule(n.moduleName),r=this.quill.getSelection();if(r&&r.length>0){if(this.quill.getFormat(r)[o.tableCellInner]){const t=s(r.index,r.length,!1),o=(new $e).retain(r.index).concat(t);return void this.quill.updateContents(o,e.sources.USER)}}if(l&&l.tableSelection&&l.tableSelection.selectedTds.length>0&&l.tableSelection.table){const t=e.find(l.tableSelection.table);if(!t)return void console.warn("TableMainFormat not found");const o=l.tableSelection.selectedTds,i=new Set,n=[];for(const t of o)if(t.parent instanceof ge){for(const e of t.parent.getNearByCell("top"))i.has(e)||(i.add(e),n.push({td:e,cleanBorder:"bottom"}));for(const e of t.parent.getNearByCell("left"))i.has(e)||(i.add(e),n.push({td:e,cleanBorder:"right"}));i.add(t.parent),n.push({td:t.parent,cleanBorder:!0})}const r=t.descendants(ge),a=new Map(r.map(((t,e)=>[t,e])));n.sort(((t,e)=>a.get(t.td)-a.get(e.td)));let c=new $e,d=0;for(const{td:t,cleanBorder:e}of n){const o=t.getCellInner().offset(this.quill.scroll),i=t.getCellInner().length(),n=s(o,i-1,(t=>{if(!t||!0===e)return"";const o=Ut(t),s=Object.keys(o).filter((t=>!t.startsWith(`border-${e}`))).reduce(((t,e)=>(t[e]=o[e],t)),{});return i=s,Object.entries(i).map((([t,e])=>`${t}: ${e};`)).join(" ");var i})),l=(new $e).retain(o-d).concat(n);c=c.concat(l),d=o+i}return this.quill.updateContents(c,e.sources.USER),void(o.length>1&&this.quill.blur())}return t.call(this,i)}}}}showTableTools(t){t&&(this.table=t,this.tableSelection?.show(),this.options.align&&(this.tableAlign=new this.options.align(this,t,this.quill,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,this.quill,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,this.quill,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,this.quill,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection?.hide(),this.tableScrollbar&&(this.tableScrollbar.destroy(),this.tableScrollbar=void 0),this.tableAlign&&(this.tableAlign.destroy(),this.tableAlign=void 0),this.tableResize&&(this.tableResize.destroy(),this.tableResize=void 0),this.tableResizeScale&&this.tableResizeScale.destroy(),this.table=void 0}async buildCustomSelect(t,e){if(!t||!y(t))return;const o=document.createElement("div");if(o.classList.add("ql-custom-select"),this.selector=await t(this,e),o.appendChild(this.selector),this.options.fullSwitch){const t=d("creator"),e=document.createElement("label");e.classList.add(t.be("checkbox"));const s=document.createElement("input");s.type="checkbox",s.checked=this.options.full,s.addEventListener("change",(()=>{this.options.full=s.checked}));const i=document.createElement("span");i.textContent=this.options.texts.fullCheckboxText,e.appendChild(s),e.appendChild(i),o.appendChild(e)}e.options.innerHTML="",e.options.appendChild(o)}setCellAttrs(t,e,o,s=!1){if(0!==t.length)for(const i of t)i.setFormatValue(e,o,s)}getTextByCell(t){let e="";for(const o of t){const t=o.offset(this.quill.scroll),s=o.length();for(const o of this.quill.getContents(t,s).ops)I(o.insert)&&(e+=o.insert)}return e}getHTMLByCell(t,e=!1){if(0===t.length)return"";let s=null;try{for(const e of t){const t=h(e,o.tableMain);if(s||(s=t),t!==s)return console.error("tableMain is not same"),""}}catch{return console.error("tds must be in same tableMain"),""}if(!s)return"";const i=this.quill.getIndex(s),n=s.length(),l=this.quill.getSemanticHTML(i,n),r=(new DOMParser).parseFromString(l,"text/html"),a=[],c=new Set,d=new Set;for(const e of t)c.add(e.colId),d.add(`${e.rowId}-${e.colId}`);for(const t of Array.from(r.querySelectorAll("col")))c.has(t.dataset.colId)?a.push(t.getAttribute("width")):t.remove();let u=0,p=null;for(const t of Array.from(r.querySelectorAll("td")))if(d.has(`${t.dataset.rowId}-${t.dataset.colId}`))p!==t.dataset.rowId&&(u+=1,p=t.dataset.rowId);else{const e=t.parentElement;t.remove(),e&&e.children.length<=0&&e.remove()}const b=Array.from(r.querySelectorAll("col")),m=b.map((t=>ve.value(t)));if(s.full){const t=m.reduce(((t,e)=>e.width+t),0);for(const[e,o]of m.entries())o.width=Math.round(o.width/t*100),b[e].setAttribute("width",`${o.width}%`)}else{let t=0;for(const e of m)t+=e.width;r.querySelector("table").style.width=`${t}px`}if(e){if(u===s.getRows().length)this.removeCol(t);else for(const e of t)e.domNode.innerHTML="<p><br></p>"}return r.body.innerHTML}insertTable(t,i){if(t>=30||i>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus();const n=this.quill.getSelection();if(null==n)return;const[l]=this.quill.getLeaf(n.index);if(!l)return;if(c(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),a=getComputedStyle(this.quill.root),d=Number.parseInt(a.paddingLeft),h=Number.parseInt(a.paddingRight),u=Number.parseInt(a.width)-d-h-r,p=Yt(),b=new Array(i).fill(0).map((()=>Yt())),m=this.options.full?`${Math.max(1/i*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(u/i),s.colMinWidthPx)}px`,f=[{retain:n.index},{insert:"\n"}];for(let t=0;t<i;t++)f.push({insert:{[o.tableCol]:{width:m,tableId:p,colId:b[t],full:this.options.full}}});for(let e=0;e<t;e++){const t=Yt();for(let e=0;e<i;e++)f.push({insert:"\n",attributes:{[o.tableCellInner]:{tableId:p,rowId:t,colId:b[e],rowspan:1,colspan:1}}})}this.quill.updateContents(new $e(f),e.sources.USER),this.quill.setSelection(n.index+i+i*t+1,e.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${Ce.className}">\n <tbody>\n <tr>\n <td class="${ge.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=Me.className,e.innerHTML=t,e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.visibility="hidden",this.quill.root.appendChild(e);const o=window.getComputedStyle(e.querySelector("td")),s=Number.parseFloat(o.borderWidth)||0;return this.quill.root.removeChild(e),s}fixUnusuaDeletelTable(t){const e=t.getRows(),o=t.getColIds();if(0===e.length)return t.remove();if(0===o.length)return;const s=new Array(e.length).fill(0).map((()=>new Array(o.length).fill(!1))),i=t.tableId;for(const[t,n]of e.entries()){let l=0,r=0;const a=s[t],c=n.descendants(ge);for(;r<o.length;){if(a[r]){r+=1;continue}const d=c[l];if(d&&d.colId===o[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:o,rowspan:i}=d;if(o>1)for(let t=1;t<o;t++)a[r+t]=!0;if(i>1)for(let e=t+1;e<t+i;e++)for(let t=0;t<o;t++)s[e][r+t]=!0;l+=1}else n.insertBefore(De(this.quill.scroll,{tableId:i,colId:o[r],rowId:n.rowId}),d);r+=1}if(l<c.length)for(let t=l;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(Ce))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)))}))}deleteTable(t){if(0===t.length)return;const e=h(t[0],o.tableMain);e&&e.remove(),this.hideTableTools()}appendRow(t,e){if(t.length<=0)return;const s=t[e?t.length-1:0],[i,n,l]=u(s,[o.tableMain,o.tableBody,o.tableRow]),r=i.getRows().indexOf(l)+(e?s.rowspan:0);n.insertRow(r)}appendCol(t,e){if(t.length<=0)return;const[s]=t.reduce(((t,o)=>{const s=o.getColumnIndex();return(!e&&s<=t[1]||e&&s>=t[1])&&(t=[o,s]),t}),[t[0],t[0].getColumnIndex()]),i=s.getColumnIndex()+(e?s.colspan:0),n=h(s,o.tableMain),l=n.tableId,r=Yt(),[a]=n.descendants(xe);a&&a.insertColByIndex(i,{tableId:l,colId:r,width:n.full?6:160,full:n.full});const c=n.getRows(),d=[];let u=0;for(const t of Object.values(c)){const e=d.shift()||0;if(u>0){u-=1;continue}const o=t.insertCell(i-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});o.skipRowNum&&(u+=o.skipRowNum);for(const[t,e]of o.entries())d[t]=(d[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),o=t.getCols(),s=o.reduce(((t,e)=>(t[e.colId]=0,t)),{}),i=[...e].reverse(),n=[];for(const[t,o]of i.entries()){const i=e.length-t-1;o.children.length<=0?n.push(i):o.foreachCellInner((t=>{const e=n.reduce(((e,o)=>t.rowspan+i>o?e+1:e),0);t.rowspan-=e,s[t.colId]+=1}))}let l=0;for(const t of Object.values(s))if(0===t){const t=[];let o=0;for(const s of Object.values(e)){const e=t.shift()||0;let i=[];o>0?(i=s.getCellByColumIndex(l-e)[2],o-=1):(i=s.removeCell(l-e),i.skipRowNum&&(o+=i.skipRowNum));for(const[e,o]of i.entries())t[e]=(t[e]||0)+o}}else l+=1;for(const t of o)0===s[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(t){if(t.length<=0)return;const e=h(t[0],o.tableMain),s=e.getRows();let i=s.length,n=-1;for(const e of t){const t=h(e,o.tableRow),l=s.indexOf(t);l<i&&(i=l),l+e.rowspan>n&&(n=l+e.rowspan)}const l={};for(let t=i;t<Math.min(s.length,n);t++){s[t].foreachCellInner((e=>{e.rowspan+t>n&&(l[e.colId]={rowspan:e.rowspan+t-n,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(s[n]){const t=s[n],o=e.tableId;for(const[e,{colIndex:s,colspan:i,rowspan:n}]of Object.entries(l))t.insertCell(s,{tableId:o,rowId:t.rowId,colId:e,colspan:i,rowspan:n})}this.fixTableByRemove(e)}removeCol(t){if(t.length<=0)return;const e=t[0],s=h(e,o.tableMain),i={};for(const e of t)i[e.rowId]||(i[e.rowId]=0),i[e.rowId]+=e.colspan;const n=Math.max(...Object.values(i)),l=e.getColumnIndex(),r=s.descendants(he);for(let t=0;t<n;t++){const t=[];let e=0;for(const o of Object.values(r)){const s=t.shift()||0;if(e>0){e-=1;continue}const i=o.removeCell(l-s);i.skipRowNum&&(e+=i.skipRowNum);for(const[e,o]of i.entries())t[e]=(t[e]||0)+o}}const[a]=s.descendants(xe);if(a)for(let t=0;t<n;t++)a.removeColByIndex(l);this.fixTableByRemove(s)}mergeCells(t){if(t.length<=1)return;const e=t.reduce(((t,e,o)=>{const s=e.colId;t[0][s]||(t[0][s]=0),t[0][s]+=e.rowspan;const i=e.rowId;return t[1][i]||(t[1][i]=0),t[1][i]+=e.colspan,0!==o&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),s=Math.max(...Object.values(e[0])),i=Math.max(...Object.values(e[1])),n=e[2];n.colspan=i,n.rowspan=s;const l=h(n,o.tableMain);this.fixTableByRemove(l)}splitCell(t){if(1!==t.length)return;const e=t[0];if(1===e.colspan&&1===e.rowspan)return;const[s,i]=u(e,[o.tableMain,o.tableRow]),n=s.tableId,l=e.getColumnIndex(),r=s.getColIds().slice(l,l+e.colspan).reverse();let a=i,c=e.rowspan;for(e.colspan=1,e.rowspan=1;a&&c>0;){for(const t of r)a===i&&t===e.colId||a.insertCell(l+(a===i?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}t.BlockOverride=se,t.ContainerFormat=te,t.ScrollOverride=de,t.Scrollbar=ze,t.TableAlign=class{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=d("align");resizeObserver=Vt((()=>this.update()),{ignoreFirstBind:!0});constructor(t,o,s){this.tableModule=t,this.table=o,this.quill=s,this.tableBlot=e.find(o),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool(),this.resizeObserver.observe(this.table),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.show()}updateWhenTextChange=()=>{this.update()};buildTool(){const t=this.tableModule.addContainer(this.bem.b()),o=e.import("ui/icons"),s={left:o.align[""],center:o.align.center,right:o.align.right};for(const[o,i]of Object.entries(s)){const s=document.createElement("span");s.dataset.align=o,s.classList.add(this.bem.be("item")),s.innerHTML=`<i class="icon">${i}</i>`,s.addEventListener("click",(()=>{const t=s.dataset.align;t&&(this.setTableAlign(this.tableBlot,t),this.quill.once(e.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableResizeScale&&this.tableModule.tableResizeScale.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),t.appendChild(s)}return this.cleanup||(this.cleanup=Ot(this.tableWrapperBlot.domNode,t,(()=>this.update()))),t}setTableAlign(t,e){const o=t.getCols();for(const t of o)t.align=e}show(){this.alignBox&&(this.alignBox.classList.add(this.bem.bm("active")),this.update())}hide(){this.alignBox&&(this.alignBox.classList.remove(this.bem.bm("active")),this.cleanup&&(this.cleanup(),this.cleanup=void 0))}update(){this.alignBox&&(this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth?this.hide():Ht(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[$t(),qt({limiter:Wt()}),zt(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})})))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}},t.TableBodyFormat=ue,t.TableCaptionFormat=fe,t.TableCellFormat=ge,t.TableCellInnerFormat=re,t.TableClipboard=Le,t.TableColFormat=ve,t.TableColgroupFormat=xe,t.TableMainFormat=Ce,t.TableMenuCommon=ke,t.TableMenuContextmenu=class extends ke{tableModule;quill;colorChooseTooltipOption={direction:"right"};constructor(t,e,o){super(t,e,o),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),Object.assign(this.menu.style,{display:"flex"}),this.isMenuDisplay=!0,this.update({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hide()}),{once:!0})):this.hide()};buildTools(){const t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));const e=t.getElementsByClassName(Se);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const o=document.createElement("span");o.textContent=e,t.appendChild(o)}show(){}update(t){if(!(this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection))return;if(!t)return;super.update();const e={display:"flex",left:0,top:0},{x:o,y:s}=t;e.left=o,e.top=s,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const i=this.menu.getBoundingClientRect(),{left:n,top:l}=Pt(i);Object.assign(this.menu.style,{left:`${n+window.scrollX}px`,top:`${l+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy()}},t.TableMenuSelect=class extends ke{tableModule;quill;constructor(t,e,o){super(t,e,o),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu),this.show(),this.update()}update(){this.isMenuDisplay&&this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.isDisplaySelection&&(super.update(),Ht(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[$t(),qt({limiter:Wt()}),zt(20)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}},t.TableResizeBox=class extends Oe{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=d("resize-box");constructor(t,o,s){super(t,s),this.tableModule=t,this.table=o,this.tableMain=e.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer(this.bem.b()),this.resizeObserver=new ResizeObserver((()=>{this.show()})),this.resizeObserver.observe(this.table),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)))}updateWhenTextChange=()=>{this.update()};handleResizerHeader(t,e,o){const{clientX:s,clientY:i}=o,n=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const l=this.tableModule.tableSelection;o.shiftKey||(this.lastHeaderSelect=null);const r=[{x:t?n.left:s,y:t?i:n.top},{x:t?n.right:s,y:t?i:n.bottom}];if(this.lastHeaderSelect){let e,o;if(this.lastHeaderSelect.isX){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=Math.min(t.left,n.left),o=t.top+t.height/2}else{const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[this.lastHeaderSelect.index].getBoundingClientRect();e=t.left+t.width/2,o=Math.min(t.top,n.top)}this.lastHeaderSelect.isX!==t?(r[1]={x:Math.max(r[0].x,e),y:Math.max(r[0].y,o)},r[0]={x:Math.min(r[0].x,e),y:Math.min(r[0].y,o)}):t?(r[0].y=Math.min(r[0].y,o),r[1].y=Math.max(r[1].y,o)):(r[0].x=Math.min(r[0].x,e),r[1].x=Math.max(r[1].x,e))}else this.lastHeaderSelect={isX:t,index:e};l.table=this.table,l.selectedTds=l.computeSelectedTds(...r),l.show()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("col-separator"))).indexOf(t.target)}colWidthChange(t,e,o){Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[t].style.width=o?`${e.pre}%`:`${e.px}px`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);if(e&&this.dragColBreak){const[t]=b(this.tableMain,fe),o=t&&"top"===t.side?0:this.size;Object.assign(this.dragColBreak.style,{top:e.top-o+"px",left:`${e.left}px`,height:`${e.height+this.size}px`})}return e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));_t.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const[e,o]of t.entries())o.addEventListener("click",this.handleResizerHeader.bind(this,!1,e));for(const t of e)t.addEventListener("mousedown",this.handleColMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}findCurrentRowIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("row-separator"))).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[t].style.height=`${e}px`}handleRowMouseDownFunc=function(t){const e=this.handleRowMouseDown(t);return e&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${e.top}px`,left:e.left-this.size+"px",width:`${e.width+this.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));_t.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const[e,o]of t.entries())o.addEventListener("click",this.handleResizerHeader.bind(this,!0,e));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const[t]=b(this.tableMain,ue);if(!t)return;const e=this.tableWrapper.domNode.getBoundingClientRect(),o=t.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:Math.max(o.y,e.y)-s.y+"px",left:Math.max(o.x,e.x)-s.x+"px"});let i=-1*this.size,n=-1*this.size;Ae(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),i=Math.min(e.width,o.width),n=Math.min(e.width,o.width)):this.root.classList.remove(this.bem.is("align-right"));const[l]=b(this.tableMain,fe),r=!l||!(l&&"top"===l.side);r?this.root.classList.remove(this.bem.is("caption-bottom")):this.root.classList.add(this.bem.is("caption-bottom")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${i}px)`,top:`${r?0:o.height+this.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${n}px)`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${r?0:o.height+this.size}px`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const[t]=b(this.tableMain,ue);if(!t)return;const e=t.domNode.getBoundingClientRect(),o=this.tableWrapper.domNode.getBoundingClientRect();if(this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener("click",(()=>{if(this.tableModule.tableSelection){const t=this.tableMain.descendants(re),e=this.tableModule.tableSelection;e.selectedTds=t,e.show(),e.updateWithSelectedTds()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let t="";for(const[,o]of this.tableCols.entries()){const s=o.domNode.getBoundingClientRect().width;t+=`<div class="${this.bem.be("col-header")}" style="width: ${s}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${e.height+this.size-3}px"></div>\n </div>`}const s=document.createElement("div");s.classList.add(this.bem.be("col"));const i=document.createElement("div");i.classList.add(this.bem.be("col-wrapper")),Object.assign(s.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${o.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=t,s.appendChild(i),this.root.appendChild(s),s.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=s,this.bindColEvents()}if(this.tableRows.length>0){let t="";for(const[,o]of this.tableRows.entries()){const s=`${o.domNode.getBoundingClientRect().height}px`;t+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(s)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${e.width+this.size-3}px"></div>\n </div>`}const s=document.createElement("div");s.classList.add(this.bem.be("row"));const i=document.createElement("div");i.classList.add(this.bem.be("row-wrapper")),Object.assign(s.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${o.height}px`}),Object.assign(i.style,{height:`${e.height}px`}),i.innerHTML=t,s.appendChild(i),this.root.appendChild(s),s.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=s,this.bindRowEvents()}this.update(),_t.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),Xt.call(this),this.resizeObserver.disconnect(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange);for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}},t.TableResizeCommon=Oe,t.TableResizeLine=class extends Oe{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=d("resize-line");constructor(t,o,s){super(t,s),this.tableModule=t,this.table=o,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.table.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(e.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=t=>{if(this.dragging)return;if(this.tableModule.tableSelection&&this.tableModule.tableSelection.dragging)return;const s=this.findTableCell(t);if(!s)return this.hide();const i=e.find(s);i&&this.currentTableCell!==s&&(this.show(),this.currentTableCell=s,this.tableCellBlot=i,this.tableMain=h(i,o.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hide()};findTableCell(t){for(const e of t.composedPath()){if(e instanceof HTMLElement&&"TD"===e.tagName)return e;if(e===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.colResizer),this.colResizer=this.tableModule.addContainer(this.bem.be("col"));const[e]=u(t,[o.tableBody]),s=e.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=i.right-n.x;Ae(this.tableMain)&&(l=i.left-n.x),Object.assign(this.colResizer.style,{top:s.y-n.y+"px",left:`${l}px`,height:`${s.height}px`});const r=this.tableMain.getCols();this.curColIndex=r.findIndex((e=>e.colId===t.colId)),this.colResizer.addEventListener("mousedown",this.handleColMouseDownFunc),this.colResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.rowResizer),this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));const e=t.parent;if(!(e instanceof he))return;const[s]=u(t,[o.tableBody]),i=s.domNode.getBoundingClientRect(),n=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:n.bottom-l.y+"px",left:i.x-l.x+"px",width:`${i.width}px`});const r=this.tableMain.getRows();this.curRowIndex=r.indexOf(e),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}show(){this.rowResizer.classList.remove(this.bem.is("hidden")),this.colResizer.classList.remove(this.bem.is("hidden"))}hide(){this.currentTableCell=void 0,this.rowResizer.classList.add(this.bem.is("hidden")),this.colResizer.classList.add(this.bem.is("hidden"))}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer.remove(),this.rowResizer.remove(),this.table.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(e.events.TEXT_CHANGE,this.hideWhenTextChange)}},t.TableResizeScale=class{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=d("scale");startX=0;startY=0;offset=6;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(t,o,s,i){this.tableModule=t,this.table=o,this.quill=s,this.options=this.resolveOptions(i),this.tableMainBlot=e.find(o),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.buildResizer(),this.show()),this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};resolveOptions(t){return Object.assign({blockSize:12},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.root.classList.add(this.bem.is("hidden")),this.block=document.createElement("div"),this.block.classList.add(this.bem.be("block")),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let t=[],e=[];const o=o=>{if(!this.tableMainBlot)return;const i=Ae(this.tableMainBlot)?-1:1,n=(o.clientX-this.startX)*i,l=o.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:o}of t)e.width=Math.max(o+r,s.colMinWidthPx);for(const{blot:t,height:o}of e)t.setHeight(`${Math.max(o+a,s.rowMinHeightPx)}px`)},i=()=>{t=[],e=[],document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",i)};this.block.addEventListener("mousedown",(s=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=s.clientX,this.startY=s.clientY,t=this.tableMainBlot.getCols().map((t=>({blot:t,width:Math.floor(t.width)}))),e=this.tableMainBlot.getRows().map((t=>({blot:t,height:Math.floor(t.domNode.getBoundingClientRect().height)}))),document.addEventListener("mousemove",o),document.addEventListener("mouseup",i))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),_t.call(this,this.quill.root,(()=>this.update())),_t.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect();if(t.width>e.width){for(const o of this.tableMainBlot.getCols())o.width=Math.floor(o.width/t.width*e.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return;if(this.tableMainBlot.full)return void this.hide();const[t]=b(this.tableMainBlot,ue);if(!t)return;const e=t.domNode.getBoundingClientRect(),o=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),{scrollTop:i,scrollLeft:n}=this.tableWrapperBlot.domNode,l=2*this.options.blockSize+this.offset,r=Math.min(e.width,o.width)+l,a=Math.min(e.height,o.height)+l;Object.assign(this.root.style,{width:`${r}px`,height:`${a}px`,left:Math.max(e.x,o.x)-s.x-this.options.blockSize+"px",top:Math.max(e.y,o.y)-s.y-this.options.blockSize+"px"});const c={left:e.width+l-n+"px",top:a-i+"px"};Ae(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),c.left=`${this.options.blockSize+-1*n}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,c)}show(){this.root&&(this.root.classList.remove(this.bem.is("hidden")),this.update())}hide(){this.root&&this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.root&&this.root.remove(),Xt.call(this)}},t.TableRowFormat=he,t.TableSelection=class{tableModule;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];tableMenu;resizeObserver;table;isDisplaySelection=!1;bem=d("selection");lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};constructor(t,o,s={}){this.tableModule=t,this.quill=o,this.options=this.resolveOptions(s),this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=Vt((()=>this.updateAfterEvent()),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.mouseDownHandler,{passive:!1}),document.addEventListener("selectionchange",this.selectionChangeHandler,{passive:!1}),this.quill.on(i.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.TEXT_CHANGE,this.updateAfterEvent),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(t,o,this.options.tableMenuOptions)),this.hide()}updateAfterEvent=()=>{this.updateWithSelectedTds()};getFirstTextNode(t){for(const e of Array.from(t.childNodes))if(e.nodeType===Node.TEXT_NODE)return e;return t}getLastTextNode(t){for(let e=t.childNodes.length-1;e>=0;e--){const o=t.childNodes[e];if(o.nodeType===Node.TEXT_NODE)return o}return t}getNodeTailOffset(t){const e=document.createRange();return e.selectNodeContents(t),e.collapse(!1),e.startOffset}quillSelectionChangeHandler=(t,s,i)=>{if(i!==e.sources.API&&t&&this.selectedTds.length>0){const e=this.quill.getFormat(t),[s]=this.quill.getLine(t.index),i=!!e[o.tableCellInner]&&!!s,n=this.selectedTds.some((t=>t.children.contains(s)));if(i&&!n)try{const t=h(s,o.tableCellInner);this.selectedTds=[t],this.updateWithSelectedTds()}catch{}else i&&n||this.hide()}};setSelectionData(t,e){const{anchorNode:o,anchorOffset:s,focusNode:i,focusOffset:n}=e;if(!o||!i)return;const l=document.createRange(),r=this.selectionDirectionUp(e);r?(l.setStart(o,s),l.setEnd(o,s)):(l.setStart(o,s),l.setEnd(i,n)),t.removeAllRanges(),t.addRange(l),r&&t.extend(i,n)}selectionDirectionUp(t){const{anchorNode:e,anchorOffset:o,focusNode:s,focusOffset:i}=t;if(!e||!s)return!1;if(e===s)return o>i;const n=e.compareDocumentPosition(s);return n&Node.DOCUMENT_POSITION_CONTAINS||n&Node.DOCUMENT_POSITION_CONTAINED_BY?!!(n&Node.DOCUMENT_POSITION_FOLLOWING):!!(n&Node.DOCUMENT_POSITION_PRECEDING)}findWrapSelection(t){let e=null,o=0,s=null,i=0;for(const{node:n,offset:l}of t)n&&(e&&!this.selectionDirectionUp({anchorNode:e,anchorOffset:o,focusNode:n,focusOffset:l})||(e=n,o=l),s&&!this.selectionDirectionUp({anchorNode:n,anchorOffset:l,focusNode:s,focusOffset:i})||(s=n,i=l));return{startNode:e,startOffset:o,endNode:s,endOffset:i}}resolveOptions(t){return Object.assign({selectColor:"#0589f340",tableMenuOptions:{}},t)}selectionChangeHandler=()=>{const t=window.getSelection();if(!t)return;const{anchorNode:s,focusNode:i,anchorOffset:n,focusOffset:l}=t;if(!s||!i)return;const r=e.find(s),a=e.find(i);if(!r||!a||r.scroll!==this.quill.scroll||a.scroll!==this.quill.scroll)return;const c=p(r),d=p(a),h=c.has(o.tableColgroup),u=d.has(o.tableColgroup);if(h||u){let e=s,r=n,a=i,p=l;if(h){const t=c.get(o.tableWrapper).descendants(re);t.length>0&&(e=t[0].domNode,r=0)}if(u){const t=d.get(o.tableWrapper).descendants(re);t.length>0&&(a=t[0].domNode,p=0)}return void this.setSelectionData(t,{anchorNode:e,anchorOffset:r,focusNode:a,focusOffset:p})}const b=c.has(o.tableCellInner),m=d.has(o.tableCellInner);let f=b&&m;if(f){const t=c.get(o.tableCellInner),e=d.get(o.tableCellInner);f&&=t!==e}if(b&&m&&f||!b&&m||!m&&b)return this.setSelectionData(t,this.lastSelection),void(this.selectedTds.length>0&&this.hide());this.lastSelection={anchorNode:s,anchorOffset:n,focusNode:i,focusOffset:l}};helpLinesInitial(){this.cellSelectWrap.style.setProperty("--select-color",this.options.selectColor);const t=document.createElement("div");return t.classList.add(this.bem.be("line")),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(t,o){if(!this.table)return[];const s=e.find(this.table);if(!s)return[];const i=s.descendants(ue)[0];if(!i)return[];const n=new Set(i.descendants(ge).map(((t,e)=>(t.index=e,t)))),{x:l,y:r}=this.getTableViewScroll(),{x:a,y:c}=this.getQuillViewScroll();this.selectedTableScrollX=l,this.selectedTableScrollY=r,this.selectedEditorScrollX=a,this.selectedEditorScrollY=c;const d=i.domNode.getBoundingClientRect(),h=t.x-l+this.startScrollX,u=t.y-r+this.startScrollY;let p={x:Math.max(d.left,Math.min(o.x,h)),y:Math.max(d.top,Math.min(o.y,u)),x1:Math.min(d.right,Math.max(o.x,h)),y1:Math.min(d.bottom,Math.max(o.y,u))};const b=new Set;let m=!0;for(;m;){m=!1;for(const t of n){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:o,right:s,bottom:i}=t.__rect;if(jt({x:Math.floor(p.x),y:Math.floor(p.y),x1:Math.floor(p.x1),y1:Math.floor(p.y1)},{x:Math.floor(e),y:Math.floor(o),x1:Math.floor(s),y1:Math.floor(i)},0,0===b.size)){b.add(t),n.delete(t),p={x:Math.min(p.x,e),y:Math.min(p.y,o),x1:Math.max(p.x1,s),y1:Math.max(p.y1,i)},m=!0;break}}}for(const t of[...b,...n])delete t.__rect;return this.boundary=function(t,e){const o=e.getBoundingClientRect();return{x:t.x-o.x-e.scrollLeft,y:t.y-o.y-e.scrollTop,x1:t.x-o.x-e.scrollLeft+t.width,y1:t.y-o.y-e.scrollTop+t.height,width:t.width,height:t.height}}({...p,width:p.x1-p.x,height:p.y1-p.y},this.quill.root),Array.from(b).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler=t=>{const{button:e,target:o,clientX:s,clientY:i}=t,n=o.closest(".ql-table"),l=o.closest("tbody");if(0!==e||!n||!l)return;this.setSelectionTable(n);const r=n.dataset.tableId,a={x:s,y:i};this.selectedTds=this.computeSelectedTds(a,a),this.dragging=!0,this.show();const c=t=>{this.tableMenu&&this.tableMenu.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.hide();const{button:e,target:o,clientX:s,clientY:i}=t,n=o.closest("tbody");if(0!==e||!n||n.dataset.tableId!==r)return;const l={x:s,y:i};this.selectedTds=this.computeSelectedTds(a,l),this.selectedTds.length>1&&this.quill.blur(),this.update()},d=()=>{document.body.removeEventListener("mousemove",c,!1),document.body.removeEventListener("mouseup",d,!1),this.dragging=!1,this.tableMenu&&this.selectedTds.length>0&&this.tableMenu.show()};document.body.addEventListener("mousemove",c,!1),document.body.addEventListener("mouseup",d,!1)};updateWithSelectedTds(){if(this.selectedTds.length<=0)return;const t={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(const o of this.selectedTds){const s=o.domNode.getBoundingClientRect();t.x=Math.min(t.x,s.left),t.y=Math.min(t.y,s.top),e.x=Math.max(e.x,s.right),e.y=Math.max(e.y,s.bottom)}this.selectedTds=this.computeSelectedTds(t,e),this.selectedTds.length>0?this.update():this.hide()}update(){if(0===this.selectedTds.length||!this.boundary||!this.table)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:o,y:s}=this.getTableViewScroll(),i=this.table.parentElement.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),l=i.x-n.x,r=i.y-n.y;this.startScrollX=o,this.startScrollY=s,Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-o-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-s-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${i.width}px`,height:`${i.height}px`}),!this.dragging&&this.tableMenu&&this.tableMenu.update()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return this.table?{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}:{x:0,y:0}}setSelectionTable(t){this.table!==t&&(this.table=t)}removeCell=t=>{if(!(this.quill.getSelection()||"Backspace"!==t.key&&"Delete"!==t.key)){for(const t of this.selectedTds)t.deleteAt(0,t.length()-1);if(this.table){const t=e.find(this.table),o=t.descendants(re);this.selectedTds.length===o.length&&t.remove()}}};showDisplay(){Object.assign(this.cellSelectWrap.style,{display:"block"}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(Xt.call(this),this.update(),this.showDisplay(),document.addEventListener("keydown",this.removeCell),_t.call(this,this.quill.root,(()=>{this.update()})),_t.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(){Xt.call(this),document.removeEventListener("keydown",this.removeCell),this.hideDisplay(),this.boundary=null,this.selectedTds=[],this.setSelectionTable(void 0),this.tableMenu&&this.tableMenu.hide()}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Xt.call(this),this.quill.root.removeEventListener("mousedown",this.mouseDownHandler),document.removeEventListener("selectionchange",this.selectionChangeHandler),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.off(e.events.TEXT_CHANGE,this.updateAfterEvent),this.quill.on(i.AFTER_TABLE_RESIZE,this.updateAfterEvent)}},t.TableUp=je,t.TableVirtualScrollbar=class{tableModule;table;quill;scrollbarContainer;scrollbar;bem=d("scrollbar");constructor(t,o,s){this.tableModule=t,this.table=o,this.quill=s,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new ze(s,!0,o,this.scrollbarContainer),new ze(s,!1,o,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar);this.quill.on(e.events.TEXT_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=()=>{this.update()};hide(){for(const t of this.scrollbar)t.hideScrollbar()}show(){for(const t of this.scrollbar)t.showScrollbar()}update(){for(const t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}destroy(){this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange);for(const t of this.scrollbar)t.destroy()}},t.TableWrapperFormat=Me,t.blotName=o,t.createColorPicker=L,t.createSelectBox=R,t.createTooltip=Ft,t.default=je,t.defaultCustomSelect=function(t,e){return R({onSelect:(o,s)=>{t.insertTable(o,s),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})},t.findParentBlot=h,t.findParentBlots=u,t.isTableAlignRight=Ae,t.randomId=Yt,t.tableMenuTools=Ee,t.tableUpEvent=i,t.tableUpInternal=n,t.tableUpSize=s,t.updateTableConstants=function(t){a.delete(o.tableCellInner),Object.assign(o,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(i,t.tableUpEvent||{}),Object.assign(n,t.tableUpInternal||{}),je.moduleName=n.moduleName,je.toolName=o.tableWrapper,te.blotName=o.container,Me.blotName=o.tableWrapper,Ce.blotName=o.tableMain,xe.blotName=o.tableColgroup,ve.blotName=o.tableCol,ue.blotName=o.tableBody,he.blotName=o.tableRow,ge.blotName=o.tableCell,re.blotName=o.tableCellInner,a.add(o.tableCellInner)},Object.defineProperty(t,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=index.umd.js.map