/*! * Tiny Advanced Tables plugin * * Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc. * Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/ * * Version: 2.1.0-81 */ !function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const o=e-t;return 0===o?0:o>0?1:-1},o=(e,t,o)=>({major:e,minor:t,patch:o}),n=t=>{const n=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return n?o(e(n[1]),e(n[2]),e(n[3])):o(0,0,0)},r=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(o=n=e,(r=String).prototype.isPrototypeOf(o)||(null===(s=n.constructor)||void 0===s?void 0:s.name)===r.name)?"string":t;var o,n,r,s})(t)===e,s=e=>t=>typeof t===e,l=e=>t=>e===t,c=r("string"),i=r("object"),a=r("array"),m=l(null),u=s("boolean"),d=l(void 0),h=e=>null==e,p=e=>!h(e),g=s("function"),f=s("number");class w{constructor(e,t){this.tag=e,this.value=t}static some(e){return new w(!0,e)}static none(){return w.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?w.some(e(this.value)):w.none()}bind(e){return this.tag?e(this.value):w.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:w.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(null!=e?e:"Called getOrDie on None")}static from(e){return p(e)?w.some(e):w.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}w.singletonNone=new w(!1);const b=()=>{},v=e=>()=>e,y=e=>e,C=(e,t)=>e===t;function x(e,...t){return(...o)=>{const n=t.concat(o);return e.apply(null,n)}}const S=v(!1),T=v(!0),R=Array.prototype.slice,D=Array.prototype.indexOf,O=Array.prototype.push,A=(e,t)=>{return o=e,n=t,D.call(o,n)>-1;var o,n},E=(e,t)=>{for(let o=0,n=e.length;o{const o=[];for(let n=0;n{const o=e.length,n=new Array(o);for(let r=0;r{for(let o=0,n=e.length;o{const o=[],n=[];for(let r=0,s=e.length;r{const o=[];for(let n=0,r=e.length;n{if(0===e.length)return[];{let o=t(e[0]);const n=[];let r=[];for(let s=0,l=e.length;s(((e,t)=>{for(let o=e.length-1;o>=0;o--)t(e[o],o)})(e,((e,n)=>{o=t(o,e,n)})),o),I=(e,t,o)=>(W(e,((e,n)=>{o=t(o,e,n)})),o),P=(e,t)=>((e,t,o)=>{for(let n=0,r=e.length;n(e=>{const t=[];for(let o=0,n=e.length;o{for(let o=0,n=e.length;o{const o=R.call(e,0);return o.sort(t),o},$=(e,t)=>t>=0&&t$(e,0),G=e=>$(e,e.length-1),q=(e,t)=>{for(let o=0;oe.exists((e=>o(e,t))),U=(e,t,o)=>e.isSome()&&t.isSome()?w.some(o(e.getOrDie(),t.getOrDie())):w.none(),K=e=>e.bind(y),Q=(e,t)=>e?w.some(t):w.none(),X=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},Y={fromHtml:(e,t)=>{const o=(t||document).createElement("div");if(o.innerHTML=e,!o.hasChildNodes()||o.childNodes.length>1){const t="HTML does not have a single root node";throw console.error(t,e),new Error(t)}return X(o.childNodes[0])},fromTag:(e,t)=>{const o=(t||document).createElement(e);return X(o)},fromText:(e,t)=>{const o=(t||document).createTextNode(e);return X(o)},fromDom:X,fromPoint:(e,t,o)=>w.from(e.dom.elementFromPoint(t,o)).map(X)},J="undefined"!=typeof window?window:Function("return this;")(),Z=(e,t)=>((e,t)=>{let o=null!=t?t:J;for(let t=0;t{const t=Z("ownerDocument.defaultView",e);return i(e)&&((e=>((e,t)=>{const o=((e,t)=>Z(e,t))(e,t);if(null==o)throw new Error(e+" not available on this browser");return o})("HTMLElement",e))(t).prototype.isPrototypeOf(e)||/^HTML\w*Element$/.test(ee(e).constructor.name))},oe=e=>e.dom.nodeName.toLowerCase(),ne=e=>e.dom.nodeType,re=e=>t=>ne(t)===e,se=e=>8===ne(e)||"#comment"===oe(e),le=re(1),ce=re(3),ie=re(9),ae=re(11),me=e=>t=>le(t)&&oe(t)===e,ue=(e,t)=>{const o=e.dom;if(1!==o.nodeType)return!1;{const e=o;if(void 0!==e.matches)return e.matches(t);if(void 0!==e.msMatchesSelector)return e.msMatchesSelector(t);if(void 0!==e.webkitMatchesSelector)return e.webkitMatchesSelector(t);if(void 0!==e.mozMatchesSelector)return e.mozMatchesSelector(t);throw new Error("Browser lacks native selectors")}},de=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,he=(e,t)=>e.dom===t.dom,pe=ue,ge=e=>Y.fromDom(e.dom.ownerDocument),fe=e=>ie(e)?e:ge(e),we=e=>w.from(e.dom.parentNode).map(Y.fromDom),be=(e,t)=>{const o=g(t)?t:S;let n=e.dom;const r=[];for(;null!==n.parentNode&&void 0!==n.parentNode;){const e=n.parentNode,t=Y.fromDom(e);if(r.push(t),!0===o(t))break;n=e}return r},ve=e=>w.from(e.dom.previousSibling).map(Y.fromDom),ye=e=>w.from(e.dom.nextSibling).map(Y.fromDom),Ce=e=>N(e.dom.childNodes,Y.fromDom),xe=g(Element.prototype.attachShadow)&&g(Node.prototype.getRootNode)?e=>Y.fromDom(e.dom.getRootNode()):fe,Se=e=>Y.fromDom(e.dom.host),Te=e=>{const t=ce(e)?e.dom.parentNode:e.dom;if(null==t||null===t.ownerDocument)return!1;const o=t.ownerDocument;return(e=>{const t=xe(e);return ae(o=t)&&p(o.dom.host)?w.some(t):w.none();var o})(Y.fromDom(t)).fold((()=>o.body.contains(t)),(n=Te,r=Se,e=>n(r(e))));var n,r},Re=(e,t)=>{let o=[];return W(Ce(e),(e=>{t(e)&&(o=o.concat([e])),o=o.concat(Re(e,t))})),o},De=(e,t,o)=>((e,o,n)=>M(be(e,n),(e=>ue(e,t))))(e,0,o),Oe=(e,t)=>((e,o)=>M(Ce(e),(e=>ue(e,t))))(e),Ae=(e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return de(o)?[]:N(o.querySelectorAll(e),Y.fromDom)})(t,e),Ee=(e,t,o)=>{let n=e.dom;const r=g(o)?o:S;for(;n.parentNode;){n=n.parentNode;const e=Y.fromDom(n);if(t(e))return w.some(e);if(r(e))break}return w.none()},ke=(e,t,o)=>Ee(e,(e=>ue(e,t)),o),Ne=(e,t)=>((e,o)=>P(e.dom.childNodes,(e=>{return o=Y.fromDom(e),ue(o,t);var o})).map(Y.fromDom))(e),We=(e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return de(o)?w.none():w.from(o.querySelector(e)).map(Y.fromDom)})(t,e),Le=(e,t,o)=>((e,t,o,n,r)=>((e,t)=>ue(e,t))(o,n)?w.some(o):g(r)&&r(o)?w.none():t(o,n,r))(0,ke,e,t,o),Me=Object.keys,je=Object.hasOwnProperty,Be=(e,t)=>{const o=Me(e);for(let n=0,r=o.length;n{const o=[];return Be(e,((e,n)=>{o.push(t(e,n))})),o},Pe=e=>Ie(e,y),ze=e=>Me(e).length,_e=(e,t)=>Fe(e,t)?w.from(e[t]):w.none(),Fe=(e,t)=>je.call(e,t),$e=e=>{for(const t in e)if(je.call(e,t))return!1;return!0},Ve=(e,t,o)=>{if(!(c(o)||u(o)||f(o)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",o,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,o+"")},Ge=(e,t,o)=>{Ve(e.dom,t,o)},qe=(e,t)=>{const o=e.dom;Be(t,((e,t)=>{Ve(o,t,e)}))},He=(e,t)=>{const o=e.dom.getAttribute(t);return null===o?void 0:o},Ue=(e,t)=>w.from(He(e,t)),Ke=(e,t)=>{e.dom.removeAttribute(t)},Qe=e=>I(e.dom.attributes,((e,t)=>(e[t.name]=t.value,e)),{}),Xe=(e,t,o=0,n)=>{const r=e.indexOf(t,o);return-1!==r&&(!!d(n)||r+t.length<=n)},Ye=(e=>t=>t.replace(e,""))(/^\s+|\s+$/g),Je=e=>!(e=>e.length>0)(e),Ze=e=>void 0!==e.style&&g(e.style.getPropertyValue),et=(e,t,o)=>{((e,t,o)=>{if(!c(o))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",o,":: Element ",e),new Error("CSS value must be a string: "+o);Ze(e)&&e.style.setProperty(t,o)})(e.dom,t,o)},tt=(e,t)=>{const o=e.dom,n=window.getComputedStyle(o).getPropertyValue(t);return""!==n||Te(e)?n:ot(o,t)},ot=(e,t)=>Ze(e)?e.style.getPropertyValue(t):"",nt=(e,t)=>{const o=e.dom,n=ot(o,t);return w.from(n).filter((e=>e.length>0))},rt=(e,t)=>{((e,t)=>{Ze(e)&&e.style.removeProperty(t)})(e.dom,t),H(Ue(e,"style").map(Ye),"")&&Ke(e,"style")},st=(e,t,o=0)=>Ue(e,t).map((e=>parseInt(e,10))).getOr(o),lt=e=>me("col")(e)?st(e,"span",1)>1:((e,t)=>st(e,"colspan",1))(e)>1,ct=v(10),it=(e,t)=>at(e,t,T),at=(e,t,o)=>z(Ce(e),(e=>ue(e,t)?o(e)?[e]:[]:at(e,t,o))),mt=["tfoot","thead","tbody","colgroup"],ut=(e,t,o)=>({element:e,rowspan:t,colspan:o}),dt=(e,t,o)=>({element:e,cells:t,section:o}),ht=(e,t,o)=>({element:e,isNew:t,isLocked:o}),pt=(e,t,o,n)=>({element:e,cells:t,section:o,isNew:n}),gt=(e,t)=>((e,t,o=S)=>o(t)?w.none():A(e,oe(t))?w.some(t):ke(t,e.join(","),(e=>ue(e,"table")||o(e))))(["td","th"],e,t),ft=e=>it(e,"th,td"),wt=e=>ue(e,"colgroup")?Oe(e,"col"):z(yt(e),(e=>Oe(e,"col"))),bt=(e,t)=>Le(e,"table",t),vt=e=>it(e,"tr"),yt=e=>bt(e).fold(v([]),(e=>Oe(e,"colgroup"))),Ct=e=>we(e).map((e=>{const t=oe(e);return(e=>A(mt,e))(t)?t:"tbody"})).getOr("tbody"),xt=(e,t)=>pt(e.element,t,e.section,e.isNew),St=(e,t)=>e.cells[t],Tt=(e,t)=>St(e,t).element,Rt=e=>{const t=L(e,(e=>"colgroup"===e.section));return{rows:t.fail,cols:t.pass}},Dt="data-snooker-locked-cols",Ot=e=>Ue(e,Dt).bind((e=>w.from(e.match(/\d+/g)))).map((e=>((e,t)=>{const o={};for(let n=0,r=e.length;ne+","+t,Et=e=>{const t={},o=[],n=V(e).map((e=>e.element)).bind(bt).bind(Ot).getOr({});let r=0,s=0,l=0;const{pass:c,fail:i}=L(e,(e=>"colgroup"===e.section));W(i,(e=>{const c=[];W(e.cells,(e=>{let o=0;for(;void 0!==t[At(l,o)];)o++;const r=((e,t)=>Fe(e,t)&&void 0!==e[t]&&null!==e[t])(n,o.toString()),i=((e,t,o,n,r,s)=>({element:e,rowspan:t,colspan:o,row:n,column:r,isLocked:s}))(e.element,e.rowspan,e.colspan,l,o,r);for(let n=0;n{const t=(e=>{const t={};let o=0;return W(e.cells,(e=>{const n=e.colspan;k(n,(r=>{const s=o+r;t[s]=((e,t,o)=>({element:e,colspan:t,column:o}))(e.element,n,s)})),o+=n})),t})(e),o=((e,t)=>({element:e,columns:t}))(e.element,Pe(t));return{colgroups:[o],columns:t}})).getOrThunk((()=>({colgroups:[],columns:{}}))),u=((e,t)=>({rows:e,columns:t}))(r,s);return{grid:u,access:t,all:o,columns:a,colgroups:m}},kt=e=>{const t=(e=>{const t=vt(e);return o=[...yt(e),...t],n=Ct,N(o,(e=>{if("colgroup"===oe(e)){const t=N(wt(e),(e=>{const t=st(e,"span",1);return ut(e,1,t)}));return dt(e,t,"colgroup")}{const t=N(ft(e),(e=>{const t=st(e,"rowspan",1),o=st(e,"colspan",1);return ut(e,t,o)}));return dt(e,t,n(e))}}));var o,n})(e);return Et(t)},Nt=Et,Wt=(e,t,o)=>w.from(e.access[At(t,o)]),Lt=(e,t,o)=>{const n=((e,t)=>{const o=z(e.all,(e=>e.cells));return M(o,t)})(e,(e=>o(t,e.element)));return n.length>0?w.some(n[0]):w.none()},Mt=e=>Pe(e.columns),jt=e=>Me(e.columns).length>0,Bt=(e,t)=>w.from(e.columns[t]),It=e=>Y.fromDom(e.getBody()),Pt=e=>t=>he(t,It(e)),zt=e=>Y.fromDom(e.selection.getStart()),_t=(e,t)=>t.column>=e.startCol&&t.column+t.colspan-1<=e.finishCol&&t.row>=e.startRow&&t.row+t.rowspan-1<=e.finishRow,Ft=(e,t,o)=>((e,t,o)=>{const n=Lt(e,t,he),r=Lt(e,o,he);return n.bind((e=>r.map((t=>{return o=e,n=t,{startRow:Math.min(o.row,n.row),startCol:Math.min(o.column,n.column),finishRow:Math.max(o.row+o.rowspan-1,n.row+n.rowspan-1),finishCol:Math.max(o.column+o.colspan-1,n.column+n.colspan-1)};var o,n}))))})(e,t,o).bind((t=>((e,t)=>{let o=!0;const n=x(_t,t);for(let r=t.startRow;r<=t.finishRow;r++)for(let s=t.startCol;s<=t.finishCol;s++)o=o&&Wt(e,r,s).exists(n);return o?w.some(t):w.none()})(e,t))),$t=(e,t,o)=>{const n=Vt(e);return Ft(n,t,o)},Vt=kt,Gt=(e,t)=>{we(e).each((o=>{o.dom.insertBefore(t.dom,e.dom)}))},qt=(e,t)=>{ye(e).fold((()=>{we(e).each((e=>{Ut(e,t)}))}),(e=>{Gt(e,t)}))},Ht=(e,t)=>{(e=>((e,t)=>{const o=e.dom.childNodes;return w.from(o[0]).map(Y.fromDom)})(e))(e).fold((()=>{Ut(e,t)}),(o=>{e.dom.insertBefore(t.dom,o.dom)}))},Ut=(e,t)=>{e.dom.appendChild(t.dom)},Kt=(e,t)=>{Gt(e,t),Ut(t,e)},Qt=(e,t)=>{W(t,((o,n)=>{const r=0===n?e:t[n-1];qt(r,o)}))},Xt=(e,t)=>{W(t,(t=>{Ut(e,t)}))},Yt=e=>{e.dom.textContent="",W(Ce(e),(e=>{Jt(e)}))},Jt=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},Zt=e=>{const t=Ce(e);t.length>0&&Qt(e,t),Jt(e)},eo=((e,t)=>{const o=t=>e(t)?w.from(t.dom.nodeValue):w.none();return{get:t=>{if(!e(t))throw new Error("Can only get text value of a text node");return o(t).getOr("")},getOption:o,set:(t,o)=>{if(!e(t))throw new Error("Can only set raw text value of a text node");t.dom.nodeValue=o}}})(ce),to=e=>eo.get(e),oo=(e,t)=>eo.set(e,t);var no=["body","p","div","article","aside","figcaption","figure","footer","header","nav","section","ol","ul","li","table","thead","tbody","tfoot","caption","tr","td","th","h1","h2","h3","h4","h5","h6","blockquote","pre","address"],ro=()=>({up:v({selector:ke,closest:Le,predicate:Ee,all:be}),down:v({selector:Ae,predicate:Re}),styles:v({get:tt,getRaw:nt,set:et,remove:rt}),attrs:v({get:He,set:Ge,remove:Ke,copyTo:(e,t)=>{const o=Qe(e);qe(t,o)}}),insert:v({before:Gt,after:qt,afterAll:Qt,append:Ut,appendAll:Xt,prepend:Ht,wrap:Kt}),remove:v({unwrap:Zt,remove:Jt}),create:v({nu:Y.fromTag,clone:e=>Y.fromDom(e.dom.cloneNode(!1)),text:Y.fromText}),query:v({comparePosition:(e,t)=>e.dom.compareDocumentPosition(t.dom),prevSibling:ve,nextSibling:ye}),property:v({children:Ce,name:oe,parent:we,document:e=>fe(e).dom,isText:ce,isComment:se,isElement:le,isSpecial:e=>{const t=oe(e);return A(["script","noscript","iframe","noframes","noembed","title","style","textarea","xmp"],t)},getLanguage:e=>le(e)?Ue(e,"lang"):w.none(),getText:to,setText:oo,isBoundary:e=>!!le(e)&&("body"===oe(e)||A(no,oe(e))),isEmptyTag:e=>!!le(e)&&A(["br","img","hr","input"],oe(e)),isNonEditable:e=>le(e)&&"false"===He(e,"contenteditable")}),eq:he,is:pe});const so=(e,t,o,n)=>{const r=t(e,o);return B(n,((o,n)=>{const r=t(e,n);return lo(e,o,r)}),r)},lo=(e,t,o)=>t.bind((t=>o.filter(x(e.eq,t)))),co=ro(),io=e=>ke(e,"table"),ao=(e,t,o)=>We(e,t).bind((t=>We(e,o).bind((e=>{return(o=io,n=[t,e],((e,t,o)=>o.length>0?((e,t,o,n)=>n(e,t,o[0],o.slice(1)))(e,t,o,so):w.none())(co,((e,t)=>o(t)),n)).map((o=>({first:t,last:e,table:o})));var o,n})))),mo=y,uo=e=>{const t=(e,t)=>Ue(e,t).exists((e=>parseInt(e,10)>1));return e.length>0&&_(e,(e=>t(e,"rowspan")||t(e,"colspan")))?w.some(e):w.none()},ho=(e,t,o)=>{return t.length<=1?w.none():(n=e,r=o.firstSelectedSelector,s=o.lastSelectedSelector,ao(n,r,s).bind((e=>{const t=e=>he(n,e),o="thead,tfoot,tbody,table",r=ke(e.first,o,t),s=ke(e.last,o,t);return r.bind((t=>s.bind((o=>he(t,o)?$t(e.table,e.first,e.last):w.none()))))}))).map((e=>({bounds:e,cells:t})));var n,r,s},po="data-mce-selected",go="data-mce-first-selected",fo="data-mce-last-selected",wo={selected:po,selectedSelector:"td["+po+"],th["+po+"]",firstSelected:go,firstSelectedSelector:"td["+go+"],th["+go+"]",lastSelected:fo,lastSelectedSelector:"td["+fo+"],th["+fo+"]"},bo=e=>({element:e,mergable:w.none(),unmergable:w.none(),selection:[e]}),vo=(e,t,o)=>({element:o,mergable:ho(t,e,wo),unmergable:uo(e),selection:mo(e)}),yo=e=>(t,o)=>{const n=oe(t),r="col"===n||"colgroup"===n?bt(s=t).bind((e=>((e,t)=>((e,t)=>{const o=Ae(e,t);return o.length>0?w.some(o):w.none()})(e,t))(e,wo.firstSelectedSelector))).fold(v(s),(e=>e[0])):t;var s;return Le(r,e,o)},Co=yo("th,td,caption"),xo=yo("th,td"),So=e=>{return t=e.model.table.getSelectedCells(),N(t,Y.fromDom);var t},To=e=>{let t,o=!1;return(...n)=>(o||(o=!0,t=e.apply(null,n)),t)},Ro=(e,t)=>({element:e,offset:t}),Do=(e,t,o)=>e.property().isText(t)&&0===e.property().getText(t).trim().length||e.property().isComment(t)?o(t).bind((t=>Do(e,t,o).orThunk((()=>w.some(t))))):w.none(),Oo=(e,t)=>e.property().isText(t)?e.property().getText(t).length:e.property().children(t).length,Ao=(e,t)=>{const o=Do(e,t,e.query().prevSibling).getOr(t);if(e.property().isText(o))return Ro(o,Oo(e,o));const n=e.property().children(o);return n.length>0?Ao(e,n[n.length-1]):Ro(o,Oo(e,o))},Eo=Ao,ko=ro(),No={unsupportedLength:["em","ex","cap","ch","ic","rem","lh","rlh","vw","vh","vi","vb","vmin","vmax","cm","mm","Q","in","pc","pt","px"],fixed:["px","pt"],relative:["%"],empty:[""]},Wo=(()=>{const e="[0-9]+",t="[eE][+-]?"+e,o=e=>`(?:${e})?`,n=["Infinity",e+"\\."+o(e)+o(t),"\\."+e+o(t),e+o(t)].join("|");return new RegExp(`^([+-]?(?:${n}))(.*)$`)})(),Lo=(e,t)=>w.from(Wo.exec(e)).bind((e=>{const o=Number(e[1]),n=e[2];return((e,t)=>E(t,(t=>E(No[t],(t=>e===t)))))(n,t)?w.some({value:o,unit:n}):w.none()})),Mo=(e,t,o)=>((e,t)=>(e=>{const t=parseFloat(e);return isNaN(t)?w.none():w.some(t)})(e).getOr(t))(tt(e,t),o),jo=((e,t)=>{const o=t=>{const o=(e=>e.dom.offsetWidth)(t);if(o<=0||null===o){const o=tt(t,e);return parseFloat(o)||0}return o},n=(e,t)=>I(t,((t,o)=>{const n=tt(e,o),r=void 0===n?0:parseInt(n,10);return isNaN(r)?t:t+r}),0);return{set:(t,o)=>{if(!f(o)&&!o.match(/^[0-9]+$/))throw new Error(e+".set accepts only positive integer values. Value was "+o);const n=t.dom;Ze(n)&&(n.style[e]=o+"px")},get:o,getOuter:o,aggregate:n,max:(e,t,o)=>{const r=n(e,o);return t>r?t-r:0}}})("width"),Bo=e=>jo.get(e),Io=e=>jo.getOuter(e),Po=e=>((e,t)=>{const o=e.dom,n=o.getBoundingClientRect().width||o.offsetWidth;return"border-box"===t?n:((e,t,o,n)=>t-Mo(e,`padding-${o}`,0)-Mo(e,`padding-${n}`,0)-Mo(e,`border-${o}-width`,0)-Mo(e,`border-${n}-width`,0))(e,n,"left","right")})(e,"content-box"),zo=me("col"),_o=(e,t,o)=>{const n=(r=e,w.from(r.dom.parentElement).map(Y.fromDom)).getOrThunk((()=>(e=>{const t=e.dom.body;if(null==t)throw new Error("Body is not available yet");return Y.fromDom(t)})(ge(e))));var r;return t(e)/o(n)*100},Fo=(e,t)=>{et(e,"width",t+"px")},$o=(e,t)=>{et(e,"width",t+"%")},Vo=e=>((e,t)=>nt(e,t).orThunk((()=>Ue(e,t).map((e=>e+"px")))))(e,"width"),Go=e=>_o(e,Bo,Po),qo=e=>{return zo(e)?Bo(e):Mo(t=e,"width",t.dom.offsetWidth);var t},Ho=(e,t,o)=>{et(e,"width",t+o)},Uo=v(/(\d+(\.\d+)?)%/),Ko=(e,t)=>{if(!lt(e)){const o=(e=>Vo(e).bind((e=>Lo(e,["fixed","relative","empty"]))))(e);o.each((o=>{const n=o.value/2;Ho(e,n,o.unit),Ho(t,n,o.unit)}))}},Qo=me("col"),Xo=me("colgroup"),Yo=e=>({element:e,colspan:st(e,"colspan",1),rowspan:st(e,"rowspan",1)}),Jo=(e,t=Yo)=>{const o=o=>{if((e=>"tr"===oe(e)||Xo(e))(o))return Xo((r={element:o}).element)?e.colgroup(r):e.row(r);{const r=o,s=(t=>Qo(t.element)?e.col(t):e.cell(t))(t(r));return n=w.some({item:r,replacement:s}),s}var r};let n=w.none();return{getOrInit:(e,t)=>n.fold((()=>o(e)),(n=>t(e,n.item)?n.replacement:o(e)))}},Zo=e=>N(e,v(0)),en=e=>(t,o,n,r)=>{if(e(n)){const e=Math.max(r,t[o]-Math.abs(n)),s=Math.abs(e-t[o]);return n>=0?s:-s}return n},tn=en((e=>e<0)),on=en(T),nn=()=>{const e=(e,t,o,n,r)=>{const s=on(e,n>=0?o:t,n,r);return((e,t,o,n,r)=>r(e.slice(0,t)).concat(n).concat(r(e.slice(o))))(e,t,o+1,[s,-s],Zo)};return{resizeTable:(e,t,o)=>{o&&e(t)},clampTableDelta:(e,t,o,n,r)=>{if(r){if(o>=0)return o;{const t=I(e,((e,t)=>e+t-n),0);return Math.max(-t,o)}}return tn(e,t,o,n)},calcLeftEdgeDeltas:e,calcMiddleDeltas:(t,o,n,r,s,l)=>e(t,n,r,s,l),calcRightEdgeDeltas:(e,t,o,n,r,s)=>{if(s)return Zo(e);{const t=n/e.length;return N(e,v(t))}},calcRedestributedWidths:(e,t,o,n)=>({delta:0,newSizes:e})}},rn=(e,t)=>Y.fromDom(e.dom.cloneNode(t)),sn=(e,t)=>{const o=((e,t)=>{const o=Y.fromTag(t),n=Qe(e);return qe(o,n),o})(e,t),n=Ce((e=>rn(e,!0))(e));return Xt(o,n),o},ln=(me("th"),(e,t,o)=>ht(o(e.element,t),!0,e.isLocked)),cn=()=>({transformRow:y,transformCell:ln}),an=()=>mn(0,0),mn=(e,t)=>({major:e,minor:t}),un={nu:mn,detect:(e,t)=>{const o=String(t).toLowerCase();return 0===e.length?an():((e,t)=>{const o=((e,t)=>{for(let o=0;oNumber(t.replace(o,"$"+e));return mn(n(1),n(2))})(e,o)},unknown:an},dn=(e,t)=>{const o=String(t).toLowerCase();return P(e,(e=>e.search(o)))},hn=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,pn=e=>t=>Xe(t,e),gn=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:e=>Xe(e,"edge/")&&Xe(e,"chrome")&&Xe(e,"safari")&&Xe(e,"applewebkit")},{name:"Chromium",brand:"Chromium",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,hn],search:e=>Xe(e,"chrome")&&!Xe(e,"chromeframe")},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:e=>Xe(e,"msie")||Xe(e,"trident")},{name:"Opera",versionRegexes:[hn,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:pn("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:pn("firefox")},{name:"Safari",versionRegexes:[hn,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:e=>(Xe(e,"safari")||Xe(e,"mobile/"))&&Xe(e,"applewebkit")}],fn=[{name:"Windows",search:pn("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:e=>Xe(e,"iphone")||Xe(e,"ipad"),versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:pn("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"macOS",search:pn("mac os x"),versionRegexes:[/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:pn("linux"),versionRegexes:[]},{name:"Solaris",search:pn("sunos"),versionRegexes:[]},{name:"FreeBSD",search:pn("freebsd"),versionRegexes:[]},{name:"ChromeOS",search:pn("cros"),versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/]}],wn={browsers:v(gn),oses:v(fn)},bn="Edge",vn="Chromium",yn="Opera",Cn="Firefox",xn="Safari",Sn=e=>{const t=e.current,o=e.version,n=e=>()=>t===e;return{current:t,version:o,isEdge:n(bn),isChromium:n(vn),isIE:n("IE"),isOpera:n(yn),isFirefox:n(Cn),isSafari:n(xn)}},Tn=()=>Sn({current:void 0,version:un.unknown()}),Rn=Sn,Dn=(v(bn),v(vn),v("IE"),v(yn),v(Cn),v(xn),"Windows"),On="Android",An="Linux",En="macOS",kn="Solaris",Nn="FreeBSD",Wn="ChromeOS",Ln=e=>{const t=e.current,o=e.version,n=e=>()=>t===e;return{current:t,version:o,isWindows:n(Dn),isiOS:n("iOS"),isAndroid:n(On),isMacOS:n(En),isLinux:n(An),isSolaris:n(kn),isFreeBSD:n(Nn),isChromeOS:n(Wn)}},Mn=()=>Ln({current:void 0,version:un.unknown()}),jn=Ln,Bn=(v(Dn),v("iOS"),v(On),v(An),v(En),v(kn),v(Nn),v(Wn),e=>window.matchMedia(e).matches);let In=To((()=>((e,t,o)=>{const n=wn.browsers(),r=wn.oses(),s=t.bind((e=>((e,t)=>q(t.brands,(t=>{const o=t.brand.toLowerCase();return P(e,(e=>{var t;return o===(null===(t=e.brand)||void 0===t?void 0:t.toLowerCase())})).map((e=>({current:e.name,version:un.nu(parseInt(t.version,10),0)})))})))(n,e))).orThunk((()=>((e,t)=>dn(e,t).map((e=>{const o=un.detect(e.versionRegexes,t);return{current:e.name,version:o}})))(n,e))).fold(Tn,Rn),l=((e,t)=>dn(e,t).map((e=>{const o=un.detect(e.versionRegexes,t);return{current:e.name,version:o}})))(r,e).fold(Mn,jn),c=((e,t,o,n)=>{const r=e.isiOS()&&!0===/ipad/i.test(o),s=e.isiOS()&&!r,l=e.isiOS()||e.isAndroid(),c=l||n("(pointer:coarse)"),i=r||!s&&l&&n("(min-device-width:768px)"),a=s||l&&!i,m=t.isSafari()&&e.isiOS()&&!1===/safari/i.test(o),u=!a&&!i&&!m;return{isiPad:v(r),isiPhone:v(s),isTablet:v(i),isPhone:v(a),isTouch:v(c),isAndroid:e.isAndroid,isiOS:e.isiOS,isWebView:v(m),isDesktop:v(u)}})(l,s,e,o);return{browser:s,os:l,deviceType:c}})(navigator.userAgent,w.from(navigator.userAgentData),Bn)));const Pn=(e,t=T)=>{const o=e.grid,n=k(o.columns,y),r=k(o.rows,y);return N(n,(o=>zn((()=>z(r,(t=>Wt(e,t,o).filter((e=>e.column===o)).toArray()))),(e=>1===e.colspan&&t(e.element)),(()=>Wt(e,0,o)))))},zn=(e,t,o)=>{const n=e();return P(n,t).orThunk((()=>w.from(n[0]).orThunk(o))).map((e=>e.element))},_n=(e,t)=>({left:e,top:t,translate:(o,n)=>_n(e+o,t+n)}),Fn=_n,$n=(e,t)=>void 0!==e?e:void 0!==t?t:0,Vn=e=>{const t=e.dom.ownerDocument,o=t.body,n=t.defaultView,r=t.documentElement;if(o===e.dom)return Fn(o.offsetLeft,o.offsetTop);const s=$n(null==n?void 0:n.pageYOffset,r.scrollTop),l=$n(null==n?void 0:n.pageXOffset,r.scrollLeft),c=$n(r.clientTop,o.clientTop),i=$n(r.clientLeft,o.clientLeft);return Gn(e).translate(l-i,s-c)},Gn=e=>{const t=e.dom,o=t.ownerDocument.body;return o===t?Fn(o.offsetLeft,o.offsetTop):Te(e)?(e=>{const t=e.getBoundingClientRect();return Fn(t.left,t.top)})(t):Fn(0,0)},qn=(e,t)=>({col:e,x:t}),Hn=e=>Vn(e).left+Io(e),Un=e=>Vn(e).left,Kn=(e,t)=>qn(e,Un(t)),Qn=(e,t)=>qn(e,Hn(t)),Xn=(e,t,o)=>{if(0===o.length)return[];const n=N(o.slice(1),((t,o)=>t.map((t=>e(o,t))))),r=o[o.length-1].map((e=>t(o.length-1,e)));return n.concat([r])},Yn=(Jn={delta:y,edge:Un,positions:e=>Xn(Kn,Qn,e)},Zn={delta:e=>-e,edge:Hn,positions:e=>Xn(Qn,Kn,e)},e=>"rtl"===(e=>"rtl"===tt(e,"direction")?"rtl":"ltr")(e)?Zn:Jn);var Jn,Zn;const er=e=>Yn(e).edge(e),tr=me("col"),or=(e,t,o,n,r,s)=>e.filter(n).fold((()=>s(((e,t)=>{if(t<0||t>=e.length-1)return w.none();const o=e[t].fold((()=>{const o=(e=>{const t=R.call(e,0);return t.reverse(),t})(e.slice(0,t));return q(o,((e,t)=>e.map((e=>({value:e,delta:t+1})))))}),(e=>w.some({value:e,delta:0}))),n=e[t+1].fold((()=>{const o=e.slice(t+1);return q(o,((e,t)=>e.map((e=>({value:e,delta:t+1})))))}),(e=>w.some({value:e,delta:1})));return o.bind((e=>n.map((t=>{const o=t.delta+e.delta;return Math.abs(t.value-e.value)/o}))))})(o,t))),(e=>r(e))),nr=(e,t,o,n)=>{const r=Pn(e),s=jt(e)?(e=>N(Mt(e),(e=>w.from(e.element))))(e):r,l=[w.some(er(t))].concat(N(((e,t)=>Yn(t).positions(e,t))(r,t),(e=>e.map((e=>e.x))))),c=(i=lt,e=>!i(e));var i;return N(s,((e,t)=>or(e,t,l,c,(e=>{if((e=>{const t=In().browser,o=t.isChromium()||t.isFirefox();return!tr(e)||o})(e))return o(e);{const e=((e,t)=>null!=e?t(e):w.none())(r[t],y);return or(e,t,l,c,(e=>n(w.some(Bo(e)))),n)}}),n)))},rr=(e,t,o)=>nr(e,t,qo,(e=>e.getOrThunk(o.minCellWidth))),sr=(e,t)=>()=>Te(e)?t(e):parseFloat(nt(e,"width").getOr("0")),lr=e=>Vo(e).fold((()=>(e=>{const t=sr(e,Bo),o=v(0);return{width:t,pixelWidth:t,getWidths:(t,o)=>rr(t,e,o),getCellDelta:o,singleColumnWidth:v([0]),minCellWidth:o,setElementWidth:b,adjustTableWidth:b,isRelative:!0,label:"none"}})(e)),(t=>{return o=e,n=t,null!==Uo().exec(n)?(e=>{const t=sr(e,(e=>parseFloat((e=>_o(e,Bo,Po)+"%")(e)))),o=sr(e,Bo);return{width:t,pixelWidth:o,getWidths:(t,o)=>((e,t,o)=>nr(e,t,Go,(e=>e.fold((()=>o.minCellWidth()),(e=>e/o.pixelWidth()*100)))))(t,e,o),getCellDelta:e=>e/o()*100,singleColumnWidth:(e,t)=>[100-e],minCellWidth:()=>ct()/o()*100,setElementWidth:$o,adjustTableWidth:o=>{const n=t();$o(e,n+o/100*n)},isRelative:!0,label:"percent"}})(o):(e=>{const t=sr(e,Bo);return{width:t,pixelWidth:t,getWidths:(t,o)=>rr(t,e,o),getCellDelta:y,singleColumnWidth:(e,t)=>[Math.max(ct(),e+t)-e],minCellWidth:ct,setElementWidth:Fo,adjustTableWidth:o=>{const n=t()+o;Fo(e,n)},isRelative:!1,label:"pixel"}})(o);var o,n})),cr=(e,t,o,n)=>{o===n?Ke(e,t):Ge(e,t,o)},ir=(e,t,o)=>{G(Oe(e,t)).fold((()=>Ht(e,o)),(e=>qt(e,o)))},ar=(e,t)=>{const o=[],n=[],r=e=>N(e,(e=>{e.isNew&&o.push(e.element);const t=e.element;return Yt(t),W(e.cells,(e=>{e.isNew&&n.push(e.element),cr(e.element,"colspan",e.colspan,1),cr(e.element,"rowspan",e.rowspan,1),Ut(t,e.element)})),t})),s=e=>z(e,(e=>N(e.cells,(e=>(cr(e.element,"span",e.colspan,1),e.element))))),l=(t,o)=>{const n=((e,t)=>{const o=Ne(e,t).getOrThunk((()=>{const o=Y.fromTag(t,ge(e).dom);return"thead"===t?ir(e,"caption,colgroup",o):"colgroup"===t?ir(e,"caption",o):Ut(e,o),o}));return Yt(o),o})(e,o),l=("colgroup"===o?s:r)(t);Xt(n,l)},c=(t,o)=>{t.length>0?l(t,o):(t=>{Ne(e,t).each(Jt)})(o)},i=[],a=[],m=[],u=[];return W(t,(e=>{switch(e.section){case"thead":i.push(e);break;case"tbody":a.push(e);break;case"tfoot":m.push(e);break;case"colgroup":u.push(e)}})),c(u,"colgroup"),c(i,"thead"),c(a,"tbody"),c(m,"tfoot"),{newRows:o,newCells:n}},mr=(e,t)=>{if(0===e.length)return 0;const o=e[0],n=((e,n)=>{for(let n=0,s=e.length;n{const o=N(e,(e=>N(e.cells,S)));return N(e,((n,r)=>{const s=z(n.cells,((n,s)=>{if(!1===o[r][s]){const m=((e,t,o,n)=>{const r=((e,t)=>e[t])(e,t),s="colgroup"===r.section,l=mr(r.cells.slice(o),n),c=s?1:mr(((e,t)=>N(e,(e=>St(e,t))))(e.slice(t),o),n);return{colspan:l,rowspan:c}})(e,r,s,t);return((e,t,n,r)=>{for(let s=e;sq(e.all,(e=>P(e.cells,(e=>he(t,e.element))))),hr=(e,t,o)=>{const n=(e=>{const t=[],o=e=>{t.push(e)};for(let t=0;tgt(t).bind((t=>dr(e,t))).filter(o))));return Q(n.length>0,n)},pr=(e,t,o,n,r)=>(s,l,c,i)=>{const a=kt(s),m=w.from(null==i?void 0:i.section).getOrThunk(cn),u=t(a,l).map((t=>{const o=((e,t)=>((e,t,o)=>{const n=[];W(e.colgroups,(r=>{const s=[];for(let n=0;nht(e.element,o,!1))).getOrThunk((()=>ht(t.colGap(),!0,!1)));s.push(r)}n.push(pt(r.element,s,"colgroup",o))}));for(let r=0;rht(e.element,o,e.isLocked))).getOrThunk((()=>ht(t.gap(),!0,!1)));s.push(l)}const l=e.all[r],c=pt(l.element,s,l.section,o);n.push(c)}return n})(e,t,!1))(a,c),n=e(o,t,he,r(c),m),s=(e=>{const t=I(Rt(e).rows,((e,t)=>(W(t.cells,((t,o)=>{t.isLocked&&(e[o]=!0)})),e)),{}),o=Ie(t,((e,t)=>parseInt(t,10)));return F(o)})(n.grid);return{info:t,grid:(l=n.grid,ur(l,he)),cursor:n.cursor,lockedColumns:s};var l}));return u.bind((e=>{const t=ar(s,e.grid),r=w.from(null==i?void 0:i.sizing).getOrThunk((()=>lr(s))),l=w.from(null==i?void 0:i.resize).getOrThunk(nn);return o(s,e.grid,e.info,{sizing:r,resize:l,section:m}),n(s),Ke(s,Dt),e.lockedColumns.length>0&&Ge(s,Dt,e.lockedColumns.join(",")),w.some({cursor:e.cursor,newRows:t.newRows,newCells:t.newCells})}))},gr=(e,t)=>gt(t.element).bind((t=>dr(e,t))),fr=(e,t)=>hr(e,t,T),wr=(e,t)=>_(t,(t=>((e,t)=>dr(e,t).exists((e=>!e.isLocked)))(e,t))),br=(e,t)=>((e,t)=>t.mergable)(0,t).filter((t=>wr(e,t.cells))),vr=(e,t)=>((e,t)=>t.unmergable)(0,t).filter((t=>wr(e,t))),yr=["img","br"],Cr=e=>{return(t=e,eo.getOption(t)).filter((e=>0!==e.trim().length||e.indexOf("\xa0")>-1)).isSome()||A(yr,oe(e))||(e=>{return le(t=e)&&te(t.dom)&&"false"===He(e,"contenteditable");var t})(e);var t},xr={scope:["row","col"]},Sr=e=>()=>{const t=Y.fromTag("td",e.dom);return Ut(t,Y.fromTag("br",e.dom)),t},Tr=e=>()=>Y.fromTag("col",e.dom),Rr=e=>()=>Y.fromTag("colgroup",e.dom),Dr=e=>()=>Y.fromTag("tr",e.dom),Or=(e,t,o)=>{const n=sn(e,t);return Be(o,((e,t)=>{null===e?Ke(n,t):Ge(n,t,e)})),n},Ar=(e,t,o)=>{return(n=e,((e,t)=>{const o=e=>{for(let n=0;n{const r=o.join(","),s=De(n,r,(t=>he(t,e)));return B(s,((e,t)=>{const o=rn(t,!1);return Ut(e,o),o}),t)})).getOr(t);var n},Er=(e,t,o)=>{const n=(e,t)=>{((e,t)=>{const o=e.dom,n=t.dom;Ze(o)&&Ze(n)&&(n.style.cssText=o.style.cssText)})(e.element,t),rt(t,"height"),1!==e.colspan&&rt(t,"width")};return{col:o=>{const r=Y.fromTag(oe(o.element),t.dom);return n(o,r),e(o.element,r),r},colgroup:Rr(t),row:Dr(t),cell:r=>{const s=Y.fromTag(oe(r.element),t.dom),l=o.getOr(["strong","em","b","i","span","font","h1","h2","h3","h4","h5","h6","p","div"]),c=l.length>0?Ar(r.element,s,l):s;return Ut(c,Y.fromTag("br")),n(r,s),((e,t)=>{Be(xr,((o,n)=>Ue(e,n).filter((e=>A(o,e))).each((e=>Ge(t,n,e)))))})(r.element,s),e(r.element,s),s},replace:Or,colGap:Tr(t),gap:Sr(t)}},kr=e=>kt(e).grid,Nr=(e,t=!1)=>{return Te(e)?e.dom.isContentEditable:(o=e,Le(o,"[contenteditable]")).fold(v(t),(e=>"true"===Wr(e)));var o},Wr=e=>e.dom.contentEditable,Lr=(e,t,o,n,r)=>N(e,(e=>{const s=t>0&&t{if("colgroup"!==o&&n)return St(e,t);{const t=St(e,r);return ht(l(t.element,s),!0,!1)}})(e,t,e.section,s,o,n,r);return((e,t,o)=>((e,t,o)=>{const n=e.cells,r=n.slice(0,t),s=n.slice(t),l=r.concat(o).concat(s);return xt(e,l)})(e,t,[o]))(e,t,l)})),Mr={...(e=>{if(!a(e))throw new Error("cases must be an array");if(0===e.length)throw new Error("there must be at least one case");const t=[],o={};return W(e,((n,r)=>{const s=Me(n);if(1!==s.length)throw new Error("one and only one name per case");const l=s[0],c=n[l];if(void 0!==o[l])throw new Error("duplicate key detected:"+l);if("cata"===l)throw new Error("cannot have a case named cata (sorry)");if(!a(c))throw new Error("case arguments must be an array");t.push(l),o[l]=(...o)=>{const n=o.length;if(n!==c.length)throw new Error("Wrong number of arguments to case "+l+". Expected "+c.length+" ("+c+"), got "+n);return{fold:(...t)=>{if(t.length!==e.length)throw new Error("Wrong number of arguments to fold. Expected "+e.length+", got "+t.length);return t[r].apply(null,o)},match:e=>{const n=Me(e);if(t.length!==n.length)throw new Error("Wrong number of arguments to match. Expected: "+t.join(",")+"\nActual: "+n.join(","));if(!_(t,(e=>A(n,e))))throw new Error("Not all branches were specified when using match. Specified: "+n.join(", ")+"\nRequired: "+t.join(", "));return e[l].apply(null,o)},log:e=>{console.log(e,{constructors:t,constructor:l,params:o})}}}})),o})([{none:[]},{only:["index"]},{left:["index","next"]},{middle:["prev","index","next"]},{right:["prev","index"]}])},jr=(e,t)=>jt(e)?((e,t)=>{const o=Mt(e);return N(o,((e,o)=>({element:e.element,width:t[o],colspan:e.colspan})))})(e,t):((e,t)=>{const o=(e=>z(e.all,(e=>e.cells)))(e);return N(o,(e=>{const o=((e,t,o)=>{let n=0;for(let r=e;r{const n=jr(e,t);W(n,(e=>{o.setElementWidth(e.element,e.width)}))},Ir=e=>I(e,((e,t)=>E(e,(e=>e.column===t.column))?e:e.concat([t])),[]).sort(((e,t)=>e.column-t.column)),Pr=e=>Nr(e,!0),zr=(e,t,o)=>((e,t)=>({grid:e,cursor:t}))(e,((e,t,o)=>{var n,r;const s=Rt(e).rows;return w.from(null===(r=null===(n=s[t])||void 0===n?void 0:n.cells[o])||void 0===r?void 0:r.element).filter(Pr).orThunk((()=>(e=>q(e,(e=>q(e.cells,(e=>{const t=e.element;return Q(Pr(t),t)})))))(s)))})(e,t,o)),_r=(e,t,o,n)=>((e,t,o,n,r)=>{const s=Nt(t),l=n.getWidths(s,n),c=n.pixelWidth(),{newSizes:i,delta:a}=r.calcRedestributedWidths(l,c,o.pixelDelta,n.isRelative);Br(s,i,n),n.adjustTableWidth(a)})(0,t,o,n.sizing,n.resize),Fr=(e,t)=>{const o=Pn(e),n=Ir(t);return I(n,((e,t)=>e+o[t.column].map(Io).getOr(0)),0)},$r=pr(((e,t,o,n)=>{const r=t.detail,s=r.column,l=r.column,c=Lr(e,l,s,o,n.getOrInit);return zr(c,r.row,l)}),((e,t)=>gr(e,t).filter((e=>!E([e],(e=>0===e.column&&e.isLocked)))).map((t=>({detail:t,pixelDelta:Fr(e,[t])})))),_r,b,Jo),Vr=pr(((e,t,o,n)=>{const r=Ir(t.details),s=((e,t)=>z(e,(e=>{const o=e.cells,n=B(t,((e,t)=>t>=0&&t0?[pt(e.element,n,e.section,e.isNew)]:[]})))(e,N(r,(e=>e.column))),l=s.length>0?s[0].cells.length-1:0;return zr(s,r[0].row,Math.min(r[0].column,l))}),((e,t)=>((e,t)=>hr(e,t,(e=>!e.isLocked)))(e,t).map((t=>({details:t,pixelDelta:-Fr(e,t)})))),_r,(e=>{0===ft(e).length&&Jt(e)}),Jo),Gr=(e,t)=>{const o=He(e,t);return void 0===o||""===o?[]:o.split(" ")},qr=e=>void 0!==e.dom.classList,Hr=e=>e.dom.textContent,Ur=me("th"),Kr=(e,t)=>e&&t?"sectionCells":e?"section":"cells",Qr=e=>{const t=M(e,(e=>Ur(e.element)));return 0===t.length?w.some("td"):t.length===e.length?w.some("th"):w.none()},Xr=e=>{const t=N(e,(e=>(e=>{const t="thead"===e.section,o=H(Qr(e.cells),"th");return"tfoot"===e.section?{type:"footer"}:t||o?{type:"header",subType:Kr(t,o)}:{type:"body"}})(e).type)),o=A(t,"header"),n=A(t,"footer");if(o||n){const e=A(t,"body");return!o||e||n?o||e||!n?w.none():w.some("footer"):w.some("header")}return w.some("body")},Yr={structure:!1,style:!0},Jr={structure:!0,style:!1},Zr=(e,t,o)=>({value:t+1}),es=(e,t,o)=>{const n="A".charCodeAt(0),r=[];let s=t;for(;s>=0;)r.push(String.fromCharCode(n+s%26)),s=Math.floor(s/26)-1;return{value:r.reverse().join("")}},ts=e=>e.options.get("advtable_value_series"),os=e=>{const t=parseFloat(e);return isNaN(t)?w.none():w.some(t)},ns=(e,t)=>et?1:0,rs=(e,t)=>U(os(e),os(t),ns).getOrThunk((()=>((e,t)=>e.localeCompare(t))(e,t))),ss=e=>{const t=(e=>w.from(e.options.get("table_clone_elements")))(e),o=(o,r,s,l)=>(c,i,a,m,u=!1)=>{const d=Y.fromDom(e.getDoc()),h=Er(s,d,t);return r(c)?o(c,i,h).bind((t=>{W(t.newRows,(t=>{((e,t)=>{e.dispatch("NewRow",{node:t})})(e,t.dom)})),W(t.newCells,(t=>{((e,t)=>{e.dispatch("NewCell",{node:t})})(e,t.dom)}));const o=((t,o,r,s)=>{const l=r.filter((e=>Te(e)&&n(e))).or(o.cursor);return l.fold((()=>{const o=ft(t);return V(o).filter(Te).map((o=>{const n=e.dom.createRng();return n.selectNode(o.dom),s&&(e.model.table.clearSelectedCells(t.dom),e.selection.setRng(n),Ge(o,"data-mce-selected","1")),n}))}),(o=>{const n=e.dom.createRng(),r=Eo(ko,o);return n.setStart(r.element.dom,r.offset),n.setEnd(r.element.dom,r.offset),s&&(e.model.table.clearSelectedCells(t.dom),e.selection.setRng(n)),w.some(n)}))})(c,t,a,m);return Te(c)&&((e=>{Ke(e,"data-mce-style");const t=e=>Ke(e,"data-mce-style");W(ft(e),t),W(wt(e),t),W(vt(e),t)})(c),u||((e,t,o)=>{e.dispatch("TableModified",{...o,table:t})})(e,c.dom,l)),o.map((e=>({rng:e,effect:l})))})):w.none()},n=e=>Nr(e,!0),r=(e,t,o)=>((e,t)=>({grid:e,cursor:t}))(e,((e,t,o)=>{var r,s;const l=Rt(e).rows;return w.from(null===(s=null===(r=l[t])||void 0===r?void 0:r.cells[o])||void 0===s?void 0:s.element).filter(n).orThunk((()=>(e=>q(e,(e=>q(e.cells,(e=>{const t=e.element;return Q(n(t),t)})))))(l)))})(e,t,o)),s=(e,t,o,n)=>{const{cols:r,rows:s}=Rt(e),l=j(s,(e=>e.section)),c=N(l,(e=>j(e,(e=>{const o=St(e,t).element;return oe(o)})))),i=z(c,(e=>z(e,(e=>{const r=St(e[0],t).element;return"th"===oe(r)?e:(e=>{const r=N(e,(e=>{const o=St(e,t).element;return{row:e,text:w.from(Hr(o)).getOr("")}})),s=F(r,((e,t)=>{const r=o(e.text,t.text);return n?r:-1*r}));return N(s,(e=>e.row))})(e)}))));return[...r,...i]},l=(e,t,o,n)=>{const{cols:r,rows:s}=Rt(e),l=s[t].cells,c=N(l,(e=>{const t=e.element;return w.from(Hr(t)).getOr("")})),i=me("th"),a=N(s,(e=>{const t=N(e.cells,((e,t)=>({cell:e,column:t,reference:l[t],referenceText:c[t]})));return{...e,zippedCells:t}})),m=N(a,(e=>{const t=j(e.zippedCells,(e=>{const t=e.reference.element;return oe(t)})),r=z(t,(e=>{const t=e[0].reference.element;if(i(t))return N(e,(e=>e.cell));{const{pass:t,fail:r}=L(e,(e=>e.cell.isLocked)),s=F(r,((e,t)=>{const r=o(e.referenceText,t.referenceText);return n?r:-1*r})),l=I(t,((e,t)=>{const o=t.column,n=e.slice(0,o),r=e.slice(o);return n.concat([t]).concat(r)}),s);return N(l,(e=>e.cell))}}));return pt(e.element,r,e.section,e.isNew)}));return[...r,...m]},u=s,d=l,h=(e,t,o,n,r)=>{const{cols:s,rows:l}=Rt(e),c=l.slice(0,t),i=[...s,...l.slice(t,o+1)];return{beforeRows:c,afterRows:l.slice(o+1,e.length),selectionGridBefore:i.map((e=>({...e,cells:e.cells.slice(0,n)}))),selectionGrid:i.map((e=>({...e,cells:e.cells.slice(n,r+1)}))),selectionGridAfter:i.map((e=>({...e,cells:e.cells.slice(r+1,e.cells.length)})))}},p=(e,t)=>{const o=N(t,((t,o)=>{const n=e.selectionGridBefore[o].cells,r=e.selectionGridAfter[o].cells;return{...t,cells:n.concat(t.cells).concat(r)}})),{cols:n,rows:r}=Rt(o);return[...n,...e.beforeRows,...r,...e.afterRows]},g=(e,t,o,n,r,l,c,i)=>{const a=h(e,o,n,r,l),m=s(a.selectionGrid,t-r,c,i);return p(a,m)},C=(e,t,o,n,r,s,c,i)=>{const a=h(e,o,n,r,s),m=l(a.selectionGrid,t-o,c,i);return p(a,m)},x=e=>I(e,((e,t)=>E(e,(e=>e.row===t.row))?e:e.concat([t])),[]).sort(((e,t)=>e.row-t.row)),S=e=>I(e,((e,t)=>E(e,(e=>e.column===t.column))?e:e.concat([t])),[]).sort(((e,t)=>e.column-t.column)),R=e=>I(e,((e,t)=>E(e,(e=>he(e.element,t.element)))?e:e.concat([t])),[]),D=e=>{const t=i(e.attributes)?Ie(e.attributes,((e,t)=>m(e)?e=>Ke(e,t):o=>Ge(o,t,e))):[];return[...t,...((e,t)=>{if(a(e)){for(let o=0,n=e.length;ot=>((e,t)=>{qr(e)?e.dom.classList.add(t):((e,t)=>{((e,t,o)=>{const n=Gr(e,t).concat([o]);Ge(e,t,n.join(" "))})(e,"class",t)})(e,t)})(t,e))):[],t=>{const o=Hr(t)||"",n=(r=e.value,f(r)?String(r):c(r)?r:void 0);var r;const s=c(n)?n:o;Je(s)?((e,t)=>{const o=ge(e).dom,n=Y.fromDom(o.createDocumentFragment()),r=((e,t)=>{const o=(t||document).createElement("div");return o.innerHTML=e,Ce(Y.fromDom(o))})(t,o);Xt(n,r),Yt(e),Ut(e,n)})(t,"
"):((e,t)=>{e.dom.textContent=t})(t,s)}]},O=(e,t,o,n,r,s,l,c)=>{let i;W(t,((t,a)=>{const m=t.element,u={sectionType:s(a),cellType:oe(m),getRowType:l(a),getColType:c(a),classes:(p=m,qr(p)?(e=>{const t=e.dom.classList,o=new Array(t.length);for(let e=0;eGr(e,"class"))(p)),prev:null==i?void 0:i.raw,direction:o},d=e(u,n(a),r(a)),h=D(d);var p;W(h,(e=>e(m))),i=d}))},A=(e,t,o,n,s)=>{const l=g(e,s,0,e.length,s,s,o,n);return r(l,t[0].row,t[0].column)},k=(e,t,o,n,s)=>{const l=x(t),c=S(t),i=g(e,s,l[0].row,l[l.length-1].row,c[0].column,c[c.length-1].column,o,n);return r(i,t[0].row,t[0].column)},M=(e,t,o,n,s)=>{const l=u(e,s,o,n);return r(l,t.row,t.column)},B=(e,t,o,n,s)=>{const l=C(e,s,s,s,0,e[t[0].row].cells.length,o,n);return r(l,t[0].row,t[0].column)},P=(e,t,o,n,s)=>{const l=x(t),c=S(t),i=C(e,s,l[0].row,l[l.length-1].row,c[0].column,c[c.length-1].column,o,n);return r(i,t[0].row,t[0].column)},_=(e,t,o,n,s)=>{const l=d(e,s,o,n);return r(l,t.row,t.column)},$=(e,t,o,n)=>{const s=Rt(e).rows,l=N(s,(e=>St(e,n))),c=R(l),i=To((()=>Qr(c).getOr("")));return O(o,c,"column",y,v(n),(e=>s[e].section),(e=>To((()=>{const t=s[e];return Xr([{cells:t.cells,section:t.section}]).getOr("")}))),(e=>i)),r(e,t.row,t.column)},G=(e,t,o,n)=>{const s=Rt(e).rows,l=s[n],c=R(l.cells),i=To((()=>Xr([{cells:l.cells,section:l.section}]).getOr("")));return O(o,c,"row",v(n),y,(e=>l.section),(e=>i),(e=>To((()=>{const t=N(s,(t=>St(t,e)));return Qr(t).getOr("")})))),r(e,t.row,t.column)},H=(e,t,o,n,r)=>(s,l,c)=>{const i=pr(((r,s)=>e(r,s,t,o,n)),r,b,b,Jo);return i(s,l,c)},U=(e,t,o,n)=>(r,s,l)=>{const c=pr(((n,r)=>e(n,r,t,o)),n,b,b,Jo);return c(r,s,l)},K=o($r,T,Ko,Jr),X=o(Vr,(t=>0==("table"===oe(It(e)))||kr(t).columns>1),b,Jr);return{sortColumnRowsAsc:e=>o(H(A,rs,!0,e,fr),T,b,Jr),sortColumnRowsDesc:e=>o(H(A,rs,!1,e,fr),T,b,Jr),sortSelectionRowsAsc:e=>o(H(k,rs,!0,e,fr),T,b,Jr),sortSelectionRowsDesc:e=>o(H(k,rs,!1,e,fr),T,b,Jr),sortTableRowsAsc:e=>o(H(M,rs,!0,e,gr),T,b,Jr),sortTableRowsDesc:e=>o(H(M,rs,!1,e,gr),T,b,Jr),sortRowColumnsAsc:e=>o(H(B,rs,!0,e,fr),T,b,Jr),sortRowColumnsDesc:e=>o(H(B,rs,!1,e,fr),T,b,Jr),sortSelectionColumnsAsc:e=>o(H(P,rs,!0,e,fr),T,b,Jr),sortSelectionColumnsDesc:e=>o(H(P,rs,!1,e,fr),T,b,Jr),sortTableColumnsAsc:e=>o(H(_,rs,!0,e,gr),T,b,Jr),sortTableColumnsDesc:e=>o(H(_,rs,!1,e,gr),T,b,Jr),insertColumnBefore:K,deleteColumn:X,populateColumn:(e,t)=>o(U($,t,e,gr),T,b,Yr),populateRow:(e,t)=>o(U(G,t,e,gr),T,b,Yr)}},ls="data-snooker-locked-cols",cs=e=>Ue(e,ls).map((e=>z(e.split(","),(e=>{const t=parseInt(e,10);return isNaN(t)?[]:[t]})))).getOr([]),is=(e,t)=>Ge(e,ls,F(t).join(",")),as=(e,t)=>{const o=cs(e);A(o,t)||is(e,o.concat([t]))},ms=(e,t)=>{const o=cs(e);is(e,M(o,(e=>t!==e)))},us="data-snooker-col-series",ds=e=>Ue(e,us),hs=(e,t)=>H(ds(e).map((e=>e.toLowerCase())),t.toLowerCase()),ps=e=>((e,t)=>{const o=e.dom;return!(!o||!o.hasAttribute)&&o.hasAttribute(t)})(e,us),gs=e=>{const t=lr(e),o=kt(e),n=Wt(o,0,0).bind((e=>{const t=e.element;return Lo(tt(t,"width"),["fixed"])})).map((e=>28-e.value)).getOr(0);((e,t,o,n,r)=>{const s=kt(e),l=r.getCellDelta(t),c=r.getWidths(s,r),i=0==s.grid.columns-1,a=n.clampTableDelta(c,0,l,r.minCellWidth(),i),m=((e,t,o,n,r)=>{const s=e.slice(0),l=((e,t)=>0===e.length?Mr.none():1===e.length?Mr.only(0):0===t?Mr.left(0,1):t===e.length-1?Mr.right(t-1,t):t>0&&tn.singleColumnWidth(s[e],o)),((e,t)=>r.calcLeftEdgeDeltas(s,e,t,o,n.minCellWidth(),n.isRelative)),((e,t,l)=>r.calcMiddleDeltas(s,e,t,l,o,n.minCellWidth(),n.isRelative)),((e,t)=>r.calcRightEdgeDeltas(s,e,t,o,n.minCellWidth(),n.isRelative)))})(c,0,a,r,n),u=N(m,((e,t)=>e+c[t]));Br(s,u,r),n.resizeTable(r.adjustTableWidth,a,i)})(e,n,0,nn(),t)},fs=(e,t,o,n,r)=>{((e,t)=>{const o=E(cs(e),(e=>0===e));o&&ms(e,0),t(),o&&as(e,1)})(e,(()=>{o.column(0,t.insertColumnBefore,!0,!0),gs(e),ws(e,t,o,n,r)}))},ws=(e,t,o,n,r)=>{o.table(e,0,0,t.populateColumn(0,((e,t,o)=>{const n=r.generator(e,t,o);return{raw:n,value:n.value,classes:n.classes,attributes:{contenteditable:"false",...n.attributes,"data-mce-resize":!1===r.resizable?"false":null}}})),!0,!0),((e,t)=>{Ge(e,us,t)})(e,n),as(e,0)},bs=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},vs=e=>bt(zt(e),Pt(e)),ys=(e,t)=>{e.execCommand("mceTableToggleSeries",!1,t)},Cs=(e,t,o)=>t.onSetupCellOrRowToggle((()=>((e,t)=>vs(e).exists((e=>Je(t)?!ps(e):hs(e,t))))(e,o))),xs=(e,t)=>({type:"togglemenuitem",text:"None",onAction:()=>{(e=>vs(e).bind(ds))(e).each((t=>{ys(e,{name:t})}))},onSetup:Cs(e,t,"")}),Ss=(e,t,o,n,r)=>({type:"togglemenuitem",text:o,value:n,icon:r,onAction:()=>ys(e,{name:n}),onSetup:Cs(e,t,n)}),Ts=(e,t,o)=>Ie(o,((o,n)=>{const r=w.from(o.title).getOrThunk((()=>{return""===(e=n)?"":e.charAt(0).toUpperCase()+e.substring(1);var e}));return Ss(e,t,r,n)})),Rs=e=>t=>{const o=t.getData();t.close(),e.undoManager.transact((()=>{e.execCommand("mceSortTableAdvanced",!1,o),e.focus(),e.addVisual()}))},Ds=e=>{const t={type:"listbox",name:"sortby",label:"Sort by",items:[{text:"Column",value:"column"},{text:"Row",value:"row"}]},o=bs(w.none()),n=t=>({type:"listbox",name:"roworcol",label:"column"===t?"Column":"Row",items:"column"===t?(()=>{const t=o.get().getOrDie("state must be present"),n=t.limit?t.finishCol+1-t.startCol:t.columns;return k(n,(o=>{const n=t.limit?t.startCol:0,r=(e=>{let t=e,o="";for(;Math.floor(t)>0;)--t,o+=String.fromCharCode("A".charCodeAt(0)+t%26),t/=26;return o.split("").reverse().join("")})(o+n+1);return{text:e.translate(["Column {0}",r]),value:`${o+n}`}}))})():(()=>{const t=o.get().getOrDie("state must be present"),n=t.limit?t.finishRow+1-t.startRow:t.rows;return k(n,(o=>{const n=t.limit?t.startRow:0,r=(o+n+1).toString();return{text:e.translate(["Row {0}",r]),value:`${o+n}`}}))})()}),r=e=>({type:"listbox",name:"sort",label:"Sort",items:["column"===e?{text:"Column",value:"column"}:{text:"Row",value:"row"},{text:"Selection",value:"selection"},{text:"Table",value:"table"}]}),s={type:"listbox",name:"order",label:"Order",items:[{text:"Ascending",value:"ascending"},{text:"Descending",value:"descending"}]},l=e=>({type:"panel",items:[{type:"grid",columns:2,items:[t,n(e),r(e),s]}]}),c=e=>({title:"Advanced Sort",size:"normal",body:l(e),buttons:[{type:"cancel",name:"cancel",text:"Cancel"},{type:"submit",name:"sort",text:"Sort",primary:!0}]}),i=()=>{o.set(w.none())},a=(t,n)=>{if("sortby"===n.name){const n=t.getData(),l=(r=n,s=o.get().getOrDie("state must be present"),"column"===r.sortby?{sortby:"column",roworcol:`${s.startCol}`,sort:"row"===r.sort?"column":r.sort,order:r.order}:{sortby:"row",roworcol:`${s.startRow}`,sort:"column"===r.sort?"row":r.sort,order:r.order}),m={...c(n.sortby),onChange:a,onClose:i,onSubmit:Rs(e),initialData:l};t.redial(m),t.focus("sortby")}var r,s};xo(zt(e)).each((t=>{bt(t,Pt(e)).each((n=>{const r=vo(So(e),n,t),s=t=>{o.set(w.some(t));const n={sortby:"column",roworcol:`${t.startCol}`,sort:"column",order:"ascending"},r={...c("column"),onChange:a,onClose:i,onSubmit:Rs(e),initialData:n};e.windowManager.open(r)},l=kr(n);r.mergable.fold((()=>{$t(n,t,t).each((e=>{const t={...e,...l,limit:!1};s(t)}))}),(e=>{const t={...e.bounds,...l,limit:!0};s(t)}))}))}))},Os=(e,t,o,n)=>{const r=e=>"selection"===e,s=e=>"ascending"===e,l=t=>bt(t,Pt(e)),i=()=>xo(zt(e),Pt(e)).bind((e=>l(e).bind((t=>$t(t,e,e))))),a=()=>i().map((e=>e.startCol)),m=()=>i().map((e=>e.startRow));e.addCommand("mceSortTableByColumnAsc",(()=>{a().each((e=>{o.selection(t.sortTableRowsAsc(e))}))})),e.addCommand("mceSortTableByColumnDesc",(()=>{a().each((e=>{o.selection(t.sortTableRowsDesc(e))}))})),e.addCommand("mceSortTableByRowAsc",(()=>{m().each((e=>{o.selection(t.sortTableColumnsAsc(e))}))})),e.addCommand("mceSortTableByRowDesc",(()=>{m().each((e=>{o.selection(t.sortTableColumnsDesc(e))}))})),e.addCommand("mceSortTableAdvanced",((e,n)=>(e=>{const n=parseInt(e.roworcol,10);"column"===e.sortby?((e,n)=>{(e=>"column"===e)(e.sort)?s(e.order)?o.selection(t.sortColumnRowsAsc(n)):o.selection(t.sortColumnRowsDesc(n)):r(e.sort)?s(e.order)?o.selection(t.sortSelectionRowsAsc(n)):o.selection(t.sortSelectionRowsDesc(n)):s(e.order)?o.selection(t.sortTableRowsAsc(n)):o.selection(t.sortTableRowsDesc(n))})(e,n):((e,n)=>{(e=>"row"===e)(e.sort)?s(e.order)?o.selection(t.sortRowColumnsAsc(n)):o.selection(t.sortRowColumnsDesc(n)):r(e.sort)?s(e.order)?o.selection(t.sortSelectionColumnsAsc(n)):o.selection(t.sortSelectionColumnsDesc(n)):s(e.order)?o.selection(t.sortTableColumnsAsc(n)):o.selection(t.sortTableColumnsDesc(n))})(e,n)})(n))),e.addCommand("mceAdvancedTableSort",(()=>Ds(e))),e.addCommand("mceTableToggleSeries",((r,s)=>{const i=w.from(s.name).filter(c),a=l(zt(e));U(i,a,((e,r)=>{hs(r,e)?((e,t,o)=>{ms(e,0),(e=>{Ke(e,us)})(e),o.column(0,t.deleteColumn,!0,!0)})(r,t,o):_e(n,e).each((n=>{(ps(r)?ws:fs)(r,t,o,e,n)}))}))}))},As=e=>{const t=bs(w.none()),o=bs([]);let n=w.none();const r=me("caption"),s=()=>Co(zt(e),Pt(e)).bind((t=>K(U(bt(t),Co((e=>Y.fromDom(e.selection.getEnd()))(e),Pt(e)).bind(bt),((o,n)=>he(o,n)?r(t)?w.some(bo(t)):w.some(vo(So(e),o,t)):w.none()))))),l=e=>bt(e.element).map((t=>{const o=kt(t),n=fr(o,e).getOr([]),r=I(n,((e,t)=>(t.isLocked&&(e.onAny=!0,0===t.column?e.onFirst=!0:t.column+t.colspan>=o.grid.columns&&(e.onLast=!0)),e)),{onAny:!1,onFirst:!1,onLast:!1});return{mergeable:br(o,e).isSome(),unmergeable:vr(o,e).isSome(),locked:r}})),c=()=>{t.set(To(s)()),n=t.get().bind(l),W(o.get(),(e=>e()))},i=e=>(e(),o.set(o.get().concat([e])),()=>{o.set(M(o.get(),(t=>t!==e)))}),a=(e,o)=>i((()=>t.get().fold((()=>{e.setEnabled(!1)}),(t=>{e.setEnabled(!o(t))}))));return e.on("NodeChange ExecCommand TableSelectorChange",c),{onSetupTable:e=>a(e,(e=>!1)),onSetupCellOrRow:e=>a(e,(e=>r(e.element))),onSetupColumn:e=>t=>a(t,(t=>r(t.element)||(e=>n.exists((t=>t.locked[e])))(e))),onSetupCellOrRowToggle:e=>o=>((e,o,n)=>i((()=>t.get().fold((()=>{e.setEnabled(!1),e.setActive(!1)}),(t=>{e.setEnabled(!(e=>r(e.element))(t)),e.setActive(n(t))})))))(o,0,e),resetTargets:c,targets:()=>t.get()}};tinymce.PluginManager.requireLangPack("advtable","ar,bg_BG,ca,cs,da,de,el,es,eu,fa,fi,fr_FR,he_IL,hi,hr,hu_HU,id,it,ja,kk,ko_KR,ms,nb_NO,nl,pl,pt_BR,pt_PT,ro,ru,sk,sl_SI,sv_SE,th_TH,tr,uk,vi,zh_CN,zh_TW"),tinymce.PluginManager.add("advtable",(e=>{if(((e,o)=>!!e&&-1===((e,o)=>{const n=t(e.major,o.major);if(0!==n)return n;const r=t(e.minor,o.minor);if(0!==r)return r;const s=t(e.patch,o.patch);return 0!==s?s:0})((e=>n((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),n(o)))(tinymce,"6.0.0"))return console.error("Please use Advanced Tables with TinyMCE 6.0.0 or later."),{};(e=>{(0,e.options.register)("advtable_value_series",{processor:"object",default:{numeric:{title:"Numeric",update:!0,resizable:!1,generator:Zr},alpha:{title:"Alpha",update:!0,resizable:!1,generator:es}}})})(e);const o=ss(e),r=As(e),s=(e=>{const t=t=>{e.focus()},o=t=>bt(t,Pt(e)),n=(n,r,s,l,c)=>{xo(zt(e)).each((e=>{o(e).each((o=>{const i=kt(o),a=(e,t)=>Lt(i,e,he).map((e=>e[t])),m=n.orThunk((()=>a(e,"row"))),u=r.orThunk((()=>a(e,"column"))),d=K(U(m,u,((e,t)=>Wt(i,e,t).map((e=>e.element)))));d.bind((t=>{const n=bo(t);return s(o,n,Q(l,e),!0,c)})).each(t)}))}))};return{selection:(n,r)=>{xo(zt(e)).each((s=>{o(s).each((o=>{const l=vo(So(e),o,s);n(o,l,w.none(),!0,r).each(t)}))}))},row:(e,t,o,r)=>n(w.some(e),w.none(),t,o,r),column:(e,t,o,r)=>n(w.none(),w.some(e),t,o,r),table:(o,n,r,s,l,c)=>{const i=kt(o),a=Wt(i,n,r).map((e=>e.element)),m=xo(zt(e)),u=m.bind((e=>Lt(i,e,he))).isSome(),d=a.bind((e=>{const t=bo(e),n=u&&l?m:w.none();return s(o,t,n,u,c)}));d.each(t)}}})(e),l=ts(e);return Os(e,o,s,l),((e,t,o,n)=>{const r=()=>bt(zt(e),Pt(e)),s=(s,l=T)=>{const c=ds(s),i=c.bind((e=>_e(n,e)));U(c,i,((n,c)=>{1===kt(s).grid.columns?r().exists((e=>he(s,e)))?e.execCommand("mceTableDelete"):e.undoManager.transact((()=>{Jt(s)})):!0===c.update&&l()&&ws(s,t,o,n,c)}))};e.on("TableModified",(e=>{const t=Y.fromDom(e.table);s(t,(()=>!1!==e.structure))})),e.on("PreInit",(()=>{((e,t)=>{const o=e=>{const t=[];return h(e)?t:((e=>"thead"===e.name||"tbody"===e.name||"tfoot"===e.name)(e)?t.push(...o(e.firstChild)):"tr"===e.name&&t.push(e),t.concat(o(e.next)))},n=e=>o(e.firstChild);e.parser.addAttributeFilter(us,(e=>{var o;for(const r of e)if("table"===r.name){const e=r.attr(us);if(!1===(null===(o=t[e])||void 0===o?void 0:o.resizable)){const e=n(r);for(const t of e)p(t.firstChild)&&t.firstChild.attr("data-mce-resize","false")}}}))})(e,n)})),e.on("init",(()=>{const t=()=>{const t=xo(zt(e),Pt(e));return e.selection.isCollapsed()&&t.exists((t=>e.dom.isEmpty(t.dom)))};e.on("ExecCommand",(e=>{const o=e.command.toLowerCase();"delete"!==o&&"forwarddelete"!==o||!t()||r().each(s)}),!0),e.on("keyup",(e=>{const o=e.keyCode;8!==o&&46!==o||!t()||r().each(s)}))}))})(e,o,s,l),e.hasPlugin("table")&&(((e,t)=>{const o=(t,o)=>()=>e.execCommand(t,!1,o),n=t.onSetupCellOrRow,r=[{type:"menuitem",text:"Sort table by column ascending",onAction:o("mceSortTableByColumnAsc"),onSetup:n},{type:"menuitem",text:"Sort table by column descending",onAction:o("mceSortTableByColumnDesc"),onSetup:n},{type:"separator"},{type:"menuitem",text:"Advanced sort...",onAction:()=>Ds(e),onSetup:n}];e.ui.registry.addNestedMenuItem("advtablesort",{type:"nestedmenuitem",text:"Sort",getSubmenuItems:v(r)});const s=ts(e);if(1===ze(s)){const o=Me(s)[0];e.ui.registry.addToggleMenuItem("advtablerownumbering",Ss(e,t,"Row numbering",o,"table-row-numbering"))}else $e(s)||e.ui.registry.addNestedMenuItem("advtablerownumbering",{type:"nestedmenuitem",text:"Row numbering",icon:"table-row-numbering",getSubmenuItems:()=>{const o=xs(e,t),n=Ts(e,t,s);return[o].concat(n)}})})(e,r),((e,t)=>{const o=ts(e);if(1===ze(o)){const n=Me(o)[0];e.ui.registry.addToggleButton("advtablerownumbering",{type:"togglebutton",tooltip:"Row numbering",icon:"table-row-numbering",onAction:()=>ys(e,{name:n}),onSetup:Cs(e,t,n)})}else $e(o)||e.ui.registry.addMenuButton("advtablerownumbering",{type:"menubutton",icon:"table-row-numbering",tooltip:"Row numbering",fetch:n=>{const r=xs(e,t),s=Ts(e,t,o);return n([r].concat(s))},onSetup:t.onSetupCellOrRow})})(e,r)),{}}))}();