quill-table-up 3.1.2 → 3.2.1

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 (111) hide show
  1. package/README.md +15 -8
  2. package/dist/index.css +1 -1
  3. package/dist/index.d.ts +168 -146
  4. package/dist/index.js +47 -47
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.umd.js +52 -52
  7. package/dist/index.umd.js.map +1 -1
  8. package/package.json +22 -24
  9. package/src/__tests__/e2e/custom-creator.test.ts +44 -44
  10. package/src/__tests__/e2e/editor-page.ts +77 -77
  11. package/src/__tests__/e2e/table-align.test.ts +104 -104
  12. package/src/__tests__/e2e/table-blots.test.ts +169 -169
  13. package/src/__tests__/e2e/table-caption.test.ts +134 -134
  14. package/src/__tests__/e2e/table-clipboard.test.ts +20 -20
  15. package/src/__tests__/e2e/table-hack.test.ts +151 -151
  16. package/src/__tests__/e2e/table-keyboard-handler.test.ts +20 -4
  17. package/src/__tests__/e2e/table-menu.test.ts +172 -172
  18. package/src/__tests__/e2e/table-resize.test.ts +654 -9
  19. package/src/__tests__/e2e/table-scrollbar.test.ts +144 -144
  20. package/src/__tests__/e2e/table-selection.test.ts +563 -563
  21. package/src/__tests__/e2e/types.d.ts +8 -7
  22. package/src/__tests__/e2e/utils.ts +52 -52
  23. package/src/__tests__/unit/table-blots.test.ts +720 -720
  24. package/src/__tests__/unit/table-caption.test.ts +234 -234
  25. package/src/__tests__/unit/table-cell-merge.test.ts +713 -724
  26. package/src/__tests__/unit/table-clipboard.test.ts +2176 -2176
  27. package/src/__tests__/unit/table-hack.test.ts +1014 -1014
  28. package/src/__tests__/unit/table-insert.test.ts +915 -926
  29. package/src/__tests__/unit/table-redo-undo.test.ts +2429 -2429
  30. package/src/__tests__/unit/table-remove.test.ts +313 -343
  31. package/src/__tests__/unit/utils.test-d.ts +49 -49
  32. package/src/__tests__/unit/utils.test.ts +711 -711
  33. package/src/__tests__/unit/utils.ts +307 -307
  34. package/src/__tests__/unit/vitest.d.ts +14 -14
  35. package/src/formats/container-format.ts +107 -107
  36. package/src/formats/overrides/block-embed.ts +72 -72
  37. package/src/formats/overrides/block.ts +95 -95
  38. package/src/formats/overrides/index.ts +3 -3
  39. package/src/formats/overrides/scroll.ts +70 -70
  40. package/src/formats/table-body-format.ts +52 -52
  41. package/src/formats/table-caption-format.ts +116 -116
  42. package/src/formats/table-cell-format.ts +304 -304
  43. package/src/formats/table-cell-inner-format.ts +403 -398
  44. package/src/formats/table-colgroup-format.ts +136 -136
  45. package/src/formats/table-foot-format.ts +7 -7
  46. package/src/formats/table-head-format.ts +7 -7
  47. package/src/formats/table-main-format.ts +1 -1
  48. package/src/formats/table-row-format.ts +218 -210
  49. package/src/formats/utils.ts +6 -6
  50. package/src/index.ts +19 -19
  51. package/src/modules/index.ts +7 -7
  52. package/src/modules/table-align.ts +131 -131
  53. package/src/modules/table-clipboard/table-clipboard.ts +6 -8
  54. package/src/modules/table-dom-selector.ts +33 -33
  55. package/src/modules/table-menu/constants.ts +223 -223
  56. package/src/modules/table-menu/index.ts +4 -4
  57. package/src/modules/table-menu/table-menu-common.ts +330 -329
  58. package/src/modules/table-menu/table-menu-contextmenu.ts +111 -118
  59. package/src/modules/table-menu/table-menu-select.ts +96 -94
  60. package/src/modules/table-resize/index.ts +5 -5
  61. package/src/modules/table-resize/table-resize-box.ts +714 -363
  62. package/src/modules/table-resize/table-resize-common.ts +246 -382
  63. package/src/modules/table-resize/table-resize-drag.ts +241 -0
  64. package/src/modules/table-resize/table-resize-line.ts +244 -182
  65. package/src/modules/table-resize/table-resize-scale.ts +174 -173
  66. package/src/modules/table-resize/utils.ts +84 -3
  67. package/src/modules/table-scrollbar.ts +292 -292
  68. package/src/modules/table-selection.ts +613 -669
  69. package/src/style/button.less +45 -45
  70. package/src/style/color-picker.less +136 -136
  71. package/src/style/dialog.less +53 -53
  72. package/src/style/functions.less +9 -9
  73. package/src/style/index.less +120 -120
  74. package/src/style/input.less +64 -64
  75. package/src/style/select-box.less +52 -52
  76. package/src/style/table-creator.less +56 -56
  77. package/src/style/table-menu.less +125 -125
  78. package/src/style/table-resize-scale.less +31 -31
  79. package/src/style/table-resize.less +249 -202
  80. package/src/style/table-scrollbar.less +49 -49
  81. package/src/style/table-selection.less +23 -23
  82. package/src/style/tooltip.less +19 -19
  83. package/src/style/variables.less +1 -1
  84. package/src/svg/arrow-up-down.svg +11 -11
  85. package/src/svg/convert-cell.svg +7 -7
  86. package/src/table-up.ts +1363 -1360
  87. package/src/types.d.ts +4 -4
  88. package/src/utils/bem.ts +23 -23
  89. package/src/utils/blot-helper.ts +101 -105
  90. package/src/utils/color.ts +109 -109
  91. package/src/utils/components/button.ts +22 -22
  92. package/src/utils/components/color-picker.ts +236 -236
  93. package/src/utils/components/dialog.ts +83 -41
  94. package/src/utils/components/index.ts +6 -6
  95. package/src/utils/components/input.ts +74 -74
  96. package/src/utils/components/table/creator.ts +89 -89
  97. package/src/utils/components/table/index.ts +2 -2
  98. package/src/utils/components/table/select-box.ts +78 -78
  99. package/src/utils/components/tooltip.ts +179 -189
  100. package/src/utils/constants.ts +125 -124
  101. package/src/utils/drag-helper.ts +112 -0
  102. package/src/utils/index.ts +15 -14
  103. package/src/utils/is.ts +9 -9
  104. package/src/utils/position.ts +60 -60
  105. package/src/utils/resize-observer-helper.ts +47 -47
  106. package/src/utils/scroll.ts +145 -47
  107. package/src/utils/style-helper.ts +47 -47
  108. package/src/utils/transformer.ts +10 -10
  109. package/src/utils/transition-event-helper.ts +8 -8
  110. package/src/utils/types.ts +156 -157
  111. package/src/utils/utils.ts +12 -12
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- import e from"quill";const t={container:`table-up-container`,tableCaption:`table-up-caption`,tableWrapper:`table-up`,tableMain:`table-up-main`,tableColgroup:`table-up-colgroup`,tableCol:`table-up-col`,tableHead:`table-up-head`,tableBody:`table-up-body`,tableFoot:`table-up-foot`,tableRow:`table-up-row`,tableCell:`table-up-cell`,tableCellInner:`table-up-cell-inner`},n={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},r={AFTER_TABLE_RESIZE:`after-table-resize`,TABLE_SELECTION_DRAG_START:`table-selection-drag-start`,TABLE_SELECTION_DRAG_END:`table-selection-drag-end`,TABLE_SELECTION_CHANGE:`table-selection-change`,TABLE_SELECTION_DISPLAY_CHANGE:`table-selection-display-change`},i={moduleName:`table-up`},a=[[`rgb(255, 255, 255)`,`rgb(0, 0, 0)`,`rgb(72, 83, 104)`,`rgb(41, 114, 244)`,`rgb(0, 163, 245)`,`rgb(49, 155, 98)`,`rgb(222, 60, 54)`,`rgb(248, 136, 37)`,`rgb(245, 196, 0)`,`rgb(153, 56, 215)`],[`rgb(242, 242, 242)`,`rgb(127, 127, 127)`,`rgb(243, 245, 247)`,`rgb(229, 239, 255)`,`rgb(229, 246, 255)`,`rgb(234, 250, 241)`,`rgb(254, 233, 232)`,`rgb(254, 243, 235)`,`rgb(254, 249, 227)`,`rgb(253, 235, 255)`],[`rgb(216, 216, 216)`,`rgb(89, 89, 89)`,`rgb(197, 202, 211)`,`rgb(199, 220, 255)`,`rgb(199, 236, 255)`,`rgb(195, 234, 213)`,`rgb(255, 201, 199)`,`rgb(255, 220, 196)`,`rgb(255, 238, 173)`,`rgb(242, 199, 255)`],[`rgb(191, 191, 191)`,`rgb(63, 63, 63)`,`rgb(128, 139, 158)`,`rgb(153, 190, 255)`,`rgb(153, 221, 255)`,`rgb(152, 215, 182)`,`rgb(255, 156, 153)`,`rgb(255, 186, 132)`,`rgb(255, 226, 112)`,`rgb(213, 142, 255)`],[`rgb(165, 165, 165)`,`rgb(38, 38, 38)`,`rgb(53, 59, 69)`,`rgb(20, 80, 184)`,`rgb(18, 116, 165)`,`rgb(39, 124, 79)`,`rgb(158, 30, 26)`,`rgb(184, 96, 20)`,`rgb(163, 130, 0)`,`rgb(94, 34, 129)`],[`rgb(147, 147, 147)`,`rgb(13, 13, 13)`,`rgb(36, 39, 46)`,`rgb(12, 48, 110)`,`rgb(10, 65, 92)`,`rgb(24, 78, 50)`,`rgb(88, 17, 14)`,`rgb(92, 48, 10)`,`rgb(102, 82, 0)`,`rgb(59, 21, 81)`]],o=new Set([t.tableCellInner]),s=e=>o.has(e.statics.blotName);function c(e){return e&&e.parent?s(e.parent)?!0:c(e.parent):!1}function l(e,t=`table-up`){let n=t?`${t}-`:``;return{b:()=>`${n}${e}`,be:t=>t?`${n}${e}__${t}`:``,bm:t=>t?`${n}${e}--${t}`:``,bem:(t,r)=>t&&r?`${n}${e}__${t}--${r}`:``,ns:e=>e?`${n}${e}`:``,bs:t=>t?`${n}${e}-${t}`:``,cv:e=>e?`--${n}${e}`:``,is:e=>`is-${e}`}}function u(e,t){let n=e.parent;for(;n&&n.statics.blotName!==t&&n!==e.scroll;)n=n.parent;if(n===e.scroll)throw Error(`${e.statics.blotName} must be a child of ${t}`);return n}function d(e,t){let n=Array(t.length),r=new Map(t.map((e,t)=>[e,t])),i=e.parent;for(;i&&i!==e.scroll&&r.size!==0;){if(r.has(i.statics.blotName)){let e=r.get(i.statics.blotName);n[e]=i,r.delete(i.statics.blotName)}i=i.parent}if(r.size>0)throw Error(`${e.statics.blotName} must be a child of ${Array.from(r.keys()).join(`, `)}`);return n}function f(e){let t=new Map,n=e;for(;n&&n.statics.blotName!==`scroll`;)t.set(n.statics.blotName,n),n=n.parent;return t}function p(e,t){let n=[],r=e.children.iterator(),i=null;for(;i=r();)i instanceof t&&n.push(i);return n}function m(e,t,n){for(let r of Object.getOwnPropertyNames(t)){if(n&&n.test(r))continue;Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}return e}function h(e,t){let n=class extends e{constructor(...e){super(...e)}};for(let e of t)m(n.prototype,e.prototype,/^constructor$/);return n}function g(e,t){return e.prototype&&e.prototype instanceof t}function _(e,t){return e=Math.min(t,Math.max(0,Number.parseFloat(`${e}`))),Math.abs(e-t)<1e-6?1:e%t/Number.parseFloat(t)}function v(e){return{h:Math.min(360,Math.max(0,e.h)),s:Math.min(100,Math.max(0,e.s)),b:Math.min(100,Math.max(0,e.b)),a:Math.min(1,Math.max(0,e.a))}}function y(e){e=e.startsWith(`#`)?e.slice(1):e;let t=Number.parseInt(e.slice(0,2),16),n=Number.parseInt(e.slice(2,4),16),r=Number.parseInt(e.slice(4,6),16),i=Number((Number.parseInt(e.slice(6,8)||`ff`,16)/255).toFixed(2));return{r:t,g:n,b:r,a:i}}function b(e){let{r:t,g:n,b:r,a:i}=e;t=_(t,255),n=_(n,255),r=_(r,255);let a=Math.max(t,n,r),o=Math.min(t,n,r),s,c=a,l=a-o,u=a===0?0:l/a;if(a===o)s=0;else{switch(a){case t:s=(n-r)/l+(n<r?6:0);break;case n:s=(r-t)/l+2;break;case r:s=(t-n)/l+4;break}s/=6}return{h:s*360,s:u*100,b:c*100,a:i}}function ee(e){let{h:t,s:n,b:r,a:i}=e;t=_(t,360)*6,n=_(n,100),r=_(r,100);let a=Math.floor(t),o=t-a,s=r*(1-n),c=r*(1-o*n),l=r*(1-(1-o)*n),u=a%6,d=[r,c,s,s,l,r][u],f=[l,r,r,c,s,s][u],p=[s,s,l,r,r,c][u];return{r:Math.round(d*255),g:Math.round(f*255),b:Math.round(p*255),a:i}}function te(e){let t=[e.r.toString(16),e.g.toString(16),e.b.toString(16),Math.round(e.a*255).toString(16)];for(let e in t)t[e].length===1&&(t[e]=`0${t[e]}`);return t.join(``)}const ne=e=>te(ee(e)),x=e=>typeof e==`function`,S=Array.isArray,C=e=>typeof e==`string`,re=e=>typeof e==`number`,ie=e=>typeof e==`object`&&!!e,ae=e=>e===void 0,oe=e=>!Number.isNaN(e)&&Number(e)>0,se=e=>S(e)?e:[e];function ce(e){let{type:t=`default`,content:n}=e||{},r=l(`button`),i=document.createElement(`button`);return i.classList.add(r.b(),t),n&&(C(n)?i.textContent=n:i.appendChild(n)),i}function le(e={}){let t=b(y(e.color||`#ff0000`)),n=l(`color-picker`),r=document.createElement(`div`);r.classList.add(n.b());let i=document.createElement(`div`);i.classList.add(n.be(`content`));let a=document.createElement(`div`);a.classList.add(n.be(`selector`));let o=document.createElement(`div`);o.classList.add(n.be(`background`)),a.appendChild(o);let s=document.createElement(`div`);s.classList.add(n.be(`background-handle`)),o.appendChild(s);let c=document.createElement(`div`);c.classList.add(n.be(`alpha`));let u=document.createElement(`div`);u.classList.add(n.be(`alpha-bg`));let d=document.createElement(`div`);d.classList.add(n.be(`alpha-handle`)),c.appendChild(u),c.appendChild(d);let f=document.createElement(`div`);f.classList.add(n.be(`hue`));let p=document.createElement(`div`);p.classList.add(n.be(`hue-handle`)),f.appendChild(p);let m=document.createElement(`div`);m.classList.add(n.be(`action`));let[h,g,_,x]=[`r`,`g`,`b`,`a`].map(e=>{let r=document.createElement(`div`);r.classList.add(n.be(`action-item`),e);let i=document.createElement(`label`);i.textContent=e.toUpperCase();let a=document.createElement(`input`);return a.classList.add(n.be(`input`)),a.addEventListener(`input`,()=>{a.value=a.value.replaceAll(/[^0-9]/g,``)}),a.addEventListener(`change`,()=>{let n=Math.round(Number(a.value));e===`a`&&(n/=100);let r=v(b(Object.assign({},ee(t),{[e]:n})));ue(r),w()}),r.appendChild(i),r.appendChild(a),m.appendChild(r),a});i.appendChild(f),i.appendChild(a),i.appendChild(c),r.appendChild(i),r.appendChild(m);let S=!1,C=!1,re=!1;function ie(){let e=ne(t);for(let[t,n]of[h,g,_].entries())n.value=String(Number.parseInt(e[t*2]+e[t*2+1],16));x.value=String((t.a*100).toFixed(0))}function ae(){Object.assign(s.style,{left:`${Math.floor(230*t.s/100)}px`,top:`${Math.floor(150*(100-t.b)/100)}px`})}function oe(){a.style.backgroundColor=`#${te(ee({h:t.h,s:100,b:100,a:1}))}`}function se(){p.style.top=`${Math.floor(150-150*t.h/360)}px`}function ce(){d.style.left=`${t.a*100}%`}function le(){let{r:e,g:n,b:r}=ee(t);u.style.background=`linear-gradient(to right, rgba(${e}, ${n}, ${r}, 0) 0%, rgba(${e}, ${n}, ${r}, 1) 100%)`}function w(){ae(),oe(),se(),ce(),le(),ie()}function ue(n){t=v(Object.assign({},t,n)),ie(),e.onChange&&e.onChange(`#${ne(t)}`)}function de(e){let t=a.getBoundingClientRect(),n=t.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),r=t.left+document.body.scrollLeft,i=Math.floor(100*Math.max(0,Math.min(230,e.pageX-r))/230),o=Math.floor(100*(150-Math.max(0,Math.min(150,e.pageY-n)))/150);ue({s:i,b:o}),w()}function fe(e){let t=f.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);ue({h:Math.floor(360*(150-Math.max(0,Math.min(150,e.pageY-t)))/150)}),w()}function pe(e){let{pageX:t}=e,n=c.getBoundingClientRect(),r=t-n.left;r=Math.max(10/2,r),r=Math.min(r,n.width-10/2),ue({a:Math.round((r-10/2)/(n.width-10)*100)/100}),w()}function T(e){S&&(e.preventDefault(),de(e)),C&&(e.preventDefault(),fe(e)),re&&(e.preventDefault(),pe(e))}function E(){document.removeEventListener(`mousemove`,T),document.removeEventListener(`mouseup`,E),S=!1}function me(e){document.addEventListener(`mousemove`,T),document.addEventListener(`mouseup`,E),S=!0,de(e)}a.addEventListener(`mousedown`,me);function he(){document.removeEventListener(`mousemove`,T),document.removeEventListener(`mouseup`,he),C=!1}function D(e){document.addEventListener(`mousemove`,T),document.addEventListener(`mouseup`,he),C=!0,fe(e)}f.addEventListener(`mousedown`,D);function ge(){document.removeEventListener(`mousemove`,T),document.removeEventListener(`mouseup`,ge),re=!1}function _e(e){document.addEventListener(`mousemove`,T),document.addEventListener(`mouseup`,ge),re=!0,pe(e)}return c.addEventListener(`mousedown`,_e),w(),r}let w=8e3;function ue({child:e,target:t=document.body,beforeClose:n=()=>{}}={}){let r=l(`dialog`),i=t,a=document.createElement(`div`);a.classList.add(r.b()),a.style.zIndex=String(w);let o=document.createElement(`div`);if(o.classList.add(r.be(`overlay`)),a.appendChild(o),e){let t=document.createElement(`div`);t.classList.add(r.be(`content`)),t.appendChild(e),o.appendChild(t),t.addEventListener(`click`,e=>{e.stopPropagation()})}let s=getComputedStyle(i).overflow;i.style.overflow=`hidden`,i.appendChild(a);let c=()=>{n(),a.remove(),i.style.overflow=s};return a.addEventListener(`click`,c),w+=1,{dialog:a,close:c}}function de(e,t){let n=l(`input`);t.type||=`text`,t.value||=``;let r=document.createElement(`div`);if(r.classList.add(n.be(`item`)),e){let t=document.createElement(`span`);t.classList.add(n.be(`label`)),t.textContent=e,r.appendChild(t)}let i=document.createElement(`div`);i.classList.add(n.be(`input`));let a=document.createElement(`input`);for(let e in t)a.setAttribute(e,t[e]);return(t.max||t.min)&&a.addEventListener(`blur`,()=>{t.max&&t.max<=Number(a.value)&&(a.value=String(t.max)),t.min&&t.min>=Number(a.value)&&(a.value=String(t.min))}),i.appendChild(a),r.appendChild(i),a.addEventListener(`focus`,()=>{i.classList.add(`focus`)}),a.addEventListener(`blur`,()=>{i.classList.remove(`focus`)}),{item:r,input:a,errorTip:e=>{let t;return i.classList.contains(`error`)?t=i.querySelector(`.${n.be(`error-tip`)}`):(t=document.createElement(`span`),t.classList.add(n.be(`error-tip`)),i.appendChild(t)),t.textContent=e,i.classList.add(`error`),{removeError:()=>{i.classList.remove(`error`),t.remove()}}}}}async function fe(e={}){let t=l(`creator`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`input`));let{item:i,input:a,errorTip:o}=de(e.rowText||`Row`,{type:`number`,value:String(e.row||``),max:99}),{item:s,input:c,errorTip:u}=de(e.colText||`Column`,{type:`number`,value:String(e.col||``),max:99});r.appendChild(i),r.appendChild(s),n.appendChild(r);let d=document.createElement(`div`);d.classList.add(t.be(`control`));let f=ce({type:`confirm`,content:e.confirmText||`Confirm`}),p=ce({type:`default`,content:e.cancelText||`Cancel`});d.appendChild(f),d.appendChild(p),n.appendChild(d);let m=(t=Number(a.value),n=Number(c.value))=>{if(Number.isNaN(t)||t<=0){o(e.notPositiveNumberError||`Please enter a positive integer`);return}if(Number.isNaN(n)||n<=0){u(e.notPositiveNumberError||`Please enter a positive integer`);return}return{row:t,col:n}},h=e=>{e.key===`Escape`&&(close(),document.removeEventListener(`keydown`,h))};return new Promise((e,t)=>{let{close:r}=ue({child:n,beforeClose:t});a.focus();for(let t of[a,c])t.addEventListener(`keydown`,t=>{if(t.key===`Enter`){let t=m();t&&(e(t),r())}});f.addEventListener(`click`,async()=>{let t=m();t&&(e(t),r())}),document.addEventListener(`keydown`,h),p.addEventListener(`click`,r)}).finally(()=>{document.removeEventListener(`keydown`,h)})}function pe(e={}){let t=l(`select-box`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`block`));for(let n=0;n<(e.row||8);n++)for(let i=0;i<(e.col||8);i++){let e=document.createElement(`div`);e.classList.add(t.be(`item`)),e.dataset.row=String(n+1),e.dataset.col=String(i+1),r.appendChild(e)}let i=()=>{let{row:e,col:t}=n.dataset;for(let e of Array.from(r.querySelectorAll(`.active`)))e.classList.remove(`active`);if(!e||!t)return;let i=Array.from(r.children);for(let n=0;n<i.length;n++){let{row:r,col:a}=i[n].dataset;if(r>e&&a>t)return;i[n].classList.toggle(`active`,r<=e&&a<=t)}};if(r.addEventListener(`mousemove`,e=>{if(!e.target)return;let{row:t,col:r}=e.target.dataset;!t||!r||(n.dataset.row=t,n.dataset.col=r,i())}),r.addEventListener(`mouseleave`,()=>{n.removeAttribute(`data-row`),n.removeAttribute(`data-col`),i()}),r.addEventListener(`click`,()=>{let{row:t,col:r}=n.dataset;!t||!r||e.onSelect&&e.onSelect(Number(t),Number(r))}),n.appendChild(r),e.customBtn){let r=e.texts||{},i=document.createElement(`div`);i.classList.add(t.be(`custom`)),i.textContent=r.customBtnText||`Custom`,i.addEventListener(`click`,async()=>{let t=await fe(r);t&&e.onSelect&&e.onSelect(t.row,t.col)}),n.appendChild(i)}return n}const T=Math.min,E=Math.max,me=Math.round,he=Math.floor,D=e=>({x:e,y:e}),ge={left:`right`,right:`left`,bottom:`top`,top:`bottom`},_e={start:`end`,end:`start`};function ve(e,t,n){return E(e,T(t,n))}function ye(e,t){return typeof e==`function`?e(t):e}function O(e){return e.split(`-`)[0]}function be(e){return e.split(`-`)[1]}function xe(e){return e===`x`?`y`:`x`}function Se(e){return e===`y`?`height`:`width`}const Ce=new Set([`top`,`bottom`]);function k(e){return Ce.has(O(e))?`y`:`x`}function we(e){return xe(k(e))}function Te(e,t,n){n===void 0&&(n=!1);let r=be(e),i=we(e),a=Se(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Pe(o)),[o,Pe(o)]}function Ee(e){let t=Pe(e);return[De(e),t,De(t)]}function De(e){return e.replace(/start|end/g,e=>_e[e])}const Oe=[`left`,`right`],ke=[`right`,`left`],Ae=[`top`,`bottom`],je=[`bottom`,`top`];function Me(e,t,n){switch(e){case`top`:case`bottom`:return n?t?ke:Oe:t?Oe:ke;case`left`:case`right`:return t?Ae:je;default:return[]}}function Ne(e,t,n,r){let i=be(e),a=Me(O(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(De)))),a}function Pe(e){return e.replace(/left|right|bottom|top/g,e=>ge[e])}function Fe(e){return{top:0,right:0,bottom:0,left:0,...e}}function Ie(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Fe(e)}function Le(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function Re(e,t,n){let{reference:r,floating:i}=e,a=k(t),o=we(t),s=Se(o),c=O(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(be(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}const ze=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=a.filter(Boolean),c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Re(l,r,c),f=r,p={},m=0;for(let n=0;n<s.length;n++){let{name:a,fn:h}=s[n],{x:g,y:_,data:v,reset:y}=await h({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:p,rects:l,platform:o,elements:{reference:e,floating:t}});u=g??u,d=_??d,p={...p,[a]:{...p[a],...v}},y&&m<=50&&(m++,typeof y==`object`&&(y.placement&&(f=y.placement),y.rects&&(l=y.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):y.rects),{x:u,y:d}=Re(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:p}};async function Be(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=ye(t,e),p=Ie(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=Le(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=Le(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}const Ve=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=ye(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=O(r),_=k(o),v=O(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Pe(o)]:Ee(o)),ee=p!==`none`;!d&&ee&&b.push(...Ne(o,m,p,y));let te=[o,...b],ne=await Be(t,h),x=[],S=i.flip?.overflows||[];if(l&&x.push(ne[g]),u){let e=Te(r,a,y);x.push(ne[e[0]],ne[e[1]])}if(S=[...S,{placement:r,overflows:x}],!x.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=te[e];if(t&&(!(u===`alignment`&&_!==k(t))||S.every(e=>k(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:S},reset:{placement:t}};let n=S.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=S.filter(e=>{if(ee){let t=k(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}},He=new Set([`left`,`top`]);async function Ue(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=O(n),s=be(n),c=k(n)===`y`,l=He.has(o)?-1:1,u=a&&c?-1:1,d=ye(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const We=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Ue(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},Ge=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i}=t,{mainAxis:a=!0,crossAxis:o=!1,limiter:s={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...c}=ye(e,t),l={x:n,y:r},u=await Be(t,c),d=k(O(i)),f=xe(d),p=l[f],m=l[d];if(a){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=p+u[e],r=p-u[t];p=ve(n,p,r)}if(o){let e=d===`y`?`top`:`left`,t=d===`y`?`bottom`:`right`,n=m+u[e],r=m-u[t];m=ve(n,m,r)}let h=s.fn({...t,[f]:p,[d]:m});return{...h,data:{x:h.x-n,y:h.y-r,enabled:{[f]:a,[d]:o}}}}}},Ke=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=ye(e,t),u={x:n,y:r},d=k(i),f=xe(d),p=u[f],m=u[d],h=ye(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=He.has(O(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}};function qe(){return typeof window<`u`}function Je(e){return Ye(e)?(e.nodeName||``).toLowerCase():`#document`}function A(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function j(e){return((Ye(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Ye(e){return qe()?e instanceof Node||e instanceof A(e).Node:!1}function M(e){return qe()?e instanceof Element||e instanceof A(e).Element:!1}function N(e){return qe()?e instanceof HTMLElement||e instanceof A(e).HTMLElement:!1}function Xe(e){return!qe()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof A(e).ShadowRoot}const Ze=new Set([`inline`,`contents`]);function Qe(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=P(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Ze.has(i)}const $e=new Set([`table`,`td`,`th`]);function et(e){return $e.has(Je(e))}const tt=[`:popover-open`,`:modal`];function nt(e){return tt.some(t=>{try{return e.matches(t)}catch{return!1}})}const rt=[`transform`,`translate`,`scale`,`rotate`,`perspective`],it=[`transform`,`translate`,`scale`,`rotate`,`perspective`,`filter`],at=[`paint`,`layout`,`strict`,`content`];function ot(e){let t=ct(),n=M(e)?P(e):e;return rt.some(e=>n[e]?n[e]!==`none`:!1)||(n.containerType?n.containerType!==`normal`:!1)||!t&&(n.backdropFilter?n.backdropFilter!==`none`:!1)||!t&&(n.filter?n.filter!==`none`:!1)||it.some(e=>(n.willChange||``).includes(e))||at.some(e=>(n.contain||``).includes(e))}function st(e){let t=F(e);for(;N(t)&&!ut(t);){if(ot(t))return t;if(nt(t))return null;t=F(t)}return null}function ct(){return typeof CSS>`u`||!CSS.supports?!1:CSS.supports(`-webkit-backdrop-filter`,`none`)}const lt=new Set([`html`,`body`,`#document`]);function ut(e){return lt.has(Je(e))}function P(e){return A(e).getComputedStyle(e)}function dt(e){return M(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function F(e){if(Je(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Xe(e)&&e.host||j(e);return Xe(t)?t.host:t}function ft(e){let t=F(e);return ut(t)?e.ownerDocument?e.ownerDocument.body:e.body:N(t)&&Qe(t)?t:ft(t)}function pt(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=ft(e),i=r===e.ownerDocument?.body,a=A(r);if(i){let e=mt(a);return t.concat(a,a.visualViewport||[],Qe(r)?r:[],e&&n?pt(e):[])}return t.concat(r,pt(r,[],n))}function mt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function ht(e){let t=P(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=N(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=me(n)!==a||me(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function gt(e){return M(e)?e:e.contextElement}function _t(e){let t=gt(e);if(!N(t))return D(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=ht(t),o=(a?me(n.width):n.width)/r,s=(a?me(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}const vt=D(0);function yt(e){let t=A(e);return!ct()||!t.visualViewport?vt:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function bt(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==A(e)?!1:t}function xt(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=gt(e),o=D(1);t&&(r?M(r)&&(o=_t(r)):o=_t(e));let s=bt(a,n,r)?yt(a):D(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=A(a),t=r&&M(r)?A(r):r,n=e,i=mt(n);for(;i&&r&&t!==n;){let e=_t(i),t=i.getBoundingClientRect(),r=P(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=A(i),i=mt(n)}}return Le({width:u,height:d,x:c,y:l})}function St(e,t){let n=dt(e).scrollLeft;return t?t.left+n:xt(j(e)).left+n}function Ct(e,t){let n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-St(e,n),i=n.top+t.scrollTop;return{x:r,y:i}}function wt(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=j(r),s=t?nt(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=D(1),u=D(0),d=N(r);if((d||!d&&!a)&&((Je(r)!==`body`||Qe(o))&&(c=dt(r)),N(r))){let e=xt(r);l=_t(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?Ct(o,c):D(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function Tt(e){return Array.from(e.getClientRects())}function Et(e){let t=j(e),n=dt(e),r=e.ownerDocument.body,i=E(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=E(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+St(e),s=-n.scrollTop;return P(r).direction===`rtl`&&(o+=E(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}function Dt(e,t){let n=A(e),r=j(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=ct();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=St(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=25&&(a-=o)}else l<=25&&(a+=l);return{width:a,height:o,x:s,y:c}}const Ot=new Set([`absolute`,`fixed`]);function kt(e,t){let n=xt(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=N(e)?_t(e):D(1),o=e.clientWidth*a.x,s=e.clientHeight*a.y,c=i*a.x,l=r*a.y;return{width:o,height:s,x:c,y:l}}function At(e,t,n){let r;if(t===`viewport`)r=Dt(e,n);else if(t===`document`)r=Et(j(e));else if(M(t))r=kt(t,n);else{let n=yt(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return Le(r)}function jt(e,t){let n=F(e);return n===t||!M(n)||ut(n)?!1:P(n).position===`fixed`||jt(n,t)}function Mt(e,t){let n=t.get(e);if(n)return n;let r=pt(e,[],!1).filter(e=>M(e)&&Je(e)!==`body`),i=null,a=P(e).position===`fixed`,o=a?F(e):e;for(;M(o)&&!ut(o);){let t=P(o),n=ot(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&Ot.has(i.position)||Qe(o)&&!n&&jt(e,o))?r=r.filter(e=>e!==o):i=t,o=F(o)}return t.set(e,r),r}function Nt(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?nt(t)?[]:Mt(t,this._c):[].concat(n),r],o=a[0],s=a.reduce((e,n)=>{let r=At(t,n,i);return e.top=E(r.top,e.top),e.right=T(r.right,e.right),e.bottom=T(r.bottom,e.bottom),e.left=E(r.left,e.left),e},At(t,o,i));return{width:s.right-s.left,height:s.bottom-s.top,x:s.left,y:s.top}}function Pt(e){let{width:t,height:n}=ht(e);return{width:t,height:n}}function Ft(e,t,n){let r=N(t),i=j(t),a=n===`fixed`,o=xt(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=D(0);function l(){c.x=St(i)}if(r||!r&&!a)if((Je(t)!==`body`||Qe(i))&&(s=dt(t)),r){let e=xt(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?Ct(i,s):D(0),d=o.left+s.scrollLeft-c.x-u.x,f=o.top+s.scrollTop-c.y-u.y;return{x:d,y:f,width:o.width,height:o.height}}function It(e){return P(e).position===`static`}function Lt(e,t){if(!N(e)||P(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return j(e)===n&&(n=n.ownerDocument.body),n}function Rt(e,t){let n=A(e);if(nt(e))return n;if(!N(e)){let t=F(e);for(;t&&!ut(t);){if(M(t)&&!It(t))return t;t=F(t)}return n}let r=Lt(e,t);for(;r&&et(r)&&It(r);)r=Lt(r,t);return r&&ut(r)&&It(r)&&!ot(r)?n:r||st(e)||n}const zt=async function(e){let t=this.getOffsetParent||Rt,n=this.getDimensions,r=await n(e.floating);return{reference:Ft(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Bt(e){return P(e).direction===`rtl`}const Vt={convertOffsetParentRelativeRectToViewportRelativeRect:wt,getDocumentElement:j,getClippingRect:Nt,getOffsetParent:Rt,getElementRects:zt,getClientRects:Tt,getDimensions:Pt,getScale:_t,isElement:M,isRTL:Bt};function Ht(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ut(e,t){let n=null,r,i=j(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=he(d),h=he(i.clientWidth-(u+f)),g=he(i.clientHeight-(d+p)),_=he(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:E(0,T(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!Ht(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function Wt(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=gt(e),u=i||a?[...l?pt(l):[],...pt(t)]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?Ut(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),p.observe(t));let m,h=c?xt(e):null;c&&g();function g(){let t=xt(e);h&&!Ht(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const Gt=We,Kt=Ge,qt=Ve,Jt=Ke,Yt=(e,t,n)=>{let r=new Map,i={platform:Vt,...n},a={...i.platform,_c:r};return ze(e,t,{...i,platform:a})};function Xt(e,t,n,r,i){return i&&clearTimeout(i),e.addEventListener(`transitionend`,n,r),setTimeout(()=>{n()},t)}let I;function Zt(e,t={}){let{msg:n=``,delay:r=150,content:i,direction:a=`bottom`,type:o=`hover`,container:s,onOpen:c,onClose:u,closed:d,onDestroy:f}=t,p=l(`tooltip`);if(n||i){I||=document.createElement(`div`);let t=s||I,l=document.createElement(`div`);l.classList.add(p.b(),`hidden`,`transparent`),i?l.appendChild(i):n&&(l.textContent=n);let m,h,g,_=()=>{g&&g(),Yt(e,l,{placement:a,middleware:[qt(),Kt({limiter:Jt()}),Gt(4)]}).then(({x:e,y:t})=>{Object.assign(l.style,{left:`${e}px`,top:`${t}px`})})},v=()=>{l.classList.add(`hidden`),t.contains(l)&&(t.removeChild(l),t===I&&!I.hasChildNodes()&&document.body.removeChild(I)),g&&g(),d&&d()},y=(n=!1)=>{h&&clearTimeout(h),m=setTimeout(()=>{if(c){let e=c(n);if(!n&&e)return}t===I&&!I.parentElement&&document.body.appendChild(I),t.appendChild(l),l.removeEventListener(`transitionend`,v),l.classList.remove(`hidden`),g=Wt(e,l,_),l.classList.remove(`transparent`)},r)},b=(e=!1)=>{m&&clearTimeout(m),h=setTimeout(()=>{if(u){let t=u(e);if(!e&&t)return}Xt(l,150,v,{once:!0}),l.classList.add(`transparent`)},r)},{prepare:ee,show:te,hide:ne,destroy:x}={hover:()=>{let t=[e,l],n=b.bind(void 0,!1),r=y.bind(void 0,!1);return{prepare:()=>{for(let e of t)e.addEventListener(`mouseenter`,r),e.addEventListener(`mouseleave`,n)},show:y,hide:b,destroy:()=>{for(let e of t)e.removeEventListener(`mouseenter`,r),e.removeEventListener(`mouseleave`,n)}}},click:()=>{let t=e=>{e.stopPropagation(),b(!1)},n=e=>{e.stopPropagation(),y(),document.removeEventListener(`click`,t),document.addEventListener(`click`,t,{once:!0})};return{prepare:()=>{l.addEventListener(`click`,e=>e.stopPropagation()),e.addEventListener(`click`,n)},show:y,hide:(e=!1)=>{b(e),document.removeEventListener(`click`,t)},destroy:()=>{e.removeEventListener(`click`,n),document.removeEventListener(`click`,t)}}}}[o]();return ee(),{show:te,hide:ne,destroy:()=>{ne(!0),f&&f(),x(),g&&g(),l.remove()}}}return null}function Qt(e,t,n=0,r=!0){let{x:i,y:a,x1:o,y1:s}=e,{x:c,y:l,x1:u,y1:d}=t,f,p;return r?(f=o<c+n||i-n>u,p=s<l+n||a-n>d):(f=o<=c+n||i-n>=u,p=s<=l+n||a-n>=d),!(f||p)}function $t(e,t){let n=t.getBoundingClientRect();return{x:e.x-n.x-t.scrollLeft,y:e.y-n.y-t.scrollTop,x1:e.x-n.x-t.scrollLeft+e.width,y1:e.y-n.y-t.scrollTop+e.height,width:e.width,height:e.height}}function en(e){let{left:t,top:n,width:r,height:i}=e,{clientWidth:a,clientHeight:o}=document.documentElement,s=!1,c=!1;return t+r>a?(t=a-r-8,s=!0):t<0&&(t=8,s=!0),n+i>o?(n=o-i-8,c=!0):n<0&&(n=8,c=!0),{left:t,top:n,leftLimited:s,topLimited:c}}function tn(e,t={}){let n=Symbol(`ignoreFirstBind`),r=new Set,i=new ResizeObserver(r=>{t.ignoreFirstBind&&r.some(e=>{let t=e.target,r=t[n];return t[n]=!0,!r})||e(r)}),a=i.observe;i.observe=(e,t)=>{r.add(e),a.call(i,e,t)};let o=i.unobserve;i.unobserve=e=>{r.has(e)&&(r.delete(e),e[n]=void 0),o.call(i,e)};let s=i.disconnect;return i.disconnect=()=>{for(let e of r.values())e[n]=void 0;s.call(i)},i}function L(e,t){e.addEventListener(`scroll`,t),this.scrollHandler.push([e,t])}function nn(){for(let e=0;e<this.scrollHandler.length;e++){let[t,n]=this.scrollHandler[e];t.removeEventListener(`scroll`,n)}this.scrollHandler=[]}function rn(e){return{y:e.scrollTop,x:e.scrollLeft}}function an({target:e=document.body}={}){let t=document.createElement(`div`);Object.assign(t.style,{visibility:`hidden`,width:`100px`,height:`100%`,overflow:`auto`,position:`absolute`,top:`-9999px`}),e.appendChild(t);let n=t.offsetWidth;t.style.overflow=`scroll`;let r=document.createElement(`div`);r.style.width=`100%`,t.appendChild(r);let i=r.offsetWidth;return t.parentNode?.removeChild(t),n-i}function on(e){return e.replaceAll(/([A-Z])/g,` $1`).trim().split(` `).join(`-`).toLowerCase()}function sn(e){return e.replaceAll(/-(\w)/g,(e,t)=>t.toUpperCase())}function cn(e){let t={};if(!e.style.cssText)return t;let n=e.style.cssText.split(`;`).filter(e=>e.trim());for(let e of n){let n=e.indexOf(`:`);if(n===-1)continue;let r=e.slice(0,n).trim();t[r]=e.slice(n+1).trim()}return t}function ln(e){let t={},n=e.trim().split(`;`);for(let e=0;e<n.length;e++){let r=n[e].trim();if(!r)continue;let i=r.indexOf(`:`);if(i===-1)continue;let a=r.slice(0,Math.max(0,i)).trim(),o=r.slice(Math.max(0,i+1)).trim();t[sn(a)]=o}return t}function un(e){return Object.entries(e).map(([e,t])=>`${on(e)}: ${t};`).join(` `)}const R=()=>Math.random().toString(36).slice(2);function dn(e,t){let n;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,r)},t)}}const fn=e.import(`parchment`),pn=e.import(`blots/container`),mn=e.import(`blots/block`),hn=e.import(`blots/block/embed`);var z=class e extends pn{static tagName;static blotName=t.container;static scope=fn.Scope.BLOCK_BLOT;static allowedChildren=[mn,hn,pn];static requiredContainer;static defaultChild;static allowAttrs=new Set([]);static allowDataAttrs=new Set([]);static allowDataAttrsChangeHandler={};static create(e){let t=document.createElement(this.tagName);return this.className&&t.classList.add(this.className),t}setFormatValue(e,t){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let n=e;this.statics.allowDataAttrs.has(e)&&(n=`data-${e}`),t?this.domNode.setAttribute(n,t):this.domNode.removeAttribute(n);let r=this.statics.allowDataAttrsChangeHandler[e];r&&x(this[r])&&this[r](t)}}optimize(e){if(this.children.length===0)if(this.statics.defaultChild!=null){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.children.length>0&&this.next!=null&&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===fn.Scope.BLOCK_BLOT?(t.parent instanceof e?(t.next!=null&&t.parent.splitAfter(t),t.prev!=null&&t.parent.splitAfter(t.prev)):(t.next!=null&&this.splitAfter(t),t.prev!=null&&this.splitAfter(t.prev)),t.parent.unwrap()):t instanceof fn.ParentBlot?t.unwrap():t.remove())})}};const B=e=>oe(e)?e:1;function gn(e,t){return Object.keys(e).every(n=>JSON.stringify(e[n])===JSON.stringify(t[n]))}const _n=e.import(`parchment`),vn=e.import(`blots/block`),yn=e.import(`blots/block/embed`),bn=e.import(`blots/container`);var xn=class extends vn{replaceWith(e,n){let r=C(e)?this.scroll.create(e,n):e;if(r instanceof _n.ParentBlot)if(r.statics.blotName===t.tableCellInner){let e=null;try{e=u(this,t.tableCellInner);let n=e.formats(),i=r.formats();if(gn(n,i))return e}catch{}if(e)e.insertBefore(r,this),r.appendChild(this),e.children.length===0&&e.remove();else{let e=this,t=e;for(;e.parent!==this.scroll&&e.parent instanceof bn;)t=e,e=e.parent;e===this.scroll&&(e=t);let n=this.offset(e),i=this.length(),a=e.isolate(n,i);a&&a.parent&&a.parent.insertBefore(r,a.next),r.appendChild(this)}return r}else this.moveChildren(r);return this.parent!==null&&(this.parent.insertBefore(r,this.next),this.remove()),this.attributes.copy(r),r}format(e,n){if(e===t.tableCellInner&&this.parent.statics.blotName===e&&!n){if(this.prev&&this.prev instanceof yn)return;try{u(this,t.tableCellInner).unwrap()}catch{console.error(`unwrap TableCellInner error`)}}else super.format(e,n)}};const Sn=e.import(`blots/block/embed`);var Cn=class extends Sn{delta(){let e=super.delta(),n=wn(this);return n[t.tableCellInner]&&e.insert(`
2
- `,{[t.tableCellInner]:n[t.tableCellInner]}),e}length(){return wn(this)[t.tableCellInner]?super.length()+1:super.length()}formatAt(e,n,r,i){if(r===t.tableCellInner)try{let e=u(this,t.tableCellInner),n=this.scroll.create(t.tableCellInner,i);e.insertBefore(n,this),n.appendChild(this),e.length()===0&&e.remove()}catch{}else this.format(r,i)}};function wn(e,t={},n=!0){return e==null||(`formats`in e&&typeof e.formats==`function`&&(t={...t,...e.formats()},n&&delete t[`code-token`]),e.parent==null||e.parent.statics.blotName===`scroll`||e.parent.statics.scope!==e.statics.scope)?t:wn(e.parent,t,n)}var V=class extends z{static blotName=t.tableBody;static tagName=`tbody`;static create(e){let t=super.create();return t.dataset.tableId=e,t}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent;if(n!==null&&n.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}super.optimize(e)}convertBody(e){let t=this.descendants(H);for(let n of t)n.wrapTag=e}getRows(){return Array.from(this.domNode.querySelectorAll(`tr`)).map(e=>this.scroll.find(e)).filter(Boolean)}};const Tn=e.import(`blots/block`),En=e.import(`blots/block/embed`);var H=class extends z{static blotName=t.tableCellInner;static tagName=`div`;static className=`ql-table-cell-inner`;static allowDataAttrs=new Set([`table-id`,`row-id`,`col-id`,`rowspan`,`colspan`,`empty-row`,`wrap-tag`]);static defaultChild=Tn;static allowStyle=new Set([`background-color`,`border`,`height`]);static isAllowStyle(e){let t=sn(e);for(let e of this.allowStyle)if(t.startsWith(sn(e)))return!0;return!1}static create(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e,u=super.create();u.dataset.tableId=t,u.dataset.rowId=n,u.dataset.colId=r,u.dataset.rowspan=String(B(i)),u.dataset.colspan=String(B(a)),u.dataset.tag=c,u.dataset.wrapTag=l,o&&(u.dataset.style=o);try{s&&(u.dataset.emptyRow=JSON.stringify(s))}catch{}return u}static formats(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e.dataset,u={tableId:String(t),rowId:String(n),colId:String(r),rowspan:Number(B(i)),colspan:Number(B(a)),tag:c,wrapTag:l};o&&(u.style=o);try{s&&(u.emptyRow=JSON.parse(s))}catch{}return u}constructor(e,t,n){super(e,t),t.setAttribute(`contenteditable`,String(e.isEnabled()))}setFormatValue(e,n,r=!1){if(r){if(!this.statics.isAllowStyle(e))return}else super.setFormatValue(e,n);this.parent&&this.parent.statics.blotName===t.tableCell&&this.parent.setFormatValue(e,n),this.clearCache()}clearCache(){let e=this.descendants(Tn,0);for(let t of e)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(e){this.setFormatValue(`row-id`,e)}get colId(){return this.domNode.dataset.colId}set colId(e){this.setFormatValue(`col-id`,e)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(e){this.setFormatValue(`rowspan`,e)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(e){this.setFormatValue(`colspan`,e)}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}set emptyRow(e){if(this.emptyRow.toString()!==e.toString())try{e.length>0?this.setFormatValue(`empty-row`,JSON.stringify(e),!1):this.setFormatValue(`empty-row`,null,!1)}catch{this.setFormatValue(`empty-row`,null,!1)}}set wrapTag(e){this.setFormatValue(`wrap-tag`,e)}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getTableBody(){let e=this.parent;for(;e&&!(e instanceof V)&&e!==this.scroll;)e=e.parent;return e===this.scroll?null:e}getTableRow(){try{return u(this,t.tableRow)}catch{return null}}setStyleByString(e){let t=ln(e);for(let[e,n]of Object.entries(t))this.setFormatValue(e,n,!0)}convertTableCell(){this.parent.statics.blotName===t.tableCell&&(this.parent.convertTableCell(),this.clearCache())}formatAt(e,t,n,r){if(this.children.length===0){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e),t+=e.length()}super.formatAt(e,t,n,r),r&&r.style&&this.setStyleByString(r.style)}insertAt(e,t,n){let[r]=this.children.find(e);if(!r&&this.statics.defaultChild){let e=this.scroll.create(this.statics.defaultChild.blotName||`block`);this.appendChild(e)}super.insertAt(e,t,n),(n==null?this.scroll.create(`text`,t):this.scroll.create(t,n))instanceof En&&r&&r.length()<=1&&r.remove()}formats(){let e=this.statics.formats(this.domNode);return{[this.statics.blotName]:e}}checkMerge(){let{colId:e,rowId:t,colspan:n,rowspan:r}=this,i=this.next;return i!==null&&i.statics.blotName===this.statics.blotName&&i.rowId===t&&i.colId===e&&i.colspan===n&&i.rowspan===r}optimize(){let e=this.parent,n=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof En){let e=this.prev;if(this.insertBefore(e,this.children.head),this.length()<=1){let t=this.scroll.create(`block`);this.insertBefore(t,e.next)}}let r=e!==null&&e.statics.blotName!==t.tableCell;if(r&&(this.wrap(t.tableCell,n),this.children.length===0)){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),this.uiNode!=null&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length===0?this.remove():this.domNode.dataset.style&&r&&e.domNode.style.cssText!==this.domNode.dataset.style&&this.setStyleByString(this.domNode.dataset.style)}insertBefore(e,n){if(e.statics.blotName===this.statics.blotName){let r=e,i=this.statics.formats(r.domNode),a=this.statics.formats(this.domNode);if(gn(a,i)){let e=this.split(n?n.offset():0);return this.parent.insertBefore(r,e)}else{let[e,o]=d(this,[t.tableRow,t.tableCell]),s=o;if(n){let r=n.offset(),i=this.length();if(r!==0&&r<i){let n=this.split(r).wrap(t.tableCell,a);e.insertBefore(n,o.next),s=n}}if(this.tableId!==r.tableId){let e=u(this,t.tableWrapper),n=this.offset(e),i=e.split(n);return e.parent.insertBefore(r,i)}if(this.rowId!==r.rowId){let a=e,o=n;if(o){let t=o.offset(e);a=e.split(t)}let s=this.scroll.create(t.tableRow,i),c=this.scroll.create(t.tableCell,i);return c.appendChild(r),s.appendChild(c),e.parent.insertBefore(s,a)}return e.insertBefore(r.wrap(t.tableCell,i),s)}}else if(e.statics.blotName===t.tableCol){try{let n=u(this,t.tableBody),r=this.offset(n),i=n.split(r);n.parent.insertBefore(e,i),e.optimize({})}catch{console.warn(`TableCellInner not in TableBody`)}return}super.insertBefore(e,n)}};const Dn=e.import(`parchment`),On=e.import(`blots/scroll`);var kn=class extends On{enable(n=!0){let r=e.import(`formats/${t.tableCellInner}`),i=this.domNode.querySelectorAll(`.${r.className}`);for(let e of Array.from(i))e.setAttribute(`contenteditable`,String(!!n));let a=e.import(`formats/${t.tableCaption}`),o=this.domNode.querySelectorAll(`.${a.className}`);for(let e of Array.from(o))e.setAttribute(`contenteditable`,String(!!n));super.enable(n)}createBlock(e,n){let r,i={};if(e[t.tableCellInner])r=t.tableCellInner;else for(let[t,n]of Object.entries(e))this.query(t,Dn.Scope.BLOCK&Dn.Scope.BLOT)==null?i[t]=n:r=t;r===t.tableCellInner&&(i={...e},delete i[r]);let a=this.create(r||this.statics.defaultChild.blotName,r?e[r]:void 0);this.insertBefore(a,n||void 0);let o=a.length();a instanceof H&&o===0&&(o+=1);for(let[e,t]of Object.entries(i))a.formatAt(0,o,e,t);return a}},An=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\r
3
- <!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE -->\r
4
- <path\r
5
- fill="none"\r
6
- stroke="currentColor"\r
7
- stroke-linecap="round"\r
8
- stroke-linejoin="round"\r
9
- stroke-width="2"\r
10
- d="M7 3v18m3-15L7 3L4 6m16 12l-3 3l-3-3m3 3V3"\r
11
- />\r
12
- </svg>\r
13
- `;const jn=e.import(`parchment`),Mn=e.import(`blots/inline`),Nn=e.import(`blots/text`);var U=class extends xn{static blotName=t.tableCaption;static tagName=`caption`;static className=`ql-table-caption`;static allowedChildren=[Mn,Nn];static create(e){let{tableId:t}=e,n=super.create();return n.dataset.tableId=t,e.side===`bottom`&&(n.style.captionSide=`bottom`),n}static formats(e){let{tableId:t}=e.dataset;return{tableId:String(t),side:e.style.captionSide===`bottom`?`bottom`:`top`}}constructor(e,t,n){super(e,t),t.setAttribute(`contenteditable`,String(e.isEnabled())),this.attachUI(this.createUI()),this.domNode.addEventListener(`mouseenter`,()=>{this.scroll.isEnabled()&&(this.uiNode.style.display=`flex`)}),this.domNode.addEventListener(`mouseleave`,()=>{this.scroll.isEnabled()&&(this.uiNode.style.display=`none`)}),this.uiNode.style.display=`none`}createUI(){let e=document.createElement(`i`);return e.classList.add(`ql-table-caption--switch`),e.innerHTML=An,e.addEventListener(`click`,()=>{this.scroll.isEnabled()&&(this.side=this.side===`top`?`bottom`:`top`)}),e}get tableId(){return this.domNode.dataset.tableId}set side(e){this.domNode.style.captionSide=e===`bottom`?`bottom`:`top`}get side(){return this.domNode.style.captionSide===`bottom`?`bottom`:`top`}format(e,t){(!this.scroll.query(e,jn.Scope.BLOCK_BLOT)||e===this.statics.blotName)&&super.format(e,t)}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent;if(n!==null&&n.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}this.children.length===0?this.remove():(super.optimize(e),this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()))}},W=class extends z{static blotName=t.tableRow;static tagName=`tr`;static className=`ql-table-row`;static allowDataAttrs=new Set([`table-id`,`row-id`,`wrap-tag`]);static allowDataAttrsChangeHandler={"wrap-tag":`wrapParentTag`};static create(e){let{tableId:t,rowId:n,wrapTag:r=`tbody`}=e,i=super.create();return i.dataset.tableId=t,i.dataset.rowId=n,i.dataset.wrapTag=r,i}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}setHeight(e){this.foreachCellInner(t=>{t.setFormatValue(`height`,e,!0)})}getCellByColId(e,n){let r=u(this,t.tableMain).getColIds(),i=r.indexOf(e),a=this.children.iterator(),o=null;for(;o=a();){if(o.colId===e)return o;let t=r.indexOf(o.colId);if(t<i&&t+o.colspan>i)return o}return this[n]&&this[n].statics.blotName===t.tableRow?this[n].getCellByColId(e,n):null}insertCell(e,n){let r=[],i=this.children.iterator(),a=0,o;for(;(o=i())&&(a+=o.colspan,!(a>e));)if(o.rowspan!==1)for(let e=0;e<o.rowspan-1;e++)r[e]=(r[e]||0)+o.colspan;if(o&&a-o.colspan<e){let e=o.getCellInner();e.colspan+=1,o.rowspan!==1&&(r.skipRowNum=o.rowspan-1)}else{let e=this.scroll.create(t.tableCell,n),r=this.scroll.create(t.tableCellInner,n),i=this.scroll.create(`block`);i.appendChild(this.scroll.create(`break`)),r.appendChild(i),e.appendChild(r),this.insertBefore(e,o)}return r}getCellByColumIndex(e){let t=[],n=null,r=0;if(e<0)return[n,r,t];let i=this.children.iterator();for(;n=i();){if(r+=n.colspan,n.rowspan!==1)for(let e=0;e<n.rowspan-1;e++)t[e]=(t[e]||0)+n.colspan;if(r>e)break}return[n,r,t]}removeCell(e){if(e<0)return[];let n=this.getCellByColumIndex(e),[r,i]=n,a=n[2];if(!r)return a;if(i-r.colspan<e||r.colspan>1){let[n]=r.descendants(H);if(r.colspan!==1&&e===i-r.colspan){let e=u(this,t.tableMain).getColIds();n.colId=e[e.indexOf(n.colId)+1]}r.rowspan!==1&&(a.skipRowNum=r.rowspan-1),--n.colspan}else r.remove();return a}foreachCellInner(e){let t=this.children.iterator(),n=0,r;for(;r=t();){let[t]=r.descendants(H);if(t&&e(t,n++))break}}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.rowId===this.rowId}wrapParentTag(){let e={thead:t.tableHead,tbody:t.tableBody,tfoot:t.tableFoot},n=this.parent;if(n!==null&&n.statics.blotName!==e[this.wrapTag])if(Object.values(e).includes(n.statics.blotName)){let t=this.offset(this.parent),n=this.parent.split(t);n&&n.length()<=0&&n.remove();let r=this.parent.splitAfter(this);r&&r.length()<=0&&r.remove(),this.parent.replaceWith(e[this.wrapTag],this.tableId)}else this.wrap(e[this.wrapTag],this.tableId)}optimize(e){this.wrapParentTag(),this.enforceAllowedChildren(),this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}},G=class extends z{static blotName=t.tableCell;static tagName=`td`;static className=`ql-table-cell`;static allowAttrs=new Set([`rowspan`,`colspan`]);static allowDataAttrs=new Set([`table-id`,`row-id`,`col-id`,`empty-row`,`wrap-tag`]);static allowStyle=new Set([`background-color`,`border`,`height`]);static isAllowStyle(e){let t=sn(e);for(let e of this.allowStyle)if(t.startsWith(sn(e)))return!0;return!1}static create(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e,u=document.createElement(c);u.classList.add(...se(this.className)),u.dataset.tableId=t,u.dataset.rowId=n,u.dataset.colId=r,u.dataset.wrapTag=l,u.setAttribute(`rowspan`,String(B(i))),u.setAttribute(`colspan`,String(B(a))),o&&(u.style.cssText=o);try{s&&(u.dataset.emptyRow=JSON.stringify(s))}catch{}return u}static formats(e){let{tableId:t,rowId:n,colId:r,emptyRow:i,wrapTag:a=`tbody`}=e.dataset,o=Number(e.getAttribute(`rowspan`)),s=Number(e.getAttribute(`colspan`)),c={tableId:t,rowId:n,colId:r,rowspan:B(o),colspan:B(s),tag:e.tagName.toLowerCase(),wrapTag:a},l=cn(e),u=Object.entries(l).filter(([,e])=>![`initial`,`inherit`].includes(e));u.length>0&&(c.style=u.map(([e,t])=>`${e}: ${t}`).join(`;`));try{i&&(c.emptyRow=JSON.parse(i))}catch{}return c}isChildHeadTableCellInner(){let e=this.children.head;return e&&e.statics.blotName===t.tableCellInner}setFormatValue(e,n){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let t=e;this.statics.allowDataAttrs.has(e)&&(t=`data-${e}`),n?this.domNode.setAttribute(t,n):this.domNode.removeAttribute(t)}else this.statics.isAllowStyle(e)&&(Object.assign(this.domNode.style,{[e]:n}),e.startsWith(`border`)&&this.setStyleBoder(e,n));let r=this.children.head;this.isChildHeadTableCellInner()&&this.domNode.style.cssText&&this.domNode.style.cssText!==r.domNode.dataset.style&&(r.domNode.dataset.style=this.domNode.style.cssText),this.parent&&this.parent.statics.blotName===t.tableRow&&this.parent.setFormatValue(e,n)}setStyleBoder(e,t){let n=t||null;if(!(![`left`,`right`,`top`,`bottom`].some(t=>e.includes(t))&&e.startsWith(`border-`)))return;let r=this.getNearByCell(`left`).map(e=>e.descendant(H,0)[0]).filter(Boolean);for(let t of r)t.setFormatValue(e.replace(`border-`,`border-right-`),n,!0);let i=this.getNearByCell(`top`).map(e=>e.descendant(H,0)[0]).filter(Boolean);for(let t of i)t.setFormatValue(e.replace(`border-`,`border-bottom-`),n,!0)}getNearByCell(e){let n=[];try{let e=u(this,t.tableMain);n.push(...e.getColIds())}catch(e){console.error(`Cell is not in table! ${e}`)}if(n.length===0)return[];if(e===`left`){let e=new Set,t=this.parent;for(let r=0;r<this.rowspan&&t instanceof W;r++){let r=t.children.iterator(),i=null;for(;i=r();){let t=n.indexOf(i.colId)+i.colspan;this.colId===n[t]&&e.add(i)}t=t.next}return Array.from(e)}else if(e===`top`){if(!(this.parent instanceof W)||!this.parent.prev)return[];let e=new Set,t=this.getColumnIndex(),r=t+this.colspan,i=new Set(n.filter((e,n)=>n>=t&&n<r)),a=1,o=this.parent.prev;for(;o;){let t=!1,r=o.children.iterator(),s=null,c=0;for(;s=r();)i.has(s.colId)&&s.rowspan>=a&&(e.add(s),i.delete(s.colId)),c+=s.colspan,s.rowspan>=a&&(t=!0);if(!t&&c===n.length)break;o=o.prev,a+=1}return Array.from(e)}return[]}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute(`rowspan`))}get colspan(){return Number(this.domNode.getAttribute(`colspan`))}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getCellInner(){return this.children.head}convertTableCell(){let e=this.statics.formats(this.domNode),n=e.tag===`td`?`th`:`td`,r=this.children.head;this.isChildHeadTableCellInner()&&r.domNode.dataset.tag!==n&&(r.domNode.dataset.tag=n),this.replaceWith(t.tableCell,{...e,tag:n})}checkMerge(){let{colId:e,rowId:t,colspan:n,rowspan:r}=this,i=this.next;return i!==null&&i.statics.blotName===this.statics.blotName&&i.rowId===t&&i.colId===e&&i.colspan===n&&i.rowspan===r}optimize(e){let{tableId:n,rowId:r,wrapTag:i}=this;if(this.parent!==null&&this.parent.statics.blotName!==t.tableRow&&this.wrap(t.tableRow,{tableId:n,rowId:r,wrapTag:i}),this.parent.statics.blotName===t.tableRow&&this.parent.wrapTag!==i&&this.parent.setFormatValue(`wrap-tag`,i),this.emptyRow.length>0){let e=this.parent.parent;if(e instanceof V){let r=this.parent.next;for(let a of this.emptyRow){let o=this.scroll.create(t.tableRow,{tableId:n,rowId:a,wrapTag:i});e.insertBefore(o,r),r=o.next}}}super.optimize(e)}};const Pn=e.import(`blots/block/embed`);var K=class extends Pn{static blotName=t.tableCol;static tagName=`col`;static validWidth(e,t){let r=Number.parseFloat(String(e));return Number.isNaN(r)&&(r=n[t?`colMinWidthPre`:`colMinWidthPx`]),`${r}${t?`%`:`px`}`}static create(e){let{width:t,tableId:n,colId:r,full:i,align:a}=e,o=super.create();return o.setAttribute(`width`,this.validWidth(t,!!i)),i&&(o.dataset.full=String(i)),a&&a!==`left`&&(o.dataset.align=a),o.dataset.tableId=n,o.dataset.colId=r,o}static value(e){let{tableId:t,colId:r}=e.dataset,i=e.getAttribute(`width`)||String(n.colDefaultWidth),a=e.dataset.align,o=Object.hasOwn(e.dataset,`full`),s={tableId:String(t),colId:String(r),full:o,width:Number.parseFloat(i)};return a&&(s.align=a),s}get width(){let e=this.domNode.getAttribute(`width`);if(!e){if(e=this.domNode.getBoundingClientRect().width,this.full){let t=this.domNode.closest(`table`);return t?e/100*t.getBoundingClientRect().width:n[this.full?`colMinWidthPre`:`colMinWidthPx`]}return e}return Number.parseFloat(String(e))}set width(e){let t=Number.parseFloat(String(e));Number.isNaN(t)&&(t=n[this.full?`colMinWidthPre`:`colMinWidthPx`]),this.domNode.setAttribute(`width`,this.statics.validWidth(t,!!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(e){e?this.domNode.dataset.full=`true`:this.domNode.removeAttribute(`data-full`)}get align(){return this.domNode.dataset.align||``}set align(e){e===`right`||e===`center`?this.domNode.dataset.align=e:this.domNode.removeAttribute(`data-align`)}checkMerge(){let e=this.next,{tableId:t,colId:n}=this;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===t&&e.colId===n}optimize(e){let n=this.parent;if(n!=null&&n.statics.blotName!==t.tableColgroup){let e=this.statics.value(this.domNode);this.wrap(t.tableColgroup,e)}let r=u(this,t.tableColgroup);r.align=this.align,this.next!=null&&this.checkMerge()&&this.next.remove(),super.optimize(e);try{let e=u(this,t.tableColgroup),n=!0;e.children.forEach(e=>{n&&=e.full}),e.full=n}catch{}}insertAt(e,n,r){if(r!=null){if(n===this.statics.blotName&&r.tableId!==this.tableId)try{let e=u(this,t.tableWrapper),i=e.split(this.offset(e)),a=this.scroll.create(n,r);i.parent.insertBefore(a,i)}catch{console.warn(`TableCol not in TableColgroup`)}else super.insertAt(e,n,r);return}try{let e=u(this,t.tableWrapper),r=e.split(this.offset(e)),i=n.split(`
14
- `),a=i.pop(),o=i.map(e=>{let t=this.scroll.create(`block`);return t.insertAt(0,e),t});for(let e of o)r.parent.insertBefore(e,r);a&&r.parent.insertBefore(this.scroll.create(`text`,a),r)}catch{console.warn(`TableCol not in TableColgroup`)}}},q=class extends z{static blotName=t.tableMain;static tagName=`table`;static className=`ql-table`;static create(e){let t=super.create(),{tableId:n,full:r,align:i}=e;return t.dataset.tableId=n,i===`right`||i===`center`?t.dataset.align=i:t.removeAttribute(`date-align`),r&&(t.dataset.full=String(r)),t.setAttribute(`cellpadding`,`0`),t.setAttribute(`cellspacing`,`0`),t}constructor(e,t,n){super(e,t),this.scroll=e,this.updateAlign()}colWidthFillTable(){if(this.full){Object.assign(this.domNode.style,{width:null});return}let e=this.getCols();if(!e)return;let t=e.reduce((e,t)=>t.width+e,0);if(!(t===0||Number.isNaN(t)))return this.domNode.style.width=`${t}px`,t}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,`full`)}set full(e){e?this.domNode.dataset.full=`true`:this.domNode.removeAttribute(`data-full`),this.colWidthFillTable()}get align(){return this.domNode.dataset.align||``}set align(e){e===`right`||e===`center`?this.domNode.dataset.align=e:this.domNode.removeAttribute(`data-align`),this.updateAlign()}setFull(){if(this.full)return;let e=this.getCols();if(e.length===0)return;let t=Math.floor(this.domNode.getBoundingClientRect().width);for(let n of e){let e=n.width/t*100;n.full=!0,n.width=e}}cancelFull(){if(!this.full)return;let e=this.getCols();if(e.length===0)return;let t=Math.floor(this.domNode.getBoundingClientRect().width);for(let r of e)r.full=!1,r.width=Math.max(r.width/100*t,n.colMinWidthPx)}updateAlign(){let e=this.align,t={marginLeft:null,marginRight:null};switch(e){case`center`:t.marginLeft=`auto`,t.marginRight=`auto`;break;case``:case`left`:t.marginRight=`auto`;break;case`right`:t.marginLeft=`auto`;break;default:break}Object.assign(this.domNode.style,t)}getBodys(){return Array.from(this.domNode.querySelectorAll(`thead, tbody, tfoot`)).map(e=>this.scroll.find(e)).filter(Boolean)}getRows(){return Array.from(this.domNode.querySelectorAll(`tr`)).map(e=>this.scroll.find(e)).filter(Boolean)}getRowIds(){return this.getRows().map(e=>e.rowId)}getCols(){return this.descendants(K)}getColIds(){return this.getCols().map(e=>e.colId)}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.domNode.dataset.tableId===this.tableId}optimize(e){let n=this.parent;n!==null&&n.statics.blotName!==t.tableWrapper&&this.wrap(t.tableWrapper,this.tableId),super.optimize(e),this.mergeRow()}mergeRow(){if(!this.parent)return;let e=this.getRows(),t={};for(let n of e)t[n.rowId]||(t[n.rowId]=[]),t[n.rowId].push(n);for(let e of Object.values(t))for(let t=1;t<e.length;t++){let n=e[t];n.moveChildren(e[0]),n.remove()}}checkEmptyCol(e){if(e){let e=this.getRows().length,t=this.getCols(),n=this.descendants(H);for(let r of n)if(r.colspan>1&&r.rowspan>=e){let e=t.findIndex(e=>e.colId===r.colId),n=t[e];for(let i=e+1;i<e+r.colspan;i++)t[i].remove(),n.width+=t[i].width;r.colspan=1}}}checkEmptyRow(e){let n=this.getRows(),r=new Set(n.map(e=>e.rowId));for(let i=n.length-1;i>=0;i--){let a=n[i];if(e){if(a.children.length===0){for(let e=1,t=i-1;t>=0;t--,e++)n[t].foreachCellInner(t=>{if(t.rowspan>e){--t.rowspan;let e=new Set(t.emptyRow);e.delete(a.rowId),t.emptyRow=Array.from(e)}});a.remove()}}else{if(a.children.length===0&&a.prev){let e=a.prev;for(;e&&e.children.length===0;)e=e.prev;e.foreachCellInner(e=>{let t=new Set(e.emptyRow);t.has(a.rowId)||(e.emptyRow=[a.rowId,...t])})}a.foreachCellInner(e=>{for(let n of e.emptyRow)r.has(n)||a.parent.insertBefore(this.scroll.create(t.tableRow,{tableId:this.tableId,rowId:n}),a.next)})}}}sortMergeChildren(){let e={[t.tableCaption]:[],[t.tableColgroup]:[],[t.tableHead]:[],[t.tableBody]:[],[t.tableFoot]:[]};this.children.forEach(t=>{e[t.statics.blotName]&&e[t.statics.blotName].push(t)});for(let t of Object.values(e))for(let e=1;e<t.length;e++)t[e].moveChildren(t[0]);let n=e[t.tableCaption][0],r=e[t.tableColgroup][0],i=e[t.tableHead][0],a=e[t.tableBody][0],o=e[t.tableFoot][0],s=n&&this.children.head!==n,c=r&&n&&n.next!==r,l=r&&!n&&this.children.head!==r,u=i&&!a&&!o&&this.children.tail!==i,d=a&&i&&a.prev!==i,f=a&&!o&&this.children.tail!==a,p=a&&o&&a.next!==o,m=o&&this.children.tail!==o;if(s||c||l||u||d||f||p||m){let e=this.clone();n&&e.appendChild(n),r&&e.appendChild(r),i&&e.appendChild(i),a&&e.appendChild(a),o&&e.appendChild(o),this.children.forEach(e=>e.remove()),e.moveChildren(this)}}insertRow(e){let n=this.getColIds(),r=this.descendants(W),i=new Set(n),a=0;for(let t of r){if(a===e)break;t.foreachCellInner(t=>{if(a+t.rowspan>e&&(t.rowspan+=1,i.delete(t.colId),t.colspan!==1)){let e=n.indexOf(t.colId);for(let r=0;r<t.colspan-1;r++)i.delete(n[e+r+1])}}),a+=1}let o=this.tableId,s=R(),c=this.scroll.create(t.tableRow,{tableId:o,rowId:s});for(let e of i){let n=this.scroll.create(`break`).wrap(`block`).wrap(t.tableCellInner,{tableId:o,rowId:s,colId:e,rowspan:1,colspan:1}).wrap(t.tableCell,{tableId:o,rowId:s,colId:e,rowspan:1,colspan:1});c.appendChild(n)}let l=r[e]||null;l?l.parent.insertBefore(c,l):r[r.length-1].parent.appendChild(c)}},J=class extends z{static blotName=t.tableColgroup;static tagName=`colgroup`;static create(e){let t=super.create();return t.dataset.tableId=e.tableId,e.full&&(t.dataset.full=String(e.full)),e.align&&e.align!==`left`&&(t.dataset.align=e.align),t.setAttribute(`contenteditable`,`false`),t}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,`full`)}set full(e){e?this.domNode.dataset.full=`true`:this.domNode.removeAttribute(`data-full`),this.parent&&this.parent instanceof q&&(this.parent.full=e)}get align(){return this.domNode.dataset.align||``}set align(e){e===`right`||e===`center`?this.domNode.dataset.align=e:this.domNode.removeAttribute(`data-align`)}findCol(e){let t=this.children.iterator(),n=0,r;for(;(r=t())&&n!==e;)n++;return r}insertColByIndex(e,r){let i=this.parent;if(!(i instanceof q))throw TypeError(`TableColgroupFormat should be child of TableFormat`);let a=this.findCol(e),o=this.scroll.create(t.tableCol,r);if(i.full){let e=this.children.iterator(),t;for(;t=e();)if(t.width-o.width>=n.colMinWidthPre){t.width-=o.width;break}}this.insertBefore(o,a)}removeColByIndex(e){let t=this.parent;if(!(t instanceof q))throw TypeError(`TableColgroupFormat should be child of TableMainFormat`);let n=this.findCol(e);n&&(t.full&&(n.next?n.next.width+=n.width:n.prev&&(n.prev.width+=n.width)),n.remove(),t.colWidthFillTable())}checkMerge(){let e=this.next,t=this.parent;return t instanceof q&&!t.full&&t.colWidthFillTable(),e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent,{tableId:r,full:i,align:a}=this;n!=null&&n.statics.blotName!==t.tableMain&&this.wrap(t.tableMain,{tableId:r,full:i,align:a});let o=u(this,t.tableMain);o.align=a,super.optimize(e)}},Fn=class extends V{static blotName=t.tableFoot;static tagName=`tfoot`},In=class extends V{static blotName=t.tableHead;static tagName=`thead`};const Ln=e.import(`parchment`);var Y=class extends z{static blotName=t.tableWrapper;static tagName=`div`;static className=`ql-table-wrapper`;static create(e){let t=super.create();return t.dataset.tableId=e,t.addEventListener(`dragstart`,e=>{e.preventDefault(),e.stopPropagation()},!0),t.addEventListener(`drop`,e=>{e.preventDefault()}),t.addEventListener(`dragover`,e=>{e.preventDefault(),e.dataTransfer.dropEffect=`none`}),t.setAttribute(`contenteditable`,`false`),t}constructor(t,n,r){super(t,n),this.scroll=t,this.scroll.emitter.on(e.events.TEXT_CHANGE,this.insertLineAround)}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){if(this.length()===0){this.remove();return}super.optimize(e)}deleteAt(e,t){super.deleteAt(e,t);let n=this.descendants(V),r=this.descendants(J);n.length===0&&r.length===0&&this.remove()}remove(){super.remove(),this.scroll.emitter.off(e.events.TEXT_CHANGE,this.insertLineAround)}isBlockLine(e){return e instanceof Ln.BlockBlot||new Set([`list-container`,`code-block-container`]).has(e.statics.blotName)}insertLineAround=()=>{(!this.prev||!this.isBlockLine(this.prev))&&this.parent.insertBefore(this.scroll.create(`block`),this),(!this.next||!this.isBlockLine(this.next))&&this.parent.insertBefore(this.scroll.create(`block`),this.next)}};function X(e){let n=new Set([t.tableHead,t.tableBody,t.tableFoot]),r=e.children.iterator(),i=null,a={};for(;i=r();)n.has(i.statics.blotName)&&(a[i.statics.blotName]=i);if(Object.values(a).length<=0)return{rect:null,head:null,body:null,foot:null};let o=Object.values(a).reduce((e,t)=>{let n=t.domNode.getBoundingClientRect();return{...e,top:Math.min(e.top,n.top),bottom:Math.max(e.bottom,n.bottom),left:Math.min(e.left,n.left),right:Math.max(e.right,n.right)}},{top:1/0,bottom:0,left:1/0,right:0,width:0,height:0,x:1/0,y:1/0});return o.width=o.right-o.left,o.height=o.bottom-o.top,o.x=o.left,o.y=o.top,{rect:o,head:a[t.tableHead]||null,body:a[t.tableBody]||null,foot:a[t.tableFoot]||null}}var Rn=class{table;constructor(e,t){this.tableModule=e,this.quill=t,this.quill.root.addEventListener(`mousedown`,this.tableSelectHandler.bind(this))}tableSelectHandler(e){let t=e.composedPath();if(e.button!==0||!t||t.length<=0)return;let n=t.find(e=>e.tagName&&e.tagName.toUpperCase()===`TABLE`);this.setSelectionTable(n)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show(),this.update())}hide(){}show(){}update(){}},zn=class extends Rn{static moduleName=`table-align`;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=l(`align`);resizeObserver;constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.alignBox=this.buildTools(),this.hide(),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};buildTools(){let t=this.tableModule.addContainer(this.bem.b()),n=e.import(`ui/icons`),r={left:n.align[``],center:n.align.center,right:n.align.right};for(let[e,n]of Object.entries(r)){let r=document.createElement(`span`);r.dataset.align=e,r.classList.add(this.bem.be(`item`)),r.innerHTML=`<i class="icon">${n}</i>`,r.addEventListener(`click`,this.handleAlignItemClick.bind(this)),t.appendChild(r)}return t}handleAlignItemClick(e){let t=e.currentTarget;if(!t)return;let n=t.dataset.align;n&&this.tableBlot&&this.setTableAlign(this.tableBlot,n)}setTableAlign(e,t){let n=e.getCols();for(let e of n)e.align=t}show(){!this.table||!this.alignBox||(this.tableBlot=e.find(this.table),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=tn(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.cleanup&&this.cleanup(),this.cleanup=Wt(this.tableWrapperBlot.domNode,this.alignBox,()=>this.update()))}hide(){this.tableBlot=void 0,this.tableWrapperBlot=void 0,this.alignBox&&this.alignBox.classList.add(this.bem.is(`hidden`)),this.cleanup&&=(this.cleanup(),void 0)}update(){if(!(!this.alignBox||!this.tableBlot||!this.tableWrapperBlot)){if(!this.table||this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth){this.hide();return}Yt(this.tableWrapperBlot.domNode,this.alignBox,{placement:`top`,middleware:[qt(),Kt({limiter:Jt()}),Gt(16)]}).then(({x:e,y:t})=>{Object.assign(this.alignBox.style,{left:`${e}px`,top:`${t}px`})})}}destroy(){this.hide(),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&=(this.alignBox.remove(),null)}};const Bn=e.import(`delta`);function Vn(e,t,n){let{rows:r,cols:i}=Hn(t),{rows:a,cols:o,cells:s}=Un(n);r===a&&i===o?Gn(t,s,e):Jn(e,t,s)}function Hn(e){if(e.length===0)return{rows:0,cols:0};let t=Kn(e);return Wn(t)}function Un(e){let n=new Map;for(let r of e){let e=r.attributes;if(!e)continue;let i=e[t.tableCellInner];if(!i)continue;let a=`${i.rowId}-${i.colId}`;if(!n.has(a)){let e={rowId:i.rowId,colId:i.colId,rowspan:i.rowspan||1,colspan:i.colspan||1,deltaOps:[]};i.emptyRow&&i.emptyRow.length>0&&(e.emptyRow=i.emptyRow),n.set(a,e)}let o=n.get(a),{[t.tableCellInner]:s,...c}=e;o.deltaOps.push({insert:r.insert,attributes:{...c}})}let r=Array.from(n.values()),i=Kn(r);return{...Wn(i),cells:r}}function Wn(e){let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e){let{cell:e,rowIndex:o,colIndex:s}=a,c=e.colspan||1,l=e.rowspan||1;t=Math.min(t,o),n=Math.max(n,o+l-1),r=Math.min(r,s),i=Math.max(i,s+c-1)}return{rows:Math.max(n-t+1,0),cols:Math.max(i-r+1,0)}}function Gn(e,t,n){let r=Kn(e),i=Kn(t),a=new Map;for(let e of i)a.set(`${e.rowIndex}-${e.colIndex}`,e.cell);let o=[],s=new Set;for(let e of r){let t=e.cell;if(!t.domNode.isConnected||s.has(t))continue;let r=a.get(`${e.rowIndex}-${e.colIndex}`);if(r){let e=Yn(n,t,r.deltaOps,{rowspan:r.rowspan,colspan:r.colspan,emptyRow:r.emptyRow});o.push(e),s.add(t)}}Xn(n,o)}function Kn(e){let t=[],n=qn(e),r=-1,i=new Map;for(let[e,a]of n.entries()){i.has(e)||(r+=1,i.set(e,r));let n=0;for(let o of a){t.push({cell:o,rowIndex:i.get(e),colIndex:n}),n+=o.colspan||1;let a=o.emptyRow||[];for(let e of a)i.has(e)||(r+=1,i.set(e,r))}}return t}function qn(e){let t=new Map;for(let n of e)t.has(n.rowId)||t.set(n.rowId,[]),t.get(n.rowId).push(n);return t}function Jn(e,t,n){let r=qn(n),i=Array.from(r.values()),a=Hn(t).cols,o=[];for(let n=0;n<t.length;n++){let r=t[n],s=Math.floor(n/a),c=n%a,l=s%i.length,u=i[l],d=c%u.length,f=u[d],p=Yn(e,r,f.deltaOps);o.push(p)}Xn(e,o)}function Yn(e,t,n,r){let{rowspan:i=1,colspan:a=1,emptyRow:o}=r||{};r&&(t.rowspan=i,t.colspan=a,o&&o.length>0&&(t.emptyRow=o));let s=t.formats(),c=new Bn;for(let e of n)c.insert(e.insert,{...e.attributes,...s});let l=t.offset(e.quill.scroll),u=t.length();return{offset:l,length:u,insertDelta:c,cell:t,rowspan:i,colspan:a,emptyRow:o}}function Xn(t,n){if(n.length===0)return;n.sort((e,t)=>e.offset-t.offset);let r=new Bn;for(let e=0;e<n.length;e++){let t=n[e],i=t.offset;if(e!==0){let r=n[e-1];i=t.offset-r.offset-r.length}r=r.retain(i).concat(t.insertDelta).delete(t.length)}for(let e of n)Zn(t,e);t.quill.updateContents(r,e.sources.USER)}function Zn(e,n){let{cell:r,rowspan:i=1,colspan:a=1}=n;if(i===1&&a===1)return;let o=u(r,t.tableMain);if(!o)return;let s=r.getTableRow();if(!s)return;let c=o.descendants(H),l=o.getRows(),d=l.indexOf(s),f=r.getColumnIndex(),p=[];for(let e of c){if(e===r)continue;let t=e.getTableRow();if(!t)continue;let n=l.indexOf(t),o=e.getColumnIndex(),s=n>=d&&n<d+i,c=o>=f&&o<f+a;s&&c&&p.push(e)}let m=e.talbeModule.options.autoMergeCell;for(let e of p)if(e.domNode.isConnected){let t=e.getTableRow();e.remove(),!m&&t&&t.length()<=0&&t.remove()}}const Qn=e.import(`delta`),$n=e.import(`modules/clipboard`);function er(e){let t=Number.parseFloat(e.getAttribute(`width`));if(Number.isNaN(t)){let n=e.style.width;t=n?Number.parseFloat(n):e.offsetWidth}return t||n.colDefaultWidth}function tr(e,t){let r=Array(t).fill(n.colDefaultWidth),i=Array.from(e.querySelectorAll(`tr`));for(let e of i){let n=Array.from(e.querySelectorAll(`td`)),i=0;for(let e of n){let n=e.colSpan||1;if(i<t){let t=er(e);for(let e=0;e<n;e++)r[i+e]=t/n}else break;i+=n}}return r}var nr=class extends $n{tableId=R();rowId=R();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(e,t){super(e,t),this.quill=e,this.addMatcher(`table`,this.matchTable.bind(this)),this.addMatcher(`thead`,this.matchThead.bind(this)),this.addMatcher(`tbody`,this.matchTbody.bind(this)),this.addMatcher(`tfoot`,this.matchTfoot.bind(this)),this.addMatcher(`colgroup`,this.matchColgroup.bind(this)),this.addMatcher(`col`,this.matchCol.bind(this)),this.addMatcher(`tr`,this.matchTr.bind(this)),this.addMatcher(`td`,this.matchTd.bind(this)),this.addMatcher(`th`,this.matchTd.bind(this)),this.addMatcher(`caption`,this.matchCaption.bind(this)),this.addMatcher(Node.ELEMENT_NODE,this.matchTdAttributor.bind(this))}getStyleBackgroundColor(e,n){let r=e.style.backgroundColor;if(r){for(let e of n.ops)if(e.attributes?.[t.tableCellInner]){let{style:n,...i}=e.attributes[t.tableCellInner],a=ln(n||``);a.backgroundColor||(a.backgroundColor=r,e.attributes[t.tableCellInner]={...i,style:un(a)})}}}matchTable(e,n){if(n.ops.length===0)return n;let r=[],i=[],a=-1;for(let e=0;e<n.ops.length;e++){let{attributes:o,insert:s}=n.ops[e];if(!ie(s)&&(!o||!o[t.tableCellInner]&&!o[t.tableCaption])){n.ops.splice(e,1),--e;continue}let{table:c,[t.tableCell]:l,...u}=o||{},d=ie(s)&&s[t.tableCol];d?i.push({insert:s}):r.push({attributes:u,insert:s}),!u?.[t.tableCellInner]&&!u?.[t.tableCaption]&&!d&&C(s)&&s.trim().length>0&&(a=e)}let o=tr(e,this.colIds.length).reduce((e,n,r)=>(i[r]?e.push(i[r]):e.push({insert:{[t.tableCol]:{tableId:this.tableId,colId:this.colIds[r],width:n,full:!1}}}),e),[]);r.splice(a+1,0,...o);let s=new Qn(r);return this.getStyleBackgroundColor(e,s),this.tableId=R(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,s}matchTbody(e,n){this.getStyleBackgroundColor(e,n);let r=[];for(let e=n.ops.length-1;e>=0;e--){let i=n.ops[e];if(i.attributes?.[t.tableCellInner]){if(i.attributes){let e=i.attributes[t.tableCellInner];e.rowspan===1?r=[]:r.length>0&&(e.emptyRow||=[],r.length>e.emptyRow.length&&e.emptyRow.push(...r.slice(e.emptyRow.length-r.length)))}}else{r=[];let e=i.insert?C(i.insert)?i.insert.split(`
15
- `).length-1:1:0;for(let t=0;t<e;t++)r.push(R())}}return this.rowspanCount=[],n}matchThead(e,n){let r=this.matchTbody(e,n);for(let e of r.ops)if(e.attributes&&e.attributes[t.tableCellInner]){let n=e.attributes[t.tableCellInner];n.wrapTag=`thead`}return r}matchTfoot(e,n){let r=this.matchTbody(e,n);for(let e of r.ops)if(e.attributes&&e.attributes[t.tableCellInner]){let n=e.attributes[t.tableCellInner];n.wrapTag=`tfoot`}return r}matchColgroup(e,n){let r=[];for(let e=0;e<n.ops.length;e++){let i=n.ops[e];i&&ie(i.insert)&&i.insert[t.tableCol]&&r.push(i)}return new Qn(r)}matchCol(e,n){let r=Number(e.getAttribute(`span`)||1);Number.isNaN(r)&&(r=1);let i=new Qn;for(let n=0;n<r;n++)this.colIds[this.colCount]=R(),i.insert({[t.tableCol]:Object.assign(K.value(e),{tableId:this.tableId,colId:this.colIds[this.colCount]})}),this.colCount+=1;return i}matchTr(e,t){this.rowId=R(),this.cellCount=0;for(let[e,t]of this.rowspanCount.entries())t.rowspan>0&&--t.rowspan,t.rowspan<=0&&(this.rowspanCount[e]={rowspan:0,colspan:0});return this.getStyleBackgroundColor(e,t),t.ops.length===0?new Qn([{insert:`
16
- `}]):t}matchTd(e,n){let r=e,i=G.formats(r);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let e=this.cellCount;e>=0;e--)this.colIds[e]||(this.colIds[e]=R()),this.rowspanCount[e]||(this.rowspanCount[e]={rowspan:0,colspan:0});for(let e=this.cellCount;e<this.rowspanCount.length;e++){let{rowspan:t,colspan:n}=this.rowspanCount[e];if(t===0)break;this.cellCount+=n}i.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:i.rowspan,colspan:i.colspan});let a=this.colIds[this.cellCount];this.cellCount+=i.colspan;let o=Object.assign(i,{tableId:this.tableId,rowId:this.rowId,colId:a});r.style.border===`none`&&(o.style=o.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,``));let s=[];for(let e of n.ops){let{attributes:n={},...r}=e,{[t.tableCell]:i,...a}=n;s.push({...r,attributes:{...a,[t.tableCellInner]:o}})}return(s.length<=0||!C(s[s.length-1].insert)||!s[s.length-1].insert.endsWith(`
1
+ import e from"quill";const t={container:`table-up-container`,tableCaption:`table-up-caption`,tableWrapper:`table-up`,tableMain:`table-up-main`,tableColgroup:`table-up-colgroup`,tableCol:`table-up-col`,tableHead:`table-up-head`,tableBody:`table-up-body`,tableFoot:`table-up-foot`,tableRow:`table-up-row`,tableCell:`table-up-cell`,tableCellInner:`table-up-cell-inner`},n={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:100,rowMinHeightPx:36},r={AFTER_TABLE_RESIZE:`after-table-resize`,TABLE_SELECTION_DRAG_START:`table-selection-drag-start`,TABLE_SELECTION_DRAG_END:`table-selection-drag-end`,TABLE_SELECTION_CHANGE:`table-selection-change`,TABLE_SELECTION_DISPLAY_CHANGE:`table-selection-display-change`},i={moduleName:`table-up`,tableSelectionName:`table-selection`},a=[[`rgb(255, 255, 255)`,`rgb(0, 0, 0)`,`rgb(72, 83, 104)`,`rgb(41, 114, 244)`,`rgb(0, 163, 245)`,`rgb(49, 155, 98)`,`rgb(222, 60, 54)`,`rgb(248, 136, 37)`,`rgb(245, 196, 0)`,`rgb(153, 56, 215)`],[`rgb(242, 242, 242)`,`rgb(127, 127, 127)`,`rgb(243, 245, 247)`,`rgb(229, 239, 255)`,`rgb(229, 246, 255)`,`rgb(234, 250, 241)`,`rgb(254, 233, 232)`,`rgb(254, 243, 235)`,`rgb(254, 249, 227)`,`rgb(253, 235, 255)`],[`rgb(216, 216, 216)`,`rgb(89, 89, 89)`,`rgb(197, 202, 211)`,`rgb(199, 220, 255)`,`rgb(199, 236, 255)`,`rgb(195, 234, 213)`,`rgb(255, 201, 199)`,`rgb(255, 220, 196)`,`rgb(255, 238, 173)`,`rgb(242, 199, 255)`],[`rgb(191, 191, 191)`,`rgb(63, 63, 63)`,`rgb(128, 139, 158)`,`rgb(153, 190, 255)`,`rgb(153, 221, 255)`,`rgb(152, 215, 182)`,`rgb(255, 156, 153)`,`rgb(255, 186, 132)`,`rgb(255, 226, 112)`,`rgb(213, 142, 255)`],[`rgb(165, 165, 165)`,`rgb(38, 38, 38)`,`rgb(53, 59, 69)`,`rgb(20, 80, 184)`,`rgb(18, 116, 165)`,`rgb(39, 124, 79)`,`rgb(158, 30, 26)`,`rgb(184, 96, 20)`,`rgb(163, 130, 0)`,`rgb(94, 34, 129)`],[`rgb(147, 147, 147)`,`rgb(13, 13, 13)`,`rgb(36, 39, 46)`,`rgb(12, 48, 110)`,`rgb(10, 65, 92)`,`rgb(24, 78, 50)`,`rgb(88, 17, 14)`,`rgb(92, 48, 10)`,`rgb(102, 82, 0)`,`rgb(59, 21, 81)`]],o=new Set([t.tableCellInner]),s=e=>o.has(e.statics.blotName);function c(e){return e?.parent?s(e.parent)?!0:c(e.parent):!1}function l(e,t=`table-up`){let n=t?`${t}-`:``;return{b:()=>`${n}${e}`,be:t=>t?`${n}${e}__${t}`:``,bm:t=>t?`${n}${e}--${t}`:``,bem:(t,r)=>t&&r?`${n}${e}__${t}--${r}`:``,ns:e=>e?`${n}${e}`:``,bs:t=>t?`${n}${e}-${t}`:``,cv:e=>e?`--${n}${e}`:``,is:e=>`is-${e}`}}function u(e,t){let n=e.parent;for(;n&&n.statics.blotName!==t&&n!==e.scroll;)n=n.parent;if(n===e.scroll)throw Error(`${e.statics.blotName} must be a child of ${t}`);return n}function d(e,t){let n=Array(t.length),r=new Map(t.map((e,t)=>[e,t])),i=e.parent;for(;i&&i!==e.scroll&&r.size!==0;){if(r.has(i.statics.blotName)){let e=r.get(i.statics.blotName);n[e]=i,r.delete(i.statics.blotName)}i=i.parent}if(r.size>0)throw Error(`${e.statics.blotName} must be a child of ${Array.from(r.keys()).join(`, `)}`);return n}function f(e){let t=new Map,n=e;for(;n&&n.statics.blotName!==`scroll`;)t.set(n.statics.blotName,n),n=n.parent;return t}function p(e,t){let n=[],r=e.children.iterator(),i=null;for(;i=r();)i instanceof t&&n.push(i);return n}function m(e,t,n){for(let r of Object.getOwnPropertyNames(t))n?.test(r)||Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));return e}function h(e,t){let n=class extends e{};for(let e of t)m(n.prototype,e.prototype,/^constructor$/);return n}function g(e,t){return e.prototype&&e.prototype instanceof t}function _(e,t){return e=Math.min(t,Math.max(0,Number.parseFloat(`${e}`))),Math.abs(e-t)<1e-6?1:e%t/Number.parseFloat(t)}function v(e){return{h:Math.min(360,Math.max(0,e.h)),s:Math.min(100,Math.max(0,e.s)),b:Math.min(100,Math.max(0,e.b)),a:Math.min(1,Math.max(0,e.a))}}function y(e){return e=e.startsWith(`#`)?e.slice(1):e,{r:Number.parseInt(e.slice(0,2),16),g:Number.parseInt(e.slice(2,4),16),b:Number.parseInt(e.slice(4,6),16),a:Number((Number.parseInt(e.slice(6,8)||`ff`,16)/255).toFixed(2))}}function b(e){let{r:t,g:n,b:r,a:i}=e;t=_(t,255),n=_(n,255),r=_(r,255);let a=Math.max(t,n,r),o=Math.min(t,n,r),s,c=a,l=a-o,u=a===0?0:l/a;if(a===o)s=0;else{switch(a){case t:s=(n-r)/l+(n<r?6:0);break;case n:s=(r-t)/l+2;break;case r:s=(t-n)/l+4;break}s/=6}return{h:s*360,s:u*100,b:c*100,a:i}}function ee(e){let{h:t,s:n,b:r,a:i}=e;t=_(t,360)*6,n=_(n,100),r=_(r,100);let a=Math.floor(t),o=t-a,s=r*(1-n),c=r*(1-o*n),l=r*(1-(1-o)*n),u=a%6,d=[r,c,s,s,l,r][u],f=[l,r,r,c,s,s][u],p=[s,s,l,r,r,c][u];return{r:Math.round(d*255),g:Math.round(f*255),b:Math.round(p*255),a:i}}function te(e){let t=[e.r.toString(16),e.g.toString(16),e.b.toString(16),Math.round(e.a*255).toString(16)];for(let e in t)t[e].length===1&&(t[e]=`0${t[e]}`);return t.join(``)}const ne=e=>te(ee(e)),x=e=>typeof e==`function`,S=Array.isArray,C=e=>typeof e==`string`,re=e=>typeof e==`number`,ie=e=>typeof e==`object`&&!!e,ae=e=>e===void 0,oe=e=>!Number.isNaN(e)&&Number(e)>0,se=e=>S(e)?e:[e];function ce(e){let{type:t=`default`,content:n}=e||{},r=l(`button`),i=document.createElement(`button`);return i.classList.add(r.b(),t),n&&(C(n)?i.textContent=n:i.appendChild(n)),i}function le(e={}){let t=b(y(e.color||`#ff0000`)),n=l(`color-picker`),r=document.createElement(`div`);r.classList.add(n.b());let i=document.createElement(`div`);i.classList.add(n.be(`content`));let a=document.createElement(`div`);a.classList.add(n.be(`selector`));let o=document.createElement(`div`);o.classList.add(n.be(`background`)),a.appendChild(o);let s=document.createElement(`div`);s.classList.add(n.be(`background-handle`)),o.appendChild(s);let c=document.createElement(`div`);c.classList.add(n.be(`alpha`));let u=document.createElement(`div`);u.classList.add(n.be(`alpha-bg`));let d=document.createElement(`div`);d.classList.add(n.be(`alpha-handle`)),c.appendChild(u),c.appendChild(d);let f=document.createElement(`div`);f.classList.add(n.be(`hue`));let p=document.createElement(`div`);p.classList.add(n.be(`hue-handle`)),f.appendChild(p);let m=document.createElement(`div`);m.classList.add(n.be(`action`));let[h,g,_,x]=[`r`,`g`,`b`,`a`].map(e=>{let r=document.createElement(`div`);r.classList.add(n.be(`action-item`),e);let i=document.createElement(`label`);i.textContent=e.toUpperCase();let a=document.createElement(`input`);return a.classList.add(n.be(`input`)),a.addEventListener(`input`,()=>{a.value=a.value.replaceAll(/[^0-9]/g,``)}),a.addEventListener(`change`,()=>{let n=Math.round(Number(a.value));e===`a`&&(n/=100),de(v(b(Object.assign({},ee(t),{[e]:n})))),ue()}),r.appendChild(i),r.appendChild(a),m.appendChild(r),a});i.appendChild(f),i.appendChild(a),i.appendChild(c),r.appendChild(i),r.appendChild(m);let S=!1,C=!1,re=!1;function ie(){let e=ne(t);for(let[t,n]of[h,g,_].entries())n.value=String(Number.parseInt(e[t*2]+e[t*2+1],16));x.value=String((t.a*100).toFixed(0))}function ae(){Object.assign(s.style,{left:`${Math.floor(230*t.s/100)}px`,top:`${Math.floor(150*(100-t.b)/100)}px`})}function oe(){a.style.backgroundColor=`#${te(ee({h:t.h,s:100,b:100,a:1}))}`}function se(){p.style.top=`${Math.floor(150-150*t.h/360)}px`}function ce(){d.style.left=`${t.a*100}%`}function le(){let{r:e,g:n,b:r}=ee(t);u.style.background=`linear-gradient(to right, rgba(${e}, ${n}, ${r}, 0) 0%, rgba(${e}, ${n}, ${r}, 1) 100%)`}function ue(){ae(),oe(),se(),ce(),le(),ie()}function de(n){t=v(Object.assign({},t,n)),ie(),e.onChange&&e.onChange(`#${ne(t)}`)}function fe(e){let t=a.getBoundingClientRect(),n=t.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),r=t.left+document.body.scrollLeft;de({s:Math.floor(100*Math.max(0,Math.min(230,e.pageX-r))/230),b:Math.floor(100*(150-Math.max(0,Math.min(150,e.pageY-n)))/150)}),ue()}function pe(e){let t=f.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);de({h:Math.floor(360*(150-Math.max(0,Math.min(150,e.pageY-t)))/150)}),ue()}function me(e){let{pageX:t}=e,n=c.getBoundingClientRect(),r=t-n.left;r=Math.max(10/2,r),r=Math.min(r,n.width-10/2),de({a:Math.round((r-10/2)/(n.width-10)*100)/100}),ue()}function w(e){S&&(e.preventDefault(),fe(e)),C&&(e.preventDefault(),pe(e)),re&&(e.preventDefault(),me(e))}function he(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,he),S=!1}function T(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,he),S=!0,fe(e)}a.addEventListener(`mousedown`,T);function ge(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,ge),C=!1}function _e(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,ge),C=!0,pe(e)}f.addEventListener(`mousedown`,_e);function E(){document.removeEventListener(`mousemove`,w),document.removeEventListener(`mouseup`,E),re=!1}function ve(e){document.addEventListener(`mousemove`,w),document.addEventListener(`mouseup`,E),re=!0,me(e)}return c.addEventListener(`mousedown`,ve),ue(),r}let ue=8e3;function de({child:e,target:t=document.body,beforeClose:n=()=>{}}={}){let r=l(`dialog`),i=t,a=document.createElement(`div`);a.classList.add(r.b()),a.style.zIndex=String(ue);let o=document.createElement(`div`);if(o.classList.add(r.be(`overlay`)),a.appendChild(o),e){let t=document.createElement(`div`);t.classList.add(r.be(`content`)),t.appendChild(e),o.appendChild(t),t.addEventListener(`click`,e=>{e.stopPropagation()})}let s=getComputedStyle(i).overflow;i.style.overflow=`hidden`,i.appendChild(a);let c=()=>{n(),a.remove(),i.style.overflow=s};return a.addEventListener(`click`,c),ue+=1,{dialog:a,close:c}}async function fe({message:e,confirm:t,cancel:n}){return new Promise(r=>{let i=document.createElement(`div`);Object.assign(i.style,{padding:`8px 12px`,fontSize:`14px`,lineHeight:`1.5`});let a=document.createElement(`p`);a.textContent=e;let o=document.createElement(`div`);Object.assign(o.style,{display:`flex`,justifyContent:`flex-end`,gap:`6px`});let s=ce({content:n}),c=ce({type:`confirm`,content:t});o.appendChild(s),o.appendChild(c),i.appendChild(a),i.appendChild(o);let{close:l}=de({child:i});s.addEventListener(`click`,()=>{r(!1),l()}),c.addEventListener(`click`,()=>{r(!0),l()})})}function pe(e,t){let n=l(`input`);t.type||=`text`,t.value||=``;let r=document.createElement(`div`);if(r.classList.add(n.be(`item`)),e){let t=document.createElement(`span`);t.classList.add(n.be(`label`)),t.textContent=e,r.appendChild(t)}let i=document.createElement(`div`);i.classList.add(n.be(`input`));let a=document.createElement(`input`);for(let e in t)a.setAttribute(e,t[e]);return(t.max||t.min)&&a.addEventListener(`blur`,()=>{t.max&&t.max<=Number(a.value)&&(a.value=String(t.max)),t.min&&t.min>=Number(a.value)&&(a.value=String(t.min))}),i.appendChild(a),r.appendChild(i),a.addEventListener(`focus`,()=>{i.classList.add(`focus`)}),a.addEventListener(`blur`,()=>{i.classList.remove(`focus`)}),{item:r,input:a,errorTip:e=>{let t;return i.classList.contains(`error`)?t=i.querySelector(`.${n.be(`error-tip`)}`):(t=document.createElement(`span`),t.classList.add(n.be(`error-tip`)),i.appendChild(t)),t.textContent=e,i.classList.add(`error`),{removeError:()=>{i.classList.remove(`error`),t.remove()}}}}}async function me(e={}){let t=l(`creator`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`input`));let{item:i,input:a,errorTip:o}=pe(e.rowText||`Row`,{type:`number`,value:String(e.row||``),max:99}),{item:s,input:c,errorTip:u}=pe(e.colText||`Column`,{type:`number`,value:String(e.col||``),max:99});r.appendChild(i),r.appendChild(s),n.appendChild(r);let d=document.createElement(`div`);d.classList.add(t.be(`control`));let f=ce({type:`confirm`,content:e.confirmText||`Confirm`}),p=ce({type:`default`,content:e.cancelText||`Cancel`});d.appendChild(f),d.appendChild(p),n.appendChild(d);let m=(t=Number(a.value),n=Number(c.value))=>{if(Number.isNaN(t)||t<=0){o(e.notPositiveNumberError||`Please enter a positive integer`);return}if(Number.isNaN(n)||n<=0){u(e.notPositiveNumberError||`Please enter a positive integer`);return}return{row:t,col:n}},h=e=>{e.key===`Escape`&&(close(),document.removeEventListener(`keydown`,h))};return new Promise((e,t)=>{let{close:r}=de({child:n,beforeClose:t});a.focus();for(let t of[a,c])t.addEventListener(`keydown`,t=>{if(t.key===`Enter`){let t=m();t&&(e(t),r())}});f.addEventListener(`click`,()=>{let t=m();t&&(e(t),r())}),document.addEventListener(`keydown`,h),p.addEventListener(`click`,r)}).finally(()=>{document.removeEventListener(`keydown`,h)})}function w(e={}){let t=l(`select-box`),n=document.createElement(`div`);n.classList.add(t.b());let r=document.createElement(`div`);r.classList.add(t.be(`block`));for(let n=0;n<(e.row||8);n++)for(let i=0;i<(e.col||8);i++){let e=document.createElement(`div`);e.classList.add(t.be(`item`)),e.dataset.row=String(n+1),e.dataset.col=String(i+1),r.appendChild(e)}let i=()=>{let{row:e,col:t}=n.dataset;for(let e of Array.from(r.querySelectorAll(`.active`)))e.classList.remove(`active`);if(!e||!t)return;let i=Array.from(r.children);for(let n of i){let{row:r,col:i}=n.dataset;if(r>e&&i>t)return;n.classList.toggle(`active`,r<=e&&i<=t)}};if(r.addEventListener(`mousemove`,e=>{if(!e.target)return;let{row:t,col:r}=e.target.dataset;!t||!r||(n.dataset.row=t,n.dataset.col=r,i())}),r.addEventListener(`mouseleave`,()=>{n.removeAttribute(`data-row`),n.removeAttribute(`data-col`),i()}),r.addEventListener(`click`,()=>{let{row:t,col:r}=n.dataset;!t||!r||e.onSelect?.(Number(t),Number(r))}),n.appendChild(r),e.customBtn){let r=e.texts||{},i=document.createElement(`div`);i.classList.add(t.be(`custom`)),i.textContent=r.customBtnText||`Custom`,i.addEventListener(`click`,async()=>{let t=await me(r);t&&e.onSelect?.(t.row,t.col)}),n.appendChild(i)}return n}const he=Math.min,T=Math.max,ge=Math.round,_e=Math.floor,E=e=>({x:e,y:e}),ve={left:`right`,right:`left`,bottom:`top`,top:`bottom`},ye={start:`end`,end:`start`};function be(e,t,n){return T(e,he(t,n))}function xe(e,t){return typeof e==`function`?e(t):e}function D(e){return e.split(`-`)[0]}function Se(e){return e.split(`-`)[1]}function Ce(e){return e===`x`?`y`:`x`}function we(e){return e===`y`?`height`:`width`}const Te=new Set([`top`,`bottom`]);function O(e){return Te.has(D(e))?`y`:`x`}function Ee(e){return Ce(O(e))}function De(e,t,n){n===void 0&&(n=!1);let r=Se(e),i=Ee(e),a=we(i),o=i===`x`?r===(n?`end`:`start`)?`right`:`left`:r===`start`?`bottom`:`top`;return t.reference[a]>t.floating[a]&&(o=Ie(o)),[o,Ie(o)]}function Oe(e){let t=Ie(e);return[ke(e),t,ke(t)]}function ke(e){return e.replace(/start|end/g,e=>ye[e])}const Ae=[`left`,`right`],je=[`right`,`left`],Me=[`top`,`bottom`],Ne=[`bottom`,`top`];function Pe(e,t,n){switch(e){case`top`:case`bottom`:return n?t?je:Ae:t?Ae:je;case`left`:case`right`:return t?Me:Ne;default:return[]}}function Fe(e,t,n,r){let i=Se(e),a=Pe(D(e),n===`start`,r);return i&&(a=a.map(e=>e+`-`+i),t&&(a=a.concat(a.map(ke)))),a}function Ie(e){return e.replace(/left|right|bottom|top/g,e=>ve[e])}function Le(e){return{top:0,right:0,bottom:0,left:0,...e}}function Re(e){return typeof e==`number`?{top:e,right:e,bottom:e,left:e}:Le(e)}function ze(e){let{x:t,y:n,width:r,height:i}=e;return{width:r,height:i,top:n,left:t,right:t+r,bottom:n+i,x:t,y:n}}function Be(e,t,n){let{reference:r,floating:i}=e,a=O(t),o=Ee(t),s=we(o),c=D(t),l=a===`y`,u=r.x+r.width/2-i.width/2,d=r.y+r.height/2-i.height/2,f=r[s]/2-i[s]/2,p;switch(c){case`top`:p={x:u,y:r.y-i.height};break;case`bottom`:p={x:u,y:r.y+r.height};break;case`right`:p={x:r.x+r.width,y:d};break;case`left`:p={x:r.x-i.width,y:d};break;default:p={x:r.x,y:r.y}}switch(Se(t)){case`start`:p[o]-=f*(n&&l?-1:1);break;case`end`:p[o]+=f*(n&&l?-1:1);break}return p}const Ve=async(e,t,n)=>{let{placement:r=`bottom`,strategy:i=`absolute`,middleware:a=[],platform:o}=n,s=a.filter(Boolean),c=await(o.isRTL==null?void 0:o.isRTL(t)),l=await o.getElementRects({reference:e,floating:t,strategy:i}),{x:u,y:d}=Be(l,r,c),f=r,p={},m=0;for(let n=0;n<s.length;n++){let{name:a,fn:h}=s[n],{x:g,y:_,data:v,reset:y}=await h({x:u,y:d,initialPlacement:r,placement:f,strategy:i,middlewareData:p,rects:l,platform:o,elements:{reference:e,floating:t}});u=g??u,d=_??d,p={...p,[a]:{...p[a],...v}},y&&m<=50&&(m++,typeof y==`object`&&(y.placement&&(f=y.placement),y.rects&&(l=y.rects===!0?await o.getElementRects({reference:e,floating:t,strategy:i}):y.rects),{x:u,y:d}=Be(l,f,c)),n=-1)}return{x:u,y:d,placement:f,strategy:i,middlewareData:p}};async function He(e,t){t===void 0&&(t={});let{x:n,y:r,platform:i,rects:a,elements:o,strategy:s}=e,{boundary:c=`clippingAncestors`,rootBoundary:l=`viewport`,elementContext:u=`floating`,altBoundary:d=!1,padding:f=0}=xe(t,e),p=Re(f),m=o[d?u===`floating`?`reference`:`floating`:u],h=ze(await i.getClippingRect({element:await(i.isElement==null?void 0:i.isElement(m))??!0?m:m.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(o.floating)),boundary:c,rootBoundary:l,strategy:s})),g=u===`floating`?{x:n,y:r,width:a.floating.width,height:a.floating.height}:a.reference,_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(o.floating)),v=await(i.isElement==null?void 0:i.isElement(_))&&await(i.getScale==null?void 0:i.getScale(_))||{x:1,y:1},y=ze(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:o,rect:g,offsetParent:_,strategy:s}):g);return{top:(h.top-y.top+p.top)/v.y,bottom:(y.bottom-h.bottom+p.bottom)/v.y,left:(h.left-y.left+p.left)/v.x,right:(y.right-h.right+p.right)/v.x}}const Ue=function(e){return e===void 0&&(e={}),{name:`flip`,options:e,async fn(t){var n;let{placement:r,middlewareData:i,rects:a,initialPlacement:o,platform:s,elements:c}=t,{mainAxis:l=!0,crossAxis:u=!0,fallbackPlacements:d,fallbackStrategy:f=`bestFit`,fallbackAxisSideDirection:p=`none`,flipAlignment:m=!0,...h}=xe(e,t);if((n=i.arrow)!=null&&n.alignmentOffset)return{};let g=D(r),_=O(o),v=D(o)===o,y=await(s.isRTL==null?void 0:s.isRTL(c.floating)),b=d||(v||!m?[Ie(o)]:Oe(o)),ee=p!==`none`;!d&&ee&&b.push(...Fe(o,m,p,y));let te=[o,...b],ne=await He(t,h),x=[],S=i.flip?.overflows||[];if(l&&x.push(ne[g]),u){let e=De(r,a,y);x.push(ne[e[0]],ne[e[1]])}if(S=[...S,{placement:r,overflows:x}],!x.every(e=>e<=0)){let e=(i.flip?.index||0)+1,t=te[e];if(t&&(!(u===`alignment`&&_!==O(t))||S.every(e=>O(e.placement)===_?e.overflows[0]>0:!0)))return{data:{index:e,overflows:S},reset:{placement:t}};let n=S.filter(e=>e.overflows[0]<=0).sort((e,t)=>e.overflows[1]-t.overflows[1])[0]?.placement;if(!n)switch(f){case`bestFit`:{let e=S.filter(e=>{if(ee){let t=O(e.placement);return t===_||t===`y`}return!0}).map(e=>[e.placement,e.overflows.filter(e=>e>0).reduce((e,t)=>e+t,0)]).sort((e,t)=>e[1]-t[1])[0]?.[0];e&&(n=e);break}case`initialPlacement`:n=o;break}if(r!==n)return{reset:{placement:n}}}return{}}}},We=new Set([`left`,`top`]);async function Ge(e,t){let{placement:n,platform:r,elements:i}=e,a=await(r.isRTL==null?void 0:r.isRTL(i.floating)),o=D(n),s=Se(n),c=O(n)===`y`,l=We.has(o)?-1:1,u=a&&c?-1:1,d=xe(t,e),{mainAxis:f,crossAxis:p,alignmentAxis:m}=typeof d==`number`?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return s&&typeof m==`number`&&(p=s===`end`?m*-1:m),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const Ke=function(e){return e===void 0&&(e=0),{name:`offset`,options:e,async fn(t){var n;let{x:r,y:i,placement:a,middlewareData:o}=t,s=await Ge(t,e);return a===o.offset?.placement&&(n=o.arrow)!=null&&n.alignmentOffset?{}:{x:r+s.x,y:i+s.y,data:{...s,placement:a}}}}},qe=function(e){return e===void 0&&(e={}),{name:`shift`,options:e,async fn(t){let{x:n,y:r,placement:i}=t,{mainAxis:a=!0,crossAxis:o=!1,limiter:s={fn:e=>{let{x:t,y:n}=e;return{x:t,y:n}}},...c}=xe(e,t),l={x:n,y:r},u=await He(t,c),d=O(D(i)),f=Ce(d),p=l[f],m=l[d];if(a){let e=f===`y`?`top`:`left`,t=f===`y`?`bottom`:`right`,n=p+u[e],r=p-u[t];p=be(n,p,r)}if(o){let e=d===`y`?`top`:`left`,t=d===`y`?`bottom`:`right`,n=m+u[e],r=m-u[t];m=be(n,m,r)}let h=s.fn({...t,[f]:p,[d]:m});return{...h,data:{x:h.x-n,y:h.y-r,enabled:{[f]:a,[d]:o}}}}}},Je=function(e){return e===void 0&&(e={}),{options:e,fn(t){let{x:n,y:r,placement:i,rects:a,middlewareData:o}=t,{offset:s=0,mainAxis:c=!0,crossAxis:l=!0}=xe(e,t),u={x:n,y:r},d=O(i),f=Ce(d),p=u[f],m=u[d],h=xe(s,t),g=typeof h==`number`?{mainAxis:h,crossAxis:0}:{mainAxis:0,crossAxis:0,...h};if(c){let e=f===`y`?`height`:`width`,t=a.reference[f]-a.floating[e]+g.mainAxis,n=a.reference[f]+a.reference[e]-g.mainAxis;p<t?p=t:p>n&&(p=n)}if(l){let e=f===`y`?`width`:`height`,t=We.has(D(i)),n=a.reference[d]-a.floating[e]+(t&&o.offset?.[d]||0)+(t?0:g.crossAxis),r=a.reference[d]+a.reference[e]+(t?0:o.offset?.[d]||0)-(t?g.crossAxis:0);m<n?m=n:m>r&&(m=r)}return{[f]:p,[d]:m}}}};function Ye(){return typeof window<`u`}function Xe(e){return Ze(e)?(e.nodeName||``).toLowerCase():`#document`}function k(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function A(e){return((Ze(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function Ze(e){return Ye()?e instanceof Node||e instanceof k(e).Node:!1}function j(e){return Ye()?e instanceof Element||e instanceof k(e).Element:!1}function M(e){return Ye()?e instanceof HTMLElement||e instanceof k(e).HTMLElement:!1}function Qe(e){return!Ye()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof k(e).ShadowRoot}const $e=new Set([`inline`,`contents`]);function et(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=N(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!$e.has(i)}const tt=new Set([`table`,`td`,`th`]);function nt(e){return tt.has(Xe(e))}const rt=[`:popover-open`,`:modal`];function it(e){return rt.some(t=>{try{return e.matches(t)}catch{return!1}})}const at=[`transform`,`translate`,`scale`,`rotate`,`perspective`],ot=[`transform`,`translate`,`scale`,`rotate`,`perspective`,`filter`],st=[`paint`,`layout`,`strict`,`content`];function ct(e){let t=ut(),n=j(e)?N(e):e;return at.some(e=>n[e]?n[e]!==`none`:!1)||(n.containerType?n.containerType!==`normal`:!1)||!t&&(n.backdropFilter?n.backdropFilter!==`none`:!1)||!t&&(n.filter?n.filter!==`none`:!1)||ot.some(e=>(n.willChange||``).includes(e))||st.some(e=>(n.contain||``).includes(e))}function lt(e){let t=P(e);for(;M(t)&&!ft(t);){if(ct(t))return t;if(it(t))return null;t=P(t)}return null}function ut(){return typeof CSS>`u`||!CSS.supports?!1:CSS.supports(`-webkit-backdrop-filter`,`none`)}const dt=new Set([`html`,`body`,`#document`]);function ft(e){return dt.has(Xe(e))}function N(e){return k(e).getComputedStyle(e)}function pt(e){return j(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function P(e){if(Xe(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||Qe(e)&&e.host||A(e);return Qe(t)?t.host:t}function mt(e){let t=P(e);return ft(t)?e.ownerDocument?e.ownerDocument.body:e.body:M(t)&&et(t)?t:mt(t)}function ht(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=mt(e),i=r===e.ownerDocument?.body,a=k(r);if(i){let e=gt(a);return t.concat(a,a.visualViewport||[],et(r)?r:[],e&&n?ht(e):[])}return t.concat(r,ht(r,[],n))}function gt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function _t(e){let t=N(e),n=parseFloat(t.width)||0,r=parseFloat(t.height)||0,i=M(e),a=i?e.offsetWidth:n,o=i?e.offsetHeight:r,s=ge(n)!==a||ge(r)!==o;return s&&(n=a,r=o),{width:n,height:r,$:s}}function vt(e){return j(e)?e:e.contextElement}function yt(e){let t=vt(e);if(!M(t))return E(1);let n=t.getBoundingClientRect(),{width:r,height:i,$:a}=_t(t),o=(a?ge(n.width):n.width)/r,s=(a?ge(n.height):n.height)/i;return(!o||!Number.isFinite(o))&&(o=1),(!s||!Number.isFinite(s))&&(s=1),{x:o,y:s}}const bt=E(0);function xt(e){let t=k(e);return!ut()||!t.visualViewport?bt:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function St(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==k(e)?!1:t}function F(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);let i=e.getBoundingClientRect(),a=vt(e),o=E(1);t&&(r?j(r)&&(o=yt(r)):o=yt(e));let s=St(a,n,r)?xt(a):E(0),c=(i.left+s.x)/o.x,l=(i.top+s.y)/o.y,u=i.width/o.x,d=i.height/o.y;if(a){let e=k(a),t=r&&j(r)?k(r):r,n=e,i=gt(n);for(;i&&r&&t!==n;){let e=yt(i),t=i.getBoundingClientRect(),r=N(i),a=t.left+(i.clientLeft+parseFloat(r.paddingLeft))*e.x,o=t.top+(i.clientTop+parseFloat(r.paddingTop))*e.y;c*=e.x,l*=e.y,u*=e.x,d*=e.y,c+=a,l+=o,n=k(i),i=gt(n)}}return ze({width:u,height:d,x:c,y:l})}function Ct(e,t){let n=pt(e).scrollLeft;return t?t.left+n:F(A(e)).left+n}function wt(e,t){let n=e.getBoundingClientRect();return{x:n.left+t.scrollLeft-Ct(e,n),y:n.top+t.scrollTop}}function Tt(e){let{elements:t,rect:n,offsetParent:r,strategy:i}=e,a=i===`fixed`,o=A(r),s=t?it(t.floating):!1;if(r===o||s&&a)return n;let c={scrollLeft:0,scrollTop:0},l=E(1),u=E(0),d=M(r);if((d||!d&&!a)&&((Xe(r)!==`body`||et(o))&&(c=pt(r)),M(r))){let e=F(r);l=yt(r),u.x=e.x+r.clientLeft,u.y=e.y+r.clientTop}let f=o&&!d&&!a?wt(o,c):E(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+f.x,y:n.y*l.y-c.scrollTop*l.y+u.y+f.y}}function Et(e){return Array.from(e.getClientRects())}function Dt(e){let t=A(e),n=pt(e),r=e.ownerDocument.body,i=T(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),a=T(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight),o=-n.scrollLeft+Ct(e),s=-n.scrollTop;return N(r).direction===`rtl`&&(o+=T(t.clientWidth,r.clientWidth)-i),{width:i,height:a,x:o,y:s}}function Ot(e,t){let n=k(e),r=A(e),i=n.visualViewport,a=r.clientWidth,o=r.clientHeight,s=0,c=0;if(i){a=i.width,o=i.height;let e=ut();(!e||e&&t===`fixed`)&&(s=i.offsetLeft,c=i.offsetTop)}let l=Ct(r);if(l<=0){let e=r.ownerDocument,t=e.body,n=getComputedStyle(t),i=e.compatMode===`CSS1Compat`&&parseFloat(n.marginLeft)+parseFloat(n.marginRight)||0,o=Math.abs(r.clientWidth-t.clientWidth-i);o<=25&&(a-=o)}else l<=25&&(a+=l);return{width:a,height:o,x:s,y:c}}const kt=new Set([`absolute`,`fixed`]);function At(e,t){let n=F(e,!0,t===`fixed`),r=n.top+e.clientTop,i=n.left+e.clientLeft,a=M(e)?yt(e):E(1);return{width:e.clientWidth*a.x,height:e.clientHeight*a.y,x:i*a.x,y:r*a.y}}function jt(e,t,n){let r;if(t===`viewport`)r=Ot(e,n);else if(t===`document`)r=Dt(A(e));else if(j(t))r=At(t,n);else{let n=xt(e);r={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return ze(r)}function Mt(e,t){let n=P(e);return n===t||!j(n)||ft(n)?!1:N(n).position===`fixed`||Mt(n,t)}function Nt(e,t){let n=t.get(e);if(n)return n;let r=ht(e,[],!1).filter(e=>j(e)&&Xe(e)!==`body`),i=null,a=N(e).position===`fixed`,o=a?P(e):e;for(;j(o)&&!ft(o);){let t=N(o),n=ct(o);!n&&t.position===`fixed`&&(i=null),(a?!n&&!i:!n&&t.position===`static`&&i&&kt.has(i.position)||et(o)&&!n&&Mt(e,o))?r=r.filter(e=>e!==o):i=t,o=P(o)}return t.set(e,r),r}function Pt(e){let{element:t,boundary:n,rootBoundary:r,strategy:i}=e,a=[...n===`clippingAncestors`?it(t)?[]:Nt(t,this._c):[].concat(n),r],o=a[0],s=a.reduce((e,n)=>{let r=jt(t,n,i);return e.top=T(r.top,e.top),e.right=he(r.right,e.right),e.bottom=he(r.bottom,e.bottom),e.left=T(r.left,e.left),e},jt(t,o,i));return{width:s.right-s.left,height:s.bottom-s.top,x:s.left,y:s.top}}function Ft(e){let{width:t,height:n}=_t(e);return{width:t,height:n}}function It(e,t,n){let r=M(t),i=A(t),a=n===`fixed`,o=F(e,!0,a,t),s={scrollLeft:0,scrollTop:0},c=E(0);function l(){c.x=Ct(i)}if(r||!r&&!a)if((Xe(t)!==`body`||et(i))&&(s=pt(t)),r){let e=F(t,!0,a,t);c.x=e.x+t.clientLeft,c.y=e.y+t.clientTop}else i&&l();a&&!r&&i&&l();let u=i&&!r&&!a?wt(i,s):E(0);return{x:o.left+s.scrollLeft-c.x-u.x,y:o.top+s.scrollTop-c.y-u.y,width:o.width,height:o.height}}function Lt(e){return N(e).position===`static`}function Rt(e,t){if(!M(e)||N(e).position===`fixed`)return null;if(t)return t(e);let n=e.offsetParent;return A(e)===n&&(n=n.ownerDocument.body),n}function zt(e,t){let n=k(e);if(it(e))return n;if(!M(e)){let t=P(e);for(;t&&!ft(t);){if(j(t)&&!Lt(t))return t;t=P(t)}return n}let r=Rt(e,t);for(;r&&nt(r)&&Lt(r);)r=Rt(r,t);return r&&ft(r)&&Lt(r)&&!ct(r)?n:r||lt(e)||n}const Bt=async function(e){let t=this.getOffsetParent||zt,n=this.getDimensions,r=await n(e.floating);return{reference:It(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Vt(e){return N(e).direction===`rtl`}const Ht={convertOffsetParentRelativeRectToViewportRelativeRect:Tt,getDocumentElement:A,getClippingRect:Pt,getOffsetParent:zt,getElementRects:Bt,getClientRects:Et,getDimensions:Ft,getScale:yt,isElement:j,isRTL:Vt};function Ut(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Wt(e,t){let n=null,r,i=A(e);function a(){var e;clearTimeout(r),(e=n)==null||e.disconnect(),n=null}function o(s,c){s===void 0&&(s=!1),c===void 0&&(c=1),a();let l=e.getBoundingClientRect(),{left:u,top:d,width:f,height:p}=l;if(s||t(),!f||!p)return;let m=_e(d),h=_e(i.clientWidth-(u+f)),g=_e(i.clientHeight-(d+p)),_=_e(u),v={rootMargin:-m+`px `+-h+`px `+-g+`px `+-_+`px`,threshold:T(0,he(1,c))||1},y=!0;function b(t){let n=t[0].intersectionRatio;if(n!==c){if(!y)return o();n?o(!1,n):r=setTimeout(()=>{o(!1,1e-7)},1e3)}n===1&&!Ut(l,e.getBoundingClientRect())&&o(),y=!1}try{n=new IntersectionObserver(b,{...v,root:i.ownerDocument})}catch{n=new IntersectionObserver(b,v)}n.observe(e)}return o(!0),a}function Gt(e,t,n,r){r===void 0&&(r={});let{ancestorScroll:i=!0,ancestorResize:a=!0,elementResize:o=typeof ResizeObserver==`function`,layoutShift:s=typeof IntersectionObserver==`function`,animationFrame:c=!1}=r,l=vt(e),u=i||a?[...l?ht(l):[],...ht(t)]:[];u.forEach(e=>{i&&e.addEventListener(`scroll`,n,{passive:!0}),a&&e.addEventListener(`resize`,n)});let d=l&&s?Wt(l,n):null,f=-1,p=null;o&&(p=new ResizeObserver(e=>{let[r]=e;r&&r.target===l&&p&&(p.unobserve(t),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var e;(e=p)==null||e.observe(t)})),n()}),l&&!c&&p.observe(l),p.observe(t));let m,h=c?F(e):null;c&&g();function g(){let t=F(e);h&&!Ut(h,t)&&n(),h=t,m=requestAnimationFrame(g)}return n(),()=>{var e;u.forEach(e=>{i&&e.removeEventListener(`scroll`,n),a&&e.removeEventListener(`resize`,n)}),d?.(),(e=p)==null||e.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const Kt=Ke,qt=qe,Jt=Ue,Yt=Je,Xt=(e,t,n)=>{let r=new Map,i={platform:Ht,...n},a={...i.platform,_c:r};return Ve(e,t,{...i,platform:a})};function Zt(e,t,n,r,i){return i&&clearTimeout(i),e.addEventListener(`transitionend`,n,r),setTimeout(()=>{n()},t)}function Qt(e,t={}){let{msg:n=``,delay:r=150,content:i,direction:a=`bottom`,type:o=`hover`,container:s,onOpen:c,onClose:u,closed:d,onDestroy:f}=t,p=l(`tooltip`);if(n||i){let t=s||document.body,l=document.createElement(`div`);l.classList.add(p.b(),`hidden`,`transparent`),i?l.appendChild(i):n&&(l.textContent=n);let m,h,g,_=()=>{g&&g(),Xt(e,l,{placement:a,middleware:[Jt(),qt({limiter:Yt()}),Kt(4)]}).then(({x:e,y:t})=>{Object.assign(l.style,{left:`${e}px`,top:`${t}px`})})},v=()=>{l.classList.add(`hidden`),t.contains(l)&&t.removeChild(l),g&&g(),d&&d()},y=(n=!1)=>{h&&clearTimeout(h),m=setTimeout(()=>{if(c){let e=c(n);if(!n&&e)return}t.appendChild(l),l.removeEventListener(`transitionend`,v),l.classList.remove(`hidden`),g=Gt(e,l,_),l.classList.remove(`transparent`)},r)},b=(e=!1)=>{m&&clearTimeout(m),h=setTimeout(()=>{if(u){let t=u(e);if(!e&&t)return}Zt(l,150,v,{once:!0}),l.classList.add(`transparent`)},r)},{prepare:ee,show:te,hide:ne,destroy:x}={hover:()=>{let t=[e,l],n=b.bind(void 0,!1),r=y.bind(void 0,!1);return{prepare:()=>{for(let e of t)e.addEventListener(`mouseenter`,r),e.addEventListener(`mouseleave`,n)},show:y,hide:b,destroy:()=>{for(let e of t)e.removeEventListener(`mouseenter`,r),e.removeEventListener(`mouseleave`,n)}}},click:()=>{let t=e=>{e.stopPropagation(),b(!1)},n=e=>{e.stopPropagation(),y(),document.removeEventListener(`click`,t),document.addEventListener(`click`,t,{once:!0})};return{prepare:()=>{l.addEventListener(`click`,e=>e.stopPropagation()),e.addEventListener(`click`,n)},show:y,hide:(e=!1)=>{b(e),document.removeEventListener(`click`,t)},destroy:()=>{e.removeEventListener(`click`,n),document.removeEventListener(`click`,t)}}}}[o]();return ee(),{show:te,hide:ne,destroy:()=>{ne(!0),f&&f(),x(),g&&g(),l.remove()}}}return null}function $t(e,t={}){let{axis:n=`both`,onMove:r=()=>{},onStart:i=()=>{},onEnd:a=()=>{},buttons:o=[0],container:s,draggingElement:c=document,exact:l=!0}=t,u={x:0,y:0},d,f={x:0,y:0};function p(t){if(!d)return;let r=e.getBoundingClientRect(),{x:i,y:a}=u;(n===`x`||n===`both`)&&(i=t.clientX-d.x,s&&(i=Math.min(Math.max(0,i),s.scrollWidth-r.width))),(n===`y`||n===`both`)&&(a=t.clientY-d.y,s&&(a=Math.min(Math.max(0,a),s.scrollHeight-r.height))),u={x:i,y:a}}function m(t){if(!o.includes(t.button)||l&&t.target!==e)return;c.addEventListener(`pointerup`,g),c.addEventListener(`pointermove`,h);let n=s?.getBoundingClientRect?.(),r=e.getBoundingClientRect(),a={x:t.clientX-(s?r.left-n.left+s.scrollLeft:r.left),y:t.clientY-(s?r.top-n.top+s.scrollTop:r.top)};f={x:t.clientX,y:t.clientY},i({position:u,startPosition:a,movePosition:{x:t.clientX-f.x,y:t.clientY-f.y}},t)!==!1&&(d=a,u=a)}function h(e){d&&(p(e),r({position:u,startPosition:d,movePosition:{x:e.clientX-f.x,y:e.clientY-f.y}},e))}function g(e){c.removeEventListener(`pointermove`,h),c.removeEventListener(`pointerup`,g),p(e),a({position:u,startPosition:d,movePosition:{x:e.clientX-f.x,y:e.clientY-f.y}},e),d=void 0,f={x:0,y:0},u={x:0,y:0}}return c.addEventListener(`pointerdown`,m),{stop:()=>{c.removeEventListener(`pointerdown`,m)}}}function en(e,t,n=0,r=!0){let{x:i,y:a,x1:o,y1:s}=e,{x:c,y:l,x1:u,y1:d}=t,f,p;return r?(f=o<c+n||i-n>u,p=s<l+n||a-n>d):(f=o<=c+n||i-n>=u,p=s<=l+n||a-n>=d),!(f||p)}function tn(e,t){let n=t.getBoundingClientRect();return{x:e.x-n.x-t.scrollLeft,y:e.y-n.y-t.scrollTop,x1:e.x-n.x-t.scrollLeft+e.width,y1:e.y-n.y-t.scrollTop+e.height,width:e.width,height:e.height}}function nn(e){let{left:t,top:n,width:r,height:i}=e,{clientWidth:a,clientHeight:o}=document.documentElement,s=!1,c=!1;return t+r>a?(t=a-r-8,s=!0):t<0&&(t=8,s=!0),n+i>o?(n=o-i-8,c=!0):n<0&&(n=8,c=!0),{left:t,top:n,leftLimited:s,topLimited:c}}function rn(e,t={}){let n=Symbol(`ignoreFirstBind`),r=new Set,i=new ResizeObserver(r=>{t.ignoreFirstBind&&r.some(e=>{let t=e.target,r=t[n];return t[n]=!0,!r})||e(r)}),a=i.observe.bind(i);i.observe=(e,t)=>{r.add(e),a(e,t)};let o=i.unobserve;i.unobserve=e=>{r.has(e)&&(r.delete(e),e[n]=void 0),o.call(i,e)};let s=i.disconnect;return i.disconnect=()=>{for(let e of r.values())e[n]=void 0;s.call(i)},i}function I(e,t){e.addEventListener(`scroll`,t),this.scrollHandler.push([e,t])}function an(e,t){for(let n=0;n<this.scrollHandler.length;n++){let[r,i]=this.scrollHandler[n];if(r===e&&i===t){this.scrollHandler.splice(n,1);break}}}function L(){for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.scrollHandler=[]}function on(e){return{y:e.scrollTop,x:e.scrollLeft}}function sn({target:e=document.body}={}){let t=document.createElement(`div`);Object.assign(t.style,{visibility:`hidden`,width:`100px`,height:`100%`,overflow:`auto`,position:`absolute`,top:`-9999px`}),e.appendChild(t);let n=t.offsetWidth;t.style.overflow=`scroll`;let r=document.createElement(`div`);r.style.width=`100%`,t.appendChild(r);let i=r.offsetWidth;return t.parentNode?.removeChild(t),n-i}var cn=class{mouseY=0;mouseX=0;animationId=null;constructor(e=50,t=20,n=20){this.scrollThresholdX=e,this.scrollThresholdY=t,this.maxScrollSpeed=n}checkMinY(e){return this.mouseY<e.top+this.scrollThresholdY}checkMaxY(e){return this.mouseY>e.bottom-this.scrollThresholdY}checkMinX(e){return this.mouseX<e.left+this.scrollThresholdX}checkMaxX(e){return this.mouseX>e.right-this.scrollThresholdX}start(e,t){let n=e.getBoundingClientRect(),r=()=>{let i=!1,a=0,o=0;if(this.checkMinY(n)){let t=n.top+this.scrollThresholdY-this.mouseY,r=Math.min(t/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollTop-=r,o=-1*r,i=!0}else if(this.checkMaxY(n)){let t=this.mouseY-(n.bottom-this.scrollThresholdY),r=Math.min(t/this.scrollThresholdY*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollTop+=r,o=r,i=!0}if(this.checkMinX(n)){let t=n.left+this.scrollThresholdX-this.mouseX,r=Math.min(t/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollLeft-=r,a=-1*r,i=!0}else if(this.checkMaxX(n)){let t=this.mouseX-(n.right-this.scrollThresholdX),r=Math.min(t/this.scrollThresholdX*this.maxScrollSpeed,this.maxScrollSpeed);e.scrollLeft+=r,a=r,i=!0}i&&t&&t(a,o),this.animationId=requestAnimationFrame(r)};this.animationId=requestAnimationFrame(r)}updateMousePosition(e,t){this.mouseX=e,this.mouseY=t}stop(){this.animationId!==null&&(cancelAnimationFrame(this.animationId),this.animationId=null)}};function ln(e){return e.replaceAll(/([A-Z])/g,` $1`).trim().split(` `).join(`-`).toLowerCase()}function un(e){return e.replaceAll(/-(\w)/g,(e,t)=>t.toUpperCase())}function dn(e){let t={};if(!e.style.cssText)return t;let n=e.style.cssText.split(`;`).filter(e=>e.trim());for(let e of n){let n=e.indexOf(`:`);if(n===-1)continue;let r=e.slice(0,n).trim();t[r]=e.slice(n+1).trim()}return t}function fn(e){let t={},n=e.trim().split(`;`);for(let e of n){let n=e.trim();if(!n)continue;let r=n.indexOf(`:`);if(r===-1)continue;let i=n.slice(0,Math.max(0,r)).trim(),a=n.slice(Math.max(0,r+1)).trim();t[un(i)]=a}return t}function pn(e){return Object.entries(e).map(([e,t])=>`${ln(e)}: ${t};`).join(` `)}const R=()=>Math.random().toString(36).slice(2);function mn(e,t){let n;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{e.apply(this,r)},t)}}const hn=e.import(`parchment`),gn=e.import(`blots/container`),_n=e.import(`blots/block`),vn=e.import(`blots/block/embed`);var z=class e extends gn{static tagName;static blotName=t.container;static scope=hn.Scope.BLOCK_BLOT;static allowedChildren=[_n,vn,gn];static requiredContainer;static defaultChild;static allowAttrs=new Set([]);static allowDataAttrs=new Set([]);static allowDataAttrsChangeHandler={};static create(e){let t=document.createElement(this.tagName);return this.className&&t.classList.add(this.className),t}setFormatValue(e,t){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let n=e;this.statics.allowDataAttrs.has(e)&&(n=`data-${e}`),t?this.domNode.setAttribute(n,t):this.domNode.removeAttribute(n);let r=this.statics.allowDataAttrsChangeHandler[e];r&&x(this[r])&&this[r](t)}}optimize(e){if(this.children.length===0)if(this.statics.defaultChild!=null){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}else this.remove();this.children.length>0&&this.next!=null&&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===hn.Scope.BLOCK_BLOT?(t.parent instanceof e?(t.next!=null&&t.parent.splitAfter(t),t.prev!=null&&t.parent.splitAfter(t.prev)):(t.next!=null&&this.splitAfter(t),t.prev!=null&&this.splitAfter(t.prev)),t.parent.unwrap()):t instanceof hn.ParentBlot?t.unwrap():t.remove())})}};const B=e=>oe(e)?e:1;function yn(e,t){return Object.keys(e).every(n=>JSON.stringify(e[n])===JSON.stringify(t[n]))}const bn=e.import(`parchment`),xn=e.import(`blots/block`),Sn=e.import(`blots/block/embed`),Cn=e.import(`blots/container`);var wn=class extends xn{replaceWith(e,n){let r=C(e)?this.scroll.create(e,n):e;if(r instanceof bn.ParentBlot)if(r.statics.blotName===t.tableCellInner){let e=null;try{if(e=u(this,t.tableCellInner),yn(e.formats(),r.formats()))return e}catch{}if(e)e.insertBefore(r,this),r.appendChild(this),e.children.length===0&&e.remove();else{let e=this,t=e;for(;e.parent!==this.scroll&&e.parent instanceof Cn;)t=e,e=e.parent;e===this.scroll&&(e=t);let n=this.offset(e),i=this.length(),a=e.isolate(n,i);a?.parent&&a.parent.insertBefore(r,a.next),r.appendChild(this)}return r}else this.moveChildren(r);return this.parent!==null&&(this.parent.insertBefore(r,this.next),this.remove()),this.attributes.copy(r),r}format(e,n){if(e===t.tableCellInner&&this.parent.statics.blotName===e&&!n){if(this.prev&&this.prev instanceof Sn)return;try{u(this,t.tableCellInner).unwrap()}catch{console.error(`unwrap TableCellInner error`)}}else super.format(e,n)}};const Tn=e.import(`blots/block/embed`);var En=class extends Tn{delta(){let e=super.delta(),n=Dn(this);return n[t.tableCellInner]&&e.insert(`
2
+ `,{[t.tableCellInner]:n[t.tableCellInner]}),e}length(){return Dn(this)[t.tableCellInner]?super.length()+1:super.length()}formatAt(e,n,r,i){if(r===t.tableCellInner)try{let e=u(this,t.tableCellInner),n=this.scroll.create(t.tableCellInner,i);e.insertBefore(n,this),n.appendChild(this),e.length()===0&&e.remove()}catch{}else this.format(r,i)}};function Dn(e,t={},n=!0){return e==null||(`formats`in e&&typeof e.formats==`function`&&(t={...t,...e.formats()},n&&delete t[`code-token`]),e.parent==null||e.parent.statics.blotName===`scroll`||e.parent.statics.scope!==e.statics.scope)?t:Dn(e.parent,t,n)}var V=class extends z{static blotName=t.tableBody;static tagName=`tbody`;static create(e){let t=super.create();return t.dataset.tableId=e,t}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent;if(n!==null&&n.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}super.optimize(e)}convertBody(e){let t=this.descendants(H);for(let n of t)n.wrapTag=e}getRows(){return Array.from(this.domNode.querySelectorAll(`tr`)).map(e=>this.scroll.find(e)).filter(Boolean)}};const On=e.import(`blots/block`),kn=e.import(`blots/block/embed`);var H=class extends z{static blotName=t.tableCellInner;static tagName=`div`;static className=`ql-table-cell-inner`;static allowDataAttrs=new Set([`table-id`,`row-id`,`col-id`,`rowspan`,`colspan`,`empty-row`,`wrap-tag`]);static defaultChild=On;static allowStyle=new Set([`background-color`,`border`,`height`]);static isAllowStyle(e){let t=un(e);for(let e of this.allowStyle)if(t.startsWith(un(e)))return!0;return!1}static create(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e,u=super.create();u.dataset.tableId=t,u.dataset.rowId=n,u.dataset.colId=r,u.dataset.rowspan=String(B(i)),u.dataset.colspan=String(B(a)),u.dataset.tag=c,u.dataset.wrapTag=l,o&&(u.dataset.style=o);try{s&&(u.dataset.emptyRow=JSON.stringify(s))}catch{}return u}static formats(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e.dataset,u={tableId:String(t),rowId:String(n),colId:String(r),rowspan:Number(B(i)),colspan:Number(B(a)),tag:c,wrapTag:l};o&&(u.style=o);try{s&&(u.emptyRow=JSON.parse(s))}catch{}return u}constructor(e,t,n){super(e,t),t.setAttribute(`contenteditable`,String(e.isEnabled()))}setFormatValue(e,n,r=!1){if(r){if(!this.statics.isAllowStyle(e))return}else super.setFormatValue(e,n);this.parent&&this.parent.statics.blotName===t.tableCell&&this.parent.setFormatValue(e,n),this.clearCache()}clearCache(){let e=this.descendants(On,0);for(let t of e)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(e){this.setFormatValue(`row-id`,e)}get colId(){return this.domNode.dataset.colId}set colId(e){this.setFormatValue(`col-id`,e)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(e){this.setFormatValue(`rowspan`,e)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(e){this.setFormatValue(`colspan`,e)}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}set emptyRow(e){if(this.emptyRow.toString()!==e.toString())try{e.length>0?this.setFormatValue(`empty-row`,JSON.stringify(e),!1):this.setFormatValue(`empty-row`,null,!1)}catch{this.setFormatValue(`empty-row`,null,!1)}}set wrapTag(e){this.setFormatValue(`wrap-tag`,e)}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getRowIndex(){return u(this,t.tableMain).getRowIds().indexOf(this.rowId)}getTableBody(){let e=this.parent;for(;e&&!(e instanceof V)&&e!==this.scroll;)e=e.parent;return e===this.scroll?null:e}getTableRow(){try{return u(this,t.tableRow)}catch{return null}}setStyleByString(e){let t=fn(e);for(let[e,n]of Object.entries(t))this.setFormatValue(e,n,!0)}convertTableCell(){this.parent.statics.blotName===t.tableCell&&(this.parent.convertTableCell(),this.clearCache())}formatAt(e,t,n,r){if(this.children.length===0){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e),t+=e.length()}super.formatAt(e,t,n,r),r?.style&&this.setStyleByString(r.style)}insertAt(e,t,n){let[r]=this.children.find(e);if(!r&&this.statics.defaultChild){let e=this.scroll.create(this.statics.defaultChild.blotName||`block`);this.appendChild(e)}super.insertAt(e,t,n),(n==null?this.scroll.create(`text`,t):this.scroll.create(t,n))instanceof kn&&r&&r.length()<=1&&r.remove()}formats(){let e=this.statics.formats(this.domNode);return{[this.statics.blotName]:e}}checkMerge(){let{colId:e,rowId:t,colspan:n,rowspan:r}=this,i=this.next;return i!==null&&i.statics.blotName===this.statics.blotName&&i.rowId===t&&i.colId===e&&i.colspan===n&&i.rowspan===r}optimize(){let e=this.parent,n=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof kn){let e=this.prev;if(this.insertBefore(e,this.children.head),this.length()<=1){let t=this.scroll.create(`block`);this.insertBefore(t,e.next)}}let r=e!==null&&e.statics.blotName!==t.tableCell;if(r&&(this.wrap(t.tableCell,n),this.children.length===0)){let e=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(e)}this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),this.uiNode!=null&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),this.children.length===0?this.remove():this.domNode.dataset.style&&r&&e.domNode.style.cssText!==this.domNode.dataset.style&&this.setStyleByString(this.domNode.dataset.style)}insertBefore(e,n){if(e.statics.blotName===this.statics.blotName){let r=e,i=this.statics.formats(r.domNode),a=this.statics.formats(this.domNode);if(yn(a,i)){let e=this.split(n?n.offset():0);return this.parent.insertBefore(r,e)}else{let[e,o]=d(this,[t.tableRow,t.tableCell]),s=o;if(n){let r=n.offset(),i=this.length();if(r!==0&&r<i){let n=this.split(r).wrap(t.tableCell,a);e.insertBefore(n,o.next),s=n}}if(this.tableId!==r.tableId){let e=u(this,t.tableWrapper),n=this.offset(e),i=e.split(n);return e.parent.insertBefore(r,i)}if(this.rowId!==r.rowId){let a=e,o=n;if(o){let t=o.offset(e);a=e.split(t)}let s=this.scroll.create(t.tableRow,i),c=this.scroll.create(t.tableCell,i);return c.appendChild(r),s.appendChild(c),e.parent.insertBefore(s,a)}return e.insertBefore(r.wrap(t.tableCell,i),s)}}else if(e.statics.blotName===t.tableCol){try{let n=u(this,t.tableBody),r=this.offset(n),i=n.split(r);n.parent.insertBefore(e,i),e.optimize({})}catch{console.warn(`TableCellInner not in TableBody`)}return}super.insertBefore(e,n)}};const An=e.import(`parchment`),jn=e.import(`blots/scroll`);var Mn=class extends jn{enable(n=!0){let r=e.import(`formats/${t.tableCellInner}`),i=this.domNode.querySelectorAll(`.${r.className}`);for(let e of Array.from(i))e.setAttribute(`contenteditable`,String(!!n));let a=e.import(`formats/${t.tableCaption}`),o=this.domNode.querySelectorAll(`.${a.className}`);for(let e of Array.from(o))e.setAttribute(`contenteditable`,String(!!n));super.enable(n)}createBlock(e,n){let r,i={};if(e[t.tableCellInner])r=t.tableCellInner;else for(let[t,n]of Object.entries(e))this.query(t,An.Scope.BLOCK&An.Scope.BLOT)==null?i[t]=n:r=t;r===t.tableCellInner&&(i={...e},delete i[r]);let a=this.create(r||this.statics.defaultChild.blotName,r?e[r]:void 0);this.insertBefore(a,n||void 0);let o=a.length();a instanceof H&&o===0&&(o+=1);for(let[e,t]of Object.entries(i))a.formatAt(0,o,e,t);return a}},Nn=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
3
+ <!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE -->
4
+ <path
5
+ fill="none"
6
+ stroke="currentColor"
7
+ stroke-linecap="round"
8
+ stroke-linejoin="round"
9
+ stroke-width="2"
10
+ d="M7 3v18m3-15L7 3L4 6m16 12l-3 3l-3-3m3 3V3"
11
+ />
12
+ </svg>
13
+ `;const Pn=e.import(`parchment`),Fn=e.import(`blots/inline`),In=e.import(`blots/text`);var Ln=class extends wn{static blotName=t.tableCaption;static tagName=`caption`;static className=`ql-table-caption`;static allowedChildren=[Fn,In];static create(e){let{tableId:t}=e,n=super.create();return n.dataset.tableId=t,e.side===`bottom`&&(n.style.captionSide=`bottom`),n}static formats(e){let{tableId:t}=e.dataset;return{tableId:String(t),side:e.style.captionSide===`bottom`?`bottom`:`top`}}constructor(e,t,n){super(e,t),t.setAttribute(`contenteditable`,String(e.isEnabled())),this.attachUI(this.createUI()),this.domNode.addEventListener(`mouseenter`,()=>{this.scroll.isEnabled()&&(this.uiNode.style.display=`flex`)}),this.domNode.addEventListener(`mouseleave`,()=>{this.scroll.isEnabled()&&(this.uiNode.style.display=`none`)}),this.uiNode.style.display=`none`}createUI(){let e=document.createElement(`i`);return e.classList.add(`ql-table-caption--switch`),e.innerHTML=Nn,e.addEventListener(`click`,()=>{this.scroll.isEnabled()&&(this.side=this.side===`top`?`bottom`:`top`)}),e}get tableId(){return this.domNode.dataset.tableId}set side(e){this.domNode.style.captionSide=e===`bottom`?`bottom`:`top`}get side(){return this.domNode.style.captionSide===`bottom`?`bottom`:`top`}format(e,t){(!this.scroll.query(e,Pn.Scope.BLOCK_BLOT)||e===this.statics.blotName)&&super.format(e,t)}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent;if(n!==null&&n.statics.blotName!==t.tableMain){let{tableId:e}=this;this.wrap(t.tableMain,{tableId:e})}this.children.length===0?this.remove():(super.optimize(e),this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()))}},U=class e extends z{static blotName=t.tableRow;static tagName=`tr`;static className=`ql-table-row`;static allowDataAttrs=new Set([`table-id`,`row-id`,`wrap-tag`]);static allowDataAttrsChangeHandler={"wrap-tag":`wrapParentTag`};static create(e){let{tableId:t,rowId:n,wrapTag:r=`tbody`}=e,i=super.create();return i.dataset.tableId=t,i.dataset.rowId=n,i.dataset.wrapTag=r,i}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}setHeight(e){this.foreachCellInner(t=>{t.setFormatValue(`height`,e,!0)})}getCellByColId(e,n){let r=u(this,t.tableMain).getColIds(),i=r.indexOf(e),a=this.children.iterator(),o=null;for(;o=a();){if(o.colId===e)return o;let t=r.indexOf(o.colId);if(t<i&&t+o.colspan>i)return o}return this[n]&&this[n].statics.blotName===t.tableRow?this[n].getCellByColId(e,n):null}insertCell(e,n){let r=[],i=this.children.iterator(),a=0,o;for(;(o=i())&&(a+=o.colspan,!(a>e));)if(o.rowspan!==1)for(let e=0;e<o.rowspan-1;e++)r[e]=(r[e]||0)+o.colspan;if(o&&a-o.colspan<e){let e=o.getCellInner();e.colspan+=1,o.rowspan!==1&&(r.skipRowNum=o.rowspan-1)}else{let e=this.scroll.create(t.tableCell,n),r=this.scroll.create(t.tableCellInner,n),i=this.scroll.create(`block`);i.appendChild(this.scroll.create(`break`)),r.appendChild(i),e.appendChild(r),this.insertBefore(e,o)}return r}getCellByColumIndex(e){let t=[],n=null,r=0;if(e<0)return[n,r,t];let i=this.children.iterator();for(;n=i();){if(r+=n.colspan,n.rowspan!==1)for(let e=0;e<n.rowspan-1;e++)t[e]=(t[e]||0)+n.colspan;if(r>e)break}return[n,r,t]}removeCell(e){if(e<0)return[];let n=this.getCellByColumIndex(e),[r,i]=n,a=n[2];if(!r)return a;if(i-r.colspan<e||r.colspan>1){let[n]=r.descendants(H);if(r.colspan!==1&&e===i-r.colspan){let e=u(this,t.tableMain).getColIds();n.colId=e[e.indexOf(n.colId)+1]}r.rowspan!==1&&(a.skipRowNum=r.rowspan-1),--n.colspan}else r.remove();return a}foreachCellInner(e){let t=this.children.iterator(),n=0,r;for(;r=t();){let[t]=r.descendants(H);if(t&&e(t,n++))break}}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.rowId===this.rowId}wrapParentTag(){let e={thead:t.tableHead,tbody:t.tableBody,tfoot:t.tableFoot},n=this.parent;if(n!==null&&n.statics.blotName!==e[this.wrapTag])if(Object.values(e).includes(n.statics.blotName)){let t=this.offset(this.parent),n=this.parent.split(t);n&&n.length()<=0&&n.remove();let r=this.parent.splitAfter(this);r&&r.length()<=0&&r.remove(),this.parent.replaceWith(e[this.wrapTag],this.tableId)}else this.wrap(e[this.wrapTag],this.tableId)}optimize(e){this.wrapParentTag(),this.enforceAllowedChildren(),this.children.length>0&&this.next!=null&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}remove(){super.remove(),this.next&&this.next instanceof e&&this.next.length()<=0&&this.next.remove()}},W=class extends z{static blotName=t.tableCell;static tagName=`td`;static className=`ql-table-cell`;static allowAttrs=new Set([`rowspan`,`colspan`]);static allowDataAttrs=new Set([`table-id`,`row-id`,`col-id`,`empty-row`,`wrap-tag`]);static allowStyle=new Set([`background-color`,`border`,`height`]);static isAllowStyle(e){let t=un(e);for(let e of this.allowStyle)if(t.startsWith(un(e)))return!0;return!1}static create(e){let{tableId:t,rowId:n,colId:r,rowspan:i,colspan:a,style:o,emptyRow:s,tag:c=`td`,wrapTag:l=`tbody`}=e,u=document.createElement(c);u.classList.add(...se(this.className)),u.dataset.tableId=t,u.dataset.rowId=n,u.dataset.colId=r,u.dataset.wrapTag=l,u.setAttribute(`rowspan`,String(B(i))),u.setAttribute(`colspan`,String(B(a))),o&&(u.style.cssText=o);try{s&&(u.dataset.emptyRow=JSON.stringify(s))}catch{}return u}static formats(e){let{tableId:t,rowId:n,colId:r,emptyRow:i,wrapTag:a=`tbody`}=e.dataset,o=Number(e.getAttribute(`rowspan`)),s=Number(e.getAttribute(`colspan`)),c={tableId:t,rowId:n,colId:r,rowspan:B(o),colspan:B(s),tag:e.tagName.toLowerCase(),wrapTag:a},l=dn(e),u=Object.entries(l).filter(([,e])=>![`initial`,`inherit`].includes(e));u.length>0&&(c.style=u.map(([e,t])=>`${e}: ${t}`).join(`;`));try{i&&(c.emptyRow=JSON.parse(i))}catch{}return c}isChildHeadTableCellInner(){let e=this.children.head;return e&&e.statics.blotName===t.tableCellInner}setFormatValue(e,n){if(this.statics.allowAttrs.has(e)||this.statics.allowDataAttrs.has(e)){let t=e;this.statics.allowDataAttrs.has(e)&&(t=`data-${e}`),n?this.domNode.setAttribute(t,n):this.domNode.removeAttribute(t)}else this.statics.isAllowStyle(e)&&(Object.assign(this.domNode.style,{[e]:n}),e.startsWith(`border`)&&this.setStyleBoder(e,n));let r=this.children.head;this.isChildHeadTableCellInner()&&this.domNode.style.cssText&&this.domNode.style.cssText!==r.domNode.dataset.style&&(r.domNode.dataset.style=this.domNode.style.cssText),this.parent&&this.parent.statics.blotName===t.tableRow&&this.parent.setFormatValue(e,n)}setStyleBoder(e,t){let n=t||null;if(!(![`left`,`right`,`top`,`bottom`].some(t=>e.includes(t))&&e.startsWith(`border-`)))return;let r=this.getNearByCell(`left`).map(e=>e.descendant(H,0)[0]).filter(Boolean);for(let t of r)t.setFormatValue(e.replace(`border-`,`border-right-`),n,!0);let i=this.getNearByCell(`top`).map(e=>e.descendant(H,0)[0]).filter(Boolean);for(let t of i)t.setFormatValue(e.replace(`border-`,`border-bottom-`),n,!0)}getNearByCell(e){let n=[];try{let e=u(this,t.tableMain);n.push(...e.getColIds())}catch(e){console.error(`Cell is not in table! ${e}`)}if(n.length===0)return[];if(e===`left`){let e=new Set,t=this.parent;for(let r=0;r<this.rowspan&&t instanceof U;r++){let r=t.children.iterator(),i=null;for(;i=r();){let t=n.indexOf(i.colId)+i.colspan;this.colId===n[t]&&e.add(i)}t=t.next}return Array.from(e)}else if(e===`top`){if(!(this.parent instanceof U)||!this.parent.prev)return[];let e=new Set,t=this.getColumnIndex(),r=t+this.colspan,i=new Set(n.filter((e,n)=>n>=t&&n<r)),a=1,o=this.parent.prev;for(;o;){let t=!1,r=o.children.iterator(),s=null,c=0;for(;s=r();)i.has(s.colId)&&s.rowspan>=a&&(e.add(s),i.delete(s.colId)),c+=s.colspan,s.rowspan>=a&&(t=!0);if(!t&&c===n.length)break;o=o.prev,a+=1}return Array.from(e)}return[]}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute(`rowspan`))}get colspan(){return Number(this.domNode.getAttribute(`colspan`))}get emptyRow(){try{return JSON.parse(this.domNode.dataset.emptyRow)}catch{return[]}}get wrapTag(){return this.domNode.dataset.wrapTag||`tbody`}getColumnIndex(){return u(this,t.tableMain).getColIds().indexOf(this.colId)}getCellInner(){return this.children.head}convertTableCell(){let e=this.statics.formats(this.domNode),n=e.tag===`td`?`th`:`td`,r=this.children.head;this.isChildHeadTableCellInner()&&r.domNode.dataset.tag!==n&&(r.domNode.dataset.tag=n),this.replaceWith(t.tableCell,{...e,tag:n})}checkMerge(){let{colId:e,rowId:t,colspan:n,rowspan:r}=this,i=this.next;return i!==null&&i.statics.blotName===this.statics.blotName&&i.rowId===t&&i.colId===e&&i.colspan===n&&i.rowspan===r}optimize(e){let{tableId:n,rowId:r,wrapTag:i}=this;if(this.parent!==null&&this.parent.statics.blotName!==t.tableRow&&this.wrap(t.tableRow,{tableId:n,rowId:r,wrapTag:i}),this.parent.statics.blotName===t.tableRow&&this.parent.wrapTag!==i&&this.parent.setFormatValue(`wrap-tag`,i),this.emptyRow.length>0){let e=this.parent.parent;if(e instanceof V){let r=this.parent.next;for(let a of this.emptyRow){let o=this.scroll.create(t.tableRow,{tableId:n,rowId:a,wrapTag:i});e.insertBefore(o,r),r=o.next}}}super.optimize(e)}};const Rn=e.import(`blots/block/embed`);var G=class extends Rn{static blotName=t.tableCol;static tagName=`col`;static validWidth(e,t){let r=Number.parseFloat(String(e));return Number.isNaN(r)&&(r=n[t?`colMinWidthPre`:`colMinWidthPx`]),`${r}${t?`%`:`px`}`}static create(e){let{width:t,tableId:n,colId:r,full:i,align:a}=e,o=super.create();return o.setAttribute(`width`,this.validWidth(t,!!i)),i&&(o.dataset.full=String(i)),a&&a!==`left`&&(o.dataset.align=a),o.dataset.tableId=n,o.dataset.colId=r,o}static value(e){let{tableId:t,colId:r}=e.dataset,i=e.getAttribute(`width`)||String(n.colDefaultWidth),a=e.dataset.align,o=Object.hasOwn(e.dataset,`full`),s={tableId:String(t),colId:String(r),full:o,width:Number.parseFloat(i)};return a&&(s.align=a),s}get width(){let e=this.domNode.getAttribute(`width`);if(!e){if(e=this.domNode.getBoundingClientRect().width,this.full){let t=this.domNode.closest(`table`);return t?e/100*t.getBoundingClientRect().width:n[this.full?`colMinWidthPre`:`colMinWidthPx`]}return e}return Number.parseFloat(String(e))}set width(e){let t=Number.parseFloat(String(e));Number.isNaN(t)&&(t=n[this.full?`colMinWidthPre`:`colMinWidthPx`]),this.domNode.setAttribute(`width`,this.statics.validWidth(t,!!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(e){e?this.domNode.dataset.full=`true`:this.domNode.removeAttribute(`data-full`)}get align(){return this.domNode.dataset.align||``}set align(e){e===`right`||e===`center`?this.domNode.dataset.align=e:this.domNode.removeAttribute(`data-align`)}checkMerge(){let e=this.next,{tableId:t,colId:n}=this;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===t&&e.colId===n}optimize(e){let n=this.parent;if(n!=null&&n.statics.blotName!==t.tableColgroup){let e=this.statics.value(this.domNode);this.wrap(t.tableColgroup,e)}let r=u(this,t.tableColgroup);r.align=this.align,this.next!=null&&this.checkMerge()&&this.next.remove(),super.optimize(e);try{let e=u(this,t.tableColgroup),n=!0;e.children.forEach(e=>{n&&=e.full}),e.full=n}catch{}}insertAt(e,n,r){if(r!=null){if(n===this.statics.blotName&&r.tableId!==this.tableId)try{let e=u(this,t.tableWrapper),i=e.split(this.offset(e)),a=this.scroll.create(n,r);i.parent.insertBefore(a,i)}catch{console.warn(`TableCol not in TableColgroup`)}else super.insertAt(e,n,r);return}try{let e=u(this,t.tableWrapper),r=e.split(this.offset(e)),i=n.split(`
14
+ `),a=i.pop(),o=i.map(e=>{let t=this.scroll.create(`block`);return t.insertAt(0,e),t});for(let e of o)r.parent.insertBefore(e,r);a&&r.parent.insertBefore(this.scroll.create(`text`,a),r)}catch{console.warn(`TableCol not in TableColgroup`)}}},K=class extends z{static blotName=t.tableMain;static tagName=`table`;static className=`ql-table`;static create(e){let t=super.create(),{tableId:n,full:r,align:i}=e;return t.dataset.tableId=n,i===`right`||i===`center`?t.dataset.align=i:t.removeAttribute(`date-align`),r&&(t.dataset.full=String(r)),t.setAttribute(`cellpadding`,`0`),t.setAttribute(`cellspacing`,`0`),t}constructor(e,t,n){super(e,t),this.scroll=e,this.updateAlign()}colWidthFillTable(){if(this.full){Object.assign(this.domNode.style,{width:null});return}let e=this.getCols();if(!e)return;let t=e.reduce((e,t)=>t.width+e,0);if(!(t===0||Number.isNaN(t)))return this.domNode.style.width=`${t}px`,t}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,`full`)}set full(e){e?this.domNode.dataset.full=`true`:this.domNode.removeAttribute(`data-full`),this.colWidthFillTable()}get align(){return this.domNode.dataset.align||``}set align(e){e===`right`||e===`center`?this.domNode.dataset.align=e:this.domNode.removeAttribute(`data-align`),this.updateAlign()}setFull(){if(this.full)return;let e=this.getCols();if(e.length===0)return;let t=Math.floor(this.domNode.getBoundingClientRect().width);for(let n of e){let e=n.width/t*100;n.full=!0,n.width=e}}cancelFull(){if(!this.full)return;let e=this.getCols();if(e.length===0)return;let t=Math.floor(this.domNode.getBoundingClientRect().width);for(let r of e)r.full=!1,r.width=Math.max(r.width/100*t,n.colMinWidthPx)}updateAlign(){let e=this.align,t={marginLeft:null,marginRight:null};switch(e){case`center`:t.marginLeft=`auto`,t.marginRight=`auto`;break;case``:case`left`:t.marginRight=`auto`;break;case`right`:t.marginLeft=`auto`;break;default:break}Object.assign(this.domNode.style,t)}getBodys(){return Array.from(this.domNode.querySelectorAll(`thead, tbody, tfoot`)).map(e=>this.scroll.find(e)).filter(Boolean)}getRows(){return Array.from(this.domNode.querySelectorAll(`tr`)).map(e=>this.scroll.find(e)).filter(Boolean)}getRowIds(){return this.getRows().map(e=>e.rowId)}getCols(){return this.descendants(G)}getColIds(){return this.getCols().map(e=>e.colId)}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.domNode.dataset.tableId===this.tableId}optimize(e){let n=this.parent;n!==null&&n.statics.blotName!==t.tableWrapper&&this.wrap(t.tableWrapper,this.tableId),super.optimize(e),this.mergeRow()}mergeRow(){if(!this.parent)return;let e=this.getRows(),t={};for(let n of e)t[n.rowId]||(t[n.rowId]=[]),t[n.rowId].push(n);for(let e of Object.values(t))for(let t=1;t<e.length;t++){let n=e[t];n.moveChildren(e[0]),n.remove()}}checkEmptyCol(e){if(e){let e=this.getRows().length,t=this.getCols(),n=this.descendants(H);for(let r of n)if(r.colspan>1&&r.rowspan>=e){let e=t.findIndex(e=>e.colId===r.colId),n=t[e];for(let i=e+1;i<e+r.colspan;i++)t[i].remove(),n.width+=t[i].width;r.colspan=1}}}checkEmptyRow(e){let n=this.getRows(),r=new Set(n.map(e=>e.rowId));for(let i=n.length-1;i>=0;i--){let a=n[i];if(e){if(a.children.length===0){for(let e=1,t=i-1;t>=0;t--,e++)n[t].foreachCellInner(t=>{if(t.rowspan>e){--t.rowspan;let e=new Set(t.emptyRow);e.delete(a.rowId),t.emptyRow=Array.from(e)}});a.remove()}}else{if(a.children.length===0&&a.prev){let e=a.prev;for(;e?.children.length===0;)e=e.prev;e.foreachCellInner(e=>{let t=new Set(e.emptyRow);t.has(a.rowId)||(e.emptyRow=[a.rowId,...t])})}a.foreachCellInner(e=>{for(let n of e.emptyRow)r.has(n)||a.parent.insertBefore(this.scroll.create(t.tableRow,{tableId:this.tableId,rowId:n}),a.next)})}}}sortMergeChildren(){let e={[t.tableCaption]:[],[t.tableColgroup]:[],[t.tableHead]:[],[t.tableBody]:[],[t.tableFoot]:[]};this.children.forEach(t=>{e[t.statics.blotName]&&e[t.statics.blotName].push(t)});for(let t of Object.values(e))for(let e=1;e<t.length;e++)t[e].moveChildren(t[0]);let n=e[t.tableCaption][0],r=e[t.tableColgroup][0],i=e[t.tableHead][0],a=e[t.tableBody][0],o=e[t.tableFoot][0],s=n&&this.children.head!==n,c=r&&n&&n.next!==r,l=r&&!n&&this.children.head!==r,u=i&&!a&&!o&&this.children.tail!==i,d=a&&i&&a.prev!==i,f=a&&!o&&this.children.tail!==a,p=a&&o&&a.next!==o,m=o&&this.children.tail!==o;if(s||c||l||u||d||f||p||m){let e=this.clone();n&&e.appendChild(n),r&&e.appendChild(r),i&&e.appendChild(i),a&&e.appendChild(a),o&&e.appendChild(o),this.children.forEach(e=>e.remove()),e.moveChildren(this)}}insertRow(e){let n=this.getColIds(),r=this.descendants(U),i=new Set(n),a=0;for(let t of r){if(a===e)break;t.foreachCellInner(t=>{if(a+t.rowspan>e&&(t.rowspan+=1,i.delete(t.colId),t.colspan!==1)){let e=n.indexOf(t.colId);for(let r=0;r<t.colspan-1;r++)i.delete(n[e+r+1])}}),a+=1}let o=this.tableId,s=R(),c=this.scroll.create(t.tableRow,{tableId:o,rowId:s});for(let e of i){let n=this.scroll.create(`break`).wrap(`block`).wrap(t.tableCellInner,{tableId:o,rowId:s,colId:e,rowspan:1,colspan:1}).wrap(t.tableCell,{tableId:o,rowId:s,colId:e,rowspan:1,colspan:1});c.appendChild(n)}let l=r[e]||null;l?l.parent.insertBefore(c,l):r[r.length-1].parent.appendChild(c)}},q=class extends z{static blotName=t.tableColgroup;static tagName=`colgroup`;static create(e){let t=super.create();return t.dataset.tableId=e.tableId,e.full&&(t.dataset.full=String(e.full)),e.align&&e.align!==`left`&&(t.dataset.align=e.align),t.setAttribute(`contenteditable`,`false`),t}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,`full`)}set full(e){e?this.domNode.dataset.full=`true`:this.domNode.removeAttribute(`data-full`),this.parent&&this.parent instanceof K&&(this.parent.full=e)}get align(){return this.domNode.dataset.align||``}set align(e){e===`right`||e===`center`?this.domNode.dataset.align=e:this.domNode.removeAttribute(`data-align`)}findCol(e){let t=this.children.iterator(),n=0,r;for(;(r=t())&&n!==e;)n++;return r}insertColByIndex(e,r){let i=this.parent;if(!(i instanceof K))throw TypeError(`TableColgroupFormat should be child of TableFormat`);let a=this.findCol(e),o=this.scroll.create(t.tableCol,r);if(i.full){let e=this.children.iterator(),t;for(;t=e();)if(t.width-o.width>=n.colMinWidthPre){t.width-=o.width;break}}this.insertBefore(o,a)}removeColByIndex(e){let t=this.parent;if(!(t instanceof K))throw TypeError(`TableColgroupFormat should be child of TableMainFormat`);let n=this.findCol(e);n&&(t.full&&(n.next?n.next.width+=n.width:n.prev&&(n.prev.width+=n.width)),n.remove(),t.colWidthFillTable())}checkMerge(){let e=this.next,t=this.parent;return t instanceof K&&!t.full&&t.colWidthFillTable(),e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){let n=this.parent,{tableId:r,full:i,align:a}=this;n!=null&&n.statics.blotName!==t.tableMain&&this.wrap(t.tableMain,{tableId:r,full:i,align:a});let o=u(this,t.tableMain);o.align=a,super.optimize(e)}},zn=class extends V{static blotName=t.tableFoot;static tagName=`tfoot`},Bn=class extends V{static blotName=t.tableHead;static tagName=`thead`};const Vn=e.import(`parchment`);var J=class extends z{static blotName=t.tableWrapper;static tagName=`div`;static className=`ql-table-wrapper`;static create(e){let t=super.create();return t.dataset.tableId=e,t.addEventListener(`dragstart`,e=>{e.preventDefault(),e.stopPropagation()},!0),t.addEventListener(`drop`,e=>{e.preventDefault()}),t.addEventListener(`dragover`,e=>{e.preventDefault(),e.dataTransfer.dropEffect=`none`}),t.setAttribute(`contenteditable`,`false`),t}constructor(t,n,r){super(t,n),this.scroll=t,this.scroll.emitter.on(e.events.TEXT_CHANGE,this.insertLineAround)}get tableId(){return this.domNode.dataset.tableId}checkMerge(){let e=this.next;return e!==null&&e.statics.blotName===this.statics.blotName&&e.tableId===this.tableId}optimize(e){if(this.length()===0){this.remove();return}super.optimize(e)}deleteAt(e,t){super.deleteAt(e,t);let n=this.descendants(V),r=this.descendants(q);n.length===0&&r.length===0&&this.remove()}remove(){super.remove(),this.scroll.emitter.off(e.events.TEXT_CHANGE,this.insertLineAround)}isBlockLine(e){return e instanceof Vn.BlockBlot||new Set([`list-container`,`code-block-container`]).has(e.statics.blotName)}insertLineAround=()=>{(!this.prev||!this.isBlockLine(this.prev))&&this.parent.insertBefore(this.scroll.create(`block`),this),(!this.next||!this.isBlockLine(this.next))&&this.parent.insertBefore(this.scroll.create(`block`),this.next)}};function Y(e){let n=new Set([t.tableHead,t.tableBody,t.tableFoot]),r=e.children.iterator(),i=null,a={};for(;i=r();)n.has(i.statics.blotName)&&(a[i.statics.blotName]=i);if(Object.values(a).length<=0)return{rect:null,head:null,body:null,foot:null};let o=Object.values(a).reduce((e,t)=>{let n=t.domNode.getBoundingClientRect();return{...e,top:Math.min(e.top,n.top),bottom:Math.max(e.bottom,n.bottom),left:Math.min(e.left,n.left),right:Math.max(e.right,n.right)}},{top:1/0,bottom:0,left:1/0,right:0,width:0,height:0,x:1/0,y:1/0});return o.width=o.right-o.left,o.height=o.bottom-o.top,o.x=o.left,o.y=o.top,{rect:o,head:a[t.tableHead]||null,body:a[t.tableBody]||null,foot:a[t.tableFoot]||null}}var Hn=class{table;constructor(e,t){this.tableModule=e,this.quill=t,this.quill.root.addEventListener(`mousedown`,this.tableSelectHandler.bind(this))}tableSelectHandler(e){let t=e.composedPath();if(e.button!==0||!t||t.length<=0)return;let n=t.find(e=>e.tagName&&e.tagName.toUpperCase()===`TABLE`);this.setSelectionTable(n)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show(),this.update())}hide(){}show(){}update(){}},Un=class extends Hn{static moduleName=`table-align`;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=l(`align`);resizeObserver;constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.alignBox=this.buildTools(),this.hide(),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};buildTools(){let t=this.tableModule.addContainer(this.bem.b()),n=e.import(`ui/icons`),r={left:n.align[``],center:n.align.center,right:n.align.right};for(let[e,n]of Object.entries(r)){let r=document.createElement(`span`);r.dataset.align=e,r.classList.add(this.bem.be(`item`)),r.innerHTML=`<i class="icon">${n}</i>`,r.addEventListener(`click`,this.handleAlignItemClick.bind(this)),t.appendChild(r)}return t}handleAlignItemClick(e){let t=e.currentTarget;if(!t)return;let n=t.dataset.align;n&&this.tableBlot&&this.setTableAlign(this.tableBlot,n)}setTableAlign(e,t){let n=e.getCols();for(let e of n)e.align=t}show(){!this.table||!this.alignBox||(this.tableBlot=e.find(this.table),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=rn(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.cleanup&&this.cleanup(),this.cleanup=Gt(this.tableWrapperBlot.domNode,this.alignBox,()=>this.update()))}hide(){this.tableBlot=void 0,this.tableWrapperBlot=void 0,this.alignBox&&this.alignBox.classList.add(this.bem.is(`hidden`)),this.cleanup&&=(this.cleanup(),void 0)}update(){if(!(!this.alignBox||!this.tableBlot||!this.tableWrapperBlot)){if(!this.table||this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth){this.hide();return}Xt(this.tableWrapperBlot.domNode,this.alignBox,{placement:`top`,middleware:[Jt(),qt({limiter:Yt()}),Kt(16)]}).then(({x:e,y:t})=>{Object.assign(this.alignBox.style,{left:`${e}px`,top:`${t}px`})})}}destroy(){this.hide(),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.alignBox&&=(this.alignBox.remove(),null)}};const Wn=e.import(`delta`);function Gn(e,t,n){let{rows:r,cols:i}=Kn(t),{rows:a,cols:o,cells:s}=qn(n);r===a&&i===o?Yn(t,s,e):Qn(e,t,s)}function Kn(e){return e.length===0?{rows:0,cols:0}:Jn(Xn(e))}function qn(e){let n=new Map;for(let r of e){let e=r.attributes;if(!e)continue;let i=e[t.tableCellInner];if(!i)continue;let a=`${i.rowId}-${i.colId}`;if(!n.has(a)){let e={rowId:i.rowId,colId:i.colId,rowspan:i.rowspan||1,colspan:i.colspan||1,deltaOps:[]};i.emptyRow&&i.emptyRow.length>0&&(e.emptyRow=i.emptyRow),n.set(a,e)}let o=n.get(a),{[t.tableCellInner]:s,...c}=e;o.deltaOps.push({insert:r.insert,attributes:{...c}})}let r=Array.from(n.values());return{...Jn(Xn(r)),cells:r}}function Jn(e){let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let a of e){let{cell:e,rowIndex:o,colIndex:s}=a,c=e.colspan||1,l=e.rowspan||1;t=Math.min(t,o),n=Math.max(n,o+l-1),r=Math.min(r,s),i=Math.max(i,s+c-1)}return{rows:Math.max(n-t+1,0),cols:Math.max(i-r+1,0)}}function Yn(e,t,n){let r=Xn(e),i=Xn(t),a=new Map;for(let e of i)a.set(`${e.rowIndex}-${e.colIndex}`,e.cell);let o=[],s=new Set;for(let e of r){let t=e.cell;if(!t.domNode.isConnected||s.has(t))continue;let r=a.get(`${e.rowIndex}-${e.colIndex}`);if(r){let e=$n(n,t,r.deltaOps,{rowspan:r.rowspan,colspan:r.colspan,emptyRow:r.emptyRow});o.push(e),s.add(t)}}er(n,o)}function Xn(e){let t=[],n=Zn(e),r=-1,i=new Map;for(let[e,a]of n.entries()){i.has(e)||(r+=1,i.set(e,r));let n=0;for(let o of a){t.push({cell:o,rowIndex:i.get(e),colIndex:n}),n+=o.colspan||1;let a=o.emptyRow||[];for(let e of a)i.has(e)||(r+=1,i.set(e,r))}}return t}function Zn(e){let t=new Map;for(let n of e)t.has(n.rowId)||t.set(n.rowId,[]),t.get(n.rowId).push(n);return t}function Qn(e,t,n){let r=Zn(n),i=Array.from(r.values()),a=Kn(t).cols,o=[];for(let n=0;n<t.length;n++){let r=t[n],s=Math.floor(n/a),c=n%a,l=i[s%i.length],u=l[c%l.length],d=$n(e,r,u.deltaOps);o.push(d)}er(e,o)}function $n(e,t,n,r){let{rowspan:i=1,colspan:a=1,emptyRow:o}=r||{};r&&(t.rowspan=i,t.colspan=a,o&&o.length>0&&(t.emptyRow=o));let s=t.formats(),c=new Wn;for(let e of n)c.insert(e.insert,{...e.attributes,...s});return{offset:t.offset(e.quill.scroll),length:t.length(),insertDelta:c,cell:t,rowspan:i,colspan:a,emptyRow:o}}function er(t,n){if(n.length===0)return;n.sort((e,t)=>e.offset-t.offset);let r=new Wn;for(let e=0;e<n.length;e++){let t=n[e],i=t.offset;if(e!==0){let r=n[e-1];i=t.offset-r.offset-r.length}r=r.retain(i).concat(t.insertDelta).delete(t.length)}for(let e of n)tr(t,e);t.quill.updateContents(r,e.sources.USER)}function tr(e,n){let{cell:r,rowspan:i=1,colspan:a=1}=n;if(i===1&&a===1)return;let o=u(r,t.tableMain);if(!o)return;let s=r.getTableRow();if(!s)return;let c=o.descendants(H),l=o.getRows(),d=l.indexOf(s),f=r.getColumnIndex(),p=[];for(let e of c){if(e===r)continue;let t=e.getTableRow();if(!t)continue;let n=l.indexOf(t),o=e.getColumnIndex(),s=n>=d&&n<d+i,c=o>=f&&o<f+a;s&&c&&p.push(e)}let m=e.talbeModule.options.autoMergeCell;for(let e of p)if(e.domNode.isConnected){let t=e.getTableRow();e.remove(),!m&&t&&t.length()<=0&&t.remove()}}const nr=e.import(`delta`),rr=e.import(`modules/clipboard`);function ir(e){let t=Number.parseFloat(e.getAttribute(`width`));if(Number.isNaN(t)){let n=e.style.width;t=n?Number.parseFloat(n):e.offsetWidth}return t||n.colDefaultWidth}function ar(e,t){let r=Array(t).fill(n.colDefaultWidth),i=Array.from(e.querySelectorAll(`tr`));for(let e of i){let n=Array.from(e.querySelectorAll(`td`)),i=0;for(let e of n){let n=e.colSpan||1;if(i<t){let t=ir(e);for(let e=0;e<n;e++)r[i+e]=t/n}else break;i+=n}}return r}var or=class extends rr{tableId=R();rowId=R();colIds=[];rowspanCount=[];cellCount=0;colCount=0;constructor(e,t){super(e,t),this.quill=e,this.addMatcher(`table`,this.matchTable.bind(this)),this.addMatcher(`thead`,this.matchThead.bind(this)),this.addMatcher(`tbody`,this.matchTbody.bind(this)),this.addMatcher(`tfoot`,this.matchTfoot.bind(this)),this.addMatcher(`colgroup`,this.matchColgroup.bind(this)),this.addMatcher(`col`,this.matchCol.bind(this)),this.addMatcher(`tr`,this.matchTr.bind(this)),this.addMatcher(`td`,this.matchTd.bind(this)),this.addMatcher(`th`,this.matchTd.bind(this)),this.addMatcher(`caption`,this.matchCaption.bind(this)),this.addMatcher(Node.ELEMENT_NODE,this.matchTdAttributor.bind(this))}getStyleBackgroundColor(e,n){let r=e.style.backgroundColor;if(r){for(let e of n.ops)if(e.attributes?.[t.tableCellInner]){let{style:n,...i}=e.attributes[t.tableCellInner],a=fn(n||``);a.backgroundColor||(a.backgroundColor=r,e.attributes[t.tableCellInner]={...i,style:pn(a)})}}}matchTable(e,n){if(n.ops.length===0)return n;let r=[],i=[],a=-1;for(let e=0;e<n.ops.length;e++){let{attributes:o,insert:s}=n.ops[e];if(!ie(s)&&(!o||!o[t.tableCellInner]&&!o[t.tableCaption])){n.ops.splice(e,1),--e;continue}let{table:c,[t.tableCell]:l,...u}=o||{},d=ie(s)&&s[t.tableCol];d?i.push({insert:s}):r.push({attributes:u,insert:s}),!u?.[t.tableCellInner]&&!u?.[t.tableCaption]&&!d&&C(s)&&s.trim().length>0&&(a=e)}let o=ar(e,this.colIds.length).reduce((e,n,r)=>(i[r]?e.push(i[r]):e.push({insert:{[t.tableCol]:{tableId:this.tableId,colId:this.colIds[r],width:n,full:!1}}}),e),[]);r.splice(a+1,0,...o);let s=new nr(r);return this.getStyleBackgroundColor(e,s),this.tableId=R(),this.colIds=[],this.rowspanCount=[],this.cellCount=0,this.colCount=0,s}matchTbody(e,n){this.getStyleBackgroundColor(e,n);let r=[];for(let e=n.ops.length-1;e>=0;e--){let i=n.ops[e];if(i.attributes?.[t.tableCellInner]){if(i.attributes){let e=i.attributes[t.tableCellInner];e.rowspan===1?r=[]:r.length>0&&(e.emptyRow||=[],r.length>e.emptyRow.length&&e.emptyRow.push(...r.slice(e.emptyRow.length-r.length)))}}else{r=[];let e=i.insert?C(i.insert)?i.insert.split(`
15
+ `).length-1:1:0;for(let t=0;t<e;t++)r.push(R())}}return this.rowspanCount=[],n}matchThead(e,n){let r=this.matchTbody(e,n);for(let e of r.ops)if(e.attributes?.[t.tableCellInner]){let n=e.attributes[t.tableCellInner];n.wrapTag=`thead`}return r}matchTfoot(e,n){let r=this.matchTbody(e,n);for(let e of r.ops)if(e.attributes?.[t.tableCellInner]){let n=e.attributes[t.tableCellInner];n.wrapTag=`tfoot`}return r}matchColgroup(e,n){let r=[];for(let e of n.ops)e&&ie(e.insert)&&e.insert[t.tableCol]&&r.push(e);return new nr(r)}matchCol(e,n){let r=Number(e.getAttribute(`span`)||1);Number.isNaN(r)&&(r=1);let i=new nr;for(let n=0;n<r;n++)this.colIds[this.colCount]=R(),i.insert({[t.tableCol]:Object.assign(G.value(e),{tableId:this.tableId,colId:this.colIds[this.colCount]})}),this.colCount+=1;return i}matchTr(e,t){this.rowId=R(),this.cellCount=0;for(let[e,t]of this.rowspanCount.entries())t.rowspan>0&&--t.rowspan,t.rowspan<=0&&(this.rowspanCount[e]={rowspan:0,colspan:0});return this.getStyleBackgroundColor(e,t),t.ops.length===0?new nr([{insert:`
16
+ `}]):t}matchTd(e,n){let r=e,i=W.formats(r);if(!this.colIds[this.cellCount]||!this.rowspanCount[this.cellCount])for(let e=this.cellCount;e>=0;e--)this.colIds[e]||(this.colIds[e]=R()),this.rowspanCount[e]||(this.rowspanCount[e]={rowspan:0,colspan:0});for(let e=this.cellCount;e<this.rowspanCount.length;e++){let{rowspan:t,colspan:n}=this.rowspanCount[e];if(t===0)break;this.cellCount+=n}i.rowspan>1&&(this.rowspanCount[this.cellCount]={rowspan:i.rowspan,colspan:i.colspan});let a=this.colIds[this.cellCount];this.cellCount+=i.colspan;let o=Object.assign(i,{tableId:this.tableId,rowId:this.rowId,colId:a});r.style.border===`none`&&(o.style=o.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,``));let s=[];for(let e of n.ops){let{attributes:n={},...r}=e,{[t.tableCell]:i,...a}=n;s.push({...r,attributes:{...a,[t.tableCellInner]:o}})}return(s.length<=0||!C(s[s.length-1].insert)||!s[s.length-1].insert.endsWith(`
17
17
  `))&&s.push({insert:`
18
- `,attributes:{[t.tableCellInner]:o}}),new Qn(s)}matchTdAttributor(e,n){if(e.tagName.toLocaleLowerCase()===`td`){let e=[];for(let r of n.ops){let{attributes:n,...i}=r,a=n?.[t.tableCellInner];if(n&&a&&a.style){let{background:t,...r}=n,o=document.createElement(`div`);o.style.background=t;let s=document.createElement(`div`);if(s.style.cssText=a.style,o.style.background===s.style.backgroundColor){e.push({...i,attributes:{...r}});continue}}e.push(r)}return new Qn(e)}return n}convert({html:e,text:n},r={}){let i=super.convert({html:e,text:n},r);if(r[t.tableCellInner])for(let e of i.ops){if(ie(e.insert)&&e.insert[t.tableCol]){e.insert=``;continue}e.attributes||={},e.attributes[t.tableCellInner]=r[t.tableCellInner]}return i}matchCaption(e,n){for(let e=0;e<n.ops.length;e++){let r=n.ops[e],{attributes:i}=r;i&&i[t.tableCaption]&&(i[t.tableCaption].tableId=this.tableId,r.attributes=i)}return n}},rr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
18
+ `,attributes:{[t.tableCellInner]:o}}),new nr(s)}matchTdAttributor(e,n){if(e.tagName.toLocaleLowerCase()===`td`){let e=[];for(let r of n.ops){let{attributes:n,...i}=r,a=n?.[t.tableCellInner];if(n&&a?.style){let{background:t,...r}=n,o=document.createElement(`div`);o.style.background=t;let s=document.createElement(`div`);if(s.style.cssText=a.style,o.style.background===s.style.backgroundColor){e.push({...i,attributes:{...r}});continue}}e.push(r)}return new nr(e)}return n}convert({html:e,text:n},r={}){let i=super.convert({html:e,text:n},r);if(r[t.tableCellInner])for(let e of i.ops){if(ie(e.insert)&&e.insert[t.tableCol]){e.insert=``;continue}e.attributes||={},e.attributes[t.tableCellInner]=r[t.tableCellInner]}return i}matchCaption(e,n){for(let e of n.ops){let{attributes:n}=e;n?.[t.tableCaption]&&(n[t.tableCaption].tableId=this.tableId,e.attributes=n)}return n}},sr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
19
19
  <!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE -->
20
20
  <path
21
21
  fill="none"
@@ -26,7 +26,7 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
26
26
  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"
27
27
  />
28
28
  </svg>
29
- `,ir=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
29
+ `,cr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
30
30
  <path
31
31
  fill="none"
32
32
  stroke="currentColor"
@@ -36,7 +36,7 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
36
36
  d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"
37
37
  />
38
38
  </svg>
39
- `,ar=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
39
+ `,lr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
40
40
  <path
41
41
  fill="none"
42
42
  stroke="currentColor"
@@ -46,14 +46,14 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
46
46
  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"
47
47
  />
48
48
  </svg>
49
- `,or=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">\r
50
- <!-- Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE -->\r
51
- <path\r
52
- fill="currentColor"\r
53
- d="M11 21V9H3V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm2-2h6v-4h-6zm0-6h6V9h-6zM5 7h14V5H5zM3 22v-2h2.55q-1.2-.575-1.937-1.7t-.738-2.55q0-1.975 1.388-3.363T7.625 11v2q-1.125 0-1.937.8t-.813 1.95q0 .975.6 1.725t1.525.95V16h2v6z"\r
54
- />\r
55
- </svg>\r
56
- `,sr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256">
49
+ `,ur=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
50
+ <!-- Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE -->
51
+ <path
52
+ fill="currentColor"
53
+ d="M11 21V9H3V5q0-.825.588-1.412T5 3h14q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21zm2-2h6v-4h-6zm0-6h6V9h-6zM5 7h14V5H5zM3 22v-2h2.55q-1.2-.575-1.937-1.7t-.738-2.55q0-1.975 1.388-3.363T7.625 11v2q-1.125 0-1.937.8t-.813 1.95q0 .975.6 1.725t1.525.95V16h2v6z"
54
+ />
55
+ </svg>
56
+ `,dr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 256 256">
57
57
  <g fill="currentColor">
58
58
  <path d="M216 40v128h-48V88H88V40Z" opacity=".2" />
59
59
  <path
@@ -61,86 +61,86 @@ import e from"quill";const t={container:`table-up-container`,tableCaption:`table
61
61
  />
62
62
  </g>
63
63
  </svg>
64
- `,cr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32">
64
+ `,fr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32">
65
65
  <path
66
66
  fill="currentColor"
67
67
  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"
68
68
  />
69
69
  <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" />
70
70
  </svg>
71
- `,lr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
71
+ `,pr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
72
72
  <path
73
73
  fill="currentColor"
74
74
  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"
75
75
  />
76
76
  </svg>
77
- `,ur=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
77
+ `,mr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
78
78
  <path
79
79
  fill="currentColor"
80
80
  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"
81
81
  />
82
82
  </svg>
83
- `,dr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
83
+ `,hr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
84
84
  <path
85
85
  fill="currentColor"
86
86
  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"
87
87
  />
88
88
  </svg>
89
- `,fr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
89
+ `,gr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
90
90
  <path
91
91
  fill="currentColor"
92
92
  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"
93
93
  />
94
94
  </svg>
95
- `,pr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
95
+ `,_r=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
96
96
  <path
97
97
  fill="currentColor"
98
98
  d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"
99
99
  />
100
100
  </svg>
101
- `,mr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
101
+ `,vr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
102
102
  <path
103
103
  fill="currentColor"
104
104
  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"
105
105
  />
106
106
  </svg>
107
- `,hr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
107
+ `,yr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
108
108
  <path
109
109
  fill="currentColor"
110
110
  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"
111
111
  />
112
112
  </svg>
113
- `,gr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
113
+ `,br=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
114
114
  <path
115
115
  fill="currentColor"
116
116
  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"
117
117
  />
118
118
  </svg>
119
- `,_r=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
119
+ `,xr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
120
120
  <path
121
121
  fill="currentColor"
122
122
  d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"
123
123
  />
124
124
  </svg>
125
- `,vr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
125
+ `,Sr=`<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">
126
126
  <!-- Icon from TDesign Icons by TDesign - https://github.com/Tencent/tdesign-icons/blob/main/LICENSE -->
127
127
  <path fill="currentColor" d="M21 10v12h-2V12H5v10H3V10zm0-8v6H3V2zm-2 2H5v2h14z" />
128
128
  </svg>
129
- `;const yr=`color-selector`;async function br(e,t,n=!1){let r=e.getTextByCell(t),i=e.getHTMLByCell(t,n),a=new ClipboardItem({"text/plain":new Blob([r],{type:`text/plain`}),"text/html":new Blob([i],{type:`text/html`})});await navigator.clipboard.write([a])}const Z={Break:{name:`break`},CopyCell:{name:`CopyCell`,tip:`Copy cell`,icon:sr,handle(e,t){br.call(this,e,t,!1)}},CutCell:{name:`CutCell`,tip:`Cut cell`,icon:cr,handle(e,t){br.call(this,e,t,!0)}},InsertTop:{name:`InsertTop`,icon:fr,tip:`Insert row above`,handle(e,t){e.appendRow(t,!1)}},InsertRight:{name:`InsertRight`,icon:dr,tip:`Insert column right`,handle(e,t){e.appendCol(t,!0)}},InsertBottom:{name:`InsertBottom`,icon:lr,tip:`Insert row below`,handle(e,t){e.appendRow(t,!0)}},InsertLeft:{name:`InsertLeft`,icon:ur,tip:`Insert column Left`,handle(e,t){e.appendCol(t,!1)}},MergeCell:{name:`MergeCell`,icon:pr,tip:`Merge Cell`,handle(e,t){e.mergeCells(t)}},SplitCell:{name:`SplitCell`,icon:_r,tip:`Split Cell`,handle(e,t){e.splitCell(t)}},DeleteRow:{name:`DeleteRow`,icon:hr,tip:`Delete Row`,handle(e,t){e.removeRow(t)}},DeleteColumn:{name:`DeleteColumn`,icon:mr,tip:`Delete Column`,handle(e,t){e.removeCol(t)}},DeleteTable:{name:`DeleteTable`,icon:gr,tip:`Delete table`,handle(e,t){e.deleteTable(t)}},BackgroundColor:{name:`BackgroundColor`,icon:ir,isColorChoose:!0,tip:`Set background color`,key:`background-color`,handle(e,t,n){e.setCellAttrs(t,`background-color`,n,!0)}},BorderColor:{name:`BorderColor`,icon:ar,isColorChoose:!0,tip:`Set border color`,key:`border-color`,handle(e,t,n){e.setCellAttrs(t,`border-color`,n,!0)}},SwitchWidth:{name:`SwitchWidth`,icon:rr,tip:`Switch table width`,handle(){if(!this.table)return;let t=e.find(this.table);t&&(t.full?t.cancelFull():t.setFull())}},InsertCaption:{name:`InsertCaption`,icon:vr,tip:`Insert table caption`,handle(){if(!this.table)return;let n=e.find(this.table);if(!n)return;let r=this.quill.scroll.create(`text`,`Table Caption`).wrap(t.tableCaption,{tableId:n.tableId});n.insertBefore(r,n.children.head)}},ToggleTdBetweenTh:{name:`ToggleTdBetweenTh`,icon:or,tip:`Toggle td between th`,handle(e,t){for(let e of t)e.convertTableCell()}},ConvertTothead:{name:`ConvertTothead`,icon:or,tip:`Convert to thead`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`thead`)}},ConvertTotfoot:{name:`ConvertTotfoot`,icon:or,tip:`Convert to tfoot`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`tfoot`)}}},xr=l(`color-map`),Q={selectWrapper:xr.b(),used:xr.bm(`used`),item:xr.be(`item`),btn:xr.be(`btn`),map:xr.be(`content`),mapRow:xr.be(`content-row`)};var Sr=class extends Rn{static moduleName=`table-menu`;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;tooltipItem=[];activeTooltip=null;bem=l(`menu`);colorItemClass=`color-${R()}`;colorChooseTooltipOption={direction:`top`};constructor(t,n,i){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i);try{let e=localStorage.getItem(this.options.localstorageKey)||`[]`,t=JSON.parse(e);S(t)||(t=[]),t.slice(-10).map(e=>this.usedColors.add(e))}catch{}this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart)}updateUsedColor=dn(e=>{if(!e)return;if(this.usedColors.add(e),this.usedColors.size>10){let e=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),e.map(e=>this.usedColors.add(e))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));let t=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Q.used}`));for(let n of t){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=String(e),Array.from(n.querySelectorAll(`.${Q.item}[style*="background-color: ${t.style.backgroundColor}"]`)).length<=0&&n.appendChild(t);let r=Array.from(n.querySelectorAll(`.${Q.item}`)).slice(0,-10);for(let e of r)e.remove()}},1e3);hideWhenSelectionDragStart=()=>{this.hide()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&this.isMenuDisplay&&this.update()};resolveOptions(e){return Object.assign({tipText:!0,tools:[Z.InsertTop,Z.InsertRight,Z.InsertBottom,Z.InsertLeft,Z.Break,Z.MergeCell,Z.SplitCell,Z.Break,Z.DeleteRow,Z.DeleteColumn,Z.DeleteTable,Z.Break,Z.BackgroundColor,Z.BorderColor],localstorageKey:`__table-bg-used-color`,defaultColorMap:a},e)}buildTools(){let e=document.createElement(`div`);e.classList.add(this.bem.b()),Object.assign(e.style,{display:`flex`});for(let t of this.options.tools){let{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s=``}=t,c=document.createElement(`span`);if(c.classList.add(this.bem.be(`item`)),n===`break`)c.classList.add(this.bem.is(`break`));else{let e=document.createElement(`i`);if(e.classList.add(`icon`),x(r)?e.appendChild(r(this.tableModule)):e.innerHTML=r,c.appendChild(e),a&&o){let e=this.createColorChoose(c,{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s});this.tooltipItem.push(e),c.classList.add(yr)}else x(i)&&c.addEventListener(`click`,e=>{this.quill.focus(),i.call(this,this.tableModule,this.getSelectedTds(),e)},!1);let t=this.tableModule.options.texts[n]||s;this.options.tipText&&t&&s&&this.createTipText(c,t)}e.appendChild(c)}return e}createColorChoose(e,{handle:t,key:n}){let r=document.createElement(`div`);if(r.classList.add(Q.selectWrapper),this.options.defaultColorMap.length>0){let e=document.createElement(`div`);e.classList.add(Q.map);for(let t of this.options.defaultColorMap){let n=document.createElement(`div`);n.classList.add(Q.mapRow);for(let e of t){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=e,n.appendChild(t)}e.appendChild(n)}r.appendChild(e)}let i=document.createElement(`div`);i.classList.add(Q.mapRow),Object.assign(i.style,{marginTop:`4px`});let a=document.createElement(`div`);a.classList.add(Q.btn,`transparent`),a.textContent=this.tableModule.options.texts.transparent,a.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),`transparent`)});let o=document.createElement(`div`);o.classList.add(Q.btn,`clear`),o.textContent=this.tableModule.options.texts.clear,o.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),null)});let s=document.createElement(`div`);s.classList.add(Q.btn,`custom`),s.textContent=this.tableModule.options.texts.custom;let c=le({onChange:e=>{t.call(this,this.tableModule,this.getSelectedTds(),e),this.updateUsedColor(e)}}),{hide:l,destroy:u}=Zt(s,{direction:`right`,type:`click`,content:c,container:s});i.appendChild(a),i.appendChild(o),i.appendChild(s),r.appendChild(i);let d=document.createElement(`div`);d.classList.add(Q.used,this.colorItemClass);for(let e of this.usedColors){let t=document.createElement(`div`);t.classList.add(Q.item),t.style.backgroundColor=e,d.appendChild(t)}r.appendChild(d),r.addEventListener(`click`,e=>{e.stopPropagation(),l();let t=e.target,r=t.style.backgroundColor,i=this.getSelectedTds();if(t&&r&&i.length>0){if(this.tableModule.setCellAttrs(i,n,r,!0),!t.closest(`.${Q.item}`))return;this.updateUsedColor(r)}});let f=Zt(e,{type:`click`,content:r,onOpen:()=>{let e=this.tableModule.getModule(`table-selection`);return this.isMenuDisplay&&e&&e.hideDisplay(),this.setActiveTooltip(f),!1},onClose:()=>{let e=this.tableModule.getModule(`table-selection`);return this.isMenuDisplay&&e&&(e.updateWithSelectedTds(),e.showDisplay()),r.contains(c)&&l(),this.activeTooltip===f&&(this.activeTooltip=null),!1},onDestroy:()=>{u(),this.activeTooltip===f&&(this.activeTooltip=null)},...this.colorChooseTooltipOption});return f.isColorPick=!0,f}setActiveTooltip(e){this.activeTooltip&&this.activeTooltip!==e&&this.activeTooltip.hide(!0),this.activeTooltip=e}getSelectedTds(){return this.tableModule.getModule(`table-selection`)?.selectedTds||[]}createTipText(e,t){let n=Zt(e,{msg:t});n&&this.tooltipItem.push(n)}show(){this.table&&(this.menu&&this.hide(),this.menu=this.buildTools())}update(){this.table&&!this.quill.root.contains(this.table)&&this.setSelectionTable(void 0)}hide(){this.menu&&=(this.menu.remove(),null);for(let e of this.tooltipItem)e.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart),this.activeTooltip=null;for(let e of this.tooltipItem)e.destroy();this.tooltipItem=[],this.hide()}},Cr=class extends Sr{colorChooseTooltipOption={direction:`right`};constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.root.addEventListener(`contextmenu`,this.listenContextmenu),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}tableSelectioChange=e=>{e.selectedTds.length<=0&&this.hide()};listenContextmenu=e=>{e.preventDefault();let t=e.composedPath();if(!t||t.length<=0)return;let n=t.find(e=>e.tagName&&e.tagName.toUpperCase()===`TABLE`&&e.classList.contains(`ql-table`)),r=this.tableModule.getModule(`table-selection`);n&&r?.selectedTds?.length?(this.menu||=this.buildTools(),Object.assign(this.menu.style,{display:`flex`}),this.isMenuDisplay=!0,this.update({x:e.clientX,y:e.clientY}),document.addEventListener(`click`,()=>{this.hide()},{once:!0})):this.hide()};buildTools(){let e=super.buildTools();e.classList.add(this.bem.is(`contextmenu`));let t=e.getElementsByClassName(yr);for(let e of Array.from(t))e.addEventListener(`click`,e=>e.stopPropagation());return document.body.appendChild(e),e}createTipText(e,t){let n=document.createElement(`span`);n.textContent=t,e.appendChild(n)}show(){}update(e){super.update();let t=this.tableModule.getModule(`table-selection`);if(!this.table||!this.isMenuDisplay||!this.menu){this.hide();return}if(!e||!t?.isDisplaySelection)return;let n={display:`flex`,left:0,top:0},{x:r,y:i}=e;n.left=r,n.top=i,Object.assign(this.menu.style,{...n,left:`${n.left+window.scrollX}px`,top:`${n.top+window.scrollY}px`});let a=this.menu.getBoundingClientRect(),{left:o,top:s}=en(a);Object.assign(this.menu.style,{left:`${o+window.scrollX}px`,top:`${s+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener(`contextmenu`,this.listenContextmenu),super.destroy(),this.quill.off(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.off(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}},wr=class extends Sr{constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.on(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.on(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectionDisplayChange)}tableSelectionDragStart=()=>{this.hide()};tableSelectionDragEnd=e=>{e.selectedTds.length>0&&this.show()};tableSelectioChange=(e,t)=>{t.length<=0&&this.hide()};tableSelectionDisplayChange=e=>{e.dragging||this.update()};buildTools(){let e=super.buildTools();return this.tableModule.addContainer(e),e}show(){super.show(),this.update()}update(){if(super.update(),!this.menu&&this.table){this.show();return}let e=this.getSelectedTds();if(!this.menu||!this.table||e.length===0){(this.menu||!this.table)&&(this.isMenuDisplay=!1,this.menu&&this.menu.classList.add(this.bem.is(`hidden`)),this.hide());return}this.isMenuDisplay=!0,this.menu.classList.remove(this.bem.is(`hidden`));let t=this.tableModule.getModule(`table-selection`);t?.isDisplaySelection&&Yt(t.cellSelect,this.menu,{placement:`bottom`,middleware:[qt(),Kt({limiter:Jt()}),Gt(20)]}).then(({x:e,y:t})=>{this.menu&&Object.assign(this.menu.style,{left:`${e}px`,top:`${t}px`})})}destroy(){super.destroy(),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.off(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd)}};const Tr=e=>!e.full&&e.align===`right`;var Er=class extends Rn{static moduleName=`table-resize`;colIndex=-1;tableBlot;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=l(`drag-line`);constructor(e,t){super(e,t),this.tableModule=e,this.quill=t}findCurrentColIndex(e){return-1}colWidthChange(e,t,n){}async createConfirmDialog({message:e,confirm:t,cancel:n}){return new Promise(r=>{let i=document.createElement(`div`);Object.assign(i.style,{padding:`8px 12px`,fontSize:`14px`,lineHeight:`1.5`});let a=document.createElement(`p`);a.textContent=e;let o=document.createElement(`div`);Object.assign(o.style,{display:`flex`,justifyContent:`flex-end`,gap:`6px`});let s=ce({content:n}),c=ce({type:`confirm`,content:t});o.appendChild(s),o.appendChild(c),i.appendChild(a),i.appendChild(o);let{close:l}=ue({child:i});s.addEventListener(`click`,()=>{r(!1),l()}),c.addEventListener(`click`,()=>{r(!0),l()})})}async handleColMouseUp(){if(!this.dragColBreak||!this.tableBlot||this.colIndex===-1)return;let e=this.tableBlot.getCols(),t=Number.parseInt(this.dragColBreak.dataset.w||`0`),i=this.tableBlot.full,a=!1,o=[];if(i){let r=this.tableBlot.domNode.getBoundingClientRect().width,i=t/r*100,s=e[this.colIndex].width;if(i<s){if(i=Math.max(n.colMinWidthPre,i),e[this.colIndex+1]||e[this.colIndex-1]){let t=e[this.colIndex+1]?this.colIndex+1:this.colIndex-1;o.push({index:t,width:e[t].width+s-i})}else i=100;a=!0,o.push({index:this.colIndex,width:i})}else if(e[this.colIndex+1]){let t=s+e[this.colIndex+1].width;i=Math.min(t-n.colMinWidthPre,i),a=!0,o.push({index:this.colIndex,width:i},{index:this.colIndex+1,width:t-i})}}else this.tableBlot.domNode.style.width=`${Number.parseFloat(this.tableBlot.domNode.style.width)-e[this.colIndex].domNode.getBoundingClientRect().width+t}px`,a=!0,o.push({index:this.colIndex,width:t});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener(`mouseup`,this.handleColMouseUpFunc),document.removeEventListener(`mousemove`,this.handleColMouseMoveFunc),this.dragging=!1,a){let t=this.tableBlot.domNode.getBoundingClientRect().width;if(i){let n=0,r=new Set(o.map(({index:e,width:t})=>(n+=t,e)));for(let[t,i]of e.entries()){if(r.has(t))continue;n+=i.width}if(n>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.tableBlot.cancelFull(),i=!1;for(let[e,n]of o.entries()){let{width:r,index:i}=n;o[e]={index:i,width:r/100*t}}}}for(let{index:n,width:r}of o){let a=Number.parseFloat(r.toFixed(3));e[n].width=`${a}${i?`%`:`px`}`,this.colWidthChange(n,{px:i?Math.round(r/100*t):a,pre:a},i)}}this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}getColumnRect(e){if(!this.tableBlot)return null;let t=this.tableBlot.getCols();if(e>=t.length)return null;let n=t[0].domNode.getBoundingClientRect().left;for(let r=0;r<e;r++){let e=t[r].domNode.getBoundingClientRect();n+=e.width}let r=t[e].domNode.getBoundingClientRect().width;return{left:n,right:n+r,width:r}}handleColMouseMove(e){if(e.preventDefault(),!this.dragColBreak||!this.tableBlot||this.colIndex===-1)return;let t=this.tableBlot.getCols(),r=this.getColumnRect(this.colIndex),i=this.tableBlot.domNode.getBoundingClientRect(),a=e.clientX;if(this.tableBlot.full){let e=n.colMinWidthPre/100*i.width,o=i.right;a>r.right&&t[this.colIndex+1]&&(o=Math.max(this.getColumnRect(this.colIndex+1).right-e,r.left+e));let s=r.left+e;a=Math.min(Math.max(a,s),o)}else Tr(this.tableBlot)?r.right-a<n.colMinWidthPx&&(a=r.right-n.colMinWidthPx):a-r.left<n.colMinWidthPx&&(a=r.left+n.colMinWidthPx);let o=a-r.left;return Tr(this.tableBlot)&&(o=r.right-a),this.dragColBreak.style.left=`${a}px`,this.dragColBreak.dataset.w=String(o),{left:a,width:o}}handleColMouseDown(e){if(e.button!==0||(e.preventDefault(),!this.tableBlot))return;let{rect:t}=X(this.tableBlot);if(!t)return;let n=this.tableBlot.getCols();if(this.colIndex=this.findCurrentColIndex(e),this.colIndex===-1)return;let r=n[this.colIndex].width,i=this.tableBlot.full?r/100*t.width:r;document.addEventListener(`mouseup`,this.handleColMouseUpFunc),document.addEventListener(`mousemove`,this.handleColMouseMoveFunc),this.dragging=!0;let a=document.createElement(`div`);a.classList.add(this.dragBEM.b(),this.dragBEM.is(`col`)),a.dataset.w=String(i);let o={top:t.y,left:e.clientX,height:t.height};Object.assign(a.style,{top:`${o.top}px`,left:`${o.left}px`,height:`${o.height}px`});let s=document.body;return s.appendChild(a),this.dragColBreak&&s.removeChild(this.dragColBreak),this.dragColBreak=a,o}findCurrentRowIndex(e){return-1}rowHeightChange(e,t){}handleRowMouseUp(){if(!this.tableBlot||!this.dragRowBreak||this.rowIndex===-1)return;let e=Number.parseInt(this.dragRowBreak.dataset.h||`0`);this.tableBlot.getRows()[this.rowIndex].setHeight(`${e}px`),this.rowHeightChange(this.rowIndex,e),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(r.AFTER_TABLE_RESIZE)}handleRowMouseMove(e){if(!this.tableBlot||!this.dragRowBreak||this.rowIndex===-1)return;e.preventDefault();let t=this.tableBlot.getRows()[this.rowIndex].domNode.getBoundingClientRect(),r=e.clientY;return r-t.y<n.rowMinHeightPx&&(r=t.y+n.rowMinHeightPx),this.dragRowBreak.style.top=`${r}px`,this.dragRowBreak.dataset.h=String(r-t.y),{top:r,height:r-t.y}}handleRowMouseDown(e){if(e.button!==0||(e.preventDefault(),!this.tableBlot)||(this.rowIndex=this.findCurrentRowIndex(e),this.rowIndex===-1))return;this.dragging=!0,document.addEventListener(`mouseup`,this.handleRowMouseUpFunc),document.addEventListener(`mousemove`,this.handleRowMouseMoveFunc);let t=this.tableBlot.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,n=this.tableBlot.domNode.getBoundingClientRect(),r=document.createElement(`div`);r.classList.add(this.dragBEM.b(),this.dragBEM.is(`row`)),r.dataset.h=String(t);let i={top:e.clientY,left:n.x,width:n.width};Object.assign(r.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});let a=document.body;return a.appendChild(r),this.dragRowBreak&&a.removeChild(this.dragRowBreak),this.dragRowBreak=r,i}update(){}destroy(){}},Dr=class extends Er{root;tableWrapperBlot;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=l(`resize-box`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.root=this.tableModule.addContainer(this.bem.b()),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};setSelectionTable(t){if(this.table!==t){if(this.hide(),this.table=t,this.table){let t=e.find(this.table);t&&(this.tableBlot=t,this.tableWrapperBlot=this.tableBlot.parent),this.show()}this.update()}}handleResizerHeader(e,t,n){if(!this.table)return;let{clientX:r,clientY:i}=n,a=this.table.getBoundingClientRect();n.shiftKey||(this.lastHeaderSelect=null);let o=[{x:e?a.left:r,y:e?i:a.top},{x:e?a.right:r,y:e?i:a.bottom}];if(this.lastHeaderSelect){let t,n;if(this.lastHeaderSelect.isX){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=Math.min(e.left,a.left),n=e.top+e.height/2}else{let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=e.left+e.width/2,n=Math.min(e.top,a.top)}this.lastHeaderSelect.isX===e?e?(o[0].y=Math.min(o[0].y,n),o[1].y=Math.max(o[1].y,n)):(o[0].x=Math.min(o[0].x,t),o[1].x=Math.max(o[1].x,t)):(o[1]={x:Math.max(o[0].x,t),y:Math.max(o[0].y,n)},o[0]={x:Math.min(o[0].x,t),y:Math.min(o[0].y,n)})}else this.lastHeaderSelect={isX:e,index:t};let s=this.tableModule.getModule(`table-selection`);s&&(s.table=this.table,s.setSelectedTds(s.computeSelectedTds(...o)),s.show())}findCurrentColIndex(e){return Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`))).indexOf(e.target)}colWidthChange(e,t,n){let r=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)));r[e].style.width=n?`${t.pre}%`:`${t.px}px`}handleColMouseDownFunc=function(e){let t=this.handleColMouseDown(e);if(t&&this.dragColBreak&&this.tableBlot){let[e]=p(this.tableBlot,U),n=e&&e.side===`top`?0:this.size;Object.assign(this.dragColBreak.style,{top:`${t.top-n}px`,left:`${t.left}px`,height:`${t.height+this.size}px`})}return t}.bind(this);bindColEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`)));L.call(this,this.tableWrapperBlot.domNode,()=>{this.colHeadWrapper.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft});for(let[t,n]of e.entries())n.addEventListener(`click`,this.handleResizerHeader.bind(this,!1,t));for(let e of t)e.addEventListener(`mousedown`,this.handleColMouseDownFunc),e.addEventListener(`dragstart`,e=>e.preventDefault())}findCurrentRowIndex(e){return Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`))).indexOf(e.target)}rowHeightChange(e,t){let n=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)));n[e].style.height=`${t}px`}handleRowMouseDownFunc=function(e){let t=this.handleRowMouseDown(e);return t&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${t.top}px`,left:`${t.left-this.size}px`,width:`${t.width+this.size}px`}),t}.bind(this);bindRowEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`)));L.call(this,this.tableWrapperBlot.domNode,()=>{this.rowHeadWrapper.scrollTop=this.tableWrapperBlot.domNode.scrollTop});for(let[t,n]of e.entries())n.addEventListener(`click`,this.handleResizerHeader.bind(this,!0,t));for(let e of t)e.addEventListener(`mousedown`,this.handleRowMouseDownFunc),e.addEventListener(`dragstart`,e=>e.preventDefault())}update(){if(!this.tableBlot||!this.tableWrapperBlot)return;let{rect:e}=X(this.tableBlot);if(!e)return;this.root.innerHTML=``,this.tableCols=this.tableBlot.getCols(),this.tableRows=this.tableBlot.getRows();let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();if(Object.assign(this.root.style,{top:`${Math.max(e.y,t.y)-n.y}px`,left:`${Math.max(e.x,t.x)-n.x}px`}),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`,()=>{let e=this.tableModule.getModule(`table-selection`);e&&this.tableBlot&&(e.setSelectedTds(this.tableBlot.descendants(H)),e.show(),e.updateWithSelectedTds())}),this.root.appendChild(this.corner)),this.tableCols.length>0){let n=``;for(let[,t]of this.tableCols.entries()){let r=t.domNode.getBoundingClientRect().width;r===0&&(r=Number.parseInt(t.domNode.getAttribute(`width`),10)),n+=`<div class="${this.bem.be(`col-header`)}" style="width: ${r}px">
130
- <div class="${this.bem.be(`col-separator`)}" style="height: ${e.height+this.size-3}px"></div>
131
- </div>`}let r=document.createElement(`div`);r.classList.add(this.bem.be(`col`));let i=document.createElement(`div`);i.classList.add(this.bem.be(`col-wrapper`)),Object.assign(r.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=n,r.appendChild(i),this.root.appendChild(r),r.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft,this.colHeadWrapper=r,this.bindColEvents()}if(this.tableRows.length>0){let n=``;for(let[,t]of this.tableRows.entries()){let r=`${t.domNode.getBoundingClientRect().height}px`;n+=`<div class="${this.bem.be(`row-header`)}" style="height: ${Number.parseFloat(r)}px">
132
- <div class="${this.bem.be(`row-separator`)}" style="width: ${e.width+this.size-3}px"></div>
133
- </div>`}let r=document.createElement(`div`);r.classList.add(this.bem.be(`row`));let i=document.createElement(`div`);i.classList.add(this.bem.be(`row-wrapper`)),Object.assign(r.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${t.height}px`}),Object.assign(i.style,{height:`${e.height}px`}),i.innerHTML=n,r.appendChild(i),this.root.appendChild(r),r.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=r,this.bindRowEvents()}let[r]=p(this.tableBlot,U),i=!r||!(r&&r.side===`top`);i?this.root.classList.remove(this.bem.is(`caption-bottom`)):this.root.classList.add(this.bem.is(`caption-bottom`));let a=-1*this.size,o=-1*this.size;Tr(this.tableBlot)?(this.root.classList.add(this.bem.is(`align-right`)),a=Math.min(t.width,e.width),o=Math.min(t.width,e.width)):this.root.classList.remove(this.bem.is(`align-right`)),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${a}px)`,top:`${i?0:e.height+this.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${o}px)`,maxHeight:`${t.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${i?0:e.height+this.size}px`,maxWidth:`${t.width}px`})}show(){!this.table||!this.tableBlot||!this.tableWrapperBlot||(this.root.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=tn(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),L.call(this,this.quill.root,()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is(`hidden`)),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0)}destroy(){this.hide(),nn.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.root.remove()}},Or=class extends Er{colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=l(`resize-line`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.colResizer=this.tableModule.addContainer(this.bem.be(`col`)),this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};mousemoveHandler=n=>{if(this.dragging||this.tableModule.getModule(`table-selection`)?.dragging)return;let r=this.findTableCell(n);if(!r)return this.hide();let i=e.find(r);i&&this.currentTableCell!==r&&(this.show(),this.currentTableCell=r,this.tableCellBlot=i,this.tableBlot=u(i,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};findTableCell(e){for(let t of e.composedPath()){if(t instanceof HTMLElement&&[`TD`,`TH`].includes(t.tagName))return t;if(t===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex+(this.tableCellBlot?.colspan||1)-1}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;let e=this.tableCellBlot;this.colResizer.remove();let{rect:t}=X(this.tableBlot);if(!t)return;this.colResizer=this.tableModule.addContainer(this.bem.be(`col`));let n=e.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect(),i=n.right-r.x;Tr(this.tableBlot)&&(i=n.left-r.x),Object.assign(this.colResizer.style,{top:`${t.y-r.y}px`,left:`${i}px`,height:`${t.height}px`}),this.curColIndex=this.tableBlot.getCols().findIndex(t=>t.colId===e.colId),this.colResizer.addEventListener(`mousedown`,this.handleColMouseDownFunc),this.colResizer.addEventListener(`dragstart`,e=>{e.preventDefault()})}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let e=this.tableCellBlot;this.rowResizer.remove();let{rect:t}=X(this.tableBlot);if(!t)return;this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`));let n=e.parent;if(!(n instanceof W))return;let r=e.domNode.getBoundingClientRect(),i=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:`${r.bottom-i.y}px`,left:`${t.x-i.x}px`,width:`${t.width}px`}),this.curRowIndex=this.tableBlot.getRows().indexOf(n),this.rowResizer.addEventListener(`mousedown`,this.handleRowMouseDownFunc),this.rowResizer.addEventListener(`dragstart`,e=>{e.preventDefault()})}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is(`hidden`)),this.colResizer.classList.remove(this.bem.is(`hidden`)),this.table.addEventListener(`mousemove`,this.mousemoveHandler))}hide(){this.currentTableCell=void 0,!(!this.rowResizer||!this.colResizer)&&(this.rowResizer.classList.add(this.bem.is(`hidden`)),this.colResizer.classList.add(this.bem.is(`hidden`)),this.table&&this.table.removeEventListener(`mousemove`,this.mousemoveHandler))}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer&&=(this.colResizer.remove(),void 0),this.rowResizer&&=(this.rowResizer.remove(),void 0),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},kr=class extends Rn{scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l(`scale`);startX=0;startY=0;offset=6;options;root;block;resizeobserver=new ResizeObserver(()=>this.update());constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(r),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};resolveOptions(e){return Object.assign({blockSize:12},e)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.block=document.createElement(`div`),this.block.classList.add(this.bem.be(`block`)),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let e=[],t=[],r=r=>{if(!this.tableMainBlot)return;let i=Tr(this.tableMainBlot)?-1:1,a=(r.clientX-this.startX)*i,o=r.clientY-this.startY,s=Math.floor(a/e.length),c=Math.floor(o/t.length);for(let{blot:t,width:r}of e)t.width=Math.max(r+s,n.colMinWidthPx);for(let{blot:e,height:r}of t)e.setHeight(`${Math.max(r+c,n.rowMinHeightPx)}px`)},i=()=>{e=[],t=[],document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};this.block.addEventListener(`mousedown`,n=>{!this.tableMainBlot||this.isTableOutofEditor()||(this.startX=n.clientX,this.startY=n.clientY,e=this.tableMainBlot.getCols().map(e=>({blot:e,width:Math.floor(e.width)})),t=this.tableMainBlot.getRows().map(e=>({blot:e,height:Math.floor(e.domNode.getBoundingClientRect().height)})),document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i))}),this.block.addEventListener(`dragstart`,e=>e.preventDefault())}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;let e=this.tableMainBlot.domNode.getBoundingClientRect(),t=this.tableWrapperBlot.domNode.getBoundingClientRect();if(e.width>t.width){for(let n of this.tableMainBlot.getCols())n.width=Math.floor(n.width/e.width*t.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!this.block||!this.root||!this.tableMainBlot||!this.tableWrapperBlot)return;if(this.tableMainBlot.full){this.hide();return}let{rect:e}=X(this.tableMainBlot);if(!e)return;let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),{scrollTop:r,scrollLeft:i}=this.tableWrapperBlot.domNode,a=this.options.blockSize*2+this.offset,o=Math.min(e.width,t.width)+a,s=Math.min(e.height,t.height)+a;Object.assign(this.root.style,{width:`${o}px`,height:`${s}px`,left:`${Math.max(e.x,t.x)-n.x-this.options.blockSize}px`,top:`${Math.max(e.y,t.y)-n.y-this.options.blockSize}px`});let c={left:`${e.width+a-i}px`,top:`${s-r}px`};Tr(this.tableMainBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is(`align-right`)),Object.assign(this.block.style,c)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),L.call(this,this.quill.root,()=>this.update()),L.call(this,this.tableWrapperBlot.domNode,()=>this.update())),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0)}destroy(){this.hide(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect(),nn.call(this)}},Ar=class{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=l(`scrollbar`);tableMainBlot;get isVertical(){return this.options.isVertical}constructor(t,n,r){this.quill=t,this.table=n,this.options=r,this.tableMainBlot=e.find(this.table),this.container=n.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(n),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),L.call(this,this.quill.root,()=>this.setScrollbarPosition()),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:e,head:t,body:n,foot:r}=X(this.tableMainBlot),i=t||n||r;if(!i||!e)return;let{scrollLeft:a,scrollTop:o,offsetLeft:s,offsetTop:c}=this.quill.root,{offsetLeft:l,offsetTop:u}=this.container,{offsetLeft:d,offsetTop:f}=i.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),h=l+d-s,g=u+f-c;this.isVertical?h+=Math.min(p,e.width):g+=Math.min(m,e.height),this.tableMainBlot&&this.tableMainBlot.align!==`left`&&(h+=this.table.offsetLeft-l),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,e.height):p}px`,transform:`translate(${h-a}px, ${g-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let e=this.container.offsetHeight-this.gap,t=this.container.offsetWidth-this.gap,n=e**2/this.container.scrollHeight,r=t**2/this.container.scrollWidth,i=Math.max(n,this.minSize),a=Math.max(r,this.minSize);this.ratioY=n/(e-n)/(i/(e-i)),this.ratioX=r/(t-r)/(a/(t-a)),this.sizeWidth=a+this.gap<t?`${a}px`:``,this.sizeHeight=i+this.gap<e?`${i}px`:``,this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let e=document.createElement(`div`);e.classList.add(this.bem.b(),this.isVertical?this.bem.is(`vertical`):this.bem.is(`horizontal`),this.bem.is(`transparent`)),Object.assign(e.style,{display:`none`}),this.thumb.classList.add(this.bem.be(`thumb`));let t=null,n=e=>{if(this.cursorDown===!1)return;let t=this.thumbState[this.propertyMap.axis];if(!t)return;let n=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],r=(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-e[this.propertyMap.client])*-1,i=this.thumb[this.propertyMap.offset]-t,a=(r-i)*100*n/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=a*this.container[this.propertyMap.scrollSize]/100},r=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=t},i=e=>{e.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r),t=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener(`mousedown`,e=>{if(e.stopPropagation(),e.ctrlKey||[1,2].includes(e.button))return;window.getSelection()?.removeAllRanges(),i(e);let t=e.currentTarget;t&&(this.thumbState[this.propertyMap.axis]=t[this.propertyMap.offset]-(e[this.propertyMap.client]-t.getBoundingClientRect()[this.propertyMap.direction]))});let a=[this.table,e];for(let e of a)e.addEventListener(`mouseenter`,this.showScrollbar),e.addEventListener(`mouseleave`,this.hideScrollbar);return L.call(this,this.container,()=>{this.containerScrollHandler(this.container)}),e.appendChild(this.thumb),e}containerScrollHandler(e){let t=e[this.propertyMap.offset]-this.gap;this.move=e[this.propertyMap.scrollDirection]*100/t*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=dn(()=>{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=dn(()=>{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(),nn.call(this),this.table.removeEventListener(`mouseenter`,this.showScrollbar),this.table.removeEventListener(`mouseleave`,this.hideScrollbar)}},jr=class extends Rn{static moduleName=`table-scrollbar`;scrollbarContainer;scrollbar=[];bem=l(`scrollbar`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n;let i=l(`scrollbar`);this.quill.container.classList.add(i.bm(`virtual`)),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be(`container`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};hide(){for(let e of this.scrollbar)e.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=``}show(){if(this.table){this.scrollbar=[new Ar(this.quill,this.table,{isVertical:!0}),new Ar(this.quill,this.table,{isVertical:!1})];for(let e of this.scrollbar)this.scrollbarContainer.appendChild(e.scrollbar),e.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let e of this.scrollbar)e.calculateSize(),e.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Mr=class extends Rn{static moduleName=`table-selection`;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l(`selection`);lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(e){this._dragging!==e&&(this._dragging=e,this.quill.emitter.emit(e?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,n,i={}){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=tn(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener(`paste`,this.handlePaste),this.quill.emitter.listenDOM(`selectionchange`,document,this.selectionChangeHandler.bind(this)),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.hide()}handlePaste=e=>{if(!(document.activeElement&&this.quill.root.contains(document.activeElement))||this.quill.getSelection())return;let n=e.clipboardData;if(!n)return;e.preventDefault();let r=this.selectedTds;if(r.length<=0)return;let i=n.getData(`text/html`),a=this.quill.clipboard.convert({html:i}).ops.filter(e=>e.attributes&&e.attributes[t.tableCellInner]);a.length!==0&&Vn({quill:this.quill,talbeModule:this.tableModule},r,a)};keyboardHandler=async e=>{if(e.ctrlKey)switch(e.key){case`c`:case`x`:await br(this.tableModule,this.selectedTds,e.key===`x`);break}else (e.key===`Backspace`||e.key===`Delete`)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let e=0;e<this.selectedTds.length;e++)if(!this.selectedTds[e].domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),n=document.activeElement;if(!(t||!this.quill.root.contains(n))){if(this.table){let t=e.find(this.table),n=t.descendants(H);if(this.selectedTds.length===n.length){t.remove();return}}for(let e of this.selectedTds){let t=e.clone();t.appendChild(e.scroll.create(`block`)),e.parent.insertBefore(t,e),e.remove()}}}setSelectedTds(e){let t=new Set(this.selectedTds),n=this.selectedTds.length===e.length&&e.every(e=>t.has(e));this.selectedTds=e,n||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}getFirstTextNode(e){for(let t of Array.from(e.childNodes))if(t.nodeType===Node.TEXT_NODE)return t;return e}getLastTextNode(e){for(let t=e.childNodes.length-1;t>=0;t--){let n=e.childNodes[t];if(n.nodeType===Node.TEXT_NODE)return n}return e}getNodeTailOffset(e){let t=document.createRange();return t.selectNodeContents(e),t.collapse(!1),t.startOffset}quillSelectionChangeHandler=(n,r,i)=>{if(i!==e.sources.API&&n&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(n),[r]=this.quill.getLine(n.index),i=!!e[t.tableCellInner]&&!!r,a=r&&this.selectedTds.some(e=>e.domNode.contains(r.domNode));if(i&&!a)try{let e=u(r,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else i&&a||this.hide()}};setSelectionData(e,t){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=t;if(!n||!i)return;let o=document.createRange(),s=this.selectionDirectionUp(t);s?(o.setStart(n,r),o.setEnd(n,r)):(o.setStart(n,r),o.setEnd(i,a)),e.removeAllRanges(),e.addRange(o),s&&e.extend(i,a)}selectionDirectionUp(e){let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:i}=e;if(!t||!r)return!1;if(t===r)return n>i;let a=t.compareDocumentPosition(r);return a&Node.DOCUMENT_POSITION_CONTAINS||a&Node.DOCUMENT_POSITION_CONTAINED_BY?(a&Node.DOCUMENT_POSITION_FOLLOWING)!==0:(a&Node.DOCUMENT_POSITION_PRECEDING)!==0}findWrapSelection(e){let t=null,n=0,r=null,i=0;for(let{node:a,offset:o}of e)a&&((!t||this.selectionDirectionUp({anchorNode:t,anchorOffset:n,focusNode:a,focusOffset:o}))&&(t=a,n=o),(!r||this.selectionDirectionUp({anchorNode:a,anchorOffset:o,focusNode:r,focusOffset:i}))&&(r=a,i=o));return{startNode:t,startOffset:n,endNode:r,endOffset:i}}resolveOptions(e){return Object.assign({selectColor:`#0589f340`},e)}selectionChangeHandler(){let n=window.getSelection();if(!n)return;let{anchorNode:r,focusNode:i,anchorOffset:a,focusOffset:o}=n;if(!r||!i)return;let s=e.find(r),c=e.find(i);if(!s||!c||s.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;let l=f(s),u=f(c),d=l.has(t.tableColgroup),p=u.has(t.tableColgroup);if(d||p){let e=r,s=a,c=i,f=o;if(d){let n=l.get(t.tableWrapper).descendants(H);n.length>0&&(e=n[0].domNode,s=0)}if(p){let e=u.get(t.tableWrapper).descendants(H);e.length>0&&(c=e[0].domNode,f=0)}this.setSelectionData(n,{anchorNode:e,anchorOffset:s,focusNode:c,focusOffset:f});return}let m=l.has(t.tableCellInner),h=u.has(t.tableCellInner),g=m&&h;if(g){let e=l.get(t.tableCellInner),n=u.get(t.tableCellInner);g&&=e!==n}if(m&&h&&g||!m&&h||!h&&m){this.setSelectionData(n,this.lastSelection),this.selectedTds.length>0&&this.hide();return}this.lastSelection={anchorNode:r,anchorOffset:a,focusNode:i,focusOffset:o}}helpLinesInitial(){this.cellSelectWrap.style.setProperty(`--select-color`,this.options.selectColor);let e=document.createElement(`div`);return e.classList.add(this.bem.be(`line`)),this.cellSelectWrap.appendChild(e),e}computeSelectedTds(t,n){if(!this.table)return[];let r=e.find(this.table);if(!r)return[];let i=new Set(r.descendants(G).map((e,t)=>(e.index=t,e))),a=this.getScrollPositionDiff(),{rect:o}=X(r);if(!o)return[];let s=t.x+a.x,c=t.y+a.y,l={x:Math.max(o.left,Math.min(n.x,s)),y:Math.max(o.top,Math.min(n.y,c)),x1:Math.min(o.right,Math.max(n.x,s)),y1:Math.min(o.bottom,Math.max(n.y,c))},u=new Set,d=!0;for(;d;){d=!1;for(let e of i){e.__rect||=e.domNode.getBoundingClientRect();let{x:t,y:n,right:r,bottom:a}=e.__rect;if(Qt({x:Math.floor(l.x),y:Math.floor(l.y),x1:Math.floor(l.x1),y1:Math.floor(l.y1)},{x:Math.floor(t),y:Math.floor(n),x1:Math.floor(r),y1:Math.floor(a)},0,u.size===0)){u.add(e),i.delete(e),l={x:Math.min(l.x,t),y:Math.min(l.y,n),x1:Math.max(l.x1,r),y1:Math.max(l.y1,a)},d=!0;break}}}for(let e of[...u,...i])delete e.__rect;return this.boundary=$t({...l,width:l.x1-l.x,height:l.y1-l.y},this.quill.root),Array.from(u).toSorted((e,t)=>e.index-t.index).map(e=>(delete e.index,e.getCellInner()))}getScrollPositionDiff(){let{x:e,y:t}=this.getTableViewScroll(),{x:n,y:r}=rn(this.quill.root);return this.selectedTableScrollX=e,this.selectedTableScrollY=t,this.selectedEditorScrollX=n,this.selectedEditorScrollY=r,this.startScrollRecordPosition.reduce((e,{x:t,y:n},r)=>{let{x:i,y:a}=rn(this.scrollRecordEls[r]);return e.x+=t-i,e.y+=n-a,e},{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let e of this.scrollRecordEls)this.startScrollRecordPosition.push(rn(e))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(e){let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`table`),o=n.closest(`caption`);if(t!==0||!a||o)return;this.setSelectionTable(a);let s=a.dataset.tableId,c={x:r,y:i};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(c,c)),this.show();let l=e=>{this.dragging=!0;let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`.ql-table`),o=n.closest(`caption`);if(t!==0||o||!a||a.dataset.tableId!==s)return;let l={x:r,y:i};this.setSelectedTds(this.computeSelectedTds(c,l)),this.selectedTds.length>1&&this.quill.blur(),this.update()},u=()=>{document.body.removeEventListener(`mousemove`,l,!1),document.body.removeEventListener(`mouseup`,u,!1),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener(`mousemove`,l,!1),document.body.addEventListener(`mouseup`,u,!1)}updateWithSelectedTds(){if(this.selectedTds.length<=0){this.hide();return}let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.selectedTds){let r=n.domNode.getBoundingClientRect();e.x=Math.min(e.x,r.left),e.y=Math.min(e.y,r.top),t.x=Math.max(t.x,r.right),t.y=Math.max(t.y,r.bottom)}this.setSelectedTds(this.computeSelectedTds(e,t)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table){this.hide();return}if(this.selectedTds.length===0||!this.boundary)return;let{x:e,y:t}=rn(this.quill.root),{x:n,y:i}=this.getTableViewScroll(),a=this.table.parentElement.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),s=a.x-o.x,c=a.y-o.y;Object.assign(this.cellSelect.style,{left:`${this.selectedEditorScrollX*2-e+this.boundary.x+this.selectedTableScrollX-n-s}px`,top:`${this.selectedEditorScrollY*2-t+this.boundary.y+this.selectedTableScrollY-i-c}px`,width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${s}px`,top:`${c}px`,width:`${a.width}px`,height:`${a.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?rn(this.table.parentElement):{x:0,y:0}}setSelectionTable(e){this.table!==e&&(this.table=e,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:`block`}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(nn.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener(`keydown`,this.keyboardHandler),L.call(this,this.quill.root,()=>{this.update()}),L.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(){nn.call(this),this.quill.root.removeEventListener(`keydown`,this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),nn.call(this),document.removeEventListener(`paste`,this.handlePaste),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Nr=e.import(`parchment`),$=e.import(`delta`),Pr=e.import(`ui/icons`),Fr=e.import(`blots/break`),Ir=e.import(`blots/block`),Lr=e.import(`blots/block/embed`);function Rr(e,{tableId:n,rowId:r,colId:i}){let a={tableId:n,rowId:r,colId:i,colspan:1,rowspan:1},o=e.create(t.tableCell,a),s=e.create(t.tableCellInner,a),c=e.create(`block`);return c.appendChild(e.create(`break`)),s.appendChild(c),o.appendChild(s),o}function zr(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),Hr.moduleName=i.moduleName,Hr.toolName=t.tableWrapper,z.blotName=t.container,U.blotName=t.tableCaption,Y.blotName=t.tableWrapper,q.blotName=t.tableMain,J.blotName=t.tableColgroup,K.blotName=t.tableCol,In.blotName=t.tableHead,V.blotName=t.tableBody,Fn.blotName=t.tableFoot,W.blotName=t.tableRow,G.blotName=t.tableCell,H.blotName=t.tableCellInner,o.add(t.tableCellInner)}function Br(t,n){return pe({onSelect:(r,i)=>{t.insertTable(r,i,e.sources.USER),n&&n.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Vr(n){return{bindInHead:!1,key:n?`ArrowUp`:`ArrowDown`,collapsed:!0,format:[t.tableCellInner],handler(r,i){let a=n?`prev`:`next`,o=n?`tail`:`head`;if(i.line[a])return!0;let s=this.quill.selection.getBounds(r.index),c=i.line.domNode.getBoundingClientRect();if(!s||!c)return!0;if(n){if(s.top-c.top>3)return!0}else if(c.bottom-s.bottom>3)return!0;let l,u,f,p;try{[l,u,f,p]=d(i.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m=u.getColIds(),h=l.descendants(U,0)[0],g;if(h){let e=window.getComputedStyle(h.domNode);g=a===`next`&&e.captionSide===`bottom`?h:a===`next`?l.next:h}else g=l[a];if(i.line[a]||!g)return!0;let _=f[a];if(_){let t=m.indexOf(p.colId),n=_.getCellByColId(m[t],a);if(!n)return!0;let r=n.children[o];r.children&&(r=r.children[o]);let s=r.offset(this.quill.scroll)+Math.min(i.offset,r.length()-1);this.quill.setSelection(s,0,e.sources.USER)}else{let t=g.offset(this.quill.scroll)+(n?g.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var Hr=class r{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:`Backspace`,collapsed:!0,offset:0,handler(e,n){let r=this.quill.getLine(e.index)[0];return r.prev instanceof Y?(r.prev.remove(),!1):!(n.format[t.tableCellInner]&&r.offset(u(r,t.tableCellInner))===0)}},"forbid remove table by delete":{bindInHead:!0,key:`Delete`,collapsed:!0,handler(e,n){let r=this.quill.getLine(e.index),i=r[0],a=r[1];if((i.next instanceof Y||i.next instanceof K)&&a===i.length()-1)return!1;if(n.format[t.tableCellInner]){let e=u(i,t.tableCellInner);if(i===e.children.tail&&a===i.length()-1)return!1}return!0}},"table up":Vr(!0),"table down":Vr(!1),"table caption break":{bindInHead:!0,key:`Enter`,shiftKey:null,format:[t.tableCaption],handler(e,t){return!1}}};static register(){Y.allowedChildren=[q],q.allowedChildren=[J,U,In,V,Fn],q.requiredContainer=Y,U.requiredContainer=q,J.allowedChildren=[K],J.requiredContainer=q,In.allowedChildren=[W],In.requiredContainer=q,V.allowedChildren=[W],V.requiredContainer=q,Fn.allowedChildren=[W],Fn.requiredContainer=q,W.allowedChildren=[G],G.allowedChildren=[H,Fr],G.requiredContainer=W,H.requiredContainer=G;let n=new Set([`table`]),r=Object.entries(e.imports).filter(([e,t])=>{let r=e.split(`formats/`)[1];return e.startsWith(`formats/`)&&!n.has(r)&&(g(t,Ir)||g(t,Lr))}).reduce((e,[t,n])=>{let r=g(n,Lr)?Cn:xn;return e[t]=class extends h(n,[r]){static register(){}},e},{});e.register({"blots/scroll":kn,"blots/block":xn,"blots/block/embed":Cn,...r,[`blots/${t.container}`]:z,[`formats/${t.tableCell}`]:G,[`formats/${t.tableCellInner}`]:H,[`formats/${t.tableRow}`]:W,[`formats/${t.tableHead}`]:In,[`formats/${t.tableBody}`]:V,[`formats/${t.tableFoot}`]:Fn,[`formats/${t.tableCol}`]:K,[`formats/${t.tableColgroup}`]:J,[`formats/${t.tableCaption}`]:U,[`formats/${t.tableMain}`]:q,[`formats/${t.tableWrapper}`]:Y,"modules/clipboard":nr},!0)}quill;options;toolBox;fixTableByLisenter=dn(this.balanceTables,100);selector;resizeOb;modules={};get statics(){return this.constructor}constructor(e,t){this.quill=e,this.options=this.resolveOptions(t||{}),this.toolBox=this.initialContainer();let n=this.quill.getModule(`toolbar`);if(n&&this.quill.theme.pickers){let[,e]=(n.controls||[]).find(([e])=>e===this.statics.toolName)||[];if(e&&e.tagName.toLocaleLowerCase()===`select`){let t=this.quill.theme.pickers.find(t=>t.select===e);t&&(t.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,t),t.label.addEventListener(`mousedown`,()=>{if(!this.selector||!t)return;let e=this.selector.getBoundingClientRect(),{leftLimited:n}=en(e);if(n){let e=t.label.getBoundingClientRect();Object.assign(t.options.style,{transform:`translateX(calc(-100% + ${e.width}px))`})}else Object.assign(t.options.style,{transform:void 0})}))}}let i=this.quill.getModule(`keyboard`);for(let e of Object.values(r.keyboradHandler))e.bindInHead?i.bindings[e.key].unshift(e):i.addBinding(e.key,e);this.initModules(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let e=l(`toolbox`),t=this.quill.addContainer(e.b());return this.resizeOb=new ResizeObserver(()=>{let e=this.quill.root.getBoundingClientRect(),{offsetLeft:n,offsetTop:r}=this.quill.root;Object.assign(t.style,{top:`${r}px`,left:`${n}px`,width:`${e.width}px`,height:`${e.height}px`})}),this.resizeOb.observe(this.quill.root),t}addContainer(e){if(C(e)){let t=document.createElement(`div`);for(let n of e.split(` `))t.classList.add(n);return this.toolBox.appendChild(t),t}else return this.toolBox.appendChild(e),e}resolveOptions(e){return Object.assign({customBtn:!1,texts:this.resolveTexts(e.texts||{}),full:!1,fullSwitch:!0,icon:Pr.table,autoMergeCell:!0,modules:[]},e)}resolveTexts(e){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`},e)}initModules(){for(let e of this.options.modules)this.modules[e.module.moduleName]=new e.module(this,this.quill,e.options)}getModule(e){return this.modules[e]}quillHack(){let n=this.quill.getSemanticHTML;this.quill.getSemanticHTML=((r=0,i)=>{let a=n.call(this.quill,r,i),o=e.import(`formats/${t.tableWrapper}`),s=new DOMParser().parseFromString(a,`text/html`);for(let e of Array.from(s.querySelectorAll(`.${o.className} caption[contenteditable], .${o.className} .${G.className} > [contenteditable]`)))e.removeAttribute(`contenteditable`);return s.body.innerHTML});let r=this.quill.format;this.quill.format=function(n,a,o=e.sources.API){if(!(this.scroll.query(n).prototype instanceof Nr.EmbedBlot)){let e=this.getModule(i.moduleName),s=this.getSelection(!0),c=this.getFormat(s),l=e.getModule(`table-selection`);if(!c[t.tableCellInner]||s.length>0||e&&l&&l.selectedTds.length<=1)return r.call(this,n,a,o);if(e&&l&&l.selectedTds.length>0){let e=l.selectedTds,t=!1,r=[];for(let i of e){let e=i.offset(this.scroll),o=i.length();r.push({index:e,length:o}),this.getFormat(e,o)[n]!==a&&(t=!0)}let i=t?a:!1,s=new $;for(let[e,{index:t,length:a}]of r.entries()){let o=e===0?0:r[e-1].index+r[e-1].length;s.retain(t-o).retain(a,{[n]:i})}let c=this.updateContents(s,o);return this.blur(),c}}return r.call(this,n,a,o)};let a=this.quill.theme.modules.toolbar;if(a){let n=a.handlers?.clean;if(n){let r=(e,n,r=()=>``)=>{let i=this.quill.getText(e,n),[a,o]=this.quill.getLine(e+n),s=0,c=new $;a!=null&&(s=a.length()-o,c=a.delta().slice(o,o+s-1).insert(`
134
- `));let l=this.quill.getContents(e,n+s),u=l.diff(new $().insert(i).concat(c)),d=0,f=u.ops.map(e=>{let{attributes:n,...i}=e;if(e.insert?d-=C(e.insert)?e.insert.length:1:e.retain?d+=re(e.retain)?e.retain:1:e.delete&&(d+=e.delete),n){let{[t.tableCellInner]:e,...a}=n;if(r){let e=l.slice(d-1,d).ops[0];if(e&&e.attributes&&e.attributes[t.tableCellInner]){let{style:n,...o}=e.attributes[t.tableCellInner],s=r(n);return s?{...i,attributes:{...a,[t.tableCellInner]:{style:s,...o}}}:{...i,attributes:{...a,[t.tableCellInner]:o}}}}return{...i,attributes:{...a}}}return e});return new $(f)};a.handlers.clean=function(a){let o=this.quill.getModule(i.moduleName),s=this.quill.getSelection();if(s&&s.length>0&&this.quill.getFormat(s)[t.tableCellInner]){let t=r(s.index,s.length,!1),n=new $().retain(s.index).concat(t);this.quill.updateContents(n,e.sources.USER);return}let c=o.getModule(`table-selection`);if(o&&c&&c.selectedTds.length>0&&c.table){let t=e.find(c.table);if(!t){console.warn(`TableMainFormat not found`);return}let n=c.selectedTds,i=new Set,a=[];for(let e of n)if(e.parent instanceof G){for(let t of e.parent.getNearByCell(`top`)){if(i.has(t))continue;i.add(t),a.push({td:t,cleanBorder:`bottom`})}for(let t of e.parent.getNearByCell(`left`)){if(i.has(t))continue;i.add(t),a.push({td:t,cleanBorder:`right`})}i.add(e.parent),a.push({td:e.parent,cleanBorder:!0})}let o=t.descendants(G),s=new Map(o.map((e,t)=>[e,t]));a.sort((e,t)=>s.get(e.td)-s.get(t.td));let l=new $,u=0;for(let{td:e,cleanBorder:t}of a){let n=e.getCellInner().offset(this.quill.scroll),i=e.getCellInner().length(),a=r(n,i-1,e=>{if(!e||t===!0)return``;let n=ln(e),r=Object.keys(n).filter(e=>!e.startsWith(sn(`border-${t}`))).reduce((e,t)=>(e[t]=n[t],e),{});return un(r)}),o=new $().retain(n-u).concat(a);l=l.concat(o),u=n+i}this.quill.updateContents(l,e.sources.USER),n.length>1&&this.quill.blur();return}return n.call(this,a)}}}}async buildCustomSelect(e,t){if(!e||!x(e))return;let n=document.createElement(`div`);if(n.classList.add(`ql-custom-select`),this.selector=await e(this,t),n.appendChild(this.selector),this.options.fullSwitch){let e=l(`creator`),t=document.createElement(`label`);t.classList.add(e.be(`checkbox`));let r=document.createElement(`input`);r.type=`checkbox`,r.checked=this.options.full,r.addEventListener(`change`,()=>{this.options.full=r.checked});let i=document.createElement(`span`);i.textContent=this.options.texts.fullCheckboxText,t.appendChild(r),t.appendChild(i),n.appendChild(t)}t.options.innerHTML=``,t.options.appendChild(n)}setCellAttrs(e,t,n,r=!1){if(e.length!==0)for(let i of e)i.setFormatValue(t,n,r)}getTextByCell(e){let t=``;for(let n of e){let e=n.offset(this.quill.scroll),r=n.length();for(let n of this.quill.getContents(e,r).ops)C(n.insert)&&(t+=n.insert)}return t}getHTMLByCell(e,n=!1){if(e.length===0)return``;let r=null;try{for(let n of e){let e=u(n,t.tableMain);if(r||=e,e!==r)return console.error(`tableMain is not same`),``}}catch{return console.error(`tds must be in same tableMain`),``}if(!r)return``;let i=this.quill.getIndex(r),a=r.length(),o=this.quill.getSemanticHTML(i,a),s=new DOMParser().parseFromString(o,`text/html`),c=Array.from(s.querySelectorAll(`col`)),l=c.map(e=>e.dataset.colId),d=[],f=new Set,p=new Set;for(let t of e){f.add(t.colId);let e=t.colId,n=l.indexOf(e);for(let e=0;e<t.colspan;e++)f.add(l[n+e]);p.add(`${t.rowId}-${t.colId}`)}for(let e=0;e<c.length;e++){let t=c[e];f.has(t.dataset.colId)?d.push(t.getAttribute(`width`)):(t.remove(),c.splice(e--,1))}let m=0,h=null;for(let e of Array.from(s.querySelectorAll(`td, th`)))if(p.has(`${e.dataset.rowId}-${e.dataset.colId}`))h!==e.dataset.rowId&&(m+=1,h=e.dataset.rowId);else{let t=e.parentElement;e.remove(),t&&t.children.length<=0&&t.remove()}let g=c.map(e=>K.value(e));if(r.full){let e=g.reduce((e,t)=>t.width+e,0);for(let[t,n]of g.entries())n.width=Math.round(n.width/e*100),c[t].setAttribute(`width`,`${n.width}%`)}else{let e=0;for(let t of g)e+=t.width;let t=s.querySelector(`table`);t.style.width=`${e}px`}if(n){let t=r.getRows();if(m===t.length)this.removeCol(e);else for(let t of e)t.domNode.innerHTML=`<p><br></p>`}return s.body.innerHTML}insertTable(r,i,a=e.sources.API){if(r>=30||i>=30)throw Error(`Both rows and columns must be less than 30.`);this.quill.focus();let o=this.quill.getSelection();if(o==null)return;let[s]=this.quill.getLeaf(o.index);if(!s)return;if(c(s))throw Error(`Not supported ${s.statics.blotName} insert into table.`);let l=R(),u=Array(i).fill(0).map(()=>R()),d=this.calculateTableCellBorderWidth(),f=getComputedStyle(this.quill.root),p=Number.parseInt(f.paddingLeft),m=Number.parseInt(f.paddingRight),h=this.quill.root.scrollHeight>this.quill.root.clientHeight?an({target:this.quill.root}):0,g=Number.parseInt(f.width)-p-m-d-h,_=this.options.full?`${Math.max(1/i*100,n.colMinWidthPre)}%`:`${Math.max(Math.floor(g/i),n.colMinWidthPx)}px`,v=[{retain:o.index}],y=this.quill.getContents(o.index,1),[,b]=this.quill.getLine(o.index);y.ops[0].insert!==`
129
+ `;const Cr=`color-selector`;async function wr(e,t,n=!1){let r=e.getTextByCell(t),i=e.getHTMLByCell(t,n),a=new ClipboardItem({"text/plain":new Blob([r],{type:`text/plain`}),"text/html":new Blob([i],{type:`text/html`})});await navigator.clipboard.write([a])}const X={Break:{name:`break`},CopyCell:{name:`CopyCell`,tip:`Copy cell`,icon:dr,handle(e,t){wr.call(this,e,t,!1)}},CutCell:{name:`CutCell`,tip:`Cut cell`,icon:fr,handle(e,t){wr.call(this,e,t,!0)}},InsertTop:{name:`InsertTop`,icon:gr,tip:`Insert row above`,handle(e,t){e.appendRow(t,!1)}},InsertRight:{name:`InsertRight`,icon:hr,tip:`Insert column right`,handle(e,t){e.appendCol(t,!0)}},InsertBottom:{name:`InsertBottom`,icon:pr,tip:`Insert row below`,handle(e,t){e.appendRow(t,!0)}},InsertLeft:{name:`InsertLeft`,icon:mr,tip:`Insert column Left`,handle(e,t){e.appendCol(t,!1)}},MergeCell:{name:`MergeCell`,icon:_r,tip:`Merge Cell`,handle(e,t){e.mergeCells(t)}},SplitCell:{name:`SplitCell`,icon:xr,tip:`Split Cell`,handle(e,t){e.splitCell(t)}},DeleteRow:{name:`DeleteRow`,icon:yr,tip:`Delete Row`,handle(e,t){e.removeRow(t)}},DeleteColumn:{name:`DeleteColumn`,icon:vr,tip:`Delete Column`,handle(e,t){e.removeCol(t)}},DeleteTable:{name:`DeleteTable`,icon:br,tip:`Delete table`,handle(e,t){e.deleteTable(t)}},BackgroundColor:{name:`BackgroundColor`,icon:cr,isColorChoose:!0,tip:`Set background color`,key:`background-color`,handle(e,t,n){e.setCellAttrs(t,`background-color`,n,!0)}},BorderColor:{name:`BorderColor`,icon:lr,isColorChoose:!0,tip:`Set border color`,key:`border-color`,handle(e,t,n){e.setCellAttrs(t,`border-color`,n,!0)}},SwitchWidth:{name:`SwitchWidth`,icon:sr,tip:`Switch table width`,handle(){if(!this.table)return;let t=e.find(this.table);t&&(t.full?t.cancelFull():t.setFull())}},InsertCaption:{name:`InsertCaption`,icon:Sr,tip:`Insert table caption`,handle(){if(!this.table)return;let n=e.find(this.table);if(!n)return;let r=this.quill.scroll.create(`text`,`Table Caption`).wrap(t.tableCaption,{tableId:n.tableId});n.insertBefore(r,n.children.head)}},ToggleTdBetweenTh:{name:`ToggleTdBetweenTh`,icon:ur,tip:`Toggle td between th`,handle(e,t){for(let e of t)e.convertTableCell()}},ConvertTothead:{name:`ConvertTothead`,icon:ur,tip:`Convert to thead`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`thead`)}},ConvertTotfoot:{name:`ConvertTotfoot`,icon:ur,tip:`Convert to tfoot`,handle(t,n){if(!this.table)return;let r=e.find(this.table);r&&t.convertTableBodyByCells(r,n,`tfoot`)}}},Tr=l(`color-map`),Z={selectWrapper:Tr.b(),used:Tr.bm(`used`),item:Tr.be(`item`),btn:Tr.be(`btn`),map:Tr.be(`content`),mapRow:Tr.be(`content-row`)};var Er=class extends Hn{static moduleName=`table-menu`;usedColors=new Set;options;menu=null;isMenuDisplay=!1;isColorPicking=!1;tooltipItem=[];activeTooltip=null;bem=l(`menu`);colorItemClass=`color-${R()}`;colorChooseTooltipOption={direction:`top`};constructor(t,n,i){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i);try{let e=localStorage.getItem(this.options.localstorageKey)||`[]`,t=JSON.parse(e);S(t)||(t=[]),t.slice(-10).map(e=>this.usedColors.add(e))}catch{}this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart)}updateUsedColor=mn(e=>{if(!e)return;if(this.usedColors.add(e),this.usedColors.size>10){let e=Array.from(this.usedColors).slice(-10);this.usedColors.clear(),e.map(e=>this.usedColors.add(e))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(this.usedColors)));let t=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${Z.used}`));for(let n of t){let t=document.createElement(`div`);t.classList.add(Z.item),t.style.backgroundColor=String(e),Array.from(n.querySelectorAll(`.${Z.item}[style*="background-color: ${t.style.backgroundColor}"]`)).length<=0&&n.appendChild(t);let r=Array.from(n.querySelectorAll(`.${Z.item}`)).slice(0,-10);for(let e of r)e.remove()}},1e3);hideWhenSelectionDragStart=()=>{this.hide()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&this.isMenuDisplay&&this.update()};resolveOptions(e){return Object.assign({tipText:!0,tools:[X.InsertTop,X.InsertRight,X.InsertBottom,X.InsertLeft,X.Break,X.MergeCell,X.SplitCell,X.Break,X.DeleteRow,X.DeleteColumn,X.DeleteTable,X.Break,X.BackgroundColor,X.BorderColor],localstorageKey:`__table-bg-used-color`,defaultColorMap:a},e)}buildTools(){let e=document.createElement(`div`);e.classList.add(this.bem.b()),Object.assign(e.style,{display:`flex`});for(let t of this.options.tools){let{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s=``}=t,c=document.createElement(`span`);if(c.classList.add(this.bem.be(`item`)),n===`break`)c.classList.add(this.bem.is(`break`));else{let e=document.createElement(`i`);if(e.classList.add(`icon`),x(r)?e.appendChild(r(this.tableModule)):e.innerHTML=r,c.appendChild(e),a&&o){let e=this.createColorChoose(c,{name:n,icon:r,handle:i,isColorChoose:a,key:o,tip:s});this.tooltipItem.push(e),c.classList.add(Cr)}else x(i)&&c.addEventListener(`click`,e=>{this.quill.focus(),i.call(this,this.tableModule,this.getSelectedTds(),e)},!1);let t=this.tableModule.options.texts[n]||s;this.options.tipText&&t&&s&&this.createTipText(c,t)}e.appendChild(c)}return e}createColorChoose(e,{handle:t,key:n}){let r=document.createElement(`div`);if(r.classList.add(Z.selectWrapper),this.options.defaultColorMap.length>0){let e=document.createElement(`div`);e.classList.add(Z.map);for(let t of this.options.defaultColorMap){let n=document.createElement(`div`);n.classList.add(Z.mapRow);for(let e of t){let t=document.createElement(`div`);t.classList.add(Z.item),t.style.backgroundColor=e,n.appendChild(t)}e.appendChild(n)}r.appendChild(e)}let a=document.createElement(`div`);a.classList.add(Z.mapRow),Object.assign(a.style,{marginTop:`4px`});let o=document.createElement(`div`);o.classList.add(Z.btn,`transparent`),o.textContent=this.tableModule.options.texts.transparent,o.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),`transparent`)});let s=document.createElement(`div`);s.classList.add(Z.btn,`clear`),s.textContent=this.tableModule.options.texts.clear,s.addEventListener(`click`,()=>{t.call(this,this.tableModule,this.getSelectedTds(),null)});let c=document.createElement(`div`);c.classList.add(Z.btn,`custom`),c.textContent=this.tableModule.options.texts.custom;let l=le({onChange:e=>{t.call(this,this.tableModule,this.getSelectedTds(),e),this.updateUsedColor(e)}}),{hide:u,destroy:d}=Qt(c,{direction:`right`,type:`click`,content:l,container:c});a.appendChild(o),a.appendChild(s),a.appendChild(c),r.appendChild(a);let f=document.createElement(`div`);f.classList.add(Z.used,this.colorItemClass);for(let e of this.usedColors){let t=document.createElement(`div`);t.classList.add(Z.item),t.style.backgroundColor=e,f.appendChild(t)}r.appendChild(f),r.addEventListener(`click`,e=>{e.stopPropagation(),u();let t=e.target,r=t.style.backgroundColor,i=this.getSelectedTds();if(t&&r&&i.length>0){if(this.tableModule.setCellAttrs(i,n,r,!0),!t.closest(`.${Z.item}`))return;this.updateUsedColor(r)}});let p=Qt(e,{...this.colorChooseTooltipOption,type:`click`,content:r,container:this.quill.container,onOpen:()=>{let e=this.tableModule.getModule(i.tableSelectionName);return this.isMenuDisplay&&e&&e.hideDisplay(),this.setActiveTooltip(p),!1},onClose:()=>{let e=this.tableModule.getModule(i.tableSelectionName);return this.isMenuDisplay&&e&&(e.updateWithSelectedTds(),e.showDisplay()),r.contains(l)&&u(),this.activeTooltip===p&&(this.activeTooltip=null),!1},onDestroy:()=>{d(),this.activeTooltip===p&&(this.activeTooltip=null)}});return p.isColorPick=!0,p}setActiveTooltip(e){this.activeTooltip&&this.activeTooltip!==e&&this.activeTooltip.hide(!0),this.activeTooltip=e}getSelectedTds(){return this.tableModule.getModule(i.tableSelectionName)?.selectedTds||[]}createTipText(e,t){let n=Qt(e,{msg:t,container:this.quill.container});n&&this.tooltipItem.push(n)}show(){this.table&&(this.menu&&this.hide(),this.menu=this.buildTools())}update(){this.table&&!this.quill.root.contains(this.table)&&this.setSelectionTable(void 0)}hide(){this.menu&&=(this.menu.remove(),null);for(let e of this.tooltipItem)e.hide(!0);this.isMenuDisplay=!1}destroy(){this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.hideWhenSelectionDragStart),this.activeTooltip=null;for(let e of this.tooltipItem)e.destroy();this.tooltipItem=[],this.hide()}},Dr=class extends Er{static moduleName=`table-menu-contextmenu`;scrollHandler=[];constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.root.addEventListener(`contextmenu`,this.listenContextmenu),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}tableSelectioChange=e=>{e.selectedTds.length<=0&&this.hide()};listenContextmenu=e=>{e.preventDefault();let t=e.composedPath();if(!t||t.length<=0)return;let n=t.find(e=>e.tagName&&e.tagName.toUpperCase()===`TABLE`&&e.classList.contains(`ql-table`)),r=this.tableModule.getModule(i.tableSelectionName);if(n&&r?.selectedTds?.length){this.menu||=this.buildTools(),this.isMenuDisplay=!0,this.update({x:e.clientX,y:e.clientY});let t=()=>{this.hide(),L.call(this)};I.call(this,this.quill.root,t),document.addEventListener(`click`,t,{once:!0})}else this.hide()};buildTools(){let e=super.buildTools();e.classList.add(this.bem.is(`contextmenu`));let t=e.getElementsByClassName(Cr);for(let e of Array.from(t))e.addEventListener(`click`,e=>e.stopPropagation());return this.quill.container.appendChild(e),e}createTipText(e,t){let n=document.createElement(`span`);n.textContent=t,e.appendChild(n)}show(){}update(e){super.update();let t=this.tableModule.getModule(i.tableSelectionName);if(!this.table||!this.isMenuDisplay||!this.menu){this.hide();return}if(!e||!t?.isDisplaySelection)return;let n=this.quill.container.getBoundingClientRect();Object.assign(this.menu.style,{left:`${e.x-n.x}px`,top:`${e.y-n.y}px`});let r=this.menu.getBoundingClientRect(),{left:a,top:o}=nn(r),s=r.left-a,c=r.top-o;Object.assign(this.menu.style,{left:`${e.x-n.x-s}px`,top:`${e.y-n.y-c}px`})}destroy(){this.quill.root.removeEventListener(`contextmenu`,this.listenContextmenu),super.destroy(),this.quill.off(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.off(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectioChange)}},Or=class extends Er{static moduleName=`table-menu-select`;constructor(e,t,n){super(e,t,n),this.tableModule=e,this.quill=t,this.quill.on(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.on(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd),this.quill.on(r.TABLE_SELECTION_CHANGE,this.tableSelectioChange),this.quill.on(r.TABLE_SELECTION_DISPLAY_CHANGE,this.tableSelectionDisplayChange)}tableSelectionDragStart=()=>{this.hide()};tableSelectionDragEnd=e=>{e.selectedTds.length>0&&this.show()};tableSelectioChange=(e,t)=>{t.length<=0&&this.hide()};tableSelectionDisplayChange=e=>{e.dragging||this.update()};buildTools(){let e=super.buildTools();return this.tableModule.addContainer(e),e}show(){super.show(),this.update()}update(){if(super.update(),!this.menu&&this.table){this.show();return}let e=this.getSelectedTds();if(!this.menu||!this.table||e.length===0){(this.menu||!this.table)&&(this.isMenuDisplay=!1,this.menu?.classList.add(this.bem.is(`hidden`)),this.hide());return}this.isMenuDisplay=!0,this.menu.classList.remove(this.bem.is(`hidden`));let t=this.tableModule.getModule(i.tableSelectionName);t?.isDisplaySelection&&Xt(t.cellSelect,this.menu,{placement:`bottom`,middleware:[Jt(),qt({limiter:Yt()}),Kt(20)]}).then(({x:e,y:t})=>{this.menu&&Object.assign(this.menu.style,{left:`${e}px`,top:`${t}px`})})}destroy(){super.destroy(),this.quill.off(r.TABLE_SELECTION_DRAG_START,this.tableSelectionDragStart),this.quill.off(r.TABLE_SELECTION_DRAG_END,this.tableSelectionDragEnd)}};const kr=e=>!e.full&&e.align===`right`;function Ar(e,t){if(t<0||t>=e.length)return null;let n=e[0].domNode.getBoundingClientRect().left;for(let r=0;r<t;r++){let t=e[r].domNode.getBoundingClientRect();n+=t.width}let r=e[t].domNode.getBoundingClientRect().width;return{left:n,right:n+r,width:r}}function jr(e,t,n){if(e){let e=t.getCols().map(e=>e.colId),r=new Set,i=new Map(e.map(e=>[e,0])),a=new Set;for(let t of n){r.add(t.colId);let n=e.indexOf(t.colId);if(n!==-1){for(let r=n;r<n+t.colspan&&r<e.length;r++){a.add(r);let n=e[r];i.set(n,(i.get(n)||0)+t.rowspan)}a.add(Math.min(n+t.colspan,e.length))}}let o=t.getRows()?.length||0;for(let[e,t]of i.entries())t>=o&&r.delete(e);return{cellIndex:a,isSpan:r.size<=0}}else{let e=t.getRows().map(e=>e.rowId),r=new Set,i=new Map(e.map(e=>[e,0])),a=new Set;for(let t of n){r.add(t.rowId);let n=e.indexOf(t.rowId);if(n!==-1){for(let r=n;r<n+t.rowspan&&r<e.length;r++){a.add(r);let n=e[r];i.set(n,(i.get(n)||0)+t.colspan)}a.add(Math.min(n+t.rowspan,e.length))}}let o=t.getCols()?.length||0;for(let[e,t]of i.entries())t>=o&&r.delete(e);return{cellIndex:a,isSpan:r.size<=0}}}var Mr=class{maxRange=1/0;minRange=-1/0;startValue=0;dragBreak=null;tableModule;isX=!1;constructor(e,t){this.tableModule=e,this.isX=t}createBreak(){this.dragBreak&&this.dragBreak.remove();let e=l(`drag`);this.dragBreak=this.tableModule.addContainer(e.be(`line`)),this.dragBreak.classList.add(e.is(this.isX?`col`:`row`))}getOffsetFromStart(e){let t=0;if(!e)return t;let{rect:n}=Y(e);return n&&(t=n[this.isX?`x`:`y`]-this.startValue),t}limitRange(e,t,n=!0){let r=0;return n&&(r=this.getOffsetFromStart(e)),Math.min(this.maxRange+r,Math.max(t,this.minRange+r))}},Nr=class extends Hn{tableBlot;dragging=!1;colIndex=-1;rowIndex=-1;dragXCommon;dragYCommon;constructor(e,t){super(e,t),this.tableModule=e,this.quill=t,this.dragXCommon=new Mr(e,!0),this.dragYCommon=new Mr(e,!1)}findDragColIndex(e){return-1}calculateColDragRangeByFull(){if(!this.tableBlot)return;let{rect:e}=Y(this.tableBlot);if(!e)return;let t=this.tableBlot.getCols();if(this.colIndex=this.findDragColIndex(t),this.colIndex===-1)return;let r=Ar(t,this.colIndex),i=n.colMinWidthPre/100*e.width,a=e.right;t[this.colIndex+1]&&(a=Math.max(Ar(t,this.colIndex+1).right-i,r.left+i));let o=r.left+i;this.dragXCommon.minRange=o,this.dragXCommon.maxRange=a}calculateColDragRangeByFixed(){if(!this.tableBlot)return;let e=this.tableBlot.getCols();if(this.colIndex=this.findDragColIndex(e),this.colIndex===-1)return;let t=Ar(e,this.colIndex);this.dragXCommon.minRange=kr(this.tableBlot)?t.right-n.colMinWidthPx:t.left+n.colMinWidthPx,this.dragXCommon.maxRange=1/0}calculateColDragRange(){this.tableBlot&&(this.tableBlot.full?this.calculateColDragRangeByFull():this.calculateColDragRangeByFixed())}async updateTableCol(e){if(!this.tableBlot||this.colIndex===-1)return;let t=this.dragXCommon.limitRange(this.tableBlot,e,!0),i=this.tableBlot.getCols(),a=Ar(i,this.colIndex),o=t-a.left;kr(this.tableBlot)&&(o=a.right-t);let s=this.tableBlot.full,c=!1,l=[];if(s){let{rect:e}=Y(this.tableBlot),t=e.width,r=o/t*100,a=i[this.colIndex].width;if(r<a){if(r=Math.max(n.colMinWidthPre,r),i[this.colIndex+1]||i[this.colIndex-1]){let e=i[this.colIndex+1]?this.colIndex+1:this.colIndex-1;l.push({index:e,width:i[e].width+a-r})}else r=100;c=!0,l.push({index:this.colIndex,width:r})}else if(i[this.colIndex+1]){let e=a+i[this.colIndex+1].width;r=Math.min(e-n.colMinWidthPre,r),c=!0,l.push({index:this.colIndex,width:r},{index:this.colIndex+1,width:e-r})}}else this.tableBlot.domNode.style.width=`${Number.parseFloat(this.tableBlot.domNode.style.width)-i[this.colIndex].domNode.getBoundingClientRect().width+o}px`,c=!0,l.push({index:this.colIndex,width:o});if(c){let e=this.tableBlot.domNode.getBoundingClientRect().width;if(s){let t=0,n=new Set(l.map(({index:e,width:n})=>(t+=n,e)));for(let[e,r]of i.entries())n.has(e)||(t+=r.width);if(t>100){if(!await fe({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableBlot.cancelFull(),s=!1;for(let[t,n]of l.entries()){let{width:r,index:i}=n;l[t]={index:i,width:r/100*e}}}}for(let{index:e,width:t}of l){let n=Number.parseFloat(t.toFixed(3));i[e].width=`${n}${s?`%`:`px`}`}this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}}findDragRowIndex(e){return-1}calculateRowDragRange(){if(!this.tableBlot)return;let e=this.tableBlot.getRows();if(this.rowIndex=this.findDragRowIndex(e),this.rowIndex===-1)return;let t=e[this.rowIndex].domNode.getBoundingClientRect();this.dragYCommon.minRange=t.y+n.rowMinHeightPx,this.dragYCommon.maxRange=1/0}updateTableRow(e){if(!this.tableBlot||this.rowIndex===-1)return;let t=this.dragYCommon.limitRange(this.tableBlot,e,!0),n=this.tableBlot.getRows(),i=t-n[this.rowIndex].domNode.getBoundingClientRect().top;n[this.rowIndex].setHeight(`${i}px`),this.quill.emitter.emit(r.AFTER_TABLE_RESIZE)}removeBreak(){this.dragXCommon.dragBreak&&(this.dragXCommon.dragBreak.remove(),this.dragXCommon.dragBreak=null),this.dragYCommon.dragBreak&&(this.dragYCommon.dragBreak.remove(),this.dragYCommon.dragBreak=null)}};const Q=e.import(`delta`);var Pr=class extends cn{minusY=0;minusX=0;checkMinY(e){return this.mouseY+this.minusY<e.top+this.scrollThresholdY}checkMinX(e){return this.mouseX+this.minusX<e.left+this.scrollThresholdX}},Fr=class{startPosition=[];selectedIndex=new Set;moveToIndex=-1;tableModule;tableBlot;dragCommon;options;get isDragX(){return this.options.isDragX}constructor(e,t,n,r){this.tableModule=e,this.tableBlot=t,this.dragCommon=n,this.options=r}onStart(e,t,n){let r=this.tableModule.getModule(i.tableSelectionName);if(!r?.boundary||!this.tableBlot)return!1;let{isSpan:a,cellIndex:o}=jr(this.isDragX,this.tableBlot,r.selectedTds);if(!a)return!1;let{rect:s}=Y(this.tableBlot);if(!s)return!1;t.preventDefault(),this.dragCommon.startValue=this.isDragX?s.x:s.y,this.selectedIndex=o,n?.(this),this.recalculateStartPosition()}onMove(e,t,n){this.moveToIndex=this.findTheMovedToIndex(t),n?.(this)}onEnd(e,t,n){n?.(this),this.moveToIndex=-1,this.selectedIndex=new Set}recalculateStartPosition(){if(this.isDragX){if(this.startPosition=[],!this.tableBlot)return;let e=this.tableBlot.getCols(),t=e[0].domNode.getBoundingClientRect().left;for(let n=0;n<e.length;n++){let r=e[n].domNode.getBoundingClientRect();this.startPosition.push({size:r.width,position:t,index:n}),t+=r.width}}else{if(this.startPosition=[],!this.tableBlot)return;this.startPosition=this.tableBlot.getRows().map((e,t)=>{let n=e.domNode.getBoundingClientRect();return{size:n.height,position:n.top,index:t}})}}findTheMovedToIndex(e){let t=this.dragCommon.getOffsetFromStart(this.tableBlot),n=this.startPosition.find(({position:n,size:r})=>(this.isDragX?e.clientX:e.clientY)<n+r/2+t)?.index;return(ae(n)||n<0)&&(n=this.startPosition.length),n=Math.max(0,Math.min(n,this.startPosition.length)),this.selectedIndex.has(n)||this.options.allowMoveToIndex&&!this.options.allowMoveToIndex(n)?-1:n}updateTableStructure(e,t){let n=new Q;if(!this.tableBlot||this.moveToIndex<0)return n;let r=this.tableModule.getModule(i.tableSelectionName);if(!r)return n;if(this.isDragX){let i=this.tableBlot.getCols(),a=i.length-1,o=this.moveToIndex>a,s=new Set(r.selectedTds.map(e=>e.colId)),c=i.filter(e=>s.has(e.colId)).map(t=>{let n=t.length(),r=t.offset(t.scroll);return{offset:r,delta:e.slice(r,r+n),length:n}}),l=i[Math.min(a,this.moveToIndex)],u=l.offset(l.scroll)+(o?l.length():0),d=c.reduce((e,t)=>(e=e.concat(t.delta),e),new Q().retain(u)),f=c.reduce((e,t,n)=>{let r=c[n-1],i=r?r.offset+r.length:0;return e=e.retain(t.offset-i).delete(t.length),e},new Q),p=t?f.compose(d):d.compose(f),m=r.selectedTds.map(t=>{let n=t.length(),r=t.offset(t.scroll);return{offset:r,delta:e.slice(r,r+n),length:n,rowId:t.rowId}}),{delta:h,insertDeltaInfo:g}=m.reduce(({delta:e,insertDeltaInfo:n},r,i)=>{let a=m[i-1],o=a?a.offset+a.length:0,s=0;return i!==0&&!t&&(s=a.rowId===r.rowId?0:n[a.rowId]?.length()),e=e.retain(r.offset-o+s).delete(r.length),n[r.rowId]||(n[r.rowId]=new Q),n[r.rowId]=n[r.rowId].concat(r.delta),{delta:e,insertDeltaInfo:n}},{delta:new Q,insertDeltaInfo:{}}),_=this.tableBlot.getRows(),{delta:v}=_.reduce(({delta:e,offset:n},r,i)=>{let s=r.getCellByColumIndex(Math.min(a,this.moveToIndex))[0];if(!s)return{delta:e,offset:n};let c=s.offset(s.scroll)+(o?s.length():0),l=c-n;if(i!==0&&t){let e=g[_[i-1].rowId];e&&(l-=e.length())}return e.retain(l),g[s.rowId]&&(e=e.concat(g[s.rowId])),{delta:e,offset:c}},{delta:new Q,offset:0}),y=t?h.compose(v):v.compose(h);n=p.compose(y)}else{let i=this.tableBlot.getRows(),a=i.length-1,o=this.moveToIndex>a,s=i[Math.min(a,this.moveToIndex)],c=Array.from(r.selectedTds.reduce((e,t)=>e.add(t.getTableRow()),new Set)).filter(Boolean),l=0,{delta:u,start:d,end:f}=c.reduce(({delta:e,start:t,end:n},r)=>{let i=r.offset(r.scroll),a=r.length();return e.retain(i-l).delete(a),l=i+a,{delta:e,start:Math.min(t,i),end:Math.max(n,i+a)}},{delta:new Q,start:1/0,end:0}),p=s.offset(s.scroll)+(o?s.length():0),m=new Q().retain(p).concat(e.slice(d,f));n=t?u.compose(m):m.compose(u)}return n}},Ir=class extends Nr{static moduleName=`table-resize-box`;options;root;tableWrapperBlot;resizeObserver;rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;bem=l(`resize-box`);draggingColIndex=-1;draggingRowIndex=-1;stopColDrag=[];stopRowDrag=[];dragWrapper=null;dragPlaceholder=null;markIndicator=null;dragTip=null;stopColMoveDrag=[];stopRowMoveDrag=[];autoScroller=null;updateContentDraggingPosition;cellSpanIndex=new Set;dragPlaceholderStartPosition={x:0,y:0};constructor(t,n,i){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.updateContentDraggingPosition=()=>this.updateContentDraggerPosition(null),this.root=this.tableModule.addContainer(this.bem.b()),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.on(r.TABLE_SELECTION_CHANGE,this.updateWrapperHead)}resolveOptions(e){return Object.assign({size:16,draggable:!0},e)}updateWrapperHead=()=>{if(!this.options.draggable)return;let e=this.tableModule.getModule(i.tableSelectionName);if(!e||!this.tableBlot)return;let{isSpan:t,cellIndex:n}=jr(!0,this.tableBlot,e.selectedTds),{isSpan:r,cellIndex:a}=jr(!1,this.tableBlot,e.selectedTds);if(t){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)));for(let t of e)t.classList.remove(this.bem.is(`selected`));if(!r)for(let t of Array.from(n).slice(0,-1))e[t].classList.add(this.bem.is(`selected`))}if(r){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`))),n=[];for(let t of e)t.classList.remove(this.bem.is(`selected`)),n[Number(t.dataset.index)]=t;if(!t)for(let e of Array.from(a).slice(0,-1))n[e]&&n[e].classList.add(this.bem.is(`selected`))}};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};setSelectionTable(t){if(this.table!==t){if(this.hide(),this.table=t,this.table){let t=e.find(this.table);t&&(this.tableBlot=t,this.tableWrapperBlot=this.tableBlot.parent),this.show()}this.update()}}handleResizerHeaderClick(e,t,n){if(!this.table)return;let{clientX:r,clientY:a}=n,o=this.table.getBoundingClientRect();n.shiftKey||(this.lastHeaderSelect=null);let s=[{x:e?o.left:r,y:e?a:o.top},{x:e?o.right:r,y:e?a:o.bottom}];if(this.lastHeaderSelect){let t,n;if(this.lastHeaderSelect.isX){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=Math.min(e.left,o.left),n=e.top+e.height/2}else{let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`)))[this.lastHeaderSelect.index].getBoundingClientRect();t=e.left+e.width/2,n=Math.min(e.top,o.top)}this.lastHeaderSelect.isX===e?e?(s[0].y=Math.min(s[0].y,n),s[1].y=Math.max(s[1].y,n)):(s[0].x=Math.min(s[0].x,t),s[1].x=Math.max(s[1].x,t)):(s[1]={x:Math.max(s[0].x,t),y:Math.max(s[0].y,n)},s[0]={x:Math.min(s[0].x,t),y:Math.min(s[0].y,n)})}else this.lastHeaderSelect={isX:e,index:t};let c=this.tableModule.getModule(i.tableSelectionName);c&&(c.table=this.table,c.setSelectedTds(c.computeSelectedTds(...s)),c.show())}findDragColIndex(){return this.draggingColIndex}findDragRowIndex(){return this.draggingRowIndex}updateContentDraggerPosition(e){if(!e||!this.dragWrapper||!this.markIndicator||!this.tableBlot||!this.tableWrapperBlot)return;let{rect:t}=Y(this.tableBlot);if(!t||e.moveToIndex<0)return;let n=this.tableWrapperBlot.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect();Object.assign(this.dragWrapper.style,{top:`${Math.max(t.y,n.y)-r.y}px`,left:`${Math.max(t.x,n.x)-r.x}px`});let{position:i}=e.startPosition[e.moveToIndex]||{},a=this.dragXCommon.getOffsetFromStart(this.tableBlot),o=this.dragYCommon.getOffsetFromStart(this.tableBlot),s=e.isDragX?{top:`${Math.max(t.y,n.y)-r.y}px`,left:`${i-r.left+a}px`}:{top:`${i-r.top+o}px`,left:`${Math.max(t.x,n.x)-r.x}px`};Object.assign(this.markIndicator.style,s)}createContentDragger(e,t,n){if(!this.tableBlot)return;let r=this.tableModule.getModule(i.tableSelectionName);if(!r||!this.tableWrapperBlot)return;r.updateWithSelectedTds();let a=r.boundary.width,o=r.boundary.height,s=this.quill.root.getBoundingClientRect(),c=this.tableWrapperBlot.domNode.getBoundingClientRect(),u=l(`drag`);this.dragWrapper=this.tableModule.addContainer(u.b());let d=c.x-s.x,f=c.y-s.y;Object.assign(this.dragWrapper.style,{left:`${d}px`,top:`${f}px`,width:`${c.width}px`,height:`${c.height}px`}),this.dragPlaceholder=document.createElement(`div`),this.dragPlaceholder.classList.add(u.be(`placeholder`),u.is(`hidden`)),this.dragWrapper.appendChild(this.dragPlaceholder),this.dragPlaceholderStartPosition={x:t?r.boundary.x-d:0,y:t?0:r.boundary.y-f},Object.assign(this.dragPlaceholder.style,{left:`${this.dragPlaceholderStartPosition.x}px`,top:`${this.dragPlaceholderStartPosition.y}px`,width:`${a}px`,height:`${o}px`}),this.markIndicator=this.tableModule.addContainer(u.be(`indicator`));let p=t?{top:`${f}px`,height:`${Math.min(r.boundary.height,c.height)}px`}:{left:`${d}px`,width:`${Math.min(r.boundary.width,c.width)}px`};Object.assign(this.markIndicator.style,p),this.updateContentDraggingPosition=()=>this.updateContentDraggerPosition(n),I.call(this,this.quill.root,this.updateContentDraggingPosition),I.call(this,this.tableWrapperBlot.domNode,this.updateContentDraggingPosition),this.dragTip=this.tableModule.addContainer(u.be(`tip`));let m=document.createElement(`div`);m.classList.add(u.be(`tip-content`)),this.dragTip.appendChild(m),t?(this.dragXCommon.minRange=0,this.dragXCommon.maxRange=c.width-a):(this.dragYCommon.minRange=0,this.dragYCommon.maxRange=c.height-o)}bindColEvents(){if(!this.tableWrapperBlot)return;let e=Array.from(this.root.getElementsByClassName(this.bem.be(`col-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`col-separator`)));if(I.call(this,this.tableWrapperBlot.domNode,()=>{this.colHeadWrapper.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft}),this.stopColMoveDrag.length>0){for(let e of this.stopColMoveDrag)e();this.stopColMoveDrag=[]}let n=new Fr(this.tableModule,this.tableBlot,this.dragXCommon,{isDragX:!0,allowMoveToIndex:e=>this.allowMoveToIndex(e)});for(let[t,r]of e.entries())if(r.addEventListener(`click`,this.handleResizerHeaderClick.bind(this,!1,t)),this.options.draggable){let{stop:e}=$t(r,this.dragHeadOptions(!0,{index:t,dragHelper:n}));this.stopColMoveDrag.push(e)}if(this.stopColDrag.length>0){for(let e of this.stopColDrag)e();this.stopColDrag=[]}for(let[e,n]of t.entries()){let{stop:t}=$t(n,{axis:`x`,onStart:(t,n)=>{if(this.dragging=!0,this.draggingColIndex=e,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let r=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:i}=Y(this.tableBlot);if(!i)return;this.dragXCommon.startValue=i.x;let a=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:`${Math.max(r.y,i.y)-a.y}px`,left:`${n.clientX-a.x}px`,height:`${Math.min(r.height,i.height)}px`})},onMove:({position:e})=>{if(!this.dragXCommon.dragBreak)return;let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=`${t-n.x}px`},onEnd:({position:e})=>{this.dragging=!1,this.updateTableCol(e.x),this.removeBreak()}});this.stopColDrag.push(t),n.addEventListener(`dragstart`,e=>e.preventDefault())}}bindRowEvents(){let e=Array.from(this.root.getElementsByClassName(this.bem.be(`row-header`))),t=Array.from(this.root.getElementsByClassName(this.bem.be(`row-separator`)));if(I.call(this,this.tableWrapperBlot.domNode,()=>{this.rowHeadWrapper.scrollTop=this.tableWrapperBlot.domNode.scrollTop}),this.stopRowMoveDrag.length>0){for(let e of this.stopRowMoveDrag)e();this.stopRowMoveDrag=[]}let n=new Fr(this.tableModule,this.tableBlot,this.dragYCommon,{isDragX:!1,allowMoveToIndex:e=>this.allowMoveToIndex(e)});for(let[t,r]of e.entries()){let e=Number(r.dataset.index||t);if(r.addEventListener(`click`,this.handleResizerHeaderClick.bind(this,!0,t)),this.options.draggable){let{stop:t}=$t(r,this.dragHeadOptions(!1,{index:e,dragHelper:n}));this.stopRowMoveDrag.push(t)}}if(this.stopRowDrag.length>0){for(let e of this.stopRowDrag)e();this.stopRowDrag=[]}for(let[e,n]of t.entries()){let{stop:t}=$t(n,{axis:`y`,onStart:(t,n)=>{if(this.dragging=!0,this.draggingRowIndex=e,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let r=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:i}=Y(this.tableBlot);if(!i)return;this.dragYCommon.startValue=i.y;let a=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:`${n.clientY-a.y}px`,left:`${Math.max(r.x,i.x)-a.x}px`,width:`${Math.min(r.width,i.width)}px`})},onMove:({position:e})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=`${t-n.y}px`},onEnd:({position:e})=>{this.dragging=!1,this.updateTableRow(e.y),this.removeBreak()}});this.stopRowDrag.push(t),n.addEventListener(`dragstart`,e=>e.preventDefault())}}allowMoveToIndex(e){return!this.cellSpanIndex.has(e)}recordCellSpan(e){let t=new Set;if(!this.tableBlot)return t;let n=this.tableBlot.descendants(H),r=e?this.tableBlot.getColIds():this.tableBlot.getRowIds(),i=e?`colspan`:`rowspan`;for(let a of n){if(a[i]<=1)continue;let n=r.indexOf(e?a.colId:a.rowId);if(n!==-1)for(let e=n+1;e<n+a[i]&&e<r.length;e++)t.add(e)}return t}dragHeadOptions(e,t){let{dragHelper:n,index:r}=t;return{axis:e?`x`:`y`,onStart:(t,i)=>{let a=!1;return n.onStart(t,i,()=>{if(!this.tableBlot)return;let t=(e?this.tableBlot.getCols():this.tableBlot.getRows()).length;if(n.selectedIndex.size>t){a=!1;return}let o=new Set(Array.from(n.selectedIndex).slice(0,-1));if(a=o.has(r),!o.has(r)){a=!1;return}this.dragging=!0,e?this.draggingColIndex=r:this.draggingRowIndex=r,this.createContentDragger(i,e,n),this.cellSpanIndex=this.recordCellSpan(e),this.tableWrapperBlot&&(this.autoScroller=new Pr(50,40),this.autoScroller.minusY=this.options.size,this.autoScroller.minusX=this.options.size,this.autoScroller.updateMousePosition(i.clientX,i.clientY),this.autoScroller.start(this.tableWrapperBlot.domNode))}),a},onMove:(t,r)=>{n.onMove(t,r,n=>{let{movePosition:i}=t;if(this.autoScroller?.updateMousePosition(r.clientX,r.clientY),!this.dragPlaceholder||!this.markIndicator||!this.dragTip||!this.tableWrapperBlot)return;this.dragPlaceholder.classList.remove(this.bem.is(`hidden`));let a=n.dragCommon.limitRange(this.tableBlot,this.dragPlaceholderStartPosition[e?`x`:`y`]+i[e?`x`:`y`],!1);if(this.dragPlaceholder.style[e?`left`:`top`]=`${a}px`,Object.assign(this.dragTip.style,{left:`${r.clientX-10}px`,top:`${r.clientY-10}px`}),n.moveToIndex<0){Object.assign(this.markIndicator.style,{opacity:`0`});return}let o=this.quill.root.getBoundingClientRect(),s=n.moveToIndex>=n.startPosition.length,c=n.startPosition[s?n.moveToIndex-1:n.moveToIndex],l=c.position+(s?c.size:0),u=n.dragCommon.getOffsetFromStart(this.tableBlot);Object.assign(this.markIndicator.style,{opacity:`1`,[e?`left`:`top`]:`${l-(e?o.left:o.top)+u}px`})})},onEnd:(t,r)=>{n.onEnd(t,r,t=>{let n=t.updateTableStructure(this.quill.getContents(),(e?this.draggingColIndex:this.draggingRowIndex)>t.moveToIndex);this.quill.updateContents(n),this.dragging=!1,this.cellSpanIndex=new Set,this.autoScroller?.stop(),an.call(this,this.quill.root,this.updateContentDraggingPosition),an.call(this,this.tableWrapperBlot.domNode,this.updateContentDraggingPosition),this.dragWrapper&&=(this.dragWrapper.remove(),null),this.markIndicator&&=(this.markIndicator.remove(),null),this.dragTip&&=(this.dragTip.remove(),null)})}}}update(){if(!this.tableBlot||!this.tableWrapperBlot)return;let{rect:e}=Y(this.tableBlot);if(!e)return;this.root.innerHTML=``;let t=this.tableBlot.getCols(),n=this.tableBlot.getRows(),r=this.tableWrapperBlot.domNode.getBoundingClientRect(),a=this.quill.root.getBoundingClientRect();if(Object.assign(this.root.style,{top:`${Math.max(e.y,r.y)-a.y}px`,left:`${Math.max(e.x,r.x)-a.x}px`}),t.length>0&&n.length>0&&(this.corner=document.createElement(`div`),this.corner.classList.add(this.bem.be(`corner`)),Object.assign(this.corner.style,{width:`${this.options.size}px`,height:`${this.options.size}px`}),this.corner.addEventListener(`click`,()=>{let e=this.tableModule.getModule(i.tableSelectionName);e&&this.tableBlot&&(e.setSelectedTds(this.tableBlot.descendants(H)),e.show(),e.updateWithSelectedTds())}),this.root.appendChild(this.corner)),t.length>0){let n=``;for(let r of t){let t=r.domNode.getBoundingClientRect().width;t===0&&(t=Number.parseInt(r.domNode.getAttribute(`width`),10)),n+=`<div class="${this.bem.be(`col-header`)}" style="width: ${t}px">
130
+ <div class="${this.bem.be(`col-separator`)}" style="height: ${e.height+this.options.size-3}px"></div>
131
+ </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`col`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`col-wrapper`)),Object.assign(i.style,{transform:`translateY(-${this.options.size}px)`,maxWidth:`${r.width}px`,height:`${this.options.size}px`}),Object.assign(a.style,{width:`${e.width}px`}),a.innerHTML=n,i.appendChild(a),this.root.appendChild(i),i.scrollLeft=this.tableWrapperBlot.domNode.scrollLeft,this.colHeadWrapper=i,this.bindColEvents()}if(n.length>0){let t=``;for(let r=0;r<n.length;r++){let i=r,a=n[r],o=a.domNode.getBoundingClientRect().height;if(a.children.length===1&&(a.children.head?.emptyRow.length||0)>0){let e=a.children.head.emptyRow.length;for(let t=r+1;t<n.length&&t<=r+e;t++){let e=n[t];o+=e.domNode.getBoundingClientRect().height}r+=e}t+=`<div class="${this.bem.be(`row-header`)}" data-index="${i}" style="height: ${o}px">
132
+ <div class="${this.bem.be(`row-separator`)}" style="width: ${e.width+this.options.size-3}px"></div>
133
+ </div>`}let i=document.createElement(`div`);i.classList.add(this.bem.be(`row`));let a=document.createElement(`div`);a.classList.add(this.bem.be(`row-wrapper`)),Object.assign(i.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${r.height}px`}),Object.assign(a.style,{height:`${e.height}px`}),a.innerHTML=t,i.appendChild(a),this.root.appendChild(i),i.scrollTop=this.tableWrapperBlot.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}let[o]=p(this.tableBlot,Ln),s=!o||o?.side!==`top`;s?this.root.classList.remove(this.bem.is(`caption-bottom`)):this.root.classList.add(this.bem.is(`caption-bottom`));let c=-1*this.options.size,l=-1*this.options.size;kr(this.tableBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c=Math.min(r.width,e.width),l=Math.min(r.width,e.width)):this.root.classList.remove(this.bem.is(`align-right`)),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${c}px)`,top:`${s?0:e.height+this.options.size}px`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`,maxHeight:`${r.height}px`}),this.colHeadWrapper&&Object.assign(this.colHeadWrapper.style,{top:`${s?0:e.height+this.options.size}px`,maxWidth:`${r.width}px`})}show(){!this.table||!this.tableBlot||(this.root.classList.remove(this.bem.is(`hidden`)),this.resizeObserver=rn(()=>this.update(),{ignoreFirstBind:!0}),this.resizeObserver.observe(this.table),this.update(),I.call(this,this.quill.root,()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is(`hidden`)),this.resizeObserver&&=(this.resizeObserver.disconnect(),void 0)}destroy(){this.hide(),L.call(this),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange);for(let[e,t]of this.scrollHandler)e.removeEventListener(`scroll`,t);this.root.remove()}},Lr=class extends Nr{static moduleName=`table-resize-line`;colResizer;rowResizer;currentTableCell;tableCellBlot;bem=l(`resize-line`);stopColDrag;stopRowDrag;scrollHandler=[];constructor(t,n){super(t,n),this.tableModule=t,this.quill=n,this.colResizer=this.tableModule.addContainer(this.bem.be(`col`)),this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}setSelectionTable(e){this.table!==e&&(this.hide(),this.table=e,this.table&&this.show())}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};findTableCell(e){for(let t of e.composedPath()){if(t instanceof HTMLElement&&[`TD`,`TH`].includes(t.tagName))return t;if(t===document.body)return null}return null}pointermoveHandler=n=>{if(this.dragging||this.tableModule.getModule(i.tableSelectionName)?.dragging)return;let r=this.findTableCell(n);if(!r)return this.hide();let a=e.find(r);a&&this.currentTableCell!==r&&(this.show(),this.currentTableCell=r,this.tableCellBlot=a,this.tableBlot=u(a,t.tableMain),this.tableBlot.getCols().length>0&&this.updateColResizer(),this.updateRowResizer(),I.call(this,this.quill.root,()=>{this.dragging||this.hideResizer()}))};findDragColIndex(e){return this.tableCellBlot?e.findIndex(e=>e.colId===this.tableCellBlot.colId):-1}updateColResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.colResizer)return;this.colResizer.remove();let{rect:e}=Y(this.tableBlot);if(!e)return;this.colResizer=this.tableModule.addContainer(this.bem.be(`col`));let t=this.tableCellBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),r=t.right-n.x;kr(this.tableBlot)&&(r=t.left-n.x),Object.assign(this.colResizer.style,{top:`${e.y-n.y}px`,left:`${r}px`,height:`${e.height}px`});let{stop:i}=$t(this.colResizer,{axis:`x`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateColDragRange(),this.dragXCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=Y(this.tableBlot);if(!r)return;this.dragXCommon.startValue=r.x;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragXCommon.dragBreak.style,{top:`${Math.max(n.y,r.y)-i.y}px`,left:`${t.clientX-i.x}px`,height:`${Math.min(n.height,r.height)}px`})},onMove:({position:e})=>{if(!this.dragXCommon.dragBreak)return;let t=this.dragXCommon.limitRange(this.tableBlot,e.x,!0),n=this.quill.root.getBoundingClientRect();this.dragXCommon.dragBreak.style.left=`${t-n.x}px`},onEnd:({position:e})=>{this.dragging=!1,this.updateTableCol(e.x),this.removeBreak()}});this.stopColDrag&&this.stopColDrag(),this.stopColDrag=i,this.colResizer.addEventListener(`dragstart`,e=>e.preventDefault())}findDragRowIndex(e){if(!this.tableCellBlot)return-1;let t=this.tableCellBlot.parent;return t instanceof U?e.indexOf(t):-1}updateRowResizer(){if(!this.tableBlot||!this.tableCellBlot||!this.rowResizer)return;let e=this.tableCellBlot;this.rowResizer.remove();let{rect:t}=Y(this.tableBlot);if(!t)return;this.rowResizer=this.tableModule.addContainer(this.bem.be(`row`));let n=e.domNode.getBoundingClientRect(),r=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:`${n.bottom-r.y}px`,left:`${t.x-r.x}px`,width:`${t.width}px`});let{stop:i}=$t(this.rowResizer,{axis:`y`,onStart:(e,t)=>{if(this.dragging=!0,this.calculateRowDragRange(),this.dragYCommon.createBreak(),!this.tableBlot)return;let n=this.tableBlot.domNode.parentElement.getBoundingClientRect(),{rect:r}=Y(this.tableBlot);if(!r)return;this.dragYCommon.startValue=r.y;let i=this.quill.root.getBoundingClientRect();Object.assign(this.dragYCommon.dragBreak.style,{top:`${t.clientY-i.y}px`,left:`${Math.max(n.x,r.x)-i.x}px`,width:`${Math.min(n.width,r.width)}px`})},onMove:({position:e})=>{if(!this.dragYCommon.dragBreak||!this.table)return;let t=this.dragYCommon.limitRange(this.tableBlot,e.y,!0),n=this.quill.root.getBoundingClientRect();this.dragYCommon.dragBreak.style.top=`${t-n.y}px`},onEnd:({position:e})=>{this.dragging=!1,this.updateTableRow(e.y),this.removeBreak()}});this.stopRowDrag&&this.stopRowDrag(),this.stopRowDrag=i,this.rowResizer.addEventListener(`dragstart`,e=>e.preventDefault())}show(){!this.table||!this.rowResizer||!this.colResizer||(this.rowResizer.classList.remove(this.bem.is(`hidden`)),this.colResizer.classList.remove(this.bem.is(`hidden`)),this.table.addEventListener(`pointermove`,this.pointermoveHandler))}hideResizer(){!this.rowResizer||!this.colResizer||(this.rowResizer.classList.add(this.bem.is(`hidden`)),this.colResizer.classList.add(this.bem.is(`hidden`)))}hide(){this.currentTableCell=void 0,L.call(this),this.hideResizer(),this.table&&this.table.removeEventListener(`pointermove`,this.pointermoveHandler)}destroy(){this.colResizer&&=(this.colResizer.remove(),void 0),this.rowResizer&&=(this.rowResizer.remove(),void 0),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}},Rr=class extends Hn{static moduleName=`table-resize-scale`;scrollHandler=[];tableMainBlot;tableWrapperBlot;bem=l(`scale`);startX=0;startY=0;offset=6;options;root;block;resizeobserver=new ResizeObserver(()=>this.update());constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(r),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};resolveOptions(e){return Object.assign({blockSize:12},e)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.block=document.createElement(`div`),this.block.classList.add(this.bem.be(`block`)),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let e=[],t=[],r=r=>{if(!this.tableMainBlot)return;let i=kr(this.tableMainBlot)?-1:1,a=(r.clientX-this.startX)*i,o=r.clientY-this.startY,s=Math.floor(a/e.length),c=Math.floor(o/t.length);for(let{blot:t,width:r}of e)t.width=Math.max(r+s,n.colMinWidthPx);for(let{blot:e,height:r}of t)e.setHeight(`${Math.max(r+c,n.rowMinHeightPx)}px`)},i=()=>{e=[],t=[],document.removeEventListener(`mousemove`,r),document.removeEventListener(`mouseup`,i)};this.block.addEventListener(`mousedown`,n=>{!this.tableMainBlot||this.isTableOutofEditor()||(this.startX=n.clientX,this.startY=n.clientY,e=this.tableMainBlot.getCols().map(e=>({blot:e,width:Math.floor(e.width)})),t=this.tableMainBlot.getRows().map(e=>({blot:e,height:Math.floor(e.domNode.getBoundingClientRect().height)})),document.addEventListener(`mousemove`,r),document.addEventListener(`mouseup`,i))}),this.block.addEventListener(`dragstart`,e=>e.preventDefault())}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;let e=this.tableMainBlot.domNode.getBoundingClientRect(),t=this.tableWrapperBlot.domNode.getBoundingClientRect();if(e.width>t.width){for(let n of this.tableMainBlot.getCols())n.width=Math.floor(n.width/e.width*t.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!this.block||!this.root||!this.tableMainBlot||!this.tableWrapperBlot)return;if(this.tableMainBlot.full){this.hide();return}let{rect:e}=Y(this.tableMainBlot);if(!e)return;let t=this.tableWrapperBlot.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),{scrollTop:r,scrollLeft:i}=this.tableWrapperBlot.domNode,a=this.options.blockSize*2+this.offset,o=Math.min(e.width,t.width)+a,s=Math.min(e.height,t.height)+a;Object.assign(this.root.style,{width:`${o}px`,height:`${s}px`,left:`${Math.max(e.x,t.x)-n.x-this.options.blockSize}px`,top:`${Math.max(e.y,t.y)-n.y-this.options.blockSize}px`});let c={left:`${e.width+a-i}px`,top:`${s-r}px`};kr(this.tableMainBlot)?(this.root.classList.add(this.bem.is(`align-right`)),c.left=`${this.options.blockSize+-1*i}px`):this.root.classList.remove(this.bem.is(`align-right`)),Object.assign(this.block.style,c)}show(){this.table&&(this.tableMainBlot=e.find(this.table),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.resizeobserver.observe(this.tableMainBlot.domNode),I.call(this,this.quill.root,()=>this.update())),this.buildResizer())}hide(){this.tableMainBlot=void 0,this.tableWrapperBlot=void 0,this.root&&(this.root.remove(),this.root=void 0,this.block=void 0)}destroy(){this.hide(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange),this.resizeobserver.disconnect(),L.call(this)}},zr=class{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=l(`scrollbar`);tableMainBlot;get isVertical(){return this.options.isVertical}constructor(t,n,r){this.quill=t,this.table=n,this.options=r,this.tableMainBlot=e.find(this.table),this.container=n.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(n),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),I.call(this,this.quill.root,()=>this.setScrollbarPosition()),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){let{rect:e,head:t,body:n,foot:r}=Y(this.tableMainBlot),i=t||n||r;if(!i||!e)return;let{scrollLeft:a,scrollTop:o,offsetLeft:s,offsetTop:c}=this.quill.root,{offsetLeft:l,offsetTop:u}=this.container,{offsetLeft:d,offsetTop:f}=i.domNode,{width:p,height:m}=this.container.getBoundingClientRect(),h=l+d-s,g=u+f-c;this.isVertical?h+=Math.min(p,e.width):g+=Math.min(m,e.height),this.tableMainBlot&&this.tableMainBlot.align!==`left`&&(h+=this.table.offsetLeft-l),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?Math.min(m,e.height):p}px`,transform:`translate(${h-a}px, ${g-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){let e=this.container.offsetHeight-this.gap,t=this.container.offsetWidth-this.gap,n=e**2/this.container.scrollHeight,r=t**2/this.container.scrollWidth,i=Math.max(n,this.minSize),a=Math.max(r,this.minSize);this.ratioY=n/(e-n)/(i/(e-i)),this.ratioX=r/(t-r)/(a/(t-a)),this.sizeWidth=a+this.gap<t?`${a}px`:``,this.sizeHeight=i+this.gap<e?`${i}px`:``,this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){let e=document.createElement(`div`);e.classList.add(this.bem.b(),this.isVertical?this.bem.is(`vertical`):this.bem.is(`horizontal`),this.bem.is(`transparent`)),Object.assign(e.style,{display:`none`}),this.thumb.classList.add(this.bem.be(`thumb`));let t=null,n=e=>{if(this.cursorDown===!1)return;let t=this.thumbState[this.propertyMap.axis];if(!t)return;let n=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],r=((this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-e[this.propertyMap.client])*-1-(this.thumb[this.propertyMap.offset]-t))*100*n/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=r*this.container[this.propertyMap.scrollSize]/100},r=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener(`mousemove`,n),document.removeEventListener(`mouseup`,r),this.cursorLeave&&this.hideScrollbar(),document.onselectstart=t},i=e=>{e.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener(`mousemove`,n),document.addEventListener(`mouseup`,r),t=document.onselectstart,document.onselectstart=()=>!1};this.thumb.addEventListener(`mousedown`,e=>{if(e.stopPropagation(),e.ctrlKey||[1,2].includes(e.button))return;window.getSelection()?.removeAllRanges(),i(e);let t=e.currentTarget;t&&(this.thumbState[this.propertyMap.axis]=t[this.propertyMap.offset]-(e[this.propertyMap.client]-t.getBoundingClientRect()[this.propertyMap.direction]))});let a=[this.table,e];for(let e of a)e.addEventListener(`mouseenter`,this.showScrollbar),e.addEventListener(`mouseleave`,this.hideScrollbar);return I.call(this,this.container,()=>{this.containerScrollHandler(this.container)}),e.appendChild(this.thumb),e}containerScrollHandler(e){let t=e[this.propertyMap.offset]-this.gap;this.move=e[this.propertyMap.scrollDirection]*100/t*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=mn(()=>{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=mn(()=>{this.cursorLeave=!0,!this.cursorDown&&(this.scrollbar.removeEventListener(`transitionend`,this.hideScrollbarTransitionend),this.scrollbar.addEventListener(`transitionend`,this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is(`transparent`)))},200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?`block`:`none`};destroy(){this.ob.disconnect(),L.call(this),this.table.removeEventListener(`mouseenter`,this.showScrollbar),this.table.removeEventListener(`mouseleave`,this.hideScrollbar)}},Br=class extends Hn{static moduleName=`table-scrollbar`;scrollbarContainer;scrollbar=[];bem=l(`scrollbar`);constructor(t,n,r){super(t,n),this.tableModule=t,this.quill=n;let i=l(`scrollbar`);this.quill.container.classList.add(i.bm(`virtual`)),this.scrollbarContainer=this.tableModule.addContainer(this.bem.be(`container`)),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange)}updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.update())};hide(){for(let e of this.scrollbar)e.destroy();this.scrollbar=[],this.scrollbarContainer.innerHTML=``}show(){if(this.table){this.scrollbar=[new zr(this.quill,this.table,{isVertical:!0}),new zr(this.quill,this.table,{isVertical:!1})];for(let e of this.scrollbar)this.scrollbarContainer.appendChild(e.scrollbar),e.showScrollbar()}}update(){if(this.table){this.scrollbar.length<=0&&this.show();for(let e of this.scrollbar)e.calculateSize(),e.setScrollbarPosition()}else this.scrollbar.length>0&&this.hide()}destroy(){this.hide(),this.scrollbarContainer.remove(),this.quill.off(e.events.TEXT_CHANGE,this.updateWhenTextChange)}},Vr=class extends Hn{static moduleName=i.tableSelectionName;options;boundary=null;scrollRecordEls=[];startScrollRecordPosition=[];selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;scrollHandler=[];resizeObserver;isDisplaySelection=!1;bem=l(`selection`);autoScroller;lastSelection={anchorNode:null,anchorOffset:0,focusNode:null,focusOffset:0};_dragging=!1;set dragging(e){this._dragging!==e&&(this._dragging=e,this.quill.emitter.emit(e?r.TABLE_SELECTION_DRAG_START:r.TABLE_SELECTION_DRAG_END,this))}get dragging(){return this._dragging}constructor(t,n,i={}){super(t,n),this.tableModule=t,this.quill=n,this.options=this.resolveOptions(i),this.scrollRecordEls=[this.quill.root,document.documentElement],this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=rn(this.updateAfterEvent,{ignoreFirstBind:!0}),this.resizeObserver.observe(this.quill.root),document.addEventListener(`paste`,this.handlePaste),this.quill.emitter.listenDOM(`selectionchange`,document,this.selectionChangeHandler.bind(this)),this.quill.on(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.on(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler),this.quill.on(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.autoScroller=new cn(50,40),this.hide()}handlePaste=e=>{if(!(document.activeElement&&this.quill.root.contains(document.activeElement))||this.quill.getSelection())return;let n=e.clipboardData;if(!n)return;e.preventDefault();let r=this.selectedTds;if(r.length<=0)return;let i=n.getData(`text/html`),a=this.quill.clipboard.convert({html:i}).ops.filter(e=>e.attributes?.[t.tableCellInner]);a.length!==0&&Gn({quill:this.quill,talbeModule:this.tableModule},r,a)};keyboardHandler=async e=>{if(e.ctrlKey)switch(e.key){case`c`:case`x`:await wr(this.tableModule,this.selectedTds,e.key===`x`);break}else (e.key===`Backspace`||e.key===`Delete`)&&this.removeCellBySelectedTds()};updateWhenTextChange=t=>{t===e.events.TEXT_CHANGE&&(this.table&&!this.quill.root.contains(this.table)?this.setSelectionTable(void 0):this.updateAfterEvent())};updateAfterEvent=()=>{for(let e of this.selectedTds)if(!e.domNode.isConnected){this.selectedTds=[];break}this.updateWithSelectedTds()};removeCellBySelectedTds(){let t=this.quill.getSelection(),n=document.activeElement;if(!(t||!this.quill.root.contains(n))){if(this.table){let t=e.find(this.table),n=t.descendants(H);if(this.selectedTds.length===n.length){t.remove();return}}for(let e of this.selectedTds){let t=e.clone();t.appendChild(e.scroll.create(`block`)),e.parent.insertBefore(t,e),e.remove()}}}setSelectedTds(e){let t=new Set(this.selectedTds),n=this.selectedTds.length===e.length&&e.every(e=>t.has(e));this.selectedTds=e,n||this.quill.emitter.emit(r.TABLE_SELECTION_CHANGE,this,this.selectedTds)}quillSelectionChangeHandler=(n,r,i)=>{if(i!==e.sources.API&&n&&!this.quill.composition.isComposing&&this.selectedTds.length>0){let e=this.quill.getFormat(n),[r]=this.quill.getLine(n.index),i=!!e[t.tableCellInner]&&!!r,a=r&&this.selectedTds.some(e=>e.domNode.contains(r.domNode));if(i&&!a)try{let e=u(r,t.tableCellInner);this.setSelectedTds([e]),this.updateWithSelectedTds()}catch{}else i&&a||this.hide()}};setSelectionData(e,t){let{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:a}=t;if(!n||!i)return;let o=document.createRange(),s=this.selectionDirectionUp(t);s?(o.setStart(n,r),o.setEnd(n,r)):(o.setStart(n,r),o.setEnd(i,a)),e.removeAllRanges(),e.addRange(o),s&&e.extend(i,a)}selectionDirectionUp(e){let{anchorNode:t,anchorOffset:n,focusNode:r,focusOffset:i}=e;if(!t||!r)return!1;if(t===r)return n>i;let a=t.compareDocumentPosition(r);return a&Node.DOCUMENT_POSITION_CONTAINS||a&Node.DOCUMENT_POSITION_CONTAINED_BY?(a&Node.DOCUMENT_POSITION_FOLLOWING)!==0:(a&Node.DOCUMENT_POSITION_PRECEDING)!==0}resolveOptions(e){return Object.assign({selectColor:`#0589f340`},e)}selectionChangeHandler(){let n=window.getSelection();if(!n)return;let{anchorNode:r,focusNode:i,anchorOffset:a,focusOffset:o}=n;if(!r||!i)return;let s=e.find(r),c=e.find(i);if(!s||!c||s.scroll!==this.quill.scroll||c.scroll!==this.quill.scroll)return;let l=f(s),u=f(c),d=l.has(t.tableColgroup),p=u.has(t.tableColgroup);if(d||p){let e=r,s=a,c=i,f=o;if(d){let n=l.get(t.tableWrapper).descendants(H);n.length>0&&(e=n[0].domNode,s=0)}if(p){let e=u.get(t.tableWrapper).descendants(H);e.length>0&&(c=e[0].domNode,f=0)}this.setSelectionData(n,{anchorNode:e,anchorOffset:s,focusNode:c,focusOffset:f});return}let m=l.has(t.tableCellInner),h=u.has(t.tableCellInner),g=m&&h;if(g){let e=l.get(t.tableCellInner),n=u.get(t.tableCellInner);g&&=e!==n}if(m&&h&&g||!m&&h||!h&&m){this.setSelectionData(n,this.lastSelection),this.selectedTds.length>0&&this.hide();return}this.lastSelection={anchorNode:r,anchorOffset:a,focusNode:i,focusOffset:o}}helpLinesInitial(){this.cellSelectWrap.style.setProperty(`--select-color`,this.options.selectColor);let e=document.createElement(`div`);return e.classList.add(this.bem.be(`line`)),this.cellSelectWrap.appendChild(e),e}computeSelectedTds(t,n){if(!this.table)return[];let r=e.find(this.table);if(!r)return[];let i=new Set(r.descendants(W).map((e,t)=>(e.index=t,e))),a=this.getScrollPositionDiff(),{rect:o}=Y(r);if(!o)return[];let s=t.x+a.x,c=t.y+a.y,l={x:Math.max(o.left,Math.min(n.x,s)),y:Math.max(o.top,Math.min(n.y,c)),x1:Math.min(o.right,Math.max(n.x,s)),y1:Math.min(o.bottom,Math.max(n.y,c))},u=new Set,d=!0;for(;d;){d=!1;for(let e of i){e.__rect||=e.domNode.getBoundingClientRect();let{x:t,y:n,right:r,bottom:a}=e.__rect;if(en({x:Math.floor(l.x),y:Math.floor(l.y),x1:Math.floor(l.x1),y1:Math.floor(l.y1)},{x:Math.floor(t),y:Math.floor(n),x1:Math.floor(r),y1:Math.floor(a)},0,u.size===0)){u.add(e),i.delete(e),l={x:Math.min(l.x,t),y:Math.min(l.y,n),x1:Math.max(l.x1,r),y1:Math.max(l.y1,a)},d=!0;break}}}for(let e of[...u,...i])delete e.__rect;return this.boundary=tn({...l,width:l.x1-l.x,height:l.y1-l.y},this.quill.root),Array.from(u).toSorted((e,t)=>e.index-t.index).map(e=>(delete e.index,e.getCellInner()))}getScrollPositionDiff(){let{x:e,y:t}=this.getTableViewScroll(),{x:n,y:r}=on(this.quill.root);return this.selectedTableScrollX=e,this.selectedTableScrollY=t,this.selectedEditorScrollX=n,this.selectedEditorScrollY=r,this.startScrollRecordPosition.reduce((e,{x:t,y:n},r)=>{let{x:i,y:a}=on(this.scrollRecordEls[r]);return e.x+=t-i,e.y+=n-a,e},{x:0,y:0})}recordScrollPosition(){this.clearRecordScrollPosition();for(let e of this.scrollRecordEls)this.startScrollRecordPosition.push(on(e))}clearRecordScrollPosition(){this.startScrollRecordPosition=[]}tableSelectHandler(t){let{button:n,target:r,clientX:i,clientY:a}=t,o=r.closest(`table`),s=r.closest(`caption`);if(n!==0||!o||s)return;this.setSelectionTable(o);let c=o.dataset.tableId,l={x:i,y:a};this.recordScrollPosition(),this.setSelectedTds(this.computeSelectedTds(l,l)),this.show();let u=e=>{this.dragging=!0;let{button:t,target:n,clientX:r,clientY:i}=e,a=n.closest(`.ql-table`),o=n.closest(`caption`);if(t!==0||o||!a||a.dataset.tableId!==c)return;let s={x:r,y:i};this.setSelectedTds(this.computeSelectedTds(l,s)),this.selectedTds.length>1&&this.quill.blur(),this.update(),this.autoScroller.updateMousePosition(r,i)},d=()=>{document.body.removeEventListener(`mousemove`,u,!1),document.body.removeEventListener(`mouseup`,d,!1),this.autoScroller.stop(),this.dragging=!1,this.clearRecordScrollPosition()};document.body.addEventListener(`mousemove`,u,!1),document.body.addEventListener(`mouseup`,d,!1);let f=e.find(o);if(!f)return;let p=f.parent.domNode;this.autoScroller.updateMousePosition(i,a),this.autoScroller.start(p)}updateWithSelectedTds(){if(this.selectedTds.length<=0){this.hide();return}let e={x:1/0,y:1/0},t={x:-1/0,y:-1/0};for(let n of this.selectedTds){let r=n.domNode.getBoundingClientRect();e.x=Math.min(e.x,r.left),e.y=Math.min(e.y,r.top),t.x=Math.max(t.x,r.right),t.y=Math.max(t.y,r.bottom)}this.setSelectedTds(this.computeSelectedTds(e,t)),this.selectedTds.length>0?this.update():this.hide()}update(){if(!this.table){this.hide();return}if(this.selectedTds.length===0||!this.boundary)return;let{x:e,y:t}=on(this.quill.root),{x:n,y:i}=this.getTableViewScroll(),a=this.table.parentElement.getBoundingClientRect(),o=this.quill.root.getBoundingClientRect(),s=a.x-o.x,c=a.y-o.y;Object.assign(this.cellSelect.style,{left:`${this.selectedEditorScrollX*2-e+this.boundary.x+this.selectedTableScrollX-n-s}px`,top:`${this.selectedEditorScrollY*2-t+this.boundary.y+this.selectedTableScrollY-i-c}px`,width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${s}px`,top:`${c}px`,width:`${a.width}px`,height:`${a.height}px`}),this.quill.emitter.emit(r.TABLE_SELECTION_DISPLAY_CHANGE,this)}getTableViewScroll(){return this.table?on(this.table.parentElement):{x:0,y:0}}setSelectionTable(e){this.table!==e&&(this.table=e,this.table?this.scrollRecordEls.push(this.table.parentElement):this.scrollRecordEls.pop())}showDisplay(){Object.assign(this.cellSelectWrap.style,{display:`block`}),this.isDisplaySelection=!0,this.table&&this.resizeObserver.observe(this.table)}show(){this.table&&(L.call(this),this.showDisplay(),this.update(),this.quill.root.addEventListener(`keydown`,this.keyboardHandler),I.call(this,this.quill.root,()=>{this.update()}),I.call(this,this.table.parentElement,()=>{this.update()}))}hideDisplay(){Object.assign(this.cellSelectWrap.style,{display:`none`}),this.isDisplaySelection=!1,this.table&&this.resizeObserver.unobserve(this.table)}hide(){L.call(this),this.quill.root.removeEventListener(`keydown`,this.keyboardHandler),this.hideDisplay(),this.boundary=null,this.setSelectedTds([]),this.setSelectionTable(void 0)}destroy(){this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),L.call(this),document.removeEventListener(`paste`,this.handlePaste),this.quill.off(r.AFTER_TABLE_RESIZE,this.updateAfterEvent),this.quill.off(e.events.EDITOR_CHANGE,this.updateWhenTextChange),this.quill.off(e.events.SELECTION_CHANGE,this.quillSelectionChangeHandler)}};const Hr=e.import(`parchment`),$=e.import(`delta`),Ur=e.import(`ui/icons`),Wr=e.import(`blots/break`),Gr=e.import(`blots/block`),Kr=e.import(`blots/block/embed`);function qr(e,{tableId:n,rowId:r,colId:i}){let a={tableId:n,rowId:r,colId:i,colspan:1,rowspan:1},o=e.create(t.tableCell,a),s=e.create(t.tableCellInner,a),c=e.create(`block`);return c.appendChild(e.create(`break`)),s.appendChild(c),o.appendChild(s),o}function Jr(e){o.delete(t.tableCellInner),Object.assign(t,e.blotName||{}),Object.assign(n,e.tableUpSize||{}),Object.assign(r,e.tableUpEvent||{}),Object.assign(i,e.tableUpInternal||{}),Zr.moduleName=i.moduleName,Zr.toolName=t.tableWrapper,z.blotName=t.container,Ln.blotName=t.tableCaption,J.blotName=t.tableWrapper,K.blotName=t.tableMain,q.blotName=t.tableColgroup,G.blotName=t.tableCol,Bn.blotName=t.tableHead,V.blotName=t.tableBody,zn.blotName=t.tableFoot,U.blotName=t.tableRow,W.blotName=t.tableCell,H.blotName=t.tableCellInner,o.add(t.tableCellInner)}function Yr(t,n){return w({onSelect:(r,i)=>{t.insertTable(r,i,e.sources.USER),n&&n.close()},customBtn:t.options.customBtn,texts:t.options.texts})}function Xr(n){return{bindInHead:!1,key:n?`ArrowUp`:`ArrowDown`,collapsed:!0,format:[t.tableCellInner],handler(r,i){let a=n?`prev`:`next`,o=n?`tail`:`head`;if(i.line[a])return!0;let s=this.quill.selection.getBounds(r.index),c=i.line.domNode.getBoundingClientRect();if(!s||!c)return!0;if(n){if(s.top-c.top>3)return!0}else if(c.bottom-s.bottom>3)return!0;let l,u,f,p;try{[l,u,f,p]=d(i.line,[t.tableWrapper,t.tableMain,t.tableRow,t.tableCell])}catch{return!0}let m=u.getColIds(),h=l.descendants(Ln,0)[0],g;if(h){let e=window.getComputedStyle(h.domNode);g=a===`next`&&e.captionSide===`bottom`?h:a===`next`?l.next:h}else g=l[a];if(i.line[a]||!g)return!0;let _=f[a];if(_){let t=m.indexOf(p.colId),n=_.getCellByColId(m[t],a);if(!n)return!0;let r=n.children[o];r.children&&(r=r.children[o]);let s=r.offset(this.quill.scroll)+Math.min(i.offset,r.length()-1);this.quill.setSelection(s,0,e.sources.USER)}else{let t=g.offset(this.quill.scroll)+(n?g.length()-1:0);this.quill.setSelection(t,0,e.sources.USER)}return!1}}}var Zr=class r{static moduleName=i.moduleName;static toolName=t.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:`Backspace`,collapsed:!0,offset:0,handler(e,n){let r=this.quill.getLine(e.index)[0];return r.prev instanceof J?(r.prev.remove(),!1):!(n.format[t.tableCellInner]&&r.offset(u(r,t.tableCellInner))===0)}},"forbid remove table by delete":{bindInHead:!0,key:`Delete`,collapsed:!0,handler(e,n){let r=this.quill.getLine(e.index),i=r[0],a=r[1];return!((i.next instanceof J||i.next instanceof G)&&a===i.length()-1||n.format[t.tableCellInner]&&i===u(i,t.tableCellInner).children.tail&&a===i.length()-1)}},"table up":Xr(!0),"table down":Xr(!1),"table caption break":{bindInHead:!0,key:`Enter`,shiftKey:null,format:[t.tableCaption],handler(e,t){return!1}}};static register(){J.allowedChildren=[K],K.allowedChildren=[q,Ln,Bn,V,zn],K.requiredContainer=J,Ln.requiredContainer=K,q.allowedChildren=[G],q.requiredContainer=K,Bn.allowedChildren=[U],Bn.requiredContainer=K,V.allowedChildren=[U],V.requiredContainer=K,zn.allowedChildren=[U],zn.requiredContainer=K,U.allowedChildren=[W],W.allowedChildren=[H,Wr],W.requiredContainer=U,H.requiredContainer=W;let n=new Set([`table`]),r=Object.entries(e.imports).filter(([e,t])=>{let r=e.split(`formats/`)[1];return e.startsWith(`formats/`)&&!n.has(r)&&(g(t,Gr)||g(t,Kr))}).reduce((e,[t,n])=>{let r=g(n,Kr)?En:wn;return e[t]=class extends h(n,[r]){static register(){}},e},{});e.register({"blots/scroll":Mn,"blots/block":wn,"blots/block/embed":En,...r,[`blots/${t.container}`]:z,[`formats/${t.tableCell}`]:W,[`formats/${t.tableCellInner}`]:H,[`formats/${t.tableRow}`]:U,[`formats/${t.tableHead}`]:Bn,[`formats/${t.tableBody}`]:V,[`formats/${t.tableFoot}`]:zn,[`formats/${t.tableCol}`]:G,[`formats/${t.tableColgroup}`]:q,[`formats/${t.tableCaption}`]:Ln,[`formats/${t.tableMain}`]:K,[`formats/${t.tableWrapper}`]:J,"modules/clipboard":or},!0)}quill;options;toolBox;fixTableByLisenter=mn(this.balanceTables,100);selector;resizeOb;modules={};get statics(){return this.constructor}constructor(e,t){this.quill=e,this.options=this.resolveOptions(t||{}),this.toolBox=this.initialContainer();let n=this.quill.getModule(`toolbar`);if(n&&this.quill.theme.pickers){let[,e]=(n.controls||[]).find(([e])=>e===this.statics.toolName)||[];if(e&&e.tagName.toLocaleLowerCase()===`select`){let t=this.quill.theme.pickers.find(t=>t.select===e);t&&(t.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,t),t.label.addEventListener(`mousedown`,()=>{if(!this.selector||!t)return;let{leftLimited:e}=nn(this.selector.getBoundingClientRect());if(e){let e=t.label.getBoundingClientRect();Object.assign(t.options.style,{transform:`translateX(calc(-100% + ${e.width}px))`})}else Object.assign(t.options.style,{transform:void 0})}))}}let i=this.quill.getModule(`keyboard`);for(let e of Object.values(r.keyboradHandler))e.bindInHead?i.bindings[e.key].unshift(e):i.addBinding(e.key,e);this.initModules(),this.quillHack(),this.listenBalanceCells()}initialContainer(){let e=l(`toolbox`),t=this.quill.addContainer(e.b());return this.resizeOb=new ResizeObserver(()=>{let e=this.quill.root.getBoundingClientRect(),{offsetLeft:n,offsetTop:r}=this.quill.root;Object.assign(t.style,{top:`${r}px`,left:`${n}px`,width:`${e.width}px`,height:`${e.height}px`})}),this.resizeOb.observe(this.quill.root),t}addContainer(e){if(C(e)){let t=document.createElement(`div`);for(let n of e.split(` `))t.classList.add(n);return this.toolBox.appendChild(t),t}else return this.toolBox.appendChild(e),e}resolveOptions(e){return Object.assign({customBtn:!1,texts:this.resolveTexts(e.texts||{}),full:!1,fullSwitch:!0,icon:Ur.table,autoMergeCell:!0,modules:[]},e)}resolveTexts(e){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`},e)}initModules(){for(let e of this.options.modules)this.modules[e.module.moduleName]=new e.module(this,this.quill,e.options)}getModule(e){return this.modules[e]}quillHack(){let n=this.quill.getSemanticHTML;this.quill.getSemanticHTML=((r=0,i)=>{let a=n.call(this.quill,r,i),o=e.import(`formats/${t.tableWrapper}`),s=new DOMParser().parseFromString(a,`text/html`);for(let e of Array.from(s.querySelectorAll(`.${o.className} caption[contenteditable], .${o.className} .${W.className} > [contenteditable]`)))e.removeAttribute(`contenteditable`);return s.body.innerHTML});let r=this.quill.format;this.quill.format=function(n,a,o=e.sources.API){if(!(this.scroll.query(n).prototype instanceof Hr.EmbedBlot)){let e=this.getModule(i.moduleName),s=this.getSelection(!0),c=this.getFormat(s),l=e.getModule(i.tableSelectionName);if(!c[t.tableCellInner]||s.length>0||e&&l&&l.selectedTds.length<=1)return r.call(this,n,a,o);if(e&&l&&l.selectedTds.length>0){let e=l.selectedTds,t=!1,r=[];for(let i of e){let e=i.offset(this.scroll),o=i.length();r.push({index:e,length:o}),this.getFormat(e,o)[n]!==a&&(t=!0)}let i=t?a:!1,s=new $;for(let[e,{index:t,length:a}]of r.entries()){let o=e===0?0:r[e-1].index+r[e-1].length;s.retain(t-o).retain(a,{[n]:i})}let c=this.updateContents(s,o);return this.blur(),c}}return r.call(this,n,a,o)};let a=this.quill.theme.modules.toolbar;if(a){let n=a.handlers?.clean;if(n){let r=(e,n,r=()=>``)=>{let i=this.quill.getText(e,n),[a,o]=this.quill.getLine(e+n),s=0,c=new $;a!=null&&(s=a.length()-o,c=a.delta().slice(o,o+s-1).insert(`
134
+ `));let l=this.quill.getContents(e,n+s),u=l.diff(new $().insert(i).concat(c)),d=0;return new $(u.ops.map(e=>{let{attributes:n,...i}=e;if(e.insert?d-=C(e.insert)?e.insert.length:1:e.retain?d+=re(e.retain)?e.retain:1:e.delete&&(d+=e.delete),n){let{[t.tableCellInner]:e,...a}=n;if(r){let e=l.slice(d-1,d).ops[0];if(e?.attributes?.[t.tableCellInner]){let{style:n,...o}=e.attributes[t.tableCellInner],s=r(n);return s?{...i,attributes:{...a,[t.tableCellInner]:{style:s,...o}}}:{...i,attributes:{...a,[t.tableCellInner]:o}}}}return{...i,attributes:{...a}}}return e}))};a.handlers.clean=function(a){let o=this.quill.getModule(i.moduleName),s=this.quill.getSelection();if(s&&s.length>0&&this.quill.getFormat(s)[t.tableCellInner]){let t=r(s.index,s.length,!1),n=new $().retain(s.index).concat(t);this.quill.updateContents(n,e.sources.USER);return}let c=o.getModule(i.tableSelectionName);if(o&&c&&c.selectedTds.length>0&&c.table){let t=e.find(c.table);if(!t){console.warn(`TableMainFormat not found`);return}let n=c.selectedTds,i=new Set,a=[];for(let e of n)if(e.parent instanceof W){for(let t of e.parent.getNearByCell(`top`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`bottom`}));for(let t of e.parent.getNearByCell(`left`))i.has(t)||(i.add(t),a.push({td:t,cleanBorder:`right`}));i.add(e.parent),a.push({td:e.parent,cleanBorder:!0})}let o=t.descendants(W),s=new Map(o.map((e,t)=>[e,t]));a.sort((e,t)=>s.get(e.td)-s.get(t.td));let l=new $,u=0;for(let{td:e,cleanBorder:t}of a){let n=e.getCellInner().offset(this.quill.scroll),i=e.getCellInner().length(),a=r(n,i-1,e=>{if(!e||t===!0)return``;let n=fn(e);return pn(Object.keys(n).filter(e=>!e.startsWith(un(`border-${t}`))).reduce((e,t)=>(e[t]=n[t],e),{}))}),o=new $().retain(n-u).concat(a);l=l.concat(o),u=n+i}this.quill.updateContents(l,e.sources.USER),n.length>1&&this.quill.blur();return}return n.call(this,a)}}}}async buildCustomSelect(e,t){if(!e||!x(e))return;let n=document.createElement(`div`);if(n.classList.add(`ql-custom-select`),this.selector=await e(this,t),n.appendChild(this.selector),this.options.fullSwitch){let e=l(`creator`),t=document.createElement(`label`);t.classList.add(e.be(`checkbox`));let r=document.createElement(`input`);r.type=`checkbox`,r.checked=this.options.full,r.addEventListener(`change`,()=>{this.options.full=r.checked});let i=document.createElement(`span`);i.textContent=this.options.texts.fullCheckboxText,t.appendChild(r),t.appendChild(i),n.appendChild(t)}t.options.innerHTML=``,t.options.appendChild(n)}setCellAttrs(e,t,n,r=!1){if(e.length!==0)for(let i of e)i.setFormatValue(t,n,r)}getTextByCell(e){let t=``;for(let n of e){let e=n.offset(this.quill.scroll),r=n.length();for(let n of this.quill.getContents(e,r).ops)C(n.insert)&&(t+=n.insert)}return t}getHTMLByCell(e,n=!1){if(e.length===0)return``;let r=null;try{for(let n of e){let e=u(n,t.tableMain);if(r||=e,e!==r)return console.error(`tableMain is not same`),``}}catch{return console.error(`tds must be in same tableMain`),``}if(!r)return``;let i=this.quill.getIndex(r),a=r.length(),o=this.quill.getSemanticHTML(i,a),s=new DOMParser().parseFromString(o,`text/html`),c=Array.from(s.querySelectorAll(`col`)),l=c.map(e=>e.dataset.colId),d=[],f=new Set,p=new Set;for(let t of e){f.add(t.colId);let e=t.colId,n=l.indexOf(e);for(let e=0;e<t.colspan;e++)f.add(l[n+e]);p.add(`${t.rowId}-${t.colId}`)}for(let e=0;e<c.length;e++){let t=c[e];f.has(t.dataset.colId)?d.push(t.getAttribute(`width`)):(t.remove(),c.splice(e--,1))}let m=0,h=null;for(let e of Array.from(s.querySelectorAll(`td, th`)))if(p.has(`${e.dataset.rowId}-${e.dataset.colId}`))h!==e.dataset.rowId&&(m+=1,h=e.dataset.rowId);else{let t=e.parentElement;e.remove(),t&&t.children.length<=0&&t.remove()}let g=c.map(e=>G.value(e));if(r.full){let e=g.reduce((e,t)=>t.width+e,0);for(let[t,n]of g.entries())n.width=Math.round(n.width/e*100),c[t].setAttribute(`width`,`${n.width}%`)}else{let e=0;for(let t of g)e+=t.width;let t=s.querySelector(`table`);t.style.width=`${e}px`}if(n){let t=r.getRows();if(m===t.length)this.removeCol(e);else for(let t of e)t.domNode.innerHTML=`<p><br></p>`}return s.body.innerHTML}insertTable(r,i,a=e.sources.API){if(r>=30||i>=30)throw Error(`Both rows and columns must be less than 30.`);this.quill.focus();let o=this.quill.getSelection();if(o==null)return;let[s]=this.quill.getLeaf(o.index);if(!s)return;if(c(s))throw Error(`Not supported ${s.statics.blotName} insert into table.`);let l=R(),u=Array(i).fill(0).map(()=>R()),d=this.calculateTableCellBorderWidth(),f=getComputedStyle(this.quill.root),p=Number.parseInt(f.paddingLeft),m=Number.parseInt(f.paddingRight),h=this.quill.root.scrollHeight>this.quill.root.clientHeight?sn({target:this.quill.root}):0,g=Number.parseInt(f.width)-p-m-d-h,_=this.options.full?`${Math.max(1/i*100,n.colMinWidthPre)}%`:`${Math.max(Math.floor(g/i),n.colMinWidthPx)}px`,v=[{retain:o.index}],y=this.quill.getContents(o.index,1),[,b]=this.quill.getLine(o.index);y.ops[0].insert!==`
135
135
  `&&b!==0&&v.push({insert:`
136
136
  `});for(let e=0;e<i;e++)v.push({insert:{[t.tableCol]:{width:_,tableId:l,colId:u[e],full:this.options.full}}});for(let e=0;e<r;e++){let e=R();for(let n=0;n<i;n++)v.push({insert:`
137
137
  `,attributes:{[t.tableCellInner]:{tableId:l,rowId:e,colId:u[n],rowspan:1,colspan:1}}})}this.quill.updateContents(new $(v),a),this.quill.setSelection(o.index+i,e.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){let e=`
138
- <table class="${q.className}">
138
+ <table class="${K.className}">
139
139
  <tbody>
140
140
  <tr>
141
- <td class="${G.className}"></td>
141
+ <td class="${W.className}"></td>
142
142
  </tr>
143
143
  </tbody>
144
144
  </table>
145
- `,t=document.createElement(`div`);t.className=Y.className,t.innerHTML=e,t.style.position=`absolute`,t.style.left=`-9999px`,t.style.top=`-9999px`,t.style.visibility=`hidden`,this.quill.root.appendChild(t);let n=window.getComputedStyle(t.querySelector(`td`)),r=Number.parseFloat(n.borderWidth)||0;return this.quill.root.removeChild(t),r}fixUnusuaDeletelTable(e){let t=e.getColIds();if(t.length===0){e.remove();return}let n=e.getBodys(),r=e.tableId;for(let e of n){let n=e.getRows();if(n.length===0){e.remove();continue}let i=Array(n.length).fill(0).map(()=>Array(t.length).fill(!1));for(let[e,a]of n.entries()){let o=0,s=0,c=i[e],l=a.descendants(G);for(;s<t.length;){if(c[s]){s+=1;continue}let u=l[o];if(!u||u.colId!==t[s])a.insertBefore(Rr(this.quill.scroll,{tableId:r,colId:t[s],rowId:a.rowId}),u);else{e+u.rowspan-1>=n.length&&(u.getCellInner().rowspan=n.length-e);let{colspan:t,rowspan:r}=u;if(t>1)for(let e=1;e<t;e++)c[s+e]=!0;if(r>1)for(let n=e+1;n<e+r;n++)for(let e=0;e<t;e++)i[n][s+e]=!0;o+=1}s+=1}if(o<l.length)for(let e=o;e<l.length;e++)l[e].remove()}}}balanceTables(){for(let e of this.quill.scroll.descendants(q))e.checkEmptyCol(this.options.autoMergeCell),e.checkEmptyRow(this.options.autoMergeCell),this.fixUnusuaDeletelTable(e)}listenBalanceCells(){this.quill.on(e.events.SCROLL_OPTIMIZE,t=>{t.some(e=>[`TD`,`TR`,`TBODY`,`TABLE`].includes(e.target.tagName)?(this.fixTableByLisenter(),!0):!1);for(let n of t){let t=n.target;if(t.tagName===`TABLE`){let n=e.find(t);if(n){n.sortMergeChildren();break}}}})}deleteTable(e){if(e.length===0)return;let n=u(e[0],t.tableMain);n&&n.remove()}appendRow(e,n){if(e.length<=0)return;let r=e[n?e.length-1:0],[i,a]=d(r,[t.tableMain,t.tableRow]),o=i.getRows().indexOf(a)+(n?r.rowspan:0);i.insertRow(o)}appendCol(e,n){if(e.length<=0)return;let[r]=e.reduce((e,t)=>{let r=t.getColumnIndex();return(!n&&r<=e[1]||n&&r>=e[1])&&(e=[t,r]),e},[e[0],e[0].getColumnIndex()]),i=r.getColumnIndex()+(n?r.colspan:0),a=u(r,t.tableMain),o=a.tableId,s=R(),[c]=a.descendants(J);c&&c.insertColByIndex(i,{tableId:o,colId:s,width:a.full?6:160,full:a.full});let l=a.getRows(),d=[],f=0;for(let e of Object.values(l)){let t=d.shift()||0;if(f>0){--f;continue}let n=e.insertCell(i-t,{tableId:o,rowId:e.rowId,colId:s,rowspan:1,colspan:1});n.skipRowNum&&(f+=n.skipRowNum);for(let[e,t]of n.entries())d[e]=(d[e]||0)+t}}fixTableByRemove(e){if(!this.options.autoMergeCell)return;let t=e.getRows(),n=e.getCols(),r=n.reduce((e,t)=>(e[t.colId]=0,e),{}),i=t.toReversed(),a=[];for(let[e,n]of i.entries()){let i=t.length-e-1;n.children.length<=0?a.push(i):n.foreachCellInner(e=>{let t=a.reduce((t,n)=>e.rowspan+i>n?t+1:t,0);e.rowspan-=t,r[e.colId]+=1})}let o=0;for(let e of Object.values(r))if(e===0){let e=[],n=0;for(let r of Object.values(t)){let t=e.shift()||0,i=[];n>0?(i=r.getCellByColumIndex(o-t)[2],--n):(i=r.removeCell(o-t),i.skipRowNum&&(n+=i.skipRowNum));for(let[t,n]of i.entries())e[t]=(e[t]||0)+n}}else o+=1;for(let e of n)r[e.colId]===0&&(e.prev?e.prev.width+=e.width:e.next&&(e.next.width+=e.width),e.remove())}removeRow(e){if(e.length<=0)return;let n=e[0],r=u(n,t.tableMain),i=r.getRows(),a=i.length,o=-1;for(let n of e){let e=u(n,t.tableRow),r=i.indexOf(e);r<a&&(a=r),r+n.rowspan>o&&(o=r+n.rowspan)}let s={};for(let e=a;e<Math.min(i.length,o);e++){let t=i[e];t.foreachCellInner(t=>{t.rowspan+e>o&&(s[t.colId]={rowspan:t.rowspan+e-o,colspan:t.colspan,colIndex:t.getColumnIndex()}),t.parent.remove()}),t.length()===0&&t.remove()}if(i[o]){let e=i[o],t=r.tableId;for(let[n,{colIndex:r,colspan:i,rowspan:a}]of Object.entries(s))e.insertCell(r,{tableId:t,rowId:e.rowId,colId:n,colspan:i,rowspan:a})}this.fixTableByRemove(r)}removeCol(e){if(e.length<=0)return;let n=e[0],r=u(n,t.tableMain),i={};for(let t of e)i[t.rowId]||(i[t.rowId]=0),i[t.rowId]+=t.colspan;let a=Math.max(...Object.values(i)),o=n.getColumnIndex(),s=r.descendants(W);for(let e=0;e<a;e++){let e=[],t=0;for(let n of Object.values(s)){let r=e.shift()||0;if(t>0){--t;continue}let i=n.removeCell(o-r);i.skipRowNum&&(t+=i.skipRowNum);for(let[t,n]of i.entries())e[t]=(e[t]||0)+n}}let[c]=r.descendants(J);if(c)for(let e=0;e<a;e++)c.removeColByIndex(o);this.fixTableByRemove(r)}mergeCells(n){if(n.length<=1)return;let r=n[0],i=r.getTableBody(),a=r.getTableRow();if(!i||!a)return;for(let e=1;e<n.length;e++){let t=n[e],r=t.getTableBody();if(r&&r!==i){let e=t.getTableRow();e&&(a.parent.insertBefore(e,a.next),a=e)}}i.convertBody(r.wrapTag);let o=n.reduce((e,t,n)=>{let r=t.colId;e[0][r]||(e[0][r]=0),e[0][r]+=t.rowspan;let i=t.rowId;return e[1][i]||(e[1][i]=0),e[1][i]+=t.colspan,n!==0&&(t.moveChildren(e[2]),t.parent.remove()),e},[{},{},r]),s=Math.max(...Object.values(o[0])),c=Math.max(...Object.values(o[1])),l=o[2];l.colspan=c,l.rowspan=s;let d=this.quill.getIndex(l);this.quill.setSelection({index:d,length:0},e.sources.SILENT);let f=u(l,t.tableMain);this.fixTableByRemove(f)}splitCell(e){if(e.length!==1)return;let n=e[0];if(n.colspan===1&&n.rowspan===1)return;let[r,i]=d(n,[t.tableMain,t.tableRow]),a=r.getRows(),o=r.tableId,s=n.getColumnIndex(),c=r.getColIds().slice(s,s+n.colspan).toReversed(),{emptyRow:l,...u}=n.formats()[t.tableCellInner],f=a.indexOf(i);if(f===-1)return;let p=a[f],m=n.rowspan;for(n.colspan=1,n.rowspan=1;p&&m>0;){for(let e of c){if(p===i&&e===n.colId)continue;p.insertCell(s+(p===i?1:0),{...u,tableId:o,rowId:p.rowId,colId:e,rowspan:1,colspan:1})}--m,f+=1,p=a[f]}}convertTableBodyByCells(e,t,n){let r,i,a=e.getRows();for(let e of t){let t=e.getTableRow();if(!t)continue;let n=a.indexOf(t);ae(r)&&(r=n),ae(i)&&(i=n),n<r?(i=r,r=n):n>i&&(i=n)}if(ae(r)||ae(i)){console.warn(`TableRow not found`);return}let o=a[r],s=a[i];e.split(s.offset(e)+s.length());let c=e.split(o.offset(e)),l=c.getRows(),[u]=c.getBodys(),d=u.clone();c.appendChild(d);for(let e of l)e.length()>0&&d.appendChild(e);d.convertBody(n),u.remove()}},Ur=Hr;export{Cn as BlockEmbedOverride,xn as BlockOverride,z as ContainerFormat,kn as ScrollOverride,Ar as Scrollbar,zn as TableAlign,V as TableBodyFormat,U as TableCaptionFormat,G as TableCellFormat,H as TableCellInnerFormat,nr as TableClipboard,K as TableColFormat,J as TableColgroupFormat,Rn as TableDomSelector,Fn as TableFootFormat,In as TableHeadFormat,q as TableMainFormat,Sr as TableMenuCommon,Cr as TableMenuContextmenu,wr as TableMenuSelect,Dr as TableResizeBox,Er as TableResizeCommon,Or as TableResizeLine,kr as TableResizeScale,W as TableRowFormat,Mr as TableSelection,Hr as TableUp,jr as TableVirtualScrollbar,Y as TableWrapperFormat,Xn as applyCellUpdates,t as blotName,le as createColorPicker,pe as createSelectBox,Zt as createTooltip,Ur as default,Br as defaultCustomSelect,u as findParentBlot,d as findParentBlots,Kn as getCellPositions,Wn as getCountByPosition,Hn as getTableCellStructure,X as getTableMainRect,qn as groupCellByRow,Tr as isTableAlignRight,Un as parsePasteDelta,Vn as pasteCells,Jn as pasteWithLoop,Gn as pasteWithStructure,Yn as prepareCellUpdate,R as randomId,Zn as removeOverlappingCells,Z as tableMenuTools,r as tableUpEvent,i as tableUpInternal,n as tableUpSize,zr as updateTableConstants};
145
+ `,t=document.createElement(`div`);t.className=J.className,t.innerHTML=e,t.style.position=`absolute`,t.style.left=`-9999px`,t.style.top=`-9999px`,t.style.visibility=`hidden`,this.quill.root.appendChild(t);let n=window.getComputedStyle(t.querySelector(`td`)),r=Number.parseFloat(n.borderWidth)||0;return this.quill.root.removeChild(t),r}fixUnusuaDeletelTable(e){let t=e.getColIds();if(t.length===0){e.remove();return}let n=e.getBodys(),r=e.tableId;for(let e of n){let n=e.getRows();if(n.length===0){e.remove();continue}let i=Array(n.length).fill(0).map(()=>Array(t.length).fill(!1));for(let[e,a]of n.entries()){let o=0,s=0,c=i[e],l=a.descendants(W);for(;s<t.length;){if(c[s]){s+=1;continue}let u=l[o];if(!u||u.colId!==t[s])a.insertBefore(qr(this.quill.scroll,{tableId:r,colId:t[s],rowId:a.rowId}),u);else{e+u.rowspan-1>=n.length&&(u.getCellInner().rowspan=n.length-e);let{colspan:t,rowspan:r}=u;if(t>1)for(let e=1;e<t;e++)c[s+e]=!0;if(r>1)for(let n=e+1;n<e+r;n++)for(let e=0;e<t;e++)i[n][s+e]=!0;o+=1}s+=1}if(o<l.length)for(let e=o;e<l.length;e++)l[e].remove()}}}balanceTables(){for(let e of this.quill.scroll.descendants(K))e.checkEmptyCol(this.options.autoMergeCell),e.checkEmptyRow(this.options.autoMergeCell),this.fixUnusuaDeletelTable(e)}listenBalanceCells(){this.quill.on(e.events.SCROLL_OPTIMIZE,t=>{t.some(e=>[`TD`,`TR`,`TBODY`,`TABLE`].includes(e.target.tagName)?(this.fixTableByLisenter(),!0):!1);for(let n of t){let t=n.target;if(t.tagName===`TABLE`){let n=e.find(t);if(n){n.sortMergeChildren();break}}}})}deleteTable(e){e.length!==0&&u(e[0],t.tableMain)?.remove()}appendRow(e,n){if(e.length<=0)return;let r=e[n?e.length-1:0],[i,a]=d(r,[t.tableMain,t.tableRow]),o=i.getRows().indexOf(a)+(n?r.rowspan:0);i.insertRow(o)}appendCol(e,n){if(e.length<=0)return;let[r]=e.reduce((e,t)=>{let r=t.getColumnIndex();return(!n&&r<=e[1]||n&&r>=e[1])&&(e=[t,r]),e},[e[0],e[0].getColumnIndex()]),i=r.getColumnIndex()+(n?r.colspan:0),a=u(r,t.tableMain),o=a.tableId,s=R(),[c]=a.descendants(q);c&&c.insertColByIndex(i,{tableId:o,colId:s,width:a.full?6:160,full:a.full});let l=a.getRows(),d=[],f=0;for(let e of Object.values(l)){let t=d.shift()||0;if(f>0){--f;continue}let n=e.insertCell(i-t,{tableId:o,rowId:e.rowId,colId:s,rowspan:1,colspan:1});n.skipRowNum&&(f+=n.skipRowNum);for(let[e,t]of n.entries())d[e]=(d[e]||0)+t}}fixTableByRemove(e){if(!this.options.autoMergeCell)return;let t=e.getRows(),n=e.getCols(),r=n.reduce((e,t)=>(e[t.colId]=0,e),{}),i=t.toReversed(),a=[];for(let[e,n]of i.entries()){let i=t.length-e-1;n.children.length<=0?a.push(i):n.foreachCellInner(e=>{let t=a.reduce((t,n)=>e.rowspan+i>n?t+1:t,0);e.rowspan-=t,r[e.colId]+=1})}let o=0;for(let e of Object.values(r))if(e===0){let e=[],n=0;for(let r of Object.values(t)){let t=e.shift()||0,i=[];n>0?(i=r.getCellByColumIndex(o-t)[2],--n):(i=r.removeCell(o-t),i.skipRowNum&&(n+=i.skipRowNum));for(let[t,n]of i.entries())e[t]=(e[t]||0)+n}}else o+=1;for(let e of n)r[e.colId]===0&&(e.prev?e.prev.width+=e.width:e.next&&(e.next.width+=e.width),e.remove())}removeRow(e){if(e.length<=0)return;let n=e[0],r=u(n,t.tableMain),i=r.getRows(),a=i.length,o=-1;for(let n of e){let e=u(n,t.tableRow),r=i.indexOf(e);r<a&&(a=r),r+n.rowspan>o&&(o=r+n.rowspan)}let s={};for(let e=a;e<Math.min(i.length,o);e++){let t=i[e];t.foreachCellInner(t=>{t.rowspan+e>o&&(s[t.colId]={rowspan:t.rowspan+e-o,colspan:t.colspan,colIndex:t.getColumnIndex()}),t.parent.remove()}),t.length()===0&&t.remove()}if(i[o]){let e=i[o],t=r.tableId;for(let[n,{colIndex:r,colspan:i,rowspan:a}]of Object.entries(s))e.insertCell(r,{tableId:t,rowId:e.rowId,colId:n,colspan:i,rowspan:a})}this.fixTableByRemove(r)}removeCol(e){if(e.length<=0)return;let n=e[0],r=u(n,t.tableMain),i={};for(let t of e)i[t.rowId]||(i[t.rowId]=0),i[t.rowId]+=t.colspan;let a=Math.max(...Object.values(i)),o=n.getColumnIndex(),s=r.descendants(U);for(let e=0;e<a;e++){let e=[],t=0;for(let n of Object.values(s)){let r=e.shift()||0;if(t>0){--t;continue}let i=n.removeCell(o-r);i.skipRowNum&&(t+=i.skipRowNum);for(let[t,n]of i.entries())e[t]=(e[t]||0)+n}}let[c]=r.descendants(q);if(c)for(let e=0;e<a;e++)c.removeColByIndex(o);this.fixTableByRemove(r)}mergeCells(n){if(n.length<=1)return;let r=n[0],i=r.getTableBody(),a=r.getTableRow();if(!i||!a)return;for(let e=1;e<n.length;e++){let t=n[e],r=t.getTableBody();if(r&&r!==i){let e=t.getTableRow();e&&(a.parent.insertBefore(e,a.next),a=e)}}i.convertBody(r.wrapTag);let o=n.reduce((e,t,n)=>{let r=t.colId;e[0][r]||(e[0][r]=0),e[0][r]+=t.rowspan;let i=t.rowId;return e[1][i]||(e[1][i]=0),e[1][i]+=t.colspan,n!==0&&(t.length()>1&&t.moveChildren(e[2]),t.parent.remove()),e},[{},{},r]),s=Math.max(...Object.values(o[0])),c=Math.max(...Object.values(o[1])),l=o[2];l.colspan=c,l.rowspan=s;let d=this.quill.getIndex(l);this.quill.setSelection({index:d,length:0},e.sources.SILENT);let f=u(l,t.tableMain);this.fixTableByRemove(f)}splitCell(e){if(e.length!==1)return;let n=e[0];if(n.colspan===1&&n.rowspan===1)return;let[r,i]=d(n,[t.tableMain,t.tableRow]),a=r.getRows(),o=r.tableId,s=n.getColumnIndex(),c=r.getColIds().slice(s,s+n.colspan).toReversed(),{emptyRow:l,...u}=n.formats()[t.tableCellInner],f=a.indexOf(i);if(f===-1)return;let p=a[f],m=n.rowspan;for(n.colspan=1,n.rowspan=1;p&&m>0;){for(let e of c)p===i&&e===n.colId||p.insertCell(s+(p===i?1:0),{...u,tableId:o,rowId:p.rowId,colId:e,rowspan:1,colspan:1});--m,f+=1,p=a[f]}}convertTableBodyByCells(e,t,n){let r,i,a=e.getRows();for(let e of t){let t=e.getTableRow();if(!t)continue;let n=a.indexOf(t);ae(r)&&(r=n),ae(i)&&(i=n),n<r?(i=r,r=n):n>i&&(i=n)}if(ae(r)||ae(i)){console.warn(`TableRow not found`);return}let o=a[r],s=a[i];e.split(s.offset(e)+s.length());let c=e.split(o.offset(e)),l=c.getRows(),[u]=c.getBodys(),d=u.clone();c.appendChild(d);for(let e of l)e.length()>0&&d.appendChild(e);d.convertBody(n),u.remove()}},Qr=Zr;export{En as BlockEmbedOverride,wn as BlockOverride,z as ContainerFormat,Mn as ScrollOverride,zr as Scrollbar,Un as TableAlign,V as TableBodyFormat,Ln as TableCaptionFormat,W as TableCellFormat,H as TableCellInnerFormat,or as TableClipboard,G as TableColFormat,q as TableColgroupFormat,Hn as TableDomSelector,zn as TableFootFormat,Bn as TableHeadFormat,K as TableMainFormat,Er as TableMenuCommon,Dr as TableMenuContextmenu,Or as TableMenuSelect,Ir as TableResizeBox,Nr as TableResizeCommon,Mr as TableResizeCommonHelper,Lr as TableResizeLine,Rr as TableResizeScale,U as TableRowFormat,Vr as TableSelection,Zr as TableUp,Br as TableVirtualScrollbar,J as TableWrapperFormat,er as applyCellUpdates,t as blotName,le as createColorPicker,w as createSelectBox,Qt as createTooltip,Qr as default,Yr as defaultCustomSelect,u as findParentBlot,d as findParentBlots,Xn as getCellPositions,Ar as getColRect,Jn as getCountByPosition,Kn as getTableCellStructure,Y as getTableMainRect,Zn as groupCellByRow,jr as isCellsSpan,kr as isTableAlignRight,qn as parsePasteDelta,Gn as pasteCells,Qn as pasteWithLoop,Yn as pasteWithStructure,$n as prepareCellUpdate,R as randomId,tr as removeOverlappingCells,X as tableMenuTools,r as tableUpEvent,i as tableUpInternal,n as tableUpSize,Jr as updateTableConstants};
146
146
  //# sourceMappingURL=index.js.map