quill-table-up 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import t from"quill";const e=Math.min,o=Math.max,s=Math.round,i=Math.floor,l=t=>({x:t,y:t}),n={left:"right",right:"left",bottom:"top",top:"bottom"},r={start:"end",end:"start"};function a(t,s,i){return o(t,e(s,i))}function c(t,e){return"function"==typeof t?t(e):t}function d(t){return t.split("-")[0]}function h(t){return t.split("-")[1]}function u(t){return"x"===t?"y":"x"}function p(t){return"y"===t?"height":"width"}function b(t){return["top","bottom"].includes(d(t))?"y":"x"}function m(t){return u(b(t))}function f(t){return t.replace(/start|end/g,(t=>r[t]))}function g(t){return t.replace(/left|right|bottom|top/g,(t=>n[t]))}function w(t){const{x:e,y:o,width:s,height:i}=t;return{width:s,height:i,top:o,left:e,right:e+s,bottom:o+i,x:e,y:o}}function v(t,e,o){let{reference:s,floating:i}=t;const l=b(e),n=m(e),r=p(n),a=d(e),c="y"===l,u=s.x+s.width/2-i.width/2,f=s.y+s.height/2-i.height/2,g=s[r]/2-i[r]/2;let w;switch(a){case"top":w={x:u,y:s.y-i.height};break;case"bottom":w={x:u,y:s.y+s.height};break;case"right":w={x:s.x+s.width,y:f};break;case"left":w={x:s.x-i.width,y:f};break;default:w={x:s.x,y:s.y}}switch(h(e)){case"start":w[n]-=g*(o&&c?-1:1);break;case"end":w[n]+=g*(o&&c?-1:1)}return w}async function x(t,e){var o;void 0===e&&(e={});const{x:s,y:i,platform:l,rects:n,elements:r,strategy:a}=t,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:u="floating",altBoundary:p=!1,padding:b=0}=c(e,t),m=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}}(b),f=r[p?"floating"===u?"reference":"floating":u],g=w(await l.getClippingRect({element:null==(o=await(null==l.isElement?void 0:l.isElement(f)))||o?f:f.contextElement||await(null==l.getDocumentElement?void 0:l.getDocumentElement(r.floating)),boundary:d,rootBoundary:h,strategy:a})),v="floating"===u?{x:s,y:i,width:n.floating.width,height:n.floating.height}:n.reference,x=await(null==l.getOffsetParent?void 0:l.getOffsetParent(r.floating)),C=await(null==l.isElement?void 0:l.isElement(x))&&await(null==l.getScale?void 0:l.getScale(x))||{x:1,y:1},y=w(l.convertOffsetParentRelativeRectToViewportRelativeRect?await l.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:v,offsetParent:x,strategy:a}):v);return{top:(g.top-y.top+m.top)/C.y,bottom:(y.bottom-g.bottom+m.bottom)/C.y,left:(g.left-y.left+m.left)/C.x,right:(y.right-g.right+m.right)/C.x}}function C(){return"undefined"!=typeof window}function y(t){return L(t)?(t.nodeName||"").toLowerCase():"#document"}function I(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function M(t){var e;return null==(e=(L(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function L(t){return!!C()&&(t instanceof Node||t instanceof I(t).Node)}function N(t){return!!C()&&(t instanceof Element||t instanceof I(t).Element)}function S(t){return!!C()&&(t instanceof HTMLElement||t instanceof I(t).HTMLElement)}function T(t){return!(!C()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof I(t).ShadowRoot)}function R(t){const{overflow:e,overflowX:o,overflowY:s,display:i}=O(t);return/auto|scroll|overlay|hidden|clip/.test(e+s+o)&&!["inline","contents"].includes(i)}function E(t){return["table","td","th"].includes(y(t))}function B(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function k(t){const e=z(),o=N(t)?O(t):t;return"none"!==o.transform||"none"!==o.perspective||!!o.containerType&&"normal"!==o.containerType||!e&&!!o.backdropFilter&&"none"!==o.backdropFilter||!e&&!!o.filter&&"none"!==o.filter||["transform","perspective","filter"].some((t=>(o.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(o.contain||"").includes(t)))}function z(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function q(t){return["html","body","#document"].includes(y(t))}function O(t){return I(t).getComputedStyle(t)}function A(t){return N(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function H(t){if("html"===y(t))return t;const e=t.assignedSlot||t.parentNode||T(t)&&t.host||M(t);return T(e)?e.host:e}function $(t){const e=H(t);return q(e)?t.ownerDocument?t.ownerDocument.body:t.body:S(e)&&R(e)?e:$(e)}function W(t,e,o){var s;void 0===e&&(e=[]),void 0===o&&(o=!0);const i=$(t),l=i===(null==(s=t.ownerDocument)?void 0:s.body),n=I(i);if(l){const t=j(n);return e.concat(n,n.visualViewport||[],R(i)?i:[],t&&o?W(t):[])}return e.concat(i,W(i,[],o))}function j(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function D(t){const e=O(t);let o=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const l=S(t),n=l?t.offsetWidth:o,r=l?t.offsetHeight:i,a=s(o)!==n||s(i)!==r;return a&&(o=n,i=r),{width:o,height:i,$:a}}function V(t){return N(t)?t:t.contextElement}function F(t){const e=V(t);if(!S(e))return l(1);const o=e.getBoundingClientRect(),{width:i,height:n,$:r}=D(e);let a=(r?s(o.width):o.width)/i,c=(r?s(o.height):o.height)/n;return a&&Number.isFinite(a)||(a=1),c&&Number.isFinite(c)||(c=1),{x:a,y:c}}const P=l(0);function _(t){const e=I(t);return z()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:P}function X(t,e,o,s){void 0===e&&(e=!1),void 0===o&&(o=!1);const i=t.getBoundingClientRect(),n=V(t);let r=l(1);e&&(s?N(s)&&(r=F(s)):r=F(t));const a=function(t,e,o){return void 0===e&&(e=!1),!(!o||e&&o!==I(t))&&e}(n,o,s)?_(n):l(0);let c=(i.left+a.x)/r.x,d=(i.top+a.y)/r.y,h=i.width/r.x,u=i.height/r.y;if(n){const t=I(n),e=s&&N(s)?I(s):s;let o=t,i=j(o);for(;i&&s&&e!==o;){const t=F(i),e=i.getBoundingClientRect(),s=O(i),l=e.left+(i.clientLeft+parseFloat(s.paddingLeft))*t.x,n=e.top+(i.clientTop+parseFloat(s.paddingTop))*t.y;c*=t.x,d*=t.y,h*=t.x,u*=t.y,c+=l,d+=n,o=I(i),i=j(o)}}return w({width:h,height:u,x:c,y:d})}function U(t,e){const o=A(t).scrollLeft;return e?e.left+o:X(M(t)).left+o}function Y(t,e,o){void 0===o&&(o=!1);const s=t.getBoundingClientRect();return{x:s.left+e.scrollLeft-(o?0:U(t,s)),y:s.top+e.scrollTop}}function K(t,e,s){let i;if("viewport"===e)i=function(t,e){const o=I(t),s=M(t),i=o.visualViewport;let l=s.clientWidth,n=s.clientHeight,r=0,a=0;if(i){l=i.width,n=i.height;const t=z();(!t||t&&"fixed"===e)&&(r=i.offsetLeft,a=i.offsetTop)}return{width:l,height:n,x:r,y:a}}(t,s);else if("document"===e)i=function(t){const e=M(t),s=A(t),i=t.ownerDocument.body,l=o(e.scrollWidth,e.clientWidth,i.scrollWidth,i.clientWidth),n=o(e.scrollHeight,e.clientHeight,i.scrollHeight,i.clientHeight);let r=-s.scrollLeft+U(t);const a=-s.scrollTop;return"rtl"===O(i).direction&&(r+=o(e.clientWidth,i.clientWidth)-l),{width:l,height:n,x:r,y:a}}(M(t));else if(N(e))i=function(t,e){const o=X(t,!0,"fixed"===e),s=o.top+t.clientTop,i=o.left+t.clientLeft,n=S(t)?F(t):l(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:i*n.x,y:s*n.y}}(e,s);else{const o=_(t);i={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return w(i)}function Z(t,e){const o=H(t);return!(o===e||!N(o)||q(o))&&("fixed"===O(o).position||Z(o,e))}function G(t,e,o){const s=S(e),i=M(e),n="fixed"===o,r=X(t,!0,n,e);let a={scrollLeft:0,scrollTop:0};const c=l(0);if(s||!s&&!n)if(("body"!==y(e)||R(i))&&(a=A(e)),s){const t=X(e,!0,n,e);c.x=t.x+e.clientLeft,c.y=t.y+e.clientTop}else i&&(c.x=U(i));const d=!i||s||n?l(0):Y(i,a);return{x:r.left+a.scrollLeft-c.x-d.x,y:r.top+a.scrollTop-c.y-d.y,width:r.width,height:r.height}}function Q(t){return"static"===O(t).position}function J(t,e){if(!S(t)||"fixed"===O(t).position)return null;if(e)return e(t);let o=t.offsetParent;return M(t)===o&&(o=o.ownerDocument.body),o}function tt(t,e){const o=I(t);if(B(t))return o;if(!S(t)){let e=H(t);for(;e&&!q(e);){if(N(e)&&!Q(e))return e;e=H(e)}return o}let s=J(t,e);for(;s&&E(s)&&Q(s);)s=J(s,e);return s&&q(s)&&Q(s)&&!k(s)?o:s||function(t){let e=H(t);for(;S(e)&&!q(e);){if(k(e))return e;if(B(e))return null;e=H(e)}return null}(t)||o}const et={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:o,offsetParent:s,strategy:i}=t;const n="fixed"===i,r=M(s),a=!!e&&B(e.floating);if(s===r||a&&n)return o;let c={scrollLeft:0,scrollTop:0},d=l(1);const h=l(0),u=S(s);if((u||!u&&!n)&&(("body"!==y(s)||R(r))&&(c=A(s)),S(s))){const t=X(s);d=F(s),h.x=t.x+s.clientLeft,h.y=t.y+s.clientTop}const p=!r||u||n?l(0):Y(r,c,!0);return{width:o.width*d.x,height:o.height*d.y,x:o.x*d.x-c.scrollLeft*d.x+h.x+p.x,y:o.y*d.y-c.scrollTop*d.y+h.y+p.y}},getDocumentElement:M,getClippingRect:function(t){let{element:s,boundary:i,rootBoundary:l,strategy:n}=t;const r=[..."clippingAncestors"===i?B(s)?[]:function(t,e){const o=e.get(t);if(o)return o;let s=W(t,[],!1).filter((t=>N(t)&&"body"!==y(t))),i=null;const l="fixed"===O(t).position;let n=l?H(t):t;for(;N(n)&&!q(n);){const e=O(n),o=k(n);o||"fixed"!==e.position||(i=null),(l?!o&&!i:!o&&"static"===e.position&&i&&["absolute","fixed"].includes(i.position)||R(n)&&!o&&Z(t,n))?s=s.filter((t=>t!==n)):i=e,n=H(n)}return e.set(t,s),s}(s,this._c):[].concat(i),l],a=r[0],c=r.reduce(((t,i)=>{const l=K(s,i,n);return t.top=o(l.top,t.top),t.right=e(l.right,t.right),t.bottom=e(l.bottom,t.bottom),t.left=o(l.left,t.left),t}),K(s,a,n));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},getOffsetParent:tt,getElementRects:async function(t){const e=this.getOffsetParent||tt,o=this.getDimensions,s=await o(t.floating);return{reference:G(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:s.width,height:s.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:o}=D(t);return{width:e,height:o}},getScale:F,isElement:N,isRTL:function(t){return"rtl"===O(t).direction}};function ot(t,s,l,n){void 0===n&&(n={});const{ancestorScroll:r=!0,ancestorResize:a=!0,elementResize:c="function"==typeof ResizeObserver,layoutShift:d="function"==typeof IntersectionObserver,animationFrame:h=!1}=n,u=V(t),p=r||a?[...u?W(u):[],...W(s)]:[];p.forEach((t=>{r&&t.addEventListener("scroll",l,{passive:!0}),a&&t.addEventListener("resize",l)}));const b=u&&d?function(t,s){let l,n=null;const r=M(t);function a(){var t;clearTimeout(l),null==(t=n)||t.disconnect(),n=null}return function c(d,h){void 0===d&&(d=!1),void 0===h&&(h=1),a();const{left:u,top:p,width:b,height:m}=t.getBoundingClientRect();if(d||s(),!b||!m)return;const f={rootMargin:-i(p)+"px "+-i(r.clientWidth-(u+b))+"px "+-i(r.clientHeight-(p+m))+"px "+-i(u)+"px",threshold:o(0,e(1,h))||1};let g=!0;function w(t){const e=t[0].intersectionRatio;if(e!==h){if(!g)return c();e?c(!1,e):l=setTimeout((()=>{c(!1,1e-7)}),1e3)}g=!1}try{n=new IntersectionObserver(w,{...f,root:r.ownerDocument})}catch(t){n=new IntersectionObserver(w,f)}n.observe(t)}(!0),a}(u,l):null;let m,f=-1,g=null;c&&(g=new ResizeObserver((t=>{let[e]=t;e&&e.target===u&&g&&(g.unobserve(s),cancelAnimationFrame(f),f=requestAnimationFrame((()=>{var t;null==(t=g)||t.observe(s)}))),l()})),u&&!h&&g.observe(u),g.observe(s));let w=h?X(t):null;return h&&function e(){const o=X(t);!w||o.x===w.x&&o.y===w.y&&o.width===w.width&&o.height===w.height||l();w=o,m=requestAnimationFrame(e)}(),l(),()=>{var t;p.forEach((t=>{r&&t.removeEventListener("scroll",l),a&&t.removeEventListener("resize",l)})),null==b||b(),null==(t=g)||t.disconnect(),g=null,h&&cancelAnimationFrame(m)}}const st=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var o,s;const{x:i,y:l,placement:n,middlewareData:r}=e,a=await async function(t,e){const{placement:o,platform:s,elements:i}=t,l=await(null==s.isRTL?void 0:s.isRTL(i.floating)),n=d(o),r=h(o),a="y"===b(o),u=["left","top"].includes(n)?-1:1,p=l&&a?-1:1,m=c(e,t);let{mainAxis:f,crossAxis:g,alignmentAxis:w}="number"==typeof m?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return r&&"number"==typeof w&&(g="end"===r?-1*w:w),a?{x:g*p,y:f*u}:{x:f*u,y:g*p}}(e,t);return n===(null==(o=r.offset)?void 0:o.placement)&&null!=(s=r.arrow)&&s.alignmentOffset?{}:{x:i+a.x,y:l+a.y,data:{...a,placement:n}}}}},it=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:o,y:s,placement:i}=e,{mainAxis:l=!0,crossAxis:n=!1,limiter:r={fn:t=>{let{x:e,y:o}=t;return{x:e,y:o}}},...h}=c(t,e),p={x:o,y:s},m=await x(e,h),f=b(d(i)),g=u(f);let w=p[g],v=p[f];if(l){const t="y"===g?"bottom":"right";w=a(w+m["y"===g?"top":"left"],w,w-m[t])}if(n){const t="y"===f?"bottom":"right";v=a(v+m["y"===f?"top":"left"],v,v-m[t])}const C=r.fn({...e,[g]:w,[f]:v});return{...C,data:{x:C.x-o,y:C.y-s,enabled:{[g]:l,[f]:n}}}}}},lt=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var o,s;const{placement:i,middlewareData:l,rects:n,initialPlacement:r,platform:a,elements:u}=e,{mainAxis:w=!0,crossAxis:v=!0,fallbackPlacements:C,fallbackStrategy:y="bestFit",fallbackAxisSideDirection:I="none",flipAlignment:M=!0,...L}=c(t,e);if(null!=(o=l.arrow)&&o.alignmentOffset)return{};const N=d(i),S=b(r),T=d(r)===r,R=await(null==a.isRTL?void 0:a.isRTL(u.floating)),E=C||(T||!M?[g(r)]:function(t){const e=g(t);return[f(t),e,f(e)]}(r)),B="none"!==I;!C&&B&&E.push(...function(t,e,o,s){const i=h(t);let l=function(t,e,o){const s=["left","right"],i=["right","left"],l=["top","bottom"],n=["bottom","top"];switch(t){case"top":case"bottom":return o?e?i:s:e?s:i;case"left":case"right":return e?l:n;default:return[]}}(d(t),"start"===o,s);return i&&(l=l.map((t=>t+"-"+i)),e&&(l=l.concat(l.map(f)))),l}(r,M,I,R));const k=[r,...E],z=await x(e,L),q=[];let O=(null==(s=l.flip)?void 0:s.overflows)||[];if(w&&q.push(z[N]),v){const t=function(t,e,o){void 0===o&&(o=!1);const s=h(t),i=m(t),l=p(i);let n="x"===i?s===(o?"end":"start")?"right":"left":"start"===s?"bottom":"top";return e.reference[l]>e.floating[l]&&(n=g(n)),[n,g(n)]}(i,n,R);q.push(z[t[0]],z[t[1]])}if(O=[...O,{placement:i,overflows:q}],!q.every((t=>t<=0))){var A,H;const t=((null==(A=l.flip)?void 0:A.index)||0)+1,e=k[t];if(e)return{data:{index:t,overflows:O},reset:{placement:e}};let o=null==(H=O.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:H.placement;if(!o)switch(y){case"bestFit":{var $;const t=null==($=O.filter((t=>{if(B){const e=b(t.placement);return e===S||"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:$[0];t&&(o=t);break}case"initialPlacement":o=r}if(i!==o)return{reset:{placement:o}}}return{}}}},nt=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:o,y:s,placement:i,rects:l,middlewareData:n}=e,{offset:r=0,mainAxis:a=!0,crossAxis:h=!0}=c(t,e),p={x:o,y:s},m=b(i),f=u(m);let g=p[f],w=p[m];const v=c(r,e),x="number"==typeof v?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(a){const t="y"===f?"height":"width",e=l.reference[f]-l.floating[t]+x.mainAxis,o=l.reference[f]+l.reference[t]-x.mainAxis;g<e?g=e:g>o&&(g=o)}if(h){var C,y;const t="y"===f?"width":"height",e=["top","left"].includes(d(i)),o=l.reference[m]-l.floating[t]+(e&&(null==(C=n.offset)?void 0:C[m])||0)+(e?0:x.crossAxis),s=l.reference[m]+l.reference[t]+(e?0:(null==(y=n.offset)?void 0:y[m])||0)-(e?x.crossAxis:0);w<o?w=o:w>s&&(w=s)}return{[f]:g,[m]:w}}}},rt=(t,e,o)=>{const s=new Map,i={platform:et,...o},l={...i.platform,_c:s};return(async(t,e,o)=>{const{placement:s="bottom",strategy:i="absolute",middleware:l=[],platform:n}=o,r=l.filter(Boolean),a=await(null==n.isRTL?void 0:n.isRTL(e));let c=await n.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:h}=v(c,s,a),u=s,p={},b=0;for(let o=0;o<r.length;o++){const{name:l,fn:m}=r[o],{x:f,y:g,data:w,reset:x}=await m({x:d,y:h,initialPlacement:s,placement:u,strategy:i,middlewareData:p,rects:c,platform:n,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[l]:{...p[l],...w}},x&&b<=50&&(b++,"object"==typeof x&&(x.placement&&(u=x.placement),x.rects&&(c=!0===x.rects?await n.getElementRects({reference:t,floating:e,strategy:i}):x.rects),({x:d,y:h}=v(c,u,a))),o=-1)}return{x:d,y:h,placement:u,strategy:i,middlewareData:p}})(t,e,{...i,platform:l})},at=t=>"function"==typeof t,ct=Array.isArray,dt=()=>Math.random().toString(36).slice(2),ht=(t,e)=>{let o;return function(...s){o&&clearTimeout(o),o=setTimeout((()=>{t.apply(this,s)}),e)}};function ut(t,e){let o=t.parent;for(;o&&o.statics.blotName!==e&&o!==t.scroll;)o=o.parent;if(o===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return o}function pt(t,e){const o=new Array(e.length),s=new Map(e.map(((t,e)=>[t,e])));let i=t.parent;for(;i&&i!==t.scroll&&0!==s.size;){if(s.has(i.statics.blotName)){o[s.get(i.statics.blotName)]=i,s.delete(i.statics.blotName)}i=i.parent}if(s.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(s.keys()).join(", ")}`);return o}function bt(t,e){for(const o of Object.getOwnPropertyNames(e))/^constructor$/.test(o)||Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(e,o));return t}function mt(t,e){const o=class extends t{constructor(...t){super(...t)}};for(const t of e)bt(o.prototype,t.prototype);return o}function ft(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function gt(){for(let t=0;t<this.scrollHandler.length;t++){const[e,o]=this.scrollHandler[t];e.removeEventListener("scroll",o)}this.scrollHandler=[]}const wt=(t,e,o,s,i)=>(t.addEventListener("transitionend",o,s),setTimeout((()=>{o()}),e)),vt=(t,e)=>{e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add("input__item"),t){const e=document.createElement("span");e.classList.add("input__label"),e.textContent=t,o.appendChild(e)}const s=document.createElement("div");s.classList.add("input__input");const i=document.createElement("input");for(const t in e)i.setAttribute(t,e[t]);(e.max||e.min)&&i.addEventListener("blur",(()=>{e.max&&e.max<=Number(i.value)&&(i.value=String(e.max)),e.min&&e.min>=Number(i.value)&&(i.value=String(e.min))})),s.appendChild(i),o.appendChild(s),i.addEventListener("focus",(()=>{s.classList.add("focus")})),i.addEventListener("blur",(()=>{s.classList.remove("focus")}));return{item:o,input:i,errorTip:t=>{let e;s.classList.contains("error")?e=s.querySelector(".input__error-tip"):(e=document.createElement("span"),e.classList.add("input__error-tip"),s.appendChild(e)),e.textContent=t,s.classList.add("error");return{removeError:()=>{s.classList.remove("error"),e.remove()}}}}};let xt=8e3;const Ct=async(t={})=>{const e=document.createElement("div");e.classList.add("table-creator");const o=document.createElement("div");o.classList.add("table-creator__input");const{item:s,input:i,errorTip:l}=vt(t.rowText||"行数",{type:"number",value:String(t.row||""),max:99}),{item:n,input:r,errorTip:a}=vt(t.colText||"列数",{type:"number",value:String(t.col||""),max:99});o.appendChild(s),o.appendChild(n),e.appendChild(o);const c=document.createElement("div");c.classList.add("table-creator__control");const d=document.createElement("button");d.classList.add("table-creator__btn","confirm"),d.textContent=t.confirmText||"Confirm";const h=document.createElement("button");h.classList.add("table-creator__btn","cancel"),h.textContent=t.cancelText||"Cancel",c.appendChild(d),c.appendChild(h),e.appendChild(c);const u=(e=Number(i.value),o=Number(r.value))=>{if(Number.isNaN(e)||e<=0)l(t.notPositiveNumberError||"请输入正整数");else{if(!(Number.isNaN(o)||o<=0))return{row:e,col:o};a(t.notPositiveNumberError||"请输入正整数")}},p=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",p))};return new Promise(((t,o)=>{const{close:s}=(({child:t,target:e=document.body,beforeClose:o=()=>{}}={})=>{const s=e,i=document.createElement("div");i.classList.add("dialog"),i.style.zIndex=String(xt);const l=document.createElement("div");if(l.classList.add("dialog__overlay"),i.appendChild(l),t){const e=document.createElement("div");e.classList.add("dialog__content"),e.appendChild(t),l.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const n=getComputedStyle(s).overflow;s.style.overflow="hidden",s.appendChild(i);const r=()=>{o(),i.remove(),s.style.overflow=n};return i.addEventListener("click",r),xt+=1,{dialog:i,close:r}})({child:e,beforeClose:o});i.focus();for(const e of[i,r])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=u();e&&(t(e),s())}}));d.addEventListener("click",(async()=>{const e=u();e&&(t(e),s())})),document.addEventListener("keydown",p),h.addEventListener("click",s)}))};let yt;const It=(t,e={})=>{const{msg:o="",delay:s=150,content:i,direction:l="bottom"}=e;if(o||i){yt||(yt=document.createElement("div"),document.body.appendChild(yt));const e=document.createElement("div");let n,r;e.classList.add("tooltip","hidden","transparent"),i?e.appendChild(i):o&&(e.textContent=o);const a=()=>{r&&r(),rt(t,e,{placement:l,middleware:[lt(),it({limiter:nt()}),st(4)]}).then((({x:t,y:o})=>{Object.assign(e.style,{left:`${t}px`,top:`${o}px`})}))},c=()=>{e.classList.add("hidden"),yt.contains(e)&&yt.removeChild(e),r&&r()},d=()=>{n&&clearTimeout(n),n=setTimeout((()=>{yt.appendChild(e),e.removeEventListener("transitionend",c),e.classList.remove("hidden"),r=ot(t,e,a),e.classList.remove("transparent")}),s)},h=()=>{n&&clearTimeout(n),n=setTimeout((()=>{e.classList.add("transparent"),wt(e,150,c,{once:!0})}),s)},u=[t,e];for(const t of u)t.addEventListener("mouseenter",d),t.addEventListener("mouseleave",h);return{destroy:()=>{for(const t of u)t.removeEventListener("mouseenter",d),t.removeEventListener("mouseleave",h);r&&r(),e.remove()}}}return null},Mt={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"},Lt={colMinWidthPre:5,colMinWidthPx:40,rowMinHeightPx:36},Nt={AFTER_TABLE_RESIZE:"after-table-resize"},St=[["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)"]],Tt=t.import("parchment"),Rt=t.import("blots/container"),Et=t.import("blots/block"),Bt=t.import("blots/block/embed");class kt extends Rt{static tagName;static blotName=Mt.container;static scope=Tt.Scope.BLOCK_BLOT;static allowedChildren=[Et,Bt,Rt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,o){const[s]=this.children.find(t);if(!s){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,o)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const zt=t.import("parchment"),qt=t.import("blots/block");class Ot extends qt{replaceWith(t,e){const o="string"==typeof t?this.scroll.create(t,e):t;if(o instanceof zt.ParentBlot){if(o.statics.blotName===Mt.tableCellInner){const t=this.parent;if(t.statics.blotName===Mt.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),this.parent.statics.blotName===Mt.tableCellInner&&this.prev){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.parent.remove();const e=t.parent.parent;e.statics.blotName===Mt.tableRow&&0===e.children.length&&e.remove()}}else null!=t&&t.insertBefore(o,this.next),o.appendChild(this);return o}this.moveChildren(o)}return null!=this.parent&&(this.parent.insertBefore(o,this.next||void 0),this.remove()),this.attributes.copy(o),o}format(t,e){if(t!==Mt.tableCellInner||this.parent.statics.blotName!==t||e)super.format(t,e);else{const[t,e,o]=pt(this,[Mt.tableCell,Mt.tableRow,Mt.tableWrapper]),s=o.next;let i=e.next,l=t.next;for(o.parent.insertBefore(this,s);l;){const t=l.next;o.parent.insertBefore(l,s),l=t}for(;i;){const t=i.next;o.parent.insertBefore(i,s),i=t}}}}const At=t.import("formats/blockquote");class Ht extends(mt(At,[Ot])){}const $t=t.import("formats/code-block");class Wt extends(mt($t,[Ot])){}const jt=t.import("formats/header");class Dt extends(mt(jt,[Ot])){}const Vt=t.import("formats/list");class Ft extends(mt(Vt,[Ot])){static register(){}}const Pt=t.import("parchment"),_t=t.import("blots/scroll");class Xt extends _t{createBlock(t,e){let o,s={};for(const[e,i]of Object.entries(t)){null!=this.query(e,Pt.Scope.BLOCK&Pt.Scope.BLOT)?o=e:s[e]=i}o===Mt.tableCellInner&&(s={...t},delete s[o]);const i=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(i,e||void 0);const l=i.length();for(const[t,e]of Object.entries(s))i.formatAt(0,l,t,e);return i}}const Ut=t.import("blots/block"),Yt=t.import("blots/block/embed"),Kt=["table-id","row-id","col-id","rowspan","colspan","background-color","border-color","height"];class Zt extends kt{static blotName=Mt.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static defaultChild=Ut;static create(t){const{tableId:e,rowId:o,colId:s,rowspan:i,colspan:l,backgroundColor:n,borderColor:r,height:a}=t,c=super.create();return c.dataset.tableId=e,c.dataset.rowId=o,c.dataset.colId=s,c.dataset.rowspan=String(i||1),c.dataset.colspan=String(l||1),a&&(c.dataset.height=a),n&&(c.dataset.backgroundColor=n),r&&(c.dataset.borderColor=r),c}static formats(t){const{tableId:e,rowId:o,colId:s,rowspan:i,colspan:l,backgroundColor:n,borderColor:r,height:a}=t.dataset,c={tableId:e,rowId:o,colId:s,rowspan:Number(i),colspan:Number(l)};return a&&(c.height=a),n&&(c.backgroundColor=n),r&&(c.borderColor=r),c}allowDataAttrs=new Set(Kt);setFormatValue(t,e){if(!this.allowDataAttrs.has(t))return;const o=`data-${t}`;e?this.domNode.setAttribute(o,e):this.domNode.removeAttribute(o),this.parent&&this.parent.setFormatValue(t,e);const s=this.descendants(Ut,0);for(const t of s)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)}get backgroundColor(){return this.domNode.dataset.backgroundColor||""}set backgroundColor(t){this.setFormatValue("background-color",t)}get height(){return this.domNode.dataset.height||""}set height(t){this.setFormatValue("height",t)}get borderColor(){return this.domNode.dataset.borderColor||""}getColumnIndex(){return ut(this,Mt.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,o,s){0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,o,s)}formats(){const t=Zt.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:o,rowspan:s}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===o&&i.rowspan===s}optimize(){const t=this.parent,e=Zt.formats(this.domNode);if(this.prev&&this.prev instanceof Yt){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==Mt.tableCell&&(this.wrap(Mt.tableCell,e),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,e){if(t.statics.blotName===this.statics.blotName){const o=t,s=Zt.formats(o.domNode),i=Zt.formats(this.domNode);if(Object.entries(i).every((([t,e])=>e===s[t])))return this.parent.insertBefore(o,this.next);{const[t,l]=pt(this,[Mt.tableRow,Mt.tableCell]);if(e){const o=e.offset();if(o+1<this.length()){const e=this.scroll.create(Mt.tableCellInner,i);this.children.forEachAt(o+1,this.length(),(t=>{e.appendChild(t)})),t.insertBefore(e.wrap(Mt.tableCell,i),l.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(e){const o=e.offset(t);t.split(o)}else if(l.next){const e=l.next.offset(t);t.split(e)}const i=this.scroll.create(Mt.tableRow,s),n=this.scroll.create(Mt.tableCell,s);return n.appendChild(o),i.appendChild(n),t.parent.insertBefore(i,t.next)}return t.insertBefore(o.wrap(Mt.tableCell,s),e?l:l.next)}}super.insertBefore(t,e)}}class Gt extends kt{static blotName=Mt.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.height=t}))}insertCell(t,e){const o=[],s=this.children.iterator();let i,l=0;for(;(i=s())&&(l+=i.colspan,!(l>t));)if(1!==i.rowspan)for(let t=0;t<i.rowspan-1;t++)o[t]=(o[t]||0)+i.colspan;if(i&&l-i.colspan<t){i.getCellInner().colspan+=1,1!==i.rowspan&&(o.skipRowNum=i.rowspan-1)}else{const t=this.scroll.create(Mt.tableCell,e),o=this.scroll.create(Mt.tableCellInner,e),s=this.scroll.create("block");s.appendChild(this.scroll.create("break")),o.appendChild(s),t.appendChild(o),this.insertBefore(t,i)}return o}getCellByColumIndex(t){const e=[];let o=null,s=0;if(t<0)return[o,s,e];const i=this.children.iterator();for(;o=i();){if(s+=o.colspan,1!==o.rowspan)for(let t=0;t<o.rowspan-1;t++)e[t]=(e[t]||0)+o.colspan;if(s>t)break}return[o,s,e]}removeCell(t){if(t<0)return[];const e=this.getCellByColumIndex(t),[o,s]=e,i=e[2];if(!o)return i;if(s-o.colspan<t||o.colspan>1){const[e]=o.descendants(Zt);if(1!==o.colspan&&t===s-o.colspan){const t=ut(this,Mt.tableMain).getColIds();e.colId=t[t.indexOf(e.colId)+1]}1!==o.rowspan&&(i.skipRowNum=o.rowspan-1),e.colspan-=1}else o.remove();return i}foreachCellInner(t){const e=this.children.iterator();let o,s=0;for(;o=e();){const[e]=o.descendants(Zt);if(t(e,s++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const e=this.parent,{tableId:o}=this;null!==e&&e.statics.blotName!==Mt.tableBody&&this.wrap(Mt.tableBody,o),super.optimize(t)}}class Qt extends kt{static blotName=Mt.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const e=ut(this,Mt.tableMain);if(!e)return;const o=e.getColIds(),s=this.descendants(Gt),i=new Set(o);let l=0;for(const e of s){if(l===t)break;e.foreachCellInner((e=>{if(l+e.rowspan>t&&(e.rowspan+=1,i.delete(e.colId),1!==e.colspan)){const t=o.indexOf(e.colId);for(let s=0;s<e.colspan-1;s++)i.delete(o[t+s+1])}})),l+=1}const n=e.tableId,r=dt(),a=this.scroll.create(Mt.tableRow,{tableId:n,rowId:r});for(const t of i){const e=this.scroll.create("break").wrap("block").wrap(Mt.tableCellInner,{tableId:n,rowId:r,colId:t,rowspan:1,colspan:1}).wrap(Mt.tableCell,{tableId:n,rowId:r,colId:t,rowspan:1,colspan:1});a.appendChild(e)}this.insertBefore(a,s[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent;if(null!==e&&e.statics.blotName!==Mt.tableMain){const{tableId:t}=this;this.wrap(Mt.tableMain,{tableId:t})}super.optimize(t)}}class Jt extends kt{static blotName=Mt.tableCell;static tagName="td";static className="ql-table-cell";static create(t){const{tableId:e,rowId:o,colId:s,rowspan:i,colspan:l,backgroundColor:n,borderColor:r,height:a}=t,c=super.create();return c.dataset.tableId=e,c.dataset.rowId=o,c.dataset.colId=s,c.setAttribute("rowspan",String(i||1)),c.setAttribute("colspan",String(l||1)),a&&(c.style.height=a),n&&(c.style.backgroundColor=n),r&&(c.style.borderColor=r),c}static formats(t){const{tableId:e,rowId:o,colId:s}=t.dataset,i=Number(t.getAttribute("rowspan")),l=Number(t.getAttribute("colspan")),n={tableId:e,rowId:o,colId:s,rowspan:Number.isNaN(i)?1:i,colspan:Number.isNaN(l)?1:l},{height:r,backgroundColor:a,borderColor:c}=t.style;return r&&(n.height=r),a&&(n.backgroundColor=a),c&&(n.borderColor=c),n}allowDataAttrs=new Set(["table-id","row-id","col-id"]);allowAttrs=new Set(["rowspan","colspan"]);allowStyle=new Set(["background-color","border-color","height"]);setFormatValue(t,e){if(this.allowAttrs.has(t)||this.allowDataAttrs.has(t)){let o=t;this.allowDataAttrs.has(t)&&(o=`data-${t}`),e?this.domNode.setAttribute(o,e):this.domNode.removeAttribute(o)}else this.allowStyle.has(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"))}get backgroundColor(){return this.domNode.dataset.backgroundColor||""}get height(){return this.domNode.style.height}getCellInner(){return this.descendants(Zt)[0]}checkMerge(){const{colId:t,rowId:e,colspan:o,rowspan:s}=this,i=this.next;return null!==i&&i.statics.blotName===this.statics.blotName&&i.rowId===e&&i.colId===t&&i.colspan===o&&i.rowspan===s}optimize(t){const e=this.parent,{tableId:o,rowId:s}=this;null!==e&&e.statics.blotName!==Mt.tableRow&&this.wrap(Mt.tableRow,{tableId:o,rowId:s}),super.optimize(t)}}const te=t.import("blots/block/embed");class ee extends te{scroll;domNode;static blotName=Mt.tableCol;static tagName="col";static create(t){const{width:e,tableId:o,colId:s,full:i,align:l}=t,n=super.create();return n.setAttribute("width",`${Number.parseFloat(e)}${i?"%":"px"}`),i&&(n.dataset.full=String(i)),l&&"left"!==l&&(n.dataset.align=l),n.dataset.tableId=o,n.dataset.colId=s,n.setAttribute("contenteditable","false"),n}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){const t=this.domNode.getAttribute("width");return Number.parseFloat(t)}set width(t){const e=Number.parseFloat(t);this.domNode.setAttribute("width",`${e}${this.full?"%":"px"}`)}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")}static value(t){const{tableId:e,colId:o}=t.dataset,s=t.getAttribute("width"),i=t.dataset.align,l={tableId:e,colId:o,full:Object.hasOwn(t.dataset,"full")};return s&&(l.width=Number.parseFloat(s)),i&&(l.align=i),l}checkMerge(){const t=this.next,{tableId:e,colId:o}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===o}optimize(t){const e=this.parent;if(null!=e&&e.statics.blotName!==Mt.tableColgroup){const t=ee.value(this.domNode);this.wrap(Mt.tableColgroup,t)}ut(this,Mt.tableColgroup).align=this.align,super.optimize(t)}insertAt(t,e,o){if(null!=o)return void super.insertAt(t,e,o);const s=e.split("\n"),i=s.pop(),l=s.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),n=this.split(t),[r,a]=pt(this,[Mt.tableColgroup,Mt.tableMain]),c=r.next;if(n){const t=n.offset(r);r.split(t)}let d=a.parent.parent,h=a.parent.next;if(c){const t=c.descendants(Zt);if(t.length>0){const e=t[0],o=Zt.formats(e.domNode),s=this.scroll.create("block"),i=s.wrap(Mt.tableCellInner,o).wrap(Mt.tableCell,o).wrap(Mt.tableRow,o).wrap(Mt.tableBody,o.tableId);r.parent.insertBefore(i,r.next),d=s,h=s.next}}for(const t of l)d.insertBefore(t,h);i&&d.insertBefore(this.scroll.create("text",i),h)}}class oe extends kt{static blotName=Mt.tableMain;static tagName="table";static create(t){const e=super.create(),{tableId:o,full:s,align:i}=t;return e.dataset.tableId=o,"right"===i||"center"===i?e.dataset.align=i:e.removeAttribute("date-align"),s&&(e.dataset.full=String(s)),e.classList.add("ql-table"),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,o){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")}set full(t){this.domNode[t?"setAttribute":"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"),this.updateAlign()}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(Gt)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(ee)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const e=this.parent;null!==e&&e.statics.blotName!==Mt.tableWrapper&&this.wrap(Mt.tableWrapper,this.tableId),super.optimize(t)}}class se extends kt{static blotName=Mt.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")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let o,s=0;for(;(o=e())&&s!==t;)s++;return o}insertColByIndex(t,e){const o=this.parent;if(!(o instanceof oe))throw new TypeError("TableColgroupFormat should be child of TableFormat");const s=this.findCol(t),i=this.scroll.create(Mt.tableCol,e);if(o.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-i.width>=Lt.colMinWidthPre){e.width-=i.width;break}}this.insertBefore(i,s)}removeColByIndex(t){const e=this.parent;if(!(e instanceof oe))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const o=this.findCol(t);o&&(e.full&&(o.next?o.next.width+=o.width:o.prev&&(o.prev.width+=o.width)),o.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof oe&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent,{tableId:o,full:s,align:i}=this;null!=e&&e.statics.blotName!==Mt.tableMain&&this.wrap(Mt.tableMain,{tableId:o,full:s,align:i});ut(this,Mt.tableMain).align=i,super.optimize(t)}}class ie extends kt{static blotName=Mt.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 o=this.descendants(Qt),s=this.descendants(se);0!==o.length&&0!==s.length||this.remove()}}class le{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;constructor(e,o,s){this.tableModule=e,this.table=o,this.quill=s,this.tableBlot=t.find(o),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const e=this.tableModule.addContainer("ql-table-align"),o=t.import("ui/icons"),s={left:o.align[""],center:o.align.center,right:o.align.right};for(const[o,i]of Object.entries(s)){const s=document.createElement("span");s.dataset.align=o,s.classList.add("ql-table-align-item"),s.innerHTML=`<i class="icon">${i}</i>`,s.addEventListener("click",(()=>{const e=s.dataset.align;e&&(this.setTableAlign(this.tableBlot,e),this.quill.once(t.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hideSelection(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),e.appendChild(s)}return this.cleanup||(this.cleanup=ot(this.tableWrapperBlot.domNode,e,(()=>this.update()))),e}setTableAlign(t,e){const o=t.getCols();for(const t of o)t.align=e}show(){this.alignBox&&Object.assign(this.alignBox.style,{display:"flex"})}hide(){this.alignBox&&(Object.assign(this.alignBox.style,{display:null}),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(),rt(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[lt(),it({limiter:nt()}),st(8)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))))}destroy(){this.hide(),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}}const ne="color-selector",re=new Set,ae=[{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,o)=>{t.setCellAttrs(e,"background-color",o)}},{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,o)=>{t.setCellAttrs(e,"border-color",o)}}],ce="table-color-used",de="table-color-item",he="table-color-btn",ue="table-color-map",pe="table-color-map-row",be="table-color-select-wrapper";class me{tableModule;quill;options;menu=null;updateUsedColor;colorItemClass=`color-${dt()}`;tooltipItem=[];constructor(t,e,o){this.tableModule=t,this.quill=e,this.options=this.resolveOptions(o);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);ct(e)||(e=[]),e.map((t=>re.add(t)))}catch{}this.updateUsedColor=ht((t=>{if(!t)return;if(re.add(t),re.size>10){const t=Array.from(re).slice(-10);re.clear(),t.map((t=>re.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(re)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${ce}`));for(const o of e){if(!o)continue;const e=o.querySelectorAll(`.${de}[style*="background-color: ${t}"]`);for(const t of Array.from(e))t.remove();const s=document.createElement("div");s.classList.add(de),s.style.backgroundColor=String(t),o.appendChild(s)}}),1e3)}resolveOptions(t){const e=Object.assign({tipText:!0,tipTexts:{},tools:ae,localstorageKey:"__table-bg-used-color",defaultColorMap:St},t);return e.texts=Object.assign(this.resolveTexts(t.texts),t.texts),e}resolveTexts(t={}){return Object.assign({custom:"Custom",clear:"Clear",transparent:"Transparent"},t)}getUsedColors(){return re}buildTools(){const t=document.createElement("div");t.classList.add("ql-table-menu"),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:o,icon:s,handle:i,isColorChoose:l,key:n,tip:r=""}=e,a=document.createElement("span");if(a.classList.add("ql-table-menu-item"),"break"===o)a.classList.add("break");else{const t=document.createElement("i");if(t.classList.add("icon"),at(s)?t.appendChild(s(this.tableModule)):t.innerHTML=s,a.appendChild(t),l&&n){const t=this.createColorChoose({name:o,icon:s,handle:i,isColorChoose:l,key:n,tip:r}),e=It(a,{content:t,direction:"top"});e&&this.tooltipItem.push(e),a.classList.add(ne)}else at(i)&&a.addEventListener("click",(t=>{this.quill.focus(),i(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.options.tipTexts[o]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose({handle:t,key:e}){const o=document.createElement("div");if(o.classList.add(be),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(ue);for(const e of this.options.defaultColorMap){const o=document.createElement("div");o.classList.add(pe);for(const t of e){const e=document.createElement("div");e.classList.add(de),e.style.backgroundColor=t,o.appendChild(e)}t.appendChild(o)}o.appendChild(t)}const s=document.createElement("div");s.classList.add(pe),Object.assign(s.style,{marginTop:"4px"});const i=document.createElement("div");i.classList.add(he,"table-color-transparent"),i.textContent=this.options.texts.transparent,i.addEventListener("click",(()=>{t(this.tableModule,this.getSelectedTds(),"transparent")}));const l=document.createElement("div");l.classList.add(he,"table-color-clear"),l.textContent=this.options.texts.clear,l.addEventListener("click",(()=>{t(this.tableModule,this.getSelectedTds(),null)}));const n=document.createElement("label");n.classList.add(he,"table-color-custom");const r=document.createElement("span");r.textContent=this.options.texts.custom;const a=document.createElement("input");if(a.type="color",Object.assign(a.style,{width:0,height:0,padding:0,border:0,outline:"none",opacity:0}),a.addEventListener("input",(()=>{t(this.tableModule,this.getSelectedTds(),a.value),this.updateUsedColor(a.value)}),!1),n.appendChild(r),n.appendChild(a),s.appendChild(i),s.appendChild(l),s.appendChild(n),o.appendChild(s),re.size>0){const t=document.createElement("div");t.classList.add(ce,this.colorItemClass);for(const e of re){const o=document.createElement("div");o.classList.add(de),o.style.backgroundColor=e,t.appendChild(o)}o.appendChild(t)}return o.addEventListener("click",(t=>{const o=t.target,s=o.style.backgroundColor,i=this.getSelectedTds();if(o&&s&&i.length>0){if(this.tableModule.setCellAttrs(i,e,s),o.closest(`.${de}`))return;this.updateUsedColor(s)}})),o}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const o=It(t,{msg:e});o&&this.tooltipItem.push(o)}updateTools(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&Object.assign(this.menu.style,{display:"flex"})}hideTools(){this.menu&&Object.assign(this.menu.style,{display:"none"})}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}class fe extends me{tableModule;quill;constructor(t,e,o){super(t,e,o),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),this.updateTools({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hideTools()}),{once:!0})):this.hideTools()};buildTools(){const t=super.buildTools();t.classList.add("contextmenu");const e=t.getElementsByClassName(ne);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const o=document.createElement("span");o.textContent=e,t.appendChild(o)}updateTools(t){if(!this.menu||!this.tableModule.tableSelection||!this.tableModule.tableSelection.boundary)return;super.updateTools();const e={display:"flex",left:0,top:0};if(!t)return this.hideTools();const{x:o,y:s}=t;e.left=o,e.top=s,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const i=this.menu.getBoundingClientRect(),{left:l,top:n}=(t=>{let{left:e,top:o,width:s,height:i}=t;const{clientWidth:l,clientHeight:n}=document.documentElement;let r=!1,a=!1;return e+s>l?(e=l-s-8,r=!0):e<0&&(e=8,r=!0),o+i>n?(o=n-i-8,a=!0):o<0&&(o=8,a=!0),{left:e,top:o,leftLimited:r,topLimited:a}})(i);Object.assign(this.menu.style,{left:`${l+window.scrollX}px`,top:`${n+window.scrollY}px`})}destroy(){for(const t of this.tooltipItem)t.destroy();this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),this.menu&&(this.menu.remove(),this.menu=null)}}class ge extends me{tableModule;quill;constructor(t,e,o){super(t,e,o),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu)}updateTools(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(super.updateTools(),rt(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[lt(),it({limiter:nt()}),st(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}const we=t=>!t.full&&"right"===t.align;class ve{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);constructor(t){this.quill=t}findCurrentColIndex(t){return-1}colWidthChange(t,e,o){}handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0"),o=this.tableMain.full;if(o){let s=e/this.tableMain.domNode.getBoundingClientRect().width*100;const i=t[this.colIndex].width;if(s<i){if(s=Math.max(Lt.colMinWidthPre,s),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1,l=t[e],n=l.width+i-s;l.width=`${n}%`,this.colWidthChange(e,n,o)}else s=100;t[this.colIndex].width=`${s}%`,this.colWidthChange(this.colIndex,s,o)}else if(t[this.colIndex+1]){const e=i+t[this.colIndex+1].width;s=Math.min(e-Lt.colMinWidthPre,s),t[this.colIndex].width=`${s}%`,this.colWidthChange(this.colIndex,s,o),t[this.colIndex+1].width=e-s+"%",this.colWidthChange(this.colIndex+1,e-s,o)}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,t[this.colIndex].width=`${e}px`,this.colWidthChange(this.colIndex,e,o);document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(Nt.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),o=e[this.colIndex].domNode.getBoundingClientRect(),s=this.tableMain.domNode.getBoundingClientRect();let i=t.clientX;if(this.tableMain.full){const t=Lt.colMinWidthPre/100*s.width;let l=s.right;i>o.right&&e[this.colIndex+1]&&(l=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,o.left+t));const n=o.x+t;i=Math.min(Math.max(i,n),l)}else we(this.tableMain)?o.right-i<Lt.colMinWidthPx&&(i=o.right-Lt.colMinWidthPx):i-o.x<Lt.colMinWidthPx&&(i=o.x+Lt.colMinWidthPx);let l=i-o.x;return we(this.tableMain)&&(l=o.right-i),this.dragColBreak.style.left=`${i}px`,this.dragColBreak.dataset.w=String(l),{left:i,width:l}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),o=this.tableMain.domNode.getBoundingClientRect(),s=o.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const i=e[this.colIndex].width,l=this.tableMain.full?i/100*s:i;if(this.tableMain.full){if(i<Lt.colMinWidthPre)return}else if(l<Lt.colMinWidthPx)return;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const n=document.createElement("div");n.classList.add("ql-table-drag-line"),n.classList.add("col"),n.dataset.w=String(l);const r={top:o.y,left:t.clientX,height:o.height};Object.assign(n.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(n),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=n,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(Nt.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let o=t.clientY;return o-e.y<Lt.rowMinHeightPx&&(o=e.y+Lt.rowMinHeightPx),this.dragRowBreak.style.top=`${o}px`,this.dragRowBreak.dataset.h=String(o-e.y),{top:o,height:o-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,o=this.tableMain?.domNode.getBoundingClientRect(),s=document.createElement("div");s.classList.add("ql-table-drag-line"),s.classList.add("row"),s.dataset.h=String(e);const i={top:t.clientY,left:o.x,width:o.width};Object.assign(s.style,{top:`${i.top}px`,left:`${i.left}px`,width:`${i.width}px`});const l=document.body;return l.appendChild(s),this.dragRowBreak&&l.removeChild(this.dragRowBreak),this.dragRowBreak=s,i}update(){}destroy(){}}class xe extends ve{tableModule;table;options;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;constructor(e,o,s,i){super(s),this.tableModule=e,this.table=o,this.options=this.resolveOptions(i),this.tableMain=t.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer("ql-table-resizer"),this.resizeObserver=new ResizeObserver((()=>{this.showTool()})),this.resizeObserver.observe(this.table)))}resolveOptions(t){return Object.assign({size:12},t)}handleResizerHeader(t,e){const{clientX:o,clientY:s}=e,i=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const l=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const n=[{x:t?i.left:o,y:t?s:i.top},{x:t?i.right:o,y:t?s:i.bottom}];this.lastHeaderSelect?(n[0]={x:Math.min(n[0].x,this.lastHeaderSelect[0].x),y:Math.min(n[0].y,this.lastHeaderSelect[0].y)},n[1]={x:Math.max(n[1].x,this.lastHeaderSelect[1].x),y:Math.max(n[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=n,l.selectedTds=l.computeSelectedTds(...n),l.showSelection()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName("ql-table-col-separator")).indexOf(t.target)}colWidthChange(t,e,o){Array.from(this.root.getElementsByClassName("ql-table-col-header"))[t].style.width=`${e}${o?"%":"px"}`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.options.size+"px",left:`${e.left}px`,height:`${e.height+this.options.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName("ql-table-col-header")),e=Array.from(this.root.getElementsByClassName("ql-table-col-separator"));ft.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("ql-table-row-separator")).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName("ql-table-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.options.size+"px",width:`${e.width+this.options.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName("ql-table-row-header")),e=Array.from(this.root.getElementsByClassName("ql-table-row-separator"));ft.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.domNode.getBoundingClientRect(),e=this.tableWrapper.domNode.getBoundingClientRect(),o=Math.max(t.x,e.x),s=Math.max(t.y,e.y),i=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:s-i.y+"px",left:o-i.x+"px"});let l=-1*this.options.size,n=-1*this.options.size;we(this.tableMain)?(this.root.classList.add("table-align-right"),l=Math.min(e.width,t.width),n=Math.min(e.width,t.width)):this.root.classList.remove("table-align-right"),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${l}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${n}px)`})}showTool(){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("ql-table-resizer-corner"),Object.assign(this.corner.style,{width:`${this.options.size}px`,height:`${this.options.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.showSelection()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let o="";for(const t of this.tableCols){let s=t.width+(this.tableMain.full?"%":"px");t.width||(s=`${t.domNode.getBoundingClientRect().width}px`),o+=`<div class="ql-table-col-header" style="width: ${s}">\n <div class="ql-table-col-separator" style="height: ${e.height+this.options.size-3}px"></div>\n </div>`}const s=document.createElement("div");s.classList.add("ql-table-resizer-col");const i=document.createElement("div");i.classList.add("ql-table-col-wrapper"),Object.assign(s.style,{transform:`translateY(-${this.options.size}px)`,maxWidth:`${t.width}px`,height:`${this.options.size}px`}),Object.assign(i.style,{width:`${e.width}px`}),i.innerHTML=o,s.appendChild(i),this.root.appendChild(s),s.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=s,this.bindColEvents()}if(this.tableRows.length>0){let o="";for(const t of this.tableRows){o+=`<div class="ql-table-row-header" style="height: ${`${t.domNode.getBoundingClientRect().height}px`}">\n <div class="ql-table-row-separator" style="width: ${e.width+this.options.size-3}px"></div>\n </div>`}const s=document.createElement("div");s.classList.add("ql-table-resizer-row");const i=document.createElement("div");i.classList.add("ql-table-row-wrapper"),Object.assign(s.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${t.height}px`}),Object.assign(i.style,{height:`${e.height}px`}),i.innerHTML=o,s.appendChild(i),this.root.appendChild(s),s.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=s,this.bindRowEvents()}this.update(),ft.call(this,this.quill.root,(()=>{this.update()}))}hideTool(){this.root.classList.add("ql-hidden")}destroy(){this.hideTool(),gt.call(this),this.resizeObserver.disconnect();for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}}class Ce extends ve{tableModule;colResizer;rowResizer;currentTableCell;dragging=!1;options;curColIndex=-1;curRowIndex=-1;tableCellBlot;constructor(e,o,s){super(o),this.tableModule=e,this.options=this.resolveOptions(s),this.colResizer=this.tableModule.addContainer("ql-table-resize-line-col"),this.rowResizer=this.tableModule.addContainer("ql-table-resize-line-row"),this.quill.root.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(t.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=e=>{if(this.dragging)return;const o=this.findTableCell(e);if(!o)return this.hideResizer();const s=t.find(o);s&&this.currentTableCell!==o&&(this.showResizer(),this.currentTableCell=o,this.tableCellBlot=s,this.tableMain=ut(s,Mt.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hideResizer()};resolveOptions(t){return Object.assign({},t)}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=function(){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("ql-table-resize-line-col");const[e]=pt(t,[Mt.tableBody]),o=e.domNode.getBoundingClientRect(),s=t.domNode.getBoundingClientRect(),i=this.quill.root.getBoundingClientRect();let l=s.right-i.x;we(this.tableMain)&&(l=s.left-i.x),Object.assign(this.colResizer.style,{top:o.y-i.y+"px",left:`${l}px`,height:`${o.height}px`});const n=this.tableMain.getCols();this.curColIndex=n.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("ql-table-resize-line-row");const e=t.parent;if(!(e instanceof Gt))return;const[o]=pt(t,[Mt.tableBody]),s=o.domNode.getBoundingClientRect(),i=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:i.bottom-l.y+"px",left:s.x-l.x+"px",width:`${s.width}px`});const n=this.tableMain.getRows();this.curRowIndex=n.indexOf(e),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}showResizer(){Object.assign(this.colResizer.style,{display:null}),Object.assign(this.rowResizer.style,{display:null})}hideResizer(){this.currentTableCell=void 0,this.rowResizer.style.display="none",this.colResizer.style.display="none"}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.quill.root.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(t.events.TEXT_CHANGE,this.hideWhenTextChange)}}class ye{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;constructor(t,e,o,s){this.quill=t,this.isVertical=e,this.table=o,this.scrollbarContainer=s,this.container=o.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(o),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),ft.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:e,scrollTop:o}=this.quill.root,{offsetLeft:s,offsetTop:i}=this.container,{width:l,height:n}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=s,d=i;this.isVertical?c+=Math.min(l,r):d+=Math.min(n,a);const h=t.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-s),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?n:l}px`,transform:`translate(${c-e}px, ${d-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,o=t**2/this.container.scrollHeight,s=e**2/this.container.scrollWidth,i=Math.max(o,this.minSize),l=Math.max(s,this.minSize);this.ratioY=o/(t-o)/(i/(t-i)),this.ratioX=s/(e-s)/(l/(e-l)),this.sizeWidth=l+this.gap<e?`${l}px`:"",this.sizeHeight=i+this.gap<t?`${i}px`:""}createScrollbar(){const t=document.createElement("div");t.classList.add("ql-table-scrollbar"),t.classList.add(this.isVertical?"vertical":"horizontal","transparent"),Object.assign(t.style,{display:"none"}),this.thumb.classList.add("ql-table-scrollbar-thumb");const e=t=>{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const o=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],s=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*o/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=s*this.container[this.propertyMap.scrollSize]/100},o=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",o),this.cursorLeave&&(this.scrollbar.style.display="none")},s=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",e),document.addEventListener("mouseup",o),document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),s(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 i=[this.table,t];for(const t of i)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return ft.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.isVertical?this.sizeHeight:this.sizeWidth,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=ht((()=>{this.cursorLeave=!1,this.scrollbar.classList.remove("transparent"),wt(this.scrollbar,150,(()=>{this.scrollbar.style.display=(this.isVertical?this.sizeHeight:this.sizeWidth)?"block":"none"}))}),200);hideScrollbar=ht((()=>{this.cursorLeave=!0,this.scrollbar.classList.add("transparent"),wt(this.scrollbar,150,(()=>{this.scrollbar.style.display=this.cursorDown&&(this.isVertical?this.sizeHeight:this.sizeWidth)?"block":"none"}))}),200);destroy(){this.ob.disconnect(),gt.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}class Ie{tableModule;table;quill;scrollbarContainer;scrollbar;constructor(t,e,o){this.tableModule=t,this.table=e,this.quill=o,this.scrollbarContainer=this.tableModule.addContainer("ql-table-scrollbar-container"),this.scrollbar=[new ye(o,!0,e,this.scrollbarContainer),new ye(o,!1,e,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar)}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 Me{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;constructor(t,e,o,s={}){this.table=e,this.quill=o,this.options=this.resolveOptions(s),this.cellSelectWrap=t.addContainer("ql-table-selection"),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((()=>this.hideSelection())),this.resizeObserver.observe(this.table),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.tableMenu=new this.options.tableMenuClass(t,o,this.options.tableMenu)}resolveOptions(t){return Object.assign({selectColor:"#0589f3",tableMenuClass:ge,tableMenu:{}},t)}helpLinesInitial(){const t=document.createElement("div");return t.classList.add("ql-table-selection_line"),Object.assign(t.style,{"border-color":this.options.selectColor}),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(e,o){const s=t.find(this.table);if(!s)return[];const i=new Set(s.descendants(Jt).map(((t,e)=>(t.index=e,t)))),{x:l,y:n}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=l,this.selectedTableScrollY=n,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=e.x-l+this.startScrollX,h=e.y-n+this.startScrollY;let u={x:Math.max(c.left,Math.min(o.x,d)),y:Math.max(c.top,Math.min(o.y,h)),x1:Math.min(c.right,Math.max(o.x,d)),y1:Math.min(c.bottom,Math.max(o.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of i){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:o,right:s,bottom:l}=t.__rect;if(Le(u,{x:e,y:o,x1:s,y1:l},2)){p.add(t),i.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,o),x1:Math.max(u.x1,s),y1:Math.max(u.y1,l)},b=!0;break}if(e>u.x1&&o>u.y1)break}}for(const t of[...p,...i])delete t.__rect;return this.boundary=Ne({...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:o,clientX:s,clientY:i}=t,l=o.closest(".ql-table");if(0!==e||!l)return;const n=l.dataset.tableId,r={x:s,y:i},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.showSelection(),this.tableMenu.hideTools();const d=t=>{const{button:e,target:o,clientX:s,clientY:i}=t,l=o.closest(".ql-table");if(0!==e||!l||l.dataset.tableId!==n)return;this.dragging=!0;const a={x:s,y:i};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.updateSelection()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu.updateTools()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)}updateSelection(){if(0===this.selectedTds.length||!this.boundary)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:o,y:s}=this.getTableViewScroll(),i=this.table.parentElement.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect(),n=i.x-l.x,r=i.y-l.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-o-n+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-s-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${n}px`,top:`${r}px`,width:`${i.width+2}px`,height:`${i.height+2}px`}),this.dragging||this.tableMenu.updateTools()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}}showSelection(){gt.call(this),Object.assign(this.cellSelectWrap.style,{display:"block"}),this.updateSelection(),ft.call(this,this.quill.root,(()=>{this.updateSelection()})),ft.call(this,this.table.parentElement,(()=>{this.updateSelection()}))}hideSelection(){this.boundary=null,this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.tableMenu.hideTools(),gt.call(this)}destroy(){return this.resizeObserver.disconnect(),this.hideSelection(),this.tableMenu.destroy(),this.cellSelectWrap.remove(),gt.call(this),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),null}}function Le(t,e,o=4){const{x:s,y:i,x1:l,y1:n}=t,{x:r,y:a,x1:c,y1:d}=e;return!(l<=r+o||s+o>=c||(n<=a+o||i+o>=d))}function Ne(t,e){const o=e.getBoundingClientRect();return{x:t.x-o.x-e.scrollLeft,y:t.y-o.y-e.scrollTop,x1:t.x-o.x-e.scrollLeft+t.width,y1:t.y-o.y-e.scrollTop+t.height,width:t.width,height:t.height}}const Se=t.import("delta"),Te=t.import("blots/break"),Re=t.import("ui/icons"),Ee=(t,{tableId:e,rowId:o,colId:s})=>{const i={tableId:e,rowId:o,colId:s,colspan:1,rowspan:1},l=t.create(Mt.tableCell,i),n=t.create(Mt.tableCellInner,i),r=t.create("block");return r.appendChild(t.create("break")),n.appendChild(r),l.appendChild(n),l},Be=[Mt.tableCell],ke=t=>{return!(!t||!t.parent)&&(e=t.parent,!!Be.includes(e.statics.blotName)||ke(t.parent));var e};class ze{static moduleName="table-up";static toolName=Mt.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,e){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof ie)return o.prev.remove(),!1;if(e.format[Mt.tableCellInner]){if(0===o.offset(ut(o,Mt.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,e){const o=this.quill.getLine(t.index),s=o[0],i=o[1];if((s.next instanceof ie||s.next instanceof ee)&&i===s.length()-1)return!1;if(e.format[Mt.tableCellInner]){if(s===ut(s,Mt.tableCellInner).children.tail&&i===s.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[Mt.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(e){const[o,s]=this.quill.getLine(e.index);if(this.quill.getFormat(e.index+s+1,1)[Mt.tableCellInner])return!0;let i=2,l=o;for(;null!==l&&l.length()<=1;)if(l=l.prev,i-=1,i<=0)return this.quill.insertText(e.index+1,"\n"),this.quill.setSelection(e.index+1,t.sources.SILENT),!1;return!0}}};static register(){ie.allowedChildren=[oe],oe.allowedChildren=[Qt,se],oe.requiredContainer=ie,se.allowedChildren=[ee],se.requiredContainer=oe,Qt.allowedChildren=[Gt],Qt.requiredContainer=oe,Gt.allowedChildren=[Jt],Jt.requiredContainer=Qt,Jt.allowedChildren=[Zt,Te],Jt.requiredContainer=Gt,Zt.requiredContainer=Jt,t.register({"blots/scroll":Xt,"blots/block":Ot,[`blots/${Mt.container}`]:kt,"formats/header":Dt,"formats/list":Ft,"formats/blockquote":Ht,"formats/code-block":Wt,[`formats/${Mt.tableCell}`]:Jt,[`formats/${Mt.tableCellInner}`]:Zt,[`formats/${Mt.tableRow}`]:Gt,[`formats/${Mt.tableBody}`]:Qt,[`formats/${Mt.tableCol}`]:ee,[`formats/${Mt.tableColgroup}`]:se,[`formats/${Mt.tableMain}`]:oe,[`formats/${Mt.tableWrapper}`]:ie},!0)}quill;options;toolBox;fixTableByLisenter=ht(this.balanceTables,100);selector;picker;range;table;tableSelection;tableResize;tableScrollbar;tableAlign;get statics(){return this.constructor}constructor(e,o){this.quill=e,this.options=this.resolveOptions(o||{}),"boolean"!=typeof this.options.scrollbar||this.options.scrollbar||this.quill.container.classList.add("ql-table-scrollbar--origin"),this.toolBox=this.quill.addContainer("ql-table-toolbox");const s=this.quill.getModule("toolbar");if(s&&this.quill.theme.pickers){const[,t]=(s.controls||[]).find((([t])=>t===this.statics.toolName))||[];t&&"select"===t.tagName.toLocaleLowerCase()&&(this.picker=this.quill.theme.pickers.find((e=>e.select===t)),this.picker&&(this.picker.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect),this.picker.label.addEventListener("mousedown",this.handleInViewport)))}const i=this.quill.getModule("keyboard");for(const t of Object.values(ze.keyboradHandler))t.bindInHead?i.bindings[t.key].unshift(t):i.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const o=t.composedPath();if(!o||o.length<=0)return;const s=o.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(s){if(this.table===s)return this.tableSelection&&this.tableSelection.showSelection(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(s,e)}else this.table&&this.hideTableTools()}),!1),this.quill.on(t.events.EDITOR_CHANGE,((e,o,s)=>{if(e===t.events.SELECTION_CHANGE&&o){const[e]=this.quill.getLine(o.index),[i]=this.quill.getLine(o.index+o.length);let l,n;try{l=ut(e,Mt.tableMain)}catch{}try{n=ut(i,Mt.tableMain)}catch{}if(e instanceof ee)return s||(s={index:0,length:0}),this.quill.setSelection(o.index+(s.index>o.index?-1:1),o.length+(s.length===o.length?0:s.length>o.length?-1:1),t.sources.USER);if(i instanceof ee)return this.quill.setSelection(o.index+1,o.length+1,t.sources.USER);o.length>0&&(l&&!n?this.quill.setSelection(o.index-1,o.length+1,t.sources.USER):n&&!l&&this.quill.setSelection(o.index,o.length+1,t.sources.USER)),l&&n||this.hideTableTools()}})),this.options.resizerSetOuter||(this.tableResize=new Ce(this,e,this.options.resizeLine||{})),this.quill.on(Nt.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hideSelection()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if("string"==typeof t){const e=document.createElement("div");for(const o of t.split(" "))e.classList.add(o);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!0,texts:this.resolveTexts(t.texts||{}),full:!1,resizerSetOuter:!1,icon:Re.table,scrollbar:!0,showAlign:!0},t)}resolveTexts(t){return Object.assign({customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer"},t)}pasteTableHandler(){let t=dt(),e=dt(),o=[],s=0,i=0;this.quill.clipboard.addMatcher("table",((e,l)=>{if(0===l.ops.length)return l;for(let t=0;t<l.ops.length;t++){const{attributes:e,insert:o}=l.ops[t];o&&"string"!=typeof o&&o[ee.blotName]&&"\n"===l.ops[t+1].insert&&(l.ops.splice(t+1,1),t-=1),e&&e.table&&delete e.table,e&&e[Jt.blotName]&&delete e[Jt.blotName]}return t=dt(),o=[],s=0,i=0,l.ops.unshift({insert:"\n"}),l.ops.push({insert:"\n"}),l})),this.quill.clipboard.addMatcher("col",(e=>{o[i]=dt();const s=(new Se).insert({[Mt.tableCol]:Object.assign(ee.value(e),{tableId:t,colId:o[i]})});return i+=1,s})),this.quill.clipboard.addMatcher("tr",((t,o)=>{e=dt(),s=0;for(const t of o.ops)t.attributes&&t.attributes.background&&t.attributes[Mt.tableCellInner]&&!t.attributes[Mt.tableCellInner].backgroundColor&&(t.attributes[Mt.tableCellInner].backgroundColor=t.attributes.background);return o}));const l=(i,l)=>{const n=i,r=Jt.formats(n);if(!o[s])for(let t=s;t>=0;t--)o[t]||(o[t]=dt());const a=o[s];s+=r.colspan;const c=Object.assign(r,{tableId:t,rowId:e,colId:a}),d=[];for(const t of l.ops)if("string"==typeof t.insert){const e=t.insert.replaceAll(/\n+/g,"\n").split("\n");for(const t of e)t&&d.push({insert:t},{insert:"\n",attributes:{[Mt.tableCellInner]:c}})}return new Se(d)};this.quill.clipboard.addMatcher("td",l),this.quill.clipboard.addMatcher("th",l)}showTableTools(t,e){t&&(this.table=t,this.tableSelection=new Me(this,t,e,this.options.selection||{}),this.options.showAlign&&(this.tableAlign=new le(this,t,e)),this.options.scrollbar&&(this.tableScrollbar=new Ie(this,t,e)),this.options.resizerSetOuter&&(this.tableResize=new xe(this,t,e,this.options.resizeBox||{})))}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.table=void 0,this.options.resizerSetOuter&&(this.tableResize&&this.tableResize.destroy(),this.tableResize=void 0)}async buildCustomSelect(t){if(!this.picker)return;const e=document.createElement("div");e.classList.add("ql-custom-select"),this.selector=t&&at(t)?await t(this):((t={})=>{const e=document.createElement("div");e.classList.add("select-box");const o=document.createElement("div");o.classList.add("select-box__block");for(let e=0;e<(t.row||8);e++)for(let s=0;s<(t.col||8);s++){const t=document.createElement("div");t.classList.add("select-box__item"),t.dataset.row=String(e+1),t.dataset.col=String(s+1),o.appendChild(t)}const s=()=>{const{row:t,col:s}=e.dataset;for(const t of Array.from(o.querySelectorAll(".active")))t.classList.remove("active");if(!t||!s)return;const i=Array.from(o.children);for(let e=0;e<i.length;e++){const{row:o,col:l}=i[e].dataset;if(o>t&&l>s)return;o<=t&&l<=s?i[e].classList.add("active"):i[e].classList.remove("active")}};if(o.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:o,col:i}=t.target.dataset;o&&i&&(e.dataset.row=o,e.dataset.col=i,s())})),o.addEventListener("mouseleave",(()=>{e.removeAttribute("data-row"),e.removeAttribute("data-col"),s()})),o.addEventListener("click",(()=>{const{row:o,col:s}=e.dataset;o&&s&&t.onSelect&&t.onSelect(Number(o),Number(s))})),e.appendChild(o),t.customBtn){const o=t.texts||{},s=document.createElement("div");s.classList.add("select-box__custom"),s.textContent=o.customBtnText||"自定义行列数",s.addEventListener("click",(async()=>{const e=await Ct(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),e.appendChild(s)}return e})({onSelect:(t,e)=>{this.insertTable(t,e),this.picker&&this.picker.close()},customBtn:this.options.customBtn,texts:this.options.texts}),e.appendChild(this.selector),this.picker.options.appendChild(e)}handleInViewport=()=>{if(!this.selector||!this.picker)return;if(this.selector.getBoundingClientRect().right>=window.innerWidth){const t=this.picker.label.getBoundingClientRect();Object.assign(this.picker.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(this.picker.options.style,{transform:void 0})};insertTable(e,o){if(e>=30||o>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus(),this.range=this.quill.getSelection();const s=this.range;if(null==s)return;const[i]=this.quill.getLeaf(s.index);if(!i)return;if(ke(i))throw new Error(`Not supported ${i.statics.blotName} insert into table.`);const l=getComputedStyle(this.quill.root),n=Number.parseInt(l.paddingLeft),r=Number.parseInt(l.paddingRight),a=Number.parseInt(l.width)-n-r,c=dt(),d=new Array(o).fill(0).map((()=>dt())),h=this.options.full?`${Math.max(1/o*100,Lt.colMinWidthPre)}%`:`${Math.max(Math.floor(a/o),Lt.colMinWidthPx)}px`,u=[{retain:s.index},{insert:"\n"}];for(let t=0;t<o;t++)u.push({insert:{[Mt.tableCol]:{width:h,tableId:c,colId:d[t],full:this.options.full}}});for(let t=0;t<e;t++){const t=dt();for(let e=0;e<o;e++)u.push({insert:"\n",attributes:{[Mt.tableCellInner]:{tableId:c,rowId:t,colId:d[e],rowspan:1,colspan:1}}})}this.quill.updateContents(new Se(u),t.sources.USER),this.quill.setSelection(s.index+o+o*e+1,t.sources.SILENT),this.quill.focus()}fixUnusuaDeletelTable(t){const e=t.getRows(),o=t.getColIds();if(0===e.length)return t.remove();if(0===o.length)return;const s=new Array(e.length).fill(0).map((()=>new Array(o.length).fill(!1))),i=t.tableId;for(const[t,l]of e.entries()){let n=0,r=0;const a=s[t],c=l.descendants(Jt);for(;r<o.length;){if(a[r]){r+=1;continue}const d=c[n];if(d&&d.colId===o[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:o,rowspan:i}=d;if(o>1)for(let t=1;t<o;t++)a[r+t]=!0;if(i>1)for(let e=t+1;e<t+i;e++)for(let t=0;t<o;t++)s[e][r+t]=!0;n+=1}else l.insertBefore(Ee(this.quill.scroll,{tableId:i,colId:o[r],rowId:l.rowId}),d);r+=1}if(n<c.length)for(let t=n;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(oe))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)))}))}setCellAttrs(t,e,o){if(0!==t.length)for(const s of t)s.setFormatValue(e,o)}deleteTable(){if(!this.tableSelection||0===this.tableSelection.selectedTds.length)return;const t=ut(this.tableSelection.selectedTds[0],Mt.tableMain);t&&t.remove(),this.hideTableTools()}appendRow(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const o=e[t?e.length-1:0],[s,i,l]=pt(o,[Mt.tableMain,Mt.tableBody,Mt.tableRow]),n=s.getRows().indexOf(l)+(t?o.rowspan:0);i.insertRow(n)}appendCol(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const[o]=e.reduce(((e,o)=>{const s=o.getColumnIndex();return(!t&&s<=e[1]||t&&s>=e[1])&&(e=[o,s]),e}),[e[0],e[0].getColumnIndex()]),s=o.getColumnIndex()+(t?o.colspan:0),i=ut(o,Mt.tableMain),l=i.tableId,n=dt(),[r]=i.descendants(se);r&&r.insertColByIndex(s,{tableId:l,colId:n,width:i.full?"6%":"160px",full:i.full});const a=i.getRows(),c=[];let d=0;for(const t of Object.values(a)){const e=c.shift()||0;if(d>0){d-=1;continue}const o=t.insertCell(s-e,{tableId:l,rowId:t.rowId,colId:n,rowspan:1,colspan:1});o.skipRowNum&&(d+=o.skipRowNum);for(const[t,e]of o.entries())c[t]=(c[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),o=t.getCols(),s=o.reduce(((t,e)=>(t[e.colId]=0,t)),{}),i=[...e].reverse(),l=[];for(const[t,o]of i.entries()){const i=e.length-t-1;o.children.length<=0?l.push(i):o.foreachCellInner((t=>{const e=l.reduce(((e,o)=>t.rowspan+i>o?e+1:e),0);t.rowspan-=e,s[t.colId]+=1}))}let n=0;for(const t of Object.values(s))if(0===t){const t=[];let o=0;for(const s of Object.values(e)){const e=t.shift()||0;let i=[];o>0?(i=s.getCellByColumIndex(n-e)[2],o-=1):(i=s.removeCell(n-e),i.skipRowNum&&(o+=i.skipRowNum));for(const[e,o]of i.entries())t[e]=(t[e]||0)+o}}else n+=1;for(const t of o)0===s[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=ut(t[0],Mt.tableMain),o=e.getRows();let s=o.length,i=-1;for(const e of t){const t=ut(e,Mt.tableRow),l=o.indexOf(t);l<s&&(s=l),l+e.rowspan>i&&(i=l+e.rowspan)}const l={};for(let t=s;t<Math.min(o.length,i);t++){o[t].foreachCellInner((e=>{e.rowspan+t>i&&(l[e.colId]={rowspan:e.rowspan+t-i,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(o[i]){const t=o[i],s=e.tableId;for(const[e,{colIndex:o,colspan:i,rowspan:n}]of Object.entries(l))t.insertCell(o,{tableId:s,rowId:t.rowId,colId:e,colspan:i,rowspan:n})}this.fixTableByRemove(e)}removeCol(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=t[0],o=ut(e,Mt.tableMain),s={};for(const e of t)s[e.rowId]||(s[e.rowId]=0),s[e.rowId]+=e.colspan;const i=Math.max(...Object.values(s)),l=e.getColumnIndex(),n=o.descendants(Gt);for(let t=0;t<i;t++){const t=[];let e=0;for(const o of Object.values(n)){const s=t.shift()||0;if(e>0){e-=1;continue}const i=o.removeCell(l-s);i.skipRowNum&&(e+=i.skipRowNum);for(const[e,o]of i.entries())t[e]=(t[e]||0)+o}}const[r]=o.descendants(se);if(r)for(let t=0;t<i;t++)r.removeColByIndex(l);this.fixTableByRemove(o)}mergeCells(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=1)return;const e=t.reduce(((t,e,o)=>{const s=e.colId;t[0][s]||(t[0][s]=0),t[0][s]+=e.rowspan;const i=e.rowId;return t[1][i]||(t[1][i]=0),t[1][i]+=e.colspan,0!==o&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),o=Math.max(...Object.values(e[0])),s=Math.max(...Object.values(e[1])),i=e[2];i.colspan=s,i.rowspan=o;const l=ut(i,Mt.tableMain);this.fixTableByRemove(l)}splitCell(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(1!==t.length)return;const e=t[0];if(1===e.colspan&&1===e.rowspan)return;const[o,s]=pt(e,[Mt.tableMain,Mt.tableRow]),i=o.tableId,l=e.getColumnIndex(),n=o.getColIds().slice(l,l+e.colspan).reverse();let r=s,a=e.rowspan;for(e.colspan=1,e.rowspan=1;r&&a>0;){for(const t of n)r===s&&t===e.colId||r.insertCell(l+(r===s?1:0),{tableId:i,rowId:r.rowId,colId:t,rowspan:1,colspan:1});a-=1,r=r.next}}}const qe=t=>{Object.assign(Mt,t.blotName||{}),Object.assign(Lt,t.tableUpSize||{}),Object.assign(Nt,t.tableUpEvent||{}),ze.toolName=Mt.tableWrapper,kt.blotName=Mt.container,ie.blotName=Mt.tableWrapper,oe.blotName=Mt.tableMain,se.blotName=Mt.tableColgroup,ee.blotName=Mt.tableCol,Qt.blotName=Mt.tableBody,Gt.blotName=Mt.tableRow,Jt.blotName=Mt.tableCell,Zt.blotName=Mt.tableCellInner};export{Ot as BlockOverride,Ht as BlockquoteOverride,Wt as CodeBlockOverride,kt as ContainerFormat,Dt as HeaderOverride,Ft as ListItemOverride,Xt as ScrollOverride,ye as Scrollbar,le as TableAlign,Qt as TableBodyFormat,Jt as TableCellFormat,Zt as TableCellInnerFormat,ee as TableColFormat,se as TableColgroupFormat,oe as TableMainFormat,me as TableMenuCommon,fe as TableMenuContextmenu,ge as TableMenuSelect,xe as TableResizeBox,ve as TableResizeCommon,Ce as TableResizeLine,Gt as TableRowFormat,Me as TableSelection,ze as TableUp,Ie as TableVitrualScroll,ie as TableWrapperFormat,Kt as allowAttrs,Mt as blotName,ze as default,ut as findParentBlot,pt as findParentBlots,Ne as getRelativeRect,Le as isRectanglesIntersect,we as isTableAlignRight,dt as randomId,Be as tableCantInsert,Nt as tableUpEvent,Lt as tableUpSize,qe as updateTableConstants};
1
+ import t from"quill";const e=Math.min,o=Math.max,s=Math.round,l=Math.floor,i=t=>({x:t,y:t}),n={left:"right",right:"left",bottom:"top",top:"bottom"},r={start:"end",end:"start"};function a(t,s,l){return o(t,e(s,l))}function c(t,e){return"function"==typeof t?t(e):t}function d(t){return t.split("-")[0]}function h(t){return t.split("-")[1]}function u(t){return"x"===t?"y":"x"}function p(t){return"y"===t?"height":"width"}function b(t){return["top","bottom"].includes(d(t))?"y":"x"}function m(t){return u(b(t))}function f(t){return t.replace(/start|end/g,(t=>r[t]))}function g(t){return t.replace(/left|right|bottom|top/g,(t=>n[t]))}function w(t){const{x:e,y:o,width:s,height:l}=t;return{width:s,height:l,top:o,left:e,right:e+s,bottom:o+l,x:e,y:o}}function v(t,e,o){let{reference:s,floating:l}=t;const i=b(e),n=m(e),r=p(n),a=d(e),c="y"===i,u=s.x+s.width/2-l.width/2,f=s.y+s.height/2-l.height/2,g=s[r]/2-l[r]/2;let w;switch(a){case"top":w={x:u,y:s.y-l.height};break;case"bottom":w={x:u,y:s.y+s.height};break;case"right":w={x:s.x+s.width,y:f};break;case"left":w={x:s.x-l.width,y:f};break;default:w={x:s.x,y:s.y}}switch(h(e)){case"start":w[n]-=g*(o&&c?-1:1);break;case"end":w[n]+=g*(o&&c?-1:1)}return w}async function x(t,e){var o;void 0===e&&(e={});const{x:s,y:l,platform:i,rects:n,elements:r,strategy:a}=t,{boundary:d="clippingAncestors",rootBoundary:h="viewport",elementContext:u="floating",altBoundary:p=!1,padding:b=0}=c(e,t),m=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}}(b),f=r[p?"floating"===u?"reference":"floating":u],g=w(await i.getClippingRect({element:null==(o=await(null==i.isElement?void 0:i.isElement(f)))||o?f:f.contextElement||await(null==i.getDocumentElement?void 0:i.getDocumentElement(r.floating)),boundary:d,rootBoundary:h,strategy:a})),v="floating"===u?{x:s,y:l,width:n.floating.width,height:n.floating.height}:n.reference,x=await(null==i.getOffsetParent?void 0:i.getOffsetParent(r.floating)),C=await(null==i.isElement?void 0:i.isElement(x))&&await(null==i.getScale?void 0:i.getScale(x))||{x:1,y:1},y=w(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:r,rect:v,offsetParent:x,strategy:a}):v);return{top:(g.top-y.top+m.top)/C.y,bottom:(y.bottom-g.bottom+m.bottom)/C.y,left:(g.left-y.left+m.left)/C.x,right:(y.right-g.right+m.right)/C.x}}function C(){return"undefined"!=typeof window}function y(t){return L(t)?(t.nodeName||"").toLowerCase():"#document"}function I(t){var e;return(null==t||null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function M(t){var e;return null==(e=(L(t)?t.ownerDocument:t.document)||window.document)?void 0:e.documentElement}function L(t){return!!C()&&(t instanceof Node||t instanceof I(t).Node)}function N(t){return!!C()&&(t instanceof Element||t instanceof I(t).Element)}function S(t){return!!C()&&(t instanceof HTMLElement||t instanceof I(t).HTMLElement)}function T(t){return!(!C()||"undefined"==typeof ShadowRoot)&&(t instanceof ShadowRoot||t instanceof I(t).ShadowRoot)}function R(t){const{overflow:e,overflowX:o,overflowY:s,display:l}=O(t);return/auto|scroll|overlay|hidden|clip/.test(e+s+o)&&!["inline","contents"].includes(l)}function E(t){return["table","td","th"].includes(y(t))}function B(t){return[":popover-open",":modal"].some((e=>{try{return t.matches(e)}catch(t){return!1}}))}function k(t){const e=z(),o=N(t)?O(t):t;return"none"!==o.transform||"none"!==o.perspective||!!o.containerType&&"normal"!==o.containerType||!e&&!!o.backdropFilter&&"none"!==o.backdropFilter||!e&&!!o.filter&&"none"!==o.filter||["transform","perspective","filter"].some((t=>(o.willChange||"").includes(t)))||["paint","layout","strict","content"].some((t=>(o.contain||"").includes(t)))}function z(){return!("undefined"==typeof CSS||!CSS.supports)&&CSS.supports("-webkit-backdrop-filter","none")}function q(t){return["html","body","#document"].includes(y(t))}function O(t){return I(t).getComputedStyle(t)}function A(t){return N(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function H(t){if("html"===y(t))return t;const e=t.assignedSlot||t.parentNode||T(t)&&t.host||M(t);return T(e)?e.host:e}function $(t){const e=H(t);return q(e)?t.ownerDocument?t.ownerDocument.body:t.body:S(e)&&R(e)?e:$(e)}function W(t,e,o){var s;void 0===e&&(e=[]),void 0===o&&(o=!0);const l=$(t),i=l===(null==(s=t.ownerDocument)?void 0:s.body),n=I(l);if(i){const t=j(n);return e.concat(n,n.visualViewport||[],R(l)?l:[],t&&o?W(t):[])}return e.concat(l,W(l,[],o))}function j(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function D(t){const e=O(t);let o=parseFloat(e.width)||0,l=parseFloat(e.height)||0;const i=S(t),n=i?t.offsetWidth:o,r=i?t.offsetHeight:l,a=s(o)!==n||s(l)!==r;return a&&(o=n,l=r),{width:o,height:l,$:a}}function V(t){return N(t)?t:t.contextElement}function F(t){const e=V(t);if(!S(e))return i(1);const o=e.getBoundingClientRect(),{width:l,height:n,$:r}=D(e);let a=(r?s(o.width):o.width)/l,c=(r?s(o.height):o.height)/n;return a&&Number.isFinite(a)||(a=1),c&&Number.isFinite(c)||(c=1),{x:a,y:c}}const _=i(0);function P(t){const e=I(t);return z()&&e.visualViewport?{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}:_}function X(t,e,o,s){void 0===e&&(e=!1),void 0===o&&(o=!1);const l=t.getBoundingClientRect(),n=V(t);let r=i(1);e&&(s?N(s)&&(r=F(s)):r=F(t));const a=function(t,e,o){return void 0===e&&(e=!1),!(!o||e&&o!==I(t))&&e}(n,o,s)?P(n):i(0);let c=(l.left+a.x)/r.x,d=(l.top+a.y)/r.y,h=l.width/r.x,u=l.height/r.y;if(n){const t=I(n),e=s&&N(s)?I(s):s;let o=t,l=j(o);for(;l&&s&&e!==o;){const t=F(l),e=l.getBoundingClientRect(),s=O(l),i=e.left+(l.clientLeft+parseFloat(s.paddingLeft))*t.x,n=e.top+(l.clientTop+parseFloat(s.paddingTop))*t.y;c*=t.x,d*=t.y,h*=t.x,u*=t.y,c+=i,d+=n,o=I(l),l=j(o)}}return w({width:h,height:u,x:c,y:d})}function U(t,e){const o=A(t).scrollLeft;return e?e.left+o:X(M(t)).left+o}function Y(t,e,o){void 0===o&&(o=!1);const s=t.getBoundingClientRect();return{x:s.left+e.scrollLeft-(o?0:U(t,s)),y:s.top+e.scrollTop}}function K(t,e,s){let l;if("viewport"===e)l=function(t,e){const o=I(t),s=M(t),l=o.visualViewport;let i=s.clientWidth,n=s.clientHeight,r=0,a=0;if(l){i=l.width,n=l.height;const t=z();(!t||t&&"fixed"===e)&&(r=l.offsetLeft,a=l.offsetTop)}return{width:i,height:n,x:r,y:a}}(t,s);else if("document"===e)l=function(t){const e=M(t),s=A(t),l=t.ownerDocument.body,i=o(e.scrollWidth,e.clientWidth,l.scrollWidth,l.clientWidth),n=o(e.scrollHeight,e.clientHeight,l.scrollHeight,l.clientHeight);let r=-s.scrollLeft+U(t);const a=-s.scrollTop;return"rtl"===O(l).direction&&(r+=o(e.clientWidth,l.clientWidth)-i),{width:i,height:n,x:r,y:a}}(M(t));else if(N(e))l=function(t,e){const o=X(t,!0,"fixed"===e),s=o.top+t.clientTop,l=o.left+t.clientLeft,n=S(t)?F(t):i(1);return{width:t.clientWidth*n.x,height:t.clientHeight*n.y,x:l*n.x,y:s*n.y}}(e,s);else{const o=P(t);l={x:e.x-o.x,y:e.y-o.y,width:e.width,height:e.height}}return w(l)}function Z(t,e){const o=H(t);return!(o===e||!N(o)||q(o))&&("fixed"===O(o).position||Z(o,e))}function G(t,e,o){const s=S(e),l=M(e),n="fixed"===o,r=X(t,!0,n,e);let a={scrollLeft:0,scrollTop:0};const c=i(0);if(s||!s&&!n)if(("body"!==y(e)||R(l))&&(a=A(e)),s){const t=X(e,!0,n,e);c.x=t.x+e.clientLeft,c.y=t.y+e.clientTop}else l&&(c.x=U(l));const d=!l||s||n?i(0):Y(l,a);return{x:r.left+a.scrollLeft-c.x-d.x,y:r.top+a.scrollTop-c.y-d.y,width:r.width,height:r.height}}function Q(t){return"static"===O(t).position}function J(t,e){if(!S(t)||"fixed"===O(t).position)return null;if(e)return e(t);let o=t.offsetParent;return M(t)===o&&(o=o.ownerDocument.body),o}function tt(t,e){const o=I(t);if(B(t))return o;if(!S(t)){let e=H(t);for(;e&&!q(e);){if(N(e)&&!Q(e))return e;e=H(e)}return o}let s=J(t,e);for(;s&&E(s)&&Q(s);)s=J(s,e);return s&&q(s)&&Q(s)&&!k(s)?o:s||function(t){let e=H(t);for(;S(e)&&!q(e);){if(k(e))return e;if(B(e))return null;e=H(e)}return null}(t)||o}const et={convertOffsetParentRelativeRectToViewportRelativeRect:function(t){let{elements:e,rect:o,offsetParent:s,strategy:l}=t;const n="fixed"===l,r=M(s),a=!!e&&B(e.floating);if(s===r||a&&n)return o;let c={scrollLeft:0,scrollTop:0},d=i(1);const h=i(0),u=S(s);if((u||!u&&!n)&&(("body"!==y(s)||R(r))&&(c=A(s)),S(s))){const t=X(s);d=F(s),h.x=t.x+s.clientLeft,h.y=t.y+s.clientTop}const p=!r||u||n?i(0):Y(r,c,!0);return{width:o.width*d.x,height:o.height*d.y,x:o.x*d.x-c.scrollLeft*d.x+h.x+p.x,y:o.y*d.y-c.scrollTop*d.y+h.y+p.y}},getDocumentElement:M,getClippingRect:function(t){let{element:s,boundary:l,rootBoundary:i,strategy:n}=t;const r=[..."clippingAncestors"===l?B(s)?[]:function(t,e){const o=e.get(t);if(o)return o;let s=W(t,[],!1).filter((t=>N(t)&&"body"!==y(t))),l=null;const i="fixed"===O(t).position;let n=i?H(t):t;for(;N(n)&&!q(n);){const e=O(n),o=k(n);o||"fixed"!==e.position||(l=null),(i?!o&&!l:!o&&"static"===e.position&&l&&["absolute","fixed"].includes(l.position)||R(n)&&!o&&Z(t,n))?s=s.filter((t=>t!==n)):l=e,n=H(n)}return e.set(t,s),s}(s,this._c):[].concat(l),i],a=r[0],c=r.reduce(((t,l)=>{const i=K(s,l,n);return t.top=o(i.top,t.top),t.right=e(i.right,t.right),t.bottom=e(i.bottom,t.bottom),t.left=o(i.left,t.left),t}),K(s,a,n));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}},getOffsetParent:tt,getElementRects:async function(t){const e=this.getOffsetParent||tt,o=this.getDimensions,s=await o(t.floating);return{reference:G(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:s.width,height:s.height}}},getClientRects:function(t){return Array.from(t.getClientRects())},getDimensions:function(t){const{width:e,height:o}=D(t);return{width:e,height:o}},getScale:F,isElement:N,isRTL:function(t){return"rtl"===O(t).direction}};function ot(t,s,i,n){void 0===n&&(n={});const{ancestorScroll:r=!0,ancestorResize:a=!0,elementResize:c="function"==typeof ResizeObserver,layoutShift:d="function"==typeof IntersectionObserver,animationFrame:h=!1}=n,u=V(t),p=r||a?[...u?W(u):[],...W(s)]:[];p.forEach((t=>{r&&t.addEventListener("scroll",i,{passive:!0}),a&&t.addEventListener("resize",i)}));const b=u&&d?function(t,s){let i,n=null;const r=M(t);function a(){var t;clearTimeout(i),null==(t=n)||t.disconnect(),n=null}return function c(d,h){void 0===d&&(d=!1),void 0===h&&(h=1),a();const{left:u,top:p,width:b,height:m}=t.getBoundingClientRect();if(d||s(),!b||!m)return;const f={rootMargin:-l(p)+"px "+-l(r.clientWidth-(u+b))+"px "+-l(r.clientHeight-(p+m))+"px "+-l(u)+"px",threshold:o(0,e(1,h))||1};let g=!0;function w(t){const e=t[0].intersectionRatio;if(e!==h){if(!g)return c();e?c(!1,e):i=setTimeout((()=>{c(!1,1e-7)}),1e3)}g=!1}try{n=new IntersectionObserver(w,{...f,root:r.ownerDocument})}catch(t){n=new IntersectionObserver(w,f)}n.observe(t)}(!0),a}(u,i):null;let m,f=-1,g=null;c&&(g=new ResizeObserver((t=>{let[e]=t;e&&e.target===u&&g&&(g.unobserve(s),cancelAnimationFrame(f),f=requestAnimationFrame((()=>{var t;null==(t=g)||t.observe(s)}))),i()})),u&&!h&&g.observe(u),g.observe(s));let w=h?X(t):null;return h&&function e(){const o=X(t);!w||o.x===w.x&&o.y===w.y&&o.width===w.width&&o.height===w.height||i();w=o,m=requestAnimationFrame(e)}(),i(),()=>{var t;p.forEach((t=>{r&&t.removeEventListener("scroll",i),a&&t.removeEventListener("resize",i)})),null==b||b(),null==(t=g)||t.disconnect(),g=null,h&&cancelAnimationFrame(m)}}const st=function(t){return void 0===t&&(t=0),{name:"offset",options:t,async fn(e){var o,s;const{x:l,y:i,placement:n,middlewareData:r}=e,a=await async function(t,e){const{placement:o,platform:s,elements:l}=t,i=await(null==s.isRTL?void 0:s.isRTL(l.floating)),n=d(o),r=h(o),a="y"===b(o),u=["left","top"].includes(n)?-1:1,p=i&&a?-1:1,m=c(e,t);let{mainAxis:f,crossAxis:g,alignmentAxis:w}="number"==typeof m?{mainAxis:m,crossAxis:0,alignmentAxis:null}:{mainAxis:m.mainAxis||0,crossAxis:m.crossAxis||0,alignmentAxis:m.alignmentAxis};return r&&"number"==typeof w&&(g="end"===r?-1*w:w),a?{x:g*p,y:f*u}:{x:f*u,y:g*p}}(e,t);return n===(null==(o=r.offset)?void 0:o.placement)&&null!=(s=r.arrow)&&s.alignmentOffset?{}:{x:l+a.x,y:i+a.y,data:{...a,placement:n}}}}},lt=function(t){return void 0===t&&(t={}),{name:"shift",options:t,async fn(e){const{x:o,y:s,placement:l}=e,{mainAxis:i=!0,crossAxis:n=!1,limiter:r={fn:t=>{let{x:e,y:o}=t;return{x:e,y:o}}},...h}=c(t,e),p={x:o,y:s},m=await x(e,h),f=b(d(l)),g=u(f);let w=p[g],v=p[f];if(i){const t="y"===g?"bottom":"right";w=a(w+m["y"===g?"top":"left"],w,w-m[t])}if(n){const t="y"===f?"bottom":"right";v=a(v+m["y"===f?"top":"left"],v,v-m[t])}const C=r.fn({...e,[g]:w,[f]:v});return{...C,data:{x:C.x-o,y:C.y-s,enabled:{[g]:i,[f]:n}}}}}},it=function(t){return void 0===t&&(t={}),{name:"flip",options:t,async fn(e){var o,s;const{placement:l,middlewareData:i,rects:n,initialPlacement:r,platform:a,elements:u}=e,{mainAxis:w=!0,crossAxis:v=!0,fallbackPlacements:C,fallbackStrategy:y="bestFit",fallbackAxisSideDirection:I="none",flipAlignment:M=!0,...L}=c(t,e);if(null!=(o=i.arrow)&&o.alignmentOffset)return{};const N=d(l),S=b(r),T=d(r)===r,R=await(null==a.isRTL?void 0:a.isRTL(u.floating)),E=C||(T||!M?[g(r)]:function(t){const e=g(t);return[f(t),e,f(e)]}(r)),B="none"!==I;!C&&B&&E.push(...function(t,e,o,s){const l=h(t);let i=function(t,e,o){const s=["left","right"],l=["right","left"],i=["top","bottom"],n=["bottom","top"];switch(t){case"top":case"bottom":return o?e?l:s:e?s:l;case"left":case"right":return e?i:n;default:return[]}}(d(t),"start"===o,s);return l&&(i=i.map((t=>t+"-"+l)),e&&(i=i.concat(i.map(f)))),i}(r,M,I,R));const k=[r,...E],z=await x(e,L),q=[];let O=(null==(s=i.flip)?void 0:s.overflows)||[];if(w&&q.push(z[N]),v){const t=function(t,e,o){void 0===o&&(o=!1);const s=h(t),l=m(t),i=p(l);let n="x"===l?s===(o?"end":"start")?"right":"left":"start"===s?"bottom":"top";return e.reference[i]>e.floating[i]&&(n=g(n)),[n,g(n)]}(l,n,R);q.push(z[t[0]],z[t[1]])}if(O=[...O,{placement:l,overflows:q}],!q.every((t=>t<=0))){var A,H;const t=((null==(A=i.flip)?void 0:A.index)||0)+1,e=k[t];if(e)return{data:{index:t,overflows:O},reset:{placement:e}};let o=null==(H=O.filter((t=>t.overflows[0]<=0)).sort(((t,e)=>t.overflows[1]-e.overflows[1]))[0])?void 0:H.placement;if(!o)switch(y){case"bestFit":{var $;const t=null==($=O.filter((t=>{if(B){const e=b(t.placement);return e===S||"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:$[0];t&&(o=t);break}case"initialPlacement":o=r}if(l!==o)return{reset:{placement:o}}}return{}}}},nt=function(t){return void 0===t&&(t={}),{options:t,fn(e){const{x:o,y:s,placement:l,rects:i,middlewareData:n}=e,{offset:r=0,mainAxis:a=!0,crossAxis:h=!0}=c(t,e),p={x:o,y:s},m=b(l),f=u(m);let g=p[f],w=p[m];const v=c(r,e),x="number"==typeof v?{mainAxis:v,crossAxis:0}:{mainAxis:0,crossAxis:0,...v};if(a){const t="y"===f?"height":"width",e=i.reference[f]-i.floating[t]+x.mainAxis,o=i.reference[f]+i.reference[t]-x.mainAxis;g<e?g=e:g>o&&(g=o)}if(h){var C,y;const t="y"===f?"width":"height",e=["top","left"].includes(d(l)),o=i.reference[m]-i.floating[t]+(e&&(null==(C=n.offset)?void 0:C[m])||0)+(e?0:x.crossAxis),s=i.reference[m]+i.reference[t]+(e?0:(null==(y=n.offset)?void 0:y[m])||0)-(e?x.crossAxis:0);w<o?w=o:w>s&&(w=s)}return{[f]:g,[m]:w}}}},rt=(t,e,o)=>{const s=new Map,l={platform:et,...o},i={...l.platform,_c:s};return(async(t,e,o)=>{const{placement:s="bottom",strategy:l="absolute",middleware:i=[],platform:n}=o,r=i.filter(Boolean),a=await(null==n.isRTL?void 0:n.isRTL(e));let c=await n.getElementRects({reference:t,floating:e,strategy:l}),{x:d,y:h}=v(c,s,a),u=s,p={},b=0;for(let o=0;o<r.length;o++){const{name:i,fn:m}=r[o],{x:f,y:g,data:w,reset:x}=await m({x:d,y:h,initialPlacement:s,placement:u,strategy:l,middlewareData:p,rects:c,platform:n,elements:{reference:t,floating:e}});d=null!=f?f:d,h=null!=g?g:h,p={...p,[i]:{...p[i],...w}},x&&b<=50&&(b++,"object"==typeof x&&(x.placement&&(u=x.placement),x.rects&&(c=!0===x.rects?await n.getElementRects({reference:t,floating:e,strategy:l}):x.rects),({x:d,y:h}=v(c,u,a))),o=-1)}return{x:d,y:h,placement:u,strategy:l,middlewareData:p}})(t,e,{...l,platform:i})},at=()=>Math.random().toString(36).slice(2),ct=(t,e)=>{let o;return function(...s){o&&clearTimeout(o),o=setTimeout((()=>{t.apply(this,s)}),e)}};function dt(t,e){let o=t.parent;for(;o&&o.statics.blotName!==e&&o!==t.scroll;)o=o.parent;if(o===t.scroll)throw new Error(`${t.statics.blotName} must be a child of ${e}`);return o}function ht(t,e){const o=new Array(e.length),s=new Map(e.map(((t,e)=>[t,e])));let l=t.parent;for(;l&&l!==t.scroll&&0!==s.size;){if(s.has(l.statics.blotName)){o[s.get(l.statics.blotName)]=l,s.delete(l.statics.blotName)}l=l.parent}if(s.size>0)throw new Error(`${t.statics.blotName} must be a child of ${Array.from(s.keys()).join(", ")}`);return o}function ut(t,e){for(const o of Object.getOwnPropertyNames(e))/^constructor$/.test(o)||Object.defineProperty(t,o,Object.getOwnPropertyDescriptor(e,o));return t}function pt(t,e){const o=class extends t{constructor(...t){super(...t)}};for(const t of e)ut(o.prototype,t.prototype);return o}function bt(t,e){t.addEventListener("scroll",e),this.scrollHandler.push([t,e])}function mt(){for(let t=0;t<this.scrollHandler.length;t++){const[e,o]=this.scrollHandler[t];e.removeEventListener("scroll",o)}this.scrollHandler=[]}const ft=(t,e,o,s,l)=>(t.addEventListener("transitionend",o,s),setTimeout((()=>{o()}),e)),gt=(t,e)=>{e.type||(e.type="text"),e.value||(e.value="");const o=document.createElement("div");if(o.classList.add("input__item"),t){const e=document.createElement("span");e.classList.add("input__label"),e.textContent=t,o.appendChild(e)}const s=document.createElement("div");s.classList.add("input__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))})),s.appendChild(l),o.appendChild(s),l.addEventListener("focus",(()=>{s.classList.add("focus")})),l.addEventListener("blur",(()=>{s.classList.remove("focus")}));return{item:o,input:l,errorTip:t=>{let e;s.classList.contains("error")?e=s.querySelector(".input__error-tip"):(e=document.createElement("span"),e.classList.add("input__error-tip"),s.appendChild(e)),e.textContent=t,s.classList.add("error");return{removeError:()=>{s.classList.remove("error"),e.remove()}}}}};let wt=8e3;const vt=async(t={})=>{const e=document.createElement("div");e.classList.add("table-creator");const o=document.createElement("div");o.classList.add("table-creator__input");const{item:s,input:l,errorTip:i}=gt(t.rowText||"行数",{type:"number",value:String(t.row||""),max:99}),{item:n,input:r,errorTip:a}=gt(t.colText||"列数",{type:"number",value:String(t.col||""),max:99});o.appendChild(s),o.appendChild(n),e.appendChild(o);const c=document.createElement("div");c.classList.add("table-creator__control");const d=document.createElement("button");d.classList.add("table-creator__btn","confirm"),d.textContent=t.confirmText||"Confirm";const h=document.createElement("button");h.classList.add("table-creator__btn","cancel"),h.textContent=t.cancelText||"Cancel",c.appendChild(d),c.appendChild(h),e.appendChild(c);const u=(e=Number(l.value),o=Number(r.value))=>{if(Number.isNaN(e)||e<=0)i(t.notPositiveNumberError||"请输入正整数");else{if(!(Number.isNaN(o)||o<=0))return{row:e,col:o};a(t.notPositiveNumberError||"请输入正整数")}},p=t=>{"Escape"===t.key&&(close(),document.removeEventListener("keydown",p))};return new Promise(((t,o)=>{const{close:s}=(({child:t,target:e=document.body,beforeClose:o=()=>{}}={})=>{const s=e,l=document.createElement("div");l.classList.add("dialog"),l.style.zIndex=String(wt);const i=document.createElement("div");if(i.classList.add("dialog__overlay"),l.appendChild(i),t){const e=document.createElement("div");e.classList.add("dialog__content"),e.appendChild(t),i.appendChild(e),e.addEventListener("click",(t=>{t.stopPropagation()}))}const n=getComputedStyle(s).overflow;s.style.overflow="hidden",s.appendChild(l);const r=()=>{o(),l.remove(),s.style.overflow=n};return l.addEventListener("click",r),wt+=1,{dialog:l,close:r}})({child:e,beforeClose:o});l.focus();for(const e of[l,r])e.addEventListener("keydown",(e=>{if("Enter"===e.key){const e=u();e&&(t(e),s())}}));d.addEventListener("click",(async()=>{const e=u();e&&(t(e),s())})),document.addEventListener("keydown",p),h.addEventListener("click",s)}))};let xt;const Ct=(t,e={})=>{const{msg:o="",delay:s=150,content:l,direction:i="bottom"}=e;if(o||l){xt||(xt=document.createElement("div"),document.body.appendChild(xt));const e=document.createElement("div");let n,r;e.classList.add("tooltip","hidden","transparent"),l?e.appendChild(l):o&&(e.textContent=o);const a=()=>{r&&r(),rt(t,e,{placement:i,middleware:[it(),lt({limiter:nt()}),st(4)]}).then((({x:t,y:o})=>{Object.assign(e.style,{left:`${t}px`,top:`${o}px`})}))},c=()=>{e.classList.add("hidden"),xt.contains(e)&&xt.removeChild(e),r&&r()},d=()=>{n&&clearTimeout(n),n=setTimeout((()=>{xt.appendChild(e),e.removeEventListener("transitionend",c),e.classList.remove("hidden"),r=ot(t,e,a),e.classList.remove("transparent")}),s)},h=()=>{n&&clearTimeout(n),n=setTimeout((()=>{e.classList.add("transparent"),ft(e,150,c,{once:!0})}),s)},u=[t,e];for(const t of u)t.addEventListener("mouseenter",d),t.addEventListener("mouseleave",h);return{destroy:()=>{for(const t of u)t.removeEventListener("mouseenter",d),t.removeEventListener("mouseleave",h);r&&r(),e.remove()}}}return null},yt={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"},It={colMinWidthPre:5,colMinWidthPx:40,rowMinHeightPx:36},Mt={AFTER_TABLE_RESIZE:"after-table-resize"},Lt=[["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)"]],Nt=t=>"function"==typeof t,St=Array.isArray,Tt=t.import("parchment"),Rt=t.import("blots/container"),Et=t.import("blots/block"),Bt=t.import("blots/block/embed");class kt extends Rt{static tagName;static blotName=yt.container;static scope=Tt.Scope.BLOCK_BLOT;static allowedChildren=[Et,Bt,Rt];static requiredContainer;static defaultChild;static create(t){const e=document.createElement(this.tagName);return this.className&&e.classList.add(this.className),e}insertAt(t,e,o){const[s]=this.children.find(t);if(!s){const t=this.scroll.create(this.statics.defaultChild.blotName||"block");this.appendChild(t)}super.insertAt(t,e,o)}optimize(t){if(0===this.children.length)if(null!=this.statics.defaultChild){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}else this.remove();this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove())}}const zt=t.import("parchment"),qt=t.import("blots/block");class Ot extends qt{replaceWith(t,e){const o="string"==typeof t?this.scroll.create(t,e):t;if(o instanceof zt.ParentBlot){if(o.statics.blotName===yt.tableCellInner){const t=this.parent;if(t.statics.blotName===yt.tableCellInner){if(null!=t&&t.insertBefore(o,this.prev?null:this.next),this.parent.statics.blotName===yt.tableCellInner&&this.prev){let t=this;for(;t;){const e=t.next;o.appendChild(t),t=e}}else o.appendChild(this);if(t&&0===t.length()){t.parent.remove();const e=t.parent.parent;e.statics.blotName===yt.tableRow&&0===e.children.length&&e.remove()}}else null!=t&&t.insertBefore(o,this.next),o.appendChild(this);return o}this.moveChildren(o)}return null!=this.parent&&(this.parent.insertBefore(o,this.next||void 0),this.remove()),this.attributes.copy(o),o}format(t,e){if(t!==yt.tableCellInner||this.parent.statics.blotName!==t||e)super.format(t,e);else{const[t,e,o]=ht(this,[yt.tableCell,yt.tableRow,yt.tableWrapper]),s=o.next;let l=e.next,i=t.next;for(o.parent.insertBefore(this,s);i;){const t=i.next;o.parent.insertBefore(i,s),i=t}for(;l;){const t=l.next;o.parent.insertBefore(l,s),l=t}}}}const At=t.import("formats/blockquote");class Ht extends(pt(At,[Ot])){}const $t=t.import("formats/code-block");class Wt extends(pt($t,[Ot])){}const jt=t.import("formats/header");class Dt extends(pt(jt,[Ot])){}const Vt=t.import("formats/list");class Ft extends(pt(Vt,[Ot])){static register(){}}const _t=t.import("parchment"),Pt=t.import("blots/scroll");class Xt extends Pt{createBlock(t,e){let o,s={};for(const[e,l]of Object.entries(t)){null!=this.query(e,_t.Scope.BLOCK&_t.Scope.BLOT)?o=e:s[e]=l}o===yt.tableCellInner&&(s={...t},delete s[o]);const l=this.create(o||this.statics.defaultChild.blotName,o?t[o]:void 0);this.insertBefore(l,e||void 0);const i=l.length();for(const[t,e]of Object.entries(s))l.formatAt(0,i,t,e);return l}}const Ut=t=>{return e=t,!Number.isNaN(e)&&Number(e)>0?t:1;var e},Yt=t.import("blots/block"),Kt=t.import("blots/block/embed"),Zt=["table-id","row-id","col-id","rowspan","colspan","background-color","border-color","height"];class Gt extends kt{static blotName=yt.tableCellInner;static tagName="div";static className="ql-table-cell-inner";static defaultChild=Yt;static create(t){const{tableId:e,rowId:o,colId:s,rowspan:l,colspan:i,backgroundColor:n,borderColor:r,height:a}=t,c=super.create();return c.dataset.tableId=e,c.dataset.rowId=o,c.dataset.colId=s,c.dataset.rowspan=String(Ut(l)),c.dataset.colspan=String(Ut(i)),a&&(c.dataset.height=a),n&&(c.dataset.backgroundColor=n),r&&(c.dataset.borderColor=r),c}static formats(t){const{tableId:e,rowId:o,colId:s,rowspan:l,colspan:i,backgroundColor:n,borderColor:r,height:a}=t.dataset,c={tableId:e,rowId:o,colId:s,rowspan:Number(Ut(l)),colspan:Number(Ut(i))};return a&&(c.height=a),n&&(c.backgroundColor=n),r&&(c.borderColor=r),c}allowDataAttrs=new Set(Zt);setFormatValue(t,e){if(!this.allowDataAttrs.has(t))return;const o=`data-${t}`;e?this.domNode.setAttribute(o,e):this.domNode.removeAttribute(o),this.parent&&this.parent.setFormatValue(t,e);const s=this.descendants(Yt,0);for(const t of s)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)}get backgroundColor(){return this.domNode.dataset.backgroundColor||""}set backgroundColor(t){this.setFormatValue("background-color",t)}get height(){return this.domNode.dataset.height||""}set height(t){this.setFormatValue("height",t)}get borderColor(){return this.domNode.dataset.borderColor||""}getColumnIndex(){return dt(this,yt.tableMain).getColIds().indexOf(this.colId)}formatAt(t,e,o,s){0===this.children.length&&(this.appendChild(this.scroll.create(this.statics.defaultChild.blotName)),e+=1),super.formatAt(t,e,o,s)}formats(){const t=Gt.formats(this.domNode);return{[this.statics.blotName]:t}}checkMerge(){const{colId:t,rowId:e,colspan:o,rowspan:s}=this,l=this.next;return null!==l&&l.statics.blotName===this.statics.blotName&&l.rowId===e&&l.colId===t&&l.colspan===o&&l.rowspan===s}optimize(){const t=this.parent,e=Gt.formats(this.domNode);if(this.prev&&this.prev instanceof Kt){const t=this.scroll.create("block");this.appendChild(this.prev),this.appendChild(t)}if(null!==t&&t.statics.blotName!==yt.tableCell&&(this.wrap(yt.tableCell,e),0===this.children.length)){const t=this.scroll.create(this.statics.defaultChild.blotName);this.appendChild(t)}this.children.length>0&&null!=this.next&&this.checkMerge()&&(this.next.moveChildren(this),this.next.remove()),null!=this.uiNode&&this.uiNode!==this.domNode.firstChild&&this.domNode.insertBefore(this.uiNode,this.domNode.firstChild),0===this.children.length&&this.remove()}insertBefore(t,e){if(t.statics.blotName===this.statics.blotName){const o=t,s=Gt.formats(o.domNode),l=Gt.formats(this.domNode);if(Object.entries(l).every((([t,e])=>e===s[t])))return this.parent.insertBefore(o,this.next);{const[t,i]=ht(this,[yt.tableRow,yt.tableCell]);if(e){const o=e.offset();if(o+1<this.length()){const e=this.scroll.create(yt.tableCellInner,l);this.children.forEachAt(o+1,this.length(),(t=>{e.appendChild(t)})),t.insertBefore(e.wrap(yt.tableCell,l),i.next),0===this.children.length&&(this.remove(),0===this.parent.children.length&&this.parent.remove())}}if(this.rowId!==o.rowId){if(e){const o=e.offset(t);t.split(o)}else if(i.next){const e=i.next.offset(t);t.split(e)}const l=this.scroll.create(yt.tableRow,s),n=this.scroll.create(yt.tableCell,s);return n.appendChild(o),l.appendChild(n),t.parent.insertBefore(l,t.next)}return t.insertBefore(o.wrap(yt.tableCell,s),e?i:i.next)}}super.insertBefore(t,e)}}class Qt extends kt{static blotName=yt.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.height=t}))}insertCell(t,e){const o=[],s=this.children.iterator();let l,i=0;for(;(l=s())&&(i+=l.colspan,!(i>t));)if(1!==l.rowspan)for(let t=0;t<l.rowspan-1;t++)o[t]=(o[t]||0)+l.colspan;if(l&&i-l.colspan<t){l.getCellInner().colspan+=1,1!==l.rowspan&&(o.skipRowNum=l.rowspan-1)}else{const t=this.scroll.create(yt.tableCell,e),o=this.scroll.create(yt.tableCellInner,e),s=this.scroll.create("block");s.appendChild(this.scroll.create("break")),o.appendChild(s),t.appendChild(o),this.insertBefore(t,l)}return o}getCellByColumIndex(t){const e=[];let o=null,s=0;if(t<0)return[o,s,e];const l=this.children.iterator();for(;o=l();){if(s+=o.colspan,1!==o.rowspan)for(let t=0;t<o.rowspan-1;t++)e[t]=(e[t]||0)+o.colspan;if(s>t)break}return[o,s,e]}removeCell(t){if(t<0)return[];const e=this.getCellByColumIndex(t),[o,s]=e,l=e[2];if(!o)return l;if(s-o.colspan<t||o.colspan>1){const[e]=o.descendants(Gt);if(1!==o.colspan&&t===s-o.colspan){const t=dt(this,yt.tableMain).getColIds();e.colId=t[t.indexOf(e.colId)+1]}1!==o.rowspan&&(l.skipRowNum=o.rowspan-1),e.colspan-=1}else o.remove();return l}foreachCellInner(t){const e=this.children.iterator();let o,s=0;for(;o=e();){const[e]=o.descendants(Gt);if(t(e,s++))break}}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.rowId===this.rowId}optimize(t){const e=this.parent,{tableId:o}=this;null!==e&&e.statics.blotName!==yt.tableBody&&this.wrap(yt.tableBody,o),super.optimize(t)}}class Jt extends kt{static blotName=yt.tableBody;static tagName="tbody";static create(t){const e=super.create();return e.dataset.tableId=t,e}get tableId(){return this.domNode.dataset.tableId}insertRow(t){const e=dt(this,yt.tableMain);if(!e)return;const o=e.getColIds(),s=this.descendants(Qt),l=new Set(o);let i=0;for(const e of s){if(i===t)break;e.foreachCellInner((e=>{if(i+e.rowspan>t&&(e.rowspan+=1,l.delete(e.colId),1!==e.colspan)){const t=o.indexOf(e.colId);for(let s=0;s<e.colspan-1;s++)l.delete(o[t+s+1])}})),i+=1}const n=e.tableId,r=at(),a=this.scroll.create(yt.tableRow,{tableId:n,rowId:r});for(const t of l){const e=this.scroll.create("break").wrap("block").wrap(yt.tableCellInner,{tableId:n,rowId:r,colId:t,rowspan:1,colspan:1}).wrap(yt.tableCell,{tableId:n,rowId:r,colId:t,rowspan:1,colspan:1});a.appendChild(e)}this.insertBefore(a,s[t]||null)}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent;if(null!==e&&e.statics.blotName!==yt.tableMain){const{tableId:t}=this;this.wrap(yt.tableMain,{tableId:t})}super.optimize(t)}}class te extends kt{static blotName=yt.tableCell;static tagName="td";static className="ql-table-cell";static create(t){const{tableId:e,rowId:o,colId:s,rowspan:l,colspan:i,backgroundColor:n,borderColor:r,height:a}=t,c=super.create();return c.dataset.tableId=e,c.dataset.rowId=o,c.dataset.colId=s,c.setAttribute("rowspan",String(Ut(l))),c.setAttribute("colspan",String(Ut(i))),a&&(c.style.height=a),n&&(c.style.backgroundColor=n),r&&(c.style.borderColor=r),c}static formats(t){const{tableId:e,rowId:o,colId:s}=t.dataset,l=Number(t.getAttribute("rowspan")),i=Number(t.getAttribute("colspan")),n={tableId:e,rowId:o,colId:s,rowspan:Ut(l),colspan:Ut(i)},{height:r,backgroundColor:a,borderColor:c}=t.style;return r&&(n.height=r),a&&(n.backgroundColor=a),c&&(n.borderColor=c),n}allowDataAttrs=new Set(["table-id","row-id","col-id"]);allowAttrs=new Set(["rowspan","colspan"]);allowStyle=new Set(["background-color","border-color","height"]);setFormatValue(t,e){if(this.allowAttrs.has(t)||this.allowDataAttrs.has(t)){let o=t;this.allowDataAttrs.has(t)&&(o=`data-${t}`),e?this.domNode.setAttribute(o,e):this.domNode.removeAttribute(o)}else this.allowStyle.has(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"))}get backgroundColor(){return this.domNode.dataset.backgroundColor||""}get height(){return this.domNode.style.height}getCellInner(){return this.descendants(Gt)[0]}checkMerge(){const{colId:t,rowId:e,colspan:o,rowspan:s}=this,l=this.next;return null!==l&&l.statics.blotName===this.statics.blotName&&l.rowId===e&&l.colId===t&&l.colspan===o&&l.rowspan===s}optimize(t){const e=this.parent,{tableId:o,rowId:s}=this;null!==e&&e.statics.blotName!==yt.tableRow&&this.wrap(yt.tableRow,{tableId:o,rowId:s}),super.optimize(t)}}const ee=t.import("blots/block/embed");class oe extends ee{scroll;domNode;static blotName=yt.tableCol;static tagName="col";static create(t){const{width:e,tableId:o,colId:s,full:l,align:i}=t,n=super.create();return n.setAttribute("width",`${Number.parseFloat(e)}${l?"%":"px"}`),l&&(n.dataset.full=String(l)),i&&"left"!==i&&(n.dataset.align=i),n.dataset.tableId=o,n.dataset.colId=s,n.setAttribute("contenteditable","false"),n}constructor(t,e){super(t,e),this.scroll=t,this.domNode=e}get width(){const t=this.domNode.getAttribute("width");return Number.parseFloat(t)}set width(t){const e=Number.parseFloat(t);this.domNode.setAttribute("width",`${e}${this.full?"%":"px"}`)}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")}static value(t){const{tableId:e,colId:o}=t.dataset,s=t.getAttribute("width"),l=t.dataset.align,i={tableId:e,colId:o,full:Object.hasOwn(t.dataset,"full")};return s&&(i.width=Number.parseFloat(s)),l&&(i.align=l),i}checkMerge(){const t=this.next,{tableId:e,colId:o}=this;return null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===e&&t.colId===o}optimize(t){const e=this.parent;if(null!=e&&e.statics.blotName!==yt.tableColgroup){const t=oe.value(this.domNode);this.wrap(yt.tableColgroup,t)}dt(this,yt.tableColgroup).align=this.align,super.optimize(t)}insertAt(t,e,o){if(null!=o)return void super.insertAt(t,e,o);const s=e.split("\n"),l=s.pop(),i=s.map((t=>{const e=this.scroll.create("block");return e.insertAt(0,t),e})),n=this.split(t),[r,a]=ht(this,[yt.tableColgroup,yt.tableMain]),c=r.next;if(n){const t=n.offset(r);r.split(t)}let d=a.parent.parent,h=a.parent.next;if(c){const t=c.descendants(Gt);if(t.length>0){const e=t[0],o=Gt.formats(e.domNode),s=this.scroll.create("block"),l=s.wrap(yt.tableCellInner,o).wrap(yt.tableCell,o).wrap(yt.tableRow,o).wrap(yt.tableBody,o.tableId);r.parent.insertBefore(l,r.next),d=s,h=s.next}}for(const t of i)d.insertBefore(t,h);l&&d.insertBefore(this.scroll.create("text",l),h)}}class se extends kt{static blotName=yt.tableMain;static tagName="table";static create(t){const e=super.create(),{tableId:o,full:s,align:l}=t;return e.dataset.tableId=o,"right"===l||"center"===l?e.dataset.align=l:e.removeAttribute("date-align"),s&&(e.dataset.full=String(s)),e.classList.add("ql-table"),e.setAttribute("cellpadding","0"),e.setAttribute("cellspacing","0"),e}constructor(t,e,o){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")}set full(t){this.domNode[t?"setAttribute":"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"),this.updateAlign()}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(Qt)}getRowIds(){return this.getRows().map((t=>t.rowId))}getCols(){return this.descendants(oe)}getColIds(){return this.getCols().map((t=>t.colId))}checkMerge(){const t=this.next;return null!==t&&t.statics.blotName===this.statics.blotName&&t.domNode.dataset.tableId===this.tableId}optimize(t){const e=this.parent;null!==e&&e.statics.blotName!==yt.tableWrapper&&this.wrap(yt.tableWrapper,this.tableId),super.optimize(t)}}class le extends kt{static blotName=yt.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")}get align(){return this.domNode.dataset.align||""}set align(t){"right"===t||"center"===t?this.domNode.dataset.align=t:this.domNode.removeAttribute("data-align")}findCol(t){const e=this.children.iterator();let o,s=0;for(;(o=e())&&s!==t;)s++;return o}insertColByIndex(t,e){const o=this.parent;if(!(o instanceof se))throw new TypeError("TableColgroupFormat should be child of TableFormat");const s=this.findCol(t),l=this.scroll.create(yt.tableCol,e);if(o.full){const t=this.children.iterator();let e;for(;e=t();)if(e.width-l.width>=It.colMinWidthPre){e.width-=l.width;break}}this.insertBefore(l,s)}removeColByIndex(t){const e=this.parent;if(!(e instanceof se))throw new TypeError("TableColgroupFormat should be child of TableMainFormat");const o=this.findCol(t);o&&(e.full&&(o.next?o.next.width+=o.width:o.prev&&(o.prev.width+=o.width)),o.remove(),e.colWidthFillTable())}checkMerge(){const t=this.next,e=this.parent;return e instanceof se&&!e.full&&e.colWidthFillTable(),null!==t&&t.statics.blotName===this.statics.blotName&&t.tableId===this.tableId}optimize(t){const e=this.parent,{tableId:o,full:s,align:l}=this;null!=e&&e.statics.blotName!==yt.tableMain&&this.wrap(yt.tableMain,{tableId:o,full:s,align:l});dt(this,yt.tableMain).align=l,super.optimize(t)}}class ie extends kt{static blotName=yt.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 o=this.descendants(Jt),s=this.descendants(le);0!==o.length&&0!==s.length||this.remove()}}class ne{tableModule;table;quill;tableBlot;tableWrapperBlot;alignBox;cleanup;constructor(e,o,s){this.tableModule=e,this.table=o,this.quill=s,this.tableBlot=t.find(o),this.tableWrapperBlot=this.tableBlot.parent,this.alignBox=this.buildTool()}buildTool(){const e=this.tableModule.addContainer("ql-table-align"),o=t.import("ui/icons"),s={left:o.align[""],center:o.align.center,right:o.align.right};for(const[o,l]of Object.entries(s)){const s=document.createElement("span");s.dataset.align=o,s.classList.add("ql-table-align-item"),s.innerHTML=`<i class="icon">${l}</i>`,s.addEventListener("click",(()=>{const e=s.dataset.align;e&&(this.setTableAlign(this.tableBlot,e),this.quill.once(t.events.SCROLL_OPTIMIZE,(()=>{this.tableModule.tableSelection&&this.tableModule.tableSelection.hideSelection(),this.tableModule.tableResize&&this.tableModule.tableResize.update(),this.tableModule.tableScrollbar&&this.tableModule.tableScrollbar.update()})))})),e.appendChild(s)}return this.cleanup||(this.cleanup=ot(this.tableWrapperBlot.domNode,e,(()=>this.update()))),e}setTableAlign(t,e){const o=t.getCols();for(const t of o)t.align=e}show(){this.alignBox&&Object.assign(this.alignBox.style,{display:"flex"})}hide(){this.alignBox&&(Object.assign(this.alignBox.style,{display:null}),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(),rt(this.tableWrapperBlot.domNode,this.alignBox,{placement:"top",middleware:[it(),lt({limiter:nt()}),st(8)]}).then((({x:t,y:e})=>{Object.assign(this.alignBox.style,{left:`${t}px`,top:`${e}px`})}))))}destroy(){this.hide(),this.alignBox&&(this.alignBox.remove(),this.alignBox=void 0)}}const re="color-selector",ae=new Set,ce=[{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,o)=>{t.setCellAttrs(e,"background-color",o)}},{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,o)=>{t.setCellAttrs(e,"border-color",o)}}],de="table-color-used",he="table-color-item",ue="table-color-btn",pe="table-color-map",be="table-color-map-row",me="table-color-select-wrapper";class fe{tableModule;quill;options;menu=null;updateUsedColor;colorItemClass=`color-${at()}`;tooltipItem=[];constructor(t,e,o){this.tableModule=t,this.quill=e,this.options=this.resolveOptions(o);try{const t=localStorage.getItem(this.options.localstorageKey)||"[]";let e=JSON.parse(t);St(e)||(e=[]),e.map((t=>ae.add(t)))}catch{}this.updateUsedColor=ct((t=>{if(!t)return;if(ae.add(t),ae.size>10){const t=Array.from(ae).slice(-10);ae.clear(),t.map((t=>ae.add(t)))}localStorage.setItem(this.options.localstorageKey,JSON.stringify(Array.from(ae)));const e=Array.from(document.querySelectorAll(`.${this.colorItemClass}.${de}`));for(const o of e){if(!o)continue;const e=o.querySelectorAll(`.${he}[style*="background-color: ${t}"]`);for(const t of Array.from(e))t.remove();const s=document.createElement("div");s.classList.add(he),s.style.backgroundColor=String(t),o.appendChild(s)}}),1e3)}resolveOptions(t){const e=Object.assign({tipText:!0,tipTexts:{},tools:ce,localstorageKey:"__table-bg-used-color",defaultColorMap:Lt},t);return e.texts=Object.assign(this.resolveTexts(t.texts),t.texts),e}resolveTexts(t={}){return Object.assign({custom:"Custom",clear:"Clear",transparent:"Transparent"},t)}getUsedColors(){return ae}buildTools(){const t=document.createElement("div");t.classList.add("ql-table-menu"),Object.assign(t.style,{display:"flex"});for(const e of this.options.tools){const{name:o,icon:s,handle:l,isColorChoose:i,key:n,tip:r=""}=e,a=document.createElement("span");if(a.classList.add("ql-table-menu-item"),"break"===o)a.classList.add("break");else{const t=document.createElement("i");if(t.classList.add("icon"),Nt(s)?t.appendChild(s(this.tableModule)):t.innerHTML=s,a.appendChild(t),i&&n){const t=this.createColorChoose({name:o,icon:s,handle:l,isColorChoose:i,key:n,tip:r}),e=Ct(a,{content:t,direction:"top"});e&&this.tooltipItem.push(e),a.classList.add(re)}else Nt(l)&&a.addEventListener("click",(t=>{this.quill.focus(),l(this.tableModule,this.getSelectedTds(),t)}),!1);const e=this.options.tipTexts[o]||r;this.options.tipText&&e&&r&&this.createTipText(a,e)}t.appendChild(a)}return t}createColorChoose({handle:t,key:e}){const o=document.createElement("div");if(o.classList.add(me),this.options.defaultColorMap.length>0){const t=document.createElement("div");t.classList.add(pe);for(const e of this.options.defaultColorMap){const o=document.createElement("div");o.classList.add(be);for(const t of e){const e=document.createElement("div");e.classList.add(he),e.style.backgroundColor=t,o.appendChild(e)}t.appendChild(o)}o.appendChild(t)}const s=document.createElement("div");s.classList.add(be),Object.assign(s.style,{marginTop:"4px"});const l=document.createElement("div");l.classList.add(ue,"table-color-transparent"),l.textContent=this.options.texts.transparent,l.addEventListener("click",(()=>{t(this.tableModule,this.getSelectedTds(),"transparent")}));const i=document.createElement("div");i.classList.add(ue,"table-color-clear"),i.textContent=this.options.texts.clear,i.addEventListener("click",(()=>{t(this.tableModule,this.getSelectedTds(),null)}));const n=document.createElement("label");n.classList.add(ue,"table-color-custom");const r=document.createElement("span");r.textContent=this.options.texts.custom;const a=document.createElement("input");if(a.type="color",Object.assign(a.style,{width:0,height:0,padding:0,border:0,outline:"none",opacity:0}),a.addEventListener("input",(()=>{t(this.tableModule,this.getSelectedTds(),a.value),this.updateUsedColor(a.value)}),!1),n.appendChild(r),n.appendChild(a),s.appendChild(l),s.appendChild(i),s.appendChild(n),o.appendChild(s),ae.size>0){const t=document.createElement("div");t.classList.add(de,this.colorItemClass);for(const e of ae){const o=document.createElement("div");o.classList.add(he),o.style.backgroundColor=e,t.appendChild(o)}o.appendChild(t)}return o.addEventListener("click",(t=>{const o=t.target,s=o.style.backgroundColor,l=this.getSelectedTds();if(o&&s&&l.length>0){if(this.tableModule.setCellAttrs(l,e,s),o.closest(`.${he}`))return;this.updateUsedColor(s)}})),o}getSelectedTds(){return this.tableModule.tableSelection?.selectedTds||[]}createTipText(t,e){const o=Ct(t,{msg:e});o&&this.tooltipItem.push(o)}updateTools(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&Object.assign(this.menu.style,{display:"flex"})}hideTools(){this.menu&&Object.assign(this.menu.style,{display:"none"})}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}class ge extends fe{tableModule;quill;constructor(t,e,o){super(t,e,o),this.tableModule=t,this.quill=e,this.quill.root.addEventListener("contextmenu",this.listenContextmenu)}listenContextmenu=t=>{t.preventDefault();const e=t.composedPath();if(!e||e.length<=0)return;e.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")))&&this.tableModule.tableSelection?.selectedTds?.length?(this.menu||(this.menu=this.buildTools()),this.updateTools({x:t.clientX,y:t.clientY}),document.addEventListener("click",(()=>{this.hideTools()}),{once:!0})):this.hideTools()};buildTools(){const t=super.buildTools();t.classList.add("contextmenu");const e=t.getElementsByClassName(re);for(const t of Array.from(e))t.addEventListener("click",(t=>t.stopPropagation()));return document.body.appendChild(t),t}createTipText(t,e){const o=document.createElement("span");o.textContent=e,t.appendChild(o)}updateTools(t){if(!this.menu||!this.tableModule.tableSelection||!this.tableModule.tableSelection.boundary)return;super.updateTools();const e={display:"flex",left:0,top:0};if(!t)return this.hideTools();const{x:o,y:s}=t;e.left=o,e.top=s,Object.assign(this.menu.style,{...e,left:`${e.left+window.scrollX}px`,top:`${e.top+window.scrollY}px`});const l=this.menu.getBoundingClientRect(),{left:i,top:n}=(t=>{let{left:e,top:o,width:s,height:l}=t;const{clientWidth:i,clientHeight:n}=document.documentElement;let r=!1,a=!1;return e+s>i?(e=i-s-8,r=!0):e<0&&(e=8,r=!0),o+l>n?(o=n-l-8,a=!0):o<0&&(o=8,a=!0),{left:e,top:o,leftLimited:r,topLimited:a}})(l);Object.assign(this.menu.style,{left:`${i+window.scrollX}px`,top:`${n+window.scrollY}px`})}destroy(){for(const t of this.tooltipItem)t.destroy();this.quill.root.removeEventListener("contextmenu",this.listenContextmenu),this.menu&&(this.menu.remove(),this.menu=null)}}class we extends fe{tableModule;quill;constructor(t,e,o){super(t,e,o),this.tableModule=t,this.quill=e,this.menu=this.buildTools(),this.tableModule.addContainer(this.menu)}updateTools(){this.menu&&this.tableModule.tableSelection&&this.tableModule.tableSelection.boundary&&(super.updateTools(),rt(this.tableModule.tableSelection.cellSelect,this.menu,{placement:"bottom",middleware:[it(),lt({limiter:nt()}),st(8)]}).then((({x:t,y:e})=>{Object.assign(this.menu.style,{left:`${t}px`,top:`${e}px`})})))}destroy(){for(const t of this.tooltipItem)t.destroy();this.menu&&(this.menu.remove(),this.menu=null)}}const ve=t=>!t.full&&"right"===t.align;class xe{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);constructor(t){this.quill=t}findCurrentColIndex(t){return-1}colWidthChange(t,e,o){}handleColMouseUp(){if(!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const t=this.tableMain.getCols(),e=Number.parseInt(this.dragColBreak.dataset.w||"0"),o=this.tableMain.full;if(o){let s=e/this.tableMain.domNode.getBoundingClientRect().width*100;const l=t[this.colIndex].width;if(s<l){if(s=Math.max(It.colMinWidthPre,s),t[this.colIndex+1]||t[this.colIndex-1]){const e=t[this.colIndex+1]?this.colIndex+1:this.colIndex-1,i=t[e],n=i.width+l-s;i.width=`${n}%`,this.colWidthChange(e,n,o)}else s=100;t[this.colIndex].width=`${s}%`,this.colWidthChange(this.colIndex,s,o)}else if(t[this.colIndex+1]){const e=l+t[this.colIndex+1].width;s=Math.min(e-It.colMinWidthPre,s),t[this.colIndex].width=`${s}%`,this.colWidthChange(this.colIndex,s,o),t[this.colIndex+1].width=e-s+"%",this.colWidthChange(this.colIndex+1,e-s,o)}}else this.tableMain.domNode.style.width=`${Number.parseFloat(this.tableMain.domNode.style.width)-t[this.colIndex].domNode.getBoundingClientRect().width+e}px`,t[this.colIndex].width=`${e}px`,this.colWidthChange(this.colIndex,e,o);document.body.removeChild(this.dragColBreak),this.dragColBreak=null,document.removeEventListener("mouseup",this.handleColMouseUpFunc),document.removeEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(Mt.AFTER_TABLE_RESIZE)}handleColMouseMove(t){if(t.preventDefault(),!this.dragColBreak||!this.tableMain||-1===this.colIndex)return;const e=this.tableMain.getCols(),o=e[this.colIndex].domNode.getBoundingClientRect(),s=this.tableMain.domNode.getBoundingClientRect();let l=t.clientX;if(this.tableMain.full){const t=It.colMinWidthPre/100*s.width;let i=s.right;l>o.right&&e[this.colIndex+1]&&(i=Math.max(e[this.colIndex+1].domNode.getBoundingClientRect().right-t,o.left+t));const n=o.x+t;l=Math.min(Math.max(l,n),i)}else ve(this.tableMain)?o.right-l<It.colMinWidthPx&&(l=o.right-It.colMinWidthPx):l-o.x<It.colMinWidthPx&&(l=o.x+It.colMinWidthPx);let i=l-o.x;return ve(this.tableMain)&&(i=o.right-l),this.dragColBreak.style.left=`${l}px`,this.dragColBreak.dataset.w=String(i),{left:l,width:i}}handleColMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;const e=this.tableMain.getCols(),o=this.tableMain.domNode.getBoundingClientRect(),s=o.width;if(this.colIndex=this.findCurrentColIndex(t),-1===this.colIndex)return;const l=e[this.colIndex].width,i=this.tableMain.full?l/100*s:l;if(this.tableMain.full){if(l<It.colMinWidthPre)return}else if(i<It.colMinWidthPx)return;document.addEventListener("mouseup",this.handleColMouseUpFunc),document.addEventListener("mousemove",this.handleColMouseMoveFunc),this.dragging=!0;const n=document.createElement("div");n.classList.add("ql-table-drag-line"),n.classList.add("col"),n.dataset.w=String(i);const r={top:o.y,left:t.clientX,height:o.height};Object.assign(n.style,{top:`${r.top}px`,left:`${r.left}px`,height:`${r.height}px`});const a=document.body;return a.appendChild(n),this.dragColBreak&&a.removeChild(this.dragColBreak),this.dragColBreak=n,r}findCurrentRowIndex(t){return-1}rowHeightChange(t,e){}handleRowMouseUp(){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;const t=Number.parseInt(this.dragRowBreak.dataset.h||"0");this.tableMain.getRows()[this.rowIndex].setHeight(`${t}px`),this.rowHeightChange(this.rowIndex,t),document.body.removeChild(this.dragRowBreak),this.dragRowBreak=null,document.removeEventListener("mouseup",this.handleRowMouseUpFunc),document.removeEventListener("mousemove",this.handleRowMouseMoveFunc),this.dragging=!1,this.quill.emitter.emit(Mt.AFTER_TABLE_RESIZE)}handleRowMouseMove(t){if(!this.tableMain||!this.dragRowBreak||-1===this.rowIndex)return;t.preventDefault();const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect();let o=t.clientY;return o-e.y<It.rowMinHeightPx&&(o=e.y+It.rowMinHeightPx),this.dragRowBreak.style.top=`${o}px`,this.dragRowBreak.dataset.h=String(o-e.y),{top:o,height:o-e.y}}handleRowMouseDown(t){if(0!==t.button)return;if(t.preventDefault(),!this.tableMain)return;if(this.rowIndex=this.findCurrentRowIndex(t),-1===this.rowIndex)return;this.dragging=!0,document.addEventListener("mouseup",this.handleRowMouseUpFunc),document.addEventListener("mousemove",this.handleRowMouseMoveFunc);const e=this.tableMain.getRows()[this.rowIndex].domNode.getBoundingClientRect().height,o=this.tableMain?.domNode.getBoundingClientRect(),s=document.createElement("div");s.classList.add("ql-table-drag-line"),s.classList.add("row"),s.dataset.h=String(e);const l={top:t.clientY,left:o.x,width:o.width};Object.assign(s.style,{top:`${l.top}px`,left:`${l.left}px`,width:`${l.width}px`});const i=document.body;return i.appendChild(s),this.dragRowBreak&&i.removeChild(this.dragRowBreak),this.dragRowBreak=s,l}update(){}destroy(){}}class Ce extends xe{tableModule;table;options;root;tableMain;tableWrapper;resizeObserver;tableCols=[];tableRows=[];rowHeadWrapper=null;colHeadWrapper=null;corner=null;scrollHandler=[];lastHeaderSelect=null;constructor(e,o,s,l){super(s),this.tableModule=e,this.table=o,this.options=this.resolveOptions(l),this.tableMain=t.find(this.table),this.tableMain&&(this.tableWrapper=this.tableMain.parent,this.tableWrapper&&(this.root=this.tableModule.addContainer("ql-table-resizer"),this.resizeObserver=new ResizeObserver((()=>{this.showTool()})),this.resizeObserver.observe(this.table)))}resolveOptions(t){return Object.assign({size:12},t)}handleResizerHeader(t,e){const{clientX:o,clientY:s}=e,l=this.table.getBoundingClientRect();if(this.tableModule.tableSelection){const i=this.tableModule.tableSelection;e.shiftKey||(this.lastHeaderSelect=null);const n=[{x:t?l.left:o,y:t?s:l.top},{x:t?l.right:o,y:t?s:l.bottom}];this.lastHeaderSelect?(n[0]={x:Math.min(n[0].x,this.lastHeaderSelect[0].x),y:Math.min(n[0].y,this.lastHeaderSelect[0].y)},n[1]={x:Math.max(n[1].x,this.lastHeaderSelect[1].x),y:Math.max(n[1].y,this.lastHeaderSelect[1].y)}):this.lastHeaderSelect=n,i.selectedTds=i.computeSelectedTds(...n),i.showSelection()}}findCurrentColIndex(t){return Array.from(this.root.getElementsByClassName("ql-table-col-separator")).indexOf(t.target)}colWidthChange(t,e,o){Array.from(this.root.getElementsByClassName("ql-table-col-header"))[t].style.width=`${e}${o?"%":"px"}`}handleColMouseDownFunc=function(t){const e=this.handleColMouseDown(t);return e&&this.dragColBreak&&Object.assign(this.dragColBreak.style,{top:e.top-this.options.size+"px",left:`${e.left}px`,height:`${e.height+this.options.size}px`}),e}.bind(this);bindColEvents(){const t=Array.from(this.root.getElementsByClassName("ql-table-col-header")),e=Array.from(this.root.getElementsByClassName("ql-table-col-separator"));bt.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("ql-table-row-separator")).indexOf(t.target)}rowHeightChange(t,e){Array.from(this.root.getElementsByClassName("ql-table-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.options.size+"px",width:`${e.width+this.options.size}px`}),e}.bind(this);bindRowEvents(){const t=Array.from(this.root.getElementsByClassName("ql-table-row-header")),e=Array.from(this.root.getElementsByClassName("ql-table-row-separator"));bt.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.domNode.getBoundingClientRect(),e=this.tableWrapper.domNode.getBoundingClientRect(),o=Math.max(t.x,e.x),s=Math.max(t.y,e.y),l=this.quill.root.getBoundingClientRect();Object.assign(this.root.style,{top:s-l.y+"px",left:o-l.x+"px"});let i=-1*this.options.size,n=-1*this.options.size;ve(this.tableMain)?(this.root.classList.add("table-align-right"),i=Math.min(e.width,t.width),n=Math.min(e.width,t.width)):this.root.classList.remove("table-align-right"),this.corner&&Object.assign(this.corner.style,{transform:`translateY(${-1*this.options.size}px) translateX(${i}px)`}),this.rowHeadWrapper&&Object.assign(this.rowHeadWrapper.style,{transform:`translateX(${n}px)`})}showTool(){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("ql-table-resizer-corner"),Object.assign(this.corner.style,{width:`${this.options.size}px`,height:`${this.options.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.showSelection()}})),this.root.appendChild(this.corner)),this.tableCols.length>0){let o="";for(const t of this.tableCols){let s=t.width+(this.tableMain.full?"%":"px");t.width||(s=`${t.domNode.getBoundingClientRect().width}px`),o+=`<div class="ql-table-col-header" style="width: ${s}">\n <div class="ql-table-col-separator" style="height: ${e.height+this.options.size-3}px"></div>\n </div>`}const s=document.createElement("div");s.classList.add("ql-table-resizer-col");const l=document.createElement("div");l.classList.add("ql-table-col-wrapper"),Object.assign(s.style,{transform:`translateY(-${this.options.size}px)`,maxWidth:`${t.width}px`,height:`${this.options.size}px`}),Object.assign(l.style,{width:`${e.width}px`}),l.innerHTML=o,s.appendChild(l),this.root.appendChild(s),s.scrollLeft=this.tableWrapper.domNode.scrollLeft,this.colHeadWrapper=s,this.bindColEvents()}if(this.tableRows.length>0){let o="";for(const t of this.tableRows){o+=`<div class="ql-table-row-header" style="height: ${`${t.domNode.getBoundingClientRect().height}px`}">\n <div class="ql-table-row-separator" style="width: ${e.width+this.options.size-3}px"></div>\n </div>`}const s=document.createElement("div");s.classList.add("ql-table-resizer-row");const l=document.createElement("div");l.classList.add("ql-table-row-wrapper"),Object.assign(s.style,{transform:`translateX(-${this.options.size}px)`,width:`${this.options.size}px`,maxHeight:`${t.height}px`}),Object.assign(l.style,{height:`${e.height}px`}),l.innerHTML=o,s.appendChild(l),this.root.appendChild(s),s.scrollTop=this.tableWrapper.domNode.scrollTop,this.rowHeadWrapper=s,this.bindRowEvents()}this.update(),bt.call(this,this.quill.root,(()=>{this.update()}))}hideTool(){this.root.classList.add("ql-hidden")}destroy(){this.hideTool(),mt.call(this),this.resizeObserver.disconnect();for(const[t,e]of this.scrollHandler)t.removeEventListener("scroll",e);this.root.remove()}}class ye extends xe{tableModule;colResizer;rowResizer;currentTableCell;dragging=!1;options;curColIndex=-1;curRowIndex=-1;tableCellBlot;constructor(e,o,s){super(o),this.tableModule=e,this.options=this.resolveOptions(s),this.colResizer=this.tableModule.addContainer("ql-table-resize-line-col"),this.rowResizer=this.tableModule.addContainer("ql-table-resize-line-row"),this.quill.root.addEventListener("mousemove",this.mousemoveHandler),this.quill.on(t.events.TEXT_CHANGE,this.hideWhenTextChange)}mousemoveHandler=e=>{if(this.dragging)return;const o=this.findTableCell(e);if(!o)return this.hideResizer();const s=t.find(o);s&&this.currentTableCell!==o&&(this.showResizer(),this.currentTableCell=o,this.tableCellBlot=s,this.tableMain=dt(s,yt.tableMain),this.tableMain.getCols().length>0&&this.updateColResizer(),this.updateRowResizer())};hideWhenTextChange=()=>{this.hideResizer()};resolveOptions(t){return Object.assign({},t)}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=function(){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("ql-table-resize-line-col");const[e]=ht(t,[yt.tableBody]),o=e.domNode.getBoundingClientRect(),s=t.domNode.getBoundingClientRect(),l=this.quill.root.getBoundingClientRect();let i=s.right-l.x;ve(this.tableMain)&&(i=s.left-l.x),Object.assign(this.colResizer.style,{top:o.y-l.y+"px",left:`${i}px`,height:`${o.height}px`});const n=this.tableMain.getCols();this.curColIndex=n.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("ql-table-resize-line-row");const e=t.parent;if(!(e instanceof Qt))return;const[o]=ht(t,[yt.tableBody]),s=o.domNode.getBoundingClientRect(),l=t.domNode.getBoundingClientRect(),i=this.quill.root.getBoundingClientRect();Object.assign(this.rowResizer.style,{top:l.bottom-i.y+"px",left:s.x-i.x+"px",width:`${s.width}px`});const n=this.tableMain.getRows();this.curRowIndex=n.indexOf(e),this.rowResizer.addEventListener("mousedown",this.handleRowMouseDownFunc),this.rowResizer.addEventListener("dragstart",(t=>{t.preventDefault()}))}showResizer(){Object.assign(this.colResizer.style,{display:null}),Object.assign(this.rowResizer.style,{display:null})}hideResizer(){this.currentTableCell=void 0,this.rowResizer.style.display="none",this.colResizer.style.display="none"}update(){this.updateColResizer(),this.updateRowResizer()}destroy(){this.quill.root.removeEventListener("mousemove",this.mousemoveHandler),this.quill.off(t.events.TEXT_CHANGE,this.hideWhenTextChange)}}class Ie{quill;isVertical;table;scrollbarContainer;minSize=20;gap=4;move=0;cursorDown=!1;cursorLeave=!1;ratioY=1;ratioX=1;sizeWidth="";sizeHeight="";thumbState={X:0,Y:0};ob;container;scrollbar;thumb=document.createElement("div");scrollHandler=[];propertyMap;constructor(t,e,o,s){this.quill=t,this.isVertical=e,this.table=o,this.scrollbarContainer=s,this.container=o.parentElement,this.propertyMap=this.isVertical?{size:"height",offset:"offsetHeight",scrollDirection:"scrollTop",scrollSize:"scrollHeight",axis:"Y",direction:"top",client:"clientY"}:{size:"width",offset:"offsetWidth",scrollDirection:"scrollLeft",scrollSize:"scrollWidth",axis:"X",direction:"left",client:"clientX"},this.calculateSize(),this.ob=new ResizeObserver((()=>{this.update()})),this.ob.observe(o),this.scrollbar=this.createScrollbar(),this.setScrollbarPosition(),bt.call(this,this.quill.root,(()=>this.setScrollbarPosition())),this.showScrollbar()}update(){this.calculateSize(),this.setScrollbarPosition()}setScrollbarPosition(){const{scrollLeft:e,scrollTop:o}=this.quill.root,{offsetLeft:s,offsetTop:l}=this.container,{width:i,height:n}=this.container.getBoundingClientRect(),{width:r,height:a}=this.table.getBoundingClientRect();let c=s,d=l;this.isVertical?c+=Math.min(i,r):d+=Math.min(n,a);const h=t.find(this.table);h&&"left"!==h.align&&(c+=this.table.offsetLeft-s),Object.assign(this.scrollbar.style,{[this.propertyMap.size]:`${this.isVertical?n:i}px`,transform:`translate(${c-e}px, ${d-o}px)`}),this.containerScrollHandler(this.container)}calculateSize(){const t=this.container.offsetHeight-this.gap,e=this.container.offsetWidth-this.gap,o=t**2/this.container.scrollHeight,s=e**2/this.container.scrollWidth,l=Math.max(o,this.minSize),i=Math.max(s,this.minSize);this.ratioY=o/(t-o)/(l/(t-l)),this.ratioX=s/(e-s)/(i/(e-i)),this.sizeWidth=i+this.gap<e?`${i}px`:"",this.sizeHeight=l+this.gap<t?`${l}px`:""}createScrollbar(){const t=document.createElement("div");t.classList.add("ql-table-scrollbar"),t.classList.add(this.isVertical?"vertical":"horizontal","transparent"),Object.assign(t.style,{display:"none"}),this.thumb.classList.add("ql-table-scrollbar-thumb");const e=t=>{if(!1===this.cursorDown)return;const e=this.thumbState[this.propertyMap.axis];if(!e)return;const o=this.scrollbar[this.propertyMap.offset]**2/this.container[this.propertyMap.scrollSize]/(this.isVertical?this.ratioY:this.ratioX)/this.thumb[this.propertyMap.offset],s=100*(-1*(this.scrollbar.getBoundingClientRect()[this.propertyMap.direction]-t[this.propertyMap.client])-(this.thumb[this.propertyMap.offset]-e))*o/this.scrollbar[this.propertyMap.offset];this.container[this.propertyMap.scrollDirection]=s*this.container[this.propertyMap.scrollSize]/100},o=()=>{this.thumbState[this.propertyMap.axis]=0,this.cursorDown=!1,document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",o),this.cursorLeave&&(this.scrollbar.style.display="none")},s=t=>{t.stopImmediatePropagation(),this.cursorDown=!0,document.addEventListener("mousemove",e),document.addEventListener("mouseup",o),document.onselectstart=()=>!1};this.thumb.addEventListener("mousedown",(t=>{if(t.stopPropagation(),t.ctrlKey||[1,2].includes(t.button))return;window.getSelection()?.removeAllRanges(),s(t);const e=t.currentTarget;e&&(this.thumbState[this.propertyMap.axis]=e[this.propertyMap.offset]-(t[this.propertyMap.client]-e.getBoundingClientRect()[this.propertyMap.direction]))}));const l=[this.table,t];for(const t of l)t.addEventListener("mouseenter",this.showScrollbar),t.addEventListener("mouseleave",this.hideScrollbar);return bt.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.isVertical?this.sizeHeight:this.sizeWidth,transform:`translate${this.propertyMap.axis}(${this.move}%)`})}showScrollbar=ct((()=>{this.cursorLeave=!1,this.scrollbar.classList.remove("transparent"),ft(this.scrollbar,150,(()=>{this.scrollbar.style.display=(this.isVertical?this.sizeHeight:this.sizeWidth)?"block":"none"}))}),200);hideScrollbar=ct((()=>{this.cursorLeave=!0,this.scrollbar.classList.add("transparent"),ft(this.scrollbar,150,(()=>{this.scrollbar.style.display=this.cursorDown&&(this.isVertical?this.sizeHeight:this.sizeWidth)?"block":"none"}))}),200);destroy(){this.ob.disconnect(),mt.call(this),this.table.removeEventListener("mouseenter",this.showScrollbar),this.table.removeEventListener("mouseleave",this.hideScrollbar)}}class Me{tableModule;table;quill;scrollbarContainer;scrollbar;constructor(t,e,o){this.tableModule=t,this.table=e,this.quill=o,this.scrollbarContainer=this.tableModule.addContainer("ql-table-scrollbar-container"),this.scrollbar=[new Ie(o,!0,e,this.scrollbarContainer),new Ie(o,!1,e,this.scrollbarContainer)];for(const t of this.scrollbar)this.scrollbarContainer.appendChild(t.scrollbar)}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 Le{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;constructor(t,e,o,s={}){this.table=e,this.quill=o,this.options=this.resolveOptions(s),this.cellSelectWrap=t.addContainer("ql-table-selection"),this.cellSelect=this.helpLinesInitial(),this.resizeObserver=new ResizeObserver((()=>this.hideSelection())),this.resizeObserver.observe(this.table),this.resizeObserver.observe(this.quill.root),this.quill.root.addEventListener("mousedown",this.selectingHandler,!1),this.tableMenu=new this.options.tableMenuClass(t,o,this.options.tableMenu)}resolveOptions(t){return Object.assign({selectColor:"#0589f3",tableMenuClass:we,tableMenu:{}},t)}helpLinesInitial(){const t=document.createElement("div");return t.classList.add("ql-table-selection_line"),Object.assign(t.style,{"border-color":this.options.selectColor}),this.cellSelectWrap.appendChild(t),t}computeSelectedTds(e,o){const s=t.find(this.table);if(!s)return[];const l=new Set(s.descendants(te).map(((t,e)=>(t.index=e,t)))),{x:i,y:n}=this.getTableViewScroll(),{x:r,y:a}=this.getQuillViewScroll();this.selectedTableScrollX=i,this.selectedTableScrollY=n,this.selectedEditorScrollX=r,this.selectedEditorScrollY=a;const c=this.table.getBoundingClientRect(),d=e.x-i+this.startScrollX,h=e.y-n+this.startScrollY;let u={x:Math.max(c.left,Math.min(o.x,d)),y:Math.max(c.top,Math.min(o.y,h)),x1:Math.min(c.right,Math.max(o.x,d)),y1:Math.min(c.bottom,Math.max(o.y,h))};const p=new Set;let b=!0;for(;b;){b=!1;for(const t of l){t.__rect||(t.__rect=t.domNode.getBoundingClientRect());const{x:e,y:o,right:s,bottom:i}=t.__rect;if(Ne(u,{x:e,y:o,x1:s,y1:i},2)){p.add(t),l.delete(t),u={x:Math.min(u.x,e),y:Math.min(u.y,o),x1:Math.max(u.x1,s),y1:Math.max(u.y1,i)},b=!0;break}if(e>u.x1&&o>u.y1)break}}for(const t of[...p,...l])delete t.__rect;return this.boundary=Se({...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:o,clientX:s,clientY:l}=t,i=o.closest(".ql-table");if(0!==e||!i)return;const n=i.dataset.tableId,r={x:s,y:l},{x:a,y:c}=this.getTableViewScroll();this.startScrollX=a,this.startScrollY=c,this.selectedTds=this.computeSelectedTds(r,r),this.showSelection(),this.tableMenu.hideTools();const d=t=>{const{button:e,target:o,clientX:s,clientY:l}=t,i=o.closest(".ql-table");if(0!==e||!i||i.dataset.tableId!==n)return;this.dragging=!0;const a={x:s,y:l};this.selectedTds=this.computeSelectedTds(r,a),this.selectedTds.length>1&&this.quill.blur(),this.updateSelection()},h=()=>{document.body.removeEventListener("mousemove",d,!1),document.body.removeEventListener("mouseup",h,!1),this.dragging=!1,this.startScrollX=0,this.startScrollY=0,this.tableMenu.updateTools()};document.body.addEventListener("mousemove",d,!1),document.body.addEventListener("mouseup",h,!1)}updateSelection(){if(0===this.selectedTds.length||!this.boundary)return;const{x:t,y:e}=this.getQuillViewScroll(),{x:o,y:s}=this.getTableViewScroll(),l=this.table.parentElement.getBoundingClientRect(),i=this.quill.root.getBoundingClientRect(),n=l.x-i.x,r=l.y-i.y;Object.assign(this.cellSelect.style,{left:2*this.selectedEditorScrollX-t+this.boundary.x+this.selectedTableScrollX-o-n+"px",top:2*this.selectedEditorScrollY-e+this.boundary.y+this.selectedTableScrollY-s-r+"px",width:`${this.boundary.width}px`,height:`${this.boundary.height}px`}),Object.assign(this.cellSelectWrap.style,{left:`${n}px`,top:`${r}px`,width:`${l.width+2}px`,height:`${l.height+2}px`}),this.dragging||this.tableMenu.updateTools()}getQuillViewScroll(){return{x:this.quill.root.scrollLeft,y:this.quill.root.scrollTop}}getTableViewScroll(){return{x:this.table.parentElement.scrollLeft,y:this.table.parentElement.scrollTop}}showSelection(){mt.call(this),Object.assign(this.cellSelectWrap.style,{display:"block"}),this.updateSelection(),bt.call(this,this.quill.root,(()=>{this.updateSelection()})),bt.call(this,this.table.parentElement,(()=>{this.updateSelection()}))}hideSelection(){this.boundary=null,this.selectedTds=[],this.cellSelectWrap&&Object.assign(this.cellSelectWrap.style,{display:"none"}),this.tableMenu.hideTools(),mt.call(this)}destroy(){return this.resizeObserver.disconnect(),this.hideSelection(),this.tableMenu.destroy(),this.cellSelectWrap.remove(),mt.call(this),this.quill.root.removeEventListener("mousedown",this.selectingHandler,!1),null}}function Ne(t,e,o=4){const{x:s,y:l,x1:i,y1:n}=t,{x:r,y:a,x1:c,y1:d}=e;return!(i<=r+o||s+o>=c||(n<=a+o||l+o>=d))}function Se(t,e){const o=e.getBoundingClientRect();return{x:t.x-o.x-e.scrollLeft,y:t.y-o.y-e.scrollTop,x1:t.x-o.x-e.scrollLeft+t.width,y1:t.y-o.y-e.scrollTop+t.height,width:t.width,height:t.height}}const Te=t.import("delta"),Re=t.import("blots/break"),Ee=t.import("ui/icons"),Be=(t,{tableId:e,rowId:o,colId:s})=>{const l={tableId:e,rowId:o,colId:s,colspan:1,rowspan:1},i=t.create(yt.tableCell,l),n=t.create(yt.tableCellInner,l),r=t.create("block");return r.appendChild(t.create("break")),n.appendChild(r),i.appendChild(n),i},ke=[yt.tableCell],ze=t=>{return!(!t||!t.parent)&&(e=t.parent,!!ke.includes(e.statics.blotName)||ze(t.parent));var e};class qe{static moduleName="table-up";static toolName=yt.tableWrapper;static keyboradHandler={"forbid remove table by backspace":{bindInHead:!0,key:"Backspace",collapsed:!0,offset:0,handler(t,e){const o=this.quill.getLine(t.index)[0];if(o.prev instanceof ie)return o.prev.remove(),!1;if(e.format[yt.tableCellInner]){if(0===o.offset(dt(o,yt.tableCellInner)))return!1}return!0}},"forbid remove table by delete":{bindInHead:!0,key:"Delete",collapsed:!0,handler(t,e){const o=this.quill.getLine(t.index),s=o[0],l=o[1];if((s.next instanceof ie||s.next instanceof oe)&&l===s.length()-1)return!1;if(e.format[yt.tableCellInner]){if(s===dt(s,yt.tableCellInner).children.tail&&l===s.length()-1)return!1}return!0}},"after table insert new line":{bindInHead:!0,key:"Enter",collapsed:!0,format:[yt.tableCellInner],prefix:/^$/,suffix:/^\s*$/,handler(e){const[o,s]=this.quill.getLine(e.index);if(this.quill.getFormat(e.index+s+1,1)[yt.tableCellInner])return!0;let l=2,i=o;for(;null!==i&&i.length()<=1;)if(i=i.prev,l-=1,l<=0)return this.quill.insertText(e.index+1,"\n"),this.quill.setSelection(e.index+1,t.sources.SILENT),!1;return!0}}};static register(){ie.allowedChildren=[se],se.allowedChildren=[Jt,le],se.requiredContainer=ie,le.allowedChildren=[oe],le.requiredContainer=se,Jt.allowedChildren=[Qt],Jt.requiredContainer=se,Qt.allowedChildren=[te],te.requiredContainer=Jt,te.allowedChildren=[Gt,Re],te.requiredContainer=Qt,Gt.requiredContainer=te,t.register({"blots/scroll":Xt,"blots/block":Ot,[`blots/${yt.container}`]:kt,"formats/header":Dt,"formats/list":Ft,"formats/blockquote":Ht,"formats/code-block":Wt,[`formats/${yt.tableCell}`]:te,[`formats/${yt.tableCellInner}`]:Gt,[`formats/${yt.tableRow}`]:Qt,[`formats/${yt.tableBody}`]:Jt,[`formats/${yt.tableCol}`]:oe,[`formats/${yt.tableColgroup}`]:le,[`formats/${yt.tableMain}`]:se,[`formats/${yt.tableWrapper}`]:ie},!0)}quill;options;toolBox;fixTableByLisenter=ct(this.balanceTables,100);selector;picker;range;table;tableSelection;tableResize;tableScrollbar;tableAlign;get statics(){return this.constructor}constructor(e,o){this.quill=e,this.options=this.resolveOptions(o||{}),"boolean"!=typeof this.options.scrollbar||this.options.scrollbar||this.quill.container.classList.add("ql-table-scrollbar--origin"),this.toolBox=this.quill.addContainer("ql-table-toolbox");const s=this.quill.getModule("toolbar");if(s&&this.quill.theme.pickers){const[,t]=(s.controls||[]).find((([t])=>t===this.statics.toolName))||[];t&&"select"===t.tagName.toLocaleLowerCase()&&(this.picker=this.quill.theme.pickers.find((e=>e.select===t)),this.picker&&(this.picker.label.innerHTML=this.options.icon,this.buildCustomSelect(this.options.customSelect),this.picker.label.addEventListener("mousedown",this.handleInViewport)))}const l=this.quill.getModule("keyboard");for(const t of Object.values(qe.keyboradHandler))t.bindInHead?l.bindings[t.key].unshift(t):l.addBinding(t.key,t);this.quill.root.addEventListener("click",(t=>{const o=t.composedPath();if(!o||o.length<=0)return;const s=o.find((t=>t.tagName&&"TABLE"===t.tagName.toUpperCase()&&t.classList.contains("ql-table")));if(s){if(this.table===s)return this.tableSelection&&this.tableSelection.showSelection(),void(this.tableAlign&&this.tableAlign.update());this.table&&this.hideTableTools(),this.showTableTools(s,e)}else this.table&&this.hideTableTools()}),!1),this.quill.on(t.events.EDITOR_CHANGE,((e,o,s)=>{if(e===t.events.SELECTION_CHANGE&&o){const[e]=this.quill.getLine(o.index),[l]=this.quill.getLine(o.index+o.length);let i,n;try{i=dt(e,yt.tableMain)}catch{}try{n=dt(l,yt.tableMain)}catch{}if(e instanceof oe)return s||(s={index:0,length:0}),this.quill.setSelection(o.index+(s.index>o.index?-1:1),o.length+(s.length===o.length?0:s.length>o.length?-1:1),t.sources.USER);if(l instanceof oe)return this.quill.setSelection(o.index+1,o.length+1,t.sources.USER);o.length>0&&(i&&!n?this.quill.setSelection(o.index-1,o.length+1,t.sources.USER):n&&!i&&this.quill.setSelection(o.index,o.length+1,t.sources.USER)),i&&n||this.hideTableTools()}})),this.options.resizerSetOuter||(this.tableResize=new ye(this,e,this.options.resizeLine||{})),this.quill.on(Mt.AFTER_TABLE_RESIZE,(()=>{this.tableSelection&&this.tableSelection.hideSelection()})),this.pasteTableHandler(),this.listenBalanceCells()}addContainer(t){if("string"==typeof t){const e=document.createElement("div");for(const o of t.split(" "))e.classList.add(o);return this.toolBox.appendChild(e),e}return this.toolBox.appendChild(t),t}resolveOptions(t){return Object.assign({customBtn:!0,texts:this.resolveTexts(t.texts||{}),full:!1,resizerSetOuter:!1,icon:Ee.table,scrollbar:!0,showAlign:!0},t)}resolveTexts(t){return Object.assign({customBtnText:"Custom",confirmText:"Confirm",cancelText:"Cancel",rowText:"Row",colText:"Column",notPositiveNumberError:"Please enter a positive integer"},t)}pasteTableHandler(){let t=at(),e=at(),o=[],s=0,l=0;const i=(t,e,o)=>{const s=this.quill.getSelection(!0),l=this.quill.getFormat(s)[yt.tableCellInner];if(l)for(const t of e.ops)t.attributes||(t.attributes={}),t.attributes[yt.tableCellInner]=l;return e};this.quill.clipboard.addMatcher(Node.TEXT_NODE,i),this.quill.clipboard.addMatcher(Node.ELEMENT_NODE,i),this.quill.clipboard.addMatcher("table",((e,i)=>{if(0===i.ops.length)return i;for(let t=0;t<i.ops.length;t++){const{attributes:e,insert:o}=i.ops[t];o&&"string"!=typeof o&&o[oe.blotName]&&"\n"===i.ops[t+1].insert&&(i.ops.splice(t+1,1),t-=1),e&&e.table&&delete e.table,e&&e[te.blotName]&&delete e[te.blotName]}return t=at(),o=[],s=0,l=0,i.ops.unshift({insert:"\n"}),i.ops.push({insert:"\n"}),i})),this.quill.clipboard.addMatcher("col",(e=>{o[l]=at();const s=(new Te).insert({[yt.tableCol]:Object.assign(oe.value(e),{tableId:t,colId:o[l]})});return l+=1,s})),this.quill.clipboard.addMatcher("tr",((t,o)=>{e=at(),s=0;for(const t of o.ops)t.attributes&&t.attributes.background&&t.attributes[yt.tableCellInner]&&!t.attributes[yt.tableCellInner].backgroundColor&&(t.attributes[yt.tableCellInner].backgroundColor=t.attributes.background);return o}));const n=(l,i)=>{const n=l,r=te.formats(n);if(!o[s])for(let t=s;t>=0;t--)o[t]||(o[t]=at());const a=o[s];s+=r.colspan;const c=Object.assign(r,{tableId:t,rowId:e,colId:a}),d=[];for(const t of i.ops)"string"==typeof t.insert&&d.push({insert:t.insert,attributes:{[yt.tableCellInner]:c}});return new Te(d)};this.quill.clipboard.addMatcher("td",n),this.quill.clipboard.addMatcher("th",n)}showTableTools(t,e){t&&(this.table=t,this.tableSelection=new Le(this,t,e,this.options.selection||{}),this.options.showAlign&&(this.tableAlign=new ne(this,t,e)),this.options.scrollbar&&(this.tableScrollbar=new Me(this,t,e)),this.options.resizerSetOuter&&(this.tableResize=new Ce(this,t,e,this.options.resizeBox||{})))}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.table=void 0,this.options.resizerSetOuter&&(this.tableResize&&this.tableResize.destroy(),this.tableResize=void 0)}async buildCustomSelect(t){if(!this.picker)return;const e=document.createElement("div");e.classList.add("ql-custom-select"),this.selector=t&&Nt(t)?await t(this):((t={})=>{const e=document.createElement("div");e.classList.add("select-box");const o=document.createElement("div");o.classList.add("select-box__block");for(let e=0;e<(t.row||8);e++)for(let s=0;s<(t.col||8);s++){const t=document.createElement("div");t.classList.add("select-box__item"),t.dataset.row=String(e+1),t.dataset.col=String(s+1),o.appendChild(t)}const s=()=>{const{row:t,col:s}=e.dataset;for(const t of Array.from(o.querySelectorAll(".active")))t.classList.remove("active");if(!t||!s)return;const l=Array.from(o.children);for(let e=0;e<l.length;e++){const{row:o,col:i}=l[e].dataset;if(o>t&&i>s)return;o<=t&&i<=s?l[e].classList.add("active"):l[e].classList.remove("active")}};if(o.addEventListener("mousemove",(t=>{if(!t.target)return;const{row:o,col:l}=t.target.dataset;o&&l&&(e.dataset.row=o,e.dataset.col=l,s())})),o.addEventListener("mouseleave",(()=>{e.removeAttribute("data-row"),e.removeAttribute("data-col"),s()})),o.addEventListener("click",(()=>{const{row:o,col:s}=e.dataset;o&&s&&t.onSelect&&t.onSelect(Number(o),Number(s))})),e.appendChild(o),t.customBtn){const o=t.texts||{},s=document.createElement("div");s.classList.add("select-box__custom"),s.textContent=o.customBtnText||"自定义行列数",s.addEventListener("click",(async()=>{const e=await vt(o);e&&t.onSelect&&t.onSelect(e.row,e.col)})),e.appendChild(s)}return e})({onSelect:(t,e)=>{this.insertTable(t,e),this.picker&&this.picker.close()},customBtn:this.options.customBtn,texts:this.options.texts}),e.appendChild(this.selector),this.picker.options.appendChild(e)}handleInViewport=()=>{if(!this.selector||!this.picker)return;if(this.selector.getBoundingClientRect().right>=window.innerWidth){const t=this.picker.label.getBoundingClientRect();Object.assign(this.picker.options.style,{transform:`translateX(calc(-100% + ${t.width}px))`})}else Object.assign(this.picker.options.style,{transform:void 0})};insertTable(e,o){if(e>=30||o>=30)throw new Error("Both rows and columns must be less than 30.");this.quill.focus(),this.range=this.quill.getSelection();const s=this.range;if(null==s)return;const[l]=this.quill.getLeaf(s.index);if(!l)return;if(ze(l))throw new Error(`Not supported ${l.statics.blotName} insert into table.`);const i=getComputedStyle(this.quill.root),n=Number.parseInt(i.paddingLeft),r=Number.parseInt(i.paddingRight),a=Number.parseInt(i.width)-n-r,c=at(),d=new Array(o).fill(0).map((()=>at())),h=this.options.full?`${Math.max(1/o*100,It.colMinWidthPre)}%`:`${Math.max(Math.floor(a/o),It.colMinWidthPx)}px`,u=[{retain:s.index},{insert:"\n"}];for(let t=0;t<o;t++)u.push({insert:{[yt.tableCol]:{width:h,tableId:c,colId:d[t],full:this.options.full}}});for(let t=0;t<e;t++){const t=at();for(let e=0;e<o;e++)u.push({insert:"\n",attributes:{[yt.tableCellInner]:{tableId:c,rowId:t,colId:d[e],rowspan:1,colspan:1}}})}this.quill.updateContents(new Te(u),t.sources.USER),this.quill.setSelection(s.index+o+o*e+1,t.sources.SILENT),this.quill.focus()}fixUnusuaDeletelTable(t){const e=t.getRows(),o=t.getColIds();if(0===e.length)return t.remove();if(0===o.length)return;const s=new Array(e.length).fill(0).map((()=>new Array(o.length).fill(!1))),l=t.tableId;for(const[t,i]of e.entries()){let n=0,r=0;const a=s[t],c=i.descendants(te);for(;r<o.length;){if(a[r]){r+=1;continue}const d=c[n];if(d&&d.colId===o[r]){t+d.rowspan-1>=e.length&&(d.getCellInner().rowspan=e.length-t);const{colspan:o,rowspan:l}=d;if(o>1)for(let t=1;t<o;t++)a[r+t]=!0;if(l>1)for(let e=t+1;e<t+l;e++)for(let t=0;t<o;t++)s[e][r+t]=!0;n+=1}else i.insertBefore(Be(this.quill.scroll,{tableId:l,colId:o[r],rowId:i.rowId}),d);r+=1}if(n<c.length)for(let t=n;t<c.length;t++)c[t].remove()}}balanceTables(){for(const t of this.quill.scroll.descendants(se))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)))}))}setCellAttrs(t,e,o){if(0!==t.length)for(const s of t)s.setFormatValue(e,o)}deleteTable(){if(!this.tableSelection||0===this.tableSelection.selectedTds.length)return;const t=dt(this.tableSelection.selectedTds[0],yt.tableMain);t&&t.remove(),this.hideTableTools()}appendRow(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const o=e[t?e.length-1:0],[s,l,i]=ht(o,[yt.tableMain,yt.tableBody,yt.tableRow]),n=s.getRows().indexOf(i)+(t?o.rowspan:0);l.insertRow(n)}appendCol(t){if(!this.tableSelection)return;const e=this.tableSelection.selectedTds;if(e.length<=0)return;const[o]=e.reduce(((e,o)=>{const s=o.getColumnIndex();return(!t&&s<=e[1]||t&&s>=e[1])&&(e=[o,s]),e}),[e[0],e[0].getColumnIndex()]),s=o.getColumnIndex()+(t?o.colspan:0),l=dt(o,yt.tableMain),i=l.tableId,n=at(),[r]=l.descendants(le);r&&r.insertColByIndex(s,{tableId:i,colId:n,width:l.full?"6%":"160px",full:l.full});const a=l.getRows(),c=[];let d=0;for(const t of Object.values(a)){const e=c.shift()||0;if(d>0){d-=1;continue}const o=t.insertCell(s-e,{tableId:i,rowId:t.rowId,colId:n,rowspan:1,colspan:1});o.skipRowNum&&(d+=o.skipRowNum);for(const[t,e]of o.entries())c[t]=(c[t]||0)+e}}fixTableByRemove(t){const e=t.getRows(),o=t.getCols(),s=o.reduce(((t,e)=>(t[e.colId]=0,t)),{}),l=[...e].reverse(),i=[];for(const[t,o]of l.entries()){const l=e.length-t-1;o.children.length<=0?i.push(l):o.foreachCellInner((t=>{const e=i.reduce(((e,o)=>t.rowspan+l>o?e+1:e),0);t.rowspan-=e,s[t.colId]+=1}))}let n=0;for(const t of Object.values(s))if(0===t){const t=[];let o=0;for(const s of Object.values(e)){const e=t.shift()||0;let l=[];o>0?(l=s.getCellByColumIndex(n-e)[2],o-=1):(l=s.removeCell(n-e),l.skipRowNum&&(o+=l.skipRowNum));for(const[e,o]of l.entries())t[e]=(t[e]||0)+o}}else n+=1;for(const t of o)0===s[t.colId]&&(t.prev?t.prev.width+=t.width:t.next&&(t.next.width+=t.width),t.remove())}removeRow(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=dt(t[0],yt.tableMain),o=e.getRows();let s=o.length,l=-1;for(const e of t){const t=dt(e,yt.tableRow),i=o.indexOf(t);i<s&&(s=i),i+e.rowspan>l&&(l=i+e.rowspan)}const i={};for(let t=s;t<Math.min(o.length,l);t++){o[t].foreachCellInner((e=>{e.rowspan+t>l&&(i[e.colId]={rowspan:e.rowspan+t-l,colspan:e.colspan,colIndex:e.getColumnIndex()}),e.parent.remove()}))}if(o[l]){const t=o[l],s=e.tableId;for(const[e,{colIndex:o,colspan:l,rowspan:n}]of Object.entries(i))t.insertCell(o,{tableId:s,rowId:t.rowId,colId:e,colspan:l,rowspan:n})}this.fixTableByRemove(e)}removeCol(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=0)return;const e=t[0],o=dt(e,yt.tableMain),s={};for(const e of t)s[e.rowId]||(s[e.rowId]=0),s[e.rowId]+=e.colspan;const l=Math.max(...Object.values(s)),i=e.getColumnIndex(),n=o.descendants(Qt);for(let t=0;t<l;t++){const t=[];let e=0;for(const o of Object.values(n)){const s=t.shift()||0;if(e>0){e-=1;continue}const l=o.removeCell(i-s);l.skipRowNum&&(e+=l.skipRowNum);for(const[e,o]of l.entries())t[e]=(t[e]||0)+o}}const[r]=o.descendants(le);if(r)for(let t=0;t<l;t++)r.removeColByIndex(i);this.fixTableByRemove(o)}mergeCells(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(t.length<=1)return;const e=t.reduce(((t,e,o)=>{const s=e.colId;t[0][s]||(t[0][s]=0),t[0][s]+=e.rowspan;const l=e.rowId;return t[1][l]||(t[1][l]=0),t[1][l]+=e.colspan,0!==o&&(e.moveChildren(t[2]),e.parent.remove()),t}),[{},{},t[0]]),o=Math.max(...Object.values(e[0])),s=Math.max(...Object.values(e[1])),l=e[2];l.colspan=s,l.rowspan=o;const i=dt(l,yt.tableMain);this.fixTableByRemove(i)}splitCell(){if(!this.tableSelection)return;const t=this.tableSelection.selectedTds;if(1!==t.length)return;const e=t[0];if(1===e.colspan&&1===e.rowspan)return;const[o,s]=ht(e,[yt.tableMain,yt.tableRow]),l=o.tableId,i=e.getColumnIndex(),n=o.getColIds().slice(i,i+e.colspan).reverse();let r=s,a=e.rowspan;for(e.colspan=1,e.rowspan=1;r&&a>0;){for(const t of n)r===s&&t===e.colId||r.insertCell(i+(r===s?1:0),{tableId:l,rowId:r.rowId,colId:t,rowspan:1,colspan:1});a-=1,r=r.next}}}const Oe=t=>{Object.assign(yt,t.blotName||{}),Object.assign(It,t.tableUpSize||{}),Object.assign(Mt,t.tableUpEvent||{}),qe.toolName=yt.tableWrapper,kt.blotName=yt.container,ie.blotName=yt.tableWrapper,se.blotName=yt.tableMain,le.blotName=yt.tableColgroup,oe.blotName=yt.tableCol,Jt.blotName=yt.tableBody,Qt.blotName=yt.tableRow,te.blotName=yt.tableCell,Gt.blotName=yt.tableCellInner};export{Ot as BlockOverride,Ht as BlockquoteOverride,Wt as CodeBlockOverride,kt as ContainerFormat,Dt as HeaderOverride,Ft as ListItemOverride,Xt as ScrollOverride,Ie as Scrollbar,ne as TableAlign,Jt as TableBodyFormat,te as TableCellFormat,Gt as TableCellInnerFormat,oe as TableColFormat,le as TableColgroupFormat,se as TableMainFormat,fe as TableMenuCommon,ge as TableMenuContextmenu,we as TableMenuSelect,Ce as TableResizeBox,xe as TableResizeCommon,ye as TableResizeLine,Qt as TableRowFormat,Le as TableSelection,qe as TableUp,Me as TableVitrualScroll,ie as TableWrapperFormat,Zt as allowAttrs,yt as blotName,qe as default,dt as findParentBlot,ht as findParentBlots,Se as getRelativeRect,Ne as isRectanglesIntersect,ve as isTableAlignRight,at as randomId,ke as tableCantInsert,Mt as tableUpEvent,It as tableUpSize,Oe as updateTableConstants};
2
2
  //# sourceMappingURL=index.js.map