quill-table-up 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/table-creator.css +1 -1
- package/package.json +9 -14
- package/src/__tests__/e2e/custom-creator.test.ts +44 -0
- package/src/__tests__/e2e/table-align.test.ts +39 -0
- package/src/__tests__/e2e/table-resize.test.ts +152 -0
- package/src/__tests__/e2e/table-scrollbar.test.ts +31 -0
- package/src/__tests__/e2e/table-selection.test.ts +83 -0
- package/src/__tests__/e2e/utils.ts +6 -0
- package/src/__tests__/unit/table-insert-blot.test.ts +464 -0
- package/src/__tests__/unit/table-insert-remove-merge.test.ts +1270 -0
- package/src/__tests__/unit/table-redo-undo.test.ts +909 -0
- package/src/__tests__/unit/utils.test-d.ts +49 -0
- package/src/__tests__/unit/utils.test.ts +715 -0
- package/src/__tests__/unit/utils.ts +216 -0
- package/src/__tests__/unit/vitest.d.ts +12 -0
- package/src/formats/container-format.ts +52 -0
- package/src/formats/index.ts +10 -0
- package/src/formats/overrides/block.ts +93 -0
- package/src/formats/overrides/blockquote.ts +8 -0
- package/src/formats/overrides/code.ts +8 -0
- package/src/formats/overrides/header.ts +8 -0
- package/src/formats/overrides/index.ts +6 -0
- package/src/formats/overrides/list.ts +10 -0
- package/src/formats/overrides/scroll.ts +51 -0
- package/src/formats/table-body-format.ts +92 -0
- package/src/formats/table-cell-format.ts +139 -0
- package/src/formats/table-cell-inner-format.ts +251 -0
- package/src/formats/table-col-format.ts +174 -0
- package/src/formats/table-colgroup-format.ts +133 -0
- package/src/formats/table-main-format.ts +143 -0
- package/src/formats/table-row-format.ts +147 -0
- package/src/formats/table-wrapper-format.ts +55 -0
- package/src/formats/utils.ts +3 -0
- package/src/index.ts +1157 -0
- package/src/modules/index.ts +5 -0
- package/src/modules/table-align.ts +116 -0
- package/src/modules/table-menu/constants.ts +140 -0
- package/src/modules/table-menu/index.ts +3 -0
- package/src/modules/table-menu/table-menu-common.ts +249 -0
- package/src/modules/table-menu/table-menu-contextmenu.ts +94 -0
- package/src/modules/table-menu/table-menu-select.ts +28 -0
- package/src/modules/table-resize/index.ts +5 -0
- package/src/modules/table-resize/table-resize-box.ts +293 -0
- package/src/modules/table-resize/table-resize-common.ts +343 -0
- package/src/modules/table-resize/table-resize-line.ts +163 -0
- package/src/modules/table-resize/table-resize-scale.ts +154 -0
- package/src/modules/table-resize/utils.ts +3 -0
- package/src/modules/table-scrollbar.ts +255 -0
- package/src/modules/table-selection.ts +262 -0
- package/src/style/button.less +45 -0
- package/src/style/color-picker.less +134 -0
- package/src/style/dialog.less +53 -0
- package/src/style/functions.less +9 -0
- package/src/style/index.less +89 -0
- package/src/style/input.less +64 -0
- package/src/style/select-box.less +51 -0
- package/src/style/table-creator.less +68 -0
- package/src/style/table-menu.less +122 -0
- package/src/style/table-resize-scale.less +31 -0
- package/src/style/table-resize.less +183 -0
- package/src/style/table-scrollbar.less +49 -0
- package/src/style/table-selection.less +15 -0
- package/src/style/tooltip.less +19 -0
- package/src/style/variables.less +1 -0
- package/src/svg/background.svg +1 -0
- package/src/svg/border.svg +1 -0
- package/src/svg/color.svg +1 -0
- package/src/svg/insert-bottom.svg +1 -0
- package/src/svg/insert-left.svg +1 -0
- package/src/svg/insert-right.svg +1 -0
- package/src/svg/insert-top.svg +1 -0
- package/src/svg/merge-cell.svg +1 -0
- package/src/svg/remove-column.svg +1 -0
- package/src/svg/remove-row.svg +1 -0
- package/src/svg/remove-table.svg +1 -0
- package/src/svg/split-cell.svg +1 -0
- package/src/types.d.ts +4 -0
- package/src/utils/bem.ts +23 -0
- package/src/utils/color.ts +109 -0
- package/src/utils/components/button.ts +22 -0
- package/src/utils/components/color-picker.ts +236 -0
- package/src/utils/components/dialog.ts +41 -0
- package/src/utils/components/index.ts +6 -0
- package/src/utils/components/input.ts +74 -0
- package/src/utils/components/table/creator.ts +86 -0
- package/src/utils/components/table/index.ts +2 -0
- package/src/utils/components/table/select-box.ts +83 -0
- package/src/utils/components/tooltip.ts +186 -0
- package/src/utils/constants.ts +99 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/is.ts +6 -0
- package/src/utils/position.ts +21 -0
- package/src/utils/types.ts +131 -0
- package/src/utils/utils.ts +139 -0
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ interface TableResizeScaleOptions {
|
|
|
42
42
|
blockSize: number;
|
|
43
43
|
}
|
|
44
44
|
interface TableCreatorTextOptions {
|
|
45
|
+
fullCheckboxText: string;
|
|
45
46
|
customBtnText: string;
|
|
46
47
|
confirmText: string;
|
|
47
48
|
cancelText: string;
|
|
@@ -59,6 +60,7 @@ interface TableTextOptions extends TableCreatorTextOptions {
|
|
|
59
60
|
interface TableUpOptions {
|
|
60
61
|
customSelect?: (tableModule: TableUp, picker: QuillThemePicker) => Promise<HTMLElement> | HTMLElement;
|
|
61
62
|
full: boolean;
|
|
63
|
+
fullSwtich: boolean;
|
|
62
64
|
customBtn: boolean;
|
|
63
65
|
texts: TableTextOptions;
|
|
64
66
|
icon: string;
|
|
@@ -853,6 +855,7 @@ declare class TableUp {
|
|
|
853
855
|
addContainer(classes: string | HTMLElement): HTMLElement;
|
|
854
856
|
resolveOptions(options: Partial<TableUpOptions>): TableUpOptions;
|
|
855
857
|
resolveTexts(options: Partial<TableTextOptions>): {
|
|
858
|
+
fullCheckboxText: string;
|
|
856
859
|
customBtnText: string;
|
|
857
860
|
confirmText: string;
|
|
858
861
|
cancelText: string;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"quill";const e={container:"table-up-container",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableBody:"table-up-body",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},s={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:"100",rowMinHeightPx:36},i={AFTER_TABLE_RESIZE:"after-table-resize"},o=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],n=(t,e="table-up")=>{const s=e?`${e}-`:"";return{b:()=>`${s}${t}`,be:e=>e?`${s}${t}__${e}`:"",bm:e=>e?`${s}${t}--${e}`:"",bem:(e,i)=>e&&i?`${s}${t}__${e}--${i}`:"",ns:t=>t?`${s}${t}`:"",bs:e=>e?`${s}${t}-${e}`:"",cv:t=>t?`--${s}${t}`:"",is:t=>`is-${t}`}},l=t=>"function"==typeof t,r=Array.isArray,a=t=>"string"==typeof t,c=t=>{const{type:e="default",content:s}=t||{},i=n("button"),o=document.createElement("button");return o.classList.add(i.b(),e),s&&(a(s)?o.textContent=s:o.appendChild(s)),o},d=function(t,e){return t=Math.min(e,Math.max(0,Number.parseFloat(`${t}`))),Math.abs(t-e)<1e-6?1:t%e/Number.parseFloat(e)},h=t=>({h:Math.min(360,Math.max(0,t.h)),s:Math.min(100,Math.max(0,t.s)),b:Math.min(100,Math.max(0,t.b)),a:Math.min(1,Math.max(0,t.a))}),u=t=>{let{r:e,g:s,b:i,a:o}=t;e=d(e,255),s=d(s,255),i=d(i,255);const n=Math.max(e,s,i),l=Math.min(e,s,i);let r;const a=n,c=n-l,h=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(s-i)/c+(s<i?6:0);break;case s:r=(i-e)/c+2;break;case i:r=(e-s)/c+4}r/=6}return{h:360*r,s:100*h,b:100*a,a:o}},p=t=>{let{h:e,s:s,b:i,a:o}=t;e=6*d(e,360),s=d(s,100),i=d(i,100);const n=Math.floor(e),l=e-n,r=i*(1-s),a=i*(1-l*s),c=i*(1-(1-l)*s),h=n%6,u=[i,a,r,r,c,i][h],p=[c,i,i,a,r,r][h],b=[r,r,c,i,i,a][h];return{r:Math.round(255*u),g:Math.round(255*p),b:Math.round(255*b),a:o}},b=t=>{const e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(const t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")},m=t=>b(p(t)),f=(t={})=>{const e=230,s=150,i=10;let o=u((l=(l=t.color||"#ff0000").startsWith("#")?l.slice(1):l,{r:Number.parseInt(l.slice(0,2),16),g:Number.parseInt(l.slice(2,4),16),b:Number.parseInt(l.slice(4,6),16),a:Number((Number.parseInt(l.slice(6,8)||"ff",16)/255).toFixed(2))}));var l;const r=n("color-picker"),a=document.createElement("div");a.classList.add(r.b());const c=document.createElement("div");c.classList.add(r.be("content"));const d=document.createElement("div");d.classList.add(r.be("selector"));const f=document.createElement("div");f.classList.add(r.be("background")),d.appendChild(f);const g=document.createElement("div");g.classList.add(r.be("background-handle")),f.appendChild(g);const w=document.createElement("div");w.classList.add(r.be("alpha"));const v=document.createElement("div");v.classList.add(r.be("alpha-bg"));const x=document.createElement("div");x.classList.add(r.be("alpha-handle")),w.appendChild(v),w.appendChild(x);const C=document.createElement("div");C.classList.add(r.be("hue"));const y=document.createElement("div");y.classList.add(r.be("hue-handle")),C.appendChild(y);const M=document.createElement("div");M.classList.add(r.be("action"));const[I,L,N,E]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(r.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const i=document.createElement("input");return i.classList.add(r.be("input")),i.addEventListener("input",(()=>{i.value=i.value.replaceAll(/[^0-9]/g,"")})),i.addEventListener("change",(()=>{let e=Math.round(Number(i.value));"a"===t&&(e/=100);z(h(u(Object.assign({},p(o),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(i),M.appendChild(e),i}));c.appendChild(C),c.appendChild(d),c.appendChild(w),a.appendChild(c),a.appendChild(M);let S=!1,R=!1,T=!1;function B(){const t=m(o);for(const[e,s]of[I,L,N].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));E.value=String((100*o.a).toFixed(0))}function k(){Object.assign(g.style,{left:`${Math.floor(e*o.s/100)}px`,top:`${Math.floor(s*(100-o.b)/100)}px`}),d.style.backgroundColor=`#${b(p({h:o.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*o.h/360)}px`,x.style.left=100*o.a+"%",function(){const{r:t,g:e,b:s}=p(o);v.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),B()}function z(e){o=h(Object.assign({},o,e)),B(),t.onChange&&t.onChange(`#${m(o)}`)}function O(t){const i=d.getBoundingClientRect(),o=i.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=i.left+document.body.scrollLeft;z({s:Math.floor(100*Math.max(0,Math.min(e,t.pageX-n))/e),b:Math.floor(100*(s-Math.max(0,Math.min(s,t.pageY-o)))/s)}),k()}function A(t){const e=C.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);z({h:Math.floor(360*(s-Math.max(0,Math.min(s,t.pageY-e)))/s)}),k()}function $(t){const{pageX:e}=t,s=w.getBoundingClientRect();let o=e-s.left;o=Math.max(i/2,o),o=Math.min(o,s.width-i/2),z({a:Math.round((o-5)/(s.width-10)*100)/100}),k()}function q(t){S&&(t.preventDefault(),O(t)),R&&(t.preventDefault(),A(t)),T&&(t.preventDefault(),$(t))}function W(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",W),S=!1}function H(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",H),R=!1}function D(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",D),T=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",W),S=!0,O(t)})),C.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",H),R=!0,A(t)})),w.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",D),T=!0,$(t)})),k(),a};let g=8e3;const w=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const i=n("dialog"),o=e,l=document.createElement("div");l.classList.add(i.b()),l.style.zIndex=String(g);const r=document.createElement("div");if(r.classList.add(i.be("overlay")),l.appendChild(r),t){const e=document.createElement("div");e.classList.add(i.be("content")),e.appendChild(t),r.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const a=getComputedStyle(o).overflow;o.style.overflow="hidden",o.appendChild(l);const c=()=>{s(),l.remove(),o.style.overflow=a};return l.addEventListener("click",c),g+=1,{dialog:l,close:c}},v=(t,e)=>{const s=n("input");e.type||(e.type="text"),e.value||(e.value="");const i=document.createElement("div");if(i.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,i.appendChild(e)}const o=document.createElement("div");o.classList.add(s.be("input"));const l=document.createElement("input");for(const t in e)l.setAttribute(t,e[t]);(e.max||e.min)&&l.addEventListener("blur",(()=>{e.max&&e.max<=Number(l.value)&&(l.value=String(e.max)),e.min&&e.min>=Number(l.value)&&(l.value=String(e.min))})),o.appendChild(l),i.appendChild(o),l.addEventListener("focus",(()=>{o.classList.add("focus")})),l.addEventListener("blur",(()=>{o.classList.remove("focus")}));return{item:i,input:l,errorTip:t=>{let e;o.classList.contains("error")?e=o.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),o.appendChild(e)),e.textContent=t,o.classList.add("error");return{removeError:()=>{o.classList.remove("error"),e.remove()}}}}},x=(t={})=>{const e=n("select-box"),s=document.createElement("div");s.classList.add(e.b());const i=document.createElement("div");i.classList.add(e.be("block"));for(let s=0;s<(t.row||8);s++)for(let o=0;o<(t.col||8);o++){const t=document.createElement("div");t.classList.add(e.be("item")),t.dataset.row=String(s+1),t.dataset.col=String(o+1),i.appendChild(t)}const o=()=>{const{row:t,col:e}=s.dataset;for(const t of Array.from(i.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;const o=Array.from(i.children);for(let s=0;s<o.length;s++){const{row:i,col:n}=o[s].dataset;if(i>t&&n>e)return;i<=t&&n<=e?o[s].classList.add("active"):o[s].classList.remove("active")}};if(i.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:e,col:i}=t.target.dataset;e&&i&&(s.dataset.row=e,s.dataset.col=i,o())})),i.addEventListener("mouseleave",(()=>{s.removeAttribute("data-row"),s.removeAttribute("data-col"),o()})),i.addEventListener("click",(()=>{const{row:e,col:i}=s.dataset;e&&i&&t.onSelect&&t.onSelect(Number(e),Number(i))})),s.appendChild(i),t.customBtn){const i=t.texts||{},o=document.createElement("div");o.classList.add(e.be("custom")),o.textContent=i.customBtnText||"Custom",o.addEventListener("click",(async()=>{const e=await(async(t={})=>{const e=n("table-creator"),s=document.createElement("div");s.classList.add(e.b());const i=document.createElement("div");i.classList.add(e.be("input"));const{item:o,input:l,errorTip:r}=v(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:d,errorTip:h}=v(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});i.appendChild(o),i.appendChild(a),s.appendChild(i);const u=document.createElement("div");u.classList.add(e.be("control"));const p=c({type:"confirm",content:t.confirmText||"Confirm"}),b=c({type:"default",content:t.cancelText||"Cancel"});u.appendChild(p),u.appendChild(b),s.appendChild(u);const m=(e=Number(l.value),s=Number(d.value))=>{if(Number.isNaN(e)||e<=0)r(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(s)||s<=0))return{row:e,col:s};h(t.notPositiveNumberError||"Please enter a positive integer")}},f=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",f))};return new Promise(((t,e)=>{const{close:i}=w({child:s,beforeClose:e});l.focus();for(const e of[l,d])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=m();e&&(t(e),i())}}));p.addEventListener("click",(async()=>{const e=m();e&&(t(e),i())})),document.addEventListener("keydown",f),b.addEventListener("click",i)}))})(i);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(o)}return s},C=Math.min,y=Math.max,M=Math.round,I=Math.floor,L=t=>({x:t,y:t}),N={left:"right",right:"left",bottom:"top",top:"bottom"},E={start:"end",end:"start"};function S(t,e,s){return y(t,C(e,s))}function R(t,e){return"function"==typeof t?t(e):t}function T(t){return t.split("-")[0]}function B(t){return t.split("-")[1]}function k(t){return"x"===t?"y":"x"}function z(t){return"y"===t?"height":"width"}function O(t){return["top","bottom"].includes(T(t))?"y":"x"}function A(t){return k(O(t))}function $(t){return t.replace(/start|end/g,(t=>E[t]))}function q(t){return t.replace(/left|right|bottom|top/g,(t=>N[t]))}function W(t){const{x:e,y:s,width:i,height:o}=t;return{width:i,height:o,top:s,left:e,right:e+i,bottom:s+o,x:e,y:s}}function H(t,e,s){let{reference:i,floating:o}=t;const n=O(e),l=A(e),r=z(l),a=T(e),c="y"===n,d=i.x+i.width/2-o.width/2,h=i.y+i.height/2-o.height/2,u=i[r]/2-o[r]/2;let p;switch(a){case"top":p={x:d,y:i.y-o.height};break;case"bottom":p={x:d,y:i.y+i.height};break;case"right":p={x:i.x+i.width,y:h};break;case"left":p={x:i.x-o.width,y:h};break;default:p={x:i.x,y:i.y}}switch(B(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function D(t,e){var s;void 0===e&&(e={});const{x:i,y:o,platform:n,rects:l,elements:r,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:u=!1,padding:p=0}=R(e,t),b=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),m=r[u?"floating"===h?"reference":"floating":h],f=W(await n.getClippingRect({element:null==(s=await(null==n.isElement?void 0:n.isElement(m)))||s?m:m.contextElement||await(null==n.getDocumentElement?void 0:n.getDocumentElement(r.floating)),boundary:c,rootBoundary:d,strategy:a})),g="floating"===h?{x:i,y:o,width:l.floating.width,height:l.floating.height}:l.reference,w=await(null==n.getOffsetParent?void 0:n.getOffsetParent(r.floating)),v=await(null==n.isElement?void 0:n.isElement(w))&&await(null==n.getScale?void 0:n.getScale(w))||{x:1,y:1},x=W(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-x.top+b.top)/v.y,bottom:(x.bottom-f.bottom+b.bottom)/v.y,left:(f.left-x.left+b.left)/v.x,right:(x.right-f.right+b.right)/v.x}}function j(){return"undefined"!=typeof window}function F(t){return X(t)?(t.nodeName||"").toLowerCase():"#document"}function P(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function V(t){var e;return null==(e=(X(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function X(t){return!!j()&&(t instanceof Node||t instanceof P(t).Node)}function Y(t){return!!j()&&(t instanceof Element||t instanceof P(t).Element)}function _(t){return!!j()&&(t instanceof HTMLElement||t instanceof P(t).HTMLElement)}function U(t){return!(!j()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof P(t).ShadowRoot)}function K(t){const{overflow:e,overflowX:s,overflowY:i,display:o}=et(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+s)&&!["inline","contents"].includes(o)}function Z(t){return["table","td","th"].includes(F(t))}function G(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function Q(t){const e=J(),s=Y(t)?et(t):t;return"none"!==s.transform||"none"!==s.perspective||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function J(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function tt(t){return["html","body","#document"].includes(F(t))}function et(t){return P(t).getComputedStyle(t)}function st(t){return Y(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function it(t){if("html"===F(t))return t;const e=t.assignedSlot||t.parentNode||U(t)&&t.host||V(t);return U(e)?e.host:e}function ot(t){const e=it(t);return tt(e)?t.ownerDocument?t.ownerDocument.body:t.body:_(e)&&K(e)?e:ot(e)}function nt(t,e,s){var i;void 0===e&&(e=[]),void 0===s&&(s=!0);const o=ot(t),n=o===(null==(i=t.ownerDocument)?void 0:i.body),l=P(o);if(n){const t=lt(l);return e.concat(l,l.visualViewport||[],K(o)?o:[],t&&s?nt(t):[])}return e.concat(o,nt(o,[],s))}function lt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function rt(t){const e=et(t);let s=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const o=_(t),n=o?t.offsetWidth:s,l=o?t.offsetHeight:i,r=M(s)!==n||M(i)!==l;return r&&(s=n,i=l),{width:s,height:i,$:r}}function at(t){return Y(t)?t:t.contextElement}function ct(t){const e=at(t);if(!_(e))return L(1);const s=e.getBoundingClientRect(),{width:i,height:o,$:n}=rt(e);let l=(n?M(s.width):s.width)/i,r=(n?M(s.height):s.height)/o;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const dt=L(0);function ht(t){const e=P(t);return J()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:dt}function ut(t,e,s,i){void 0===e&&(e=!1),void 0===s&&(s=!1);const o=t.getBoundingClientRect(),n=at(t);let l=L(1);e&&(i?Y(i)&&(l=ct(i)):l=ct(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==P(t))&&e}(n,s,i)?ht(n):L(0);let a=(o.left+r.x)/l.x,c=(o.top+r.y)/l.y,d=o.width/l.x,h=o.height/l.y;if(n){const t=P(n),e=i&&Y(i)?P(i):i;let s=t,o=lt(s);for(;o&&i&&e!==s;){const t=ct(o),e=o.getBoundingClientRect(),i=et(o),n=e.left+(o.clientLeft+parseFloat(i.paddingLeft))*t.x,l=e.top+(o.clientTop+parseFloat(i.paddingTop))*t.y;a*=t.x,c*=t.y,d*=t.x,h*=t.y,a+=n,c+=l,s=P(o),o=lt(s)}}return W({width:d,height:h,x:a,y:c})}function pt(t,e){const s=st(t).scrollLeft;return e?e.left+s:ut(V(t)).left+s}function bt(t,e,s){void 0===s&&(s=!1);const i=t.getBoundingClientRect();return{x:i.left+e.scrollLeft-(s?0:pt(t,i)),y:i.top+e.scrollTop}}function mt(t,e,s){let i;if("viewport"===e)i=function(t,e){const s=P(t),i=V(t),o=s.visualViewport;let n=i.clientWidth,l=i.clientHeight,r=0,a=0;if(o){n=o.width,l=o.height;const t=J();(!t||t&&"fixed"===e)&&(r=o.offsetLeft,a=o.offsetTop)}return{width:n,height:l,x:r,y:a}}(t,s);else if("document"===e)i=function(t){const e=V(t),s=st(t),i=t.ownerDocument.body,o=y(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),n=y(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let l=-s.scrollLeft+pt(t);const r=-s.scrollTop;return"rtl"===et(i).direction&&(l+=y(e.clientWidth,i.clientWidth)-o),{width:o,height:n,x:l,y:r}}(V(t));else if(Y(e))i=function(t,e){const s=ut(t,!0,"fixed"===e),i=s.top+t.clientTop,o=s.left+t.clientLeft,n=_(t)?ct(t):L(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:o*n.x,y:i*n.y}}(e,s);else{const s=ht(t);i={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return W(i)}function ft(t,e){const s=it(t);return!(s===e||!Y(s)||tt(s))&&("fixed"===et(s).position||ft(s,e))}function gt(t,e,s){const i=_(e),o=V(e),n="fixed"===s,l=ut(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=L(0);if(i||!i&&!n)if(("body"!==F(e)||K(o))&&(r=st(e)),i){const t=ut(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else o&&(a.x=pt(o));const c=!o||i||n?L(0):bt(o,r);return{x:l.left+r.scrollLeft-a.x-c.x,y:l.top+r.scrollTop-a.y-c.y,width:l.width,height:l.height}}function wt(t){return"static"===et(t).position}function vt(t,e){if(!_(t)||"fixed"===et(t).position)return null;if(e)return e(t);let s=t.offsetParent;return V(t)===s&&(s=s.ownerDocument.body),s}function xt(t,e){const s=P(t);if(G(t))return s;if(!_(t)){let e=it(t);for(;e&&!tt(e);){if(Y(e)&&!wt(e))return e;e=it(e)}return s}let i=vt(t,e);for(;i&&Z(i)&&wt(i);)i=vt(i,e);return i&&tt(i)&&wt(i)&&!Q(i)?s:i||function(t){let e=it(t);for(;_(e)&&!tt(e);){if(Q(e))return e;if(G(e))return null;e=it(e)}return null}(t)||s}const Ct={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:i,strategy:o}=t;const n="fixed"===o,l=V(i),r=!!e&&G(e.floating);if(i===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=L(1);const d=L(0),h=_(i);if((h||!h&&!n)&&(("body"!==F(i)||K(l))&&(a=st(i)),_(i))){const t=ut(i);c=ct(i),d.x=t.x+i.clientLeft,d.y=t.y+i.clientTop}const u=!l||h||n?L(0):bt(l,a,!0);return{width:s.width*c.x,height:s.height*c.y,x:s.x*c.x-a.scrollLeft*c.x+d.x+u.x,y:s.y*c.y-a.scrollTop*c.y+d.y+u.y}},getDocumentElement:V,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:i,strategy:o}=t;const n=[..."clippingAncestors"===s?G(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let i=nt(t,[],!1).filter((t=>Y(t)&&"body"!==F(t))),o=null;const n="fixed"===et(t).position;let l=n?it(t):t;for(;Y(l)&&!tt(l);){const e=et(l),s=Q(l);s||"fixed"!==e.position||(o=null),(n?!s&&!o:!s&&"static"===e.position&&o&&["absolute","fixed"].includes(o.position)||K(l)&&!s&&ft(t,l))?i=i.filter((t=>t!==l)):o=e,l=it(l)}return e.set(t,i),i}(e,this._c):[].concat(s),i],l=n[0],r=n.reduce(((t,s)=>{const i=mt(e,s,o);return t.top=y(i.top,t.top),t.right=C(i.right,t.right),t.bottom=C(i.bottom,t.bottom),t.left=y(i.left,t.left),t}),mt(e,l,o));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:xt,getElementRects:async function(t){const e=this.getOffsetParent||xt,s=this.getDimensions,i=await s(t.floating);return{reference:gt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:s}=rt(t);return{width:e,height:s}},getScale:ct,isElement:Y,isRTL:function(t){return"rtl"===et(t).direction}};function yt(t,e,s,i){void 0===i&&(i={});const{ancestorScroll:o=!0,ancestorResize:n=!0,elementResize:l="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=i,c=at(t),d=o||n?[...c?nt(c):[],...nt(e)]:[];d.forEach((t=>{o&&t.addEventListener("scroll",s,{passive:!0}),n&&t.addEventListener("resize",s)}));const h=c&&r?function(t,e){let s,i=null;const o=V(t);function n(){var t;clearTimeout(s),null==(t=i)||t.disconnect(),i=null}return function l(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),n();const{left:c,top:d,width:h,height:u}=t.getBoundingClientRect();if(r||e(),!h||!u)return;const p={rootMargin:-I(d)+"px "+-I(o.clientWidth-(c+h))+"px "+-I(o.clientHeight-(d+u))+"px "+-I(c)+"px",threshold:y(0,C(1,a))||1};let b=!0;function m(t){const e=t[0].intersectionRatio;if(e!==a){if(!b)return l();e?l(!1,e):s=setTimeout((()=>{l(!1,1e-7)}),1e3)}b=!1}try{i=new IntersectionObserver(m,{...p,root:o.ownerDocument})}catch(t){i=new IntersectionObserver(m,p)}i.observe(t)}(!0),n}(c,s):null;let u,p=-1,b=null;l&&(b=new ResizeObserver((t=>{let[i]=t;i&&i.target===c&&b&&(b.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame((()=>{var t;null==(t=b)||t.observe(e)}))),s()})),c&&!a&&b.observe(c),b.observe(e));let m=a?ut(t):null;return a&&function e(){const i=ut(t);!m||i.x===m.x&&i.y===m.y&&i.width===m.width&&i.height===m.height||s();m=i,u=requestAnimationFrame(e)}(),s(),()=>{var t;d.forEach((t=>{o&&t.removeEventListener("scroll",s),n&&t.removeEventListener("resize",s)})),null==h||h(),null==(t=b)||t.disconnect(),b=null,a&&cancelAnimationFrame(u)}}const Mt=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var s,i;const{x:o,y:n,placement:l,middlewareData:r}=e,a=await async function(t,e){const{placement:s,platform:i,elements:o}=t,n=await(null==i.isRTL?void 0:i.isRTL(o.floating)),l=T(s),r=B(s),a="y"===O(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=R(e,t);let{mainAxis:u,crossAxis:p,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return r&&"number"==typeof b&&(p="end"===r?-1*b:b),a?{x:p*d,y:u*c}:{x:u*c,y:p*d}}(e,t);return l===(null==(s=r.offset)?void 0:s.placement)&&null!=(i=r.arrow)&&i.alignmentOffset?{}:{x:o+a.x,y:n+a.y,data:{...a,placement:l}}}}},It=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:s,y:i,placement:o}=e,{mainAxis:n=!0,crossAxis:l=!1,limiter:r={fn:t=>{let{x:e,y:s}=t;return{x:e,y:s}}},...a}=R(t,e),c={x:s,y:i},d=await D(e,a),h=O(T(o)),u=k(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=S(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=S(b+d["y"===h?"top":"left"],b,b-d[t])}const m=r.fn({...e,[u]:p,[h]:b});return{...m,data:{x:m.x-s,y:m.y-i,enabled:{[u]:n,[h]:l}}}}}},Lt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var s,i;const{placement:o,middlewareData:n,rects:l,initialPlacement:r,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:u,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:m=!0,...f}=R(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=T(o),w=O(r),v=T(r)===r,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),C=u||(v||!m?[q(r)]:function(t){const e=q(t);return[$(t),e,$(e)]}(r)),y="none"!==b;!u&&y&&C.push(...function(t,e,s,i){const o=B(t);let n=function(t,e,s){const i=["left","right"],o=["right","left"],n=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return s?e?o:i:e?i:o;case"left":case"right":return e?n:l;default:return[]}}(T(t),"start"===s,i);return o&&(n=n.map((t=>t+"-"+o)),e&&(n=n.concat(n.map($)))),n}(r,m,b,x));const M=[r,...C],I=await D(e,f),L=[];let N=(null==(i=n.flip)?void 0:i.overflows)||[];if(d&&L.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const i=B(t),o=A(t),n=z(o);let l="x"===o?i===(s?"end":"start")?"right":"left":"start"===i?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=q(l)),[l,q(l)]}(o,l,x);L.push(I[t[0]],I[t[1]])}if(N=[...N,{placement:o,overflows:L}],!L.every((t=>t<=0))){var E,S;const t=((null==(E=n.flip)?void 0:E.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:N},reset:{placement:e}};let s=null==(S=N.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:S.placement;if(!s)switch(p){case"bestFit":{var k;const t=null==(k=N.filter((t=>{if(y){const e=O(t.placement);return e===w||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:k[0];t&&(s=t);break}case"initialPlacement":s=r}if(o!==s)return{reset:{placement:s}}}return{}}}},Nt=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:s,y:i,placement:o,rects:n,middlewareData:l}=e,{offset:r=0,mainAxis:a=!0,crossAxis:c=!0}=R(t,e),d={x:s,y:i},h=O(o),u=k(h);let p=d[u],b=d[h];const m=R(r,e),f="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const t="y"===u?"height":"width",e=n.reference[u]-n.floating[t]+f.mainAxis,s=n.reference[u]+n.reference[t]-f.mainAxis;p<e?p=e:p>s&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(T(o)),s=n.reference[h]-n.floating[t]+(e&&(null==(g=l.offset)?void 0:g[h])||0)+(e?0:f.crossAxis),i=n.reference[h]+n.reference[t]+(e?0:(null==(w=l.offset)?void 0:w[h])||0)-(e?f.crossAxis:0);b<s?b=s:b>i&&(b=i)}return{[u]:p,[h]:b}}}},Et=(t,e,s)=>{const i=new Map,o={platform:Ct,...s},n={...o.platform,_c:i};return(async(t,e,s)=>{const{placement:i="bottom",strategy:o="absolute",middleware:n=[],platform:l}=s,r=n.filter(Boolean),a=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:h}=H(c,i,a),u=i,p={},b=0;for(let s=0;s<r.length;s++){const{name:n,fn:m}=r[s],{x:f,y:g,data:w,reset:v}=await m({x:d,y:h,initialPlacement:i,placement:u,strategy:o,middlewareData:p,rects:c,platform:l,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[n]:{...p[n],...w}},v&&b<=50&&(b++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(c=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:o}):v.rects),({x:d,y:h}=H(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:o,middlewareData:p}})(t,e,{...o,platform:n})};let St;const Rt=(t,e={})=>{const{msg:s="",delay:i=150,content:o,direction:l="bottom",type:r="hover",container:a,onOpen:c,onClose:d,closed:h,onDestroy:u}=e,p=n("tooltip");if(s||o){St||(St=document.createElement("div"),document.body.appendChild(St));const e=a||St,n=document.createElement("div");let b,m,f;n.classList.add(p.b(),"hidden","transparent"),o?n.appendChild(o):s&&(n.textContent=s);const g=()=>{f&&f(),Et(t,n,{placement:l,middleware:[Lt(),It({limiter:Nt()}),Mt(4)]}).then((({x:t,y:e})=>{Object.assign(n.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{n.classList.add("hidden"),e.contains(n)&&e.removeChild(n),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(c){const t=c(s);if(!s&&t)return}e.appendChild(n),n.removeEventListener("transitionend",w),n.classList.remove("hidden"),f=yt(t,n,g),n.classList.remove("transparent")}),i)},x=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}n.addEventListener("transitionend",w,{once:!0}),n.classList.add("transparent")}),i)},C=()=>{const e=t=>{t.stopPropagation(),x(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{n.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{x(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,n],s=x.bind(void 0,!1),i=v.bind(void 0,!1);return{prepare:()=>{for(const t of e)t.addEventListener("mouseenter",i),t.addEventListener("mouseleave",s)},show:v,hide:x,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",i),t.removeEventListener("mouseleave",s)}}},click:C},{prepare:M,show:I,hide:L,destroy:N}=y[r]();M();const E=()=>{L(!0),u&&u(),N(),f&&f(),n.remove()};return{show:I,hide:L,destroy:E}}return null};function Tt(t,e,s=4){const{x:i,y:o,x1:n,y1:l}=t,{x:r,y:a,x1:c,y1:d}=e;return!(n<=r+s||i+s>=c||(l<=a+s||o+s>=d))}const Bt=()=>Math.random().toString(36).slice(2),kt=(t,e)=>{let s;return function(...i){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,i)}),e)}};function zt(t,e){let s=t.parent;for(;s&&s.statics.blotName!==e&&s!==t.scroll;)s=s.parent;if(s===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return s}function Ot(t,e){const s=new Array(e.length),i=new Map(e.map(((t,e)=>[t,e])));let o=t.parent;for(;o&&o!==t.scroll&&0!==i.size;){if(i.has(o.statics.blotName)){s[i.get(o.statics.blotName)]=o,i.delete(o.statics.blotName)}o=o.parent}if(i.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(i.keys()).join(", ")}`);return s}function At(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}function $t(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)At(s.prototype,t.prototype);return s}const qt=t=>{let{left:e,top:s,width:i,height:o}=t;const{clientWidth:n,clientHeight:l}=document.documentElement;let r=!1,a=!1;return e+i>n?(e=n-i-8,r=!0):e<0&&(e=8,r=!0),s+o>l?(s=l-o-8,a=!0):s<0&&(s=8,a=!0),{left:e,top:s,leftLimited:r,topLimited:a}};function Wt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Ht(){for(let t=0;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}const Dt=t.import("parchment"),jt=t.import("blots/container"),Ft=t.import("blots/block"),Pt=t.import("blots/block/embed");class Vt extends jt{static tagName;static blotName=e.container;static scope=Dt.Scope.BLOCK_BLOT;static allowedChildren=[Ft,Pt,jt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,s){const[i]=this.children.find(t);if(!i){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,s)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const Xt=t.import("parchment"),Yt=t.import("blots/block");class _t extends Yt{replaceWith(t,s){const i="string"==typeof t?this.scroll.create(t,s):t;if(i instanceof Xt.ParentBlot){if(i.statics.blotName===e.tableCellInner){const t=this.parent;if(t.statics.blotName===e.tableCellInner){if(null!=t&&t.insertBefore(i,this.prev?null:this.next),this.parent.statics.blotName===e.tableCellInner&&this.prev){let t=this;for(;t;){const e=t.next;i.appendChild(t),t=e}}else i.appendChild(this);if(t&&0===t.length()){t.parent.remove();const s=t.parent.parent;s.statics.blotName===e.tableRow&&0===s.children.length&&s.remove()}}else null!=t&&t.insertBefore(i,this.next),i.appendChild(this);return i}this.moveChildren(i)}return null!=this.parent&&(this.parent.insertBefore(i,this.next||void 0),this.remove()),this.attributes.copy(i),i}format(t,s){if(t!==e.tableCellInner||this.parent.statics.blotName!==t||s)super.format(t,s);else{const[t,s,i]=Ot(this,[e.tableCell,e.tableRow,e.tableWrapper]),o=i.next;let n=s.next,l=t.next;for(i.parent.insertBefore(this,o);l;){const t=l.next;i.parent.insertBefore(l,o),l=t}for(;n;){const t=n.next;i.parent.insertBefore(n,o),n=t}}}}const Ut=t.import("formats/blockquote");class Kt extends($t(Ut,[_t])){}const Zt=t.import("formats/code-block");class Gt extends($t(Zt,[_t])){}const Qt=t.import("formats/header");class Jt extends($t(Qt,[_t])){}const te=t.import("formats/list");class ee extends($t(te,[_t])){static register(){}}const se=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},ie=t.import("blots/block"),oe=t.import("blots/block/embed");class ne extends Vt{static blotName=e.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan"]);static defaultChild=ie;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:i,rowspan:o,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=i,r.dataset.rowspan=String(se(o)),r.dataset.colspan=String(se(n)),l&&(r.dataset.style=l),r}static formats(t){const{tableId:e,rowId:s,colId:i,rowspan:o,colspan:n,style:l}=t.dataset,r={tableId:e,rowId:s,colId:i,rowspan:Number(se(o)),colspan:Number(se(n))};return l&&(r.style=l),r}setFormatValue(t,e,s=!1){if(s){if(!this.statics.isAllowStyle(t))return;this.parent&&(this.parent.setFormatValue(t,e),this.domNode.dataset.style=this.parent.domNode.style.cssText)}else{if(!this.statics.allowDataAttrs.has(t))return;const s=`data-${t}`;e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s),this.parent&&this.parent.setFormatValue(t,e)}const i=this.descendants(ie,0);for(const t of i)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(t){this.setFormatValue("row-id",t)}get colId(){return this.domNode.dataset.colId}set colId(t){this.setFormatValue("col-id",t)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(t){this.setFormatValue("rowspan",t)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(t){this.setFormatValue("colspan",t)}getColumnIndex(){return zt(this,e.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,i){0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,i)}formats(){const t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:i}=this,o=this.next;return null!==o&&o.statics.blotName===this.statics.blotName&&o.rowId===e&&o.colId===t&&o.colspan===s&&o.rowspan===i}optimize(){const t=this.parent,s=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof oe){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==e.tableCell&&(this.wrap(e.tableCell,s),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,s){if(t.statics.blotName===this.statics.blotName){const i=t,o=this.statics.formats(i.domNode),n=this.statics.formats(this.domNode);if(Object.entries(n).every((([t,e])=>e===o[t])))return this.parent.insertBefore(i,this.next);{const[t,l]=Ot(this,[e.tableRow,e.tableCell]);if(s){const i=s.offset();if(i+1<this.length()){const s=this.scroll.create(e.tableCellInner,n);this.children.forEachAt(i+1,this.length(),(t=>{s.appendChild(t)})),t.insertBefore(s.wrap(e.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==i.rowId){if(s){const e=s.offset(t);t.split(e)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(e.tableRow,o),r=this.scroll.create(e.tableCell,o);return r.appendChild(i),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(i.wrap(e.tableCell,o),s?l:l.next)}}super.insertBefore(t,s)}}const le=t.import("parchment"),re=t.import("blots/scroll");class ae extends re{createBlock(t,s){let i,o={};if(t[e.tableCellInner])i=e.tableCellInner;else for(const[e,s]of Object.entries(t)){null!=this.query(e,le.Scope.BLOCK&le.Scope.BLOT)?i=e:o[e]=s}i===e.tableCellInner&&(o={...t},delete o[i]);const n=this.create(i||this.statics.defaultChild.blotName,i?t[i]:void 0);this.insertBefore(n,s||void 0);let l=n.length();n instanceof ne&&0===l&&(l+=1);for(const[t,e]of Object.entries(o))n.formatAt(0,l,t,e);return n}}class ce extends Vt{static blotName=e.tableRow;static tagName="tr";static className="ql-table-row";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,e.dataset.rowId=t.rowId,e}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}insertCell(t,s){const i=[],o=this.children.iterator();let n,l=0;for(;(n=o())&&(l+=n.colspan,!(l>t));)if(1!==n.rowspan)for(let t=0;t<n.rowspan-1;t++)i[t]=(i[t]||0)+n.colspan;if(n&&l-n.colspan<t){n.getCellInner().colspan+=1,1!==n.rowspan&&(i.skipRowNum=n.rowspan-1)}else{const t=this.scroll.create(e.tableCell,s),i=this.scroll.create(e.tableCellInner,s),o=this.scroll.create("block");o.appendChild(this.scroll.create("break")),i.appendChild(o),t.appendChild(i),this.insertBefore(t,n)}return i}getCellByColumIndex(t){const e=[];let s=null,i=0;if(t<0)return[s,i,e];const o=this.children.iterator();for(;s=o();){if(i+=s.colspan,1!==s.rowspan)for(let t=0;t<s.rowspan-1;t++)e[t]=(e[t]||0)+s.colspan;if(i>t)break}return[s,i,e]}removeCell(t){if(t<0)return[];const s=this.getCellByColumIndex(t),[i,o]=s,n=s[2];if(!i)return n;if(o-i.colspan<t||i.colspan>1){const[s]=i.descendants(ne);if(1!==i.colspan&&t===o-i.colspan){const t=zt(this,e.tableMain).getColIds();s.colId=t[t.indexOf(s.colId)+1]}1!==i.rowspan&&(n.skipRowNum=i.rowspan-1),s.colspan-=1}else i.remove();return n}foreachCellInner(t){const e=this.children.iterator();let s,i=0;for(;s=e();){const[e]=s.descendants(ne);if(t(e,i++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const s=this.parent,{tableId:i}=this;null!==s&&s.statics.blotName!==e.tableBody&&this.wrap(e.tableBody,i),super.optimize(t)}}class de extends Vt{static blotName=e.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const s=zt(this,e.tableMain);if(!s)return;const i=s.getColIds(),o=this.descendants(ce),n=new Set(i);let l=0;for(const e of o){if(l===t)break;e.foreachCellInner((e=>{if(l+e.rowspan>t&&(e.rowspan+=1,n.delete(e.colId),1!==e.colspan)){const t=i.indexOf(e.colId);for(let s=0;s<e.colspan-1;s++)n.delete(i[t+s+1])}})),l+=1}const r=s.tableId,a=Bt(),c=this.scroll.create(e.tableRow,{tableId:r,rowId:a});for(const t of n){const s=this.scroll.create("break").wrap("block").wrap(e.tableCellInner,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1}).wrap(e.tableCell,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1});c.appendChild(s)}this.insertBefore(c,o[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const s=this.parent;if(null!==s&&s.statics.blotName!==e.tableMain){const{tableId:t}=this;this.wrap(e.tableMain,{tableId:t})}super.optimize(t)}}class he extends Vt{static blotName=e.tableCell;static tagName="td";static className="ql-table-cell";static allowDataAttrs=new Set(["table-id","row-id","col-id"]);static allowAttrs=new Set(["rowspan","colspan"]);static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:i,rowspan:o,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=i,r.setAttribute("rowspan",String(se(o))),r.setAttribute("colspan",String(se(n))),l&&(r.style.cssText=l),r}static formats(t){const{tableId:e,rowId:s,colId:i}=t.dataset,o=Number(t.getAttribute("rowspan")),n=Number(t.getAttribute("colspan")),l={tableId:e,rowId:s,colId:i,rowspan:se(o),colspan:se(n)},r={};for(let e=0;e<t.style.length;e++){const s=t.style[e],i=t.style[s];this.isAllowStyle(String(s))&&!["initial","inherit"].includes(i)&&(r[s]=i)}const a=Object.entries(r);return a.length>0&&(l.style=a.map((([t,e])=>`${t}:${e}`)).join(";")),l}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let s=t;this.statics.allowDataAttrs.has(t)&&(s=`data-${t}`),e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s)}else this.statics.isAllowStyle(t)&&Object.assign(this.domNode.style,{[t]:e})}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute("rowspan"))}get colspan(){return Number(this.domNode.getAttribute("colspan"))}getCellInner(){return this.children.head}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:i}=this,o=this.next;return null!==o&&o.statics.blotName===this.statics.blotName&&o.rowId===e&&o.colId===t&&o.colspan===s&&o.rowspan===i}optimize(t){const s=this.parent,{tableId:i,rowId:o}=this;null!==s&&s.statics.blotName!==e.tableRow&&this.wrap(e.tableRow,{tableId:i,rowId:o}),super.optimize(t)}}const ue=t.import("blots/block/embed");class pe extends ue{scroll;domNode;static blotName=e.tableCol;static tagName="col";static validWidth(t,e){let i=Number.parseFloat(String(t));return Number.isNaN(i)&&(i=s[e?"colMinWidthPre":"colMinWidthPx"]),`${i}${e?"%":"px"}`}static create(t){const{width:e,tableId:s,colId:i,full:o,align:n}=t,l=super.create();return l.setAttribute("width",this.validWidth(e,!!o)),o&&(l.dataset.full=String(o)),n&&"left"!==n&&(l.dataset.align=n),l.dataset.tableId=s,l.dataset.colId=i,l}static value(t){const{tableId:e,colId:i}=t.dataset,o=t.getAttribute("width")||s.colDefaultWidth,n=t.dataset.align,l={tableId:e,colId:i,full:Object.hasOwn(t.dataset,"full")};return o&&(l.width=Number.parseFloat(o)),n&&(l.align=n),l}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){const e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:s[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=s[this.full?"colMinWidthPre":"colMinWidthPx"]),this.domNode.setAttribute("width",this.statics.validWidth(e,!!this.full))}get tableId(){return this.domNode.dataset.tableId}get colId(){return this.domNode.dataset.colId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){const t=this.next,{tableId:e,colId:s}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===s}optimize(t){const s=this.parent;if(null!=s&&s.statics.blotName!==e.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(e.tableColgroup,t)}zt(this,e.tableColgroup).align=this.align,super.optimize(t)}insertAt(t,s,i){if(null!=i)return void super.insertAt(t,s,i);const o=s.split("\n"),n=o.pop(),l=o.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),r=this.split(t),[a,c]=Ot(this,[e.tableColgroup,e.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let h=c.parent.parent,u=c.parent.next;if(d){const t=d.descendants(ne);if(t.length>0){const s=t[0],i=ne.formats(s.domNode),o=this.scroll.create("block"),n=o.wrap(e.tableCellInner,i).wrap(e.tableCell,i).wrap(e.tableRow,i).wrap(e.tableBody,i.tableId);a.parent.insertBefore(n,a.next),h=o,u=o.next}}for(const t of l)h.insertBefore(t,u);n&&h.insertBefore(this.scroll.create("text",n),u)}}class be extends Vt{static blotName=e.tableMain;static tagName="table";static className="ql-table";static create(t){const e=super.create(),{tableId:s,full:i,align:o}=t;return e.dataset.tableId=s,"right"===o||"center"===o?e.dataset.align=o:e.removeAttribute("date-align"),i&&(e.dataset.full=String(i)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,s){super(t,e),this.updateAlign()}colWidthFillTable(){if(this.full)return;const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?null:(this.domNode.style.width=`${e}px`,e)}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align"),this.updateAlign()}cancelFull(){if(!this.full)return;const t=this.getCols(),s=this.domNode.getBoundingClientRect().width;for(const e of t)e.domNode.removeAttribute("data-full"),e.width=e.width/100*s;const i=this.children.head;i&&i.statics.blotName===e.tableColgroup&&(i.full=!1),this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}updateAlign(){const t={marginLeft:null,marginRight:null};switch(this.align){case"center":t.marginLeft="auto",t.marginRight="auto";break;case"":case"left":t.marginRight="auto";break;case"right":t.marginLeft="auto"}Object.assign(this.domNode.style,t)}getRows(){return this.descendants(ce)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(pe)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const s=this.parent;null!==s&&s.statics.blotName!==e.tableWrapper&&this.wrap(e.tableWrapper,this.tableId),super.optimize(t)}}class me extends Vt{static blotName=e.tableColgroup;static tagName="colgroup";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full="true":this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let s,i=0;for(;(s=e())&&i!==t;)i++;return s}insertColByIndex(t,i){const o=this.parent;if(!(o instanceof be))throw new TypeError("TableColgroupFormat should be child of TableFormat");const n=this.findCol(t),l=this.scroll.create(e.tableCol,i);if(o.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=s.colMinWidthPre){e.width-=l.width;break}}this.insertBefore(l,n)}removeColByIndex(t){const e=this.parent;if(!(e instanceof be))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const s=this.findCol(t);s&&(e.full&&(s.next?s.next.width+=s.width:s.prev&&(s.prev.width+=s.width)),s.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof be&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const s=this.parent,{tableId:i,full:o,align:n}=this;null!=s&&s.statics.blotName!==e.tableMain&&this.wrap(e.tableMain,{tableId:i,full:o,align:n});zt(this,e.tableMain).align=n,super.optimize(t)}}class fe extends Vt{static blotName=e.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){const e=super.create();return e.dataset.tableId=t,e.addEventListener("dragstart",(t=>{t.preventDefault(),t.stopPropagation()}),!0),e.addEventListener("drop",(t=>{t.preventDefault()})),e.addEventListener("dragover",(t=>{t.preventDefault(),t.dataTransfer.dropEffect="none"})),e}get tableId(){return this.domNode.dataset.tableId}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}deleteAt(t,e){super.deleteAt(t,e);const s=this.descendants(de),i=this.descendants(me);0!==s.length&&0!==i.length||this.remove()}}class ge{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=n("align");resizeObserver=new ResizeObserver((()=>this.hide()));constructor(e,s,i){this.tableModule=e,this.table=s,this.quill=i,this.tableBlot=t.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const e=this.tableModule.addContainer(this.bem.b()),s=t.import("ui/icons"),i={left:s.align[""],center:s.align.center,right:s.align.right};for(const[s,o]of Object.entries(i)){const i=document.createElement("span");i.dataset.align=s,i.classList.add(this.bem.be("item")),i.innerHTML=`<i class="icon">${o}</i>`,i.addEventListener("click",(()=>{const e=i.dataset.align;e&&(this.setTableAlign(this.tableBlot,e),this.quill.once(t.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableResizeScale&&this.tableModule.tableResizeScale.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),e.appendChild(i)}return this.cleanup||(this.cleanup=yt(this.tableWrapperBlot.domNode,e,(()=>this.update()))),e}setTableAlign(t,e){const s=t.getCols();for(const t of s)t.align=e}show(){this.alignBox&&(this.alignBox.classList.add(this.bem.bm("active")),this.resizeObserver.observe(this.table))}hide(){this.alignBox&&(this.alignBox.classList.remove(this.bem.bm("active")),this.cleanup&&(this.cleanup(),this.cleanup=void 0))}update(){this.alignBox&&(this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth?this.hide():(this.show(),Et(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[Lt(),It({limiter:Nt()}),Mt(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}}const we="color-selector",ve=[{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm17.94 4.5h-2v4h-2v-4h-2l3-3z"/></svg>',tip:"Insert row above",handle:t=>{t.appendRow(!1),t.hideTableTools()}},{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm15.44 8v-2h-4v-2h4v-2l3 3z"/></svg>',tip:"Insert column right",handle:t=>{t.appendCol(!0),t.hideTableTools()}},{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm11.94 5.5h2v-4h2v4h2l-3 3z"/></svg>',tip:"Insert row below",handle:t=>{t.appendRow(!0),t.hideTableTools()}},{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm14.44 2v2h4v2h-4v2l-3-3z"/></svg>',tip:"Insert column Left",handle:t=>{t.appendCol(!1),t.hideTableTools()}},{name:"break"},{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"/></svg>',tip:"Merge Cell",handle:t=>{t.mergeCells(),t.hideTableTools()}},{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"/></svg>',tip:"Split Cell",handle:t=>{t.splitCell(),t.hideTableTools()}},{name:"break"},{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41zM22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2zM4 9h4V6H4zm6 0h4V6h-4zm6 0h4V6h-4z"/></svg>',tip:"Delete Row",handle:t=>{t.removeRow(),t.hideTableTools()}},{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4zm0 6v4h7v-4zM4 4v4h7V4zm13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59z"/></svg>',tip:"Delete Column",handle:t=>{t.removeCol(),t.hideTableTools()}},{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="m15.46 15.88l1.42-1.42L19 16.59l2.12-2.13l1.42 1.42L20.41 18l2.13 2.12l-1.42 1.42L19 19.41l-2.12 2.13l-1.42-1.42L17.59 18zM4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4z"/></svg>',tip:"Delete table",handle:t=>{t.deleteTable()}},{name:"break"},{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"/></svg>',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m12.01 16l-.01.011M12.01 12l-.01.011M12.01 8l-.01.011M8.01 12l-.01.011M16.01 12l-.01.011M21 3.6v16.8a.6.6 0 0 1-.6.6H3.6a.6.6 0 0 1-.6-.6V3.6a.6.6 0 0 1 .6-.6h16.8a.6.6 0 0 1 .6.6"/></svg>',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}}],xe=new Set,Ce=n("color-map"),ye={selectWrapper:Ce.b(),used:Ce.bm("used"),item:Ce.be("item"),btn:Ce.be("btn"),map:Ce.be("content"),mapRow:Ce.be("content-row")};class Me{tableModule;quill;options;menu=null;updateUsedColor;tooltipItem=[];bem=n("menu");colorItemClass=`color-${Bt()}`;colorChooseTooltipOption={direction:"top"};constructor(t,e,s){this.tableModule=t,this.quill=e,this.options=this.resolveOptions(s);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);r(e)||(e=[]),e.slice(-10).map((t=>xe.add(t)))}catch{}this.updateUsedColor=kt((t=>{if(!t)return;if(xe.add(t),xe.size>10){const t=Array.from(xe).slice(-10);xe.clear(),t.map((t=>xe.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(xe)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${ye.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${ye.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const i=Array.from(s.querySelectorAll(`.${ye.item}`)).slice(0,-10);for(const t of i)t.remove()}}),1e3)}resolveOptions(t){return Object.assign({tipText:!0,tipTexts:{},tools:ve,localstorageKey:"__table-bg-used-color",defaultColorMap:o},t)}getUsedColors(){return xe}buildTools(){const t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:s,icon:i,handle:o,isColorChoose:n,key:r,tip:a=""}=e,c=document.createElement("span");if(c.classList.add(this.bem.be("item")),"break"===s)c.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),l(i)?t.appendChild(i(this.tableModule)):t.innerHTML=i,c.appendChild(t),n&&r){const t=this.createColorChoose(c,{name:s,icon:i,handle:o,isColorChoose:n,key:r,tip:a});this.tooltipItem.push(t),c.classList.add(we)}else l(o)&&c.addEventListener("click",(t=>{this.quill.focus(),o(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.options.tipTexts[s]||a;this.options.tipText&&e&&a&&this.createTipText(c,e)}t.appendChild(c)}return t}createColorChoose(t,{handle:e,key:s}){const i=document.createElement("div");if(i.classList.add(ye.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(ye.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(ye.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}i.appendChild(t)}const o=document.createElement("div");o.classList.add(ye.mapRow),Object.assign(o.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(ye.btn,"transparent"),n.textContent=this.tableModule.options.texts.transparent,n.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),"transparent")}));const l=document.createElement("div");l.classList.add(ye.btn,"clear"),l.textContent=this.tableModule.options.texts.clear,l.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),null)}));const r=document.createElement("div");r.classList.add(ye.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=f({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Rt(r,{direction:"right",type:"click",content:a,container:r});if(o.appendChild(n),o.appendChild(l),o.appendChild(r),i.appendChild(o),xe.size>0){const t=document.createElement("div");t.classList.add(ye.used,this.colorItemClass);for(const e of xe){const s=document.createElement("div");s.classList.add(ye.item),s.style.backgroundColor=e,t.appendChild(s)}i.appendChild(t)}return i.addEventListener("click",(t=>{t.stopPropagation(),c();const e=t.target,i=e.style.backgroundColor,o=this.getSelectedTds();if(e&&i&&o.length>0){if(this.tableModule.setCellAttrs(o,s,i,!0),!e.closest(`.${ye.item}`))return;this.updateUsedColor(i)}})),Rt(t,{content:i,onClose(t){const e=i.contains(a);return t&&e&&c(),e},onDestroy(){d()},...this.colorChooseTooltipOption})}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Rt(t,{msg:e});s&&this.tooltipItem.push(s)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&Object.assign(this.menu.style,{display:"flex"})}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0)}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}class Ie extends Me{tableModule;quill;colorChooseTooltipOption={direction:"right"};constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),this.update({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hide()}),{once:!0})):this.hide()};buildTools(){const t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));const e=t.getElementsByClassName(we);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const s=document.createElement("span");s.textContent=e,t.appendChild(s)}update(t){if(!this.menu||!this.tableModule.tableSelection||!this.tableModule.tableSelection.boundary)return;super.update();const e={display:"flex",left:0,top:0};if(!t)return this.hide();const{x:s,y:i}=t;e.left=s,e.top=i,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const o=this.menu.getBoundingClientRect(),{left:n,top:l}=qt(o);Object.assign(this.menu.style,{left:`${n+window.scrollX}px`,top:`${l+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy()}}class Le extends Me{tableModule;quill;constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(super.update(),Et(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[Lt(),It({limiter:Nt()}),Mt(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}}const Ne=t=>!t.full&&"right"===t.align;class Ee{tableModule;quill;colIndex=-1;tableMain;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=n("drag-line");constructor(t,e){this.tableModule=t,this.quill=e}findCurrentColIndex(t){return-1}colWidthChange(t,e,s){}async createConfirmDialog({message:t,confirm:e,cancel:s}){return new Promise((i=>{const o=document.createElement("div");Object.assign(o.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});const n=document.createElement("p");n.textContent=t;const l=document.createElement("div");Object.assign(l.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});const r=c({content:s}),a=c({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),o.appendChild(n),o.appendChild(l);const{close:d}=w({child:o});r.addEventListener("click",(()=>{i(!1),d()})),a.addEventListener("click",(()=>{i(!0),d()}))}))}async handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0");let o=this.tableMain.full,n=!1;const l=[];if(o){let i=e/this.tableMain.domNode.getBoundingClientRect().width*100;const o=t[this.colIndex].width;if(i<o){if(i=Math.max(s.colMinWidthPre,i),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1;l.push({index:e,width:t[e].width+o-i})}else i=100;n=!0,l.push({index:this.colIndex,width:i})}else if(t[this.colIndex+1]){const e=o+t[this.colIndex+1].width;i=Math.min(e-s.colMinWidthPre,i),n=!0,l.push({index:this.colIndex,width:i},{index:this.colIndex+1,width:e-i})}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,n=!0,l.push({index:this.colIndex,width:e});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,n){const e=this.tableMain.domNode.getBoundingClientRect().width;if(o){let s=0;const i=new Set(l.map((({index:t,width:e})=>(s+=e,t))));for(const[e,o]of t.entries())i.has(e)||(s+=o.width);if(s>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableMain.cancelFull(),o=!1;for(const[t,s]of l.entries()){const{width:i,index:o}=s;l[t]={index:o,width:i/100*e}}}}for(const{index:s,width:i}of l)t[s].width=`${Math.round(i)}${o?"%":"px"}`,this.colWidthChange(s,o?i/100*e:i,o)}this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),i=e[this.colIndex].domNode.getBoundingClientRect(),o=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=s.colMinWidthPre/100*o.width;let l=o.right;n>i.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,i.left+t));const r=i.x+t;n=Math.min(Math.max(n,r),l)}else Ne(this.tableMain)?i.right-n<s.colMinWidthPx&&(n=i.right-s.colMinWidthPx):n-i.x<s.colMinWidthPx&&(n=i.x+s.colMinWidthPx);let l=n-i.x;return Ne(this.tableMain)&&(l=i.right-n),this.dragColBreak.style.left=`${n}px`,this.dragColBreak.dataset.w=String(l),{left:n,width:l}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),s=this.tableMain.domNode.getBoundingClientRect(),i=s.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const o=e[this.colIndex].width,n=this.tableMain.full?o/100*i:o;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const l=document.createElement("div");l.classList.add(this.dragBEM.b()),l.classList.add(this.dragBEM.is("col")),l.dataset.w=String(n);const r={top:s.y,left:t.clientX,height:s.height};Object.assign(l.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(l),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=l,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let i=t.clientY;return i-e.y<s.rowMinHeightPx&&(i=e.y+s.rowMinHeightPx),this.dragRowBreak.style.top=`${i}px`,this.dragRowBreak.dataset.h=String(i-e.y),{top:i,height:i-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,s=this.tableMain.domNode.getBoundingClientRect(),i=document.createElement("div");i.classList.add(this.dragBEM.b()),i.classList.add(this.dragBEM.is("row")),i.dataset.h=String(e);const o={top:t.clientY,left:s.x,width:s.width};Object.assign(i.style,{top:`${o.top}px`,left:`${o.left}px`,width:`${o.width}px`});const n=document.body;return n.appendChild(i),this.dragRowBreak&&n.removeChild(this.dragRowBreak),this.dragRowBreak=i,o}update(){}destroy(){}}class Se extends Ee{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=n("resize-box");constructor(e,s,i){super(e,i),this.tableModule=e,this.table=s,this.tableMain=t.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer(this.bem.b()),this.resizeObserver=new ResizeObserver((()=>{this.show()})),this.resizeObserver.observe(this.table)))}handleResizerHeader(t,e){const{clientX:s,clientY:i}=e,o=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const n=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const l=[{x:t?o.left:s,y:t?i:o.top},{x:t?o.right:s,y:t?i:o.bottom}];this.lastHeaderSelect?(l[0]={x:Math.min(l[0].x,this.lastHeaderSelect[0].x),y:Math.min(l[0].y,this.lastHeaderSelect[0].y)},l[1]={x:Math.max(l[1].x,this.lastHeaderSelect[1].x),y:Math.max(l[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=l,n.selectedTds=n.computeSelectedTds(...l),n.show()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("col-separator"))).indexOf(t.target)}colWidthChange(t,e,s){Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[t].style.width=`${e}px`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.size+"px",left:`${e.left}px`,height:`${e.height+this.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));Wt.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!1));for(const t of e)t.addEventListener("mousedown",this.handleColMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}findCurrentRowIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("row-separator"))).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[t].style.height=`${e}px`}handleRowMouseDownFunc=function(t){const e=this.handleRowMouseDown(t);return e&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${e.top}px`,left:e.left-this.size+"px",width:`${e.width+this.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));Wt.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!0));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const[t]=this.tableMain.descendant(de,this.tableMain.length()-1);if(!t)return;const e=t.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:e.y-s.y+"px",left:e.x-s.x+"px"});const i=this.tableMain.domNode.getBoundingClientRect(),o=this.tableWrapper.domNode.getBoundingClientRect();let n=-1*this.size,l=-1*this.size;Ne(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),n=Math.min(o.width,i.width),l=Math.min(o.width,i.width)):this.root.classList.remove(this.bem.is("align-right")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${n}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const t=this.tableWrapper.domNode.getBoundingClientRect(),e=this.tableMain.domNode.getBoundingClientRect();if(this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener("click",(()=>{const t=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const e=this.tableModule.tableSelection;e.selectedTds=e.computeSelectedTds({x:t.x,y:t.y},{x:t.right,y:t.bottom}),e.show()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let s="";for(const[,t]of this.tableCols.entries()){const i=t.domNode.getBoundingClientRect().width;s+=`<div class="${this.bem.be("col-header")}" style="width: ${i}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${e.height+this.size-3}px"></div>\n </div>`}const i=document.createElement("div");i.classList.add(this.bem.be("col"));const o=document.createElement("div");o.classList.add(this.bem.be("col-wrapper")),Object.assign(i.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(o.style,{width:`${e.width}px`}),o.innerHTML=s,i.appendChild(o),this.root.appendChild(i),i.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=i,this.bindColEvents()}if(this.tableRows.length>0){let s="";for(const[,t]of this.tableRows.entries()){const i=`${t.domNode.getBoundingClientRect().height}px`;s+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(i)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${e.width+this.size-3}px"></div>\n </div>`}const i=document.createElement("div");i.classList.add(this.bem.be("row"));const o=document.createElement("div");o.classList.add(this.bem.be("row-wrapper")),Object.assign(i.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${t.height}px`}),Object.assign(o.style,{height:`${e.height}px`}),o.innerHTML=s,i.appendChild(o),this.root.appendChild(i),i.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}this.update(),Wt.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),Ht.call(this),this.resizeObserver.disconnect();for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}}class Re extends Ee{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=n("resize-line");constructor(e,s,i){super(e,i),this.tableModule=e,this.table=s,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.table.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(t.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=s=>{if(this.dragging)return;const i=this.findTableCell(s);if(!i)return this.hide();const o=t.find(i);o&&this.currentTableCell!==i&&(this.show(),this.currentTableCell=i,this.tableCellBlot=o,this.tableMain=zt(o,e.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hide()};findTableCell(t){for(const e of t.composedPath()){if(e instanceof HTMLElement&&"TD"===e.tagName)return e;if(e===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.colResizer),this.colResizer=this.tableModule.addContainer(this.bem.be("col"));const[s]=Ot(t,[e.tableBody]),i=s.domNode.getBoundingClientRect(),o=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=o.right-n.x;Ne(this.tableMain)&&(l=o.left-n.x),Object.assign(this.colResizer.style,{top:i.y-n.y+"px",left:`${l}px`,height:`${i.height}px`});const r=this.tableMain.getCols();this.curColIndex=r.findIndex((e=>e.colId===t.colId)),this.colResizer.addEventListener("mousedown",this.handleColMouseDownFunc),this.colResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.rowResizer),this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));const s=t.parent;if(!(s instanceof ce))return;const[i]=Ot(t,[e.tableBody]),o=i.domNode.getBoundingClientRect(),n=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:n.bottom-l.y+"px",left:o.x-l.x+"px",width:`${o.width}px`});const r=this.tableMain.getRows();this.curRowIndex=r.indexOf(s),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}show(){Object.assign(this.colResizer.style,{display:null}),Object.assign(this.rowResizer.style,{display:null})}hide(){this.currentTableCell=void 0,this.rowResizer.style.display="none",this.colResizer.style.display="none"}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer.remove(),this.rowResizer.remove(),this.table.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(t.events.TEXT_CHANGE,this.hideWhenTextChange)}}class Te{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=n("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(e,s,i,o){this.tableModule=e,this.table=s,this.quill=i,this.options=this.resolveOptions(o),this.tableMainBlot=t.find(s),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.buildResizer(),this.show())}resolveOptions(t){return Object.assign({blockSize:12},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.root.classList.add(this.bem.is("hidden")),this.block=document.createElement("div"),this.block.classList.add(this.bem.be("block")),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let t=[],e=[];const i=i=>{if(!this.tableMainBlot)return;const o=Ne(this.tableMainBlot)?-1:1,n=(i.clientX-this.startX)*o,l=i.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:i}of t)e.width=Math.max(i+r,s.colMinWidthPx);for(const{blot:t,height:i}of e)t.setHeight(`${Math.max(i+a,s.rowMinHeightPx)}px`)},o=()=>{t=[],e=[],document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",o)};this.block.addEventListener("mousedown",(s=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=s.clientX,this.startY=s.clientY,t=this.tableMainBlot.getCols().map((t=>({blot:t,width:Math.floor(t.width)}))),e=this.tableMainBlot.getRows().map((t=>({blot:t,height:Math.floor(t.domNode.getBoundingClientRect().height)}))),document.addEventListener("mousemove",i),document.addEventListener("mouseup",o))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),Wt.call(this,this.quill.root,(()=>this.update())),Wt.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect();if(t.width>e.width){for(const s of this.tableMainBlot.getCols())s.width=Math.floor(s.width/t.width*e.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),{scrollTop:i,scrollLeft:o}=this.tableWrapperBlot.domNode,n=2*this.options.blockSize,l=Math.min(t.width,e.width)+n,r=Math.min(t.height,e.height)+n;Object.assign(this.root.style,{width:`${l}px`,height:`${r}px`,left:Math.max(t.x,e.x)-s.x-this.options.blockSize+"px",top:Math.max(t.y,e.y)-s.y-this.options.blockSize+"px"});const a={left:t.width+n-o+"px",top:r-i+"px"};Ne(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),a.left=`${this.options.blockSize+-1*o}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,a)}show(){this.root&&(this.root.classList.remove(this.bem.is("hidden")),this.update())}hide(){this.root&&this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),this.root&&this.root.remove(),Ht.call(this)}}class Be{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;bem=n("scrollbar");constructor(t,e,s,i){this.quill=t,this.isVertical=e,this.table=s,this.scrollbarContainer=i,this.container=s.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Wt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:e,scrollTop:s}=this.quill.root,{offsetLeft:i,offsetTop:o}=this.container,{width:n,height:l}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=i,d=o;this.isVertical?c+=Math.min(n,r):d+=Math.min(l,a);const h=t.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-i),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?l:n}px`,transform:`translate(${c-e}px, ${d-s}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,s=t**2/this.container.scrollHeight,i=e**2/this.container.scrollWidth,o=Math.max(s,this.minSize),n=Math.max(i,this.minSize);this.ratioY=s/(t-s)/(o/(t-o)),this.ratioX=i/(e-i)/(n/(e-n)),this.sizeWidth=n+this.gap<e?`${n}px`:"",this.sizeHeight=o+this.gap<t?`${o}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){const t=document.createElement("div");t.classList.add(this.bem.b()),t.classList.add(this.isVertical?this.bem.is("vertical"):this.bem.is("horizontal"),this.bem.is("transparent")),Object.assign(t.style,{display:"none"}),this.thumb.classList.add(this.bem.be("thumb"));const e=t=>{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const s=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],i=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*s/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=i*this.container[this.propertyMap.scrollSize]/100},s=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",s),this.cursorLeave&&this.hideScrollbar()},i=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",e),document.addEventListener("mouseup",s),document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),i(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const o=[this.table,t];for(const t of o)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Wt.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){const e=t[this.propertyMap.offset]-this.gap;this.move=100*t[this.propertyMap.scrollDirection]/e*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=kt((()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?"block":"none",requestAnimationFrame((()=>{this.scrollbar.classList.remove(this.bem.is("transparent"))}))}),200);hideScrollbar=kt((()=>{this.cursorLeave=!0,this.cursorDown||(this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.addEventListener("transitionend",this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is("transparent")))}),200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?"block":"none"};destroy(){this.ob.disconnect(),Ht.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}class ke{tableModule;table;quill;scrollbarContainer;scrollbar;bem=n("scrollbar");constructor(t,e,s){this.tableModule=t,this.table=e,this.quill=s,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Be(s,!0,e,this.scrollbarContainer),new Be(s,!1,e,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar)}hide(){for(const t of this.scrollbar)t.hideScrollbar()}show(){for(const t of this.scrollbar)t.showScrollbar()}update(){for(const t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}destroy(){this.scrollbarContainer.remove();for(const t of this.scrollbar)t.destroy();return null}}class ze{table;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];selectingHandler=this.mouseDownHandler.bind(this);tableMenu;resizeObserver;bem=n("selection");constructor(t,e,s,i={}){this.table=e,this.quill=s,this.options=this.resolveOptions(i),this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((()=>this.hide())),this.resizeObserver.observe(this.table),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(t,s,this.options.tableMenuOptions))}resolveOptions(t){return Object.assign({selectColor:"#0589f3",tableMenuOptions:{}},t)}helpLinesInitial(){const t=document.createElement("div");return t.classList.add(this.bem.be("line")),Object.assign(t.style,{"border-color":this.options.selectColor}),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(e,s){const i=t.find(this.table);if(!i)return[];const o=new Set(i.descendants(he).map(((t,e)=>(t.index=e,t)))),{x:n,y:l}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=n,this.selectedTableScrollY=l,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=e.x-n+this.startScrollX,h=e.y-l+this.startScrollY;let u={x:Math.max(c.left,Math.min(s.x,d)),y:Math.max(c.top,Math.min(s.y,h)),x1:Math.min(c.right,Math.max(s.x,d)),y1:Math.min(c.bottom,Math.max(s.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of o){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:i,bottom:n}=t.__rect;if(Tt(u,{x:e,y:s,x1:i,y1:n},2)){p.add(t),o.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,s),x1:Math.max(u.x1,i),y1:Math.max(u.y1,n)},b=!0;break}if(e>u.x1&&s>u.y1)break}}for(const t of[...p,...o])delete t.__rect;return this.boundary=function(t,e){const s=e.getBoundingClientRect();return{x:t.x-s.x-e.scrollLeft,y:t.y-s.y-e.scrollTop,x1:t.x-s.x-e.scrollLeft+t.width,y1:t.y-s.y-e.scrollTop+t.height,width:t.width,height:t.height}}({...u,width:u.x1-u.x,height:u.y1-u.y},this.quill.root),Array.from(p).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler(t){const{button:e,target:s,clientX:i,clientY:o}=t,n=s.closest(".ql-table");if(0!==e||!n)return;const l=n.dataset.tableId,r={x:i,y:o},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.show(),this.tableMenu&&this.tableMenu.hide();const d=t=>{const{button:e,target:s,clientX:i,clientY:o}=t,n=s.closest(".ql-table");if(0!==e||!n||n.dataset.tableId!==l)return;this.dragging=!0;const a={x:i,y:o};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.update()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu&&this.tableMenu.update()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)}update(){if(0===this.selectedTds.length||!this.boundary)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:s,y:i}=this.getTableViewScroll(),o=this.table.parentElement.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),l=o.x-n.x,r=o.y-n.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-i-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${o.width+2}px`,height:`${o.height+2}px`}),!this.dragging&&this.tableMenu&&this.tableMenu.update()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}}show(){Ht.call(this),Object.assign(this.cellSelectWrap.style,{display:"block"}),this.update(),Wt.call(this,this.quill.root,(()=>{this.update()})),Wt.call(this,this.table.parentElement,(()=>{this.update()}))}hide(){this.boundary=null,this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.tableMenu&&this.tableMenu.hide(),Ht.call(this)}destroy(){return this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Ht.call(this),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),null}}const Oe=t.import("delta"),Ae=t.import("blots/break"),$e=t.import("ui/icons"),qe=(t,{tableId:s,rowId:i,colId:o})=>{const n={tableId:s,rowId:i,colId:o,colspan:1,rowspan:1},l=t.create(e.tableCell,n),r=t.create(e.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l},We=t=>{let e=Number.parseFloat(t.getAttribute("width")||s.colDefaultWidth);if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e},He=new Set([e.tableCellInner]),De=t=>{return!(!t||!t.parent)&&(e=t.parent,!!He.has(e.statics.blotName)||De(t.parent));var e};class je{static moduleName="table-up";static toolName=e.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,s){const i=this.quill.getLine(t.index)[0];if(i.prev instanceof fe)return i.prev.remove(),!1;if(s.format[e.tableCellInner]){if(0===i.offset(zt(i,e.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,s){const i=this.quill.getLine(t.index),o=i[0],n=i[1];if((o.next instanceof fe||o.next instanceof pe)&&n===o.length()-1)return!1;if(s.format[e.tableCellInner]){if(o===zt(o,e.tableCellInner).children.tail&&n===o.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[e.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(s){const[i,o]=this.quill.getLine(s.index);if(this.quill.getFormat(s.index+o+1,1)[e.tableCellInner])return!0;let n=2,l=i;for(;null!==l&&l.length()<=1;)if(l=l.prev,n-=1,n<=0)return this.quill.insertText(s.index+1,"\n"),this.quill.setSelection(s.index+1,t.sources.SILENT),!1;return!0}}};static register(){fe.allowedChildren=[be],be.allowedChildren=[de,me],be.requiredContainer=fe,me.allowedChildren=[pe],me.requiredContainer=be,de.allowedChildren=[ce],de.requiredContainer=be,ce.allowedChildren=[he],he.requiredContainer=de,he.allowedChildren=[ne,Ae],he.requiredContainer=ce,ne.requiredContainer=he,t.register({"blots/scroll":ae,"blots/block":_t,[`blots/${e.container}`]:Vt,"formats/header":Jt,"formats/list":ee,"formats/blockquote":Kt,"formats/code-block":Gt,[`formats/${e.tableCell}`]:he,[`formats/${e.tableCellInner}`]:ne,[`formats/${e.tableRow}`]:ce,[`formats/${e.tableBody}`]:de,[`formats/${e.tableCol}`]:pe,[`formats/${e.tableColgroup}`]:me,[`formats/${e.tableMain}`]:be,[`formats/${e.tableWrapper}`]:fe},!0)}quill;options;toolBox;fixTableByLisenter=kt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(s,o){if(this.quill=s,this.options=this.resolveOptions(o||{}),!this.options.scrollbar){const t=n("scrollbar");this.quill.container.classList.add(t.bm("origin"))}const l=n("toolbox");this.toolBox=this.quill.addContainer(l.b());const r=this.quill.getModule("toolbar");if(r&&this.quill.theme.pickers){const[,t]=(r.controls||[]).find((([t])=>t===this.statics.toolName))||[];if(t&&"select"===t.tagName.toLocaleLowerCase()){const e=this.quill.theme.pickers.find((e=>e.select===t));e&&(e.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,e),e.label.addEventListener("mousedown",(()=>{if(!this.selector||!e)return;const t=this.selector.getBoundingClientRect(),{leftLimited:s}=qt(t);if(s){const t=e.label.getBoundingClientRect();Object.assign(e.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(e.options.style,{transform:void 0})})))}}const a=this.quill.getModule("keyboard");for(const t of Object.values(je.keyboradHandler))t.bindInHead?a.bindings[t.key].unshift(t):a.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const e=t.composedPath();if(!e||e.length<=0)return;const i=e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(i){if(this.table===i)return this.tableSelection&&this.tableSelection.show(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(i,s)}else this.table&&this.hideTableTools()}),!1),this.quill.on(t.events.EDITOR_CHANGE,((s,i,o)=>{if(s===t.events.SELECTION_CHANGE&&i){const[s]=this.quill.getLine(i.index),[n]=this.quill.getLine(i.index+i.length);let l,r;try{l=zt(s,e.tableMain)}catch{}try{r=zt(n,e.tableMain)}catch{}if(s instanceof pe)return o||(o={index:0,length:0}),this.quill.setSelection(i.index+(o.index>i.index?-1:1),i.length+(o.length===i.length?0:o.length>i.length?-1:1),t.sources.USER);if(n instanceof pe)return this.quill.setSelection(i.index+1,i.length+1,t.sources.USER);i.length>0&&(l&&!r?this.quill.setSelection(i.index-1,i.length+1,t.sources.USER):r&&!l&&this.quill.setSelection(i.index,i.length+1,t.sources.USER)),l&&r||this.hideTableTools()}})),this.quill.on(i.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hide()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if(a(t)){const e=document.createElement("div");for(const s of t.split(" "))e.classList.add(s);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!1,texts:this.resolveTexts(t.texts||{}),full:!1,icon:$e.table,selectionOptions:{},alignOptions:{},scrollbarOptions:{},resizeOptions:{},resizeScaleOptions:{}},t)}resolveTexts(t){return Object.assign({customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer",custom:"Custom",clear:"Clear",transparent:"Transparent",perWidthInsufficient:"The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?"},t)}pasteTableHandler(){let t=Bt(),i=Bt(),o=[],n=0,l=0;const r=(t,s,i)=>{const o=this.quill.getSelection(!0),n=this.quill.getFormat(o)[e.tableCellInner];if(n)for(const t of s.ops)t.attributes||(t.attributes={}),t.attributes[e.tableCellInner]=n;return s};this.quill.clipboard.addMatcher(Node.TEXT_NODE,r),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,r),this.quill.clipboard.addMatcher("table",((i,r)=>{if(0===r.ops.length)return r;if(this.quill.getFormat()[e.tableCellInner])return new Oe;const a=[],c=[];for(let t=0;t<r.ops.length;t++){const{attributes:s,insert:i}=r.ops[t],{table:o,[e.tableCell]:n,...l}=s||{};i&&i[e.tableCol]?c.push({insert:i}):a.push({attributes:l,insert:i})}const d=((t,e)=>{const i=new Array(e).fill(s.colDefaultWidth),o=Array.from(t.querySelectorAll("tr"));for(const t of o){const s=Array.from(t.querySelectorAll("td"));for(const[t,o]of s.entries()){if(!(t<e))break;{const e=We(o);i[t]=e||i[t]}}}return i})(i,o.length).reduce(((s,i,n)=>(c[n]?s.push(c[n]):s.push({insert:{[e.tableCol]:{tableId:t,colId:o[n],width:i,full:!1}}}),s)),[]);return a.unshift(...d),t=Bt(),o=[],n=0,l=0,a.unshift({insert:"\n"}),a.push({insert:"\n"}),new Oe(a)})),this.quill.clipboard.addMatcher("colgroup",((t,s)=>{const i=[];for(let t=0;t<s.ops.length;t++){const n=s.ops[t];n&&(null!==(o=n.insert)&&"object"==typeof o)&&n.insert[e.tableCol]&&i.push(n)}var o;return new Oe(i)})),this.quill.clipboard.addMatcher("col",(s=>{o[l]=Bt();const i=(new Oe).insert({[e.tableCol]:Object.assign(pe.value(s),{tableId:t,colId:o[l]})});return l+=1,i})),this.quill.clipboard.addMatcher("tr",((t,s)=>{i=Bt(),n=0;for(const t of s.ops)if(t.attributes&&t.attributes.background&&t.attributes[e.tableCellInner]){const s=t.attributes[e.tableCellInner];s.style||(s.style=""),t.attributes[e.tableCellInner].style=`background:${t.attributes.background};${s.style}`}return s}));const a=(s,l)=>{const r=s,a=he.formats(r);if(!o[n])for(let t=n;t>=0;t--)o[t]||(o[t]=Bt());const c=o[n];n+=a.colspan;const d=Object.assign(a,{tableId:t,rowId:i,colId:c});"none"===r.style.border&&(d.style=d.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const h=[];for(const t of l.ops){const{insert:s,attributes:i}=t;if(t.insert){const t={...i};delete t[e.tableCell],h.push({insert:s,attributes:{...t,[e.tableCellInner]:d}})}}return new Oe(h)};this.quill.clipboard.addMatcher("td",a),this.quill.clipboard.addMatcher("th",a)}showTableTools(t,e){t&&(this.table=t,this.options.selection&&(this.tableSelection=new this.options.selection(this,t,e,this.options.selectionOptions)),this.options.align&&(this.tableAlign=new this.options.align(this,t,e,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,e,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,e,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,e,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection&&(this.tableSelection.destroy(),this.tableSelection=void 0),this.tableScrollbar&&(this.tableScrollbar.destroy(),this.tableScrollbar=void 0),this.tableAlign&&(this.tableAlign.destroy(),this.tableAlign=void 0),this.tableResize&&(this.tableResize.destroy(),this.tableResize=void 0),this.tableResizeScale&&this.tableResizeScale.destroy(),this.table=void 0}async buildCustomSelect(t,e){if(!t||!l(t))return;const s=document.createElement("div");s.classList.add("ql-custom-select"),this.selector=await t(this,e),s.appendChild(this.selector),e.options.appendChild(s)}setCellAttrs(t,e,s,i=!1){if(0!==t.length)for(const o of t)o.setFormatValue(e,s,i)}insertTable(i,o){if(i>=30||o>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus();const n=this.quill.getSelection();if(null==n)return;const[l]=this.quill.getLeaf(n.index);if(!l)return;if(De(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),a=getComputedStyle(this.quill.root),c=Number.parseInt(a.paddingLeft),d=Number.parseInt(a.paddingRight),h=Number.parseInt(a.width)-c-d-r,u=Bt(),p=new Array(o).fill(0).map((()=>Bt())),b=this.options.full?`${Math.max(1/o*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(h/o),s.colMinWidthPx)}px`,m=[{retain:n.index},{insert:"\n"}];for(let t=0;t<o;t++)m.push({insert:{[e.tableCol]:{width:b,tableId:u,colId:p[t],full:this.options.full}}});for(let t=0;t<i;t++){const t=Bt();for(let s=0;s<o;s++)m.push({insert:"\n",attributes:{[e.tableCellInner]:{tableId:u,rowId:t,colId:p[s],rowspan:1,colspan:1}}})}this.quill.updateContents(new Oe(m),t.sources.USER),this.quill.setSelection(n.index+o+o*i+1,t.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${be.className}">\n <tbody>\n <tr>\n <td class="${he.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=fe.className,e.innerHTML=t,e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.visibility="hidden",this.quill.root.appendChild(e);const s=window.getComputedStyle(e.querySelector("td")),i=Number.parseFloat(s.borderWidth)||0;return this.quill.root.removeChild(e),i}fixUnusuaDeletelTable(t){const e=t.getRows(),s=t.getColIds();if(0===e.length)return t.remove();if(0===s.length)return;const i=new Array(e.length).fill(0).map((()=>new Array(s.length).fill(!1))),o=t.tableId;for(const[t,n]of e.entries()){let l=0,r=0;const a=i[t],c=n.descendants(he);for(;r<s.length;){if(a[r]){r+=1;continue}const d=c[l];if(d&&d.colId===s[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:o}=d;if(s>1)for(let t=1;t<s;t++)a[r+t]=!0;if(o>1)for(let e=t+1;e<t+o;e++)for(let t=0;t<s;t++)i[e][r+t]=!0;l+=1}else n.insertBefore(qe(this.quill.scroll,{tableId:o,colId:s[r],rowId:n.rowId}),d);r+=1}if(l<c.length)for(let t=l;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(be))this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(t.events.SCROLL_OPTIMIZE,(t=>{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)))}))}deleteTable(){if(!this.tableSelection||0===this.tableSelection.selectedTds.length)return;const t=zt(this.tableSelection.selectedTds[0],e.tableMain);t&&t.remove(),this.hideTableTools()}appendRow(t){if(!this.tableSelection)return;const s=this.tableSelection.selectedTds;if(s.length<=0)return;const i=s[t?s.length-1:0],[o,n,l]=Ot(i,[e.tableMain,e.tableBody,e.tableRow]),r=o.getRows().indexOf(l)+(t?i.rowspan:0);n.insertRow(r)}appendCol(t){if(!this.tableSelection)return;const s=this.tableSelection.selectedTds;if(s.length<=0)return;const[i]=s.reduce(((e,s)=>{const i=s.getColumnIndex();return(!t&&i<=e[1]||t&&i>=e[1])&&(e=[s,i]),e}),[s[0],s[0].getColumnIndex()]),o=i.getColumnIndex()+(t?i.colspan:0),n=zt(i,e.tableMain),l=n.tableId,r=Bt(),[a]=n.descendants(me);a&&a.insertColByIndex(o,{tableId:l,colId:r,width:n.full?"6%":"160px",full:n.full});const c=n.getRows(),d=[];let h=0;for(const t of Object.values(c)){const e=d.shift()||0;if(h>0){h-=1;continue}const s=t.insertCell(o-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(h+=s.skipRowNum);for(const[t,e]of s.entries())d[t]=(d[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),s=t.getCols(),i=s.reduce(((t,e)=>(t[e.colId]=0,t)),{}),o=[...e].reverse(),n=[];for(const[t,s]of o.entries()){const o=e.length-t-1;s.children.length<=0?n.push(o):s.foreachCellInner((t=>{const e=n.reduce(((e,s)=>t.rowspan+o>s?e+1:e),0);t.rowspan-=e,i[t.colId]+=1}))}let l=0;for(const t of Object.values(i))if(0===t){const t=[];let s=0;for(const i of Object.values(e)){const e=t.shift()||0;let o=[];s>0?(o=i.getCellByColumIndex(l-e)[2],s-=1):(o=i.removeCell(l-e),o.skipRowNum&&(s+=o.skipRowNum));for(const[e,s]of o.entries())t[e]=(t[e]||0)+s}}else l+=1;for(const t of s)0===i[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const s=zt(t[0],e.tableMain),i=s.getRows();let o=i.length,n=-1;for(const s of t){const t=zt(s,e.tableRow),l=i.indexOf(t);l<o&&(o=l),l+s.rowspan>n&&(n=l+s.rowspan)}const l={};for(let t=o;t<Math.min(i.length,n);t++){i[t].foreachCellInner((e=>{e.rowspan+t>n&&(l[e.colId]={rowspan:e.rowspan+t-n,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(i[n]){const t=i[n],e=s.tableId;for(const[s,{colIndex:i,colspan:o,rowspan:n}]of Object.entries(l))t.insertCell(i,{tableId:e,rowId:t.rowId,colId:s,colspan:o,rowspan:n})}this.fixTableByRemove(s)}removeCol(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const s=t[0],i=zt(s,e.tableMain),o={};for(const e of t)o[e.rowId]||(o[e.rowId]=0),o[e.rowId]+=e.colspan;const n=Math.max(...Object.values(o)),l=s.getColumnIndex(),r=i.descendants(ce);for(let t=0;t<n;t++){const t=[];let e=0;for(const s of Object.values(r)){const i=t.shift()||0;if(e>0){e-=1;continue}const o=s.removeCell(l-i);o.skipRowNum&&(e+=o.skipRowNum);for(const[e,s]of o.entries())t[e]=(t[e]||0)+s}}const[a]=i.descendants(me);if(a)for(let t=0;t<n;t++)a.removeColByIndex(l);this.fixTableByRemove(i)}mergeCells(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=1)return;const s=t.reduce(((t,e,s)=>{const i=e.colId;t[0][i]||(t[0][i]=0),t[0][i]+=e.rowspan;const o=e.rowId;return t[1][o]||(t[1][o]=0),t[1][o]+=e.colspan,0!==s&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),i=Math.max(...Object.values(s[0])),o=Math.max(...Object.values(s[1])),n=s[2];n.colspan=o,n.rowspan=i;const l=zt(n,e.tableMain);this.fixTableByRemove(l)}splitCell(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(1!==t.length)return;const s=t[0];if(1===s.colspan&&1===s.rowspan)return;const[i,o]=Ot(s,[e.tableMain,e.tableRow]),n=i.tableId,l=s.getColumnIndex(),r=i.getColIds().slice(l,l+s.colspan).reverse();let a=o,c=s.rowspan;for(s.colspan=1,s.rowspan=1;a&&c>0;){for(const t of r)a===o&&t===s.colId||a.insertCell(l+(a===o?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}function Fe(t){He.delete(e.tableCellInner),Object.assign(e,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(i,t.tableUpEvent||{}),je.toolName=e.tableWrapper,Vt.blotName=e.container,fe.blotName=e.tableWrapper,be.blotName=e.tableMain,me.blotName=e.tableColgroup,pe.blotName=e.tableCol,de.blotName=e.tableBody,ce.blotName=e.tableRow,he.blotName=e.tableCell,ne.blotName=e.tableCellInner}function Pe(t,e){return x({onSelect:(s,i)=>{t.insertTable(s,i),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})}export{_t as BlockOverride,Kt as BlockquoteOverride,Gt as CodeBlockOverride,Vt as ContainerFormat,Jt as HeaderOverride,ee as ListItemOverride,ae as ScrollOverride,Be as Scrollbar,ge as TableAlign,de as TableBodyFormat,he as TableCellFormat,ne as TableCellInnerFormat,pe as TableColFormat,me as TableColgroupFormat,be as TableMainFormat,Me as TableMenuCommon,Ie as TableMenuContextmenu,Le as TableMenuSelect,Se as TableResizeBox,Ee as TableResizeCommon,Re as TableResizeLine,Te as TableResizeScale,ce as TableRowFormat,ze as TableSelection,je as TableUp,ke as TableVirtualScrollbar,fe as TableWrapperFormat,e as blotName,je as default,Pe as defaultCustomSelect,zt as findParentBlot,Ot as findParentBlots,Ne as isTableAlignRight,Bt as randomId,He as tableCantInsert,i as tableUpEvent,s as tableUpSize,Fe as updateTableConstants};
|
|
1
|
+
import t from"quill";const e={container:"table-up-container",tableWrapper:"table-up",tableMain:"table-up-main",tableColgroup:"table-up-colgroup",tableCol:"table-up-col",tableBody:"table-up-body",tableRow:"table-up-row",tableCell:"table-up-cell",tableCellInner:"table-up-cell-inner"},s={colMinWidthPre:5,colMinWidthPx:40,colDefaultWidth:"100",rowMinHeightPx:36},i={AFTER_TABLE_RESIZE:"after-table-resize"},o=[["rgb(255, 255, 255)","rgb(0, 0, 0)","rgb(72, 83, 104)","rgb(41, 114, 244)","rgb(0, 163, 245)","rgb(49, 155, 98)","rgb(222, 60, 54)","rgb(248, 136, 37)","rgb(245, 196, 0)","rgb(153, 56, 215)"],["rgb(242, 242, 242)","rgb(127, 127, 127)","rgb(243, 245, 247)","rgb(229, 239, 255)","rgb(229, 246, 255)","rgb(234, 250, 241)","rgb(254, 233, 232)","rgb(254, 243, 235)","rgb(254, 249, 227)","rgb(253, 235, 255)"],["rgb(216, 216, 216)","rgb(89, 89, 89)","rgb(197, 202, 211)","rgb(199, 220, 255)","rgb(199, 236, 255)","rgb(195, 234, 213)","rgb(255, 201, 199)","rgb(255, 220, 196)","rgb(255, 238, 173)","rgb(242, 199, 255)"],["rgb(191, 191, 191)","rgb(63, 63, 63)","rgb(128, 139, 158)","rgb(153, 190, 255)","rgb(153, 221, 255)","rgb(152, 215, 182)","rgb(255, 156, 153)","rgb(255, 186, 132)","rgb(255, 226, 112)","rgb(213, 142, 255)"],["rgb(165, 165, 165)","rgb(38, 38, 38)","rgb(53, 59, 69)","rgb(20, 80, 184)","rgb(18, 116, 165)","rgb(39, 124, 79)","rgb(158, 30, 26)","rgb(184, 96, 20)","rgb(163, 130, 0)","rgb(94, 34, 129)"],["rgb(147, 147, 147)","rgb(13, 13, 13)","rgb(36, 39, 46)","rgb(12, 48, 110)","rgb(10, 65, 92)","rgb(24, 78, 50)","rgb(88, 17, 14)","rgb(92, 48, 10)","rgb(102, 82, 0)","rgb(59, 21, 81)"]],n=(t,e="table-up")=>{const s=e?`${e}-`:"";return{b:()=>`${s}${t}`,be:e=>e?`${s}${t}__${e}`:"",bm:e=>e?`${s}${t}--${e}`:"",bem:(e,i)=>e&&i?`${s}${t}__${e}--${i}`:"",ns:t=>t?`${s}${t}`:"",bs:e=>e?`${s}${t}-${e}`:"",cv:t=>t?`--${s}${t}`:"",is:t=>`is-${t}`}},l=t=>"function"==typeof t,r=Array.isArray,a=t=>"string"==typeof t,c=t=>{const{type:e="default",content:s}=t||{},i=n("button"),o=document.createElement("button");return o.classList.add(i.b(),e),s&&(a(s)?o.textContent=s:o.appendChild(s)),o},d=function(t,e){return t=Math.min(e,Math.max(0,Number.parseFloat(`${t}`))),Math.abs(t-e)<1e-6?1:t%e/Number.parseFloat(e)},h=t=>({h:Math.min(360,Math.max(0,t.h)),s:Math.min(100,Math.max(0,t.s)),b:Math.min(100,Math.max(0,t.b)),a:Math.min(1,Math.max(0,t.a))}),u=t=>{let{r:e,g:s,b:i,a:o}=t;e=d(e,255),s=d(s,255),i=d(i,255);const n=Math.max(e,s,i),l=Math.min(e,s,i);let r;const a=n,c=n-l,h=0===n?0:c/n;if(n===l)r=0;else{switch(n){case e:r=(s-i)/c+(s<i?6:0);break;case s:r=(i-e)/c+2;break;case i:r=(e-s)/c+4}r/=6}return{h:360*r,s:100*h,b:100*a,a:o}},p=t=>{let{h:e,s:s,b:i,a:o}=t;e=6*d(e,360),s=d(s,100),i=d(i,100);const n=Math.floor(e),l=e-n,r=i*(1-s),a=i*(1-l*s),c=i*(1-(1-l)*s),h=n%6,u=[i,a,r,r,c,i][h],p=[c,i,i,a,r,r][h],b=[r,r,c,i,i,a][h];return{r:Math.round(255*u),g:Math.round(255*p),b:Math.round(255*b),a:o}},b=t=>{const e=[t.r.toString(16),t.g.toString(16),t.b.toString(16),Math.round(255*t.a).toString(16)];for(const t in e)1===e[t].length&&(e[t]=`0${e[t]}`);return e.join("")},m=t=>b(p(t)),f=(t={})=>{const e=230,s=150,i=10;let o=u((l=(l=t.color||"#ff0000").startsWith("#")?l.slice(1):l,{r:Number.parseInt(l.slice(0,2),16),g:Number.parseInt(l.slice(2,4),16),b:Number.parseInt(l.slice(4,6),16),a:Number((Number.parseInt(l.slice(6,8)||"ff",16)/255).toFixed(2))}));var l;const r=n("color-picker"),a=document.createElement("div");a.classList.add(r.b());const c=document.createElement("div");c.classList.add(r.be("content"));const d=document.createElement("div");d.classList.add(r.be("selector"));const f=document.createElement("div");f.classList.add(r.be("background")),d.appendChild(f);const g=document.createElement("div");g.classList.add(r.be("background-handle")),f.appendChild(g);const w=document.createElement("div");w.classList.add(r.be("alpha"));const v=document.createElement("div");v.classList.add(r.be("alpha-bg"));const x=document.createElement("div");x.classList.add(r.be("alpha-handle")),w.appendChild(v),w.appendChild(x);const C=document.createElement("div");C.classList.add(r.be("hue"));const y=document.createElement("div");y.classList.add(r.be("hue-handle")),C.appendChild(y);const M=document.createElement("div");M.classList.add(r.be("action"));const[I,L,N,E]=["r","g","b","a"].map((t=>{const e=document.createElement("div");e.classList.add(r.be("action-item"),t);const s=document.createElement("label");s.textContent=t.toUpperCase();const i=document.createElement("input");return i.classList.add(r.be("input")),i.addEventListener("input",(()=>{i.value=i.value.replaceAll(/[^0-9]/g,"")})),i.addEventListener("change",(()=>{let e=Math.round(Number(i.value));"a"===t&&(e/=100);z(h(u(Object.assign({},p(o),{[t]:e})))),k()})),e.appendChild(s),e.appendChild(i),M.appendChild(e),i}));c.appendChild(C),c.appendChild(d),c.appendChild(w),a.appendChild(c),a.appendChild(M);let S=!1,R=!1,T=!1;function B(){const t=m(o);for(const[e,s]of[I,L,N].entries())s.value=String(Number.parseInt(t[2*e]+t[2*e+1],16));E.value=String((100*o.a).toFixed(0))}function k(){Object.assign(g.style,{left:`${Math.floor(e*o.s/100)}px`,top:`${Math.floor(s*(100-o.b)/100)}px`}),d.style.backgroundColor=`#${b(p({h:o.h,s:100,b:100,a:1}))}`,y.style.top=`${Math.floor(s-s*o.h/360)}px`,x.style.left=100*o.a+"%",function(){const{r:t,g:e,b:s}=p(o);v.style.background=`linear-gradient(to right, rgba(${t}, ${e}, ${s}, 0) 0%, rgba(${t}, ${e}, ${s}, 1) 100%)`}(),B()}function z(e){o=h(Object.assign({},o,e)),B(),t.onChange&&t.onChange(`#${m(o)}`)}function O(t){const i=d.getBoundingClientRect(),o=i.top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0),n=i.left+document.body.scrollLeft;z({s:Math.floor(100*Math.max(0,Math.min(e,t.pageX-n))/e),b:Math.floor(100*(s-Math.max(0,Math.min(s,t.pageY-o)))/s)}),k()}function A(t){const e=C.getBoundingClientRect().top+(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0);z({h:Math.floor(360*(s-Math.max(0,Math.min(s,t.pageY-e)))/s)}),k()}function $(t){const{pageX:e}=t,s=w.getBoundingClientRect();let o=e-s.left;o=Math.max(i/2,o),o=Math.min(o,s.width-i/2),z({a:Math.round((o-5)/(s.width-10)*100)/100}),k()}function q(t){S&&(t.preventDefault(),O(t)),R&&(t.preventDefault(),A(t)),T&&(t.preventDefault(),$(t))}function W(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",W),S=!1}function H(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",H),R=!1}function D(){document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",D),T=!1}return d.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",W),S=!0,O(t)})),C.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",H),R=!0,A(t)})),w.addEventListener("mousedown",(function(t){document.addEventListener("mousemove",q),document.addEventListener("mouseup",D),T=!0,$(t)})),k(),a};let g=8e3;const w=({child:t,target:e=document.body,beforeClose:s=()=>{}}={})=>{const i=n("dialog"),o=e,l=document.createElement("div");l.classList.add(i.b()),l.style.zIndex=String(g);const r=document.createElement("div");if(r.classList.add(i.be("overlay")),l.appendChild(r),t){const e=document.createElement("div");e.classList.add(i.be("content")),e.appendChild(t),r.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const a=getComputedStyle(o).overflow;o.style.overflow="hidden",o.appendChild(l);const c=()=>{s(),l.remove(),o.style.overflow=a};return l.addEventListener("click",c),g+=1,{dialog:l,close:c}},v=(t,e)=>{const s=n("input");e.type||(e.type="text"),e.value||(e.value="");const i=document.createElement("div");if(i.classList.add(s.be("item")),t){const e=document.createElement("span");e.classList.add(s.be("label")),e.textContent=t,i.appendChild(e)}const o=document.createElement("div");o.classList.add(s.be("input"));const l=document.createElement("input");for(const t in e)l.setAttribute(t,e[t]);(e.max||e.min)&&l.addEventListener("blur",(()=>{e.max&&e.max<=Number(l.value)&&(l.value=String(e.max)),e.min&&e.min>=Number(l.value)&&(l.value=String(e.min))})),o.appendChild(l),i.appendChild(o),l.addEventListener("focus",(()=>{o.classList.add("focus")})),l.addEventListener("blur",(()=>{o.classList.remove("focus")}));return{item:i,input:l,errorTip:t=>{let e;o.classList.contains("error")?e=o.querySelector(`.${s.be("error-tip")}`):(e=document.createElement("span"),e.classList.add(s.be("error-tip")),o.appendChild(e)),e.textContent=t,o.classList.add("error");return{removeError:()=>{o.classList.remove("error"),e.remove()}}}}},x=(t={})=>{const e=n("select-box"),s=document.createElement("div");s.classList.add(e.b());const i=document.createElement("div");i.classList.add(e.be("block"));for(let s=0;s<(t.row||8);s++)for(let o=0;o<(t.col||8);o++){const t=document.createElement("div");t.classList.add(e.be("item")),t.dataset.row=String(s+1),t.dataset.col=String(o+1),i.appendChild(t)}const o=()=>{const{row:t,col:e}=s.dataset;for(const t of Array.from(i.querySelectorAll(".active")))t.classList.remove("active");if(!t||!e)return;const o=Array.from(i.children);for(let s=0;s<o.length;s++){const{row:i,col:n}=o[s].dataset;if(i>t&&n>e)return;i<=t&&n<=e?o[s].classList.add("active"):o[s].classList.remove("active")}};if(i.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:e,col:i}=t.target.dataset;e&&i&&(s.dataset.row=e,s.dataset.col=i,o())})),i.addEventListener("mouseleave",(()=>{s.removeAttribute("data-row"),s.removeAttribute("data-col"),o()})),i.addEventListener("click",(()=>{const{row:e,col:i}=s.dataset;e&&i&&t.onSelect&&t.onSelect(Number(e),Number(i))})),s.appendChild(i),t.customBtn){const i=t.texts||{},o=document.createElement("div");o.classList.add(e.be("custom")),o.textContent=i.customBtnText||"Custom",o.addEventListener("click",(async()=>{const e=await(async(t={})=>{const e=n("creator"),s=document.createElement("div");s.classList.add(e.b());const i=document.createElement("div");i.classList.add(e.be("input"));const{item:o,input:l,errorTip:r}=v(t.rowText||"Row",{type:"number",value:String(t.row||""),max:99}),{item:a,input:d,errorTip:h}=v(t.colText||"Column",{type:"number",value:String(t.col||""),max:99});i.appendChild(o),i.appendChild(a),s.appendChild(i);const u=document.createElement("div");u.classList.add(e.be("control"));const p=c({type:"confirm",content:t.confirmText||"Confirm"}),b=c({type:"default",content:t.cancelText||"Cancel"});u.appendChild(p),u.appendChild(b),s.appendChild(u);const m=(e=Number(l.value),s=Number(d.value))=>{if(Number.isNaN(e)||e<=0)r(t.notPositiveNumberError||"Please enter a positive integer");else{if(!(Number.isNaN(s)||s<=0))return{row:e,col:s};h(t.notPositiveNumberError||"Please enter a positive integer")}},f=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",f))};return new Promise(((t,e)=>{const{close:i}=w({child:s,beforeClose:e});l.focus();for(const e of[l,d])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=m();e&&(t(e),i())}}));p.addEventListener("click",(async()=>{const e=m();e&&(t(e),i())})),document.addEventListener("keydown",f),b.addEventListener("click",i)}))})(i);e&&t.onSelect&&t.onSelect(e.row,e.col)})),s.appendChild(o)}return s},C=Math.min,y=Math.max,M=Math.round,I=Math.floor,L=t=>({x:t,y:t}),N={left:"right",right:"left",bottom:"top",top:"bottom"},E={start:"end",end:"start"};function S(t,e,s){return y(t,C(e,s))}function R(t,e){return"function"==typeof t?t(e):t}function T(t){return t.split("-")[0]}function B(t){return t.split("-")[1]}function k(t){return"x"===t?"y":"x"}function z(t){return"y"===t?"height":"width"}function O(t){return["top","bottom"].includes(T(t))?"y":"x"}function A(t){return k(O(t))}function $(t){return t.replace(/start|end/g,(t=>E[t]))}function q(t){return t.replace(/left|right|bottom|top/g,(t=>N[t]))}function W(t){const{x:e,y:s,width:i,height:o}=t;return{width:i,height:o,top:s,left:e,right:e+i,bottom:s+o,x:e,y:s}}function H(t,e,s){let{reference:i,floating:o}=t;const n=O(e),l=A(e),r=z(l),a=T(e),c="y"===n,d=i.x+i.width/2-o.width/2,h=i.y+i.height/2-o.height/2,u=i[r]/2-o[r]/2;let p;switch(a){case"top":p={x:d,y:i.y-o.height};break;case"bottom":p={x:d,y:i.y+i.height};break;case"right":p={x:i.x+i.width,y:h};break;case"left":p={x:i.x-o.width,y:h};break;default:p={x:i.x,y:i.y}}switch(B(e)){case"start":p[l]-=u*(s&&c?-1:1);break;case"end":p[l]+=u*(s&&c?-1:1)}return p}async function D(t,e){var s;void 0===e&&(e={});const{x:i,y:o,platform:n,rects:l,elements:r,strategy:a}=t,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:u=!1,padding:p=0}=R(e,t),b=function(t){return"number"!=typeof t?function(t){return{top:0,right:0,bottom:0,left:0,...t}}(t):{top:t,right:t,bottom:t,left:t}}(p),m=r[u?"floating"===h?"reference":"floating":h],f=W(await n.getClippingRect({element:null==(s=await(null==n.isElement?void 0:n.isElement(m)))||s?m:m.contextElement||await(null==n.getDocumentElement?void 0:n.getDocumentElement(r.floating)),boundary:c,rootBoundary:d,strategy:a})),g="floating"===h?{x:i,y:o,width:l.floating.width,height:l.floating.height}:l.reference,w=await(null==n.getOffsetParent?void 0:n.getOffsetParent(r.floating)),v=await(null==n.isElement?void 0:n.isElement(w))&&await(null==n.getScale?void 0:n.getScale(w))||{x:1,y:1},x=W(n.convertOffsetParentRelativeRectToViewportRelativeRect?await n.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:g,offsetParent:w,strategy:a}):g);return{top:(f.top-x.top+b.top)/v.y,bottom:(x.bottom-f.bottom+b.bottom)/v.y,left:(f.left-x.left+b.left)/v.x,right:(x.right-f.right+b.right)/v.x}}function j(){return"undefined"!=typeof window}function F(t){return X(t)?(t.nodeName||"").toLowerCase():"#document"}function P(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function V(t){var e;return null==(e=(X(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function X(t){return!!j()&&(t instanceof Node||t instanceof P(t).Node)}function Y(t){return!!j()&&(t instanceof Element||t instanceof P(t).Element)}function _(t){return!!j()&&(t instanceof HTMLElement||t instanceof P(t).HTMLElement)}function U(t){return!(!j()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof P(t).ShadowRoot)}function K(t){const{overflow:e,overflowX:s,overflowY:i,display:o}=et(t);return/auto|scroll|overlay|hidden|clip/.test(e+i+s)&&!["inline","contents"].includes(o)}function Z(t){return["table","td","th"].includes(F(t))}function G(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function Q(t){const e=J(),s=Y(t)?et(t):t;return"none"!==s.transform||"none"!==s.perspective||!!s.containerType&&"normal"!==s.containerType||!e&&!!s.backdropFilter&&"none"!==s.backdropFilter||!e&&!!s.filter&&"none"!==s.filter||["transform","perspective","filter"].some((t=>(s.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(s.contain||"").includes(t)))}function J(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function tt(t){return["html","body","#document"].includes(F(t))}function et(t){return P(t).getComputedStyle(t)}function st(t){return Y(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function it(t){if("html"===F(t))return t;const e=t.assignedSlot||t.parentNode||U(t)&&t.host||V(t);return U(e)?e.host:e}function ot(t){const e=it(t);return tt(e)?t.ownerDocument?t.ownerDocument.body:t.body:_(e)&&K(e)?e:ot(e)}function nt(t,e,s){var i;void 0===e&&(e=[]),void 0===s&&(s=!0);const o=ot(t),n=o===(null==(i=t.ownerDocument)?void 0:i.body),l=P(o);if(n){const t=lt(l);return e.concat(l,l.visualViewport||[],K(o)?o:[],t&&s?nt(t):[])}return e.concat(o,nt(o,[],s))}function lt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function rt(t){const e=et(t);let s=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const o=_(t),n=o?t.offsetWidth:s,l=o?t.offsetHeight:i,r=M(s)!==n||M(i)!==l;return r&&(s=n,i=l),{width:s,height:i,$:r}}function at(t){return Y(t)?t:t.contextElement}function ct(t){const e=at(t);if(!_(e))return L(1);const s=e.getBoundingClientRect(),{width:i,height:o,$:n}=rt(e);let l=(n?M(s.width):s.width)/i,r=(n?M(s.height):s.height)/o;return l&&Number.isFinite(l)||(l=1),r&&Number.isFinite(r)||(r=1),{x:l,y:r}}const dt=L(0);function ht(t){const e=P(t);return J()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:dt}function ut(t,e,s,i){void 0===e&&(e=!1),void 0===s&&(s=!1);const o=t.getBoundingClientRect(),n=at(t);let l=L(1);e&&(i?Y(i)&&(l=ct(i)):l=ct(t));const r=function(t,e,s){return void 0===e&&(e=!1),!(!s||e&&s!==P(t))&&e}(n,s,i)?ht(n):L(0);let a=(o.left+r.x)/l.x,c=(o.top+r.y)/l.y,d=o.width/l.x,h=o.height/l.y;if(n){const t=P(n),e=i&&Y(i)?P(i):i;let s=t,o=lt(s);for(;o&&i&&e!==s;){const t=ct(o),e=o.getBoundingClientRect(),i=et(o),n=e.left+(o.clientLeft+parseFloat(i.paddingLeft))*t.x,l=e.top+(o.clientTop+parseFloat(i.paddingTop))*t.y;a*=t.x,c*=t.y,d*=t.x,h*=t.y,a+=n,c+=l,s=P(o),o=lt(s)}}return W({width:d,height:h,x:a,y:c})}function pt(t,e){const s=st(t).scrollLeft;return e?e.left+s:ut(V(t)).left+s}function bt(t,e,s){void 0===s&&(s=!1);const i=t.getBoundingClientRect();return{x:i.left+e.scrollLeft-(s?0:pt(t,i)),y:i.top+e.scrollTop}}function mt(t,e,s){let i;if("viewport"===e)i=function(t,e){const s=P(t),i=V(t),o=s.visualViewport;let n=i.clientWidth,l=i.clientHeight,r=0,a=0;if(o){n=o.width,l=o.height;const t=J();(!t||t&&"fixed"===e)&&(r=o.offsetLeft,a=o.offsetTop)}return{width:n,height:l,x:r,y:a}}(t,s);else if("document"===e)i=function(t){const e=V(t),s=st(t),i=t.ownerDocument.body,o=y(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),n=y(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let l=-s.scrollLeft+pt(t);const r=-s.scrollTop;return"rtl"===et(i).direction&&(l+=y(e.clientWidth,i.clientWidth)-o),{width:o,height:n,x:l,y:r}}(V(t));else if(Y(e))i=function(t,e){const s=ut(t,!0,"fixed"===e),i=s.top+t.clientTop,o=s.left+t.clientLeft,n=_(t)?ct(t):L(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:o*n.x,y:i*n.y}}(e,s);else{const s=ht(t);i={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return W(i)}function ft(t,e){const s=it(t);return!(s===e||!Y(s)||tt(s))&&("fixed"===et(s).position||ft(s,e))}function gt(t,e,s){const i=_(e),o=V(e),n="fixed"===s,l=ut(t,!0,n,e);let r={scrollLeft:0,scrollTop:0};const a=L(0);if(i||!i&&!n)if(("body"!==F(e)||K(o))&&(r=st(e)),i){const t=ut(e,!0,n,e);a.x=t.x+e.clientLeft,a.y=t.y+e.clientTop}else o&&(a.x=pt(o));const c=!o||i||n?L(0):bt(o,r);return{x:l.left+r.scrollLeft-a.x-c.x,y:l.top+r.scrollTop-a.y-c.y,width:l.width,height:l.height}}function wt(t){return"static"===et(t).position}function vt(t,e){if(!_(t)||"fixed"===et(t).position)return null;if(e)return e(t);let s=t.offsetParent;return V(t)===s&&(s=s.ownerDocument.body),s}function xt(t,e){const s=P(t);if(G(t))return s;if(!_(t)){let e=it(t);for(;e&&!tt(e);){if(Y(e)&&!wt(e))return e;e=it(e)}return s}let i=vt(t,e);for(;i&&Z(i)&&wt(i);)i=vt(i,e);return i&&tt(i)&&wt(i)&&!Q(i)?s:i||function(t){let e=it(t);for(;_(e)&&!tt(e);){if(Q(e))return e;if(G(e))return null;e=it(e)}return null}(t)||s}const Ct={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:s,offsetParent:i,strategy:o}=t;const n="fixed"===o,l=V(i),r=!!e&&G(e.floating);if(i===l||r&&n)return s;let a={scrollLeft:0,scrollTop:0},c=L(1);const d=L(0),h=_(i);if((h||!h&&!n)&&(("body"!==F(i)||K(l))&&(a=st(i)),_(i))){const t=ut(i);c=ct(i),d.x=t.x+i.clientLeft,d.y=t.y+i.clientTop}const u=!l||h||n?L(0):bt(l,a,!0);return{width:s.width*c.x,height:s.height*c.y,x:s.x*c.x-a.scrollLeft*c.x+d.x+u.x,y:s.y*c.y-a.scrollTop*c.y+d.y+u.y}},getDocumentElement:V,getClippingRect:function(t){let{element:e,boundary:s,rootBoundary:i,strategy:o}=t;const n=[..."clippingAncestors"===s?G(e)?[]:function(t,e){const s=e.get(t);if(s)return s;let i=nt(t,[],!1).filter((t=>Y(t)&&"body"!==F(t))),o=null;const n="fixed"===et(t).position;let l=n?it(t):t;for(;Y(l)&&!tt(l);){const e=et(l),s=Q(l);s||"fixed"!==e.position||(o=null),(n?!s&&!o:!s&&"static"===e.position&&o&&["absolute","fixed"].includes(o.position)||K(l)&&!s&&ft(t,l))?i=i.filter((t=>t!==l)):o=e,l=it(l)}return e.set(t,i),i}(e,this._c):[].concat(s),i],l=n[0],r=n.reduce(((t,s)=>{const i=mt(e,s,o);return t.top=y(i.top,t.top),t.right=C(i.right,t.right),t.bottom=C(i.bottom,t.bottom),t.left=y(i.left,t.left),t}),mt(e,l,o));return{width:r.right-r.left,height:r.bottom-r.top,x:r.left,y:r.top}},getOffsetParent:xt,getElementRects:async function(t){const e=this.getOffsetParent||xt,s=this.getDimensions,i=await s(t.floating);return{reference:gt(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:i.width,height:i.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:s}=rt(t);return{width:e,height:s}},getScale:ct,isElement:Y,isRTL:function(t){return"rtl"===et(t).direction}};function yt(t,e,s,i){void 0===i&&(i={});const{ancestorScroll:o=!0,ancestorResize:n=!0,elementResize:l="function"==typeof ResizeObserver,layoutShift:r="function"==typeof IntersectionObserver,animationFrame:a=!1}=i,c=at(t),d=o||n?[...c?nt(c):[],...nt(e)]:[];d.forEach((t=>{o&&t.addEventListener("scroll",s,{passive:!0}),n&&t.addEventListener("resize",s)}));const h=c&&r?function(t,e){let s,i=null;const o=V(t);function n(){var t;clearTimeout(s),null==(t=i)||t.disconnect(),i=null}return function l(r,a){void 0===r&&(r=!1),void 0===a&&(a=1),n();const{left:c,top:d,width:h,height:u}=t.getBoundingClientRect();if(r||e(),!h||!u)return;const p={rootMargin:-I(d)+"px "+-I(o.clientWidth-(c+h))+"px "+-I(o.clientHeight-(d+u))+"px "+-I(c)+"px",threshold:y(0,C(1,a))||1};let b=!0;function m(t){const e=t[0].intersectionRatio;if(e!==a){if(!b)return l();e?l(!1,e):s=setTimeout((()=>{l(!1,1e-7)}),1e3)}b=!1}try{i=new IntersectionObserver(m,{...p,root:o.ownerDocument})}catch(t){i=new IntersectionObserver(m,p)}i.observe(t)}(!0),n}(c,s):null;let u,p=-1,b=null;l&&(b=new ResizeObserver((t=>{let[i]=t;i&&i.target===c&&b&&(b.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame((()=>{var t;null==(t=b)||t.observe(e)}))),s()})),c&&!a&&b.observe(c),b.observe(e));let m=a?ut(t):null;return a&&function e(){const i=ut(t);!m||i.x===m.x&&i.y===m.y&&i.width===m.width&&i.height===m.height||s();m=i,u=requestAnimationFrame(e)}(),s(),()=>{var t;d.forEach((t=>{o&&t.removeEventListener("scroll",s),n&&t.removeEventListener("resize",s)})),null==h||h(),null==(t=b)||t.disconnect(),b=null,a&&cancelAnimationFrame(u)}}const Mt=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var s,i;const{x:o,y:n,placement:l,middlewareData:r}=e,a=await async function(t,e){const{placement:s,platform:i,elements:o}=t,n=await(null==i.isRTL?void 0:i.isRTL(o.floating)),l=T(s),r=B(s),a="y"===O(s),c=["left","top"].includes(l)?-1:1,d=n&&a?-1:1,h=R(e,t);let{mainAxis:u,crossAxis:p,alignmentAxis:b}="number"==typeof h?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return r&&"number"==typeof b&&(p="end"===r?-1*b:b),a?{x:p*d,y:u*c}:{x:u*c,y:p*d}}(e,t);return l===(null==(s=r.offset)?void 0:s.placement)&&null!=(i=r.arrow)&&i.alignmentOffset?{}:{x:o+a.x,y:n+a.y,data:{...a,placement:l}}}}},It=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:s,y:i,placement:o}=e,{mainAxis:n=!0,crossAxis:l=!1,limiter:r={fn:t=>{let{x:e,y:s}=t;return{x:e,y:s}}},...a}=R(t,e),c={x:s,y:i},d=await D(e,a),h=O(T(o)),u=k(h);let p=c[u],b=c[h];if(n){const t="y"===u?"bottom":"right";p=S(p+d["y"===u?"top":"left"],p,p-d[t])}if(l){const t="y"===h?"bottom":"right";b=S(b+d["y"===h?"top":"left"],b,b-d[t])}const m=r.fn({...e,[u]:p,[h]:b});return{...m,data:{x:m.x-s,y:m.y-i,enabled:{[u]:n,[h]:l}}}}}},Lt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var s,i;const{placement:o,middlewareData:n,rects:l,initialPlacement:r,platform:a,elements:c}=e,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:u,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:b="none",flipAlignment:m=!0,...f}=R(t,e);if(null!=(s=n.arrow)&&s.alignmentOffset)return{};const g=T(o),w=O(r),v=T(r)===r,x=await(null==a.isRTL?void 0:a.isRTL(c.floating)),C=u||(v||!m?[q(r)]:function(t){const e=q(t);return[$(t),e,$(e)]}(r)),y="none"!==b;!u&&y&&C.push(...function(t,e,s,i){const o=B(t);let n=function(t,e,s){const i=["left","right"],o=["right","left"],n=["top","bottom"],l=["bottom","top"];switch(t){case"top":case"bottom":return s?e?o:i:e?i:o;case"left":case"right":return e?n:l;default:return[]}}(T(t),"start"===s,i);return o&&(n=n.map((t=>t+"-"+o)),e&&(n=n.concat(n.map($)))),n}(r,m,b,x));const M=[r,...C],I=await D(e,f),L=[];let N=(null==(i=n.flip)?void 0:i.overflows)||[];if(d&&L.push(I[g]),h){const t=function(t,e,s){void 0===s&&(s=!1);const i=B(t),o=A(t),n=z(o);let l="x"===o?i===(s?"end":"start")?"right":"left":"start"===i?"bottom":"top";return e.reference[n]>e.floating[n]&&(l=q(l)),[l,q(l)]}(o,l,x);L.push(I[t[0]],I[t[1]])}if(N=[...N,{placement:o,overflows:L}],!L.every((t=>t<=0))){var E,S;const t=((null==(E=n.flip)?void 0:E.index)||0)+1,e=M[t];if(e)return{data:{index:t,overflows:N},reset:{placement:e}};let s=null==(S=N.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:S.placement;if(!s)switch(p){case"bestFit":{var k;const t=null==(k=N.filter((t=>{if(y){const e=O(t.placement);return e===w||"y"===e}return!0})).map((t=>[t.placement,t.overflows.filter((t=>t>0)).reduce(((t,e)=>t+e),0)])).sort(((t,e)=>t[1]-e[1]))[0])?void 0:k[0];t&&(s=t);break}case"initialPlacement":s=r}if(o!==s)return{reset:{placement:s}}}return{}}}},Nt=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:s,y:i,placement:o,rects:n,middlewareData:l}=e,{offset:r=0,mainAxis:a=!0,crossAxis:c=!0}=R(t,e),d={x:s,y:i},h=O(o),u=k(h);let p=d[u],b=d[h];const m=R(r,e),f="number"==typeof m?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(a){const t="y"===u?"height":"width",e=n.reference[u]-n.floating[t]+f.mainAxis,s=n.reference[u]+n.reference[t]-f.mainAxis;p<e?p=e:p>s&&(p=s)}if(c){var g,w;const t="y"===u?"width":"height",e=["top","left"].includes(T(o)),s=n.reference[h]-n.floating[t]+(e&&(null==(g=l.offset)?void 0:g[h])||0)+(e?0:f.crossAxis),i=n.reference[h]+n.reference[t]+(e?0:(null==(w=l.offset)?void 0:w[h])||0)-(e?f.crossAxis:0);b<s?b=s:b>i&&(b=i)}return{[u]:p,[h]:b}}}},Et=(t,e,s)=>{const i=new Map,o={platform:Ct,...s},n={...o.platform,_c:i};return(async(t,e,s)=>{const{placement:i="bottom",strategy:o="absolute",middleware:n=[],platform:l}=s,r=n.filter(Boolean),a=await(null==l.isRTL?void 0:l.isRTL(e));let c=await l.getElementRects({reference:t,floating:e,strategy:o}),{x:d,y:h}=H(c,i,a),u=i,p={},b=0;for(let s=0;s<r.length;s++){const{name:n,fn:m}=r[s],{x:f,y:g,data:w,reset:v}=await m({x:d,y:h,initialPlacement:i,placement:u,strategy:o,middlewareData:p,rects:c,platform:l,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[n]:{...p[n],...w}},v&&b<=50&&(b++,"object"==typeof v&&(v.placement&&(u=v.placement),v.rects&&(c=!0===v.rects?await l.getElementRects({reference:t,floating:e,strategy:o}):v.rects),({x:d,y:h}=H(c,u,a))),s=-1)}return{x:d,y:h,placement:u,strategy:o,middlewareData:p}})(t,e,{...o,platform:n})};let St;const Rt=(t,e={})=>{const{msg:s="",delay:i=150,content:o,direction:l="bottom",type:r="hover",container:a,onOpen:c,onClose:d,closed:h,onDestroy:u}=e,p=n("tooltip");if(s||o){St||(St=document.createElement("div"),document.body.appendChild(St));const e=a||St,n=document.createElement("div");let b,m,f;n.classList.add(p.b(),"hidden","transparent"),o?n.appendChild(o):s&&(n.textContent=s);const g=()=>{f&&f(),Et(t,n,{placement:l,middleware:[Lt(),It({limiter:Nt()}),Mt(4)]}).then((({x:t,y:e})=>{Object.assign(n.style,{left:`${t}px`,top:`${e}px`})}))},w=()=>{n.classList.add("hidden"),e.contains(n)&&e.removeChild(n),f&&f(),h&&h()},v=(s=!1)=>{m&&clearTimeout(m),b=setTimeout((()=>{if(c){const t=c(s);if(!s&&t)return}e.appendChild(n),n.removeEventListener("transitionend",w),n.classList.remove("hidden"),f=yt(t,n,g),n.classList.remove("transparent")}),i)},x=(t=!1)=>{b&&clearTimeout(b),m=setTimeout((()=>{if(d){const e=d(t);if(!t&&e)return}n.addEventListener("transitionend",w,{once:!0}),n.classList.add("transparent")}),i)},C=()=>{const e=t=>{t.stopPropagation(),x(!1)},s=t=>{t.stopPropagation(),v(),document.removeEventListener("click",e),document.addEventListener("click",e,{once:!0})};return{prepare:()=>{n.addEventListener("click",(t=>t.stopPropagation())),t.addEventListener("click",s)},show:v,hide:(t=!1)=>{x(t),document.removeEventListener("click",e)},destroy:()=>{t.removeEventListener("click",s),document.removeEventListener("click",e)}}},y={hover:()=>{const e=[t,n],s=x.bind(void 0,!1),i=v.bind(void 0,!1);return{prepare:()=>{for(const t of e)t.addEventListener("mouseenter",i),t.addEventListener("mouseleave",s)},show:v,hide:x,destroy:()=>{for(const t of e)t.removeEventListener("mouseenter",i),t.removeEventListener("mouseleave",s)}}},click:C},{prepare:M,show:I,hide:L,destroy:N}=y[r]();M();const E=()=>{L(!0),u&&u(),N(),f&&f(),n.remove()};return{show:I,hide:L,destroy:E}}return null};function Tt(t,e,s=4){const{x:i,y:o,x1:n,y1:l}=t,{x:r,y:a,x1:c,y1:d}=e;return!(n<=r+s||i+s>=c||(l<=a+s||o+s>=d))}const Bt=()=>Math.random().toString(36).slice(2),kt=(t,e)=>{let s;return function(...i){s&&clearTimeout(s),s=setTimeout((()=>{t.apply(this,i)}),e)}};function zt(t,e){let s=t.parent;for(;s&&s.statics.blotName!==e&&s!==t.scroll;)s=s.parent;if(s===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return s}function Ot(t,e){const s=new Array(e.length),i=new Map(e.map(((t,e)=>[t,e])));let o=t.parent;for(;o&&o!==t.scroll&&0!==i.size;){if(i.has(o.statics.blotName)){s[i.get(o.statics.blotName)]=o,i.delete(o.statics.blotName)}o=o.parent}if(i.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(i.keys()).join(", ")}`);return s}function At(t,e){for(const s of Object.getOwnPropertyNames(e))/^constructor$/.test(s)||Object.defineProperty(t,s,Object.getOwnPropertyDescriptor(e,s));return t}function $t(t,e){const s=class extends t{constructor(...t){super(...t)}};for(const t of e)At(s.prototype,t.prototype);return s}const qt=t=>{let{left:e,top:s,width:i,height:o}=t;const{clientWidth:n,clientHeight:l}=document.documentElement;let r=!1,a=!1;return e+i>n?(e=n-i-8,r=!0):e<0&&(e=8,r=!0),s+o>l?(s=l-o-8,a=!0):s<0&&(s=8,a=!0),{left:e,top:s,leftLimited:r,topLimited:a}};function Wt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function Ht(){for(let t=0;t<this.scrollHandler.length;t++){const[e,s]=this.scrollHandler[t];e.removeEventListener("scroll",s)}this.scrollHandler=[]}const Dt=t.import("parchment"),jt=t.import("blots/container"),Ft=t.import("blots/block"),Pt=t.import("blots/block/embed");class Vt extends jt{static tagName;static blotName=e.container;static scope=Dt.Scope.BLOCK_BLOT;static allowedChildren=[Ft,Pt,jt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,s){const[i]=this.children.find(t);if(!i){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,s)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const Xt=t.import("parchment"),Yt=t.import("blots/block");class _t extends Yt{replaceWith(t,s){const i="string"==typeof t?this.scroll.create(t,s):t;if(i instanceof Xt.ParentBlot){if(i.statics.blotName===e.tableCellInner){const t=this.parent;if(t.statics.blotName===e.tableCellInner){if(null!=t&&t.insertBefore(i,this.prev?null:this.next),this.parent.statics.blotName===e.tableCellInner&&this.prev){let t=this;for(;t;){const e=t.next;i.appendChild(t),t=e}}else i.appendChild(this);if(t&&0===t.length()){t.parent.remove();const s=t.parent.parent;s.statics.blotName===e.tableRow&&0===s.children.length&&s.remove()}}else null!=t&&t.insertBefore(i,this.next),i.appendChild(this);return i}this.moveChildren(i)}return null!=this.parent&&(this.parent.insertBefore(i,this.next||void 0),this.remove()),this.attributes.copy(i),i}format(t,s){if(t!==e.tableCellInner||this.parent.statics.blotName!==t||s)super.format(t,s);else{const[t,s,i]=Ot(this,[e.tableCell,e.tableRow,e.tableWrapper]),o=i.next;let n=s.next,l=t.next;for(i.parent.insertBefore(this,o);l;){const t=l.next;i.parent.insertBefore(l,o),l=t}for(;n;){const t=n.next;i.parent.insertBefore(n,o),n=t}}}}const Ut=t.import("formats/blockquote");class Kt extends($t(Ut,[_t])){}const Zt=t.import("formats/code-block");class Gt extends($t(Zt,[_t])){}const Qt=t.import("formats/header");class Jt extends($t(Qt,[_t])){}const te=t.import("formats/list");class ee extends($t(te,[_t])){static register(){}}const se=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},ie=t.import("blots/block"),oe=t.import("blots/block/embed");class ne extends Vt{static blotName=e.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static allowDataAttrs=new Set(["table-id","row-id","col-id","rowspan","colspan"]);static defaultChild=ie;static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:i,rowspan:o,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=i,r.dataset.rowspan=String(se(o)),r.dataset.colspan=String(se(n)),l&&(r.dataset.style=l),r}static formats(t){const{tableId:e,rowId:s,colId:i,rowspan:o,colspan:n,style:l}=t.dataset,r={tableId:e,rowId:s,colId:i,rowspan:Number(se(o)),colspan:Number(se(n))};return l&&(r.style=l),r}setFormatValue(t,e,s=!1){if(s){if(!this.statics.isAllowStyle(t))return;this.parent&&(this.parent.setFormatValue(t,e),this.domNode.dataset.style=this.parent.domNode.style.cssText)}else{if(!this.statics.allowDataAttrs.has(t))return;const s=`data-${t}`;e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s),this.parent&&this.parent.setFormatValue(t,e)}const i=this.descendants(ie,0);for(const t of i)t.cache={}}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}set rowId(t){this.setFormatValue("row-id",t)}get colId(){return this.domNode.dataset.colId}set colId(t){this.setFormatValue("col-id",t)}get rowspan(){return Number(this.domNode.dataset.rowspan)}set rowspan(t){this.setFormatValue("rowspan",t)}get colspan(){return Number(this.domNode.dataset.colspan)}set colspan(t){this.setFormatValue("colspan",t)}getColumnIndex(){return zt(this,e.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,s,i){0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,s,i)}formats(){const t=this.statics.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:i}=this,o=this.next;return null!==o&&o.statics.blotName===this.statics.blotName&&o.rowId===e&&o.colId===t&&o.colspan===s&&o.rowspan===i}optimize(){const t=this.parent,s=this.statics.formats(this.domNode);if(this.prev&&this.prev instanceof oe){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==e.tableCell&&(this.wrap(e.tableCell,s),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,s){if(t.statics.blotName===this.statics.blotName){const i=t,o=this.statics.formats(i.domNode),n=this.statics.formats(this.domNode);if(Object.entries(n).every((([t,e])=>e===o[t])))return this.parent.insertBefore(i,this.next);{const[t,l]=Ot(this,[e.tableRow,e.tableCell]);if(s){const i=s.offset();if(i+1<this.length()){const s=this.scroll.create(e.tableCellInner,n);this.children.forEachAt(i+1,this.length(),(t=>{s.appendChild(t)})),t.insertBefore(s.wrap(e.tableCell,n),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==i.rowId){if(s){const e=s.offset(t);t.split(e)}else if(l.next){const e=l.next.offset(t);t.split(e)}const n=this.scroll.create(e.tableRow,o),r=this.scroll.create(e.tableCell,o);return r.appendChild(i),n.appendChild(r),t.parent.insertBefore(n,t.next)}return t.insertBefore(i.wrap(e.tableCell,o),s?l:l.next)}}super.insertBefore(t,s)}}const le=t.import("parchment"),re=t.import("blots/scroll");class ae extends re{createBlock(t,s){let i,o={};if(t[e.tableCellInner])i=e.tableCellInner;else for(const[e,s]of Object.entries(t)){null!=this.query(e,le.Scope.BLOCK&le.Scope.BLOT)?i=e:o[e]=s}i===e.tableCellInner&&(o={...t},delete o[i]);const n=this.create(i||this.statics.defaultChild.blotName,i?t[i]:void 0);this.insertBefore(n,s||void 0);let l=n.length();n instanceof ne&&0===l&&(l+=1);for(const[t,e]of Object.entries(o))n.formatAt(0,l,t,e);return n}}class ce extends Vt{static blotName=e.tableRow;static tagName="tr";static className="ql-table-row";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,e.dataset.rowId=t.rowId,e}get rowId(){return this.domNode.dataset.rowId}get tableId(){return this.domNode.dataset.tableId}setHeight(t){this.foreachCellInner((e=>{e.setFormatValue("height",t,!0)}))}insertCell(t,s){const i=[],o=this.children.iterator();let n,l=0;for(;(n=o())&&(l+=n.colspan,!(l>t));)if(1!==n.rowspan)for(let t=0;t<n.rowspan-1;t++)i[t]=(i[t]||0)+n.colspan;if(n&&l-n.colspan<t){n.getCellInner().colspan+=1,1!==n.rowspan&&(i.skipRowNum=n.rowspan-1)}else{const t=this.scroll.create(e.tableCell,s),i=this.scroll.create(e.tableCellInner,s),o=this.scroll.create("block");o.appendChild(this.scroll.create("break")),i.appendChild(o),t.appendChild(i),this.insertBefore(t,n)}return i}getCellByColumIndex(t){const e=[];let s=null,i=0;if(t<0)return[s,i,e];const o=this.children.iterator();for(;s=o();){if(i+=s.colspan,1!==s.rowspan)for(let t=0;t<s.rowspan-1;t++)e[t]=(e[t]||0)+s.colspan;if(i>t)break}return[s,i,e]}removeCell(t){if(t<0)return[];const s=this.getCellByColumIndex(t),[i,o]=s,n=s[2];if(!i)return n;if(o-i.colspan<t||i.colspan>1){const[s]=i.descendants(ne);if(1!==i.colspan&&t===o-i.colspan){const t=zt(this,e.tableMain).getColIds();s.colId=t[t.indexOf(s.colId)+1]}1!==i.rowspan&&(n.skipRowNum=i.rowspan-1),s.colspan-=1}else i.remove();return n}foreachCellInner(t){const e=this.children.iterator();let s,i=0;for(;s=e();){const[e]=s.descendants(ne);if(t(e,i++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const s=this.parent,{tableId:i}=this;null!==s&&s.statics.blotName!==e.tableBody&&this.wrap(e.tableBody,i),super.optimize(t)}}class de extends Vt{static blotName=e.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const s=zt(this,e.tableMain);if(!s)return;const i=s.getColIds(),o=this.descendants(ce),n=new Set(i);let l=0;for(const e of o){if(l===t)break;e.foreachCellInner((e=>{if(l+e.rowspan>t&&(e.rowspan+=1,n.delete(e.colId),1!==e.colspan)){const t=i.indexOf(e.colId);for(let s=0;s<e.colspan-1;s++)n.delete(i[t+s+1])}})),l+=1}const r=s.tableId,a=Bt(),c=this.scroll.create(e.tableRow,{tableId:r,rowId:a});for(const t of n){const s=this.scroll.create("break").wrap("block").wrap(e.tableCellInner,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1}).wrap(e.tableCell,{tableId:r,rowId:a,colId:t,rowspan:1,colspan:1});c.appendChild(s)}this.insertBefore(c,o[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const s=this.parent;if(null!==s&&s.statics.blotName!==e.tableMain){const{tableId:t}=this;this.wrap(e.tableMain,{tableId:t})}super.optimize(t)}}class he extends Vt{static blotName=e.tableCell;static tagName="td";static className="ql-table-cell";static allowDataAttrs=new Set(["table-id","row-id","col-id"]);static allowAttrs=new Set(["rowspan","colspan"]);static allowStyle=new Set(["background-color","border","height"]);static isAllowStyle(t){for(const e of this.allowStyle)if(t.startsWith(e))return!0;return!1}static create(t){const{tableId:e,rowId:s,colId:i,rowspan:o,colspan:n,style:l}=t,r=super.create();return r.dataset.tableId=e,r.dataset.rowId=s,r.dataset.colId=i,r.setAttribute("rowspan",String(se(o))),r.setAttribute("colspan",String(se(n))),l&&(r.style.cssText=l),r}static formats(t){const{tableId:e,rowId:s,colId:i}=t.dataset,o=Number(t.getAttribute("rowspan")),n=Number(t.getAttribute("colspan")),l={tableId:e,rowId:s,colId:i,rowspan:se(o),colspan:se(n)},r={};for(let e=0;e<t.style.length;e++){const s=t.style[e],i=t.style[s];this.isAllowStyle(String(s))&&!["initial","inherit"].includes(i)&&(r[s]=i)}const a=Object.entries(r);return a.length>0&&(l.style=a.map((([t,e])=>`${t}:${e}`)).join(";")),l}setFormatValue(t,e){if(this.statics.allowAttrs.has(t)||this.statics.allowDataAttrs.has(t)){let s=t;this.statics.allowDataAttrs.has(t)&&(s=`data-${t}`),e?this.domNode.setAttribute(s,e):this.domNode.removeAttribute(s)}else this.statics.isAllowStyle(t)&&Object.assign(this.domNode.style,{[t]:e})}get tableId(){return this.domNode.dataset.tableId}get rowId(){return this.domNode.dataset.rowId}get colId(){return this.domNode.dataset.colId}get rowspan(){return Number(this.domNode.getAttribute("rowspan"))}get colspan(){return Number(this.domNode.getAttribute("colspan"))}getCellInner(){return this.children.head}checkMerge(){const{colId:t,rowId:e,colspan:s,rowspan:i}=this,o=this.next;return null!==o&&o.statics.blotName===this.statics.blotName&&o.rowId===e&&o.colId===t&&o.colspan===s&&o.rowspan===i}optimize(t){const s=this.parent,{tableId:i,rowId:o}=this;null!==s&&s.statics.blotName!==e.tableRow&&this.wrap(e.tableRow,{tableId:i,rowId:o}),super.optimize(t)}}const ue=t.import("blots/block/embed");class pe extends ue{scroll;domNode;static blotName=e.tableCol;static tagName="col";static validWidth(t,e){let i=Number.parseFloat(String(t));return Number.isNaN(i)&&(i=s[e?"colMinWidthPre":"colMinWidthPx"]),`${i}${e?"%":"px"}`}static create(t){const{width:e,tableId:s,colId:i,full:o,align:n}=t,l=super.create();return l.setAttribute("width",this.validWidth(e,!!o)),o&&(l.dataset.full=String(o)),n&&"left"!==n&&(l.dataset.align=n),l.dataset.tableId=s,l.dataset.colId=i,l}static value(t){const{tableId:e,colId:i}=t.dataset,o=t.getAttribute("width")||s.colDefaultWidth,n=t.dataset.align,l={tableId:e,colId:i,full:Object.hasOwn(t.dataset,"full")};return o&&(l.width=Number.parseFloat(o)),n&&(l.align=n),l}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){let t=this.domNode.getAttribute("width");if(!t){if(t=this.domNode.getBoundingClientRect().width,this.full){const e=this.domNode.closest("table");return e?t/100*e.getBoundingClientRect().width:s[this.full?"colMinWidthPre":"colMinWidthPx"]}return t}return Number.parseFloat(String(t))}set width(t){let e=Number.parseFloat(String(t));Number.isNaN(e)&&(e=s[this.full?"colMinWidthPre":"colMinWidthPx"]),this.domNode.setAttribute("width",this.statics.validWidth(e,!!this.full))}get tableId(){return this.domNode.dataset.tableId}get colId(){return this.domNode.dataset.colId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}checkMerge(){const t=this.next,{tableId:e,colId:s}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===s}optimize(t){const s=this.parent;if(null!=s&&s.statics.blotName!==e.tableColgroup){const t=this.statics.value(this.domNode);this.wrap(e.tableColgroup,t)}zt(this,e.tableColgroup).align=this.align,super.optimize(t)}insertAt(t,s,i){if(null!=i)return void super.insertAt(t,s,i);const o=s.split("\n"),n=o.pop(),l=o.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),r=this.split(t),[a,c]=Ot(this,[e.tableColgroup,e.tableMain]),d=a.next;if(r){const t=r.offset(a);a.split(t)}let h=c.parent.parent,u=c.parent.next;if(d){const t=d.descendants(ne);if(t.length>0){const s=t[0],i=ne.formats(s.domNode),o=this.scroll.create("block"),n=o.wrap(e.tableCellInner,i).wrap(e.tableCell,i).wrap(e.tableRow,i).wrap(e.tableBody,i.tableId);a.parent.insertBefore(n,a.next),h=o,u=o.next}}for(const t of l)h.insertBefore(t,u);n&&h.insertBefore(this.scroll.create("text",n),u)}}class be extends Vt{static blotName=e.tableMain;static tagName="table";static className="ql-table";static create(t){const e=super.create(),{tableId:s,full:i,align:o}=t;return e.dataset.tableId=s,"right"===o||"center"===o?e.dataset.align=o:e.removeAttribute("date-align"),i&&(e.dataset.full=String(i)),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,s){super(t,e),this.updateAlign()}colWidthFillTable(){if(this.full)return;const t=this.getCols();if(!t)return;const e=t.reduce(((t,e)=>e.width+t),0);return 0===e||Number.isNaN(e)?null:(this.domNode.style.width=`${e}px`,e)}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align"),this.updateAlign()}cancelFull(){if(!this.full)return;const t=this.getCols(),s=this.domNode.getBoundingClientRect().width;for(const e of t)e.domNode.removeAttribute("data-full"),e.width=e.width/100*s;const i=this.children.head;i&&i.statics.blotName===e.tableColgroup&&(i.full=!1),this.domNode.removeAttribute("data-full"),this.colWidthFillTable()}updateAlign(){const t={marginLeft:null,marginRight:null};switch(this.align){case"center":t.marginLeft="auto",t.marginRight="auto";break;case"":case"left":t.marginRight="auto";break;case"right":t.marginLeft="auto"}Object.assign(this.domNode.style,t)}getRows(){return this.descendants(ce)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(pe)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const s=this.parent;null!==s&&s.statics.blotName!==e.tableWrapper&&this.wrap(e.tableWrapper,this.tableId),super.optimize(t)}}class me extends Vt{static blotName=e.tableColgroup;static tagName="colgroup";static create(t){const e=super.create();return e.dataset.tableId=t.tableId,t.full&&(e.dataset.full=String(t.full)),t.align&&"left"!==t.align&&(e.dataset.align=t.align),e.setAttribute("contenteditable","false"),e}get tableId(){return this.domNode.dataset.tableId}get full(){return Object.hasOwn(this.domNode.dataset,"full")}set full(t){t?this.domNode.dataset.full="true":this.domNode.removeAttribute("data-full")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let s,i=0;for(;(s=e())&&i!==t;)i++;return s}insertColByIndex(t,i){const o=this.parent;if(!(o instanceof be))throw new TypeError("TableColgroupFormat should be child of TableFormat");const n=this.findCol(t),l=this.scroll.create(e.tableCol,i);if(o.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=s.colMinWidthPre){e.width-=l.width;break}}this.insertBefore(l,n)}removeColByIndex(t){const e=this.parent;if(!(e instanceof be))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const s=this.findCol(t);s&&(e.full&&(s.next?s.next.width+=s.width:s.prev&&(s.prev.width+=s.width)),s.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof be&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const s=this.parent,{tableId:i,full:o,align:n}=this;null!=s&&s.statics.blotName!==e.tableMain&&this.wrap(e.tableMain,{tableId:i,full:o,align:n});zt(this,e.tableMain).align=n,super.optimize(t)}}class fe extends Vt{static blotName=e.tableWrapper;static tagName="div";static className="ql-table-wrapper";static create(t){const e=super.create();return e.dataset.tableId=t,e.addEventListener("dragstart",(t=>{t.preventDefault(),t.stopPropagation()}),!0),e.addEventListener("drop",(t=>{t.preventDefault()})),e.addEventListener("dragover",(t=>{t.preventDefault(),t.dataTransfer.dropEffect="none"})),e}get tableId(){return this.domNode.dataset.tableId}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}deleteAt(t,e){super.deleteAt(t,e);const s=this.descendants(de),i=this.descendants(me);0!==s.length&&0!==i.length||this.remove()}}class ge{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;bem=n("align");resizeObserver=new ResizeObserver((()=>this.hide()));constructor(e,s,i){this.tableModule=e,this.table=s,this.quill=i,this.tableBlot=t.find(s),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const e=this.tableModule.addContainer(this.bem.b()),s=t.import("ui/icons"),i={left:s.align[""],center:s.align.center,right:s.align.right};for(const[s,o]of Object.entries(i)){const i=document.createElement("span");i.dataset.align=s,i.classList.add(this.bem.be("item")),i.innerHTML=`<i class="icon">${o}</i>`,i.addEventListener("click",(()=>{const e=i.dataset.align;e&&(this.setTableAlign(this.tableBlot,e),this.quill.once(t.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hide(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableResizeScale&&this.tableModule.tableResizeScale.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),e.appendChild(i)}return this.cleanup||(this.cleanup=yt(this.tableWrapperBlot.domNode,e,(()=>this.update()))),e}setTableAlign(t,e){const s=t.getCols();for(const t of s)t.align=e}show(){this.alignBox&&(this.alignBox.classList.add(this.bem.bm("active")),this.resizeObserver.observe(this.table))}hide(){this.alignBox&&(this.alignBox.classList.remove(this.bem.bm("active")),this.cleanup&&(this.cleanup(),this.cleanup=void 0))}update(){this.alignBox&&(this.tableBlot.full||this.tableBlot.domNode.offsetWidth>=this.quill.root.offsetWidth?this.hide():(this.show(),Et(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[Lt(),It({limiter:Nt()}),Mt(16)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))))}destroy(){this.hide(),this.resizeObserver.disconnect(),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}}const we="color-selector",ve=[{name:"InsertTop",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm17.94 4.5h-2v4h-2v-4h-2l3-3z"/></svg>',tip:"Insert row above",handle:t=>{t.appendRow(!1),t.hideTableTools()}},{name:"InsertRight",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm15.44 8v-2h-4v-2h4v-2l3 3z"/></svg>',tip:"Insert column right",handle:t=>{t.appendCol(!0),t.hideTableTools()}},{name:"InsertBottom",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm11.94 5.5h2v-4h2v4h2l-3 3z"/></svg>',tip:"Insert row below",handle:t=>{t.appendRow(!0),t.hideTableTools()}},{name:"InsertLeft",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5c0-1.1.9-2 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4zm14.44 2v2h4v2h-4v2l-3-3z"/></svg>',tip:"Insert column Left",handle:t=>{t.appendCol(!1),t.hideTableTools()}},{name:"break"},{name:"MergeCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M5 10H3V4h8v2H5zm14 8h-6v2h8v-6h-2zM5 18v-4H3v6h8v-2zM21 4h-8v2h6v4h2zM8 13v2l3-3l-3-3v2H3v2zm8-2V9l-3 3l3 3v-2h5v-2z"/></svg>',tip:"Merge Cell",handle:t=>{t.mergeCells(),t.hideTableTools()}},{name:"SplitCell",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M19 14h2v6H3v-6h2v4h14zM3 4v6h2V6h14v4h2V4zm8 7v2H8v2l-3-3l3-3v2zm5 0V9l3 3l-3 3v-2h-3v-2z"/></svg>',tip:"Split Cell",handle:t=>{t.splitCell(),t.hideTableTools()}},{name:"break"},{name:"DeleteRow",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M9.41 13L12 15.59L14.59 13L16 14.41L13.41 17L16 19.59L14.59 21L12 18.41L9.41 21L8 19.59L10.59 17L8 14.41zM22 9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2zM4 9h4V6H4zm6 0h4V6h-4zm6 0h4V6h-4z"/></svg>',tip:"Delete Row",handle:t=>{t.removeRow(),t.hideTableTools()}},{name:"DeleteColumn",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M4 2h7a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m0 8v4h7v-4zm0 6v4h7v-4zM4 4v4h7V4zm13.59 8L15 9.41L16.41 8L19 10.59L21.59 8L23 9.41L20.41 12L23 14.59L21.59 16L19 13.41L16.41 16L15 14.59z"/></svg>',tip:"Delete Column",handle:t=>{t.removeCol(),t.hideTableTools()}},{name:"DeleteTable",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="m15.46 15.88l1.42-1.42L19 16.59l2.12-2.13l1.42 1.42L20.41 18l2.13 2.12l-1.42 1.42L19 19.41l-2.12 2.13l-1.42-1.42L17.59 18zM4 3h14a2 2 0 0 1 2 2v7.08a6 6 0 0 0-4.32.92H12v4h1.08c-.11.68-.11 1.35 0 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2m0 4v4h6V7zm8 0v4h6V7zm-8 6v4h6v-4z"/></svg>',tip:"Delete table",handle:t=>{t.deleteTable()}},{name:"break"},{name:"BackgroundColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m4 8l4-4m6 0L4 14m0 6L20 4m0 6L10 20m10-4l-4 4"/></svg>',isColorChoose:!0,tip:"Set background color",key:"background-color",handle:(t,e,s)=>{t.setCellAttrs(e,"background-color",s,!0)}},{name:"BorderColor",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m12.01 16l-.01.011M12.01 12l-.01.011M12.01 8l-.01.011M8.01 12l-.01.011M16.01 12l-.01.011M21 3.6v16.8a.6.6 0 0 1-.6.6H3.6a.6.6 0 0 1-.6-.6V3.6a.6.6 0 0 1 .6-.6h16.8a.6.6 0 0 1 .6.6"/></svg>',isColorChoose:!0,tip:"Set border color",key:"border-color",handle:(t,e,s)=>{t.setCellAttrs(e,"border-color",s,!0)}}],xe=new Set,Ce=n("color-map"),ye={selectWrapper:Ce.b(),used:Ce.bm("used"),item:Ce.be("item"),btn:Ce.be("btn"),map:Ce.be("content"),mapRow:Ce.be("content-row")};class Me{tableModule;quill;options;menu=null;updateUsedColor;tooltipItem=[];bem=n("menu");colorItemClass=`color-${Bt()}`;colorChooseTooltipOption={direction:"top"};constructor(t,e,s){this.tableModule=t,this.quill=e,this.options=this.resolveOptions(s);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);r(e)||(e=[]),e.slice(-10).map((t=>xe.add(t)))}catch{}this.updateUsedColor=kt((t=>{if(!t)return;if(xe.add(t),xe.size>10){const t=Array.from(xe).slice(-10);xe.clear(),t.map((t=>xe.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(xe)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${ye.used}`));for(const s of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=String(t);Array.from(s.querySelectorAll(`.${ye.item}[style*="background-color: ${e.style.backgroundColor}"]`)).length<=0&&s.appendChild(e);const i=Array.from(s.querySelectorAll(`.${ye.item}`)).slice(0,-10);for(const t of i)t.remove()}}),1e3)}resolveOptions(t){return Object.assign({tipText:!0,tipTexts:{},tools:ve,localstorageKey:"__table-bg-used-color",defaultColorMap:o},t)}getUsedColors(){return xe}buildTools(){const t=document.createElement("div");t.classList.add(this.bem.b()),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:s,icon:i,handle:o,isColorChoose:n,key:r,tip:a=""}=e,c=document.createElement("span");if(c.classList.add(this.bem.be("item")),"break"===s)c.classList.add(this.bem.is("break"));else{const t=document.createElement("i");if(t.classList.add("icon"),l(i)?t.appendChild(i(this.tableModule)):t.innerHTML=i,c.appendChild(t),n&&r){const t=this.createColorChoose(c,{name:s,icon:i,handle:o,isColorChoose:n,key:r,tip:a});this.tooltipItem.push(t),c.classList.add(we)}else l(o)&&c.addEventListener("click",(t=>{this.quill.focus(),o(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.options.tipTexts[s]||a;this.options.tipText&&e&&a&&this.createTipText(c,e)}t.appendChild(c)}return t}createColorChoose(t,{handle:e,key:s}){const i=document.createElement("div");if(i.classList.add(ye.selectWrapper),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(ye.map);for(const e of this.options.defaultColorMap){const s=document.createElement("div");s.classList.add(ye.mapRow);for(const t of e){const e=document.createElement("div");e.classList.add(ye.item),e.style.backgroundColor=t,s.appendChild(e)}t.appendChild(s)}i.appendChild(t)}const o=document.createElement("div");o.classList.add(ye.mapRow),Object.assign(o.style,{marginTop:"4px"});const n=document.createElement("div");n.classList.add(ye.btn,"transparent"),n.textContent=this.tableModule.options.texts.transparent,n.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),"transparent")}));const l=document.createElement("div");l.classList.add(ye.btn,"clear"),l.textContent=this.tableModule.options.texts.clear,l.addEventListener("click",(()=>{e(this.tableModule,this.getSelectedTds(),null)}));const r=document.createElement("div");r.classList.add(ye.btn,"custom"),r.textContent=this.tableModule.options.texts.custom;const a=f({onChange:t=>{e(this.tableModule,this.getSelectedTds(),t),this.updateUsedColor(t)}}),{hide:c,destroy:d}=Rt(r,{direction:"right",type:"click",content:a,container:r});if(o.appendChild(n),o.appendChild(l),o.appendChild(r),i.appendChild(o),xe.size>0){const t=document.createElement("div");t.classList.add(ye.used,this.colorItemClass);for(const e of xe){const s=document.createElement("div");s.classList.add(ye.item),s.style.backgroundColor=e,t.appendChild(s)}i.appendChild(t)}return i.addEventListener("click",(t=>{t.stopPropagation(),c();const e=t.target,i=e.style.backgroundColor,o=this.getSelectedTds();if(e&&i&&o.length>0){if(this.tableModule.setCellAttrs(o,s,i,!0),!e.closest(`.${ye.item}`))return;this.updateUsedColor(i)}})),Rt(t,{content:i,onClose(t){const e=i.contains(a);return t&&e&&c(),e},onDestroy(){d()},...this.colorChooseTooltipOption})}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const s=Rt(t,{msg:e});s&&this.tooltipItem.push(s)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&Object.assign(this.menu.style,{display:"flex"})}hide(){this.menu&&Object.assign(this.menu.style,{display:"none"});for(const t of this.tooltipItem)t.hide(!0)}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}class Ie extends Me{tableModule;quill;colorChooseTooltipOption={direction:"right"};constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),this.update({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hide()}),{once:!0})):this.hide()};buildTools(){const t=super.buildTools();t.classList.add(this.bem.is("contextmenu"));const e=t.getElementsByClassName(we);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const s=document.createElement("span");s.textContent=e,t.appendChild(s)}update(t){if(!this.menu||!this.tableModule.tableSelection||!this.tableModule.tableSelection.boundary)return;super.update();const e={display:"flex",left:0,top:0};if(!t)return this.hide();const{x:s,y:i}=t;e.left=s,e.top=i,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const o=this.menu.getBoundingClientRect(),{left:n,top:l}=qt(o);Object.assign(this.menu.style,{left:`${n+window.scrollX}px`,top:`${l+window.scrollY}px`})}destroy(){this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),super.destroy()}}class Le extends Me{tableModule;quill;constructor(t,e,s){super(t,e,s),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu)}update(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(super.update(),Et(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[Lt(),It({limiter:Nt()}),Mt(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}}const Ne=t=>!t.full&&"right"===t.align;class Ee{tableModule;quill;colIndex=-1;tableMain;dragging=!1;dragColBreak=null;handleColMouseUpFunc=this.handleColMouseUp.bind(this);handleColMouseMoveFunc=this.handleColMouseMove.bind(this);handleColMouseDownFunc=this.handleColMouseDown.bind(this);rowIndex=-1;dragRowBreak=null;handleRowMouseUpFunc=this.handleRowMouseUp.bind(this);handleRowMouseMoveFunc=this.handleRowMouseMove.bind(this);handleRowMouseDownFunc=this.handleRowMouseDown.bind(this);dragBEM=n("drag-line");constructor(t,e){this.tableModule=t,this.quill=e}findCurrentColIndex(t){return-1}colWidthChange(t,e,s){}async createConfirmDialog({message:t,confirm:e,cancel:s}){return new Promise((i=>{const o=document.createElement("div");Object.assign(o.style,{padding:"8px 12px",fontSize:"14px",lineHeight:"1.5"});const n=document.createElement("p");n.textContent=t;const l=document.createElement("div");Object.assign(l.style,{display:"flex",justifyContent:"flex-end",gap:"6px"});const r=c({content:s}),a=c({type:"confirm",content:e});l.appendChild(r),l.appendChild(a),o.appendChild(n),o.appendChild(l);const{close:d}=w({child:o});r.addEventListener("click",(()=>{i(!1),d()})),a.addEventListener("click",(()=>{i(!0),d()}))}))}async handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0");let o=this.tableMain.full,n=!1;const l=[];if(o){let i=e/this.tableMain.domNode.getBoundingClientRect().width*100;const o=t[this.colIndex].width;if(i<o){if(i=Math.max(s.colMinWidthPre,i),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1;l.push({index:e,width:t[e].width+o-i})}else i=100;n=!0,l.push({index:this.colIndex,width:i})}else if(t[this.colIndex+1]){const e=o+t[this.colIndex+1].width;i=Math.min(e-s.colMinWidthPre,i),n=!0,l.push({index:this.colIndex,width:i},{index:this.colIndex+1,width:e-i})}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,n=!0,l.push({index:this.colIndex,width:e});if(document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,n){const e=this.tableMain.domNode.getBoundingClientRect().width;if(o){let s=0;const i=new Set(l.map((({index:t,width:e})=>(s+=e,t))));for(const[e,o]of t.entries())i.has(e)||(s+=o.width);if(s>100){if(!await this.createConfirmDialog({message:this.tableModule.options.texts.perWidthInsufficient,confirm:this.tableModule.options.texts.confirmText,cancel:this.tableModule.options.texts.cancelText}))return;this.tableMain.cancelFull(),o=!1;for(const[t,s]of l.entries()){const{width:i,index:o}=s;l[t]={index:o,width:i/100*e}}}}for(const{index:s,width:i}of l)t[s].width=`${Math.round(i)}${o?"%":"px"}`,this.colWidthChange(s,o?i/100*e:i,o)}this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),i=e[this.colIndex].domNode.getBoundingClientRect(),o=this.tableMain.domNode.getBoundingClientRect();let n=t.clientX;if(this.tableMain.full){const t=s.colMinWidthPre/100*o.width;let l=o.right;n>i.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,i.left+t));const r=i.x+t;n=Math.min(Math.max(n,r),l)}else Ne(this.tableMain)?i.right-n<s.colMinWidthPx&&(n=i.right-s.colMinWidthPx):n-i.x<s.colMinWidthPx&&(n=i.x+s.colMinWidthPx);let l=n-i.x;return Ne(this.tableMain)&&(l=i.right-n),this.dragColBreak.style.left=`${n}px`,this.dragColBreak.dataset.w=String(l),{left:n,width:l}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),s=this.tableMain.domNode.getBoundingClientRect(),i=s.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const o=e[this.colIndex].width,n=this.tableMain.full?o/100*i:o;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const l=document.createElement("div");l.classList.add(this.dragBEM.b()),l.classList.add(this.dragBEM.is("col")),l.dataset.w=String(n);const r={top:s.y,left:t.clientX,height:s.height};Object.assign(l.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(l),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=l,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(i.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let i=t.clientY;return i-e.y<s.rowMinHeightPx&&(i=e.y+s.rowMinHeightPx),this.dragRowBreak.style.top=`${i}px`,this.dragRowBreak.dataset.h=String(i-e.y),{top:i,height:i-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,s=this.tableMain.domNode.getBoundingClientRect(),i=document.createElement("div");i.classList.add(this.dragBEM.b()),i.classList.add(this.dragBEM.is("row")),i.dataset.h=String(e);const o={top:t.clientY,left:s.x,width:s.width};Object.assign(i.style,{top:`${o.top}px`,left:`${o.left}px`,width:`${o.width}px`});const n=document.body;return n.appendChild(i),this.dragRowBreak&&n.removeChild(this.dragRowBreak),this.dragRowBreak=i,o}update(){}destroy(){}}class Se extends Ee{tableModule;table;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;size=12;bem=n("resize-box");constructor(e,s,i){super(e,i),this.tableModule=e,this.table=s,this.tableMain=t.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer(this.bem.b()),this.resizeObserver=new ResizeObserver((()=>{this.show()})),this.resizeObserver.observe(this.table)))}handleResizerHeader(t,e){const{clientX:s,clientY:i}=e,o=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const n=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const l=[{x:t?o.left:s,y:t?i:o.top},{x:t?o.right:s,y:t?i:o.bottom}];this.lastHeaderSelect?(l[0]={x:Math.min(l[0].x,this.lastHeaderSelect[0].x),y:Math.min(l[0].y,this.lastHeaderSelect[0].y)},l[1]={x:Math.max(l[1].x,this.lastHeaderSelect[1].x),y:Math.max(l[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=l,n.selectedTds=n.computeSelectedTds(...l),n.show()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("col-separator"))).indexOf(t.target)}colWidthChange(t,e,s){Array.from(this.root.getElementsByClassName(this.bem.be("col-header")))[t].style.width=`${e}px`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.size+"px",left:`${e.left}px`,height:`${e.height+this.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("col-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("col-separator")));Wt.call(this,this.tableWrapper.domNode,(()=>{this.colHeadWrapper.scrollLeft=this.tableWrapper.domNode.scrollLeft}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!1));for(const t of e)t.addEventListener("mousedown",this.handleColMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}findCurrentRowIndex(t){return Array.from(this.root.getElementsByClassName(this.bem.be("row-separator"))).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName(this.bem.be("row-header")))[t].style.height=`${e}px`}handleRowMouseDownFunc=function(t){const e=this.handleRowMouseDown(t);return e&&this.dragRowBreak&&Object.assign(this.dragRowBreak.style,{top:`${e.top}px`,left:e.left-this.size+"px",width:`${e.width+this.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName(this.bem.be("row-header"))),e=Array.from(this.root.getElementsByClassName(this.bem.be("row-separator")));Wt.call(this,this.tableWrapper.domNode,(()=>{this.rowHeadWrapper.scrollTop=this.tableWrapper.domNode.scrollTop}));for(const e of t)e.addEventListener("click",this.handleResizerHeader.bind(this,!0));for(const t of e)t.addEventListener("mousedown",this.handleRowMouseDownFunc),t.addEventListener("dragstart",(t=>t.preventDefault()))}update(){const[t]=this.tableMain.descendant(de,this.tableMain.length()-1);if(!t)return;const e=t.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:e.y-s.y+"px",left:e.x-s.x+"px"});const i=this.tableMain.domNode.getBoundingClientRect(),o=this.tableWrapper.domNode.getBoundingClientRect();let n=-1*this.size,l=-1*this.size;Ne(this.tableMain)?(this.root.classList.add(this.bem.is("align-right")),n=Math.min(o.width,i.width),l=Math.min(o.width,i.width)):this.root.classList.remove(this.bem.is("align-right")),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.size}px) translateX(${n}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${l}px)`})}show(){this.tableCols=this.tableMain.getCols(),this.tableRows=this.tableMain.getRows(),this.root.innerHTML="";const t=this.tableWrapper.domNode.getBoundingClientRect(),e=this.tableMain.domNode.getBoundingClientRect();if(this.tableCols.length>0&&this.tableRows.length>0&&(this.corner=document.createElement("div"),this.corner.classList.add(this.bem.be("corner")),Object.assign(this.corner.style,{width:`${this.size}px`,height:`${this.size}px`}),this.corner.addEventListener("click",(()=>{const t=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const e=this.tableModule.tableSelection;e.selectedTds=e.computeSelectedTds({x:t.x,y:t.y},{x:t.right,y:t.bottom}),e.show()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let s="";for(const[,t]of this.tableCols.entries()){const i=t.domNode.getBoundingClientRect().width;s+=`<div class="${this.bem.be("col-header")}" style="width: ${i}px">\n <div class="${this.bem.be("col-separator")}" style="height: ${e.height+this.size-3}px"></div>\n </div>`}const i=document.createElement("div");i.classList.add(this.bem.be("col"));const o=document.createElement("div");o.classList.add(this.bem.be("col-wrapper")),Object.assign(i.style,{transform:`translateY(-${this.size}px)`,maxWidth:`${t.width}px`,height:`${this.size}px`}),Object.assign(o.style,{width:`${e.width}px`}),o.innerHTML=s,i.appendChild(o),this.root.appendChild(i),i.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=i,this.bindColEvents()}if(this.tableRows.length>0){let s="";for(const[,t]of this.tableRows.entries()){const i=`${t.domNode.getBoundingClientRect().height}px`;s+=`<div class="${this.bem.be("row-header")}" style="height: ${Number.parseFloat(i)}px">\n <div class="${this.bem.be("row-separator")}" style="width: ${e.width+this.size-3}px"></div>\n </div>`}const i=document.createElement("div");i.classList.add(this.bem.be("row"));const o=document.createElement("div");o.classList.add(this.bem.be("row-wrapper")),Object.assign(i.style,{transform:`translateX(-${this.size}px)`,width:`${this.size}px`,maxHeight:`${t.height}px`}),Object.assign(o.style,{height:`${e.height}px`}),o.innerHTML=s,i.appendChild(o),this.root.appendChild(i),i.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=i,this.bindRowEvents()}this.update(),Wt.call(this,this.quill.root,(()=>{this.update()}))}hide(){this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),Ht.call(this),this.resizeObserver.disconnect();for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}}class Re extends Ee{tableModule;table;colResizer;rowResizer;currentTableCell;dragging=!1;curColIndex=-1;curRowIndex=-1;tableCellBlot;bem=n("resize-line");constructor(e,s,i){super(e,i),this.tableModule=e,this.table=s,this.colResizer=this.tableModule.addContainer(this.bem.be("col")),this.rowResizer=this.tableModule.addContainer(this.bem.be("row")),this.table.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(t.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=s=>{if(this.dragging)return;const i=this.findTableCell(s);if(!i)return this.hide();const o=t.find(i);o&&this.currentTableCell!==i&&(this.show(),this.currentTableCell=i,this.tableCellBlot=o,this.tableMain=zt(o,e.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hide()};findTableCell(t){for(const e of t.composedPath()){if(e instanceof HTMLElement&&"TD"===e.tagName)return e;if(e===document.body)return null}return null}findCurrentColIndex(){return this.curColIndex}handleColMouseUpFunc=async function(){await this.handleColMouseUp(),this.updateColResizer()}.bind(this);updateColResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.colResizer),this.colResizer=this.tableModule.addContainer(this.bem.be("col"));const[s]=Ot(t,[e.tableBody]),i=s.domNode.getBoundingClientRect(),o=t.domNode.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect();let l=o.right-n.x;Ne(this.tableMain)&&(l=o.left-n.x),Object.assign(this.colResizer.style,{top:i.y-n.y+"px",left:`${l}px`,height:`${i.height}px`});const r=this.tableMain.getCols();this.curColIndex=r.findIndex((e=>e.colId===t.colId)),this.colResizer.addEventListener("mousedown",this.handleColMouseDownFunc),this.colResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}findCurrentRowIndex(){return this.curRowIndex}handleRowMouseUpFunc=function(){this.handleRowMouseUp(),this.updateRowResizer()}.bind(this);updateRowResizer(){if(!this.tableMain||!this.tableCellBlot)return;const t=this.tableCellBlot;this.tableModule.toolBox.removeChild(this.rowResizer),this.rowResizer=this.tableModule.addContainer(this.bem.be("row"));const s=t.parent;if(!(s instanceof ce))return;const[i]=Ot(t,[e.tableBody]),o=i.domNode.getBoundingClientRect(),n=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:n.bottom-l.y+"px",left:o.x-l.x+"px",width:`${o.width}px`});const r=this.tableMain.getRows();this.curRowIndex=r.indexOf(s),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}show(){Object.assign(this.colResizer.style,{display:null}),Object.assign(this.rowResizer.style,{display:null})}hide(){this.currentTableCell=void 0,this.rowResizer.style.display="none",this.colResizer.style.display="none"}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.colResizer.remove(),this.rowResizer.remove(),this.table.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(t.events.TEXT_CHANGE,this.hideWhenTextChange)}}class Te{tableModule;table;quill;scrollHandler=[];tableMainBlot=null;tableWrapperBlot=null;bem=n("scale");startX=0;startY=0;options;root;block;resizeobserver=new ResizeObserver((()=>this.update()));constructor(e,s,i,o){this.tableModule=e,this.table=s,this.quill=i,this.options=this.resolveOptions(o),this.tableMainBlot=t.find(s),this.tableMainBlot&&!this.tableMainBlot.full&&(this.tableWrapperBlot=this.tableMainBlot.parent,this.buildResizer(),this.show())}resolveOptions(t){return Object.assign({blockSize:12},t)}buildResizer(){if(!this.tableMainBlot||!this.tableWrapperBlot)return;this.root=this.tableModule.addContainer(this.bem.b()),this.root.classList.add(this.bem.is("hidden")),this.block=document.createElement("div"),this.block.classList.add(this.bem.be("block")),Object.assign(this.block.style,{width:`${this.options.blockSize}px`,height:`${this.options.blockSize}px`}),this.root.appendChild(this.block);let t=[],e=[];const i=i=>{if(!this.tableMainBlot)return;const o=Ne(this.tableMainBlot)?-1:1,n=(i.clientX-this.startX)*o,l=i.clientY-this.startY,r=Math.floor(n/t.length),a=Math.floor(l/e.length);for(const{blot:e,width:i}of t)e.width=Math.max(i+r,s.colMinWidthPx);for(const{blot:t,height:i}of e)t.setHeight(`${Math.max(i+a,s.rowMinHeightPx)}px`)},o=()=>{t=[],e=[],document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",o)};this.block.addEventListener("mousedown",(s=>{this.tableMainBlot&&!this.isTableOutofEditor()&&(this.startX=s.clientX,this.startY=s.clientY,t=this.tableMainBlot.getCols().map((t=>({blot:t,width:Math.floor(t.width)}))),e=this.tableMainBlot.getRows().map((t=>({blot:t,height:Math.floor(t.domNode.getBoundingClientRect().height)}))),document.addEventListener("mousemove",i),document.addEventListener("mouseup",o))})),this.block.addEventListener("dragstart",(t=>t.preventDefault())),this.resizeobserver.observe(this.tableMainBlot.domNode),Wt.call(this,this.quill.root,(()=>this.update())),Wt.call(this,this.tableWrapperBlot.domNode,(()=>this.update()))}isTableOutofEditor(){if(!this.tableMainBlot||!this.tableWrapperBlot||this.tableMainBlot.full)return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect();if(t.width>e.width){for(const s of this.tableMainBlot.getCols())s.width=Math.floor(s.width/t.width*e.width);return this.tableMainBlot.colWidthFillTable(),!0}return!1}update(){if(!(this.block&&this.root&&this.tableMainBlot&&this.tableWrapperBlot))return!1;const t=this.tableMainBlot.domNode.getBoundingClientRect(),e=this.tableWrapperBlot.domNode.getBoundingClientRect(),s=this.quill.root.getBoundingClientRect(),{scrollTop:i,scrollLeft:o}=this.tableWrapperBlot.domNode,n=2*this.options.blockSize,l=Math.min(t.width,e.width)+n,r=Math.min(t.height,e.height)+n;Object.assign(this.root.style,{width:`${l}px`,height:`${r}px`,left:Math.max(t.x,e.x)-s.x-this.options.blockSize+"px",top:Math.max(t.y,e.y)-s.y-this.options.blockSize+"px"});const a={left:t.width+n-o+"px",top:r-i+"px"};Ne(this.tableMainBlot)?(this.root.classList.add(this.bem.is("align-right")),a.left=`${this.options.blockSize+-1*o}px`):this.root.classList.remove(this.bem.is("align-right")),Object.assign(this.block.style,a)}show(){this.root&&(this.root.classList.remove(this.bem.is("hidden")),this.update())}hide(){this.root&&this.root.classList.add(this.bem.is("hidden"))}destroy(){this.hide(),this.root&&this.root.remove(),Ht.call(this)}}class Be{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";size="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;bem=n("scrollbar");constructor(t,e,s,i){this.quill=t,this.isVertical=e,this.table=s,this.scrollbarContainer=i,this.container=s.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(s),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),Wt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:e,scrollTop:s}=this.quill.root,{offsetLeft:i,offsetTop:o}=this.container,{width:n,height:l}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=i,d=o;this.isVertical?c+=Math.min(n,r):d+=Math.min(l,a);const h=t.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-i),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?l:n}px`,transform:`translate(${c-e}px, ${d-s}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,s=t**2/this.container.scrollHeight,i=e**2/this.container.scrollWidth,o=Math.max(s,this.minSize),n=Math.max(i,this.minSize);this.ratioY=s/(t-s)/(o/(t-o)),this.ratioX=i/(e-i)/(n/(e-n)),this.sizeWidth=n+this.gap<e?`${n}px`:"",this.sizeHeight=o+this.gap<t?`${o}px`:"",this.size=this.isVertical?this.sizeHeight:this.sizeWidth}createScrollbar(){const t=document.createElement("div");t.classList.add(this.bem.b()),t.classList.add(this.isVertical?this.bem.is("vertical"):this.bem.is("horizontal"),this.bem.is("transparent")),Object.assign(t.style,{display:"none"}),this.thumb.classList.add(this.bem.be("thumb"));const e=t=>{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const s=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],i=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*s/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=i*this.container[this.propertyMap.scrollSize]/100},s=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",s),this.cursorLeave&&this.hideScrollbar()},i=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",e),document.addEventListener("mouseup",s),document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),i(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const o=[this.table,t];for(const t of o)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return Wt.call(this,this.container,(()=>{this.containerScrollHandler(this.container)})),t.appendChild(this.thumb),t}containerScrollHandler(t){const e=t[this.propertyMap.offset]-this.gap;this.move=100*t[this.propertyMap.scrollDirection]/e*(this.isVertical?this.ratioY:this.ratioX),Object.assign(this.thumb.style,{[this.propertyMap.size]:this.size,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=kt((()=>{this.cursorLeave=!1,this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.style.display=this.size?"block":"none",requestAnimationFrame((()=>{this.scrollbar.classList.remove(this.bem.is("transparent"))}))}),200);hideScrollbar=kt((()=>{this.cursorLeave=!0,this.cursorDown||(this.scrollbar.removeEventListener("transitionend",this.hideScrollbarTransitionend),this.scrollbar.addEventListener("transitionend",this.hideScrollbarTransitionend,{once:!0}),this.scrollbar.classList.add(this.bem.is("transparent")))}),200);hideScrollbarTransitionend=()=>{this.scrollbar.style.display=this.cursorDown&&this.size?"block":"none"};destroy(){this.ob.disconnect(),Ht.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}class ke{tableModule;table;quill;scrollbarContainer;scrollbar;bem=n("scrollbar");constructor(t,e,s){this.tableModule=t,this.table=e,this.quill=s,this.scrollbarContainer=this.tableModule.addContainer(this.bem.be("container")),this.scrollbar=[new Be(s,!0,e,this.scrollbarContainer),new Be(s,!1,e,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar)}hide(){for(const t of this.scrollbar)t.hideScrollbar()}show(){for(const t of this.scrollbar)t.showScrollbar()}update(){for(const t of this.scrollbar)t.calculateSize(),t.setScrollbarPosition()}destroy(){this.scrollbarContainer.remove();for(const t of this.scrollbar)t.destroy();return null}}class ze{table;quill;options;boundary=null;startScrollX=0;startScrollY=0;selectedTableScrollX=0;selectedTableScrollY=0;selectedEditorScrollX=0;selectedEditorScrollY=0;selectedTds=[];cellSelectWrap;cellSelect;dragging=!1;scrollHandler=[];selectingHandler=this.mouseDownHandler.bind(this);tableMenu;resizeObserver;bem=n("selection");constructor(t,e,s,i={}){this.table=e,this.quill=s,this.options=this.resolveOptions(i),this.cellSelectWrap=t.addContainer(this.bem.b()),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((()=>this.hide())),this.resizeObserver.observe(this.table),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.options.tableMenu&&(this.tableMenu=new this.options.tableMenu(t,s,this.options.tableMenuOptions))}resolveOptions(t){return Object.assign({selectColor:"#0589f3",tableMenuOptions:{}},t)}helpLinesInitial(){const t=document.createElement("div");return t.classList.add(this.bem.be("line")),Object.assign(t.style,{"border-color":this.options.selectColor}),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(e,s){const i=t.find(this.table);if(!i)return[];const o=new Set(i.descendants(he).map(((t,e)=>(t.index=e,t)))),{x:n,y:l}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=n,this.selectedTableScrollY=l,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=e.x-n+this.startScrollX,h=e.y-l+this.startScrollY;let u={x:Math.max(c.left,Math.min(s.x,d)),y:Math.max(c.top,Math.min(s.y,h)),x1:Math.min(c.right,Math.max(s.x,d)),y1:Math.min(c.bottom,Math.max(s.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of o){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:s,right:i,bottom:n}=t.__rect;if(Tt(u,{x:e,y:s,x1:i,y1:n},2)){p.add(t),o.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,s),x1:Math.max(u.x1,i),y1:Math.max(u.y1,n)},b=!0;break}if(e>u.x1&&s>u.y1)break}}for(const t of[...p,...o])delete t.__rect;return this.boundary=function(t,e){const s=e.getBoundingClientRect();return{x:t.x-s.x-e.scrollLeft,y:t.y-s.y-e.scrollTop,x1:t.x-s.x-e.scrollLeft+t.width,y1:t.y-s.y-e.scrollTop+t.height,width:t.width,height:t.height}}({...u,width:u.x1-u.x,height:u.y1-u.y},this.quill.root),Array.from(p).sort(((t,e)=>t.index-e.index)).map((t=>(delete t.index,t.getCellInner())))}mouseDownHandler(t){const{button:e,target:s,clientX:i,clientY:o}=t,n=s.closest(".ql-table");if(0!==e||!n)return;const l=n.dataset.tableId,r={x:i,y:o},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.show(),this.tableMenu&&this.tableMenu.hide();const d=t=>{const{button:e,target:s,clientX:i,clientY:o}=t,n=s.closest(".ql-table");if(0!==e||!n||n.dataset.tableId!==l)return;this.dragging=!0;const a={x:i,y:o};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.update()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu&&this.tableMenu.update()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)}update(){if(0===this.selectedTds.length||!this.boundary)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:s,y:i}=this.getTableViewScroll(),o=this.table.parentElement.getBoundingClientRect(),n=this.quill.root.getBoundingClientRect(),l=o.x-n.x,r=o.y-n.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-s-l+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-i-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${l}px`,top:`${r}px`,width:`${o.width+2}px`,height:`${o.height+2}px`}),!this.dragging&&this.tableMenu&&this.tableMenu.update()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}}show(){Ht.call(this),Object.assign(this.cellSelectWrap.style,{display:"block"}),this.update(),Wt.call(this,this.quill.root,(()=>{this.update()})),Wt.call(this,this.table.parentElement,(()=>{this.update()}))}hide(){this.boundary=null,this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.tableMenu&&this.tableMenu.hide(),Ht.call(this)}destroy(){return this.resizeObserver.disconnect(),this.hide(),this.cellSelectWrap.remove(),this.tableMenu&&this.tableMenu.destroy(),Ht.call(this),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),null}}const Oe=t.import("delta"),Ae=t.import("blots/break"),$e=t.import("ui/icons"),qe=(t,{tableId:s,rowId:i,colId:o})=>{const n={tableId:s,rowId:i,colId:o,colspan:1,rowspan:1},l=t.create(e.tableCell,n),r=t.create(e.tableCellInner,n),a=t.create("block");return a.appendChild(t.create("break")),r.appendChild(a),l.appendChild(r),l},We=t=>{let e=Number.parseFloat(t.getAttribute("width")||s.colDefaultWidth);if(Number.isNaN(e)){const s=t.style.width;e=s?Number.parseFloat(s):t.offsetWidth}return e},He=new Set([e.tableCellInner]),De=t=>{return!(!t||!t.parent)&&(e=t.parent,!!He.has(e.statics.blotName)||De(t.parent));var e};class je{static moduleName="table-up";static toolName=e.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,s){const i=this.quill.getLine(t.index)[0];if(i.prev instanceof fe)return i.prev.remove(),!1;if(s.format[e.tableCellInner]){if(0===i.offset(zt(i,e.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,s){const i=this.quill.getLine(t.index),o=i[0],n=i[1];if((o.next instanceof fe||o.next instanceof pe)&&n===o.length()-1)return!1;if(s.format[e.tableCellInner]){if(o===zt(o,e.tableCellInner).children.tail&&n===o.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[e.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(s){const[i,o]=this.quill.getLine(s.index);if(this.quill.getFormat(s.index+o+1,1)[e.tableCellInner])return!0;let n=2,l=i;for(;null!==l&&l.length()<=1;)if(l=l.prev,n-=1,n<=0)return this.quill.insertText(s.index+1,"\n"),this.quill.setSelection(s.index+1,t.sources.SILENT),!1;return!0}}};static register(){fe.allowedChildren=[be],be.allowedChildren=[de,me],be.requiredContainer=fe,me.allowedChildren=[pe],me.requiredContainer=be,de.allowedChildren=[ce],de.requiredContainer=be,ce.allowedChildren=[he],he.requiredContainer=de,he.allowedChildren=[ne,Ae],he.requiredContainer=ce,ne.requiredContainer=he,t.register({"blots/scroll":ae,"blots/block":_t,[`blots/${e.container}`]:Vt,"formats/header":Jt,"formats/list":ee,"formats/blockquote":Kt,"formats/code-block":Gt,[`formats/${e.tableCell}`]:he,[`formats/${e.tableCellInner}`]:ne,[`formats/${e.tableRow}`]:ce,[`formats/${e.tableBody}`]:de,[`formats/${e.tableCol}`]:pe,[`formats/${e.tableColgroup}`]:me,[`formats/${e.tableMain}`]:be,[`formats/${e.tableWrapper}`]:fe},!0)}quill;options;toolBox;fixTableByLisenter=kt(this.balanceTables,100);selector;table;tableSelection;tableResize;tableScrollbar;tableAlign;tableResizeScale;get statics(){return this.constructor}constructor(s,o){if(this.quill=s,this.options=this.resolveOptions(o||{}),!this.options.scrollbar){const t=n("scrollbar");this.quill.container.classList.add(t.bm("origin"))}const l=n("toolbox");this.toolBox=this.quill.addContainer(l.b());const r=this.quill.getModule("toolbar");if(r&&this.quill.theme.pickers){const[,t]=(r.controls||[]).find((([t])=>t===this.statics.toolName))||[];if(t&&"select"===t.tagName.toLocaleLowerCase()){const e=this.quill.theme.pickers.find((e=>e.select===t));e&&(e.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect,e),e.label.addEventListener("mousedown",(()=>{if(!this.selector||!e)return;const t=this.selector.getBoundingClientRect(),{leftLimited:s}=qt(t);if(s){const t=e.label.getBoundingClientRect();Object.assign(e.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(e.options.style,{transform:void 0})})))}}const a=this.quill.getModule("keyboard");for(const t of Object.values(je.keyboradHandler))t.bindInHead?a.bindings[t.key].unshift(t):a.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const e=t.composedPath();if(!e||e.length<=0)return;const i=e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(i){if(this.table===i)return this.tableSelection&&this.tableSelection.show(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(i,s)}else this.table&&this.hideTableTools()}),!1),this.quill.on(t.events.EDITOR_CHANGE,((s,i,o)=>{if(s===t.events.SELECTION_CHANGE&&i){const[s]=this.quill.getLine(i.index),[n]=this.quill.getLine(i.index+i.length);let l,r;try{l=zt(s,e.tableMain)}catch{}try{r=zt(n,e.tableMain)}catch{}if(s instanceof pe)return o||(o={index:0,length:0}),this.quill.setSelection(i.index+(o.index>i.index?-1:1),i.length+(o.length===i.length?0:o.length>i.length?-1:1),t.sources.USER);if(n instanceof pe)return this.quill.setSelection(i.index+1,i.length+1,t.sources.USER);i.length>0&&(l&&!r?this.quill.setSelection(i.index-1,i.length+1,t.sources.USER):r&&!l&&this.quill.setSelection(i.index,i.length+1,t.sources.USER)),l&&r||this.hideTableTools()}})),this.quill.on(i.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hide()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if(a(t)){const e=document.createElement("div");for(const s of t.split(" "))e.classList.add(s);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!1,texts:this.resolveTexts(t.texts||{}),full:!1,fullSwtich:!0,icon:$e.table,selectionOptions:{},alignOptions:{},scrollbarOptions:{},resizeOptions:{},resizeScaleOptions:{}},t)}resolveTexts(t){return Object.assign({fullCheckboxText:"Insert full width table",customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer",custom:"Custom",clear:"Clear",transparent:"Transparent",perWidthInsufficient:"The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?"},t)}pasteTableHandler(){let t=Bt(),i=Bt(),o=[],n=0,l=0;const r=(t,s,i)=>{const o=this.quill.getSelection(!0),n=this.quill.getFormat(o)[e.tableCellInner];if(n)for(const t of s.ops)t.attributes||(t.attributes={}),t.attributes[e.tableCellInner]=n;return s};this.quill.clipboard.addMatcher(Node.TEXT_NODE,r),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,r),this.quill.clipboard.addMatcher("table",((i,r)=>{if(0===r.ops.length)return r;if(this.quill.getFormat()[e.tableCellInner])return new Oe;const a=[],c=[];for(let t=0;t<r.ops.length;t++){const{attributes:s,insert:i}=r.ops[t],{table:o,[e.tableCell]:n,...l}=s||{};i&&i[e.tableCol]?c.push({insert:i}):a.push({attributes:l,insert:i})}const d=((t,e)=>{const i=new Array(e).fill(s.colDefaultWidth),o=Array.from(t.querySelectorAll("tr"));for(const t of o){const s=Array.from(t.querySelectorAll("td"));for(const[t,o]of s.entries()){if(!(t<e))break;{const e=We(o);i[t]=e||i[t]}}}return i})(i,o.length).reduce(((s,i,n)=>(c[n]?s.push(c[n]):s.push({insert:{[e.tableCol]:{tableId:t,colId:o[n],width:i,full:!1}}}),s)),[]);return a.unshift(...d),t=Bt(),o=[],n=0,l=0,a.unshift({insert:"\n"}),a.push({insert:"\n"}),new Oe(a)})),this.quill.clipboard.addMatcher("colgroup",((t,s)=>{const i=[];for(let t=0;t<s.ops.length;t++){const n=s.ops[t];n&&(null!==(o=n.insert)&&"object"==typeof o)&&n.insert[e.tableCol]&&i.push(n)}var o;return new Oe(i)})),this.quill.clipboard.addMatcher("col",(s=>{o[l]=Bt();const i=(new Oe).insert({[e.tableCol]:Object.assign(pe.value(s),{tableId:t,colId:o[l]})});return l+=1,i})),this.quill.clipboard.addMatcher("tr",((t,s)=>{i=Bt(),n=0;for(const t of s.ops)if(t.attributes&&t.attributes.background&&t.attributes[e.tableCellInner]){const s=t.attributes[e.tableCellInner];s.style||(s.style=""),t.attributes[e.tableCellInner].style=`background:${t.attributes.background};${s.style}`}return s}));const a=(s,l)=>{const r=s,a=he.formats(r);if(!o[n])for(let t=n;t>=0;t--)o[t]||(o[t]=Bt());const c=o[n];n+=a.colspan;const d=Object.assign(a,{tableId:t,rowId:i,colId:c});"none"===r.style.border&&(d.style=d.style.replaceAll(/border-(top|right|bottom|left)-style:none;?/g,""));const h=[];for(const t of l.ops){const{insert:s,attributes:i}=t;if(t.insert){const t={...i};delete t[e.tableCell],h.push({insert:s,attributes:{...t,[e.tableCellInner]:d}})}}return new Oe(h)};this.quill.clipboard.addMatcher("td",a),this.quill.clipboard.addMatcher("th",a)}showTableTools(t,e){t&&(this.table=t,this.options.selection&&(this.tableSelection=new this.options.selection(this,t,e,this.options.selectionOptions)),this.options.align&&(this.tableAlign=new this.options.align(this,t,e,this.options.alignOptions)),this.options.scrollbar&&(this.tableScrollbar=new this.options.scrollbar(this,t,e,this.options.scrollbarOptions)),this.options.resize&&(this.tableResize=new this.options.resize(this,t,e,this.options.resizeOptions)),this.options.resizeScale&&(this.tableResizeScale=new this.options.resizeScale(this,t,e,this.options.resizeScaleOptions)))}hideTableTools(){this.tableSelection&&(this.tableSelection.destroy(),this.tableSelection=void 0),this.tableScrollbar&&(this.tableScrollbar.destroy(),this.tableScrollbar=void 0),this.tableAlign&&(this.tableAlign.destroy(),this.tableAlign=void 0),this.tableResize&&(this.tableResize.destroy(),this.tableResize=void 0),this.tableResizeScale&&this.tableResizeScale.destroy(),this.table=void 0}async buildCustomSelect(t,e){if(!t||!l(t))return;const s=document.createElement("div");if(s.classList.add("ql-custom-select"),this.selector=await t(this,e),s.appendChild(this.selector),this.options.fullSwtich){const t=n("creator"),e=document.createElement("label");e.classList.add(t.be("checkbox"));const i=document.createElement("input");i.type="checkbox",i.checked=this.options.full,i.addEventListener("change",(()=>{this.options.full=i.checked}));const o=document.createElement("div");o.classList.add(t.be("mark"));const l=document.createElement("span");l.textContent=this.options.texts.fullCheckboxText,e.appendChild(i),e.appendChild(o),e.appendChild(l),s.appendChild(e)}e.options.appendChild(s)}setCellAttrs(t,e,s,i=!1){if(0!==t.length)for(const o of t)o.setFormatValue(e,s,i)}insertTable(i,o){if(i>=30||o>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus();const n=this.quill.getSelection();if(null==n)return;const[l]=this.quill.getLeaf(n.index);if(!l)return;if(De(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const r=this.calculateTableCellBorderWidth(),a=getComputedStyle(this.quill.root),c=Number.parseInt(a.paddingLeft),d=Number.parseInt(a.paddingRight),h=Number.parseInt(a.width)-c-d-r,u=Bt(),p=new Array(o).fill(0).map((()=>Bt())),b=this.options.full?`${Math.max(1/o*100,s.colMinWidthPre)}%`:`${Math.max(Math.floor(h/o),s.colMinWidthPx)}px`,m=[{retain:n.index},{insert:"\n"}];for(let t=0;t<o;t++)m.push({insert:{[e.tableCol]:{width:b,tableId:u,colId:p[t],full:this.options.full}}});for(let t=0;t<i;t++){const t=Bt();for(let s=0;s<o;s++)m.push({insert:"\n",attributes:{[e.tableCellInner]:{tableId:u,rowId:t,colId:p[s],rowspan:1,colspan:1}}})}this.quill.updateContents(new Oe(m),t.sources.USER),this.quill.setSelection(n.index+o+o*i+1,t.sources.SILENT),this.quill.focus()}calculateTableCellBorderWidth(){const t=`\n <table class="${be.className}">\n <tbody>\n <tr>\n <td class="${he.className}"></td>\n </tr>\n </tbody>\n </table>\n `,e=document.createElement("div");e.className=fe.className,e.innerHTML=t,e.style.position="absolute",e.style.left="-9999px",e.style.top="-9999px",e.style.visibility="hidden",this.quill.root.appendChild(e);const s=window.getComputedStyle(e.querySelector("td")),i=Number.parseFloat(s.borderWidth)||0;return this.quill.root.removeChild(e),i}fixUnusuaDeletelTable(t){const e=t.getRows(),s=t.getColIds();if(0===e.length)return t.remove();if(0===s.length)return;const i=new Array(e.length).fill(0).map((()=>new Array(s.length).fill(!1))),o=t.tableId;for(const[t,n]of e.entries()){let l=0,r=0;const a=i[t],c=n.descendants(he);for(;r<s.length;){if(a[r]){r+=1;continue}const d=c[l];if(d&&d.colId===s[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:s,rowspan:o}=d;if(s>1)for(let t=1;t<s;t++)a[r+t]=!0;if(o>1)for(let e=t+1;e<t+o;e++)for(let t=0;t<s;t++)i[e][r+t]=!0;l+=1}else n.insertBefore(qe(this.quill.scroll,{tableId:o,colId:s[r],rowId:n.rowId}),d);r+=1}if(l<c.length)for(let t=l;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(be))this.fixUnusuaDeletelTable(t)}listenBalanceCells(){this.quill.on(t.events.SCROLL_OPTIMIZE,(t=>{t.some((t=>!!["TD","TR","TBODY","TABLE"].includes(t.target.tagName)&&(this.fixTableByLisenter(),!0)))}))}deleteTable(){if(!this.tableSelection||0===this.tableSelection.selectedTds.length)return;const t=zt(this.tableSelection.selectedTds[0],e.tableMain);t&&t.remove(),this.hideTableTools()}appendRow(t){if(!this.tableSelection)return;const s=this.tableSelection.selectedTds;if(s.length<=0)return;const i=s[t?s.length-1:0],[o,n,l]=Ot(i,[e.tableMain,e.tableBody,e.tableRow]),r=o.getRows().indexOf(l)+(t?i.rowspan:0);n.insertRow(r)}appendCol(t){if(!this.tableSelection)return;const s=this.tableSelection.selectedTds;if(s.length<=0)return;const[i]=s.reduce(((e,s)=>{const i=s.getColumnIndex();return(!t&&i<=e[1]||t&&i>=e[1])&&(e=[s,i]),e}),[s[0],s[0].getColumnIndex()]),o=i.getColumnIndex()+(t?i.colspan:0),n=zt(i,e.tableMain),l=n.tableId,r=Bt(),[a]=n.descendants(me);a&&a.insertColByIndex(o,{tableId:l,colId:r,width:n.full?"6%":"160px",full:n.full});const c=n.getRows(),d=[];let h=0;for(const t of Object.values(c)){const e=d.shift()||0;if(h>0){h-=1;continue}const s=t.insertCell(o-e,{tableId:l,rowId:t.rowId,colId:r,rowspan:1,colspan:1});s.skipRowNum&&(h+=s.skipRowNum);for(const[t,e]of s.entries())d[t]=(d[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),s=t.getCols(),i=s.reduce(((t,e)=>(t[e.colId]=0,t)),{}),o=[...e].reverse(),n=[];for(const[t,s]of o.entries()){const o=e.length-t-1;s.children.length<=0?n.push(o):s.foreachCellInner((t=>{const e=n.reduce(((e,s)=>t.rowspan+o>s?e+1:e),0);t.rowspan-=e,i[t.colId]+=1}))}let l=0;for(const t of Object.values(i))if(0===t){const t=[];let s=0;for(const i of Object.values(e)){const e=t.shift()||0;let o=[];s>0?(o=i.getCellByColumIndex(l-e)[2],s-=1):(o=i.removeCell(l-e),o.skipRowNum&&(s+=o.skipRowNum));for(const[e,s]of o.entries())t[e]=(t[e]||0)+s}}else l+=1;for(const t of s)0===i[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const s=zt(t[0],e.tableMain),i=s.getRows();let o=i.length,n=-1;for(const s of t){const t=zt(s,e.tableRow),l=i.indexOf(t);l<o&&(o=l),l+s.rowspan>n&&(n=l+s.rowspan)}const l={};for(let t=o;t<Math.min(i.length,n);t++){i[t].foreachCellInner((e=>{e.rowspan+t>n&&(l[e.colId]={rowspan:e.rowspan+t-n,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(i[n]){const t=i[n],e=s.tableId;for(const[s,{colIndex:i,colspan:o,rowspan:n}]of Object.entries(l))t.insertCell(i,{tableId:e,rowId:t.rowId,colId:s,colspan:o,rowspan:n})}this.fixTableByRemove(s)}removeCol(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const s=t[0],i=zt(s,e.tableMain),o={};for(const e of t)o[e.rowId]||(o[e.rowId]=0),o[e.rowId]+=e.colspan;const n=Math.max(...Object.values(o)),l=s.getColumnIndex(),r=i.descendants(ce);for(let t=0;t<n;t++){const t=[];let e=0;for(const s of Object.values(r)){const i=t.shift()||0;if(e>0){e-=1;continue}const o=s.removeCell(l-i);o.skipRowNum&&(e+=o.skipRowNum);for(const[e,s]of o.entries())t[e]=(t[e]||0)+s}}const[a]=i.descendants(me);if(a)for(let t=0;t<n;t++)a.removeColByIndex(l);this.fixTableByRemove(i)}mergeCells(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=1)return;const s=t.reduce(((t,e,s)=>{const i=e.colId;t[0][i]||(t[0][i]=0),t[0][i]+=e.rowspan;const o=e.rowId;return t[1][o]||(t[1][o]=0),t[1][o]+=e.colspan,0!==s&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),i=Math.max(...Object.values(s[0])),o=Math.max(...Object.values(s[1])),n=s[2];n.colspan=o,n.rowspan=i;const l=zt(n,e.tableMain);this.fixTableByRemove(l)}splitCell(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(1!==t.length)return;const s=t[0];if(1===s.colspan&&1===s.rowspan)return;const[i,o]=Ot(s,[e.tableMain,e.tableRow]),n=i.tableId,l=s.getColumnIndex(),r=i.getColIds().slice(l,l+s.colspan).reverse();let a=o,c=s.rowspan;for(s.colspan=1,s.rowspan=1;a&&c>0;){for(const t of r)a===o&&t===s.colId||a.insertCell(l+(a===o?1:0),{tableId:n,rowId:a.rowId,colId:t,rowspan:1,colspan:1});c-=1,a=a.next}}}function Fe(t){He.delete(e.tableCellInner),Object.assign(e,t.blotName||{}),Object.assign(s,t.tableUpSize||{}),Object.assign(i,t.tableUpEvent||{}),je.toolName=e.tableWrapper,Vt.blotName=e.container,fe.blotName=e.tableWrapper,be.blotName=e.tableMain,me.blotName=e.tableColgroup,pe.blotName=e.tableCol,de.blotName=e.tableBody,ce.blotName=e.tableRow,he.blotName=e.tableCell,ne.blotName=e.tableCellInner}function Pe(t,e){return x({onSelect:(s,i)=>{t.insertTable(s,i),e&&e.close()},customBtn:t.options.customBtn,texts:t.options.texts})}export{_t as BlockOverride,Kt as BlockquoteOverride,Gt as CodeBlockOverride,Vt as ContainerFormat,Jt as HeaderOverride,ee as ListItemOverride,ae as ScrollOverride,Be as Scrollbar,ge as TableAlign,de as TableBodyFormat,he as TableCellFormat,ne as TableCellInnerFormat,pe as TableColFormat,me as TableColgroupFormat,be as TableMainFormat,Me as TableMenuCommon,Ie as TableMenuContextmenu,Le as TableMenuSelect,Se as TableResizeBox,Ee as TableResizeCommon,Re as TableResizeLine,Te as TableResizeScale,ce as TableRowFormat,ze as TableSelection,je as TableUp,ke as TableVirtualScrollbar,fe as TableWrapperFormat,e as blotName,je as default,Pe as defaultCustomSelect,zt as findParentBlot,Ot as findParentBlots,Ne as isTableAlignRight,Bt as randomId,He as tableCantInsert,i as tableUpEvent,s as tableUpSize,Fe as updateTableConstants};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|