@guiexpert/table 1.1.110 → 1.1.113

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/index.cjs CHANGED
@@ -38,7 +38,7 @@ export class ${t} implements CellRendererIf {
38
38
 
39
39
  }
40
40
 
41
- `)}}class To{fixJSON(e){const t=[];let s="",o=!1,i=!1;for(let r=0;r<e.length;r++){const l=e[r];if(s+=l,l==='"'&&!i&&(o=!o),l==="\\"&&!i){i=!0;continue}else i=!1;if(!o){if(l==="{"||l==="[")t.push(l);else if(l==="}"||l==="]"){const a=t.pop();if(l==="}"&&a!=="{"||l==="]"&&a!=="[")throw new Error("Invalid JSON structure detected.")}}}for(;t.length>0;){const r=t.pop();r==="{"?s+="}":r==="["&&(s+="]")}return s}}class _r{constructor(){this.property="",this.value="",this.path="",this.propertyItem=new ni("",[new ri("")])}toString(){var e;return`${this.path} -> : ${((e=this.propertyItem)==null?void 0:e.toString())??""}`}}const Io="Entity";function Br(n){let e=$r(Hr(n));return e.includes(Io)||(e=e+Io),e}function $r(n){if(!n||n.length===0)return n;const e=["Array","Arr","List","s"];for(const t of e)if(n.endsWith(t))return n.slice(0,-t.length);return n}function Hr(n){return!n||n.length===0?"":n[0].toUpperCase()+n.slice(1)}class Ra{constructor(){this.debugging=!1}json2PropertyType(e,t=""){let s;if(typeof e=="string"){const o=new To().fixJSON(e);s=this.json2Object(o)}else s=e;return this.object2PropertyType(s,t)}json2Object(e){return JSON.parse(e)}object2PropertyType(e,t=""){const s=this.object2ValueInfos(e,t);this.debugging&&this.logValueInfos(s);const o=this.valueInfos2PropertyType(s);return"name"in o&&(o.name=t),o}json2ValueInfos(e,t=""){let s;if(typeof e=="string"){const o=new To().fixJSON(e);s=this.json2Object(o)}else s=e;return this.object2ValueInfos(s,t)}object2ValueInfos(e,t=""){const s=this.extractValueInfos(e,t),o=this.mergeValueInfos(s);return o.length>0&&(o[0].propertyItem.propertyName=t),this.debugging&&this.logValueInfos(o),o}getParentPath(e){const t=e.lastIndexOf("/");return t===-1?"":e.substring(0,t)}valueInfos2PropertyType(e){const t=e[0].propertyItem.types[0],s=new Map;for(const o of e)s.set(o.path,o);for(const o of e){const i=this.getParentPath(o.path);if(i){const r=s.get(i);if(r){let l=!1;const a=r.propertyItem.types.filter(c=>!Qt.includes(c.type));if(a.length===1){const c=a[0];if(c instanceof We){l=!0;for(const h of o.propertyItem.types)c.items.push(h)}else c instanceof ve&&(l=!0,c.properties.push(o.propertyItem))}if(!l)for(const c of o.propertyItem.types)r.propertyItem.types.push(c)}}}return t||new ri("")}logValueInfos(e){for(let t=0;t<e.length;t++){const s=e[t];s.value=null;const o=t.toString().padStart(2,"0");console.info(o+") "+s.toString()+" parent: "+this.getParentPath(s.path))}}mergeValueInfos(e){const t=[];let s=e.length-1;t.push(e[s]);let o=e[s].path;for(let i=s-1;i>=0;i--){if(e[i].path===o){const r=e[i].propertyItem.types[0];e[s].propertyItem.types.some(l=>l.type===r.type)||e[s].propertyItem.types.push(r)}(i===0||e[i].path!==o)&&(s=i,t.push(e[i]),o=e[s].path)}for(const i of e){const r=this.getParentPath(i.path);if(r){const l=this.getParentPath(r);if(l){const a=this.getFirstValueInfoByPath(e,l);if(Array.isArray(a==null?void 0:a.value)){const c=(a==null?void 0:a.value.length)??0,h=this.countPath(e,i.path);c>h&&(i.propertyItem.types.some(d=>d.type===St)||i.propertyItem.types.push(new Cs(i.property)))}}}}return t.reverse(),t}countPath(e,t){let s=0;for(const o of e)o.path===t&&s++;return s}getFirstValueInfoByPath(e,t){for(let s=e.length-1;s>=0;s--)if(e[s].path===t)return e[s];return null}extractValueInfos(e,t){const s=[],o=(i,r,l)=>{const a=new _r;let c=r.split("/").pop()||"";if(c==="[]"?c=l:c==="root"&&(c=t),a.property=c,a.value=i,a.path=r,a.propertyItem=this.createPropertyItem(i,a.property),s.push(a),i&&typeof i===xt&&!Array.isArray(i)){for(const h in i)if(i.hasOwnProperty(h)){const d=r?`${r}/${h}`:h;o(i[h],d,c)}}else Array.isArray(i)&&i.forEach((h,d)=>{const u=`${r}/[]`;o(h,u,c)})};return o(e,"root",t),s.sort((i,r)=>i.path.localeCompare(r.path))}createPropertyItem(e,t){return new ni(t,[this.createPropertyType(e,t)])}createPropertyType(e,t){return e===null?new Or(t):e===void 0?new Cs(t):typeof e===oi?new Nr(t):typeof e===Ks&&!isNaN(e)?new Pr(t):typeof e===js?new Vr(t):Array.isArray(e)?new We(t):typeof e===xt?new ve(t,Br(t)):new Cs(t)}}class Aa{constructor(){this.orOperator="|",this.rootPropertyType=null,this.rootName="Root",this.renderTypeScriptInterfacesFifo=[],this.renderTypeScriptInterfacesDone=[]}renderTypeScriptInterfaces(e){"name"in e&&(this.rootName=e.name+""),this.rootPropertyType=e;const t=[];return this.rootPropertyType&&(this.renderTypeScriptInterfacesFifo=[],this.renderTypeScriptInterfacesDone=[],this.renderTypeScriptInterfacesRecursive(this.rootPropertyType,t),this.renderTypeScriptInterfacesFifoNext(t)),t}renderTypeScriptInterfacesFifoNext(e){var t;for(;(t=this.renderTypeScriptInterfacesFifo)!=null&&t.length;){const s=this.renderTypeScriptInterfacesFifo.shift();s&&this.renderTypeScriptInterfacesRecursive(s,e,s.propertyName)}}renderTypeScriptInterfacesRecursive(e=this.rootPropertyType,t=[],s=this.rootName){if(!e)return t;if(e instanceof We){for(const o of e.items)if(this.renderTypeScriptInterfacesRecursive(o,t,s),o instanceof ve){const i=o;i!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(i)}}else if(e instanceof ve){const o=e,i=o.className;if(!this.renderTypeScriptInterfacesDone.includes(i)){this.renderTypeScriptInterfacesDone.push(i),t.push(`export interface ${i} {`);for(const r of o.properties){let l=this.propertyItem2InterfaceDateType(r);l==="[]"?l="any[]":l.startsWith("(")&&l.endsWith(")")&&(l=l.substring(1,l.length-1));const a=this.containsUndefinedPropertyType(r)?"?":"";t.push(" "+r.propertyName+a+": "+l+";");for(const c of r.types)if(c instanceof ve)c!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(c);else if(c instanceof We)for(const h of c.items)h instanceof ve&&this.renderTypeScriptInterfacesFifo.push(h)}t.push("}"),t.push("")}}return t}propertyItem2InterfaceDateType(e){var s,o;if(((s=e.types)==null?void 0:s.length)===0)return"any";if(((o=e.types)==null?void 0:o.length)===1)return this.renderType(e.types[0],e);const t=e.types.map(i=>this.renderType(i,e)).filter(i=>i!==St).sort((i,r)=>Qt.includes(i)?100:Qt.includes(r)?-100:i.localeCompare(r)).join(this.orOperator);return t.includes(this.orOperator)?"("+t+")":t}renderType(e,t){if(e instanceof We){const s=e.items.map(o=>this.renderType(o,t)).join(this.orOperator);return s.includes(this.orOperator)?`(${s})[]`:`${s}[]`}return e instanceof ve?e.className:e.type}containsUndefinedPropertyType(e){for(const t of e.types)if(t.type===St)return!0;return!1}}class Qe{constructor(){this.alreadySet=!1}static getInstance(){return Qe.instance||(Qe.instance=new Qe),Qe.instance}setLicenseKey(e){if(e&&!this.alreadySet){const t=document.createElement("meta");t.content="license="+e,t.name="guiexperttable",document.getElementsByTagName("head")[0].appendChild(t),this.alreadySet=!0}}}function U(n){return n&&n.type==="TreeRow"}function Z(n){return n&&n.type==="AreaModelTree"}function li(n){return!!n&&n.type==="CheckboxCellRenderer"}function be(n){return n&&n.type==="CheckboxColumnDef"}function N(n){return!!n&&n.type==="RowNumberColumnDef"}function Gr(n){return!!n&&n.type==="AreaModelAggregateFooter"}function le(n){return!!n&&n.type==="RowGroup"}function Do(n){return U(n)&&le(n.data)}function ne(n){return!!n&&n.kind==="AreaModelRowGroups"}function it(n){return!!n&&n.type==="RowGroupColumnDef"}function Rs(n){return!!n&&n.kind==="PivotTableModel"}function ko(n){return!!n&&n.kind==="AreaModelPivot"}function Xs(n){return!!n&&n.type==="PivotColumnDef"}class es{constructor(e=-1,t=-1,s=-1,o=-1,i,r,l,a=0,c=0,h=0,d=""){this.rowIndex=e,this.rowTop=t,this.columnIndex=s,this.columnLeft=o,this.areaIdent=i,this.sideIdent=r,this.originalEvent=l,this.clickCount=a,this.draggingX=c,this.draggingY=h,this.action=d}clone(){return new es(this.rowIndex,this.rowTop,this.columnIndex,this.columnLeft,this.areaIdent,this.sideIdent,this.originalEvent,this.clickCount,this.draggingX,this.draggingY,this.action)}}class Me{constructor(e=">",t="",s=[]){this.content=e,this.style=t,this.classes=s}}class ai{constructor(e=new Me(">","transform: rotate(90deg) translate(66%, -66%); transform-origin: 0 0;",["gt-table-tree-arrow-expanded"]),t=new Me(">","",["ge-table-tree-arrow-collapsed"]),s=new Me(">","color:transparent;",["gt-table-tree-arrow-hidden"]),o=new Me("↕","",["gt-table-tree-arrow-expanded-all"])){this.arrowExpanded=e,this.arrowCollapsed=t,this.arrowPlaceholder=s,this.arrowExpandCollapseAll=o}}class ci{constructor(e=new Me("↑","",["ge-header-sorted-asc"]),t=new Me("↓","",["ge-header-sorted-desc"]),s=new Me("↑","color:transparent;",[])){this.iconAsc=e,this.iconDesc=t,this.iconPlaceholder=s}}const _s=class _s{constructor(e){this.domService=e,this.rtl=!1,this.startKey="left",this.endKey="right"}setDirection(e){this.rtl=e==="rtl",this.startKey=this.rtl?"right":"left",this.endKey=this.rtl?"left":"right"}getDirection(){return this.rtl?"rtl":"ltr"}toPhysicalStyleKey(e){if(this.rtl){if(e==="left")return"right";if(e==="right")return"left"}return e}getInlineStart(e){return parseFloat(e.style.getPropertyValue(this.startKey))||0}setStyle(e,t,s){return this.domService.setStyle(e,this.toPhysicalStyleKey(t),s),e}applyStyle(e,t){for(const s in t)this.domService.setStyle(e,this.toPhysicalStyleKey(s),t[s]);return e}applyDisplayNoneStyle(e){return this.domService.setStyle(e,"display","none"),e}applyDisplayBlockStyle(e){return this.domService.setStyle(e,"display","block"),e}applyStyleInPx(e,t){return Object.entries(t).forEach(([s,o])=>this.domService.setStyle(e,this.toPhysicalStyleKey(s),o+"px")),e}applyStylePosistionRelative(e){return this.domService.setStyle(e,"position","relative"),this.domService.setStyle(e,"overflow","clip"),e}applyStylePosistionAbsolute(e){return this.domService.setStyle(e,"position","absolute"),e}applyStyleFullSize(e){return this.domService.setStyle(e,"width","100%"),this.domService.setStyle(e,"height","100%"),e}applyStyleOverflowAuto(e="auto",t="auto",s){return this.domService.setStyle(s,"overflow-x",e),this.domService.setStyle(s,"overflow-y",t),s}applyStyleNoPadding(e){return this.domService.setStyle(e,"padding","0"),this.domService.setStyle(e,"margin","0"),this.domService.setStyle(e,"border","0"),e}appendRelativeChildDiv(e){const t=this.applyStylePosistionRelative(this.applyStyleFullSize(this.applyStyleNoPadding(this.domService.createElement("div"))));return this.domService.appendChild(e,t),this.applyStylePosistionAbsolute(e),{parent:e,child:t,cache:{}}}appendText(e,t){const s=this.domService.createText(t);return this.domService.appendChild(e,s),s}addClass(e,t){return e.includes(" ")?e.split(" ").forEach(s=>this.domService.addClass(t,s)):this.domService.addClass(t,e),t}removeClass(e,t){return e.includes(" ")?e.split(" ").forEach(s=>this.domService.removeClass(t,s)):this.domService.removeClass(t,e),t}addClasses(e,t){if(e)for(const s of e)this.domService.addClass(t,s);return t}setAttribute(e,t,s){return t&&s&&this.domService.setAttribute(e,t,s),e}removeAttribute(e,t){return this.domService.removeAttribute?this.domService.removeAttribute(e,t):e.removeAttribute(t),e}setAriaHidden(e){return this.domService.setAttribute(e,"aria-hidden","true"),e}createAreaDivWithClass(e,t,s,o){const i=this.domService.createElement("div");return this.addClass(e,i),this.domService.setAttribute(i,"data-area",s),this.domService.setAttribute(i,"data-side",o),this.domService.appendChild(t,i),i}createDivWithClass(e,t){const s=this.domService.createElement("div");return this.addClass(e,s),this.domService.appendChild(t,s),s}addRowDiv(e,t,s=-1,o,i,r=""){const l=t.index??-1,a=this.getDivOrCreateDiv(l,e);if(this.domService.addClass(a,"ge-table-row-div"),this.domService.addClass(a,`ge-table-row-div-${t.index}`),o==="body"&&i==="center"){const c=((t==null?void 0:t.index)??0)%2===0?"even":"odd";this.domService.addClass(a,`ge-table-row-${c}`)}if(this.domService.setStyle(a,"display","clip"),this.domService.setStyle(a,"position","absolute"),this.domService.setStyle(a,this.startKey,`${t.left}px`),this.domService.setStyle(a,"top",`${t.top}px`),this.domService.setStyle(a,"width",`${t.width}px`),this.domService.setStyle(a,"height",`${t.height}px`),this.domService.setAttribute(a,"data-row-index",`${s}`),this.domService.setAttribute(a,"data-area",`${o}`),r){const c=this.domService.createText(r);this.domService.appendChild(a,c)}return this.domService.appendChild(e.child,a),a}addColumnDiv(e){const{parent:t,geo:s,rowIndex:o=-1,columnIndex:i=-1,areaIdent:r,sideIdent:l,text:a="",treeArrow:c,tableOptions:h,checkedType:d=void 0,sortState:u,checkboxAriaLabel:f,firstDataColumnIndex:g=0}=e,p=h==null?void 0:h.treeOptions,m=h==null?void 0:h.showCheckboxWihoutExtraColumn,b=this.domService.createElement("div");this.domService.addClass(b,"ge-table-col-div"),m&&this.domService.addClass(b,"ge-with-checkbox"),this.domService.addClass(b,`ge-table-col-div-${s.index}`),this.domService.setAttribute(b,"data-col-index",`${s.index}`),this.domService.setAttribute(b,"data-row-index",`${o}`),this.domService.setAttribute(b,"data-area",`${r}`);const y=((s==null?void 0:s.index)??0)%2===0?"even":"odd";if(r==="body"&&l==="center"&&this.domService.addClass(b,`ge-table-column-${y}`),this.domService.setStyle(b,"display","clip"),this.domService.setStyle(b,"position","absolute"),this.domService.setStyle(b,this.startKey,`${s.left}px`),this.domService.setStyle(b,"top",`${s.top}px`),this.domService.setStyle(b,"width",`${s.width}px`),this.domService.setStyle(b,"height",`${s.height}px`),c&&c!=="none"&&(this.domService.addClass(b,"ge-table-col-tree"),this.addArrowDiv(b,c,p,o,i,r)),m&&i===g&&d&&this.addCheckboxToDiv(b,d,r,o,f),a){const C=c!=="none"&&i===g;this.addLabelDiv(b,a,C,o,i,r)}return u&&this.addSortedIcon(b,u,h==null?void 0:h.sortedOptions,i),this.domService.appendChild(t,b),b}addCheckboxToDiv(e,t,s,o,i){const r=this.domService.createElement("div"),l=this.domService.createElement("input");return this.domService.setAttribute(l,"type","checkbox"),this.domService.setAttribute(l,"data-area",`${s}`),this.domService.setAttribute(l,"data-row-index",`${o}`),this.domService.setAttribute(l,"data-input-type","checkbox"),this.domService.setAttribute(l,"tabindex","-1"),t==="full"&&(this.domService.setAttribute(l,"checked",""),l.checked=!0),t==="semi"&&(l.indeterminate=!0),this.domService.addClass(l,"ge-table-row-checkbox"),i&&this.domService.setAttribute(l,"aria-label",i),this.domService.appendChild(r,l),this.domService.setStyle(r,"display","inline"),this.domService.setStyle(r,"width","inherit"),this.domService.setAttribute(r,"data-row-index",`${o}`),this.domService.appendChild(e,r),r}addLabelDiv(e,t="",s=!1,o=-1,i=-1,r="body"){const l=this.domService.createElement("div");if(this.domService.addClass(l,"ge-table-label-div"),this.domService.setStyle(l,"position","relative"),this.domService.setStyle(l,"background","transparent"),this.domService.setStyle(l,"width","100%"),this.domService.setStyle(l,"height","100%"),this.domService.setAttribute(l,"data-row-index",`${o}`),this.domService.setAttribute(l,"data-col-index",`${i}`),this.domService.setAttribute(l,"data-area",`${r}`),t)if(s){const a=this.domService.createText(t);this.domService.appendChild(l,a)}else{const a=this.domService.createElement("div");this.domService.appendChild(l,a);const c=this.domService.createText(t);this.domService.addClass(a,"ge-table-label"),this.domService.appendChild(a,c),this.domService.setAttribute(a,"data-row-index",`${o}`),this.domService.setAttribute(a,"data-col-index",`${i}`),this.domService.setAttribute(a,"data-area",`${r}`)}return this.domService.appendChild(e,l),l}addSortedIcon(e,t="",s=new ci,o=-1){const i=this.domService.createElement("div");this.domService.addClass(i,"ge-table-sorted-icon-div"),this.setAriaHidden(i),this.domService.setStyle(i,"position","absolute"),this.domService.setStyle(i,"top","0"),this.domService.setStyle(i,this.endKey,"0"),this.domService.setStyle(i,"width","20px"),this.domService.setStyle(i,"background","transparent"),this.domService.setStyle(i,"cursor","pointer"),this.domService.setAttribute(i,"data-col-index",`${o}`),this.domService.setAttribute(i,"data-area","header");let r;t==="asc"?r=s.iconAsc:t==="desc"?r=s.iconDesc:r=s.iconPlaceholder;const l=r.content,a=this.domService.createText(l);this.domService.appendChild(i,a),r.style&&this.applyStyleString(i,r.style);for(const c of r.classes)this.domService.addClass(i,c);return this.domService.appendChild(e,i),i}addArrowDiv(e,t="none",s=new ai,o=-1,i=-1,r="body"){const l=this.domService.createElement("div");this.domService.addClass(l,"ge-table-tree-arrow-div"),this.setAriaHidden(l),this.domService.setStyle(l,"display","inline-block"),this.domService.setStyle(l,"position",""),this.domService.setStyle(l,"width","20px"),this.domService.setStyle(l,"background","transparent"),this.domService.setStyle(l,"cursor","pointer"),this.domService.setAttribute(l,"data-row-index",`${o}`),this.domService.setAttribute(l,"data-col-index",`${i}`),this.domService.setAttribute(l,"data-area",`${r}`);let a;t==="expanded"?a=s.arrowExpanded:t==="collapsed"?a=s.arrowCollapsed:a=s.arrowPlaceholder;const c=a.content,h=this.domService.createText(c);this.domService.appendChild(l,h),a.style&&this.applyStyleString(l,a.style);for(const d of a.classes)this.domService.addClass(l,d);return this.domService.appendChild(e,l),l}addColumnBorderDivs(e,t,s,o,i){if(e.verticalBorderVisible){const r=`ge-table-${o}-${i}-vertical-border`;this.addVerticalBorder(s,t,r)}if(e.horizontalBorderVisible){const r=`ge-table-${o}-${i}-horizontal-border`;this.addHorizontalBorder(s,t,r)}return t}addHorizontalBorder(e,t,s="ge-table-body-center-horizontal-border"){const o=this.domService.createElement("div");return this.domService.addClass(o,s),this.setAriaHidden(o),this.domService.setStyle(o,"display","clip"),this.domService.setStyle(o,"position","absolute"),this.domService.setStyle(o,this.startKey,`${e.left}px`),this.domService.setStyle(o,"top",`${e.top}px`),this.domService.setStyle(o,"width",`${e.width}px`),this.domService.setStyle(o,"height","1px"),this.domService.appendChild(t,o),o}addFocusBorderDivs(e,t,s){t={...t,width:t.width+1,height:t.height+1};const o=_s.focusBorderWidthInPx,i=[[t.left,t.top,o,t.height],[t.left+t.width-o,t.top,o,t.height],[t.left,t.top,t.width,o],[t.left,t.top+t.height-o,t.width,o]];for(const[r,l,a,c]of i){const h=this.domService.createElement("div");this.domService.addClass(h,"ge-table-focus-border"),this.setAriaHidden(h),this.domService.setStyle(h,"display","clip"),this.domService.setStyle(h,"position","absolute"),this.domService.setStyle(h,this.startKey,`${r}px`),this.domService.setStyle(h,"top",`${l}px`),this.domService.setStyle(h,"width",`${a}px`),this.domService.setStyle(h,"height",`${c}px`),this.domService.setStyle(h,"z-index","9999"),this.applyStyle(h,s),this.domService.appendChild(e,h)}return e}addVerticalBorder(e,t,s="ge-table-body-center-vertical-border"){const o=this.domService.createElement("div");return this.domService.addClass(o,s),this.setAriaHidden(o),this.domService.setStyle(o,"display","clip"),this.domService.setStyle(o,"position","absolute"),this.domService.setStyle(o,this.startKey,`${e.left}px`),this.domService.setStyle(o,"top",`${e.top}px`),this.domService.setStyle(o,"width","1px"),this.domService.setStyle(o,"height",`${e.height}px`),this.domService.appendChild(t,o),o}addDiv(e,t,s=""){const o=this.domService.createElement("div");return s&&this.domService.addClass(o,s),this.setAriaHidden(o),this.domService.setStyle(o,"display","clip"),this.domService.setStyle(o,"position","absolute"),this.domService.setStyle(o,this.startKey,`${t.left}px`),this.domService.setStyle(o,"top",`${t.top}px`),this.domService.setStyle(o,"width",`${t.width}px`),this.domService.setStyle(o,"height",`${t.height}px`),this.domService.appendChild(e,o),o}applyStyleString(e,t){const s=t.split(";").map(o=>o.trim()).filter(o=>o);for(const o of s){const[i,r]=o.split(":");this.domService.setStyle(e,i.trim(),r.trim())}}getDivOrCreateDiv(e,t){let s=t.cache[e];return s?(s.innerText="",s):(s=this.domService.createElement("div"),t.cache[e]=s,s)}};_s.focusBorderWidthInPx=2;let As=_s;const Rt=n=>n==="header"?"header":n==="footer"?"footer":"body";class Es{constructor(e,t){if(this.rowIdx=-1,this.colIdx=-1,this.action=null,this.inputType=null,this.className="",e!==null&&(e instanceof HTMLDivElement||e instanceof HTMLSpanElement||e instanceof HTMLInputElement)){this.className=e.className,this.action=e.getAttribute("data-ge-action"),this.inputType=e.getAttribute("data-input-type"),this.rowIdx=Number(e.getAttribute("data-row-index")),this.colIdx=Number(e.getAttribute("data-col-index"));const s=e.getAttribute("data-area");if(s&&(this.areaIdent=Rt(s),this.areaModel=t.tableModel.getAreaModel(this.areaIdent),this.row=this.areaModel.getRowByIndex(this.rowIdx)),e instanceof HTMLInputElement){const o=e;this.value=o.value}}}}class Wr{constructor(e){this.tableScope=e,this.doubleClickDelay=500,this.clickMoveTolerance=4,this.lastClickedCellKey="",this.nativeClickCount=0,this.nativeDblClickCount=0,this.mouseDown=!1,this.repaintAfterMouseUp=!1,this.dragging=!1,this.dragGeneration=0,this.lastClicked=0;const t=this.tableScope.listenerAbortController.signal;this.tableScope.hostElement.addEventListener("click",this.onHostElementClicked.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("dblclick",this.onHostElementDblClicked.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("mousedown",this.onMouseDown.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("mousemove",this.onMouseMove.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("mouseup",this.onMouseUp.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("contextmenu",this.onContextmenu.bind(this),{signal:t}),t.addEventListener("abort",()=>clearTimeout(this.lostClickTimer)),this.tableScope.hostElement._MouseHandler="true",this.tableScope.scrollViewport.addEventListener("scroll",()=>this.tableScope.onViewportScroll(),{signal:t}),this.tableScope.scrollViewport.addEventListener("wheel",this.tableScope.onWheel.bind(this.tableScope),{passive:!1,signal:t}),[window,this.tableScope.hostElement].forEach(s=>s.addEventListener("resize",this.tableScope.adjustContainersAndRows.bind(this.tableScope),{signal:t}))}onContextmenu(e){if(this.isBlocked(e)||!(e instanceof MouseEvent))return;this.pressedCell=void 0,this.mouseEvent=e;const t=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.contextmenu(t)}onHostElementClicked(e){this.nativeClickCount++,!this.isBlocked(e)&&this.handleClick(e,this.tableScope.getMouseEventTarget(e))}handleClick(e,t,s){var c;const o=Date.now(),i=s?this.toCellKey(s):this.getCellKey(t),r=e.detail>=2||e.detail===0&&o-this.lastClicked<this.doubleClickDelay&&i===this.lastClickedCellKey;this.lastClicked=o,this.lastClickedCellKey=i;const l=new Es(t,this.tableScope);s&&this.applyCell(l,s);const a=s?this.createCellEvent(e,s):void 0;if(r&&(this.reportedDoubleClick={time:o,cellKey:i}),r&&!this.isClickAction(l)){this.publishGeMouseEvent(e,2,a,t);return}if(l.action==="toggleExpandCollapseAll")this.tableScope.toggleExpandCollapseAll(!this.tableScope.allExpanded),e.preventDefault(),e.stopPropagation();else if(l.action==="toggle-detail")this.tableScope.toggleDetail(l.rowIdx,"mouse"),e.preventDefault(),e.stopPropagation();else if(l.action==="toggleHeaderGroup")this.tableScope.toggleHeaderGroup(l),e.preventDefault(),e.stopPropagation();else if(l.inputType==="checkbox"&&l.areaIdent)this.tableScope.toggleRowCheckbox(l.rowIdx,l.colIdx,l.areaIdent),e.preventDefault(),e.stopPropagation();else if(U(l.row)&&l.areaModel){const h=l.colIdx===this.getArrowColumnIndex()&&e.altKey,d=l.className.includes("ge-table-tree-arrow-div");if(h||d){e.preventDefault(),e.stopPropagation();const u=l.row;this.tableScope.setTreeRowExpanded(u,!u.expanded)}}l.areaIdent==="body"&&((c=this.tableScope.focusModel())==null||c.setFocus(l.rowIdx,l.colIdx)),this.publishGeMouseEvent(e,r?2:1,a,t)}toCellKey(e){return e.areaIdent+":"+e.rowIdx+":"+e.colIdx}applyCell(e,t){e.areaIdent=t.areaIdent,e.areaModel=this.tableScope.tableModel.getAreaModel(t.areaIdent),e.rowIdx=t.rowIdx,e.colIdx=t.colIdx,e.row=e.areaModel.getRowByIndex(t.rowIdx)}createCellEvent(e,t){return this.tableScope.createGeMouseEventForCell(e,{areaIdent:t.areaIdent,sideIdent:t.sideIdent,rowIndex:t.rowIdx,columnIndex:t.colIdx,action:t.action})}getCellKey(e){var s;const t=e instanceof Element?e:null;return(s=t==null?void 0:t.closest)!=null&&s.call(t,"[data-col-index]")?["data-area","data-row-index","data-col-index"].map(o=>{var i;return((i=t.closest("["+o+"]"))==null?void 0:i.getAttribute(o))??""}).join(":"):""}isClickAction(e){return e.action==="toggleExpandCollapseAll"||e.action==="toggleHeaderGroup"||e.action==="toggle-detail"||e.inputType==="checkbox"&&!!e.areaIdent||e.className.includes("ge-table-tree-arrow-div")}onHostElementDblClicked(e){this.nativeDblClickCount++,!this.isBlocked(e)&&this.handleDblClick(e,this.tableScope.getMouseEventTarget(e))}handleDblClick(e,t,s){var c,h,d,u;this.lastClicked=Date.now();const o=s?this.createCellEvent(e,s):this.tableScope.createGeMouseEvent(e),i=new Es(t,this.tableScope),r=(s?s.action:i.action)==="resize-column";if(r){const f=s?s.colIdx:Number(((c=t instanceof Element?t.closest("[data-col-index]"):null)==null?void 0:c.getAttribute("data-col-index"))??-1);this.tableScope.autoResizeColumnByUser(f,e)}if(!r&&t instanceof HTMLElement&&!this.isClickAction(i)){const f=t.closest("[data-col-index]")??t,g=s?s.areaIdent:((h=f.closest("[data-area]"))==null?void 0:h.getAttribute("data-area"))??null,p=Rt(g),m=s?s.rowIdx:Number((d=f.closest("[data-row-index]"))==null?void 0:d.getAttribute("data-row-index")),b=s?s.colIdx:Number(f.getAttribute("data-col-index")),y=this.tableScope.tableModel.getAreaModel(p);if(g&&p==="header"){const C=(u=y.isColumnLetterRow)==null?void 0:u.call(y,m);this.tableScope.tableModel.isSortable(b)&&!C&&(this.tableScope.clearSelection(),this.tableScope.onHeaderDblClicked(e,m,b))}else if(s||f.getAttribute("data-row-index")){const C=y.getRowByIndex(m);if(g&&p==="body"&&y.isEditable(m,b)&&this.tableScope.startEditing(m,b,"edit"),U(C)&&b===this.getArrowColumnIndex()){e.preventDefault(),e.stopPropagation();const v=C;this.tableScope.setTreeRowExpanded(v,!v.expanded)}}}const l=this.reportedDoubleClick,a=s?this.toCellKey(s):this.getCellKey(t);(!l||Date.now()-l.time>this.doubleClickDelay||l.cellKey!==a)&&this.publishGeMouseEvent(e,2,o),this.reportedDoubleClick=void 0}publishGeMouseEvent(e,t,s,o=e.target){var r;this.mouseEvent=e,this.geMouseEventOld=(r=this.geMouseEvent)==null?void 0:r.clone(),this.geMouseEvent=s??this.tableScope.createGeMouseEvent(e),this.geMouseEvent&&(this.geMouseEvent.clickCount=t);const i=this.tableScope.onMouseClicked(this.geMouseEvent,this.geMouseEventOld);this.tableScope.publishGeMouseEvent(this.geMouseEvent),i&&!this.isInteractiveCellElement(o)&&this.tableScope.debounceRepaint()}isInteractiveCellElement(e){const t=e instanceof Element?e:null,s=t==null?void 0:t.closest('input, select, textarea, button, a[href], [contenteditable]:not([contenteditable="false"])');return!!s&&this.tableScope.hostElement.contains(s)}getArrowColumnIndex(){const e=this.tableScope.tableModel.isRowCheckboxVisible();return this.tableScope.getFirstDataColumnIndex()+(e?1:0)}onMouseDown(e){if(!this.isBlocked(e)&&(this.tableScope.cancelPendingRepaint()&&(this.repaintAfterMouseUp=!0),this.pressedCell=e.button===0?this.readPressedCell(e):void 0,!this.dragging)){this.mouseEvent=e,this.startMouseEvent=this.tableScope.createGeMouseEvent(this.mouseEvent),this.flushDraggingEnd(),this.tableScope.onMouseDown(this.startMouseEvent),this.mouseDown=!0;const t=this.tableScope.listenerAbortController.signal;document.addEventListener("mouseup",s=>this.onDocumentMouseUp(s),{once:!0,signal:t})}}onDocumentMouseUp(e){this.mouseDown&&!this.tableScope.hostElement.contains(e.target)&&this.onMouseUp(e)}adjustForRowChanges(e){const t=this.startMouseEvent;(this.mouseDown||this.pendingDraggingEnd)&&t&&t.areaIdent==="body"&&t.rowIndex>=0&&(t.rowIndex=Math.max(0,e.mapIndexOrNext(t.rowIndex)))}onMouseMove(e){var t,s,o,i;if(!this.mouseDown&&((s=(t=this.tableScope).isEventInDetail)!=null&&s.call(t,e))){(i=(o=this.tableScope).hideHover)==null||i.call(o);return}if(!(!this.mouseDown&&this.isBlocked(e)))if(this.mouseEvent=e,this.mouseDown){this.dragging||(this.dragging=!0,this.tableScope.setDragging(!0));const r=this.dragGeneration;requestAnimationFrame(()=>{r===this.dragGeneration&&this.mouseDraggingOnFrame()})}else requestAnimationFrame(this.mouseMoveOnFrame.bind(this))}onMouseUp(e){var s,o;const t=this.pressedCell;if(this.pressedCell=void 0,!(!this.mouseDown&&((o=(s=this.tableScope).isEventInDetail)!=null&&o.call(s,e)))){if(this.mouseEvent=e,t&&e.button===0&&this.checkLostClick(t,e),this.repaintAfterMouseUp&&(this.repaintAfterMouseUp=!1,this.tableScope.debounceRepaint()),this.dragging){const i={evt:e,start:this.startMouseEvent,frameId:0};i.frameId=requestAnimationFrame(()=>this.flushDraggingEnd()),this.pendingDraggingEnd=i}this.mouseDown=!1,this.dragging=!1,this.tableScope.setDragging(!1)}}readPressedCell(e){var f,g,p;const t=this.tableScope.getMouseEventTarget(e),s=t instanceof Element?t:null,o=(f=s==null?void 0:s.closest)==null?void 0:f.call(s,"[data-col-index]"),i=(g=o==null?void 0:o.closest("[data-area]"))==null?void 0:g.getAttribute("data-area"),r=(p=o==null?void 0:o.closest("[data-row-index]"))==null?void 0:p.getAttribute("data-row-index");if(!s||!o||!i||r===null||r===void 0)return;const l=this.tableScope.createGeMouseEvent(e),a=Number(r),c=Number(o.getAttribute("data-col-index")),h=Rt(i);let d,u=!1;if(h==="body"){const m=this.tableScope.tableModel.getBodyModel();d=this.rowAt(m,a),u=typeof d=="object"&&d!==null&&this.rowAt(m,a)===d}return{target:s,areaIdent:h,sideIdent:l.sideIdent,rowIdx:a,colIdx:c,action:l.action,row:d,stableRow:u,clientX:e.clientX,clientY:e.clientY}}checkLostClick(e,t){if(e.target.isConnected)return;const s=t.clientX-e.clientX,o=t.clientY-e.clientY;if(s*s+o*o>this.clickMoveTolerance*this.clickMoveTolerance)return;const i=this.nativeClickCount,r=this.nativeDblClickCount;clearTimeout(this.lostClickTimer),this.lostClickTimer=setTimeout(()=>{if(this.lostClickTimer=void 0,this.nativeClickCount!==i||this.tableScope.isDestroyed()||this.isBlocked(t))return;const l=this.resolveRowIndex(e);if(l<0)return;const a={areaIdent:e.areaIdent,sideIdent:e.sideIdent,rowIdx:l,colIdx:e.colIdx,action:e.action};this.handleClick(t,e.target,a),t.detail===2&&this.nativeDblClickCount===r&&this.handleDblClick(t,e.target,a)},0)}resolveRowIndex(e){if(e.areaIdent!=="body"||!e.stableRow)return e.rowIdx;const t=this.tableScope.tableModel.getBodyModel();if(this.rowAt(t,e.rowIdx)===e.row)return e.rowIdx;const s=t.getRowCount();for(let o=1;o<s;o++){const i=e.rowIdx-o,r=e.rowIdx+o;if(i<0&&r>=s)break;if(i>=0&&this.rowAt(t,i)===e.row)return i;if(r<s&&this.rowAt(t,r)===e.row)return r}return-1}rowAt(e,t){try{return e.getRowByIndex(t)}catch{return}}mouseDraggingOnFrame(){var e;if(this.mouseEvent){const t=this.tableScope.createGeMouseEvent(this.mouseEvent);(e=this.startMouseEvent)!=null&&e.originalEvent&&(t.draggingX=this.mouseEvent.clientX-this.startMouseEvent.originalEvent.clientX,t.draggingY=this.mouseEvent.clientY-this.startMouseEvent.originalEvent.clientY),this.tableScope.mouseDraggingOnFrame(t,this.startMouseEvent)}}flushDraggingEnd(){var s;const e=this.pendingDraggingEnd;if(!e)return;this.pendingDraggingEnd=void 0,cancelAnimationFrame(e.frameId),this.dragGeneration++;const t=this.tableScope.createGeMouseEvent(e.evt);(s=e.start)!=null&&s.originalEvent&&(t.draggingX=e.evt.clientX-e.start.originalEvent.clientX,t.draggingY=e.evt.clientY-e.start.originalEvent.clientY),this.tableScope.mouseDraggingEndOnFrame(t)}mouseMoveOnFrame(){if(this.mouseEvent){const e=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.mouseMove(e)}}isButtonDown(){return this.mouseDown}isBlocked(e){var t,s,o;return(((t=this.tableScope.tableOverlay)==null?void 0:t.isEventBlocked(e))??!1)||!!((o=(s=this.tableScope).isEventInDetail)!=null&&o.call(s,e))}}const Ur=()=>!1;function zr(n){return n.editable===void 0||n.editable===Ur}function hi(n){return typeof n=="number"&&!Number.isNaN(n)}function Ea(n){if(hi(n))return n;if(n instanceof Date){const e=n.getTime();return Number.isNaN(e)?void 0:e}}function di(n,e){const t=n.sum,s=t+e;Number.isFinite(s)&&(n.compensation+=Math.abs(t)>=Math.abs(e)?t-s+e:e-s+t),n.sum=s}function Kr(n){return Number.isFinite(n.sum)?n.sum+n.compensation:n.sum}function jr(n,e){di(n,e.sum),n.compensation+=e.compensation}const Ma={name:"sum",init:()=>({sum:0,compensation:0}),add:(n,e)=>(hi(e)&&di(n,e),n),merge:(n,e)=>(jr(n,e),n),result:n=>Kr(n)},Ta={name:"count",init:()=>0,add:n=>n+1,merge:(n,e)=>n+e,result:n=>n},Ia={name:"avg",init:()=>({sum:0,compensation:0,count:0}),add:(n,e)=>(hi(e)&&(di(n,e),n.count++),n),merge:(n,e)=>(jr(n,e),n.count+=e.count,n),result:n=>n.count?Kr(n)/n.count:void 0};function Wi(n,e){return{name:n,init:()=>({has:!1,value:void 0,key:0}),add:(t,s)=>{const o=Ea(s);return o!==void 0&&(!t.has||e(o,t.key))&&(t.has=!0,t.value=s,t.key=o),t},merge:(t,s)=>(s.has&&(!t.has||e(s.key,t.key))&&(t.has=!0,t.value=s.value,t.key=s.key),t),result:t=>t.has?t.value:void 0}}const Da={name:"countDistinct",init:()=>({values:new Set,dates:new Set}),add:(n,e)=>(e instanceof Date?n.dates.add(e.getTime()):e!=null&&n.values.add(e),n),merge:(n,e)=>(e.values.forEach(t=>n.values.add(t)),e.dates.forEach(t=>n.dates.add(t)),n),result:n=>n.values.size+n.dates.size},ka={name:"first",init:()=>({has:!1,value:void 0}),add:(n,e)=>(n.has||(n.has=!0,n.value=e),n),merge:(n,e)=>(!n.has&&e.has&&(n.has=!0,n.value=e.value),n),result:n=>n.value},Fa={name:"last",init:()=>({has:!1,value:void 0}),add:(n,e)=>(n.has=!0,n.value=e,n),merge:(n,e)=>(e.has&&(n.has=!0,n.value=e.value),n),result:n=>n.value},Oe=Object.freeze({sum:Ma,count:Ta,avg:Ia,min:Wi("min",(n,e)=>n<e),max:Wi("max",(n,e)=>n>e),countDistinct:Da,first:ka,last:Fa});function Ys(n){if(typeof n!="string")return n;const e=Oe[n];if(!e)throw new Error(`Unknown aggregator "${n}" – use one of: ${Object.keys(Oe).join(", ")}, or an own AggregatorIf.`);return e}function cs(n){if(typeof n=="function")return n;const e=n.split(".");return e.length===1?t=>t==null?void 0:t[n]:t=>{let s=t;for(const o of e){if(s==null)return;s=s[o]}return s}}function hs(n,e){const t=typeof e=="string"||!("aggregator"in e)?{aggregator:e}:e,s=Ys(t.aggregator),o=t.value??n;return{key:n,aggregator:s,value:o,getValue:s===Oe.count?void 0:cs(o),format:t.format}}function Js(n,e){const t=e.map(o=>o.aggregator.init()),s=e.length;for(let o=0;o<n.length;o++){const i=n[o];for(let r=0;r<s;r++){const l=e[r];t[r]=l.aggregator.add(t[r],l.getValue?l.getValue(i):i)}}return t}function La(n,e){const t=e.map(o=>o.aggregator.init()),s=e.length;for(let o=0;o<n;o++)for(let i=0;i<s;i++){const r=e[i];t[i]=r.aggregator.add(t[i],r.getValue?r.getValue(o):o)}return t}function Oa(n,e,t){const s=hs("",{aggregator:t,value:e}),[o]=Js(n,[s]);return s.aggregator.result(o)}function Na(n,e){const t=Object.keys(e).map(i=>hs(i,e[i])),s=Js(n,t),o={};return t.forEach((i,r)=>o[i.key]=i.aggregator.result(s[r])),o}const Pa=new Intl.NumberFormat("en-US",{maximumFractionDigits:2});function Ft(n){return n==null?"":typeof n=="number"?Number.isFinite(n)?Pa.format(n):String(n):n instanceof Date?Number.isNaN(n.getTime())?"":n.toLocaleDateString("en-US"):String(n)}const Va=new Set(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal"]),Ui=new Map,_a=new Intl.NumberFormat("en-US",{maximumFractionDigits:0});function Lt(n){if(!n)return;const e=typeof n=="string"?{mode:n}:n;return Xr.includes(e.mode)?e:void 0}const Xr=Object.freeze(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal","differenceFromPrevious","runningTotal","rank"]);function ui(n){return!!n&&Va.has(n)}function qs(n,e){const t=Lt(e);if(typeof n!="number"||Number.isNaN(n)||!t)return n==null?"":`${n}`;if(t.format)return`${t.format(n)??""}`;if(ui(t.mode)){const s=zi(t.fractionDigits??1);let o=Ui.get(s);return o||(o=new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:s,maximumFractionDigits:s}),Ui.set(s,o)),o.format(n)}if(t.mode==="rank")return _a.format(n);if(t.fractionDigits!==void 0){const s=zi(t.fractionDigits);return new Intl.NumberFormat("en-US",{minimumFractionDigits:s,maximumFractionDigits:s}).format(n)}return Ft(n)}function zi(n){return Math.min(10,Math.max(0,Math.trunc(Number(n)||0)))}function ct(n){return typeof n=="number"&&!Number.isNaN(n)}function Zs(n){const e=Oe.sum;let t=e.init();for(let s=0;s<n.length;s++)t=e.add(t,n[s]);return e.result(t)??0}function fi(n,e){const t=n.length,s=new Array(t);switch(e){case"percentOfColumnTotal":case"percentOfGrandTotal":case"percentOfParentTotal":{const o=Zs(n);for(let i=0;i<t;i++)s[i]=Ba(n[i],o);return s}case"runningTotal":{const o=Oe.sum;let i=o.init();for(let r=0;r<t;r++){const l=n[r];i=o.add(i,l),s[r]=ct(l)?o.result(i):void 0}return s}case"differenceFromPrevious":for(let o=0;o<t;o++){const i=n[o],r=o>0?n[o-1]:void 0;s[o]=ct(i)&&ct(r)?i-r:void 0}return s;case"rank":{const o=[];for(let r=0;r<t;r++)ct(n[r])&&o.push(r);o.sort((r,l)=>n[l]-n[r]);let i=0;for(let r=0;r<o.length;r++)(r===0||n[o[r]]!==n[o[r-1]])&&(i=r+1),s[o[r]]=i;return s}default:for(let o=0;o<t;o++)s[o]=ct(n[o])?n[o]:void 0;return s}}function Ba(n,e){return ct(n)&&e!==0?n/e:void 0}class I{constructor(e,t,s){this.code=e,this.message=t,this.position=s,this.type="FormulaError"}toString(){return this.code}}function w(n){return!!n&&typeof n=="object"&&n.type==="FormulaError"}class $a{constructor(e){this.owner=e,this.defsLength=-1,this.computing=new Map,this.contexts=new Map,this.aggregates=new Map,this.aggSignal=void 0,this.aggLength=-1}invalidate(){this.getters=void 0,this.showValuesAs=void 0,this.properties=void 0,this.aggregates.clear()}getter(e){if(e!==void 0)return this.lookup().get(e)}hasGetters(){return this.lookup().size>0}isCalculated(e){return this.lookup().has(e)}hasColumn(e){return this.lookup(),this.properties.has(e)}getShowValuesAs(e){if(e!==void 0)return this.lookup(),this.showValuesAs.get(e)}hasShowValuesAs(){return this.lookup(),this.showValuesAs.size>0}get(e,t){const s=this.lookup().get(t);if(!s)return this.owner.readPath(e,t);if(e!=null)return this.call(s,e,t)}aggregate(e,t){var c;if((c=this.computing.get(e))!=null&&c.size)return new I("#CIRC!",`Circular reference: the column "${e}" uses its own aggregate`);const s=this.owner.getAggregationSource();(s.signal!==this.aggSignal||s.length!==this.aggLength)&&(this.aggregates.clear(),this.aggSignal=s.signal,this.aggLength=s.length);const o=Ys(t),i=`${o.name}\0${e}`;if(this.aggregates.has(i))return this.aggregates.get(i);const r=s.rows();let l=o.init(),a;for(let h=0;h<r.length;h++){const d=this.get(r[h],e);if(w(d)&&d.code==="#CIRC!"){a=d;break}l=o.add(l,d)}return a===void 0&&(a=o.result(l)),this.aggregates.set(i,a),a}context(e){let t=this.contexts.get(e);return t||(t={property:e,getValue:(s,o)=>this.get(s,o),hasColumn:s=>this.hasColumn(s),isCalculated:s=>{var o,i;return this.isCalculated(s)||!!((i=(o=this.owner).isSheetFormula)!=null&&i.call(o,s))},aggregate:(s,o)=>this.aggregate(s,o)},this.contexts.set(e,t)),t}call(e,t,s){let o=this.computing.get(s);if(o!=null&&o.has(t))return new I("#CIRC!",`Circular reference: the column "${s}" depends on itself`);o||(o=new Set,this.computing.set(s,o)),o.add(t);try{return e(t,this.context(s))}catch(i){return new I("#VALUE!",`valueGetter of "${s}": ${i instanceof Error?i.message.slice(0,200):"failed"}`)}finally{o.delete(t)}}lookup(){const e=this.owner.getColumnDefsForValues()??[];if(this.getters&&this.defsLength===e.length)return this.getters;const t=new Map,s=new Map,o=new Set;for(const i of e){if(!i)continue;o.add(i.property),typeof i.valueGetter=="function"&&t.set(i.property,i.valueGetter);const r=Lt(i.showValuesAs);r&&s.set(i.property,r)}return this.getters=t,this.showValuesAs=s,this.properties=o,this.defsLength=e.length,t}}class Ot{constructor(){this.type="AggregateCellRenderer"}render(e,t,s,o,i,r,l){const a=i.getTextValueAt(t,s);if(!a)return;const c=l.createElement("div");l.addClass(c,"ge-table-label-div");const h=l.createElement("div");l.addClass(h,"ge-table-label"),l.setAttribute(h,"data-row-index",`${t}`),l.setAttribute(h,"data-col-index",`${s}`),l.setAttribute(h,"data-area",o),l.appendChild(h,l.createText(a)),l.appendChild(c,h),l.appendChild(e,c)}}class ds{constructor(e,t=[],s=-1){this.areaIdent=e,this.columnDefs=t,this.defaultRowHeight=s,this.rowSelectionModel=void 0,this.yPositions=[],this.defaultEditable=!1,this.cellRenderers=t.map(o=>o.rendererMap[e])}getTextValueAt(e,t){return""+this.getValueAt(e,t)}getTooltipAt(e,t){var s;if((s=this.sheetCells)!=null&&s.isFormulaColumnIndex(t)){const o=this.getValueAt(e,t);if(w(o))return o.message}return""}getCellRenderer(e,t){if(t<this.cellRenderers.length)return this.cellRenderers[t]}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){var s;return(s=this.sheetCells)!=null&&s.isFormulaColumnIndex(t)&&w(this.getValueAt(e,t))?["ge-table-cell-error"]:[]}getCustomStyleAt(e,t){}getRowspanAt(e,t){return 0}getRowByIndex(e){}isRowCheckable(e){return!0}isRowChecked(e){var s;const t=this.getRowByIndex(e);return(s=this.rowSelectionModel)==null?void 0:s.isRowChecked(t)}setRowChecked(e,t){if(this.rowSelectionModel){const s=this.getRowByIndex(e);this.rowSelectionModel.checkRow(s,t)}}getMaxColspan(){return 31}getMaxRowspan(){return 31}getYPosByRowIndex(e){var o;const t=(o=this.getConstantRowHeight)==null?void 0:o.call(this);if(t!==void 0&&t>0)return t*e;let s=0;for(let i=0;i<e;i++)s+=this.getRowHeight(i);return s}init(){!this.yPositions.length&&this.getRowCount()!==void 0&&this.defaultRowHeight===-1&&this.calcYPositions()}isFilterable(){return this.areaIdent==="body"}doSort(e){return!1}sort(e){}isEditable(e,t){var o,i;const s=(o=this.columnDefs)==null?void 0:o[t];return this.areaIdent==="body"&&(s!=null&&s.valueGetter)&&!s.valueSetter?!1:this.defaultEditable&&this.areaIdent==="body"&&s&&zr(s)?!be(s)&&!N(s)&&!it(s):((i=s==null?void 0:s.editable)==null?void 0:i.call(s))??!1}setValue(e,t,s){var a;const o=(a=this.columnDefs[t])==null?void 0:a.editInputPipe;o&&(s=o(s,e,t));const i=this.getRowByIndex(e),r=this.columnDefs[t];if(this.areaIdent==="body"&&(r!=null&&r.valueGetter))return this.setCalculatedValue(i,r,s);const l=this.columnDefs[t].property;return l.includes(".")?this.setPropertyValue(i,l.split("."),s):(i[l]=s,!0)}isSelectable(e,t){return!0}changeColumnOrder(e,t){this.arrayMove(this.cellRenderers,e,t)}setPropertyValue(e,t,s){const o=t.shift();if(o){const i=e[o];return i&&t.length?this.setPropertyValue(i,t,s):(e[o]=s,!0)}return!1}arrayMove(e,t,s){const o=e.splice(t,1)[0];return e.splice(s,0,o),e}calcYPositions(){const e=this.getRowCount();this.yPositions=new Array(e+1),this.yPositions[0]=0;for(let t=0;t<e;t++)this.yPositions[t+1]=this.getRowHeight(t)+this.yPositions[t]}isCalculatedProperty(e){var t;return this.getColumnValues().isCalculated(e)||!!((t=this.sheetCells)!=null&&t.isFormulaProperty(e))}getRowValue(e,t){U(e)&&(e=e.data);const s=this.getColumnValues().get(e,t);return this.sheetCells&&typeof s=="string"?this.sheetCells.valueOfProperty(e,t,s):s}hasDerivedColumns(){const e=this.getColumnValues();return e.hasGetters()||e.hasShowValuesAs()}isDerivedProperty(e){const t=this.getColumnValues();return t.isCalculated(e)||!!t.getShowValuesAs(e)}getColumnValues(){return this.columnValuesInstance??(this.columnValuesInstance=new $a({getColumnDefsForValues:()=>this.areaIdent==="body"?this.columnDefs:[],readPath:(e,t)=>{const s=this.readPropertyPath(e,t);return this.sheetCells&&typeof s=="string"?this.sheetCells.valueOfProperty(e,t,s):s},getAggregationSource:()=>this.getAggregationSourceForValues(),isSheetFormula:e=>{var t;return!!((t=this.sheetCells)!=null&&t.isFormulaProperty(e))}}))}invalidateColumnValues(){var e;(e=this.columnValuesInstance)==null||e.invalidate()}readPropertyPath(e,t){if(e==null||!t)return;let s=e;for(const o of t.split(".")){if(s==null)return;s=s[o]}return s}getAggregationSourceForValues(){const e=this.getRowCount();return{signal:void 0,length:e,rows:()=>Array.from({length:e},(t,s)=>this.getRowByIndex(s))}}setCalculatedValue(e,t,s){return!t.valueSetter||e===void 0||e===null?!1:(U(e)&&(e=e.data),t.valueSetter(e,s)!==!1)}getCalculatedText(e,t){if(e===void 0)return;const s=this.getColumnValues(),o=s.getShowValuesAs(e),i=s.isCalculated(e);if(i&&w(t))return t.code;if(o)return qs(t,o);if(i)return t==null?"":`${t}`}getCalculatedRenderer(e){if(e!==void 0&&this.getColumnValues().getShowValuesAs(e))return this.calcTextRenderer??(this.calcTextRenderer=new Ot)}addCalculatedClasses(e,t,s){return t!==void 0&&this.getColumnValues().isCalculated(t)&&w(s())?[...e,"ge-table-cell-error"]:e}}class gi{genericSortComparator(e,t,s){if(typeof e=="number"&&typeof t=="number")return s*(e-t);if(typeof e=="string"&&typeof t=="string")return s*e.localeCompare(t);if(typeof e=="boolean"&&typeof t=="boolean")return s*((e?-1:1)-(t?-1:1));if(e instanceof Date&&t instanceof Date)return s*(e.getTime()-t.getTime());if(e instanceof Array&&t instanceof Array){const o=e,i=t;if(o.length&&i.length)return this.genericSortComparator(o[0],i[0],s)}return s*(""+e).localeCompare(""+t)}}function rt(n,e){return Ha(n,e)?n:Array.from(new Set(n)).filter(t=>Number.isInteger(t)&&t>=0&&t<e).sort((t,s)=>t-s)}function Ha(n,e){let t=-1;for(const s of n){if(!Number.isInteger(s)||s<=t||s>=e)return!1;t=s}return!0}function pi(n){return n.position==="before"?n.rowIndex:n.rowIndex+1}function Fo(n,e){if(!n.length)return-1;const t=pi(e);return t-n.filter(s=>s<t).length}function Yr(n,e,t){const s=rt(e,n.length);if(!s.length)return-1;const o=Math.min(Math.max(0,t),n.length),i=new Uint8Array(n.length);s.forEach(h=>i[h]=1);const r=new Array(s.length);s.forEach((h,d)=>r[d]=n[h]);const l=[];let a=-1;for(let h=0;h<=n.length;h++)h===o&&(a=l.length),h<n.length&&!i[h]&&l.push(n[h]);let c=0;for(let h=0;h<a;h++)n[c++]=l[h];for(const h of r)n[c++]=h;for(let h=a;h<l.length;h++)n[c++]=l[h];return a}function mi(n){const e=new Set(n);return n.filter(t=>{for(let s=t.parent;s;s=s.parent)if(e.has(s))return!1;return!0})}function bi(n,e){if(!e||!n.length)return!1;const t=new Set(n);for(let s=e;s;s=s.parent)if(t.has(s))return!1;return!0}function Jr(n,e,t,s){const o=mi(e);if(!bi(o,t))return!1;for(const a of o){const c=a.parent?a.parent.children:n,h=(c==null?void 0:c.indexOf(a))??-1;c&&h>-1&&c.splice(h,1)}let i,r,l;s==="inside"?(i=t,t.children=t.children??[],r=t.children,l=r.length,t.expanded=!0):(i=t.parent,r=i?i.children??(i.children=[]):n,l=r.indexOf(t)+(s==="after"?1:0)),r.splice(l,0,...o);for(const a of o)a.parent=i,qr(a,i?i.deep+1:0);return!0}function qr(n,e){n.deep=e;for(const t of n.children??[])qr(t,e+1)}function Qs(n,e,t,s){return n===e&&s.position!=="inside"&&Number.isInteger(s.rowIndex)&&s.rowIndex>=0&&s.rowIndex<n&&rt(t,n).length>0}function wi(n,e,t,s){if(!Qs(n.length,e.length,t,s))return!1;if(Yr(n,rt(t,n.length),pi(s)),e!==n)for(let o=0;o<n.length;o++)e[o]=n[o];return!0}function Ga(n,e,t,s){if(e<1)return-1;if(s&&s>0)return Math.min(e-1,Math.max(0,Math.floor(n/s)));let o=0,i=e-1;for(;o<i;){const r=o+i+1>>1;t(r)<=n?o=r:i=r-1}return o}const Wa=new Int32Array(0);class z extends ds{constructor(e,t,s,o=[],i="ge-selected-row",r="ge-focused-row"){super(e,o,s),this.areaIdent=e,this.rows=t,this.defaultRowHeight=s,this.columnDefs=o,this.selectedRowClass=i,this.focusedRowClass=r,this.sorterService=new gi,this.displayInDataOrder=!0,this.showValuesCache=new Map,this._focusedRowIndex=0,this.filteredRows=[...t],this.properties=o.map(l=>l.property)}getFocusedRowIndex(){return this._focusedRowIndex}setFocusedRowIndex(e){this._focusedRowIndex=e}setRows(e){this.rows=e,this.filteredRows=[...e],this.displayInDataOrder=!0,this.showValuesCache.clear()}appendRows(e,t={}){const s=this.rows,o=t.maxRows!==void 0&&t.maxRows>=0?Math.floor(t.maxRows):Number.POSITIVE_INFINITY,i=Math.max(0,s.length+e.length-o),r=i>0?Math.max(i,Math.ceil(o/100)):0,l=Math.min(r,s.length),a=Math.max(0,i-l),c=l>0?this.removeFirstRows(l):Wa,h=[],d=t.filter;for(let f=a;f<e.length;f++){const g=e[f];s.push(g),(!d||d(g))&&h.push(g)}const u=t.compare?this.mergeSorted(h,t.compare):this.appendShown(h);return(h.length||c.length)&&this.showValuesCache.clear(),{added:e.length-a,shown:h.length,removed:l,removedPositions:c,insertedPositions:u}}removeFirstRows(e){const t=this.rows.splice(0,e),s=this.filteredRows;if(this.displayInDataOrder){let l=0;for(let c=0;c<t.length&&l<s.length;c++)s[l]===t[c]&&l++;s.splice(0,l);const a=new Int32Array(l);for(let c=0;c<l;c++)a[c]=c;return a}const o=new Set(t),i=[];let r=0;for(let l=0;l<s.length;l++){const a=s[l];o.has(a)?i.push(l):s[r++]=a}return s.length=r,Int32Array.from(i)}appendShown(e){const t=this.filteredRows,s=new Int32Array(e.length);for(let o=0;o<e.length;o++)s[o]=t.length,t.push(e[o]);return s}mergeSorted(e,t){const s=this.filteredRows,o=e.length,i=new Int32Array(o);if(!o)return i;e.sort(t),this.displayInDataOrder=!1;let r=s.length;for(let l=0;l<o;l++)s.push(e[l]);for(let l=o-1;l>=0;l--){const a=e[l];let c=0,h=r;for(;c<h;){const d=c+h>>>1;t(s[d],a)>0?h=d:c=d+1}c<r&&s.copyWithin(c+l+1,c,r),s[c+l]=a,i[l]=c+l,r=c}return i}createSortComparator(e){const t=e.filter(({sortState:s})=>s==="asc"||s==="desc").map(({columnIndex:s,sortState:o})=>this.genericFlatTableSortComparator(this.properties[s],o==="asc"?1:-1));if(t.length)return(s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}}filterRowsByPredict(e){this.rows=this.rows.filter(e),this.filteredRows=this.filteredRows.filter(e)}getRowCount(){var e;return((e=this.filteredRows)==null?void 0:e.length)??0}getUnfilteredRowCount(){var e;return((e=this.rows)==null?void 0:e.length)??0}canMoveRows(e,t){return Qs(this.filteredRows.length,this.rows.length,e,t)}moveRows(e,t){const s=wi(this.filteredRows,this.rows,e,t);return s&&(this.displayInDataOrder=!0,this.invalidateDerivedValues()),s}getValueAt(e,t){const s=this.properties[t];let o=this.filteredRows[e];if(U(o)&&(o=o.data),o){const i=this.getValueByT(o,s),r=this.getColumnValues().getShowValuesAs(s);return r?this.applyShowValuesAs(e,s,i,r):i}return""}getTextValueAt(e,t){const s=this.getValueAt(e,t);return this.getCalculatedText(this.properties[t],s)??""+s}getCellRenderer(e,t){return super.getCellRenderer(e,t)??this.getCalculatedRenderer(this.properties[t])}getTooltipAt(e,t){const s=this.properties[t];if(s!==void 0&&this.getColumnValues().isCalculated(s)){const o=this.getValueAt(e,t);if(w(o))return o.message}return super.getTooltipAt(e,t)}invalidateDerivedValues(e){this.invalidateColumnValues(),this.showValuesCache.clear()}applyShowValuesAs(e,t,s,o){if(w(s))return s;let i=this.showValuesCache.get(t);switch(i||(i={},this.showValuesCache.set(t,i)),o.mode){case"percentOfColumnTotal":case"percentOfGrandTotal":case"percentOfParentTotal":return i.total===void 0&&(i.total=Zs(this.filteredRows.map(r=>this.getValueByT(U(r)?r.data:r,t)))),typeof s=="number"&&!Number.isNaN(s)&&i.total!==0?s/i.total:void 0;case"percentOfRowTotal":return s;default:return(!i.values||i.values.length!==this.filteredRows.length)&&(i.values=fi(this.filteredRows.map(r=>this.getValueByT(U(r)?r.data:r,t)),o.mode)),i.values[e]}}readPropertyPath(e,t){return t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}getAggregationSourceForValues(){const e=this.filteredRows;return{signal:e,length:e.length,rows:()=>e.some(t=>U(t))?e.map(t=>U(t)?t.data:t):e}}getFilteredRows(){return this.filteredRows}getAllRows(){return this.rows}findRowFromFilteredRowsByAllCriteria(e,t){return this.getFilteredRows().find(s=>t(e,s))}findRowFromAllRowsByAllCriteria(e,t){return this.getAllRows().find(s=>t(e,s))}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.getRowHeight===z.prototype.getRowHeight&&this.defaultRowHeight>0?this.defaultRowHeight:void 0}getRowByIndex(e){return this.filteredRows[e]}externalFilterChanged(e){this.filteredRows=this.rows?this.rows.filter(e):[],this.displayInDataOrder=!0,this.showValuesCache.clear()}doSort(e){const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.genericFlatTableSortComparator(this.properties[s],i)});return this.showValuesCache.clear(),e.some(({sortState:s})=>s==="asc"||s==="desc")&&(this.displayInDataOrder=!1),t.length&&(this.filteredRows=this.filteredRows.sort((s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0})),!0}sort(e){this.displayInDataOrder=!1,this.filteredRows=this.filteredRows.sort(e),this.showValuesCache.clear()}getValueByT(e,t){if(!e||!t)return;const s=this.getColumnValues();if(s.getter(t))return s.get(e,t);const o=t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t];return this.sheetCells&&typeof o=="string"?this.sheetCells.valueOfProperty(e,t,o):o}getInputValueAt(e,t){const s=this.sheetCells;this.sheetCells=void 0;try{return this.getValueAt(e,t)}finally{this.sheetCells=s}}changeColumnOrder(e,t){this.arrayMove(this.properties,e,t),super.changeColumnOrder(e,t)}getCustomClassesAt(e,t){let s=super.getCustomClassesAt(e,t);return s=this.addCalculatedClasses(s,this.properties[t],()=>this.getValueAt(e,t)),this.getRowByIndex(e).selected&&s.push(this.selectedRowClass),this._focusedRowIndex===e&&s.push(this.focusedRowClass),s}genericFlatTableSortComparator(e,t){const s=this.columnDefs.find(r=>r.property===e),o=this.createSortValueReader(e),i=this.getColumnValues().isCalculated(e);return(r,l)=>{const a=o(r),c=o(l);return i&&(a===void 0||c===void 0)?a===c?0:a===void 0?1:-1:s!=null&&s.sortComparator?t*s.sortComparator(a,c,r,l,t):this.sorterService.genericSortComparator(a,c,t)}}createSortValueReader(e){if(!this.getColumnValues().getter(e))return s=>this.getValueByT(s,e);const t=new Map;return s=>{if(t.has(s))return t.get(s);const o=this.getValueByT(s,e),i=w(o)?void 0:o;return t.set(s,i),i}}getPropertyValue(e,t){const s=t.shift(),o=e[s];return o&&t.length?this.getPropertyValue(o,t):o}}class M{constructor(e,t,s,o,i=!1){this.r1=e,this.c1=t,this.r2=s,this.c2=o,this.gammaRange=i}static create(e){return e.gammaRange===void 0&&(e.gammaRange=!1),new M(e.rowIndex1,e.columnIndex1,e.rowIndex2,e.columnIndex2,e.gammaRange)}static singleCell(e,t){return new M(e,t,e,t)}static singleRow(e){return new M(e,0,e,Number.MAX_SAFE_INTEGER)}static singleColumn(e){return new M(0,e,Number.MAX_SAFE_INTEGER,e)}isInRange(e,t){return e>=this.r1&&e<=this.r2&&t>=this.c1&&t<=this.c2}}const Bs=class Bs{aggregate(e,t){const s={count:0,numericCount:0,sum:0,avg:void 0,min:void 0,max:void 0,capped:!1};if(!(t!=null&&t.hasSelection()))return s;const o=e.getBodyModel(),i=o.getRowCount(),r=e.getColumnCount(),l=(t.isAllSelected()?[new M(0,0,i-1,r-1)]:t.getRanges()).map(p=>({r1:Math.max(0,Math.min(p.r1,p.r2)),r2:Math.min(i-1,Math.max(p.r1,p.r2)),columns:this.dataColumns(e,Math.max(0,Math.min(p.c1,p.c2)),Math.min(r-1,Math.max(p.c1,p.c2)))})).filter(p=>p.r2>=p.r1&&p.columns.length);if(l.reduce((p,m)=>p+(m.r2-m.r1+1)*m.columns.length,0)>Bs.maxCells)return s.capped=!0,s;const{sum:c,min:h,max:d}=Oe;let u=c.init(),f=h.init(),g=d.init();return l.forEach((p,m)=>{const b=l.slice(0,m);for(let y=p.r1;y<=p.r2;y++)for(const C of p.columns){if(b.length&&b.some(E=>y>=E.r1&&y<=E.r2&&E.columns.includes(C))||!t.isSelected(y,C))continue;s.count++;const v=o.getValueAt(y,C);typeof v=="number"&&!Number.isNaN(v)&&(s.numericCount++,u=c.add(u,v),f=h.add(f,v),g=d.add(g,v))}}),s.numericCount&&(s.sum=c.result(u),s.avg=s.sum/s.numericCount,s.min=h.result(f),s.max=d.result(g)),s}dataColumns(e,t,s){var i;const o=[];for(let r=t;r<=s;r++){const l=e.getColumnDef(r);((i=l==null?void 0:l.isVisible)==null?void 0:i.call(l))===!1||N(l)||be(l)||o.push(r)}return o}};Bs.maxCells=1e6;let Ms=Bs;function Ua(n){const e=Lt(n);if(!e||!ui(e.mode))return;const t=Math.min(10,Math.max(0,Math.trunc(Number(e.fractionDigits??1)||0)));return t?`0.${"0".repeat(t)}%`:"0%"}const ie=1048576,q=16384;function Ne(n){if(!Number.isInteger(n)||n<0||n>=q)return"";let e="",t=n+1;for(;t>0;){const s=(t-1)%26;e=String.fromCharCode(65+s)+e,t=Math.floor((t-1)/26)}return e}function Fe(n){if(!/^[A-Za-z]{1,3}$/.test(n))return-1;let e=0;for(const t of n.toUpperCase())e=e*26+(t.charCodeAt(0)-64);return e-1<q?e-1:-1}function bt(n,e,t={}){const s=Ne(e);return!s||!Number.isInteger(n)||n<0||n>=ie?"#REF!":`${t.absCol?"$":""}${s}${t.absRow?"$":""}${n+1}`}function Ue(n){const e=/^(\$?)([A-Za-z]{1,3})(\$?)([1-9]\d{0,6})$/.exec(n.trim());if(!e)return;const t=Fe(e[2]),s=Number(e[4])-1;if(!(t<0||s>=ie))return{row:s,col:t,absRow:e[3]==="$",absCol:e[1]==="$"}}function Zr(n){const e=n.trim(),t=e.split(":");if(t.length===1){const c=Ue(e);return c?{from:c,to:{...c}}:void 0}if(t.length!==2)return;const s=Ue(t[0]),o=Ue(t[1]);if(s&&o)return{from:{row:Math.min(s.row,o.row),col:Math.min(s.col,o.col),absRow:s.absRow,absCol:s.absCol},to:{row:Math.max(s.row,o.row),col:Math.max(s.col,o.col),absRow:o.absRow,absCol:o.absCol}};const i=/^(\$?)([A-Za-z]{1,3})$/.exec(t[0]),r=/^(\$?)([A-Za-z]{1,3})$/.exec(t[1]);if(i&&r){const c=Fe(i[2]),h=Fe(r[2]);return c<0||h<0?void 0:{from:{row:0,col:Math.min(c,h),absRow:!1,absCol:i[1]==="$"},to:{row:ie-1,col:Math.max(c,h),absRow:!1,absCol:r[1]==="$"},wholeColumns:!0}}const l=/^(\$?)([1-9]\d{0,6})$/.exec(t[0]),a=/^(\$?)([1-9]\d{0,6})$/.exec(t[1]);if(l&&a){const c=Number(l[2])-1,h=Number(a[2])-1;return c>=ie||h>=ie?void 0:{from:{row:Math.min(c,h),col:0,absRow:l[1]==="$",absCol:!1},to:{row:Math.max(c,h),col:q-1,absRow:a[1]==="$",absCol:!1},wholeRows:!0}}}class B extends Error{constructor(e,t){super(e),this.pos=t}toFormulaError(){return new I("#ERROR!",`${this.message} (at ${this.pos+1})`,this.pos)}}const za=["<=",">=","<>","!=","==","+","-","*","/","^","&","=","<",">"],Ka=["<=",">=","<>","+","-","*","/","^","&","=","<",">",":","%"],ja=/^#(REF!|N\/A|DIV\/0!|VALUE!|NAME\?|NUM!|NULL!|CIRC!|ERROR!)/i,Xa={n:`
41
+ `)}}class To{fixJSON(e){const t=[];let s="",o=!1,i=!1;for(let r=0;r<e.length;r++){const l=e[r];if(s+=l,l==='"'&&!i&&(o=!o),l==="\\"&&!i){i=!0;continue}else i=!1;if(!o){if(l==="{"||l==="[")t.push(l);else if(l==="}"||l==="]"){const a=t.pop();if(l==="}"&&a!=="{"||l==="]"&&a!=="[")throw new Error("Invalid JSON structure detected.")}}}for(;t.length>0;){const r=t.pop();r==="{"?s+="}":r==="["&&(s+="]")}return s}}class _r{constructor(){this.property="",this.value="",this.path="",this.propertyItem=new ni("",[new ri("")])}toString(){var e;return`${this.path} -> : ${((e=this.propertyItem)==null?void 0:e.toString())??""}`}}const Io="Entity";function Br(n){let e=$r(Hr(n));return e.includes(Io)||(e=e+Io),e}function $r(n){if(!n||n.length===0)return n;const e=["Array","Arr","List","s"];for(const t of e)if(n.endsWith(t))return n.slice(0,-t.length);return n}function Hr(n){return!n||n.length===0?"":n[0].toUpperCase()+n.slice(1)}class Ra{constructor(){this.debugging=!1}json2PropertyType(e,t=""){let s;if(typeof e=="string"){const o=new To().fixJSON(e);s=this.json2Object(o)}else s=e;return this.object2PropertyType(s,t)}json2Object(e){return JSON.parse(e)}object2PropertyType(e,t=""){const s=this.object2ValueInfos(e,t);this.debugging&&this.logValueInfos(s);const o=this.valueInfos2PropertyType(s);return"name"in o&&(o.name=t),o}json2ValueInfos(e,t=""){let s;if(typeof e=="string"){const o=new To().fixJSON(e);s=this.json2Object(o)}else s=e;return this.object2ValueInfos(s,t)}object2ValueInfos(e,t=""){const s=this.extractValueInfos(e,t),o=this.mergeValueInfos(s);return o.length>0&&(o[0].propertyItem.propertyName=t),this.debugging&&this.logValueInfos(o),o}getParentPath(e){const t=e.lastIndexOf("/");return t===-1?"":e.substring(0,t)}valueInfos2PropertyType(e){const t=e[0].propertyItem.types[0],s=new Map;for(const o of e)s.set(o.path,o);for(const o of e){const i=this.getParentPath(o.path);if(i){const r=s.get(i);if(r){let l=!1;const a=r.propertyItem.types.filter(c=>!Qt.includes(c.type));if(a.length===1){const c=a[0];if(c instanceof We){l=!0;for(const h of o.propertyItem.types)c.items.push(h)}else c instanceof ve&&(l=!0,c.properties.push(o.propertyItem))}if(!l)for(const c of o.propertyItem.types)r.propertyItem.types.push(c)}}}return t||new ri("")}logValueInfos(e){for(let t=0;t<e.length;t++){const s=e[t];s.value=null;const o=t.toString().padStart(2,"0");console.info(o+") "+s.toString()+" parent: "+this.getParentPath(s.path))}}mergeValueInfos(e){const t=[];let s=e.length-1;t.push(e[s]);let o=e[s].path;for(let i=s-1;i>=0;i--){if(e[i].path===o){const r=e[i].propertyItem.types[0];e[s].propertyItem.types.some(l=>l.type===r.type)||e[s].propertyItem.types.push(r)}(i===0||e[i].path!==o)&&(s=i,t.push(e[i]),o=e[s].path)}for(const i of e){const r=this.getParentPath(i.path);if(r){const l=this.getParentPath(r);if(l){const a=this.getFirstValueInfoByPath(e,l);if(Array.isArray(a==null?void 0:a.value)){const c=(a==null?void 0:a.value.length)??0,h=this.countPath(e,i.path);c>h&&(i.propertyItem.types.some(d=>d.type===St)||i.propertyItem.types.push(new Cs(i.property)))}}}}return t.reverse(),t}countPath(e,t){let s=0;for(const o of e)o.path===t&&s++;return s}getFirstValueInfoByPath(e,t){for(let s=e.length-1;s>=0;s--)if(e[s].path===t)return e[s];return null}extractValueInfos(e,t){const s=[],o=(i,r,l)=>{const a=new _r;let c=r.split("/").pop()||"";if(c==="[]"?c=l:c==="root"&&(c=t),a.property=c,a.value=i,a.path=r,a.propertyItem=this.createPropertyItem(i,a.property),s.push(a),i&&typeof i===xt&&!Array.isArray(i)){for(const h in i)if(i.hasOwnProperty(h)){const d=r?`${r}/${h}`:h;o(i[h],d,c)}}else Array.isArray(i)&&i.forEach((h,d)=>{const u=`${r}/[]`;o(h,u,c)})};return o(e,"root",t),s.sort((i,r)=>i.path.localeCompare(r.path))}createPropertyItem(e,t){return new ni(t,[this.createPropertyType(e,t)])}createPropertyType(e,t){return e===null?new Or(t):e===void 0?new Cs(t):typeof e===oi?new Nr(t):typeof e===Ks&&!isNaN(e)?new Pr(t):typeof e===js?new Vr(t):Array.isArray(e)?new We(t):typeof e===xt?new ve(t,Br(t)):new Cs(t)}}class Aa{constructor(){this.orOperator="|",this.rootPropertyType=null,this.rootName="Root",this.renderTypeScriptInterfacesFifo=[],this.renderTypeScriptInterfacesDone=[]}renderTypeScriptInterfaces(e){"name"in e&&(this.rootName=e.name+""),this.rootPropertyType=e;const t=[];return this.rootPropertyType&&(this.renderTypeScriptInterfacesFifo=[],this.renderTypeScriptInterfacesDone=[],this.renderTypeScriptInterfacesRecursive(this.rootPropertyType,t),this.renderTypeScriptInterfacesFifoNext(t)),t}renderTypeScriptInterfacesFifoNext(e){var t;for(;(t=this.renderTypeScriptInterfacesFifo)!=null&&t.length;){const s=this.renderTypeScriptInterfacesFifo.shift();s&&this.renderTypeScriptInterfacesRecursive(s,e,s.propertyName)}}renderTypeScriptInterfacesRecursive(e=this.rootPropertyType,t=[],s=this.rootName){if(!e)return t;if(e instanceof We){for(const o of e.items)if(this.renderTypeScriptInterfacesRecursive(o,t,s),o instanceof ve){const i=o;i!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(i)}}else if(e instanceof ve){const o=e,i=o.className;if(!this.renderTypeScriptInterfacesDone.includes(i)){this.renderTypeScriptInterfacesDone.push(i),t.push(`export interface ${i} {`);for(const r of o.properties){let l=this.propertyItem2InterfaceDateType(r);l==="[]"?l="any[]":l.startsWith("(")&&l.endsWith(")")&&(l=l.substring(1,l.length-1));const a=this.containsUndefinedPropertyType(r)?"?":"";t.push(" "+r.propertyName+a+": "+l+";");for(const c of r.types)if(c instanceof ve)c!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(c);else if(c instanceof We)for(const h of c.items)h instanceof ve&&this.renderTypeScriptInterfacesFifo.push(h)}t.push("}"),t.push("")}}return t}propertyItem2InterfaceDateType(e){var s,o;if(((s=e.types)==null?void 0:s.length)===0)return"any";if(((o=e.types)==null?void 0:o.length)===1)return this.renderType(e.types[0],e);const t=e.types.map(i=>this.renderType(i,e)).filter(i=>i!==St).sort((i,r)=>Qt.includes(i)?100:Qt.includes(r)?-100:i.localeCompare(r)).join(this.orOperator);return t.includes(this.orOperator)?"("+t+")":t}renderType(e,t){if(e instanceof We){const s=e.items.map(o=>this.renderType(o,t)).join(this.orOperator);return s.includes(this.orOperator)?`(${s})[]`:`${s}[]`}return e instanceof ve?e.className:e.type}containsUndefinedPropertyType(e){for(const t of e.types)if(t.type===St)return!0;return!1}}class Qe{constructor(){this.alreadySet=!1}static getInstance(){return Qe.instance||(Qe.instance=new Qe),Qe.instance}setLicenseKey(e){if(e&&!this.alreadySet){const t=document.createElement("meta");t.content="license="+e,t.name="guiexperttable",document.getElementsByTagName("head")[0].appendChild(t),this.alreadySet=!0}}}function U(n){return n&&n.type==="TreeRow"}function Z(n){return n&&n.type==="AreaModelTree"}function li(n){return!!n&&n.type==="CheckboxCellRenderer"}function be(n){return n&&n.type==="CheckboxColumnDef"}function N(n){return!!n&&n.type==="RowNumberColumnDef"}function Gr(n){return!!n&&n.type==="AreaModelAggregateFooter"}function le(n){return!!n&&n.type==="RowGroup"}function Do(n){return U(n)&&le(n.data)}function ne(n){return!!n&&n.kind==="AreaModelRowGroups"}function it(n){return!!n&&n.type==="RowGroupColumnDef"}function Rs(n){return!!n&&n.kind==="PivotTableModel"}function ko(n){return!!n&&n.kind==="AreaModelPivot"}function Xs(n){return!!n&&n.type==="PivotColumnDef"}class es{constructor(e=-1,t=-1,s=-1,o=-1,i,r,l,a=0,c=0,h=0,d=""){this.rowIndex=e,this.rowTop=t,this.columnIndex=s,this.columnLeft=o,this.areaIdent=i,this.sideIdent=r,this.originalEvent=l,this.clickCount=a,this.draggingX=c,this.draggingY=h,this.action=d}clone(){return new es(this.rowIndex,this.rowTop,this.columnIndex,this.columnLeft,this.areaIdent,this.sideIdent,this.originalEvent,this.clickCount,this.draggingX,this.draggingY,this.action)}}class Me{constructor(e=">",t="",s=[]){this.content=e,this.style=t,this.classes=s}}class ai{constructor(e=new Me(">","transform: rotate(90deg) translate(66%, -66%); transform-origin: 0 0;",["gt-table-tree-arrow-expanded"]),t=new Me(">","",["ge-table-tree-arrow-collapsed"]),s=new Me(">","color:transparent;",["gt-table-tree-arrow-hidden"]),o=new Me("↕","",["gt-table-tree-arrow-expanded-all"])){this.arrowExpanded=e,this.arrowCollapsed=t,this.arrowPlaceholder=s,this.arrowExpandCollapseAll=o}}class ci{constructor(e=new Me("↑","",["ge-header-sorted-asc"]),t=new Me("↓","",["ge-header-sorted-desc"]),s=new Me("↑","color:transparent;",[])){this.iconAsc=e,this.iconDesc=t,this.iconPlaceholder=s}}const _s=class _s{constructor(e){this.domService=e,this.rtl=!1,this.startKey="left",this.endKey="right"}setDirection(e){this.rtl=e==="rtl",this.startKey=this.rtl?"right":"left",this.endKey=this.rtl?"left":"right"}getDirection(){return this.rtl?"rtl":"ltr"}toPhysicalStyleKey(e){if(this.rtl){if(e==="left")return"right";if(e==="right")return"left"}return e}getInlineStart(e){return parseFloat(e.style.getPropertyValue(this.startKey))||0}setStyle(e,t,s){return this.domService.setStyle(e,this.toPhysicalStyleKey(t),s),e}applyStyle(e,t){for(const s in t)this.domService.setStyle(e,this.toPhysicalStyleKey(s),t[s]);return e}applyDisplayNoneStyle(e){return this.domService.setStyle(e,"display","none"),e}applyDisplayBlockStyle(e){return this.domService.setStyle(e,"display","block"),e}applyStyleInPx(e,t){return Object.entries(t).forEach(([s,o])=>this.domService.setStyle(e,this.toPhysicalStyleKey(s),o+"px")),e}applyStylePosistionRelative(e){return this.domService.setStyle(e,"position","relative"),this.domService.setStyle(e,"overflow","clip"),e}applyStylePosistionAbsolute(e){return this.domService.setStyle(e,"position","absolute"),e}applyStyleFullSize(e){return this.domService.setStyle(e,"width","100%"),this.domService.setStyle(e,"height","100%"),e}applyStyleOverflowAuto(e="auto",t="auto",s){return this.domService.setStyle(s,"overflow-x",e),this.domService.setStyle(s,"overflow-y",t),s}applyStyleNoPadding(e){return this.domService.setStyle(e,"padding","0"),this.domService.setStyle(e,"margin","0"),this.domService.setStyle(e,"border","0"),e}appendRelativeChildDiv(e){const t=this.applyStylePosistionRelative(this.applyStyleFullSize(this.applyStyleNoPadding(this.domService.createElement("div"))));return this.domService.appendChild(e,t),this.applyStylePosistionAbsolute(e),{parent:e,child:t,cache:{}}}appendText(e,t){const s=this.domService.createText(t);return this.domService.appendChild(e,s),s}addClass(e,t){return e.includes(" ")?e.split(" ").forEach(s=>this.domService.addClass(t,s)):this.domService.addClass(t,e),t}removeClass(e,t){return e.includes(" ")?e.split(" ").forEach(s=>this.domService.removeClass(t,s)):this.domService.removeClass(t,e),t}addClasses(e,t){if(e)for(const s of e)this.domService.addClass(t,s);return t}setAttribute(e,t,s){return t&&s&&this.domService.setAttribute(e,t,s),e}removeAttribute(e,t){return this.domService.removeAttribute?this.domService.removeAttribute(e,t):e.removeAttribute(t),e}setAriaHidden(e){return this.domService.setAttribute(e,"aria-hidden","true"),e}createAreaDivWithClass(e,t,s,o){const i=this.domService.createElement("div");return this.addClass(e,i),this.domService.setAttribute(i,"data-area",s),this.domService.setAttribute(i,"data-side",o),this.domService.appendChild(t,i),i}createDivWithClass(e,t){const s=this.domService.createElement("div");return this.addClass(e,s),this.domService.appendChild(t,s),s}addRowDiv(e,t,s=-1,o,i,r=""){const l=t.index??-1,a=this.getDivOrCreateDiv(l,e);if(this.domService.addClass(a,"ge-table-row-div"),this.domService.addClass(a,`ge-table-row-div-${t.index}`),o==="body"&&i==="center"){const c=((t==null?void 0:t.index)??0)%2===0?"even":"odd";this.domService.addClass(a,`ge-table-row-${c}`)}if(this.domService.setStyle(a,"display","clip"),this.domService.setStyle(a,"position","absolute"),this.domService.setStyle(a,this.startKey,`${t.left}px`),this.domService.setStyle(a,"top",`${t.top}px`),this.domService.setStyle(a,"width",`${t.width}px`),this.domService.setStyle(a,"height",`${t.height}px`),this.domService.setAttribute(a,"data-row-index",`${s}`),this.domService.setAttribute(a,"data-area",`${o}`),r){const c=this.domService.createText(r);this.domService.appendChild(a,c)}return this.domService.appendChild(e.child,a),a}addColumnDiv(e){const{parent:t,geo:s,rowIndex:o=-1,columnIndex:i=-1,areaIdent:r,sideIdent:l,text:a="",treeArrow:c,tableOptions:h,checkedType:d=void 0,sortState:u,checkboxAriaLabel:f,firstDataColumnIndex:g=0}=e,p=h==null?void 0:h.treeOptions,m=h==null?void 0:h.showCheckboxWihoutExtraColumn,b=this.domService.createElement("div");this.domService.addClass(b,"ge-table-col-div"),m&&this.domService.addClass(b,"ge-with-checkbox"),this.domService.addClass(b,`ge-table-col-div-${s.index}`),this.domService.setAttribute(b,"data-col-index",`${s.index}`),this.domService.setAttribute(b,"data-row-index",`${o}`),this.domService.setAttribute(b,"data-area",`${r}`);const y=((s==null?void 0:s.index)??0)%2===0?"even":"odd";if(r==="body"&&l==="center"&&this.domService.addClass(b,`ge-table-column-${y}`),this.domService.setStyle(b,"display","clip"),this.domService.setStyle(b,"position","absolute"),this.domService.setStyle(b,this.startKey,`${s.left}px`),this.domService.setStyle(b,"top",`${s.top}px`),this.domService.setStyle(b,"width",`${s.width}px`),this.domService.setStyle(b,"height",`${s.height}px`),c&&c!=="none"&&(this.domService.addClass(b,"ge-table-col-tree"),this.addArrowDiv(b,c,p,o,i,r)),m&&i===g&&d&&this.addCheckboxToDiv(b,d,r,o,f),a){const C=c!=="none"&&i===g;this.addLabelDiv(b,a,C,o,i,r)}return u&&this.addSortedIcon(b,u,h==null?void 0:h.sortedOptions,i),this.domService.appendChild(t,b),b}addCheckboxToDiv(e,t,s,o,i){const r=this.domService.createElement("div"),l=this.domService.createElement("input");return this.domService.setAttribute(l,"type","checkbox"),this.domService.setAttribute(l,"data-area",`${s}`),this.domService.setAttribute(l,"data-row-index",`${o}`),this.domService.setAttribute(l,"data-input-type","checkbox"),this.domService.setAttribute(l,"tabindex","-1"),t==="full"&&(this.domService.setAttribute(l,"checked",""),l.checked=!0),t==="semi"&&(l.indeterminate=!0),this.domService.addClass(l,"ge-table-row-checkbox"),i&&this.domService.setAttribute(l,"aria-label",i),this.domService.appendChild(r,l),this.domService.setStyle(r,"display","inline"),this.domService.setStyle(r,"width","inherit"),this.domService.setAttribute(r,"data-row-index",`${o}`),this.domService.appendChild(e,r),r}addLabelDiv(e,t="",s=!1,o=-1,i=-1,r="body"){const l=this.domService.createElement("div");if(this.domService.addClass(l,"ge-table-label-div"),this.domService.setStyle(l,"position","relative"),this.domService.setStyle(l,"background","transparent"),this.domService.setStyle(l,"width","100%"),this.domService.setStyle(l,"height","100%"),this.domService.setAttribute(l,"data-row-index",`${o}`),this.domService.setAttribute(l,"data-col-index",`${i}`),this.domService.setAttribute(l,"data-area",`${r}`),t)if(s){const a=this.domService.createText(t);this.domService.appendChild(l,a)}else{const a=this.domService.createElement("div");this.domService.appendChild(l,a);const c=this.domService.createText(t);this.domService.addClass(a,"ge-table-label"),this.domService.appendChild(a,c),this.domService.setAttribute(a,"data-row-index",`${o}`),this.domService.setAttribute(a,"data-col-index",`${i}`),this.domService.setAttribute(a,"data-area",`${r}`)}return this.domService.appendChild(e,l),l}addSortedIcon(e,t="",s=new ci,o=-1){const i=this.domService.createElement("div");this.domService.addClass(i,"ge-table-sorted-icon-div"),this.setAriaHidden(i),this.domService.setStyle(i,"position","absolute"),this.domService.setStyle(i,"top","0"),this.domService.setStyle(i,this.endKey,"0"),this.domService.setStyle(i,"width","20px"),this.domService.setStyle(i,"background","transparent"),this.domService.setStyle(i,"cursor","pointer"),this.domService.setAttribute(i,"data-col-index",`${o}`),this.domService.setAttribute(i,"data-area","header");let r;t==="asc"?r=s.iconAsc:t==="desc"?r=s.iconDesc:r=s.iconPlaceholder;const l=r.content,a=this.domService.createText(l);this.domService.appendChild(i,a),r.style&&this.applyStyleString(i,r.style);for(const c of r.classes)this.domService.addClass(i,c);return this.domService.appendChild(e,i),i}addArrowDiv(e,t="none",s=new ai,o=-1,i=-1,r="body"){const l=this.domService.createElement("div");this.domService.addClass(l,"ge-table-tree-arrow-div"),this.setAriaHidden(l),this.domService.setStyle(l,"display","inline-block"),this.domService.setStyle(l,"position",""),this.domService.setStyle(l,"width","20px"),this.domService.setStyle(l,"background","transparent"),this.domService.setStyle(l,"cursor","pointer"),this.domService.setAttribute(l,"data-row-index",`${o}`),this.domService.setAttribute(l,"data-col-index",`${i}`),this.domService.setAttribute(l,"data-area",`${r}`);let a;t==="expanded"?a=s.arrowExpanded:t==="collapsed"?a=s.arrowCollapsed:a=s.arrowPlaceholder;const c=a.content,h=this.domService.createText(c);this.domService.appendChild(l,h),a.style&&this.applyStyleString(l,a.style);for(const d of a.classes)this.domService.addClass(l,d);return this.domService.appendChild(e,l),l}addColumnBorderDivs(e,t,s,o,i){if(e.verticalBorderVisible){const r=`ge-table-${o}-${i}-vertical-border`;this.addVerticalBorder(s,t,r)}if(e.horizontalBorderVisible){const r=`ge-table-${o}-${i}-horizontal-border`;this.addHorizontalBorder(s,t,r)}return t}addHorizontalBorder(e,t,s="ge-table-body-center-horizontal-border"){const o=this.domService.createElement("div");return this.domService.addClass(o,s),this.setAriaHidden(o),this.domService.setStyle(o,"display","clip"),this.domService.setStyle(o,"position","absolute"),this.domService.setStyle(o,this.startKey,`${e.left}px`),this.domService.setStyle(o,"top",`${e.top}px`),this.domService.setStyle(o,"width",`${e.width}px`),this.domService.setStyle(o,"height","1px"),this.domService.appendChild(t,o),o}addFocusBorderDivs(e,t,s){t={...t,width:t.width+1,height:t.height+1};const o=_s.focusBorderWidthInPx,i=[[t.left,t.top,o,t.height],[t.left+t.width-o,t.top,o,t.height],[t.left,t.top,t.width,o],[t.left,t.top+t.height-o,t.width,o]];for(const[r,l,a,c]of i){const h=this.domService.createElement("div");this.domService.addClass(h,"ge-table-focus-border"),this.setAriaHidden(h),this.domService.setStyle(h,"display","clip"),this.domService.setStyle(h,"position","absolute"),this.domService.setStyle(h,this.startKey,`${r}px`),this.domService.setStyle(h,"top",`${l}px`),this.domService.setStyle(h,"width",`${a}px`),this.domService.setStyle(h,"height",`${c}px`),this.domService.setStyle(h,"z-index","9999"),this.applyStyle(h,s),this.domService.appendChild(e,h)}return e}addVerticalBorder(e,t,s="ge-table-body-center-vertical-border"){const o=this.domService.createElement("div");return this.domService.addClass(o,s),this.setAriaHidden(o),this.domService.setStyle(o,"display","clip"),this.domService.setStyle(o,"position","absolute"),this.domService.setStyle(o,this.startKey,`${e.left}px`),this.domService.setStyle(o,"top",`${e.top}px`),this.domService.setStyle(o,"width","1px"),this.domService.setStyle(o,"height",`${e.height}px`),this.domService.appendChild(t,o),o}addDiv(e,t,s=""){const o=this.domService.createElement("div");return s&&this.domService.addClass(o,s),this.setAriaHidden(o),this.domService.setStyle(o,"display","clip"),this.domService.setStyle(o,"position","absolute"),this.domService.setStyle(o,this.startKey,`${t.left}px`),this.domService.setStyle(o,"top",`${t.top}px`),this.domService.setStyle(o,"width",`${t.width}px`),this.domService.setStyle(o,"height",`${t.height}px`),this.domService.appendChild(e,o),o}applyStyleString(e,t){const s=t.split(";").map(o=>o.trim()).filter(o=>o);for(const o of s){const[i,r]=o.split(":");this.domService.setStyle(e,i.trim(),r.trim())}}getDivOrCreateDiv(e,t){let s=t.cache[e];return s?(s.innerText="",s):(s=this.domService.createElement("div"),t.cache[e]=s,s)}};_s.focusBorderWidthInPx=2;let As=_s;const Rt=n=>n==="header"?"header":n==="footer"?"footer":"body";class Es{constructor(e,t){if(this.rowIdx=-1,this.colIdx=-1,this.action=null,this.inputType=null,this.className="",e!==null&&(e instanceof HTMLDivElement||e instanceof HTMLSpanElement||e instanceof HTMLInputElement)){this.className=e.className,this.action=e.getAttribute("data-ge-action"),this.inputType=e.getAttribute("data-input-type"),this.rowIdx=Number(e.getAttribute("data-row-index")),this.colIdx=Number(e.getAttribute("data-col-index"));const s=e.getAttribute("data-area");if(s&&(this.areaIdent=Rt(s),this.areaModel=t.tableModel.getAreaModel(this.areaIdent),this.row=this.areaModel.getRowByIndex(this.rowIdx)),e instanceof HTMLInputElement){const o=e;this.value=o.value}}}}class Wr{constructor(e){this.tableScope=e,this.doubleClickDelay=500,this.clickMoveTolerance=4,this.lastClickedCellKey="",this.nativeClickCount=0,this.nativeDblClickCount=0,this.mouseDown=!1,this.repaintAfterMouseUp=!1,this.dragging=!1,this.dragGeneration=0,this.lastClicked=0;const t=this.tableScope.listenerAbortController.signal;this.tableScope.hostElement.addEventListener("click",this.onHostElementClicked.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("dblclick",this.onHostElementDblClicked.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("mousedown",this.onMouseDown.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("mousemove",this.onMouseMove.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("mouseup",this.onMouseUp.bind(this),{signal:t}),this.tableScope.hostElement.addEventListener("contextmenu",this.onContextmenu.bind(this),{signal:t}),t.addEventListener("abort",()=>clearTimeout(this.lostClickTimer)),this.tableScope.hostElement._MouseHandler="true",this.tableScope.scrollViewport.addEventListener("scroll",()=>this.tableScope.onViewportScroll(),{signal:t}),this.tableScope.scrollViewport.addEventListener("wheel",this.tableScope.onWheel.bind(this.tableScope),{passive:!1,signal:t}),[window,this.tableScope.hostElement].forEach(s=>s.addEventListener("resize",this.tableScope.adjustContainersAndRows.bind(this.tableScope),{signal:t}))}onContextmenu(e){if(this.isBlocked(e)||!(e instanceof MouseEvent))return;this.pressedCell=void 0,this.mouseEvent=e;const t=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.contextmenu(t)}onHostElementClicked(e){this.nativeClickCount++,!this.isBlocked(e)&&this.handleClick(e,this.tableScope.getMouseEventTarget(e))}handleClick(e,t,s){var c;const o=Date.now(),i=s?this.toCellKey(s):this.getCellKey(t),r=e.detail>=2||e.detail===0&&o-this.lastClicked<this.doubleClickDelay&&i===this.lastClickedCellKey;this.lastClicked=o,this.lastClickedCellKey=i;const l=new Es(t,this.tableScope);s&&this.applyCell(l,s);const a=s?this.createCellEvent(e,s):void 0;if(r&&(this.reportedDoubleClick={time:o,cellKey:i}),r&&!this.isClickAction(l)){this.publishGeMouseEvent(e,2,a,t);return}if(l.action==="toggleExpandCollapseAll")this.tableScope.toggleExpandCollapseAll(!this.tableScope.allExpanded),e.preventDefault(),e.stopPropagation();else if(l.action==="toggle-detail")this.tableScope.toggleDetail(l.rowIdx,"mouse"),e.preventDefault(),e.stopPropagation();else if(l.action==="toggleHeaderGroup")this.tableScope.toggleHeaderGroup(l),e.preventDefault(),e.stopPropagation();else if(l.inputType==="checkbox"&&l.areaIdent)this.tableScope.toggleRowCheckbox(l.rowIdx,l.colIdx,l.areaIdent),e.preventDefault(),e.stopPropagation();else if(U(l.row)&&l.areaModel){const h=l.colIdx===this.getArrowColumnIndex()&&e.altKey,d=l.className.includes("ge-table-tree-arrow-div");if(h||d){e.preventDefault(),e.stopPropagation();const u=l.row;this.tableScope.setTreeRowExpanded(u,!u.expanded)}}l.areaIdent==="body"&&((c=this.tableScope.focusModel())==null||c.setFocus(l.rowIdx,l.colIdx)),this.publishGeMouseEvent(e,r?2:1,a,t)}toCellKey(e){return e.areaIdent+":"+e.rowIdx+":"+e.colIdx}applyCell(e,t){e.areaIdent=t.areaIdent,e.areaModel=this.tableScope.tableModel.getAreaModel(t.areaIdent),e.rowIdx=t.rowIdx,e.colIdx=t.colIdx,e.row=e.areaModel.getRowByIndex(t.rowIdx)}createCellEvent(e,t){return this.tableScope.createGeMouseEventForCell(e,{areaIdent:t.areaIdent,sideIdent:t.sideIdent,rowIndex:t.rowIdx,columnIndex:t.colIdx,action:t.action})}getCellKey(e){var s;const t=e instanceof Element?e:null;return(s=t==null?void 0:t.closest)!=null&&s.call(t,"[data-col-index]")?["data-area","data-row-index","data-col-index"].map(o=>{var i;return((i=t.closest("["+o+"]"))==null?void 0:i.getAttribute(o))??""}).join(":"):""}isClickAction(e){return e.action==="toggleExpandCollapseAll"||e.action==="toggleHeaderGroup"||e.action==="toggle-detail"||e.inputType==="checkbox"&&!!e.areaIdent||e.className.includes("ge-table-tree-arrow-div")}onHostElementDblClicked(e){this.nativeDblClickCount++,!this.isBlocked(e)&&this.handleDblClick(e,this.tableScope.getMouseEventTarget(e))}handleDblClick(e,t,s){var c,h,d,u;this.lastClicked=Date.now();const o=s?this.createCellEvent(e,s):this.tableScope.createGeMouseEvent(e),i=new Es(t,this.tableScope),r=(s?s.action:i.action)==="resize-column";if(r){const f=s?s.colIdx:Number(((c=t instanceof Element?t.closest("[data-col-index]"):null)==null?void 0:c.getAttribute("data-col-index"))??-1);this.tableScope.autoResizeColumnByUser(f,e)}if(!r&&t instanceof HTMLElement&&!this.isClickAction(i)){const f=t.closest("[data-col-index]")??t,g=s?s.areaIdent:((h=f.closest("[data-area]"))==null?void 0:h.getAttribute("data-area"))??null,p=Rt(g),m=s?s.rowIdx:Number((d=f.closest("[data-row-index]"))==null?void 0:d.getAttribute("data-row-index")),b=s?s.colIdx:Number(f.getAttribute("data-col-index")),y=this.tableScope.tableModel.getAreaModel(p);if(g&&p==="header"){const C=(u=y.isColumnLetterRow)==null?void 0:u.call(y,m);this.tableScope.tableModel.isSortable(b)&&!C&&(this.tableScope.clearSelection(),this.tableScope.onHeaderDblClicked(e,m,b))}else if(s||f.getAttribute("data-row-index")){const C=y.getRowByIndex(m);if(g&&p==="body"&&y.isEditable(m,b)&&this.tableScope.startEditing(m,b,"edit"),U(C)&&b===this.getArrowColumnIndex()){e.preventDefault(),e.stopPropagation();const v=C;this.tableScope.setTreeRowExpanded(v,!v.expanded)}}}const l=this.reportedDoubleClick,a=s?this.toCellKey(s):this.getCellKey(t);(!l||Date.now()-l.time>this.doubleClickDelay||l.cellKey!==a)&&this.publishGeMouseEvent(e,2,o),this.reportedDoubleClick=void 0}publishGeMouseEvent(e,t,s,o=e.target){var r;this.mouseEvent=e,this.geMouseEventOld=(r=this.geMouseEvent)==null?void 0:r.clone(),this.geMouseEvent=s??this.tableScope.createGeMouseEvent(e),this.geMouseEvent&&(this.geMouseEvent.clickCount=t);const i=this.tableScope.onMouseClicked(this.geMouseEvent,this.geMouseEventOld);this.tableScope.publishGeMouseEvent(this.geMouseEvent),i&&!this.isInteractiveCellElement(o)&&this.tableScope.debounceRepaint()}isInteractiveCellElement(e){const t=e instanceof Element?e:null,s=t==null?void 0:t.closest('input, select, textarea, button, a[href], [contenteditable]:not([contenteditable="false"])');return!!s&&this.tableScope.hostElement.contains(s)}getArrowColumnIndex(){const e=this.tableScope.tableModel.isRowCheckboxVisible();return this.tableScope.getFirstDataColumnIndex()+(e?1:0)}onMouseDown(e){if(!this.isBlocked(e)&&(this.tableScope.cancelPendingRepaint()&&(this.repaintAfterMouseUp=!0),this.pressedCell=e.button===0?this.readPressedCell(e):void 0,!this.dragging)){this.mouseEvent=e,this.startMouseEvent=this.tableScope.createGeMouseEvent(this.mouseEvent),this.flushDraggingEnd(),this.tableScope.onMouseDown(this.startMouseEvent),this.mouseDown=!0;const t=this.tableScope.listenerAbortController.signal;document.addEventListener("mouseup",s=>this.onDocumentMouseUp(s),{once:!0,signal:t})}}onDocumentMouseUp(e){this.mouseDown&&!this.tableScope.hostElement.contains(e.target)&&this.onMouseUp(e)}adjustForRowChanges(e){const t=this.startMouseEvent;(this.mouseDown||this.pendingDraggingEnd)&&t&&t.areaIdent==="body"&&t.rowIndex>=0&&(t.rowIndex=Math.max(0,e.mapIndexOrNext(t.rowIndex)))}onMouseMove(e){var t,s,o,i,r;if(!this.mouseDown&&((s=(t=this.tableScope).isEventInDetail)!=null&&s.call(t,e))){(i=(o=this.tableScope).hideHover)==null||i.call(o);return}if(!(!this.mouseDown&&this.isBlocked(e))){if(this.mouseDown&&!this.dragging){const l=(r=this.startMouseEvent)==null?void 0:r.originalEvent;if(l&&l.clientX===e.clientX&&l.clientY===e.clientY)return}if(this.mouseEvent=e,this.mouseDown){this.dragging||(this.dragging=!0,this.tableScope.setDragging(!0));const l=this.dragGeneration;requestAnimationFrame(()=>{l===this.dragGeneration&&this.mouseDraggingOnFrame()})}else requestAnimationFrame(this.mouseMoveOnFrame.bind(this))}}onMouseUp(e){var s,o;const t=this.pressedCell;if(this.pressedCell=void 0,!(!this.mouseDown&&((o=(s=this.tableScope).isEventInDetail)!=null&&o.call(s,e)))){if(this.mouseEvent=e,t&&e.button===0&&this.checkLostClick(t,e),this.repaintAfterMouseUp&&(this.repaintAfterMouseUp=!1,this.tableScope.debounceRepaint()),this.dragging){const i={evt:e,start:this.startMouseEvent,frameId:0};i.frameId=requestAnimationFrame(()=>this.flushDraggingEnd()),this.pendingDraggingEnd=i}this.mouseDown=!1,this.dragging=!1,this.tableScope.setDragging(!1)}}readPressedCell(e){var f,g,p;const t=this.tableScope.getMouseEventTarget(e),s=t instanceof Element?t:null,o=(f=s==null?void 0:s.closest)==null?void 0:f.call(s,"[data-col-index]"),i=(g=o==null?void 0:o.closest("[data-area]"))==null?void 0:g.getAttribute("data-area"),r=(p=o==null?void 0:o.closest("[data-row-index]"))==null?void 0:p.getAttribute("data-row-index");if(!s||!o||!i||r===null||r===void 0)return;const l=this.tableScope.createGeMouseEvent(e),a=Number(r),c=Number(o.getAttribute("data-col-index")),h=Rt(i);let d,u=!1;if(h==="body"){const m=this.tableScope.tableModel.getBodyModel();d=this.rowAt(m,a),u=typeof d=="object"&&d!==null&&this.rowAt(m,a)===d}return{target:s,areaIdent:h,sideIdent:l.sideIdent,rowIdx:a,colIdx:c,action:l.action,row:d,stableRow:u,clientX:e.clientX,clientY:e.clientY}}checkLostClick(e,t){if(e.target.isConnected)return;const s=t.clientX-e.clientX,o=t.clientY-e.clientY;if(s*s+o*o>this.clickMoveTolerance*this.clickMoveTolerance)return;const i=this.nativeClickCount,r=this.nativeDblClickCount;clearTimeout(this.lostClickTimer),this.lostClickTimer=setTimeout(()=>{if(this.lostClickTimer=void 0,this.nativeClickCount!==i||this.tableScope.isDestroyed()||this.isBlocked(t))return;const l=this.resolveRowIndex(e);if(l<0)return;const a={areaIdent:e.areaIdent,sideIdent:e.sideIdent,rowIdx:l,colIdx:e.colIdx,action:e.action};this.handleClick(t,e.target,a),t.detail===2&&this.nativeDblClickCount===r&&this.handleDblClick(t,e.target,a)},0)}resolveRowIndex(e){if(e.areaIdent!=="body"||!e.stableRow)return e.rowIdx;const t=this.tableScope.tableModel.getBodyModel();if(this.rowAt(t,e.rowIdx)===e.row)return e.rowIdx;const s=t.getRowCount();for(let o=1;o<s;o++){const i=e.rowIdx-o,r=e.rowIdx+o;if(i<0&&r>=s)break;if(i>=0&&this.rowAt(t,i)===e.row)return i;if(r<s&&this.rowAt(t,r)===e.row)return r}return-1}rowAt(e,t){try{return e.getRowByIndex(t)}catch{return}}mouseDraggingOnFrame(){var e;if(this.mouseEvent){const t=this.tableScope.createGeMouseEvent(this.mouseEvent);(e=this.startMouseEvent)!=null&&e.originalEvent&&(t.draggingX=this.mouseEvent.clientX-this.startMouseEvent.originalEvent.clientX,t.draggingY=this.mouseEvent.clientY-this.startMouseEvent.originalEvent.clientY),this.tableScope.mouseDraggingOnFrame(t,this.startMouseEvent)}}flushDraggingEnd(){var s;const e=this.pendingDraggingEnd;if(!e)return;this.pendingDraggingEnd=void 0,cancelAnimationFrame(e.frameId),this.dragGeneration++;const t=this.tableScope.createGeMouseEvent(e.evt);(s=e.start)!=null&&s.originalEvent&&(t.draggingX=e.evt.clientX-e.start.originalEvent.clientX,t.draggingY=e.evt.clientY-e.start.originalEvent.clientY),this.tableScope.mouseDraggingEndOnFrame(t)}mouseMoveOnFrame(){if(this.mouseEvent){const e=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.mouseMove(e)}}isButtonDown(){return this.mouseDown}isBlocked(e){var t,s,o;return(((t=this.tableScope.tableOverlay)==null?void 0:t.isEventBlocked(e))??!1)||!!((o=(s=this.tableScope).isEventInDetail)!=null&&o.call(s,e))}}const Ur=()=>!1;function zr(n){return n.editable===void 0||n.editable===Ur}function hi(n){return typeof n=="number"&&!Number.isNaN(n)}function Ea(n){if(hi(n))return n;if(n instanceof Date){const e=n.getTime();return Number.isNaN(e)?void 0:e}}function di(n,e){const t=n.sum,s=t+e;Number.isFinite(s)&&(n.compensation+=Math.abs(t)>=Math.abs(e)?t-s+e:e-s+t),n.sum=s}function Kr(n){return Number.isFinite(n.sum)?n.sum+n.compensation:n.sum}function jr(n,e){di(n,e.sum),n.compensation+=e.compensation}const Ma={name:"sum",init:()=>({sum:0,compensation:0}),add:(n,e)=>(hi(e)&&di(n,e),n),merge:(n,e)=>(jr(n,e),n),result:n=>Kr(n)},Ta={name:"count",init:()=>0,add:n=>n+1,merge:(n,e)=>n+e,result:n=>n},Ia={name:"avg",init:()=>({sum:0,compensation:0,count:0}),add:(n,e)=>(hi(e)&&(di(n,e),n.count++),n),merge:(n,e)=>(jr(n,e),n.count+=e.count,n),result:n=>n.count?Kr(n)/n.count:void 0};function Wi(n,e){return{name:n,init:()=>({has:!1,value:void 0,key:0}),add:(t,s)=>{const o=Ea(s);return o!==void 0&&(!t.has||e(o,t.key))&&(t.has=!0,t.value=s,t.key=o),t},merge:(t,s)=>(s.has&&(!t.has||e(s.key,t.key))&&(t.has=!0,t.value=s.value,t.key=s.key),t),result:t=>t.has?t.value:void 0}}const Da={name:"countDistinct",init:()=>({values:new Set,dates:new Set}),add:(n,e)=>(e instanceof Date?n.dates.add(e.getTime()):e!=null&&n.values.add(e),n),merge:(n,e)=>(e.values.forEach(t=>n.values.add(t)),e.dates.forEach(t=>n.dates.add(t)),n),result:n=>n.values.size+n.dates.size},ka={name:"first",init:()=>({has:!1,value:void 0}),add:(n,e)=>(n.has||(n.has=!0,n.value=e),n),merge:(n,e)=>(!n.has&&e.has&&(n.has=!0,n.value=e.value),n),result:n=>n.value},Fa={name:"last",init:()=>({has:!1,value:void 0}),add:(n,e)=>(n.has=!0,n.value=e,n),merge:(n,e)=>(e.has&&(n.has=!0,n.value=e.value),n),result:n=>n.value},Oe=Object.freeze({sum:Ma,count:Ta,avg:Ia,min:Wi("min",(n,e)=>n<e),max:Wi("max",(n,e)=>n>e),countDistinct:Da,first:ka,last:Fa});function Ys(n){if(typeof n!="string")return n;const e=Oe[n];if(!e)throw new Error(`Unknown aggregator "${n}" – use one of: ${Object.keys(Oe).join(", ")}, or an own AggregatorIf.`);return e}function cs(n){if(typeof n=="function")return n;const e=n.split(".");return e.length===1?t=>t==null?void 0:t[n]:t=>{let s=t;for(const o of e){if(s==null)return;s=s[o]}return s}}function hs(n,e){const t=typeof e=="string"||!("aggregator"in e)?{aggregator:e}:e,s=Ys(t.aggregator),o=t.value??n;return{key:n,aggregator:s,value:o,getValue:s===Oe.count?void 0:cs(o),format:t.format}}function Js(n,e){const t=e.map(o=>o.aggregator.init()),s=e.length;for(let o=0;o<n.length;o++){const i=n[o];for(let r=0;r<s;r++){const l=e[r];t[r]=l.aggregator.add(t[r],l.getValue?l.getValue(i):i)}}return t}function La(n,e){const t=e.map(o=>o.aggregator.init()),s=e.length;for(let o=0;o<n;o++)for(let i=0;i<s;i++){const r=e[i];t[i]=r.aggregator.add(t[i],r.getValue?r.getValue(o):o)}return t}function Oa(n,e,t){const s=hs("",{aggregator:t,value:e}),[o]=Js(n,[s]);return s.aggregator.result(o)}function Na(n,e){const t=Object.keys(e).map(i=>hs(i,e[i])),s=Js(n,t),o={};return t.forEach((i,r)=>o[i.key]=i.aggregator.result(s[r])),o}const Pa=new Intl.NumberFormat("en-US",{maximumFractionDigits:2});function Ft(n){return n==null?"":typeof n=="number"?Number.isFinite(n)?Pa.format(n):String(n):n instanceof Date?Number.isNaN(n.getTime())?"":n.toLocaleDateString("en-US"):String(n)}const Va=new Set(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal"]),Ui=new Map,_a=new Intl.NumberFormat("en-US",{maximumFractionDigits:0});function Lt(n){if(!n)return;const e=typeof n=="string"?{mode:n}:n;return Xr.includes(e.mode)?e:void 0}const Xr=Object.freeze(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal","differenceFromPrevious","runningTotal","rank"]);function ui(n){return!!n&&Va.has(n)}function qs(n,e){const t=Lt(e);if(typeof n!="number"||Number.isNaN(n)||!t)return n==null?"":`${n}`;if(t.format)return`${t.format(n)??""}`;if(ui(t.mode)){const s=zi(t.fractionDigits??1);let o=Ui.get(s);return o||(o=new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:s,maximumFractionDigits:s}),Ui.set(s,o)),o.format(n)}if(t.mode==="rank")return _a.format(n);if(t.fractionDigits!==void 0){const s=zi(t.fractionDigits);return new Intl.NumberFormat("en-US",{minimumFractionDigits:s,maximumFractionDigits:s}).format(n)}return Ft(n)}function zi(n){return Math.min(10,Math.max(0,Math.trunc(Number(n)||0)))}function ct(n){return typeof n=="number"&&!Number.isNaN(n)}function Zs(n){const e=Oe.sum;let t=e.init();for(let s=0;s<n.length;s++)t=e.add(t,n[s]);return e.result(t)??0}function fi(n,e){const t=n.length,s=new Array(t);switch(e){case"percentOfColumnTotal":case"percentOfGrandTotal":case"percentOfParentTotal":{const o=Zs(n);for(let i=0;i<t;i++)s[i]=Ba(n[i],o);return s}case"runningTotal":{const o=Oe.sum;let i=o.init();for(let r=0;r<t;r++){const l=n[r];i=o.add(i,l),s[r]=ct(l)?o.result(i):void 0}return s}case"differenceFromPrevious":for(let o=0;o<t;o++){const i=n[o],r=o>0?n[o-1]:void 0;s[o]=ct(i)&&ct(r)?i-r:void 0}return s;case"rank":{const o=[];for(let r=0;r<t;r++)ct(n[r])&&o.push(r);o.sort((r,l)=>n[l]-n[r]);let i=0;for(let r=0;r<o.length;r++)(r===0||n[o[r]]!==n[o[r-1]])&&(i=r+1),s[o[r]]=i;return s}default:for(let o=0;o<t;o++)s[o]=ct(n[o])?n[o]:void 0;return s}}function Ba(n,e){return ct(n)&&e!==0?n/e:void 0}class I{constructor(e,t,s){this.code=e,this.message=t,this.position=s,this.type="FormulaError"}toString(){return this.code}}function w(n){return!!n&&typeof n=="object"&&n.type==="FormulaError"}class $a{constructor(e){this.owner=e,this.defsLength=-1,this.computing=new Map,this.contexts=new Map,this.aggregates=new Map,this.aggSignal=void 0,this.aggLength=-1}invalidate(){this.getters=void 0,this.showValuesAs=void 0,this.properties=void 0,this.aggregates.clear()}getter(e){if(e!==void 0)return this.lookup().get(e)}hasGetters(){return this.lookup().size>0}isCalculated(e){return this.lookup().has(e)}hasColumn(e){return this.lookup(),this.properties.has(e)}getShowValuesAs(e){if(e!==void 0)return this.lookup(),this.showValuesAs.get(e)}hasShowValuesAs(){return this.lookup(),this.showValuesAs.size>0}get(e,t){const s=this.lookup().get(t);if(!s)return this.owner.readPath(e,t);if(e!=null)return this.call(s,e,t)}aggregate(e,t){var c;if((c=this.computing.get(e))!=null&&c.size)return new I("#CIRC!",`Circular reference: the column "${e}" uses its own aggregate`);const s=this.owner.getAggregationSource();(s.signal!==this.aggSignal||s.length!==this.aggLength)&&(this.aggregates.clear(),this.aggSignal=s.signal,this.aggLength=s.length);const o=Ys(t),i=`${o.name}\0${e}`;if(this.aggregates.has(i))return this.aggregates.get(i);const r=s.rows();let l=o.init(),a;for(let h=0;h<r.length;h++){const d=this.get(r[h],e);if(w(d)&&d.code==="#CIRC!"){a=d;break}l=o.add(l,d)}return a===void 0&&(a=o.result(l)),this.aggregates.set(i,a),a}context(e){let t=this.contexts.get(e);return t||(t={property:e,getValue:(s,o)=>this.get(s,o),hasColumn:s=>this.hasColumn(s),isCalculated:s=>{var o,i;return this.isCalculated(s)||!!((i=(o=this.owner).isSheetFormula)!=null&&i.call(o,s))},aggregate:(s,o)=>this.aggregate(s,o)},this.contexts.set(e,t)),t}call(e,t,s){let o=this.computing.get(s);if(o!=null&&o.has(t))return new I("#CIRC!",`Circular reference: the column "${s}" depends on itself`);o||(o=new Set,this.computing.set(s,o)),o.add(t);try{return e(t,this.context(s))}catch(i){return new I("#VALUE!",`valueGetter of "${s}": ${i instanceof Error?i.message.slice(0,200):"failed"}`)}finally{o.delete(t)}}lookup(){const e=this.owner.getColumnDefsForValues()??[];if(this.getters&&this.defsLength===e.length)return this.getters;const t=new Map,s=new Map,o=new Set;for(const i of e){if(!i)continue;o.add(i.property),typeof i.valueGetter=="function"&&t.set(i.property,i.valueGetter);const r=Lt(i.showValuesAs);r&&s.set(i.property,r)}return this.getters=t,this.showValuesAs=s,this.properties=o,this.defsLength=e.length,t}}class Ot{constructor(){this.type="AggregateCellRenderer"}render(e,t,s,o,i,r,l){const a=i.getTextValueAt(t,s);if(!a)return;const c=l.createElement("div");l.addClass(c,"ge-table-label-div");const h=l.createElement("div");l.addClass(h,"ge-table-label"),l.setAttribute(h,"data-row-index",`${t}`),l.setAttribute(h,"data-col-index",`${s}`),l.setAttribute(h,"data-area",o),l.appendChild(h,l.createText(a)),l.appendChild(c,h),l.appendChild(e,c)}}class ds{constructor(e,t=[],s=-1){this.areaIdent=e,this.columnDefs=t,this.defaultRowHeight=s,this.rowSelectionModel=void 0,this.yPositions=[],this.defaultEditable=!1,this.cellRenderers=t.map(o=>o.rendererMap[e])}getTextValueAt(e,t){return""+this.getValueAt(e,t)}getTooltipAt(e,t){var s;if((s=this.sheetCells)!=null&&s.isFormulaColumnIndex(t)){const o=this.getValueAt(e,t);if(w(o))return o.message}return""}getCellRenderer(e,t){if(t<this.cellRenderers.length)return this.cellRenderers[t]}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){var s;return(s=this.sheetCells)!=null&&s.isFormulaColumnIndex(t)&&w(this.getValueAt(e,t))?["ge-table-cell-error"]:[]}getCustomStyleAt(e,t){}getRowspanAt(e,t){return 0}getRowByIndex(e){}isRowCheckable(e){return!0}isRowChecked(e){var s;const t=this.getRowByIndex(e);return(s=this.rowSelectionModel)==null?void 0:s.isRowChecked(t)}setRowChecked(e,t){if(this.rowSelectionModel){const s=this.getRowByIndex(e);this.rowSelectionModel.checkRow(s,t)}}getMaxColspan(){return 31}getMaxRowspan(){return 31}getYPosByRowIndex(e){var o;const t=(o=this.getConstantRowHeight)==null?void 0:o.call(this);if(t!==void 0&&t>0)return t*e;let s=0;for(let i=0;i<e;i++)s+=this.getRowHeight(i);return s}init(){!this.yPositions.length&&this.getRowCount()!==void 0&&this.defaultRowHeight===-1&&this.calcYPositions()}isFilterable(){return this.areaIdent==="body"}doSort(e){return!1}sort(e){}isEditable(e,t){var o,i;const s=(o=this.columnDefs)==null?void 0:o[t];return this.areaIdent==="body"&&(s!=null&&s.valueGetter)&&!s.valueSetter?!1:this.defaultEditable&&this.areaIdent==="body"&&s&&zr(s)?!be(s)&&!N(s)&&!it(s):((i=s==null?void 0:s.editable)==null?void 0:i.call(s))??!1}setValue(e,t,s){var a;const o=(a=this.columnDefs[t])==null?void 0:a.editInputPipe;o&&(s=o(s,e,t));const i=this.getRowByIndex(e),r=this.columnDefs[t];if(this.areaIdent==="body"&&(r!=null&&r.valueGetter))return this.setCalculatedValue(i,r,s);const l=this.columnDefs[t].property;return l.includes(".")?this.setPropertyValue(i,l.split("."),s):(i[l]=s,!0)}isSelectable(e,t){return!0}changeColumnOrder(e,t){this.arrayMove(this.cellRenderers,e,t)}setPropertyValue(e,t,s){const o=t.shift();if(o){const i=e[o];return i&&t.length?this.setPropertyValue(i,t,s):(e[o]=s,!0)}return!1}arrayMove(e,t,s){const o=e.splice(t,1)[0];return e.splice(s,0,o),e}calcYPositions(){const e=this.getRowCount();this.yPositions=new Array(e+1),this.yPositions[0]=0;for(let t=0;t<e;t++)this.yPositions[t+1]=this.getRowHeight(t)+this.yPositions[t]}isCalculatedProperty(e){var t;return this.getColumnValues().isCalculated(e)||!!((t=this.sheetCells)!=null&&t.isFormulaProperty(e))}getRowValue(e,t){U(e)&&(e=e.data);const s=this.getColumnValues().get(e,t);return this.sheetCells&&typeof s=="string"?this.sheetCells.valueOfProperty(e,t,s):s}hasDerivedColumns(){const e=this.getColumnValues();return e.hasGetters()||e.hasShowValuesAs()}isDerivedProperty(e){const t=this.getColumnValues();return t.isCalculated(e)||!!t.getShowValuesAs(e)}getColumnValues(){return this.columnValuesInstance??(this.columnValuesInstance=new $a({getColumnDefsForValues:()=>this.areaIdent==="body"?this.columnDefs:[],readPath:(e,t)=>{const s=this.readPropertyPath(e,t);return this.sheetCells&&typeof s=="string"?this.sheetCells.valueOfProperty(e,t,s):s},getAggregationSource:()=>this.getAggregationSourceForValues(),isSheetFormula:e=>{var t;return!!((t=this.sheetCells)!=null&&t.isFormulaProperty(e))}}))}invalidateColumnValues(){var e;(e=this.columnValuesInstance)==null||e.invalidate()}readPropertyPath(e,t){if(e==null||!t)return;let s=e;for(const o of t.split(".")){if(s==null)return;s=s[o]}return s}getAggregationSourceForValues(){const e=this.getRowCount();return{signal:void 0,length:e,rows:()=>Array.from({length:e},(t,s)=>this.getRowByIndex(s))}}setCalculatedValue(e,t,s){return!t.valueSetter||e===void 0||e===null?!1:(U(e)&&(e=e.data),t.valueSetter(e,s)!==!1)}getCalculatedText(e,t){if(e===void 0)return;const s=this.getColumnValues(),o=s.getShowValuesAs(e),i=s.isCalculated(e);if(i&&w(t))return t.code;if(o)return qs(t,o);if(i)return t==null?"":`${t}`}getCalculatedRenderer(e){if(e!==void 0&&this.getColumnValues().getShowValuesAs(e))return this.calcTextRenderer??(this.calcTextRenderer=new Ot)}addCalculatedClasses(e,t,s){return t!==void 0&&this.getColumnValues().isCalculated(t)&&w(s())?[...e,"ge-table-cell-error"]:e}}class gi{genericSortComparator(e,t,s){if(typeof e=="number"&&typeof t=="number")return s*(e-t);if(typeof e=="string"&&typeof t=="string")return s*e.localeCompare(t);if(typeof e=="boolean"&&typeof t=="boolean")return s*((e?-1:1)-(t?-1:1));if(e instanceof Date&&t instanceof Date)return s*(e.getTime()-t.getTime());if(e instanceof Array&&t instanceof Array){const o=e,i=t;if(o.length&&i.length)return this.genericSortComparator(o[0],i[0],s)}return s*(""+e).localeCompare(""+t)}}function rt(n,e){return Ha(n,e)?n:Array.from(new Set(n)).filter(t=>Number.isInteger(t)&&t>=0&&t<e).sort((t,s)=>t-s)}function Ha(n,e){let t=-1;for(const s of n){if(!Number.isInteger(s)||s<=t||s>=e)return!1;t=s}return!0}function pi(n){return n.position==="before"?n.rowIndex:n.rowIndex+1}function Fo(n,e){if(!n.length)return-1;const t=pi(e);return t-n.filter(s=>s<t).length}function Yr(n,e,t){const s=rt(e,n.length);if(!s.length)return-1;const o=Math.min(Math.max(0,t),n.length),i=new Uint8Array(n.length);s.forEach(h=>i[h]=1);const r=new Array(s.length);s.forEach((h,d)=>r[d]=n[h]);const l=[];let a=-1;for(let h=0;h<=n.length;h++)h===o&&(a=l.length),h<n.length&&!i[h]&&l.push(n[h]);let c=0;for(let h=0;h<a;h++)n[c++]=l[h];for(const h of r)n[c++]=h;for(let h=a;h<l.length;h++)n[c++]=l[h];return a}function mi(n){const e=new Set(n);return n.filter(t=>{for(let s=t.parent;s;s=s.parent)if(e.has(s))return!1;return!0})}function bi(n,e){if(!e||!n.length)return!1;const t=new Set(n);for(let s=e;s;s=s.parent)if(t.has(s))return!1;return!0}function Jr(n,e,t,s){const o=mi(e);if(!bi(o,t))return!1;for(const a of o){const c=a.parent?a.parent.children:n,h=(c==null?void 0:c.indexOf(a))??-1;c&&h>-1&&c.splice(h,1)}let i,r,l;s==="inside"?(i=t,t.children=t.children??[],r=t.children,l=r.length,t.expanded=!0):(i=t.parent,r=i?i.children??(i.children=[]):n,l=r.indexOf(t)+(s==="after"?1:0)),r.splice(l,0,...o);for(const a of o)a.parent=i,qr(a,i?i.deep+1:0);return!0}function qr(n,e){n.deep=e;for(const t of n.children??[])qr(t,e+1)}function Qs(n,e,t,s){return n===e&&s.position!=="inside"&&Number.isInteger(s.rowIndex)&&s.rowIndex>=0&&s.rowIndex<n&&rt(t,n).length>0}function wi(n,e,t,s){if(!Qs(n.length,e.length,t,s))return!1;if(Yr(n,rt(t,n.length),pi(s)),e!==n)for(let o=0;o<n.length;o++)e[o]=n[o];return!0}function Ga(n,e,t,s){if(e<1)return-1;if(s&&s>0)return Math.min(e-1,Math.max(0,Math.floor(n/s)));let o=0,i=e-1;for(;o<i;){const r=o+i+1>>1;t(r)<=n?o=r:i=r-1}return o}const Wa=new Int32Array(0);class z extends ds{constructor(e,t,s,o=[],i="ge-selected-row",r="ge-focused-row"){super(e,o,s),this.areaIdent=e,this.rows=t,this.defaultRowHeight=s,this.columnDefs=o,this.selectedRowClass=i,this.focusedRowClass=r,this.sorterService=new gi,this.displayInDataOrder=!0,this.showValuesCache=new Map,this._focusedRowIndex=0,this.filteredRows=[...t],this.properties=o.map(l=>l.property)}getFocusedRowIndex(){return this._focusedRowIndex}setFocusedRowIndex(e){this._focusedRowIndex=e}setRows(e){this.rows=e,this.filteredRows=[...e],this.displayInDataOrder=!0,this.showValuesCache.clear()}appendRows(e,t={}){const s=this.rows,o=t.maxRows!==void 0&&t.maxRows>=0?Math.floor(t.maxRows):Number.POSITIVE_INFINITY,i=Math.max(0,s.length+e.length-o),r=i>0?Math.max(i,Math.ceil(o/100)):0,l=Math.min(r,s.length),a=Math.max(0,i-l),c=l>0?this.removeFirstRows(l):Wa,h=[],d=t.filter;for(let f=a;f<e.length;f++){const g=e[f];s.push(g),(!d||d(g))&&h.push(g)}const u=t.compare?this.mergeSorted(h,t.compare):this.appendShown(h);return(h.length||c.length)&&this.showValuesCache.clear(),{added:e.length-a,shown:h.length,removed:l,removedPositions:c,insertedPositions:u}}removeFirstRows(e){const t=this.rows.splice(0,e),s=this.filteredRows;if(this.displayInDataOrder){let l=0;for(let c=0;c<t.length&&l<s.length;c++)s[l]===t[c]&&l++;s.splice(0,l);const a=new Int32Array(l);for(let c=0;c<l;c++)a[c]=c;return a}const o=new Set(t),i=[];let r=0;for(let l=0;l<s.length;l++){const a=s[l];o.has(a)?i.push(l):s[r++]=a}return s.length=r,Int32Array.from(i)}appendShown(e){const t=this.filteredRows,s=new Int32Array(e.length);for(let o=0;o<e.length;o++)s[o]=t.length,t.push(e[o]);return s}mergeSorted(e,t){const s=this.filteredRows,o=e.length,i=new Int32Array(o);if(!o)return i;e.sort(t),this.displayInDataOrder=!1;let r=s.length;for(let l=0;l<o;l++)s.push(e[l]);for(let l=o-1;l>=0;l--){const a=e[l];let c=0,h=r;for(;c<h;){const d=c+h>>>1;t(s[d],a)>0?h=d:c=d+1}c<r&&s.copyWithin(c+l+1,c,r),s[c+l]=a,i[l]=c+l,r=c}return i}createSortComparator(e){const t=e.filter(({sortState:s})=>s==="asc"||s==="desc").map(({columnIndex:s,sortState:o})=>this.genericFlatTableSortComparator(this.properties[s],o==="asc"?1:-1));if(t.length)return(s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}}filterRowsByPredict(e){this.rows=this.rows.filter(e),this.filteredRows=this.filteredRows.filter(e)}getRowCount(){var e;return((e=this.filteredRows)==null?void 0:e.length)??0}getUnfilteredRowCount(){var e;return((e=this.rows)==null?void 0:e.length)??0}canMoveRows(e,t){return Qs(this.filteredRows.length,this.rows.length,e,t)}moveRows(e,t){const s=wi(this.filteredRows,this.rows,e,t);return s&&(this.displayInDataOrder=!0,this.invalidateDerivedValues()),s}getValueAt(e,t){const s=this.properties[t];let o=this.filteredRows[e];if(U(o)&&(o=o.data),o){const i=this.getValueByT(o,s),r=this.getColumnValues().getShowValuesAs(s);return r?this.applyShowValuesAs(e,s,i,r):i}return""}getTextValueAt(e,t){const s=this.getValueAt(e,t);return this.getCalculatedText(this.properties[t],s)??""+s}getCellRenderer(e,t){return super.getCellRenderer(e,t)??this.getCalculatedRenderer(this.properties[t])}getTooltipAt(e,t){const s=this.properties[t];if(s!==void 0&&this.getColumnValues().isCalculated(s)){const o=this.getValueAt(e,t);if(w(o))return o.message}return super.getTooltipAt(e,t)}invalidateDerivedValues(e){this.invalidateColumnValues(),this.showValuesCache.clear()}applyShowValuesAs(e,t,s,o){if(w(s))return s;let i=this.showValuesCache.get(t);switch(i||(i={},this.showValuesCache.set(t,i)),o.mode){case"percentOfColumnTotal":case"percentOfGrandTotal":case"percentOfParentTotal":return i.total===void 0&&(i.total=Zs(this.filteredRows.map(r=>this.getValueByT(U(r)?r.data:r,t)))),typeof s=="number"&&!Number.isNaN(s)&&i.total!==0?s/i.total:void 0;case"percentOfRowTotal":return s;default:return(!i.values||i.values.length!==this.filteredRows.length)&&(i.values=fi(this.filteredRows.map(r=>this.getValueByT(U(r)?r.data:r,t)),o.mode)),i.values[e]}}readPropertyPath(e,t){return t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}getAggregationSourceForValues(){const e=this.filteredRows;return{signal:e,length:e.length,rows:()=>e.some(t=>U(t))?e.map(t=>U(t)?t.data:t):e}}getFilteredRows(){return this.filteredRows}getAllRows(){return this.rows}findRowFromFilteredRowsByAllCriteria(e,t){return this.getFilteredRows().find(s=>t(e,s))}findRowFromAllRowsByAllCriteria(e,t){return this.getAllRows().find(s=>t(e,s))}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.getRowHeight===z.prototype.getRowHeight&&this.defaultRowHeight>0?this.defaultRowHeight:void 0}getRowByIndex(e){return this.filteredRows[e]}externalFilterChanged(e){this.filteredRows=this.rows?this.rows.filter(e):[],this.displayInDataOrder=!0,this.showValuesCache.clear()}doSort(e){const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.genericFlatTableSortComparator(this.properties[s],i)});return this.showValuesCache.clear(),e.some(({sortState:s})=>s==="asc"||s==="desc")&&(this.displayInDataOrder=!1),t.length&&(this.filteredRows=this.filteredRows.sort((s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0})),!0}sort(e){this.displayInDataOrder=!1,this.filteredRows=this.filteredRows.sort(e),this.showValuesCache.clear()}getValueByT(e,t){if(!e||!t)return;const s=this.getColumnValues();if(s.getter(t))return s.get(e,t);const o=t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t];return this.sheetCells&&typeof o=="string"?this.sheetCells.valueOfProperty(e,t,o):o}getInputValueAt(e,t){const s=this.sheetCells;this.sheetCells=void 0;try{return this.getValueAt(e,t)}finally{this.sheetCells=s}}changeColumnOrder(e,t){this.arrayMove(this.properties,e,t),super.changeColumnOrder(e,t)}getCustomClassesAt(e,t){let s=super.getCustomClassesAt(e,t);return s=this.addCalculatedClasses(s,this.properties[t],()=>this.getValueAt(e,t)),this.getRowByIndex(e).selected&&s.push(this.selectedRowClass),this._focusedRowIndex===e&&s.push(this.focusedRowClass),s}genericFlatTableSortComparator(e,t){const s=this.columnDefs.find(r=>r.property===e),o=this.createSortValueReader(e),i=this.getColumnValues().isCalculated(e);return(r,l)=>{const a=o(r),c=o(l);return i&&(a===void 0||c===void 0)?a===c?0:a===void 0?1:-1:s!=null&&s.sortComparator?t*s.sortComparator(a,c,r,l,t):this.sorterService.genericSortComparator(a,c,t)}}createSortValueReader(e){if(!this.getColumnValues().getter(e))return s=>this.getValueByT(s,e);const t=new Map;return s=>{if(t.has(s))return t.get(s);const o=this.getValueByT(s,e),i=w(o)?void 0:o;return t.set(s,i),i}}getPropertyValue(e,t){const s=t.shift(),o=e[s];return o&&t.length?this.getPropertyValue(o,t):o}}class M{constructor(e,t,s,o,i=!1){this.r1=e,this.c1=t,this.r2=s,this.c2=o,this.gammaRange=i}static create(e){return e.gammaRange===void 0&&(e.gammaRange=!1),new M(e.rowIndex1,e.columnIndex1,e.rowIndex2,e.columnIndex2,e.gammaRange)}static singleCell(e,t){return new M(e,t,e,t)}static singleRow(e){return new M(e,0,e,Number.MAX_SAFE_INTEGER)}static singleColumn(e){return new M(0,e,Number.MAX_SAFE_INTEGER,e)}isInRange(e,t){return e>=this.r1&&e<=this.r2&&t>=this.c1&&t<=this.c2}}const Bs=class Bs{aggregate(e,t){const s={count:0,numericCount:0,sum:0,avg:void 0,min:void 0,max:void 0,capped:!1};if(!(t!=null&&t.hasSelection()))return s;const o=e.getBodyModel(),i=o.getRowCount(),r=e.getColumnCount(),l=(t.isAllSelected()?[new M(0,0,i-1,r-1)]:t.getRanges()).map(p=>({r1:Math.max(0,Math.min(p.r1,p.r2)),r2:Math.min(i-1,Math.max(p.r1,p.r2)),columns:this.dataColumns(e,Math.max(0,Math.min(p.c1,p.c2)),Math.min(r-1,Math.max(p.c1,p.c2)))})).filter(p=>p.r2>=p.r1&&p.columns.length);if(l.reduce((p,m)=>p+(m.r2-m.r1+1)*m.columns.length,0)>Bs.maxCells)return s.capped=!0,s;const{sum:c,min:h,max:d}=Oe;let u=c.init(),f=h.init(),g=d.init();return l.forEach((p,m)=>{const b=l.slice(0,m);for(let y=p.r1;y<=p.r2;y++)for(const C of p.columns){if(b.length&&b.some(E=>y>=E.r1&&y<=E.r2&&E.columns.includes(C))||!t.isSelected(y,C))continue;s.count++;const v=o.getValueAt(y,C);typeof v=="number"&&!Number.isNaN(v)&&(s.numericCount++,u=c.add(u,v),f=h.add(f,v),g=d.add(g,v))}}),s.numericCount&&(s.sum=c.result(u),s.avg=s.sum/s.numericCount,s.min=h.result(f),s.max=d.result(g)),s}dataColumns(e,t,s){var i;const o=[];for(let r=t;r<=s;r++){const l=e.getColumnDef(r);((i=l==null?void 0:l.isVisible)==null?void 0:i.call(l))===!1||N(l)||be(l)||o.push(r)}return o}};Bs.maxCells=1e6;let Ms=Bs;function Ua(n){const e=Lt(n);if(!e||!ui(e.mode))return;const t=Math.min(10,Math.max(0,Math.trunc(Number(e.fractionDigits??1)||0)));return t?`0.${"0".repeat(t)}%`:"0%"}const ie=1048576,q=16384;function Ne(n){if(!Number.isInteger(n)||n<0||n>=q)return"";let e="",t=n+1;for(;t>0;){const s=(t-1)%26;e=String.fromCharCode(65+s)+e,t=Math.floor((t-1)/26)}return e}function Fe(n){if(!/^[A-Za-z]{1,3}$/.test(n))return-1;let e=0;for(const t of n.toUpperCase())e=e*26+(t.charCodeAt(0)-64);return e-1<q?e-1:-1}function bt(n,e,t={}){const s=Ne(e);return!s||!Number.isInteger(n)||n<0||n>=ie?"#REF!":`${t.absCol?"$":""}${s}${t.absRow?"$":""}${n+1}`}function Ue(n){const e=/^(\$?)([A-Za-z]{1,3})(\$?)([1-9]\d{0,6})$/.exec(n.trim());if(!e)return;const t=Fe(e[2]),s=Number(e[4])-1;if(!(t<0||s>=ie))return{row:s,col:t,absRow:e[3]==="$",absCol:e[1]==="$"}}function Zr(n){const e=n.trim(),t=e.split(":");if(t.length===1){const c=Ue(e);return c?{from:c,to:{...c}}:void 0}if(t.length!==2)return;const s=Ue(t[0]),o=Ue(t[1]);if(s&&o)return{from:{row:Math.min(s.row,o.row),col:Math.min(s.col,o.col),absRow:s.absRow,absCol:s.absCol},to:{row:Math.max(s.row,o.row),col:Math.max(s.col,o.col),absRow:o.absRow,absCol:o.absCol}};const i=/^(\$?)([A-Za-z]{1,3})$/.exec(t[0]),r=/^(\$?)([A-Za-z]{1,3})$/.exec(t[1]);if(i&&r){const c=Fe(i[2]),h=Fe(r[2]);return c<0||h<0?void 0:{from:{row:0,col:Math.min(c,h),absRow:!1,absCol:i[1]==="$"},to:{row:ie-1,col:Math.max(c,h),absRow:!1,absCol:r[1]==="$"},wholeColumns:!0}}const l=/^(\$?)([1-9]\d{0,6})$/.exec(t[0]),a=/^(\$?)([1-9]\d{0,6})$/.exec(t[1]);if(l&&a){const c=Number(l[2])-1,h=Number(a[2])-1;return c>=ie||h>=ie?void 0:{from:{row:Math.min(c,h),col:0,absRow:l[1]==="$",absCol:!1},to:{row:Math.max(c,h),col:q-1,absRow:a[1]==="$",absCol:!1},wholeRows:!0}}}class B extends Error{constructor(e,t){super(e),this.pos=t}toFormulaError(){return new I("#ERROR!",`${this.message} (at ${this.pos+1})`,this.pos)}}const za=["<=",">=","<>","!=","==","+","-","*","/","^","&","=","<",">"],Ka=["<=",">=","<>","+","-","*","/","^","&","=","<",">",":","%"],ja=/^#(REF!|N\/A|DIV\/0!|VALUE!|NAME\?|NUM!|NULL!|CIRC!|ERROR!)/i,Xa={n:`
42
42
  `,t:" ",r:"\r","\\":"\\",'"':'"',"'":"'"};function he(n){return n>="0"&&n<="9"}function ts(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}function Qr(n){return ts(n)||he(n)||n==="."}function Ya(n,e=!1){if(e)return Ja(n);const t=[],s=n.length;let o=0;for(;o<s;){const i=n[o];if(i===" "||i===" "||i===`
43
43
  `||i==="\r"){o++;continue}const r=o;if(he(i)||i==="."&&o+1<s&&he(n[o+1])){for(;o<s&&he(n[o]);)o++;if(n[o]===".")for(o++;o<s&&he(n[o]);)o++;if(n[o]==="e"||n[o]==="E"){let c=o+1;if((n[c]==="+"||n[c]==="-")&&c++,c<s&&he(n[c]))for(o=c;o<s&&he(n[o]);)o++}if(o<s&&(ts(n[o])||n[o]==="."))throw new B(`Invalid number "${n.slice(r,o+1)}"`,r);const a=n.slice(r,o);t.push({kind:"number",text:a,value:Number(a),pos:r});continue}if(i==='"'||i==="'"){o++;let a="",c=!1;for(;o<s;){const h=n[o];if(h==="\\"){const d=n[o+1];if(d===void 0)break;a+=Xa[d]??d,o+=2;continue}if(h===i){c=!0,o++;break}a+=h,o++}if(!c)throw new B("Unterminated text",r);t.push({kind:"string",text:a,pos:r});continue}if(i==="["){o++;let a="",c=!1;for(;o<s;){const d=n[o];if(d==="\\"&&o+1<s){a+=n[o+1],o+=2;continue}if(d==="]"){c=!0,o++;break}if(d==="[")break;a+=d,o++}if(!c)throw new B("Unterminated field reference, missing ]",r);const h=a.trim();if(!h)throw new B("Empty field reference []",r);t.push({kind:"field",text:h,pos:r});continue}if(ts(i)){for(;o<s&&Qr(n[o]);)o++;t.push({kind:"ident",text:n.slice(r,o),pos:r});continue}if(i==="("||i===")"||i===","){t.push({kind:i,text:i,pos:r}),o++;continue}const l=za.find(a=>n.startsWith(a,o));if(l){t.push({kind:"op",text:l,pos:r}),o+=l.length;continue}throw new B(`Unexpected character "${i}"`,r)}return t.push({kind:"eof",text:"",pos:s}),t}function Ja(n){const e=[],t=n.length;let s=0;for(;s<t;){const o=n[s];if(o===" "||o===" "||o===`
44
44
  `||o==="\r"){s++;continue}const i=s;if(he(o)||o==="."&&s+1<t&&he(n[s+1])){for(;s<t&&he(n[s]);)s++;if(n[s]===".")for(s++;s<t&&he(n[s]);)s++;if(n[s]==="e"||n[s]==="E"){let a=s+1;if((n[a]==="+"||n[a]==="-")&&a++,a<t&&he(n[a]))for(s=a;s<t&&he(n[s]);)s++}if(s<t&&(ts(n[s])||n[s]==="."||n[s]==="$"))throw new B(`Invalid number "${n.slice(i,s+1)}"`,i);const l=n.slice(i,s);e.push({kind:"number",text:l,value:Number(l),pos:i});continue}if(o==='"'){s++;let l="",a=!1;for(;s<t;){if(n[s]==='"'){if(n[s+1]==='"'){l+='"',s+=2;continue}a=!0,s++;break}l+=n[s++]}if(!a)throw new B("Unterminated text",i);e.push({kind:"string",text:l,pos:i});continue}if(o==="["){const l=n.indexOf("]",s+1),a=l<0?"":n.slice(s+1,l);if(l<0||a.includes("["))throw new B("Unterminated field reference, missing ]",i);const c=a.trim();if(!c)throw new B("Empty field reference []",i);e.push({kind:"field",text:c,pos:i}),s=l+1;continue}if(o==="#"){const l=ja.exec(n.slice(s));if(!l)throw new B('Unexpected character "#"',i);e.push({kind:"error",text:l[0].toUpperCase(),pos:i}),s+=l[0].length;continue}if(ts(o)||o==="$"){for(;s<t&&(Qr(n[s])||n[s]==="$");)s++;e.push({kind:"ident",text:n.slice(i,s),pos:i});continue}if(o==="("||o===")"||o===","){e.push({kind:o,text:o,pos:i}),s++;continue}if(o===";"){e.push({kind:",",text:";",pos:i}),s++;continue}const r=Ka.find(l=>n.startsWith(l,s));if(r){e.push({kind:"op",text:r,pos:i}),s+=r.length;continue}throw new B(`Unexpected character "${o}"`,i)}return e.push({kind:"eof",text:"",pos:t}),e}const go=1e4,Ki=64,ji=1e3,qa={"=":{bp:10,op:"="},"==":{bp:10,op:"="},"<>":{bp:10,op:"<>"},"!=":{bp:10,op:"<>"},"<":{bp:10,op:"<"},"<=":{bp:10,op:"<="},">":{bp:10,op:">"},">=":{bp:10,op:">="},"&":{bp:20,op:"&"},"+":{bp:30,op:"+"},"-":{bp:30,op:"-"},"*":{bp:40,op:"*"},"/":{bp:40,op:"/"},"^":{bp:60,right:!0,op:"^"}},Za=50,Qa=75,ec=70,tc=80;class sc{constructor(e,t=!1){this.tokens=e,this.references=t,this.index=0,this.depth=0,this.operators=0}parse(){if(this.peek().kind==="eof")throw new B("Empty formula",0);const e=this.expression(0),t=this.peek();if(t.kind!=="eof")throw new B(`Unexpected "${t.text}"`,t.pos);return e}peek(){return this.tokens[this.index]}next(){return this.tokens[this.index++]}enter(e){if(++this.depth>Ki)throw new B(`Nested too deeply (more than ${Ki} levels)`,e)}expression(e){let t=this.prefix();for(;;){const s=this.peek();if(s.kind!=="op")break;if(this.references&&s.text==="%"){if(ec<=e)break;this.next(),t={kind:"unary",op:"%",operand:t};continue}if(this.references&&s.text===":"){if(tc<=e)break;this.next(),t=this.range(t,s.pos);continue}const o=qa[s.text];if(!o||o.bp<=e)break;if(this.next(),++this.operators>ji)throw new B(`Too many operators (more than ${ji})`,s.pos);this.enter(s.pos);const i=this.expression(o.right&&!this.references?o.bp-1:o.bp);this.depth--,t={kind:"binary",op:o.op,left:t,right:i}}return t}prefix(){const e=this.next();switch(e.kind){case"number":return this.references&&this.peekRangeOp()&&/^\d+$/.test(e.text)?this.rowRef(e.text,e.pos):{kind:"literal",value:e.value};case"string":return{kind:"literal",value:e.text};case"field":return{kind:"field",name:e.text};case"error":return{kind:"error",code:e.text};case"op":if(e.text==="-"||e.text==="+"){this.enter(e.pos);const t=this.expression(this.references?Qa:Za);return this.depth--,{kind:"unary",op:e.text,operand:t}}throw new B(`Unexpected "${e.text}"`,e.pos);case"(":{this.enter(e.pos);const t=this.expression(0);return this.depth--,this.expect(")","Missing )"),t}case"ident":return this.identifier(e);case"eof":throw new B("Unexpected end of formula",e.pos);default:throw new B(`Unexpected "${e.text}"`,e.pos)}}identifier(e){const t=e.text.toUpperCase();if(this.references&&this.peek().kind!=="("){if(t==="TRUE")return{kind:"literal",value:!0};if(t==="FALSE")return{kind:"literal",value:!1};const o=Ue(e.text);if(o)return{kind:"ref",row:o.row,col:o.col,absRow:o.absRow,absCol:o.absCol};if(this.peekRangeOp()){const i=/^(\$?)([A-Za-z]{1,3})$/.exec(e.text);if(i&&Fe(i[2])>=0)return{kind:"ref",row:-1,col:Fe(i[2]),absRow:!1,absCol:i[1]==="$"};const r=/^\$(\d+)$/.exec(e.text);if(r)return this.rowRef(r[1],e.pos,!0)}return{kind:"error",code:"#NAME?",message:`Unknown name "${e.text}"`,text:e.text}}if(this.references&&t.includes("$"))throw new B(`Unexpected "${e.text}"`,e.pos);if(this.peek().kind!=="("){if(t==="TRUE")return{kind:"literal",value:!0};if(t==="FALSE")return{kind:"literal",value:!1};throw new B(`Unknown name "${e.text}" – fields are written in brackets: [${e.text}]`,e.pos)}this.next(),this.enter(e.pos);const s=[];if(this.peek().kind!==")")for(;;){const o=this.peek().kind;if(s.push(this.references&&(o===","||o===")")?{kind:"literal",value:null}:this.expression(0)),this.peek().kind===","){this.next();continue}break}return this.expect(")",`Missing ) after the arguments of ${t}`),this.depth--,{kind:"call",name:t,args:s}}peekRangeOp(){const e=this.peek();return e.kind==="op"&&e.text===":"}rowRef(e,t,s=!1){const o=Number(e)-1;if(!(o>=0&&o<ie))throw new B(`Invalid row "${e}"`,t);return{kind:"ref",row:o,col:-1,absRow:s,absCol:!1}}rangeOperand(){const e=this.next();if(e.kind==="number"&&/^\d+$/.test(e.text))return this.rowRef(e.text,e.pos);if(e.kind==="ident"){const t=Ue(e.text);if(t)return{kind:"ref",row:t.row,col:t.col,absRow:t.absRow,absCol:t.absCol};const s=/^(\$?)([A-Za-z]{1,3})$/.exec(e.text);if(s&&Fe(s[2])>=0)return{kind:"ref",row:-1,col:Fe(s[2]),absRow:!1,absCol:s[1]==="$"};const o=/^\$(\d+)$/.exec(e.text);if(o)return this.rowRef(o[1],e.pos,!0)}throw new B("A range needs two cells, columns or rows (A1:B5, A:A, 3:3)",e.pos)}range(e,t){const s=this.rangeOperand();if(e.kind!=="ref"||s.kind!=="ref")throw new B("A range needs two cells, columns or rows (A1:B5, A:A, 3:3)",t);const o=c=>c.row<0?"col":c.col<0?"row":"cell";if(o(e)!==o(s))throw new B("A range needs two cells, columns or rows (A1:B5, A:A, 3:3)",t);const[i,r]=e.row<=s.row?[e,s]:[s,e],[l,a]=e.col<=s.col?[e,s]:[s,e];return{kind:"range",from:{kind:"ref",row:i.row,col:l.col,absRow:i.absRow,absCol:l.absCol},to:{kind:"ref",row:r.row,col:a.col,absRow:r.absRow,absCol:a.absCol}}}expect(e,t){const s=this.peek();if(s.kind!==e)throw new B(t,s.pos);this.next()}}function us(n,e=!1){if(n.length>go)throw new B(`Formula too long (more than ${go} characters)`,go);return new sc(Ya(n,e),e).parse()}const oc=/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;function ft(n){return n===null||n===""}function Ts(n,e,t=!1){if(n==null)return null;switch(typeof n){case"number":return Number.isNaN(n)?null:n;case"string":case"boolean":return n;case"bigint":return Number(n)}if(t&&w(n))return n;if(n instanceof Date){const s=n.getTime();return Number.isNaN(s)?null:s}return new I("#VALUE!",`[${e}] is not a number, text or boolean`)}function oe(n){if(typeof n=="number")return n;if(n===null||n==="")return 0;if(typeof n=="boolean")return n?1:0;if(typeof n=="string"){const e=n.trim();if(oc.test(e)){const t=Number(e);if(Number.isFinite(t))return t}return new I("#VALUE!",`"${n.length>40?n.slice(0,40)+"…":n}" is not a number`)}return n}function ke(n){return typeof n=="string"?n:n===null?"":typeof n=="number"?String(n):typeof n=="boolean"?n?"TRUE":"FALSE":n}function Lo(n){if(typeof n=="boolean")return n;if(n===null||n==="")return!1;if(typeof n=="number")return n!==0;if(typeof n=="string"){const e=n.trim().toUpperCase();return e==="TRUE"?!0:e==="FALSE"?!1:new I("#VALUE!",`"${n.length>40?n.slice(0,40)+"…":n}" is not TRUE or FALSE`)}return n}function de(n){return Number.isFinite(n)?n===0?0:n:new I("#NUM!","The result is not a finite number")}function ic(n,e){if(w(n))return n;if(w(e))return e;if(ft(n)&&ft(e))return 0;const t=typeof n=="string"&&!ft(n),s=typeof e=="string"&&!ft(e);if(t||s){if(t&&s){const u=n.toLowerCase(),f=e.toLowerCase();return u<f?-1:u>f?1:0}const r=oe(n),l=oe(e);if(!w(r)&&!w(l))return r-l;const a=ke(n),c=ke(e),h=a.toLowerCase(),d=c.toLowerCase();return h<d?-1:h>d?1:0}const o=oe(n),i=oe(e);return o-i}const en={IF:{min:2,max:3},IFERROR:{min:2,max:2},AND:{min:1,max:255},OR:{min:1,max:255}},rc={SUM:"sum",AVG:"avg",AVERAGE:"avg",MIN:"min",MAX:"max",COUNT:"count"};function ps(n){const e=[];for(const t of n){if(ft(t))continue;const s=oe(t);if(w(s))return s;e.push(s)}return e}function po(n){return{min:1,max:1,fn:e=>{const t=oe(e[0]);return w(t)?t:de(n(t))}}}function yi(n,e){const t=Math.trunc(e),s=Math.pow(10,t);if(s===0)return 0;const o=Math.abs(n)*s;if(!Number.isFinite(o))return n;const i=Math.round(o>=1e15?o:Number(o.toPrecision(15)))/s;return n<0?-i:i}const ss={ABS:po(Math.abs),FLOOR:po(Math.floor),CEILING:po(Math.ceil),SQRT:{min:1,max:1,fn:n=>{const e=oe(n[0]);return w(e)?e:e<0?new I("#NUM!","SQRT of a negative number"):Math.sqrt(e)}},ROUND:{min:1,max:2,fn:n=>{const e=oe(n[0]);if(w(e))return e;const t=n.length>1?oe(n[1]):0;return w(t)?t:de(yi(e,t))}},MOD:{min:2,max:2,fn:n=>{const e=oe(n[0]);if(w(e))return e;const t=oe(n[1]);return w(t)?t:t===0?new I("#DIV/0!","MOD by zero"):de(e-t*Math.floor(e/t))}},POWER:{min:2,max:2,fn:n=>{const e=oe(n[0]);if(w(e))return e;const t=oe(n[1]);return w(t)?t:de(Math.pow(e,t))}},SUM:{min:1,max:255,fn:n=>{const e=ps(n);return w(e)?e:de(e.reduce((t,s)=>t+s,0))}},AVG:{min:1,max:255,fn:n=>{const e=ps(n);return w(e)?e:e.length?de(e.reduce((t,s)=>t+s,0)/e.length):new I("#DIV/0!","AVG of no numbers")}},MIN:{min:1,max:255,fn:n=>{const e=ps(n);return w(e)?e:e.length?Math.min(...e):0}},MAX:{min:1,max:255,fn:n=>{const e=ps(n);return w(e)?e:e.length?Math.max(...e):0}},COUNT:{min:1,max:255,fn:n=>n.filter(e=>typeof e=="number").length},NOT:{min:1,max:1,fn:n=>{const e=Lo(n[0]);return w(e)?e:!e}},CONCAT:{min:1,max:255,fn:n=>{let e="";for(const t of n){const s=ke(t);if(w(s))return s;e+=s}return e}},LEN:{min:1,max:1,fn:n=>{const e=ke(n[0]);return w(e)?e:e.length}},UPPER:{min:1,max:1,fn:n=>{const e=ke(n[0]);return w(e)?e:e.toUpperCase()}},LOWER:{min:1,max:1,fn:n=>{const e=ke(n[0]);return w(e)?e:e.toLowerCase()}},TRIM:{min:1,max:1,fn:n=>{const e=ke(n[0]);return w(e)?e:e.trim().replace(/\s+/g," ")}},ISBLANK:{min:1,max:1,fn:n=>ft(n[0])}};ss.AVERAGE=ss.AVG;const nc=new Set(["__proto__","constructor","prototype"]),lc=(n,e)=>Object.prototype.hasOwnProperty.call(n,e);function ac(n,e,t,s=e.split(".")){if(t!=null&&t.isCalculated(e))return Ts(t.getValue(n,e),e,!0);if(s.some(i=>nc.has(i)))return new I("#NAME?",`Unknown field [${e}]`);let o=n;for(let i=0;i<s.length;i++){if(o==null||typeof o!="object")return null;if(!lc(o,s[i]))return i===0&&!(t!=null&&t.hasColumn(e))?new I("#NAME?",`Unknown field [${e}]`):null;o=o[s[i]]}return Ts(o,e)}function Xi(n,e,t){if(w(e))return e;if(w(t))return t;if(n==="&"){const i=ke(e);if(w(i))return i;const r=ke(t);return w(r)?r:i+r}if(n==="="||n==="<>"||n==="<"||n==="<="||n===">"||n===">="){const i=ic(e,t);if(w(i))return i;switch(n){case"=":return i===0;case"<>":return i!==0;case"<":return i<0;case"<=":return i<=0;case">":return i>0;default:return i>=0}}const s=typeof e=="number"?e:oe(e);if(w(s))return s;const o=typeof t=="number"?t:oe(t);if(w(o))return o;switch(n){case"+":return de(s+o);case"-":return de(s-o);case"*":return de(s*o);case"/":return o===0?new I("#DIV/0!","Division by zero"):de(s/o);default:return de(Math.pow(s,o))}}function cc(n,e){return n==null?null:typeof n=="number"?Number.isNaN(n)?new I("#NUM!",`${e} returned NaN`):n:typeof n=="string"||typeof n=="boolean"||w(n)?n:n instanceof Date?Ts(n,e):new I("#VALUE!",`${e} returned no number, text or boolean`)}function Yi(n,e,t){const s=new Array(n.length);for(let o=0;o<n.length;o++){const i=n[o](e,t);if(w(i))return i;s[o]=i}return s}class hc{constructor(e){this.functions=e}compile(e){const t=this.node(e);return(s,o)=>{try{const i=t(s,o);return typeof i=="number"?de(i):i}catch(i){return new I("#VALUE!",i instanceof Error?i.message.slice(0,200):"Evaluation failed")}}}evaluate(e,t,s){return this.compile(e)(t,s)}node(e){switch(e.kind){case"literal":{const t=e.value;return()=>t}case"field":{const t=e.name,s=t.split(".");return(o,i)=>ac(o,t,i,s)}case"unary":{const t=this.node(e.operand),s=e.op==="-";return(o,i)=>{const r=t(o,i),l=typeof r=="number"?r:oe(r);return w(l)?l:s?-l:l}}case"binary":{const t=this.node(e.left),s=this.node(e.right),o=e.op;return o==="*"||o==="+"||o==="-"?(i,r)=>{const l=t(i,r),a=s(i,r);return typeof l=="number"&&typeof a=="number"?de(o==="*"?l*a:o==="+"?l+a:l-a):Xi(o,l,a)}:(i,r)=>Xi(o,t(i,r),s(i,r))}case"call":return this.call(e.name,e.args);default:{const t=new I("#ERROR!","Cell references are not allowed in column formulas");return()=>t}}}call(e,t){const s=this.functions.get(e);if(s){const a=t.map(c=>this.node(c));return(c,h)=>{const d=Yi(a,c,h);if(w(d))return d;try{return cc(s(...d),e)}catch(u){return new I("#VALUE!",`${e}: ${u instanceof Error?u.message.slice(0,200):"failed"}`)}}}switch(e){case"IF":{const[a,c,h]=t.map(d=>this.node(d));return(d,u)=>{const f=Lo(a(d,u));return w(f)?f:f?c(d,u):h?h(d,u):!1}}case"IFERROR":{const[a,c]=t.map(h=>this.node(h));return(h,d)=>{const u=a(h,d);return w(u)?c(h,d):u}}case"AND":case"OR":{const a=e==="AND",c=t.map(h=>this.node(h));return(h,d)=>{for(const u of c){const f=Lo(u(h,d));if(w(f))return f;if(a&&!f)return!1;if(!a&&f)return!0}return a}}}const o=rc[e],i=t[0];if(o&&t.length===1&&i.kind==="field"){const a=i.name;return(c,h)=>{if(!h)return new I("#VALUE!",`${e}([${a}]) needs the rows of a table`);if(!h.hasColumn(a))return new I("#NAME?",`Unknown column [${a}] in ${e}`);const d=h.aggregate(a,o);return d===void 0?o==="avg"?new I("#DIV/0!","AVG of no numbers"):0:Ts(d,a,!0)}}const r=ss[e];if(!r){const a=new I("#NAME?",`Unknown function ${e}`);return()=>a}const l=t.map(a=>this.node(a));return(a,c)=>{const h=Yi(l,a,c);return w(h)?h:r.fn(h)}}}const dc=Object.freeze([...Object.keys(ss),...Object.keys(en)].sort());function Ht(n,e,t,s){switch(n.kind){case"literal":return;case"field":t.includes(n.name)||t.push(n.name);return;case"unary":return Ht(n.operand,e,t,s);case"binary":return Ht(n.left,e,t,s)??Ht(n.right,e,t,s);case"call":{if(!e.has(n.name)){const o=ss[n.name]??en[n.name];if(!o)return new I("#NAME?",`Unknown function ${n.name}`);if(n.args.length<o.min||n.args.length>o.max){const i=o.min===o.max?`${o.min}`:o.max>=255?`at least ${o.min}`:`${o.min} to ${o.max}`;return new I("#ERROR!",`${n.name} needs ${i} argument${o.max===1?"":"s"}, got ${n.args.length}`)}["SUM","AVG","AVERAGE","MIN","MAX","COUNT"].includes(n.name)&&n.args.length===1&&n.args[0].kind==="field"&&(s.aggregates=!0)}for(const o of n.args){const i=Ht(o,e,t,s);if(i)return i}return}default:return new I("#ERROR!","Cell references are not allowed in column formulas")}}function Ci(n,e){let t="";const s=new Map;for(const c of Object.keys((e==null?void 0:e.functions)??{})){const h=e.functions[c];typeof h=="function"&&s.set(c.toUpperCase(),h)}let o,i;const r=[],l={aggregates:!1};let a;try{t=typeof n=="string"?n:String(n??"");const c=t.replace(/^\s+/,"");o=us(c.startsWith("=")&&!c.startsWith("==")?c.slice(1):t),i=Ht(o,s,r,l),i||(a=new hc(s).compile(o))}catch(c){i=c instanceof B?c.toFormulaError():new I("#ERROR!","Invalid formula")}return i&&(o=void 0,r.length=0),i&&(a=void 0),Object.freeze({source:t,ast:o,error:i,fields:Object.freeze([...r]),usesAggregates:l.aggregates,evaluate:(c,h)=>a?a(c,h):i})}function vi(n,e){const t=typeof n=="string"?Ci(n,e):n;return(s,o)=>t.evaluate(s,o)}const uc={"=":10,"<>":10,"<":10,"<=":10,">":10,">=":10,"&":20,"+":30,"-":30,"*":40,"/":40,"^":60};function mo(n){return n.row<0?`${n.absCol?"$":""}${Ne(n.col)}`:n.col<0?`${n.absRow?"$":""}${n.row+1}`:n.row>=ie||n.col>=q?"#REF!":`${n.absCol?"$":""}${Ne(n.col)}${n.absRow?"$":""}${n.row+1}`}function fc(n){return String(n)}function ht(n,e){switch(n.kind){case"literal":return n.value===null?"":typeof n.value=="string"?`"${n.value.replace(/"/g,'""')}"`:typeof n.value=="boolean"?n.value?"TRUE":"FALSE":fc(n.value);case"field":return`[${n.name}]`;case"ref":return mo(n);case"range":return`${mo(n.from)}:${mo(n.to)}`;case"error":return n.text??n.code;case"call":return`${n.name}(${n.args.map(t=>ht(t,0)).join(",")})`;case"unary":{if(n.op==="%")return`${ht(n.operand,70)}%`;const t=ht(n.operand,75);return`${n.op}${t}`}case"binary":{const t=uc[n.op],s=`${ht(n.left,t)}${n.op}${ht(n.right,t+1)}`;return t<e?`(${s})`:s}}}function zt(n){return ht(n,0)}const gc=new Set(["XLOOKUP","IFS","SWITCH","TEXTJOIN","CONCAT","IFNA","XOR"]);function pc(n,e){let t;try{t=us(n.slice(1),!0)}catch{return}let s=!0;const o=(l,a)=>({...l,row:l.row<0?e.dRow+(a?e.rows-1:0):l.row+e.dRow,col:l.col<0?e.dCol+(a?e.cols-1:0):l.col+e.dCol,absRow:l.row<0?!0:l.absRow,absCol:l.col<0?!0:l.absCol}),i=l=>{switch(l.kind){case"field":return s=!1,l;case"ref":return o(l,!1);case"range":return{kind:"range",from:o(l.from,!1),to:o(l.to,!0)};case"unary":return{...l,operand:i(l.operand)};case"binary":return{...l,left:i(l.left),right:i(l.right)};case"call":return{...l,name:gc.has(l.name)?`_xlfn.${l.name}`:l.name,args:l.args.map(i)};default:return l}},r=i(t);return s?zt(r):void 0}class Q extends ds{constructor(e,t,s,o=[]){super(e,o,s),this.areaIdent=e,this.arr=t,this.defaultRowHeight=s,this.columnDefs=o,this.filteredArr=[...t]}externalFilterChanged(e){this.filteredArr=this.arr?this.arr.filter(e):[]}getRowCount(){return this.filteredArr?this.filteredArr.length:0}getUnfilteredRowCount(){var e;return((e=this.arr)==null?void 0:e.length)??0}canMoveRows(e,t){return Qs(this.filteredArr.length,this.arr.length,e,t)}moveRows(e,t){return wi(this.filteredArr,this.arr,e,t)}getValueAt(e,t){const s=this.filteredArr[e],o=s[t];return this.sheetCells&&typeof o=="string"?this.sheetCells.valueAt(s,t,o):o}getInputValueAt(e,t){var s;return(s=this.filteredArr[e])==null?void 0:s[t]}setValue(e,t,s){var r;const o=(r=this.columnDefs[t])==null?void 0:r.editInputPipe;o&&(s=o(s,e,t));const i=this.filteredArr[e];return i?(i[t]=s,!0):!1}getRowByIndex(e){return this.filteredArr[e]}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.getRowHeight===Q.prototype.getRowHeight&&this.defaultRowHeight>0?this.defaultRowHeight:void 0}changeColumnOrder(e,t){const s=new Set,o=i=>{i&&!s.has(i)&&(s.add(i),this.arrayMove(i,e,t))};(this.arr??[]).forEach(o),this.filteredArr.forEach(o),super.changeColumnOrder(e,t)}}class At{constructor(e){this.serial=e,this.type="SheetDate"}toDate(){return Si(this.serial)}}function G(n){return!!n&&typeof n=="object"&&n.type==="SheetDate"&&typeof n.serial=="number"}const tn=864e5,sn=Date.UTC(1899,11,30);function Nt(n){const e=n.getTime();if(Number.isNaN(e))return NaN;let s=(Date.UTC(n.getFullYear(),n.getMonth(),n.getDate(),n.getHours(),n.getMinutes(),n.getSeconds(),n.getMilliseconds())-sn)/tn;return s<61&&(s-=1),s}function Si(n){const e=n<60?n+1:n>=60&&n<61?61+(n-60):n,t=new Date(sn+Math.round(e*tn));return new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds())}function Kt(n,e,t){return Nt(new Date(n,e-1,t))}function et(n){if(Math.floor(n)===60)return{y:1900,m:2,d:29};const e=Si(Math.floor(n));return{y:e.getFullYear(),m:e.getMonth()+1,d:e.getDate()}}class tt{constructor(e,t,s,o,i){this.row=e,this.col=t,this.rows=s,this.cols=o,this.read=i,this.type="FormulaRange"}get(e,t){return e<0||t<0||e>=this.rows||t>=this.cols?null:this.read(this.row+e,this.col+t)}values(){const e=[];for(let t=0;t<this.rows;t++)for(let s=0;s<this.cols;s++)e.push(this.get(t,s));return e}}function Ye(n){return!!n&&typeof n=="object"&&n.type==="FormulaRange"}function xe(n){if(n===0||!Number.isFinite(n))return n===0?0:n;const e=Number(n.toPrecision(15));return e===0?0:e}function W(n){return Number.isFinite(n)?xe(n):new I("#NUM!","The result is not a finite number")}const Ji=/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i,mc=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function Et(n){const e=mc.exec(n);if(!e)return;const t=new Date(+e[1],+e[2]-1,+e[3],+(e[4]??0),+(e[5]??0),+(e[6]??0));if(t.getMonth()===+e[2]-1)return Nt(t)}function on(n){if(n==null)return null;switch(typeof n){case"number":return Number.isNaN(n)?null:n;case"string":return n;case"boolean":return n;case"bigint":return Number(n)}if(w(n)||G(n))return n;if(n instanceof Date){const e=Nt(n);return Number.isNaN(e)?null:new At(e)}return new I("#VALUE!","The cell holds no number, text or boolean")}function _(n){return Ye(n)?n.rows===1&&n.cols===1?_(n.get(0,0)):new I("#VALUE!","A range where one value is expected"):n}function K(n,e){const t=_(n);if(typeof t=="number")return t;if(t===null||t==="")return 0;if(typeof t=="boolean")return t?1:0;if(G(t))return t.serial;if(typeof t=="string"){const s=t.trim();if(Ji.test(s)){const o=Number(s);if(Number.isFinite(o))return o}if(s.endsWith("%")&&Ji.test(s.slice(0,-1).trim()))return Number(s.slice(0,-1).trim())/100;if(e.isoDatesAsDates){const o=Et(s);if(o!==void 0)return o}return new I("#VALUE!",`"${t.length>40?t.slice(0,40)+"…":t}" is not a number`)}return t}function qi(n){const e=xe(n),t=Math.abs(e);return t!==0&&(t>=1e15||t<1e-9)?e.toExponential().replace("e","E"):String(e)}function re(n){const e=_(n);return typeof e=="string"?e:e===null?"":typeof e=="number"?qi(e):typeof e=="boolean"?e?"TRUE":"FALSE":G(e)?qi(e.serial):e}function gt(n){const e=_(n);if(typeof e=="boolean")return e;if(e===null||e==="")return!1;if(typeof e=="number")return e!==0;if(G(e))return e.serial!==0;if(typeof e=="string"){const t=e.trim().toUpperCase();return t==="TRUE"?!0:t==="FALSE"?!1:new I("#VALUE!",`"${e.length>40?e.slice(0,40)+"…":e}" is not TRUE or FALSE`)}return e}function Zi(n){return typeof n=="string"?1:typeof n=="boolean"?2:0}function fs(n,e){let t=_(n),s=_(e);if(w(t))return t;if(w(s))return s;if(G(t)&&(t=t.serial),G(s)&&(s=s.serial),t===null&&s===null)return 0;t===null&&(t=typeof s=="string"?"":typeof s=="boolean"?!1:0),s===null&&(s=typeof t=="string"?"":typeof t=="boolean"?!1:0);const o=Zi(t),i=Zi(s);if(o!==i)return o-i;if(typeof t=="number"&&typeof s=="number"){const r=xe(t)-xe(s);return r===0?0:r<0?-1:1}if(typeof t=="string"&&typeof s=="string"){const r=t.toLowerCase(),l=s.toLowerCase();return r<l?-1:r>l?1:0}return(t?1:0)-(s?1:0)}function Oo(n){return n===null||n===""}function Qi(n){return G(n)?n.toDate():Ye(n)?_(n):n}class Pe extends ds{constructor(e,t,s,o,i,r=[],l=0){super(e,r,i),this.rowCount=s,this.columnCount=o,this.columnOffset=l,this.version=0,this.rows=new Map,this.physicalOfArray=new Map,this.setSheetData(t,s,o)}setSheetData(e,t=this.rowCount,s=this.columnCount){this.rows.clear(),this.physicalOfArray.clear(),e.forEach((o,i)=>{if(o&&o.some(r=>r!=null&&r!=="")){const r=[...o];this.rows.set(i,r),this.physicalOfArray.set(r,i)}}),this.rowCount=Math.max(t,e.length),this.columnCount=Math.max(s,e.reduce((o,i)=>Math.max(o,(i==null?void 0:i.length)??0),0)),this.perm=void 0,this.inverse=void 0,this.version++}getSheetData(){let e=-1,t=-1;this.rows.forEach((o,i)=>{for(let r=o.length-1;r>=0;r--)if(!_t(o[r])){e=Math.max(e,i),t=Math.max(t,r);break}});const s=[];for(let o=0;o<=e;o++){const i=this.rows.get(o);s.push(Array.from({length:t+1},(r,l)=>i&&!_t(i[l])?i[l]:""))}return s}getCell(e,t){var s;return(s=this.rows.get(e))==null?void 0:s[t]}setCell(e,t,s){let o=this.rows.get(e);if(!o){if(_t(s))return;o=[],this.rows.set(e,o),this.physicalOfArray.set(o,e)}o[t]=s}getRowArray(e){return this.rows.get(e)}forEachCell(e){this.rows.forEach((t,s)=>t.forEach((o,i)=>e(s,i,o)))}getPhysicalRowOfArray(e){return this.physicalOfArray.get(e)}getSheetColumnCount(){return this.columnCount}setColumnDefs(e){this.columnDefs=e,this.cellRenderers=e.map(t=>{var s;return(s=t.rendererMap)==null?void 0:s[this.areaIdent]})}getRowCount(){return this.perm?this.perm.length:this.rowCount}getUnfilteredRowCount(){return this.rowCount}getPhysicalRowIndex(e){return this.perm?this.perm[e]:e}getDisplayRowIndex(e){return this.perm?(this.inverse||(this.inverse=new Map,this.perm.forEach((t,s)=>this.inverse.set(t,s))),this.inverse.get(e)??-1):e<this.rowCount?e:-1}getValueAt(e,t){const s=this.rows.get(this.getPhysicalRowIndex(e)),o=s==null?void 0:s[t-this.columnOffset];return o==null?"":this.sheetCells&&typeof o=="string"?this.sheetCells.valueAt(s,t,o):o}getInputValueAt(e,t){var s;return((s=this.rows.get(this.getPhysicalRowIndex(e)))==null?void 0:s[t-this.columnOffset])??""}getTextValueAt(e,t){const s=this.getValueAt(e,t);return w(s)?s.code:String(s)}setValue(e,t,s){var i;const o=(i=this.columnDefs[t])==null?void 0:i.editInputPipe;return o&&(s=o(s,e,t)),t<this.columnOffset||e<0||e>=this.getRowCount()?!1:(this.setCell(this.getPhysicalRowIndex(e),t-this.columnOffset,s),!0)}getRowByIndex(e){return this.rows.get(this.getPhysicalRowIndex(e))}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.defaultRowHeight>0?this.defaultRowHeight:void 0}getMaxColspan(){return 1}getMaxRowspan(){return 1}externalFilterChanged(e){const t=[];for(let s=0;s<this.rowCount;s++)e(this.rows.get(s)??[],s,[])&&t.push(s);this.perm=t.length===this.rowCount?void 0:Int32Array.from(t),this.inverse=void 0}doSort(e){const t=e.filter(o=>o.sortState==="asc"||o.sortState==="desc"),s=this.perm?Array.from(this.perm):Array.from({length:this.rowCount},(o,i)=>i);return s.sort((o,i)=>{for(const{columnIndex:r,sortState:l}of t){const a=this.valueOfPhysical(o,r),c=this.valueOfPhysical(i,r),h=a===""||w(a),d=c===""||w(c);if(h||d){if(h!==d)return h?1:-1;continue}const u=fs(a,c),f=typeof u=="number"?u:0;if(f)return l==="asc"?f:-f}return o-i}),!t.length&&s.length===this.rowCount?(this.perm=void 0,this.inverse=void 0,!0):(this.perm=Int32Array.from(s),this.inverse=void 0,!0)}insertRows(e,t){this.shiftRows(e,t),this.rowCount+=t}deleteRows(e,t){const s=[];for(let o=e;o<e+t;o++){const i=this.rows.get(o);i&&(s.push([o-e,i]),this.physicalOfArray.delete(i),this.rows.delete(o))}return this.shiftRows(e+t,-t),this.rowCount=Math.max(0,this.rowCount-t),s}restoreRows(e,t,s){this.insertRows(e,t);for(const[o,i]of s)this.rows.set(e+o,i),this.physicalOfArray.set(i,e+o)}insertColumns(e,t){this.rows.forEach(s=>{s.length>e&&s.splice(e,0,...new Array(t))}),this.columnCount+=t,this.changed()}deleteColumns(e,t){const s=[];return this.rows.forEach(o=>{const i=o.splice(e,t);i.some(r=>!_t(r))&&s.push([o,i])}),this.columnCount=Math.max(0,this.columnCount-t),this.changed(),s}restoreColumns(e,t,s){this.insertColumns(e,t);for(const[o,i]of s)i.forEach((r,l)=>{o[e+l]=r})}getContentExtent(){let e=-1,t=-1;return this.rows.forEach((s,o)=>{let i=-1;for(let l=s.length-1;l>=0;l--)if(!_t(s[l])){i=l;break}if(i<0)return;const r=this.getDisplayRowIndex(o);r<0||(e=Math.max(e,r),t=Math.max(t,i+this.columnOffset))}),[e,t]}valueOfPhysical(e,t){const s=this.rows.get(e),o=s==null?void 0:s[t-this.columnOffset];return o==null?"":this.sheetCells&&typeof o=="string"?this.sheetCells.valueAt(s,t,o):o}shiftRows(e,t){const s=Array.from(this.rows).filter(([o])=>o>=e).sort((o,i)=>t>0?i[0]-o[0]:o[0]-i[0]);for(const[o]of s)this.rows.delete(o);for(const[o,i]of s)this.rows.set(o+t,i),this.physicalOfArray.set(i,o+t);this.changed()}changed(){this.perm=void 0,this.inverse=void 0,this.version++}}function _t(n){return n==null||n===""}class Is{constructor(e=0,t=0,s=0,o=0){this.top=e,this.right=t,this.bottom=s,this.left=o}}class Le{constructor(e=34,t=34,s=34){this.header=e,this.body=t,this.footer=s}}class rn{constructor(){this.checkedRows=[]}getCheckedRows(){return this.checkedRows}setCheckedRows(e){this.checkedRows=e}addCheckedRows(e){this.checkedRows||(this.checkedRows=[]);for(const t of e)this.checkedRows.includes(t)||this.checkedRows.push(t)}checkRow(e,t){this.checkedRows||(this.checkedRows=[]),t?this.checkedRows.includes(e)||this.checkedRows.push(e):this.removeSelectedRow(e)}isRowChecked(e){return this.checkedRows&&this.checkedRows.includes(e)?"full":"none"}checkAll(e){this.checkedRows=[]}removeSelectedRow(e){if(this.checkedRows){const t=this.checkedRows.indexOf(e);t>-1&&this.checkedRows.splice(t,1)}}}class Mt{constructor(e=[]){this.allRootNodes=e}checkRow(e,t){this.setCheckedRecursive(e,t),this.autoCheckParent(e.parent)}checkAll(e=this.allRootNodes){for(const s of e)this.uncheckRecursive(s);const t=new Set;for(const s of e)s.parent&&t.add(s.parent);t.forEach(s=>this.autoCheckParent(s))}getCheckedRows(){const e=[];return this.addSelectedRecursive(this.allRootNodes,e),e}isRowChecked(e){return e.checked?"full":this.hasMixedDescendants(e)?"semi":"none"}hasMixedDescendants(e){let t=!1,s=!1;const o=i=>{for(const r of i??[])if(r.checked?t=!0:s=!0,t&&s||o(r.children))return!0;return!1};return o(e.children)}setCheckedRecursive(e,t){if(e.checked=t,e.children)for(const s of e.children)this.setCheckedRecursive(s,t)}setCheckedRows(e){this.addCheckedRows(e)}addCheckedRows(e){for(const t of e)t.checked=!0}autoCheckParent(e){if(e){const t=this.areAllChildrenChecked(e),s=this.areAllChildrenUnchecked(e);t?e.checked=!0:e.checked=!1,this.autoCheckParent(e.parent)}}areAllChildrenChecked(e){var t,s;if((t=e.children)!=null&&t.length){for(const o of e.children)if(!o.checked||(s=o.children)!=null&&s.length&&!this.areAllChildrenChecked(o))return!1}return!0}areAllChildrenUnchecked(e){var t,s;if((t=e.children)!=null&&t.length){for(const o of e.children)if(o.checked||(s=o.children)!=null&&s.length&&!this.areAllChildrenUnchecked(o))return!1}return!0}uncheckRecursive(e){if(e.checked=!1,e.children)for(const t of e.children)this.uncheckRecursive(t)}addSelectedRecursive(e,t){for(const s of e)s.checked&&t.push(s),s.children&&this.addSelectedRecursive(s.children,t)}}class bc{constructor(e){this.bodyAreaModel=e}getCheckedRows(){var e;return((e=this.bodyAreaModel.rowSelectionModel)==null?void 0:e.getCheckedRows())??[]}setCheckedRows(e){var t;(t=this.bodyAreaModel.rowSelectionModel)==null||t.setCheckedRows(e)}addCheckedRows(e){var t;(t=this.bodyAreaModel.rowSelectionModel)==null||t.addCheckedRows(e)}checkRow(e,t){const s=this.bodyAreaModel.rowSelectionModel;if(s instanceof Mt){this.getTopTreeRows().forEach(o=>s.checkRow(o,t));return}this.checkAll(t?this.getBodyRows():[])}isRowChecked(e){const t=this.bodyAreaModel.rowSelectionModel;if(t instanceof Mt){const a=this.getTopTreeRows().map(c=>t.isRowChecked(c));return!a.length||a.every(c=>c==="none")?"none":a.every(c=>c==="full")?"full":"semi"}const s=this.getCheckedRows(),o=this.bodyAreaModel.getRowCount();if(!s.length||!o)return"none";if(s.length<o)return"semi";const i=this.cache;if(i&&i.checkedRows===s&&i.checkedCount===s.length&&i.rowCount===o)return i.state;const r=new Set(s);let l="full";for(let a=0;a<o;a++)if(!r.has(this.bodyAreaModel.getRowByIndex(a))){l="semi";break}return this.cache={checkedRows:s,checkedCount:s.length,rowCount:o,state:l},l}checkAll(e){const t=this.bodyAreaModel.rowSelectionModel;if(!t)return;if(!e.length){t.setCheckedRows([]);return}const s=new Set(t.getCheckedRows());e.forEach(o=>s.add(o)),t.setCheckedRows(Array.from(s))}getTopTreeRows(){const e=this.bodyAreaModel;return typeof e.getDisplayedRootRows=="function"?e.getDisplayedRootRows():this.getBodyRows().filter(t=>!t.parent)}getBodyRows(){const e=this.bodyAreaModel.getRowCount(),t=new Array(e);for(let s=0;s<e;s++)t[s]=this.bodyAreaModel.getRowByIndex(s);return t}}function os(n){return n!=null&&n.length&&N(n[0])?1:0}class T{constructor(e=100,t="px"){this.value=e,this.unit=t}}const Pt=()=>!0,nn=()=>!1,Tt=new WeakSet,Ds=new WeakMap;function ln(n,e){e?Tt.delete(n):Tt.add(n),an(n)}function bo(n,e){e?Ds.set(n,e):Ds.delete(n),an(n)}function No(n){var e;return Ds.has(n)?!Tt.has(n):!Tt.has(n)&&((e=n.isVisible)==null?void 0:e.call(n))!==!1}function an(n){const e=Ds.get(n),t=!Tt.has(n);e?n.isVisible=()=>!Tt.has(n)&&e():n.isVisible=t?Pt:nn}const $s=class $s{constructor(e,t,s,o=0,i=0,r=!1,l=new Le,a=[],c=[],h=-1,d=0,u=400,f=()=>{}){var p,m,b,y;this.headerAreaModel=e,this.bodyAreaModel=t,this.footerAreaModel=s,this.fixedLeftColumnCount=o,this.fixedRightColumnCount=i,this.rowCheckboxVisible=r,this.defaultRowHeights=l,this.columnDefs=a,this.columnSizes=c,this.overridingColumnWidth=h,this.columnCount=d,this.parentSize=u,this.getSelectionModel=f,this.rowCount=0,this.contentHeightInPx=0,this.contentWidthInPx=0,this.padding=new Is(0,0,0,0),this.xPositions=[],this.headerVisible=!0,this.footerVisible=!0,e.areaIdent="header",t.areaIdent="body",s.areaIdent="footer",this.columnCount||((p=this.columnDefs)!=null&&p.length?this.columnCount=this.columnDefs.length:(m=this.columnSizes)!=null&&m.length&&(this.columnCount=(b=this.columnSizes)==null?void 0:b.length));const g=(y=this.columnDefs)==null?void 0:y[os(this.columnDefs)];be(g)&&!t.rowSelectionModel&&(t.rowSelectionModel=new rn),be(g)&&!e.rowSelectionModel&&(e.rowSelectionModel=new bc(t))}init(){this.recalcSize(this.parentSize),this.overridingColumnWidth===-1&&this.calcXPositions(),this.headerAreaModel&&this.headerAreaModel.init(),this.bodyAreaModel&&this.bodyAreaModel.init(),this.footerAreaModel&&this.footerAreaModel.init()}setParentWidth(e){this.parentSize=e}getColumnCount(){return this.columnCount}setColumnWidth(e,t){var s,o;if(t=Math.max(0,t),this.overridingColumnWidth!==-1&&(this.overridingColumnWidth=t),e>-1&&e<((s=this.columnSizes)==null?void 0:s.length)){this.columnSizes[e]=t;const i=(o=this.columnDefs)==null?void 0:o[e];i&&(i.width=new T(t,"px"))}this.overridingColumnWidth===-1&&this.calcXPositions(),this.recalcContentWidthInPx()}getColumnWidth(e){var s;const t=this.getColumnDef(e);return t&&t.isVisible&&!t.isVisible()?0:this.overridingColumnWidth!==-1?this.overridingColumnWidth:e>-1&&e<((s=this.columnSizes)==null?void 0:s.length)?this.columnSizes[e]:0}getXPosByColumnIndex(e){return e===0?0:this.overridingColumnWidth>-1?this.overridingColumnWidth*e:this.xPositions[e]}recalcSize(e){e>0&&(this.parentSize=e),this.recalcColumnWidths(e),this.recalcHeightAndPadding()}recalcHeightAndPadding(){const e=this.getAreaModel("body");this.rowCount=e.getRowCount(),this.contentHeightInPx=this.getAreaHeight("body"),this.recalcContentWidthInPx(),this.recalcPadding()}recalcPadding(){const e=this.getSideAreaWidth("west"),t=this.getSideAreaWidth("east"),s=this.headerVisible?this.getAreaHeight("header"):0,o=this.footerVisible?this.getAreaHeight("footer"):0;this.padding=new Is(s,t,o,e)}getPadding(){return this.padding}getContentHeightInPixel(){return this.contentHeightInPx}getContentWidthInPixel(){return this.contentWidthInPx}getRowHeight(e,t){return this.getAreaModel(e).getRowHeight(t)}getModel(e){return this.getAreaModel(e)}getAreaHeight(e){var r;const t=this.getModel(e),s=t.getRowCount();if(!(s>0))return 0;const o=(r=t.getConstantRowHeight)==null?void 0:r.call(t);if(o!==void 0&&o>0)return s*o;let i=0;for(let l=0;l<s;l++)i=i+t.getRowHeight(l);return i>0?i:s*(this.defaultRowHeights[e]||0)}getSideAreaWidth(e){const[t,s]=this.getSideStartAndEndColumnIndex(e);let o=0;for(let i=t;i<=s;i++)o=o+this.getColumnWidth(i);return o}getSideStartAndEndColumnIndex(e){const t=this.getFixedLeftColumnCount(),s=this.getFixedRightColumnCount();let o=0,i=this.columnCount-1;return e==="west"?i=t-1:e==="east"?o=this.columnCount-s:(o=t,i=this.columnCount-s-1),[o,i]}getColumnDef(e){if(e<this.columnDefs.length)return this.columnDefs[e]}getFixedLeftColumnCount(){return this.fixedLeftColumnCount}getFixedRightColumnCount(){return this.fixedRightColumnCount}getAreaModel(e){if(e==="header")return this.headerAreaModel;if(e==="body")return this.bodyAreaModel;if(e==="footer")return this.footerAreaModel;throw new Error("Wrong ident.")}getBodyModel(){return this.bodyAreaModel}isFooterVisibe(){var e;return this.footerVisible&&(((e=this.footerAreaModel)==null?void 0:e.getRowCount())??0)>0}isHeaderVisibe(){var e;return this.headerVisible&&(((e=this.headerAreaModel)==null?void 0:e.getRowCount())??0)>0}setHeaderVisible(e){this.headerVisible=e,this.recalcPadding()}setFooterVisible(e){this.footerVisible=e,this.recalcPadding()}setColumnVisible(e,t){var i;const s=this.findColumnDef(e);if(!s)return!1;ln(s,t);const o=s;return typeof o.visible=="boolean"&&(o.visible=t),(i=this.columnDefs)!=null&&i.some(r=>{var l;return((l=r.width)==null?void 0:l.unit)==="weight"})&&this.recalcColumnWidths(this.parentSize),this.recalcContentWidthInPx(),this.recalcPadding(),this.calcXPositions(),!0}isColumnVisible(e){var s;const t=this.findColumnDef(e);return t?((s=t.isVisible)==null?void 0:s.call(t))!==!1:typeof e=="number"&&e>=0&&e<this.getColumnCount()}isRowCheckboxVisible(){return this.rowCheckboxVisible}externalFilterChanged(e){this.getAreaModel("body").externalFilterChanged(e)}doSort(e){return this.getAreaModel("body").doSort(e)}sort(e){return this.getAreaModel("body").sort(e)}getColumnDefs(){return this.columnDefs}getColumnProperty(e){var t,s;return((s=(t=this.columnDefs)==null?void 0:t[e])==null?void 0:s.property)??""}getBodyRowByIndex(e){return this.getBodyModel().getRowByIndex(e)}isSortable(e){var t;if(this.columnDefs&&e<this.columnDefs.length){const s=(t=this.columnDefs[e])==null?void 0:t.sortable;if(typeof s=="function")return s()}return!1}changeColumnOrder(e,t){var s,o,i;this.arrayMove(this.columnDefs,e,t),this.arrayMove(this.columnSizes,e,t),(s=this.headerAreaModel)==null||s.changeColumnOrder(e,t),(o=this.bodyAreaModel)==null||o.changeColumnOrder(e,t),(i=this.footerAreaModel)==null||i.changeColumnOrder(e,t),this.calcXPositions()}recalcColumnWidths(e){var t,s,o;if(!((t=this.columnDefs)!=null&&t.length)&&!((s=this.columnSizes)!=null&&s.length)&&(this.columnSizes=new Array(this.getColumnCount()).fill(this.overridingColumnWidth>-1?this.overridingColumnWidth:$s.DEFAULT_COLUMN_WIDTH)),(o=this.columnDefs)!=null&&o.length){const i=this.columnDefs.filter(h=>{var d;return((d=h.width)==null?void 0:d.unit)==="weight"});this.columnSizes=this.columnDefs.map(h=>{if(h.width.unit==="%"&&e){let d=Math.floor(h.width.value*e/100);if(h.minWidth){const u=this.sizeToPixel(h.minWidth,e);d=Math.max(u,d)}if(h.maxWidth){const u=this.sizeToPixel(h.maxWidth,e);d=Math.min(u,d)}return d}else if(h.width.unit==="px"&&e)return h.width.value;return 0});const r=h=>{var d;return((d=h.isVisible)==null?void 0:d.call(h))!==!1},l=this.columnSizes.reduce((h,d,u)=>r(this.columnDefs[u])?h+d:h,0),a=e-l,c=i.filter(r);if(a>0&&c.length){const h=c.map(d=>d.width.value).reduce((d,u)=>d+u);for(let d=0;d<this.columnDefs.length;d++){const u=this.columnDefs[d];u.width.unit==="weight"&&r(u)&&(this.columnSizes[d]=u.width.value*a/h)}}}}sizeToPixel(e,t){return e.unit==="px"?e.value:e.unit==="%"?Math.floor(e.value*t/100):-1}findColumnDef(e){const t=this.columnDefs??[];if(typeof e=="number")return e>=0?t[e]:void 0;if(typeof e=="string"){for(const s of t)if(s.property===e)return s;return}return t.indexOf(e)>-1?e:void 0}arrayMove(e,t,s){if(t<0||t>=e.length)return e;const o=e.splice(t,1)[0];return e.splice(s,0,o),e}recalcContentWidthInPx(){this.contentWidthInPx=this.getSideAreaWidth("center")}calcXPositions(){const e=this.getColumnCount();this.xPositions=new Array(e+1),this.xPositions[0]=0;for(let t=0;t<e;t++)this.xPositions[t+1]=this.getColumnWidth(t)+this.xPositions[t]}setTableScope(e){this.tableScope=e}getTableScope(){return this.tableScope}};$s.DEFAULT_COLUMN_WIDTH=100;let ze=$s;class ee{constructor(e,t,s){this.header=e,this.body=t,this.footer=s}}class we{constructor(e,t,s=new T(100,"px"),o=new ee,i=new ee,r,l,a,c,h,d,u,f,g,p,m=()=>this.visible){this.property=e,this.headerLabel=t,this.width=s,this.classes=o,this.rendererMap=i,this.sortable=a,this.sortComparator=c,this.sortState=h,this.sortStatesOrder=d,this.sortIconVisible=u,this.editable=f,this.getEditRenderer=g,this.editInputPipe=p,this.isVisible=m,this.visible=!0,this.minWidth=r??new T(0,"px"),this.maxWidth=l??new T(1e5,"px")}static bodyRenderer(e){return new ee(void 0,e,void 0)}static create(e){const t=new ee(e.headerRenderer,e.bodyRenderer,e.footerRenderer),s=new ee(e.headerClasses,e.bodyClasses,e.footerClasses),o=e.sortIconVisible??e.sortable,i=e.editable??Ur,r=e.isVisible??e.isVisible??Pt,l=new we(e.property??"",e.headerLabel??"",e.width??new T(100,"px"),s,t,e.minWidth,e.maxWidth,e.sortable,e.sortComparator,e.sortState,e.sortStatesOrder,o,i,e.getEditRenderer,e.editInputPipe,r);return e.formula!==void 0&&e.formula!==null?(l.formula=e.formula,l.valueGetter=vi(e.formula,e.formulaOptions)):e.valueGetter&&(l.valueGetter=e.valueGetter),e.valueSetter&&(l.valueSetter=e.valueSetter),e.showValuesAs&&(l.showValuesAs=e.showValuesAs),e.rowDrag!==void 0&&(l.rowDrag=e.rowDrag),e.validate&&(l.validate=e.validate),e.editor&&(l.editor=e.editor),e.emptyValue!==void 0&&(l.emptyValue=e.emptyValue),e.cellFormulas!==void 0&&(l.cellFormulas=e.cellFormulas),e.resizable!==void 0&&(l.resizable=e.resizable),e.movable!==void 0&&(l.movable=e.movable),l}}class ae{constructor(e="body"){this.areaIdent=e,this.rowSelectionModel=void 0}sort(e){}getRowCount(){return 0}getValueAt(e,t){return""}getTextValueAt(e,t){return""}getCellRenderer(e,t){}getRowHeight(e){return 0}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){return[]}getCustomStyleAt(e,t){}getRowspanAt(e,t){return 0}getRowByIndex(e){}isRowCheckable(e){return!1}isRowChecked(e){}setRowChecked(e,t){}getTooltipAt(e,t){return""}getMaxColspan(){return 0}getMaxRowspan(){return 0}getYPosByRowIndex(e){return 0}init(){}externalFilterChanged(e){}isFilterable(){return!1}doSort(e){return!1}isEditable(e,t){return!1}setValue(e,t,s){return!1}isSelectable(e,t){return!1}changeColumnOrder(e,t){}}class cn{constructor(e){this.columnDef=e,this.type="RowNumberCellRenderer"}render(e,t,s,o,i,r,l){const a=this.columnDef.getRowNumberText(t,i),c=l.createElement("div");l.addClass(c,"ge-table-label-div");const h=l.createElement("div");l.addClass(h,"ge-table-label"),l.setAttribute(h,"data-row-index",`${t}`),l.setAttribute(h,"data-col-index",`${s}`),l.setAttribute(h,"data-area",o),l.appendChild(h,l.createText(a)),l.appendChild(c,h),l.appendChild(e,c)}}class Po{constructor(){this.mode="display",this.format=wc,this.headerLabel="#",this.exported=!1,this.minWidthInPx=36}}function wc(n){return String(n)}class gs{constructor(e={}){this.type="RowNumberColumnDef",this.property="RowNumberColumn",this.maxWidth=new T(400,"px"),this.classes=new ee(["ge-table-row-number-header","ge-table-text-align-right"],["ge-table-row-number","ge-table-text-align-right"],["ge-table-row-number-footer"]),this.isVisible=Pt,this.resizable=!1,this.movable=!1,this.options={...new Po,...e},this.headerLabel=this.options.headerLabel,this.width=new T(this.options.minWidthInPx,"px"),this.minWidth=new T(this.options.minWidthInPx,"px"),this.rendererMap=new ee(void 0,new cn(this),void 0)}getRowNumber(e,t){var s;if(this.options.mode==="original"){const o=(s=t.getPhysicalRowIndex)==null?void 0:s.call(t,e);if(o!==void 0)return o+1;const i=this.getOriginalPosition(t.getRowByIndex(e),t);if(i!==void 0)return i+1}return e+1}getRowNumberText(e,t){return this.options.format(this.getRowNumber(e,t))}getWidestText(e){var s,o;let t=e.getRowCount();return this.options.mode==="original"&&this.hasAllRows(e)?t=((s=e.getUnfilteredRowCount)==null?void 0:s.call(e))??e.getAllRows().length:this.options.mode==="original"&&"getPhysicalRowIndex"in e&&(t=((o=e.getUnfilteredRowCount)==null?void 0:o.call(e))??t),this.options.format(Math.max(1,t))}hasDefaultFormat(){return this.options.format===new Po().format}hasAllRows(e){return typeof e.getAllRows=="function"}getOriginalPosition(e,t){if(!this.hasAllRows(t))return;const s=t.getAllRows();if(!Array.isArray(s))return;let o=this.originalIndex;(!o||o.rows!==s||o.length!==s.length)&&(o=this.buildOriginalIndex(s));const i=o.index.get(e);if(i!==void 0&&s[i]===e)return i;if(i!==void 0||!o.missRebuilt){o=this.buildOriginalIndex(s),o.missRebuilt=!0;const r=o.index.get(e);return r!==void 0&&s[r]===e?r:void 0}}buildOriginalIndex(e){const t=new Map;for(let s=0;s<e.length;s++)t.has(e[s])||t.set(e[s],s);return this.originalIndex={rows:e,length:e.length,index:t,missRebuilt:!1},this.originalIndex}}class hn{render(e,t,s,o,i,r,l){if(i.isEditable(t,s)){l.addClass(e,"ge-table-row-input-div");const a=r!==void 0?r:i.getValueAt(t,s),c=l.createElement("input");l.setAttribute(c,"type","text"),l.setAttribute(c,"autofocus",""),l.setAttribute(c,"data-listen","change"),l.setAttribute(c,"data-area",o),l.setAttribute(c,"data-row-index",String(t)),l.setAttribute(c,"data-col-index",String(s)),l.setAttribute(c,"data-input-type","text"),l.addClass(c,"ge-table-cell-editor-input"),c.value=a==null?"":String(a),c.defaultValue=c.value,c.addEventListener("focus",()=>c.setSelectionRange(0,c.value.length),{once:!0}),e.textContent="",l.appendChild(e,c)}}}class eo{constructor(e=new Me("❯","",["gt-table-icon-expanded"]),t=new Me("❯","transform: rotate(180deg) translate(-100%, -100%); transform-origin: 0 0;",["ge-table-icon-collapsed"])){this.iconExpanded=e,this.iconCollapsed=t}}const xi=(n,e)=>new hn;class je{constructor(){this.overflowX="auto",this.overflowY="auto",this.horizontalBorderVisible=!0,this.verticalBorderVisible=!0,this.footerSeparatorBorderVisible=!0,this.headerSeparatorBorderVisible=!0,this.fixedEastSeparatorBorderVisible=!0,this.fixedWestSeparatorBorderVisible=!0,this.tableTopBorderVisible=!0,this.tableBottomBorderVisible=!0,this.hoverRowVisible=!0,this.hoverColumnVisible=!0,this.columnsResizable=!0,this.columnsDraggable=!0,this.columnResizeHandleWidthInPx=4,this.defaultRowHeights={header:34,body:34,footer:34},this.footerVerticalSeparator=!1,this.headerToggleExpandCollapseIcons=!1,this.headerVerticalSeparator=!1,this.treeOptions=new ai,this.headerGroupOptions=new eo,this.showCheckboxWihoutExtraColumn=!1,this.externalFilterFunction=void 0,this.sortedOptions=new ci,this.sortOrder=["asc","desc"],this.shortcutActionsDisabled=!1,this.resizeEventDebounceDelay=500,this.getEditRenderer=xi,this.getSelectionModel=void 0,this.getFocusModel=void 0,this.ariaLabel=void 0,this.ariaLabelledBy=void 0,this.ariaDescribedBy=void 0,this.ariaTexts=void 0,this.overlayOptions=void 0,this.rowDragOptions=void 0,this.columnAutoWidth=void 0,this.fillHandle=void 0,this.masterDetail=void 0,this.batchEdit=void 0,this.editing=void 0,this.clipboard=void 0,this.undo=void 0,this.cellFormulas=void 0,this.spreadsheet=void 0,this.direction=void 0}}class pe{constructor(e="none",t="single"){this.selectionType=e,this.selectionMode=t,this.ranges=[],this.negativeRanges=[],this.allSelected=!1,this.silent=!1,this.listenerArr=[]}getEventSelectionChangedListeners(){return this.listenerArr}addEventSelectionChangedListener(e){this.listenerArr.includes(e)||this.listenerArr.push(e)}removeEventSelectionChangedListener(e){const t=this.listenerArr.indexOf(e,0);t>-1&&this.listenerArr.splice(t,1)}fireChangeEvent(){this.silent||this.listenerArr.forEach(e=>e.onSelectionChanged(this))}firstClick(e,t){this.selectionType==="row"?this.addRange(M.singleRow(e)):this.selectionType==="column"?this.addRange(M.singleColumn(t)):(this.selectionType==="cell"||this.selectionType==="range")&&this.addRange(M.singleCell(e,t))}createSnapshot(){return{ranges:[...this.ranges],negativeRanges:[...this.negativeRanges],allSelected:this.allSelected}}restoreSnapshot(e){this.ranges=[...e.ranges],this.negativeRanges=[...e.negativeRanges],this.allSelected=e.allSelected,this.fireChangeEvent()}adjustForRowChanges(e){if(e.isEmpty())return!1;const t=pe.shiftRanges(this.ranges,e);return pe.shiftRanges(this.negativeRanges,e),t}static shiftRanges(e,t){let s=!1;const o=[];for(const i of e){const r=Math.min(i.r1,i.r2),l=Math.max(i.r1,i.r2);if(r===0&&l>=Number.MAX_SAFE_INTEGER){o.push(i);continue}const a=l>=Number.MAX_SAFE_INTEGER?[[t.mapIndexOrNext(r),Number.MAX_SAFE_INTEGER]]:t.mapRange(r,l),c=a.reduce((f,[g,p])=>f+(p>=Number.MAX_SAFE_INTEGER?0:p-g+1),0);if(l<Number.MAX_SAFE_INTEGER&&c<l-r+1&&(s=!0),!a.length)continue;const h=i.r1>i.r2,[d,...u]=a;i.r1=h?d[1]:d[0],i.r2=h?d[0]:d[1],o.push(i);for(const[f,g]of u)o.push(new M(f,i.c1,g,i.c2,i.gammaRange))}e.length=0;for(const i of o)e.push(i);return s}getSelectionCount(e,t){let s=0;for(const o of this.ranges)o.isInRange(e,t)&&s++;return this.allSelected&&s++,this.isInNegativeRange(e,t)&&(s=0),s}isInNegativeRange(e,t){for(const s of this.negativeRanges)if(s.isInRange(e,t))return!0;return!1}getRanges(){return this.ranges}clear(){this.ranges=[],this.negativeRanges=[],this.allSelected=!1,this.fireChangeEvent()}hasSelection(){return this.allSelected||!!this.ranges.length}hasNoSelection(){return!this.hasSelection()}getMergedRowIndices(e){const t=e===void 0?void 0:e-1,s=[...this.ranges];this.allSelected&&t!==void 0&&s.push(new M(0,0,t,Number.MAX_SAFE_INTEGER));const o=new Set;for(const i of s){const r=Math.max(i.r1,0),l=t===void 0?i.r2:Math.min(i.r2,t);if(t===void 0&&!(l<Number.MAX_SAFE_INTEGER))continue;const a=this.negativeRanges.filter(c=>pe.intersects(c,i));for(let c=r;c<=l;c++)!o.has(c)&&(!a.length||!pe.coversColumns(a,c,i.c1,i.c2))&&o.add(c)}return Array.from(o).sort((i,r)=>i-r)}selectAll(){this.selectionType!=="none"&&(this.allSelected=!0,this.negativeRanges=[],this.fireChangeEvent())}isAllSelected(){return this.allSelected}addSelection(e){this.addRange(e)}removeSelection(e){if(this.selectionType==="none")return;let t=e;this.selectionType==="row"?t=new M(e.r1,0,e.r2,Number.MAX_SAFE_INTEGER):this.selectionType==="column"&&(t=new M(0,e.c1,Number.MAX_SAFE_INTEGER,e.c2)),this.negativeRanges.push(t),this.ranges=this.ranges.filter(s=>!this.isCoveredByNegativeRanges(s)),this.fireChangeEvent()}togglePoint(e,t){this.getSelectionCount(e,t)>0?this.removeSelection(M.singleCell(e,t)):this.reselectPoint(e,t)?this.fireChangeEvent():this.addSelection(M.singleCell(e,t))}isSelected(e,t){return this.getSelectionCount(e,t)>0}addRange(e){this.selectionType!=="none"&&(this.allSelected=!1,this.selectionMode==="single"&&(this.ranges=[],this.negativeRanges=[]),this.adjustRangeToSelectionType(e),this.liftNegativeRanges(e),this.ranges.push(e),this.fireChangeEvent())}adjustRangeToSelectionType(e){return this.selectionType==="row"?(e.c1=0,e.c2=Number.MAX_SAFE_INTEGER):this.selectionType==="column"?(e.r1=0,e.r2=Number.MAX_SAFE_INTEGER):this.selectionType==="cell"?(e.r2=e.r1,e.c2=e.c1):this.selectionType,e}reselectPoint(e,t){return this.selectionType==="none"||!this.isInNegativeRange(e,t)||!this.allSelected&&!this.ranges.some(s=>s.isInRange(e,t))?!1:(this.liftNegativeRanges(this.adjustRangeToSelectionType(M.singleCell(e,t))),!0)}liftNegativeRanges(e){if(!this.negativeRanges.length)return;const t=[];for(const s of this.negativeRanges){const o=Math.max(s.r1,e.r1),i=Math.min(s.r2,e.r2),r=Math.max(s.c1,e.c1),l=Math.min(s.c2,e.c2);if(o>i||r>l){t.push(s);continue}s.r1<o&&t.push(new M(s.r1,s.c1,o-1,s.c2,s.gammaRange)),i<s.r2&&t.push(new M(i+1,s.c1,s.r2,s.c2,s.gammaRange)),s.c1<r&&t.push(new M(o,s.c1,i,r-1,s.gammaRange)),l<s.c2&&t.push(new M(o,l+1,i,s.c2,s.gammaRange))}this.negativeRanges=t}isCoveredByNegativeRanges(e){let t=[e];for(const s of this.negativeRanges)if(t=t.flatMap(o=>pe.difference(o,s)),!t.length)return!0;return!1}static difference(e,t){const s=Math.max(e.r1,t.r1),o=Math.min(e.r2,t.r2),i=Math.max(e.c1,t.c1),r=Math.min(e.c2,t.c2);if(s>o||i>r)return[e];const l=[];return e.r1<s&&l.push(new M(e.r1,e.c1,s-1,e.c2)),o<e.r2&&l.push(new M(o+1,e.c1,e.r2,e.c2)),e.c1<i&&l.push(new M(s,e.c1,o,i-1)),r<e.c2&&l.push(new M(s,r+1,o,e.c2)),l}static intersects(e,t){return Math.max(e.r1,t.r1)<=Math.min(e.r2,t.r2)&&Math.max(e.c1,t.c1)<=Math.min(e.c2,t.c2)}static coversColumns(e,t,s,o){const i=e.filter(l=>l.r1<=t&&t<=l.r2&&l.c1<=l.c2).sort((l,a)=>l.c1-a.c1);let r=s;for(const l of i){if(l.c1>r)return!1;if(l.c2>=r&&(r=l.c2+1),r>o)return!0}return r>o}}class Ri{constructor(e="none"){this.selectionType=e,this.rowIndex=-1,this.columnIndex=-1,this.changed=!1,this.listenerArr=[]}getEventFocusChangedListeners(){return this.listenerArr}addEventFocusChangedListener(e){this.listenerArr.includes(e)||this.listenerArr.push(e)}removeEventFocusChangedListener(e){const t=this.listenerArr.indexOf(e,0);t>-1&&this.listenerArr.splice(t,1)}fireChangeEvent(){this.listenerArr.forEach(e=>e.onFocusChanged(this))}clearChanged(){this.changed=!1}hasChanged(){return this.changed}clear(){this.rowIndex=-1,this.columnIndex=-1,this.fireChangeEvent()}setFocus(e,t){(this.rowIndex!==e||this.columnIndex!==t)&&(this.rowIndex=e,this.columnIndex=t,this.changed=!0,this.fireChangeEvent())}adjustForRowChanges(e){if(this.rowIndex<0||e.isEmpty())return;const t=e.mapIndex(this.rowIndex);if(t>=0){this.rowIndex=t;return}this.rowIndex=e.mapIndexOrNext(this.rowIndex),this.changed=!0,this.fireChangeEvent()}hasFocus(e,t){return this.rowIndex===e&&this.columnIndex===t}getFocus(){return[this.rowIndex,this.columnIndex]}}function yc(n){var e,t;try{const o=new Intl.NumberFormat(n).formatToParts(12345.6);return{decimal:((e=o.find(i=>i.type==="decimal"))==null?void 0:e.value)??".",group:((t=o.find(i=>i.type==="group"))==null?void 0:t.value)??","}}catch{return{decimal:".",group:","}}}const Cc=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");let wo;function dn(n){var e;if(!wo){let t=[];try{t=((e=Intl.supportedValuesOf)==null?void 0:e.call(Intl,"currency"))??[]}catch{t=[]}wo=new Set(t.length?t:["EUR","USD","GBP","CHF","JPY","CNY","CAD","AUD","SEK","NOK","DKK","PLN","CZK"])}return wo.has(n)}function er(n){return n.replace(new RegExp("^\\p{Sc}\\s*","u"),"").replace(/^([A-Z]{3})\s+/u,(e,t)=>dn(t)?"":e)}function un(n,e){let t=n.trim().replace(/[   ]/g," ").replace(/−/g,"-");if(!t)return;let s=!1;if(/^\(.*\)$/.test(t)&&(s=!0,t=t.slice(1,-1).trim(),/^[-+]/.test(t)))return;let o=!1;t=er(t),t=t.replace(/\s*%$/u,()=>(o=!0,"")),t=t.replace(new RegExp("\\s*\\p{Sc}$","u"),"").replace(/\s+([A-Z]{3})$/u,(c,h)=>dn(h)?"":c),(t.startsWith("-")||t.startsWith("+"))&&(s=s!==t.startsWith("-"),t=er(t.slice(1).trim()));const{decimal:i,group:r}=yc(e),l=r.trim()===""?" ":r;if(t=t.replace(new RegExp(`[${Cc(l)}](?=\\d{3}(\\D|$))`,"g"),""),i!=="."){if(t.includes(".")&&!/[eE]/.test(t))return;t=t.replace(i,".")}if(!/^(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?$/.test(t))return;let a=Number(t);return o&&(a/=100),s?-a:a}function vc(n){return e=>typeof e!="string"?e:e.trim()===""?"":un(e,n)??e}function Sc(n){try{return new Intl.DateTimeFormat(n).formatToParts(new Date(2026,10,23)).filter(e=>e.type==="day"||e.type==="month"||e.type==="year").map(e=>e.type)}catch{return["month","day","year"]}}function fn(n,e){const t=n.trim(),s=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/.exec(t);if(s)return tr(+s[1],+s[2],+s[3],+(s[4]??0),+(s[5]??0),+(s[6]??0));const o=/^(\d{1,4})([./-])(\d{1,2})\2(\d{1,4})(?:,? (\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(t);if(!o)return;const i=Sc(e),r=[o[1],o[3],o[4]],l={};for(let c=0;c<3;c++){const h=i[c],d=r[c];if(h==="year"?d.length!==2&&d.length!==4:d.length>2)return;l[h]=+d}let a=l.year;return a<100&&(a+=2e3),tr(a,l.month,l.day,+(o[5]??0),+(o[6]??0),+(o[7]??0))}function tr(n,e,t,s,o,i){const r=new Date(n,e-1,t,s,o,i);return r.getFullYear()===n&&r.getMonth()===e-1&&r.getDate()===t?r:void 0}function xc(n){return e=>typeof e!="string"?e:e.trim()===""?"":fn(e,n)??e}const Rc=["true","yes","1","x","wahr","ja"],Ac=["false","no","0","falsch","nein"],Ec=n=>{if(typeof n!="string")return n;const e=n.trim().toLowerCase();return e===""?"":Rc.includes(e)?!0:Ac.includes(e)?!1:n};function Ai(n){return e=>{if(typeof e!="string"||e.startsWith("=")||e.startsWith("'="))return e;if(e.startsWith("'"))return e.slice(1);const t=e.trim();if(t==="")return"";const s=t.toUpperCase();if(s==="TRUE")return!0;if(s==="FALSE")return!1;const o=un(t,n);return o!==void 0?o:fn(t,n)??e}}class Ei extends Q{constructor(){super(...arguments),this.columnLetterRows=1}isColumnLetterRow(e){return e<this.columnLetterRows}setColumns(e){this.arr.length=0,this.arr.push(e.map(t=>t.headerLabel)),this.filteredArr=[...this.arr],this.columnDefs=e,this.cellRenderers=e.map(t=>{var s;return(s=t.rendererMap)==null?void 0:s[this.areaIdent]})}}class Mi extends ze{constructor(e,t,s,o,i,r,l=Ai()){super(e,t,new ae("footer"),s?1:0,0,!1,new Le(i,i,i),o),this.sheetBody=t,this.rowNumberColumn=s,this.columnWidth=r,this.inputPipe=l}setDataColumns(e,t=[]){const s=gn(e,this.columnWidth,this.rowNumberColumn,t,this.inputPipe);this.columnDefs=s,this.columnCount=s.length,this.columnSizes=[],this.headerAreaModel.setColumns(s),this.sheetBody.setColumnDefs(s),this.init()}getDataColumnWidths(){const e=this.rowNumberColumn?1:0;return Array.from({length:this.getColumnCount()-e},(t,s)=>this.getColumnWidth(s+e))}}function gn(n,e,t,s=[],o){const i=Array.from({length:n},(r,l)=>we.create({editInputPipe:o,property:Ne(l),headerLabel:Ne(l),width:new T(s[l]??e,"px"),minWidth:new T(20,"px"),maxWidth:new T(2e3,"px")}));return t?[t,...i]:i}class Mc{static create(e={}){const t=e.data??[],s=Math.max(e.rowCount??100,t.length),o=Math.max(e.columnCount??26,t.reduce((m,b)=>Math.max(m,(b==null?void 0:b.length)??0),0)),i=e.rowHeight??30,r=e.columnWidth??100,l=e.rowNumbers===!1?void 0:new gs({mode:"original"}),a=Ai(e.locale),c=gn(o,r,l,[],a),h=new Ei("header",[c.map(m=>m.headerLabel)],i,c),d=new Pe("body",t,s,o,i,c,l?1:0),u=new Mi(h,d,l,c,i,r,a),f=new pe("range","multi"),g=new Ri("cell");g.setFocus(0,l?1:0);const p={...new je,getSelectionModel:()=>f,getFocusModel:()=>g,spreadsheet:!0,...e.functions?{cellFormulas:{functions:e.functions}}:{},hoverRowVisible:!1,hoverColumnVisible:!1,...e.tableOptions};return{tableModel:u,tableOptions:p}}}function to(n){return n instanceof Mi}class Vo{constructor(e=-1,t=-1){this.rowIndex=e,this.columnIndex=t}}class Xe{constructor(e,t,s){this.cells=e,this.changes=t,this.source=s}static createForChanges(e,t){const s=e.filter(o=>o.rowIndex>-1).map(o=>new Vo(o.rowIndex,o.columnIndex));return new Xe(s,e,t)}static createSingle(e,t){return new Xe([new Vo(e,t)])}}class me{static create(e){const t=new me;if(e)for(const s of Object.keys(e)){const o=e[s];typeof o=="function"&&(t[s]=o)}return t}sorted(e,t){return t==="asc"?`Sorted by ${e}, ascending`:t==="desc"?`Sorted by ${e}, descending`:`Sorting of ${e} removed`}filtered(e){return e===0?"No rows":e===1?"1 row":`${e} rows`}copied(e){return e===1?"1 cell copied":`${e} cells copied`}allSelected(){return"All cells selected"}selectionCleared(){return"Selection cleared"}selectRow(e){return`Select row ${e}`}selectAllRows(){return"Select all rows"}expandGroup(e){return e?`Expand group ${e}`:"Expand group"}collapseGroup(e){return e?`Collapse group ${e}`:"Collapse group"}rowDragStarted(e){return e===1?"Dragging 1 row. Press Escape to cancel.":`Dragging ${e} rows. Press Escape to cancel.`}rowMoved(e,t){return`Row moved to position ${e} of ${t}`}rowMoveNotPossible(){return"Rows cannot be moved while the table is sorted or filtered"}rowDragCancelled(){return"Drag cancelled"}cellsFilled(e){return e===1?"1 cell filled":`${e} cells filled`}detailExpanded(){return"Details expanded"}detailCollapsed(){return"Details collapsed"}fillTooLarge(e){return`Too many cells to fill (at most ${e})`}pendingChanges(e){return e===0?"No unsaved changes":e===1?"1 change not saved":`${e} changes not saved`}changesCommitted(e){return e===1?"1 change saved":`${e} changes saved`}changesDiscarded(){return"Changes discarded"}commitBlocked(e){return e===1?"1 invalid value – nothing saved":`${e} invalid values – nothing saved`}invalidValue(e){return e?`Invalid value: ${e}`:"Invalid value"}editingStarted(e){return e?`Editing ${e}`:"Editing"}readOnlyCell(){return"Read only"}cellsCleared(e){return e===1?"1 cell cleared":`${e} cells cleared`}clearTooLarge(e){return`Too many cells to clear (at most ${e})`}rangeSelected(e,t){const s=e===1?"1 row":`${e} rows`,o=t===1?"1 column":`${t} columns`;return`${s}, ${o} selected`}rowSelected(e){return e===1?"Row selected":`${e} rows selected`}columnSelected(e){return e===1?"Column selected":`${e} columns selected`}gridEditingHint(){return"Type to edit a cell, Enter to edit or commit, Escape to cancel. Tab in the last column leaves the table."}cellsPasted(e,t){const s=e===1?"1 cell pasted":`${e} cells pasted`;return t>0?`${s}, ${t} skipped`:s}pasteTooLarge(e){return`Too many cells to paste (at most ${e})`}copyTooLarge(e){return`Too many cells to copy (at most ${e})`}cutMarked(e){return`${e===1?"1 cell":`${e} cells`} cut, paste to move them`}copiedLastRangeOnly(){return"Only the last selected range was copied"}undone(e,t){return`Undo ${e}, ${t===1?"1 cell":`${t} cells`}`}redone(e,t){return`Redo ${e}, ${t===1?"1 cell":`${t} cells`}`}nothingToUndo(){return"Nothing to undo"}nothingToRedo(){return"Nothing to redo"}undoSkipped(e){return`${e===1?"1 cell":`${e} cells`} skipped`}undoHistoryCleared(e){return`This change cannot be undone (more than ${e} cells)`}formulaError(e){return`Formula error: ${e}`}functionSuggestions(){return"Functions"}referenceInserted(e){return e}rowsInserted(e){return e===1?"1 row inserted":`${e} rows inserted`}rowsDeleted(e){return e===1?"1 row deleted":`${e} rows deleted`}columnsInserted(e){return e===1?"1 column inserted":`${e} columns inserted`}columnsDeleted(e){return e===1?"1 column deleted":`${e} columns deleted`}}const Tc={insertRows:"Insert rows",deleteRows:"Delete rows",insertColumns:"Insert columns",deleteColumns:"Delete columns"};function pt(n,e,t={}){var m,b,y,C,v;const s=n.tableModel,o=s.getBodyModel(),i=e.kind==="insertColumns"||e.kind==="deleteColumns",r=o instanceof Pe?o:void 0,l=o instanceof z||o instanceof Q;if(!(e.count>=1)||!(e.at>=0)||(i?!r||!to(s):!r&&!l)||n.isBatchEditActive())return!1;const a=i?r.getSheetColumnCount():r?r.getUnfilteredRowCount():Ti(o).length,h=e.kind==="deleteRows"||e.kind==="deleteColumns"?Math.min(e.count,a-e.at):e.count;if(e.at>a||h<1||(m=n.cellEditorService)!=null&&m.isOpen()&&!n.cellEditorService.commit("none"))return!1;const d={...e,count:h},u=n.tableSheet;u==null||u.rowCount();const f=u?u.engine.adjustForStructureChange(d):[],g=Ic(n,d,t.rows),p=[];if(u){const E=u.rowsArray();for(const{row:S,col:R,input:L}of f){const x=E?E[S]:r==null?void 0:r.getRowArray(S),D=u.inputAt(S,R);if(x&&typeof x=="object"){const P=d.kind==="insertColumns"?R>=d.at+h?R-h:R:d.kind==="deleteColumns"&&R>=d.at?R+h:R;g.inputs.push({row:x,col:P,old:D})}u.writeInput(S,R,L);const k=u.modelColumn(R);p.push({row:x,rowIndex:u.displayRow(S),columnIndex:k,property:((b=s.getColumnDef(k))==null?void 0:b.property)??"",oldValue:D,newValue:L})}u.recalculate()}return n.refreshAfterStructureChange(i),t.record!==!1&&((y=n.undoService)==null||y.addStep(new Fc(d,g))),n.announce(kc(n,d)),(v=(C=n.getEventListener()).onModelChanged)==null||v.call(C,Xe.createForChanges(p,t.source??"structure")),!0}function Ic(n,e,t){const s=n.tableModel,o=s.getBodyModel(),{at:i,count:r}=e,l={inputs:[]};if(o instanceof Pe){if(e.kind==="insertRows")o.insertRows(i,r);else if(e.kind==="deleteRows")l.sheetRows=o.deleteRows(i,r);else if(to(s)){const c=s.getDataColumnWidths();l.widths=[...c],e.kind==="insertColumns"?(o.insertColumns(i,r),c.splice(i,0,...new Array(r).fill(NaN))):(l.sheetColumns=o.deleteColumns(i,r),c.splice(i,r)),s.setDataColumns(o.getSheetColumnCount(),c.map(h=>Number.isNaN(h)?void 0:h))}return l}const a=Ti(o);if(e.kind==="insertRows"){const c=t??Array.from({length:r},(h,d)=>Dc(n,i+d));for(let h=0;h<c.length;h++)a.splice(i+h,0,c[h]);l.rows=c}else l.rows=a.splice(i,r);return pn(o,a),l}function Ti(n){return n instanceof z?n.getAllRows():n.arr}function pn(n,e){n instanceof z?n.setRows(e):n instanceof Q&&(n.filteredArr=[...e])}function Dc(n,e){if(n.tableModel.getBodyModel()instanceof Q)return new Array(n.tableModel.getColumnCount()).fill("");const s=n.getClipboardService().options.createRow;return s?s(e):{}}function kc(n,e){const t=n.ariaTexts,s=new me;switch(e.kind){case"insertRows":return(t.rowsInserted??s.rowsInserted).call(t,e.count);case"deleteRows":return(t.rowsDeleted??s.rowsDeleted).call(t,e.count);case"insertColumns":return(t.columnsInserted??s.columnsInserted).call(t,e.count);default:return(t.columnsDeleted??s.columnsDeleted).call(t,e.count)}}class Fc{constructor(e,t){var s,o;this.edit=e,this.delta=t,this.source="structure",this.label=Tc[e.kind],this.cellCount=e.count+t.inputs.length+(((s=t.sheetRows)==null?void 0:s.reduce((i,[,r])=>i+r.length,0))??0)+(((o=t.sheetColumns)==null?void 0:o.reduce((i,[,r])=>i+r.length,0))??0)}undo(e){var a,c,h,d,u;const t=e.tableModel,s=t.getBodyModel(),{at:o,count:i,kind:r}=this.edit,l=this.delta;if(s instanceof Pe)r==="insertRows"?s.deleteRows(o,i):r==="deleteRows"?s.restoreRows(o,i,l.sheetRows):to(t)&&(r==="insertColumns"?s.deleteColumns(o,i):s.restoreColumns(o,i,l.sheetColumns),t.setDataColumns(s.getSheetColumnCount(),l.widths));else{const f=Ti(s);if(r==="insertRows")f.splice(o,i);else for(let g=0;g<(((a=l.rows)==null?void 0:a.length)??0);g++)f.splice(o+g,0,l.rows[g]);pn(s,f)}for(const{row:f,col:g,old:p}of l.inputs)(c=e.tableSheet)==null||c.writeInput(f,g,p);return(h=e.tableSheet)==null||h.recalculate(),e.refreshAfterStructureChange(r==="insertColumns"||r==="deleteColumns"),(u=(d=e.getEventListener()).onModelChanged)==null||u.call(d,Xe.createForChanges([],"undo")),{applied:i,skipped:0}}redo(e){return pt(e,this.edit,{record:!1,rows:this.edit.kind==="insertRows"?this.delta.rows:void 0,source:"redo"}),{applied:this.edit.count,skipped:0}}}class mn{constructor(e){this.tableScope=e}updateCells(e,t=!1){this.tableScope.updateCells(e,t)}externalFilterChanged(){this.tableScope.externalFilterChanged()}scrollToPixel(e=0,t=0){this.tableScope.scrollToPixel(e,t)}getDirection(){return this.tableScope.direction}scrollToIndex(e=0,t=0){this.tableScope.scrollToIndex(e,t)}setHeaderVisible(e=!0){this.tableScope.setHeaderVisible(e)}setColumnVisible(e,t=!0){return this.tableScope.setColumnVisible(e,t)}isColumnVisible(e){var i;const t=this.tableScope.tableModel;if(t.isColumnVisible)return t.isColumnVisible(e);const s=t.getColumnDefs()??[],o=typeof e=="number"?s[e]:typeof e=="string"?s.filter(r=>r.property===e)[0]:e;return o?((i=o.isVisible)==null?void 0:i.call(o))!==!1:typeof e=="number"&&e>=0&&e<t.getColumnCount()}isHeaderVisible(){return this.tableScope.tableModel.isHeaderVisibe()}setFooterVisible(e=!0){this.tableScope.setFooterVisible(e)}isFooterVisible(){return this.tableScope.tableModel.isFooterVisibe()}repaint(){this.tableScope.invalidateAggregates(),this.tableScope.repaint()}destroy(){this.tableScope.destroy()}repaintHard(e){this.tableScope.invalidateAggregates(),this.tableScope.repaintHard(e)}recalcColumnWidths(e){this.tableScope.recalcColumnWidths(e)}clearSelection(){this.tableScope.clearSelection(!0)}setSelectionModel(e,t=!0){this.tableScope.setSelectionModel(e,t)}triggerAction(e){return this.tableScope.onActionTriggered(e)}getShortcutActionMapping(){return this.tableScope.shortcutService.getShortcutActionMapping()}copyToClipboard(){return this.tableScope.copyService.copyToClipboard(this.tableScope.tableModel,this.tableScope.selectionModel(),this.tableScope.focusModel()).then(e=>(this.tableScope.announceCopied(e),e))}announce(e){this.tableScope.announce(e)}showLoadingOverlay(e){this.tableScope.showLoadingOverlay(e)}showNoRowsOverlay(e){this.tableScope.showNoRowsOverlay(e)}hideOverlay(){this.tableScope.hideOverlay()}getOverlayState(){return this.tableScope.getOverlayState()}getState(e){return this.tableScope.stateService.getState(e)}applyState(e,t){this.tableScope.stateService.applyState(e,t)}resetState(){this.tableScope.stateService.resetState()}setCustomState(e){this.tableScope.stateService.setCustomState(e)}setHeaderGroupCollapsed(e,t=!0){return this.tableScope.setHeaderGroupCollapsed(e,t)}getHeaderFocus(){return this.tableScope.getHeaderFocus()}downloadExcel(e="table.xlsx",t="",s={}){var f;const o=[],i=this.tableScope.tableModel,r=[];for(let g=0;g<i.getColumnCount();g++){const p=i.getColumnDef(g);((f=p==null?void 0:p.isVisible)==null?void 0:f.call(p))!==!1&&(N(p)&&!p.options.exported||r.push(g))}const l=i.getBodyModel(),a=l instanceof Pe?l.getContentExtent():void 0;if(a){const g=this.tableScope.getFirstDataColumnIndex();for(let p=r.length-1;p>=0;p--)r[p]>=g&&r[p]>a[1]&&r.splice(p,1)}const c=s.cellFormulas?this.getExcelFormulaOffset(r,a==null?void 0:a[1]):void 0,h=["header","body","footer"];for(const g of h){const p=i.getAreaModel(g),m=g==="body"&&a?a[0]+1:(p==null?void 0:p.getRowCount())??0;for(let b=0;b<m;b++)g==="header"&&sr(p,b)||o.push(r.map(y=>c&&g==="body"?this.getExcelFormulaCell(p,b,y,c)??this.getExportValue(i,g,p,b,y):this.getExportValue(i,g,p,b,y)))}const d=this.tableScope.isRtl()?{rightToLeft:!0}:void 0,u=Object.keys(s).length?{...s,...d}:d;return Promise.resolve(u?this.tableScope.excelService.downloadExcel(o,e,t,u):this.tableScope.excelService.downloadExcel(o,e,t))}getExcelFormulaOffset(e,t=Number.MAX_SAFE_INTEGER){var f;const s=this.tableScope,o=s.tableSheet;if(!o)return;const i=g=>{console.warn(`GuiExpert Table – downloadExcel: values instead of formulas (${g}).`)};if(!s.excelService.supportsFormulas)return i("the Excel service writes no formulas");const r=s.tableModel.getBodyModel(),l=r.getRowCount();if(l!==(((f=r.getUnfilteredRowCount)==null?void 0:f.call(r))??l))return i("a filter hides rows");for(let g=0;g<l;g++)if(o.physicalRow(g)!==g)return i("the rows are sorted");const a=e.map(g=>o.engineColumn(g)),c=a.findIndex(g=>g!==void 0);let h=0;for(let g=0;g<e.length;g++){const p=a[g];if(p!==void 0){if(p!==h||g!==c+h)return i("a data column is hidden or moved");h++}}for(let g=0;g<s.tableModel.getColumnCount();g++)if(o.engineColumn(g)!==void 0&&!e.includes(g)&&g<=t)return i("a data column is hidden");const d=s.tableModel.getAreaModel("header");let u=0;for(let g=0;g<((d==null?void 0:d.getRowCount())??0);g++)sr(d,g)||u++;return u+l>ie||Math.max(0,c)+h>q?i("the sheet is larger than an Excel sheet"):{dRow:u,dCol:Math.max(0,c),rows:l,cols:h,sheet:o}}getExcelFormulaCell(e,t,s,o){var l;const i=(l=e.getInputValueAt)==null?void 0:l.call(e,t,s);if(!o.sheet.isFormulaInput(s,i))return;const r=pc(i,o);return r===void 0?void 0:{formula:r,value:e.getValueAt(t,s)}}getExportValue(e,t,s,o,i){const r=e.getColumnDef(i);if(N(r)&&t!=="header")return t!=="body"?"":r.hasDefaultFormat()?r.getRowNumber(o,s):r.getRowNumberText(o,s);const l=s.getValueAt(o,i);if(t!=="header"&&typeof l=="number"&&this.tableScope.excelService.supportsNumberFormats){const a=Xs(r)?r.pivot.value.showValuesAs:t==="body"?r==null?void 0:r.showValuesAs:void 0,c=Ua(a);if(c)return{value:l,numberFormat:c}}return l}getColumnIndex(e){var s,o,i;const t=((o=(s=this.tableScope.tableModel).getColumnDefs)==null?void 0:o.call(s))??[];for(let r=0;r<t.length;r++)if(((i=t[r])==null?void 0:i.property)===e)return r;return-1}getTableScope(){return this.tableScope}getSelectionModel(){return this.tableScope.selectionModel()}getSelectionAggregates(){return new Ms().aggregate(this.tableScope.tableModel,this.getSelectionModel())}autoResizeColumns(e=!0){this.tableScope.autoResizeColumns(e)}autoResizeColumn(e){return this.tableScope.autoResizeColumn(e)}isColumnDragging(){return this.tableScope.isColumnDragging()}cancelColumnDrag(){this.tableScope.cancelColumnDrag()}recalcWrappers(){this.tableScope.recalcWrappers()}setColumnWidth(e,t){this.tableScope.setColumnWidth(e,t)}getTableModel(){return this.tableScope.tableModel}getBodyModel(){return this.tableScope.tableModel.getBodyModel()}setRows(e){var s;const t=this.getBodyModel();t instanceof z?(t.setRows(e),(s=this.tableScope.batchEditService)==null||s.pruneOrphans(),this.tableScope.invalidateRowLayout()):console.warn("setRows<T>(rows: T[]) only works with AreaModelObjectArray<T>, but this body area model is ",typeof t,t)}appendRows(e,t){return this.tableScope.appendRows(e,t)}rowsAppended(e,t){return this.tableScope.notifyRowsAppended(e,t)}addRows(e){const t=this.getBodyModel();if(t instanceof z){const s=t;let o=s.getAllRows();s.setRows([...o,...e])}else console.warn("addRows<T>(rows: T[]) only works with AreaModelObjectArray<T>, but this body area model is ",typeof t,t)}addRowsAt(e,t){const s=this.getBodyModel();if(s instanceof z){const o=s;let i=o.getAllRows();o.setRows([...i.slice(0,t),...e,...i.slice(t)])}else console.warn("addRowsAt<T>(rows: T[]) only works with AreaModelObjectArray<T>, but this body area model is ",typeof s,s)}removeRows(e,t=(s,o)=>s===o){const s=this.getBodyModel();if(s instanceof z){const o=s,i=o.getAllRows().filter(r=>!e.some(l=>t(r,l)));o.setRows(i)}else console.warn("removeRows<T>(rows: T[]) only works with AreaModelObjectArray<T>, but this body area model is ",typeof s,s)}findRows(e,t=(s,o)=>s===o){const s=this.getBodyModel();return s instanceof z?s.getAllRows().filter(i=>e.some(r=>t(i,r))):(console.warn("findRows<T>(rows: T[], predicate: (a: T, b: T) => boolean) only works with AreaModelObjectArray<T>, but this body area model is ",typeof s,s),[])}findRowFromFilteredRowsByAllCriteria(e,t){const s=this.getBodyModel();if(s instanceof z)return s.getFilteredRows().find(i=>t(e,i));console.warn("findRowFromFilteredRowsByAllCriteria(...) only works with AreaModelObjectArray<T>, but this body area model is ",typeof s,s)}findRowFromAllRowsByAllCriteria(e,t){const s=this.getBodyModel();if(s instanceof z)return s.getAllRows().find(i=>t(e,i));console.warn("findRowFromAllRowsByAllCriteria(...) only works with AreaModelObjectArray<T>, but this body area model is ",typeof s,s)}updateRows(e,t=(s,o)=>s===o){const s=this.getBodyModel();if(s instanceof z){let i=s.getAllRows();for(const r of i)for(const l of e)if(t(r,l))for(const a of Object.keys(l))r[a]=l[a]}else console.warn("updateRows<T>(rows: T[], predicate: (a: T, b: T) => boolean) only works with AreaModelObjectArray<T>, but this body area model is ",typeof s,s)}sortByColumn(e,t){return this.tableScope.sortByColumn(e,t)}reSort(){this.tableScope.reSort()}expandAll(){this.tableScope.toggleExpandCollapseAll(!0)}collapseAll(){this.tableScope.toggleExpandCollapseAll(!1)}setRowExpanded(e,t){const s=this.tableScope.tableModel.getBodyModel().getRowByIndex(e);return U(s)?this.tableScope.setTreeRowExpanded(s,t):!1}setRowGroupBy(e){return this.tableScope.setRowGroupBy(e)}getRowGroupBy(){const e=this.tableScope.tableModel.getBodyModel();return ne(e)?e.getGroupBy():void 0}setPivotConfig(e,t){return this.tableScope.setPivotConfig(e,t)}getPivotConfig(){const e=this.tableScope.tableModel;return Rs(e)?e.getPivotConfig():void 0}getRowValue(e,t){const s=this.tableScope.tableModel.getBodyModel();if(typeof s.getRowValue=="function")return s.getRowValue(e,t);const o=U(e)?e.data:e;if(o==null)return;let i=o;for(const r of t.split(".")){if(i==null)return;i=i[r]}return i}setShowValuesAs(e,t){const s=(this.tableScope.tableModel.getColumnDefs()??[]).filter(o=>o.property===e);return!s.length||t!==void 0&&!Lt(t)?!1:(s.forEach(o=>o.showValuesAs=t),this.repaint(),!0)}getShowValuesAs(e){var t,s;return(s=(t=this.tableScope.tableModel.getColumnDefs())==null?void 0:t.find(o=>o.property===e))==null?void 0:s.showValuesAs}setColumnFormula(e,t,s){const o=(this.tableScope.tableModel.getColumnDefs()??[]).filter(l=>l.property===e);if(!o.length)return new I("#NAME?",`No column "${e}"`);const i=Ci(t,s),r=vi(i);return o.forEach(l=>{l.formula=i.source,l.valueGetter=r}),this.repaint(),i.error}sort(e){this.tableScope.sort(e)}moveRows(e,t){const s=this.tableScope.rowDragService;if(!s)return!1;const o=Array.isArray(e)?e:[e];let i;if(typeof t=="number"){const r=this.tableScope.tableModel.getBodyModel().getRowCount();i=t>=r?{rowIndex:r-1,position:"after"}:{rowIndex:Math.max(0,t),position:"before"}}else i=t;return s.moveRows(o,i,!0)>-1}isRowDragging(){var e;return!!((e=this.tableScope.rowDragService)!=null&&e.isDragging())}cancelRowDrag(){var e;(e=this.tableScope.rowDragService)==null||e.cancel()}applyCellChanges(e,t="api",s={}){return this.tableScope.applyCellChanges(e,t,s)}fillRange(e,t,s,o="auto"){return this.tableScope.fillRange(e,t,s,o)}isFilling(){var e;return!!((e=this.tableScope.fillHandleService)!=null&&e.isFilling())}cancelFill(){var e;(e=this.tableScope.fillHandleService)==null||e.cancel()}subscribe(e){return this.tableScope.subscribe(e)}startEditing(e,t,s){var i;const o=typeof t=="number"?t:this.getColumnIndex(t);return o<0?!1:s!==void 0&&((i=this.tableScope.cellEditorService)!=null&&i.handlesColumn(o))?this.tableScope.cellEditorService.start(e,o,{mode:"enter",typedText:s}):this.tableScope.startEditing(e,o,"edit","end")}stopEditing(e=!1){const t=this.tableScope.cellEditorService;if(t!=null&&t.isOpen())return e?(t.cancel(),!0):t.commit("none");const s=this.tableScope.getInCellEditorCell();if(s){const o=this.tableScope.hostElement.querySelector(".ge-table-cell-editor-input, .ge-table-cell-editor-select");e||!o?this.tableScope.cancelEditing(o??void 0):this.tableScope.updateModelValueAfterEdit("body",s[0],s[1],o.value)}return!this.tableScope.isEditing()}isEditing(){return this.tableScope.isEditing()}getEditingCell(){var e;return((e=this.tableScope.cellEditorService)==null?void 0:e.getCell())??this.tableScope.getInCellEditorCell()}clearCells(e){return this.tableScope.clearCells(e)}copySelection(){return this.tableScope.getClipboardService().writeSelection(!1)}cutSelection(){return this.tableScope.getClipboardService().writeSelection(!0)}pasteText(e,t){return this.tableScope.getClipboardService().paste(e,void 0,t)}getSelectionAsText(){return this.tableScope.getClipboardService().getSelectionAsText()}cancelCut(){var e;(e=this.tableScope.clipboardService)==null||e.cancelCut()}undo(){var e;return!!((e=this.tableScope.undoService)!=null&&e.undo())}redo(){var e;return!!((e=this.tableScope.undoService)!=null&&e.redo())}canUndo(){var e;return!!((e=this.tableScope.undoService)!=null&&e.canUndo())}canRedo(){var e;return!!((e=this.tableScope.undoService)!=null&&e.canRedo())}clearUndoHistory(){var e;(e=this.tableScope.undoService)==null||e.clear()}getUndoState(){var e;return(e=this.tableScope.undoService)==null?void 0:e.getState()}batchUndoable(e,t){const s=this.tableScope.undoService;return s?s.batch(e,t):t()}hasCellFormulas(){return!!this.tableScope.tableSheet}getCellAddress(e,t){var s;return(s=this.tableScope.tableSheet)==null?void 0:s.address(e,this.toColumnIndex(t))}getCellByAddress(e){var t;return(t=this.tableScope.tableSheet)==null?void 0:t.cellOfAddress(e)}getCellInput(e,t){const s=this.toColumnIndex(t),o=this.tableScope.tableModel.getBodyModel();if(!(e<0||e>=o.getRowCount()||s<0))return this.tableScope.getCellInput(e,s)}getCellValue(e,t){const s=this.toColumnIndex(t),o=this.tableScope.tableModel.getBodyModel();if(!(e<0||e>=o.getRowCount()||s<0))return o.getValueAt(e,s)}setCellInput(e,t,s){return this.tableScope.applyCellChanges([{rowIndex:e,column:t,value:s}],"api").length>0}evaluateFormula(e){var t;return(t=this.tableScope.tableSheet)==null?void 0:t.evaluate(e)}getSheetValue(e){const t=this.tableScope.tableSheet;if(!t)return;const s=Ue(e);return s?t.cellValue(s.row,s.col):void 0}recalculate(){const e=this.tableScope.tableSheet;e&&(e.recalculate(),this.tableScope.invalidateAggregates(),this.tableScope.repaint())}getPrecedents(e,t){var s;return((s=this.tableScope.tableSheet)==null?void 0:s.precedents(e,this.toColumnIndex(t)))??[]}getDependents(e,t){var s;return((s=this.tableScope.tableSheet)==null?void 0:s.dependents(e,this.toColumnIndex(t)))??[]}getSheetEngine(){var e;return(e=this.tableScope.tableSheet)==null?void 0:e.engine}getActiveCell(){return this.tableScope.getActiveBodyCell()}goToAddress(e){const t=this.tableScope.tableSheet,s=e.trim().split(":");if(!t||s.length>2)return!1;const o=s.map(a=>t.cellOfAddress(a));if(o.some(a=>!a||a[0]<0))return!1;const[i,r]=[o[0],o[o.length-1]],l=new M(Math.min(i[0],r[0]),Math.min(i[1],r[1]),Math.max(i[0],r[0]),Math.max(i[1],r[1]));return this.tableScope.selectBodyRange(l),this.tableScope.ensureRowIsVisible(l.r1),this.tableScope.ensureColumnIsVisible(l.c1),!0}insertRows(e,t=1){return pt(this.tableScope,{kind:"insertRows",at:e,count:t})}deleteRows(e,t=1){return pt(this.tableScope,{kind:"deleteRows",at:e,count:t})}insertColumns(e,t=1){return pt(this.tableScope,{kind:"insertColumns",at:e,count:t})}deleteColumns(e,t=1){return pt(this.tableScope,{kind:"deleteColumns",at:e,count:t})}getSheetData(){const e=this.tableScope.tableModel.getBodyModel();return e instanceof Pe?e.getSheetData():void 0}toColumnIndex(e){return typeof e=="number"?e:this.getColumnIndex(e)}setDetailExpanded(e,t){return this.tableScope.setDetailExpanded(e,t,"api")}toggleDetail(e){return this.tableScope.toggleDetail(e,"api")}isDetailExpanded(e){var t;return!!((t=this.tableScope.masterDetailService)!=null&&t.isExpanded(e))}getExpandedDetailRows(){var e;return((e=this.tableScope.masterDetailService)==null?void 0:e.getExpandedRows())??[]}expandAllDetails(){var e;return((e=this.tableScope.masterDetailService)==null?void 0:e.expandAll())??0}collapseAllDetails(){var e;return((e=this.tableScope.masterDetailService)==null?void 0:e.collapseAll())??0}refreshDetail(e){var t;return!!((t=this.tableScope.masterDetailService)!=null&&t.refresh(e))}getDetailElement(e){var t;return(t=this.tableScope.masterDetailService)==null?void 0:t.getDetailElement(e)}startBatchEdit(){var t;const e=!!((t=this.tableScope.batchEditService)!=null&&t.start());return e&&this.tableScope.repaint(),e}isBatchEditing(){var e;return!!((e=this.tableScope.batchEditService)!=null&&e.isActive())}hasPendingChanges(){var e,t;return(e=this.tableScope.batchEditService)==null||e.pruneOrphans(),!!((t=this.tableScope.batchEditService)!=null&&t.hasPending())}getPendingChanges(){var e;return((e=this.tableScope.batchEditService)==null?void 0:e.getPendingChanges())??[]}commitBatchEdit(){var e;return!!((e=this.tableScope.batchEditService)!=null&&e.commit())}cancelBatchEdit(){var e;(e=this.tableScope.batchEditService)==null||e.cancel()}ensureRowIsVisible(e){return this.tableScope.ensureRowIsVisible(e)}ensureColumnIsVisible(e){return this.tableScope.ensureColumnIsVisible(e)}getDisplayedRowCount(){return this.tableScope.getDisplayedRowCount()}getFirstVisibleRowIndex(){return this.tableScope.getFirstVisibleRowIndex()}getFirstFullVisibleRowIndex(){return this.tableScope.getFirstFullVisibleRowIndex()}getLastVisibleRowIndex(){return this.tableScope.getLastVisibleRowIndex()}getLastFullVisibleRowIndex(){return this.tableScope.getLastFullVisibleRowIndex()}setLoggingActive(e){this.tableScope.loggingActive=e}isLoggingActive(){return this.tableScope.loggingActive}}function sr(n,e){var t;return!!((t=n==null?void 0:n.isColumnLetterRow)!=null&&t.call(n,e))}class Ee{constructor(e=0,t=0,s=0,o=0,i){this.left=e,this.width=t,this.height=s,this.top=o,this.index=i}}const Zt=class Zt{constructor(e){this.prefix=e}static createPrefix(e){const t=(e??"").trim();return t?`ge-${t.replace(/\s+/g,"_")}`:(Zt.counter++,`ge-t${Zt.counter}`)}cell(e,t,s){return`${this.prefix}-${e}-r${t}-c${s}`}rowGroup(e,t){return`${this.prefix}-rg-${e}-${t}`}detailRowGroup(){return`${this.prefix}-rg-detail`}liveRegion(){return`${this.prefix}-live`}};Zt.counter=0;let is=Zt;class so{constructor(){this.loadingText="Loading…",this.noRowsText="No rows to show",this.noMatchesText="No matching rows",this.autoNoRows=!0,this.blockInteractionWhileLoading=!0,this.loadingDelayInMs=0,this.getOverlayElement=void 0}static create(e){const t=new so;if(e)for(const s of Object.keys(e))e[s]!==void 0&&(t[s]=e[s]);return t}}function _o(n){return n.manual?n.manual:!n.autoNoRows||n.rowCount!==0?"none":(n.unfilteredRowCount??0)>0?"noMatches":"noRows"}const or={none:"",loading:"ge-table-overlay-loading",noRows:"ge-table-overlay-no-rows",noMatches:"ge-table-overlay-no-matches"};class bn{constructor(e,t,s,o=()=>{}){this.dom=t,this.requestUpdate=o,this.shownKind="none",this.shownText="",this.shownBlocking=!1,this.bounds="",this.destroyed=!1,this.options=so.create(s),this.element=t.applyStylePosistionAbsolute(t.createDivWithClass("ge-table-overlay",e)),t.setAriaHidden(this.element),t.applyDisplayNoneStyle(this.element),this.contentElement=t.createDivWithClass("ge-table-overlay-content",this.element)}showLoading(e){var o;if(this.destroyed)return;const t=((o=this.manual)==null?void 0:o.kind)==="loading";this.manual={kind:"loading",text:e};const s=this.options.loadingDelayInMs;!t&&s>0&&!this.delayTimeout&&(this.delayTimeout=setTimeout(()=>{this.delayTimeout=void 0,this.requestUpdate()},s)),this.requestUpdate()}showNoRows(e){this.destroyed||(this.clearDelay(),this.manual={kind:"noRows",text:e},this.requestUpdate())}hide(){this.destroyed||!this.manual||(this.clearDelay(),this.manual=void 0,this.requestUpdate())}getState(){return this.shownKind}isBlocking(){return this.shownBlocking}isEventBlocked(e){const t=e.target;return this.shownBlocking&&t instanceof Node&&this.element.contains(t)}update(e,t){var a;if(this.destroyed)return;const s=this.options.autoNoRows,o=this.delayTimeout?_o({rowCount:e,unfilteredRowCount:t,autoNoRows:s}):_o({manual:(a=this.manual)==null?void 0:a.kind,rowCount:e,unfilteredRowCount:t,autoNoRows:s}),i=this.getText(o),r=o==="loading"&&this.options.blockInteractionWhileLoading;if(o===this.shownKind&&i===this.shownText&&r===this.shownBlocking)return;const l=this.shownKind;return this.render(o,i,r),{previous:l,kind:o,text:i}}setBounds(e,t,s,o){const i=`${e},${t},${s},${o}`;this.destroyed||i===this.bounds||(this.bounds=i,this.dom.applyStyle(this.element,{left:`${e}px`,top:`${t}px`,width:`${Math.max(0,s)}px`,height:`${Math.max(0,o)}px`}))}destroy(){this.destroyed||(this.destroyed=!0,this.clearDelay(),this.contentElement.replaceChildren(),this.element.remove(),this.manual=void 0,this.shownKind="none",this.shownBlocking=!1)}getText(e){var s,o;const t=this.options;switch(e){case"loading":return((s=this.manual)==null?void 0:s.text)??t.loadingText;case"noRows":return(((o=this.manual)==null?void 0:o.kind)==="noRows"?this.manual.text:void 0)??t.noRowsText;case"noMatches":return t.noMatchesText;default:return""}}render(e,t,s){const o=this.dom,i=this.element;if(this.shownKind!=="none"&&o.removeClass(or[this.shownKind],i),this.contentElement.replaceChildren(),e==="none")o.removeClass("ge-table-overlay-visible",i),o.applyDisplayNoneStyle(i);else{o.addClass(`ge-table-overlay-visible ${or[e]}`,i),o.setStyle(i,"display","flex");const r=this.getOwnElement(e,t);if(r)o.domService.appendChild(this.contentElement,r);else{e==="loading"&&o.createDivWithClass("ge-table-spinner",this.contentElement);const l=o.createDivWithClass("ge-table-overlay-text",this.contentElement);l.textContent=t}}s?o.addClass("ge-table-overlay-blocking",i):o.removeClass("ge-table-overlay-blocking",i),this.shownKind=e,this.shownText=t,this.shownBlocking=s}getOwnElement(e,t){var s,o;try{return(o=(s=this.options).getOverlayElement)==null?void 0:o.call(s,e,t)}catch(i){console.error("TableOverlay: getOverlayElement failed, the built-in content is shown",i);return}}clearDelay(){this.delayTimeout&&(clearTimeout(this.delayTimeout),this.delayTimeout=void 0)}}function wn(n,e){var s,o,i;if(n==="rtl")return"rtl";if(n!=="auto"||!e)return"ltr";if(e.isConnected&&typeof getComputedStyle=="function"){const r=getComputedStyle(e).direction;if(r==="rtl"||r==="ltr")return r}return((i=(o=(s=e.closest)==null?void 0:s.call(e,"[dir]"))==null?void 0:o.getAttribute("dir"))==null?void 0:i.toLowerCase())==="rtl"?"rtl":"ltr"}function yn(n,e){const t=n.scrollLeft;return e?Math.max(0,-t):t}function Cn(n,e,t){n.scrollLeft=t?-e:e}function Ii(n,e){return e&&n!==0?-n:n}function vn(n,e,t){if(!e)return!1;const s=n.scrollWidth-n.clientWidth;return s<=0?!1:t?e>0?n.scrollLeft<0:n.scrollLeft>-s+1:e>0?n.scrollLeft+n.clientWidth<n.scrollWidth-1:n.scrollLeft>0}function Sn(n,e,t,s){return s?e+t-n:n-e}function xn(n){return n.split(" ").map(e=>e==="left"?"right":e==="right"?"left":e).join(" ")}const Hs=class Hs{constructor(e,t,s,o){this.hostElement=e,this.tableModel=t,this.dom=s,this.tableOptions=o,this.scrollTop=0,this.horizontalScrollBarHeight=0,this.verticalScrollBarWidth=0,this.areaBodyWestGeo=new Ee,this.areaBodyCenterGeo=new Ee,this.areaBodyEastGeo=new Ee,this.hostAttributesBefore=new Map;const i=this.hostElement;i.innerText="",this.direction=wn(o==null?void 0:o.direction,i),this.dom.setDirection(this.direction),this.dom.setAttribute(i,"tabindex","0"),this.ariaIds=new is(is.createPrefix(i.id)),this.initHostAria(),this.setHostAriaAttribute("dir",this.direction),this.dom.setStyle(this.dom.addClass("ge-table",i),"position","relative"),this.hoverRow=s.applyStylePosistionAbsolute(s.createDivWithClass("ge-table-hover-row",i)),this.hoverColumn=s.applyStylePosistionAbsolute(s.createDivWithClass("ge-table-hover-column",i)),this.draggingColumn=s.applyStylePosistionAbsolute(s.createDivWithClass("ge-table-dragging-column",i)),this.areaHeaderWest=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-header ge-table-header-west",i,"header","west"))),this.areaHeaderCenter=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-header ge-table-header-center",i,"header","center"))),this.areaHeaderEast=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-header ge-table-header-east",i,"header","east"))),this.areaBodyWest=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-body ge-table-body-west",i,"body","west"))),this.areaBodyEast=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-body ge-table-body-east",i,"body","east"))),this.areaFooterWest=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-footer ge-table-footer-west",i,"footer","west"))),this.areaFooterCenter=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-footer ge-table-footer-center",i,"footer","center"))),this.areaFooterEast=s.appendRelativeChildDiv(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-footer ge-table-footer-east",i,"footer","east"))),this.scrollViewport=s.applyStyleOverflowAuto(this.tableOptions.overflowX??"auto",this.tableOptions.overflowY??"auto",s.applyStyleNoPadding(s.applyStylePosistionAbsolute(s.createAreaDivWithClass("ge-table-scroll-viewport",i,"body","center")))),this.contentWrapperDiv=s.applyStyleNoPadding(s.applyStylePosistionRelative(s.createDivWithClass("ge-table-scroll-content-wrapper",this.scrollViewport))),this.contentDiv=s.applyStyleNoPadding(s.applyStylePosistionRelative(s.createDivWithClass("ge-table-scroll-content",this.contentWrapperDiv))),s.applyStyle(this.contentDiv,{position:"sticky",top:"0",left:"0"}),this.areaBodyCenter=s.appendRelativeChildDiv(s.createDivWithClass("ge-table-body-center",this.contentDiv));const r=(a,c)=>a?s.applyStylePosistionAbsolute(s.createDivWithClass(c,i)):void 0;this.borderHeaderBottom=r(o==null?void 0:o.headerSeparatorBorderVisible,"ge-table-header-border"),this.borderFixedWest=r(o==null?void 0:o.fixedWestSeparatorBorderVisible,"ge-table-west-fixed-column-border"),this.borderFixedEast=r(o==null?void 0:o.fixedEastSeparatorBorderVisible,"ge-table-east-fixed-column-border"),this.borderFooterTop=r(o==null?void 0:o.footerSeparatorBorderVisible,"ge-table-footer-border"),[this.hoverRow,this.hoverColumn,this.draggingColumn,this.borderHeaderBottom,this.borderFixedWest,this.borderFixedEast,this.borderFooterTop].forEach(a=>{a&&s.setAriaHidden(a)}),o!=null&&o.shortcutActionsDisabled||s.setAttribute(this.scrollViewport,"tabindex","-1"),[this.areaHeaderWest,this.areaHeaderCenter,this.areaHeaderEast,this.areaBodyWest,this.areaBodyEast,this.areaFooterWest,this.areaFooterCenter,this.areaFooterEast,this.areaBodyCenter].forEach(a=>s.setAttribute(a.parent,"role","presentation")),s.setAttribute(this.contentWrapperDiv,"role","presentation"),s.setAttribute(this.contentDiv,"role","presentation");const l=[];for(const a of["header","body","footer"])for(const c of["west","center","east"]){const h=this.ariaIds.rowGroup(a,c),d=this.getAreaChild(a,c);s.setAttribute(d,"id",h),s.setAttribute(d,"role","presentation"),l.push(h)}this.setHostAriaAttribute("aria-owns",l.join(" ")),this.tableOverlay=new bn(i,s,o==null?void 0:o.overlayOptions,()=>this.updateOverlay())}isRtl(){return this.direction==="rtl"}getViewportScrollLeft(){return yn(this.scrollViewport,this.isRtl())}setViewportScrollLeft(e){Cn(this.scrollViewport,e,this.isRtl())}clientXToHostX(e){const t=this.hostElement,s=t.getBoundingClientRect();return Sn(e,s.left+t.clientLeft,t.clientWidth,this.isRtl())}updateOverlay(){}setHostAriaAttribute(e,t){const s=this.hostElement;this.hostAttributesBefore.has(e)||this.hostAttributesBefore.set(e,s.getAttribute(e)),t===void 0?s.hasAttribute(e)&&this.dom.removeAttribute(s,e):s.getAttribute(e)!==t&&this.dom.setAttribute(s,e,t)}restoreHostAriaAttribute(e){const t=this.hostAttributesBefore.get(e)??null;t===null?this.hostElement.hasAttribute(e)&&this.dom.removeAttribute(this.hostElement,e):this.hostElement.getAttribute(e)!==t&&this.dom.setAttribute(this.hostElement,e,t)}removeHostAria(){this.hostAttributesBefore.forEach((e,t)=>{e===null?this.dom.removeAttribute(this.hostElement,t):this.dom.setAttribute(this.hostElement,t,e)}),this.hostAttributesBefore.clear()}initHostAria(){const e=this.tableOptions,t=Z(this.tableModel.getAreaModel("body"));this.setHostAriaAttribute("role",t?"treegrid":"grid"),e!=null&&e.ariaLabelledBy?this.setHostAriaAttribute("aria-labelledby",e.ariaLabelledBy):e!=null&&e.ariaLabel&&this.setHostAriaAttribute("aria-label",e.ariaLabel),e!=null&&e.ariaDescribedBy&&this.setHostAriaAttribute("aria-describedby",e.ariaDescribedBy)}getAreaChild(e,t){return{"header-west":this.areaHeaderWest,"header-center":this.areaHeaderCenter,"header-east":this.areaHeaderEast,"body-west":this.areaBodyWest,"body-center":this.areaBodyCenter,"body-east":this.areaBodyEast,"footer-west":this.areaFooterWest,"footer-center":this.areaFooterCenter,"footer-east":this.areaFooterEast}[`${e}-${t}`].child}adjustContainersAndRows(){this.layoutContainers(),this.adjustAfterScrolling()}layoutContainers(){const e=this.tableModel.getPadding(),t=this.hostElement.clientWidth,s=this.hostElement.clientHeight;this.dom.applyStyle(this.scrollViewport,{width:`${t-e.left}px`,height:`${s-e.top}px`,top:`${e.top}px`,left:`${e.left}px`}),this.horizontalScrollBarHeight=this.measureHorizontalScrollBarHeight(),this.verticalScrollBarWidth=this.measureVerticalScrollBarWidth();const o=this.getLayoutWidth(),i=this.getLayoutHeight();this.scrollTop=this.scrollViewport.scrollTop,this.dom.applyStyle(this.contentDiv,{width:`${this.scrollViewport.clientWidth}px`,height:`${this.scrollViewport.clientHeight}px`}),this.areaBodyWestGeo.width=e.left,this.areaBodyWestGeo.height=i-e.top-e.bottom,this.areaBodyWestGeo.top=e.top,this.areaBodyWestGeo.left=0,this.dom.applyStyleInPx(this.areaBodyWest.parent,this.areaBodyWestGeo),this.borderFixedWest&&this.tableModel.getFixedLeftColumnCount()?this.dom.applyDisplayBlockStyle(this.dom.applyStyle(this.borderFixedWest,{width:"1px",height:`${this.areaBodyWestGeo.height}px`,top:`${this.areaBodyWestGeo.top}px`,left:`${this.areaBodyWestGeo.width}px`})):this.borderFixedWest&&this.dom.applyDisplayNoneStyle(this.borderFixedWest),this.areaBodyEastGeo.width=e.right,this.areaBodyEastGeo.height=i-e.top-e.bottom,this.areaBodyEastGeo.top=e.top,this.areaBodyEastGeo.left=o-e.right,this.dom.applyStyleInPx(this.areaBodyEast.parent,this.areaBodyEastGeo),this.borderFixedEast&&this.tableModel.getFixedRightColumnCount()?this.dom.applyDisplayBlockStyle(this.dom.applyStyle(this.borderFixedEast,{width:"1px",height:`${this.areaBodyEastGeo.height}px`,top:`${this.areaBodyEastGeo.top}px`,left:`${this.areaBodyEastGeo.left}px`})):this.borderFixedEast&&this.dom.applyDisplayNoneStyle(this.borderFixedEast),this.areaBodyCenterGeo.width=o-e.left-e.right,this.areaBodyCenterGeo.height=i-e.top-e.bottom,this.areaBodyCenterGeo.top=0,this.areaBodyCenterGeo.left=0,this.dom.applyStyleInPx(this.areaBodyCenter.parent,this.areaBodyCenterGeo),this.dom.applyStyle(this.areaHeaderCenter.parent,{width:`${o-e.left-e.right}px`,height:`${e.top}px`,top:"0",left:`${e.left}px`}),this.dom.applyStyle(this.areaHeaderWest.parent,{width:`${e.left}px`,height:`${e.top}px`,top:"0",left:"0"}),this.dom.applyStyle(this.areaHeaderEast.parent,{width:`${e.right}px`,height:`${e.top}px`,top:"0",left:`${o-e.right}px`}),this.borderHeaderBottom&&this.tableModel.isHeaderVisibe()?this.dom.applyDisplayBlockStyle(this.dom.applyStyle(this.borderHeaderBottom,{width:`${o}px`,height:"1px",top:`${e.top}px`,left:"0px"})):this.borderHeaderBottom&&this.dom.applyDisplayNoneStyle(this.borderHeaderBottom),this.dom.applyStyle(this.areaFooterWest.parent,{width:`${e.left}px`,height:`${e.bottom}px`,top:`${i-e.bottom}px`,left:"0"}),this.dom.applyStyle(this.areaFooterCenter.parent,{width:`${o-e.left-e.right}px`,height:`${e.bottom}px`,top:`${i-e.bottom}px`,left:`${e.left}px`}),this.dom.applyStyle(this.areaFooterEast.parent,{width:`${e.right}px`,height:`${e.bottom}px`,top:`${i-e.bottom}px`,left:`${o-e.right}px`}),this.borderFooterTop&&this.tableModel.isFooterVisibe()?this.dom.applyDisplayBlockStyle(this.dom.applyStyle(this.borderFooterTop,{width:`${o}px`,height:"1px",top:`${i-e.bottom}px`,left:"0px"})):this.borderFooterTop&&this.dom.applyDisplayNoneStyle(this.borderFooterTop),this.tableOverlay.setBounds(0,e.top,Math.min(o,e.left+this.scrollViewport.clientWidth),i-e.top-e.bottom),this.adjustDetailLayerBounds(0,e.top,Math.min(o,e.left+this.scrollViewport.clientWidth),Math.max(0,Math.min(i-e.top-e.bottom,this.scrollViewport.clientHeight)))}getLayoutHeight(){return Math.max(0,this.hostElement.clientHeight-this.horizontalScrollBarHeight)}getLayoutWidth(){return Math.max(0,this.hostElement.clientWidth-this.verticalScrollBarWidth)}measureHorizontalScrollBarHeight(){const e=this.scrollViewport;return Math.max(0,e.offsetHeight-e.clientHeight)}measureVerticalScrollBarWidth(){const e=this.scrollViewport;return Math.max(0,e.offsetWidth-e.clientWidth)}adjustDetailLayerBounds(e,t,s,o){}adjustAfterScrolling(){}getBodyContentHeight(){return this.tableModel.getContentHeightInPixel()}resetSizeOfWrapperDiv(){const e=`${this.tableModel.getContentWidthInPixel()}px`,t=this.getBodyContentHeight()+1,s=`${Math.min(t,Hs.maxScrollHeightInPx)}px`;this.dom.setStyle(this.contentWrapperDiv,"width",e),this.dom.setStyle(this.contentWrapperDiv,"height",s)}};Hs.maxScrollHeightInPx=8e6;let rs=Hs;class Rn{constructor(e,t){this.tableModel=e,this.areaModel=t,this.colAndRowspanRanges=void 0,this.rowCountAtInit=-1}init(){if(this.rowCountAtInit=this.areaModel.getRowCount(),this.areaModel.getMaxColspan()<2&&this.areaModel.getMaxRowspan()<2){this.colAndRowspanRanges=void 0;return}this.colAndRowspanRanges=[];const e=this.areaModel.getRowCount();for(let t=0;t<e;t++)this.scanRow(t,this.colAndRowspanRanges)}scanRow(e,t){const s=this.tableModel.getColumnCount();for(let o=0;o<s;o++){let i=this.areaModel.getColspanAt(e,o),r=this.areaModel.getRowspanAt(e,o);if(i>1||r>1){i===0&&(i=1),r===0&&(r=1);const l="gammaCells"in this.areaModel;t.push(new M(e,o,e+r-1,o+i-1,l))}}}updateForInsertedRows(e){var s;if(this.rowCountAtInit<0||(s=this.colAndRowspanRanges)!=null&&s.length)return!1;const t=[];if(this.areaModel.getMaxColspan()>=2||this.areaModel.getMaxRowspan()>=2)for(let o=0;o<e.length;o++)this.scanRow(e[o],t);return this.colAndRowspanRanges=t.length?t:this.colAndRowspanRanges,this.rowCountAtInit=this.areaModel.getRowCount(),!0}initIfRowCountChanged(){return this.areaModel.getRowCount()===this.rowCountAtInit?!1:(this.init(),!0)}getRanges(){return this.colAndRowspanRanges?this.colAndRowspanRanges:[]}isInRange(e,t){if(this.colAndRowspanRanges){for(const s of this.colAndRowspanRanges)if(s.isInRange(e,t))return!0}return!1}}class wt{constructor(e,t,s,o){this.headerRowCount=e,this.bodyRowCount=t,this.footerRowCount=s,this.colIndexMap=o}static create(e){var a,c,h;const t=e.isHeaderVisibe()?Math.max(0,((a=e.getAreaModel("header"))==null?void 0:a.getRowCount())??0):0,s=e.isFooterVisibe()?Math.max(0,((c=e.getAreaModel("footer"))==null?void 0:c.getRowCount())??0):0,o=((h=e.getAreaModel("body"))==null?void 0:h.getRowCount())??0,i=e.getColumnCount(),r=new Array(Math.max(0,i));let l=0;for(let d=0;d<i;d++)r[d]=e.getColumnWidth(d)>0?++l:0;return new wt(t,o,s,r)}get rowCount(){return this.bodyRowCount<0?-1:this.headerRowCount+this.bodyRowCount+this.footerRowCount}get colCount(){let e=0;for(const t of this.colIndexMap)t>0&&e++;return e}rowIndex(e,t){return e==="header"?t+1:e==="body"?this.headerRowCount+t+1:this.headerRowCount+Math.max(0,this.bodyRowCount)+t+1}colIndex(e){return this.colIndexMap[e]??0}colSpan(e,t){let s=0;for(let o=e;o<e+t;o++)(this.colIndexMap[o]??0)>0&&s++;return Math.max(1,s)}}class An{constructor(){this.positions=new WeakMap,this.sizes=new WeakMap}get(e,t){const s=e.getRowByIndex(t);if(!s)return;const o=e.getFilteredFlattenRows();o!==this.displayedRows&&(this.displayedRows=o,this.positions=new WeakMap,this.sizes=new WeakMap);const i=s.parent??e;let r=this.positions.get(i);if(!r){const a=s.parent?e.getDisplayedChildren(s.parent):e.getDisplayedRootRows();r=new Map,a.forEach((c,h)=>r.set(c,h+1)),this.positions.set(i,r),this.sizes.set(i,a.length)}const l=e.hasDisplayedChildren(s);return{level:(s.deep??0)+1,setSize:Math.max(1,this.sizes.get(i)??1),posInSet:r.get(s)??1,expanded:l?!!s.expanded:void 0}}}class En{constructor(){this.rowCount=0,this.heightOf=()=>0,this.extraIndices=new Int32Array(0),this.extraHeights=new Float64Array(0),this.extraPrefix=new Float64Array(1)}setRows(e,t,s){if(this.rowCount=Math.max(0,Math.floor(e)||0),this.heightOf=t,this.constantHeight=s!==void 0&&s>0?s:void 0,this.prefix=void 0,this.extraIndices.length&&this.extraIndices[this.extraIndices.length-1]>=this.rowCount){const o=[],i=[];this.extraIndices.forEach((r,l)=>{r<this.rowCount&&(o.push(r),i.push(this.extraHeights[l]))}),this.setExtras(o,i)}}setExtras(e,t){const s=new Map;for(let i=0;i<e.length;i++){const r=e[i],l=t[i];r>=0&&r<this.rowCount&&l>0&&s.set(r,(s.get(r)??0)+l)}const o=Int32Array.from(s.keys()).sort();this.extraIndices=o,this.extraHeights=Float64Array.from(o,i=>s.get(i)),this.rebuildExtraPrefix()}setExtraHeight(e,t){const s=this.findExtra(e);return s<0||!(t>0)||this.extraHeights[s]===t?!1:(this.extraHeights[s]=t,this.rebuildExtraPrefix(),!0)}setExtra(e,t){if(!(e>=0&&e<this.rowCount))return!1;const s=this.findExtra(e);if(s>=0){if(t>0)return this.setExtraHeight(e,t);const l=Array.from(this.extraIndices),a=Array.from(this.extraHeights);return l.splice(s,1),a.splice(s,1),this.extraIndices=Int32Array.from(l),this.extraHeights=Float64Array.from(a),this.rebuildExtraPrefix(),!0}if(!(t>0))return!1;const o=this.countExtrasBelow(e),i=Array.from(this.extraIndices),r=Array.from(this.extraHeights);return i.splice(o,0,e),r.splice(o,0,t),this.extraIndices=Int32Array.from(i),this.extraHeights=Float64Array.from(r),this.rebuildExtraPrefix(),!0}getRowCount(){return this.rowCount}getExtraCount(){return this.extraIndices.length}hasPrefixSums(){return!!this.prefix}getRowHeight(e){if(this.constantHeight!==void 0)return this.constantHeight;const t=this.ensurePrefix();return e>=0&&e<this.rowCount?t[e+1]-t[e]:0}getExtraHeight(e){const t=this.findExtra(e);return t<0?0:this.extraHeights[t]}getExtraBefore(e){return this.extraPrefix[this.countExtrasBelow(e)]}getExtraTotal(){return this.extraPrefix[this.extraIndices.length]}getTop(e){const t=Math.min(Math.max(0,Math.floor(e)||0),this.rowCount);return this.getBaseTop(t)+this.extraPrefix[this.countExtrasBelow(t)]}getTotalHeight(){return this.getTop(this.rowCount)}findIndexAt(e){const t=this.rowCount;if(t<1)return-1;if(!(e>0))return 0;const s=this.constantHeight;if(s!==void 0&&!this.extraIndices.length){let r=Math.min(t-1,Math.floor(e/s));for(;r>0&&r*s>e;)r--;for(;r<t-1&&(r+1)*s<=e;)r++;return r}let o=0,i=t-1;for(;o<i;){const r=o+i>>>1;this.getTop(r+1)>e?i=r:o=r+1}return o}getBaseTop(e){return this.constantHeight!==void 0?e*this.constantHeight:this.ensurePrefix()[e]}ensurePrefix(){if(!this.prefix){const e=this.rowCount,t=new Float64Array(e+1);let s=0;for(let o=0;o<e;o++)s+=this.heightOf(o)||0,t[o+1]=s;this.prefix=t}return this.prefix}rebuildExtraPrefix(){const e=this.extraIndices.length,t=new Float64Array(e+1);for(let s=0;s<e;s++)t[s+1]=t[s]+this.extraHeights[s];this.extraPrefix=t}countExtrasBelow(e){const t=this.extraIndices;let s=0,o=t.length;for(;s<o;){const i=s+o>>>1;t[i]<e?s=i+1:o=i}return s}findExtra(e){const t=this.countExtrasBelow(e);return t<this.extraIndices.length&&this.extraIndices[t]===e?t:-1}}class Mn extends rs{constructor(e,t,s,o){var r,l,a,c,h;if(super(e,t,s,o),this.firstVisibleRowIndex=-1,this.lastVisibleRowIndex=-1,this.firstFullVisibleRowIndex=-1,this.lastFullVisibleRowIndex=-1,this.displayedRowCount=0,this.pixelLimitForFullVisible=5,this.loggingActive=!1,this.dragging=!1,this.editing=!1,this.storedColumnWidths=[],this.scrollLeft=0,this.scrollViewportLeft=0,this.scrollFactorY=0,this.scrollFactorX=0,this.cleanupFunctions={header:[],body:[],footer:[]},this.tree=!1,this.colAndRowspanModels=new ee,this.draggingTargetColumnIndex=-1,this.contentScrollTop=0,this.renderedScrollTop=Number.NaN,this.renderedBodyRows={count:0,first:0,offset:0,last:-1,atEnd:!0},this.renderedScrollLeft=Number.NaN,this.removables=[],this.treeAriaInfo=new An,this.ariaSelectionKind="none",this.renderedSpanCells=new Set,this.bodyRowLayout=new En,this.bodyRowLayoutDirty=!0,this.adjustingRowNumberWidth=!1,this.adjustingRelativeWidths=!1,this.relativeWidthsBase=-1,this.rowNumberRemeasureScheduled=!1,this.ariaTexts=me.create(o==null?void 0:o.ariaTexts),(l=(r=this.tableModel).getSelectionModel)!=null&&l.call(r))this.getSelectionModel=()=>this.tableModel.getSelectionModel();else if((a=this.tableOptions)!=null&&a.getSelectionModel)this.getSelectionModel=this.tableOptions.getSelectionModel;else{const d=(c=this.tableOptions)!=null&&c.spreadsheet?new pe("range","multi"):new pe;this.getSelectionModel=()=>d}if((h=this.tableOptions)!=null&&h.getFocusModel)this.getFocusModel=this.tableOptions.getFocusModel;else{const d=new Ri("cell");this.getFocusModel=()=>d}Z(t.getAreaModel("body"))&&(this.tree=!0),["header","body","footer"].forEach(d=>{var u;this.colAndRowspanModels[d]=new Rn(t,t.getAreaModel(d)),(u=this.colAndRowspanModels[d])==null||u.init()})}getDomService(){return this.dom}getBodyViewport(){const e=this.hostElement,t=e.getBoundingClientRect();return{top:t.top+e.clientTop+this.tableModel.getPadding().top,height:this.areaBodyCenterGeo.height,left:t.left+e.clientLeft,width:this.scrollViewport.clientWidth,contentScrollTop:this.contentScrollTop}}getBodyCellRectInHost(e,t){const s=this.tableModel,o=s.getBodyModel(),i=s.getPadding(),r=this.getLayoutWidth(),l=this.getLayoutHeight(),a=i.top+this.getBodyRowTop(e)-this.contentScrollTop,c=this.getColumnLeftInHost(t,s.getXPosByColumnIndex(t)),h=s.getColumnCount(),d=s.getFixedLeftColumnCount(),u=s.getFixedRightColumnCount();let f=i.left,g=r-i.right;return t<d?(f=0,g=i.left):u>0&&t>=h-u&&(f=r-i.right,g=r),{left:c,top:a,width:s.getColumnWidth(t),height:o.getRowHeight(e),clipLeft:f,clipRight:g,clipTop:i.top,clipBottom:l-i.bottom}}getBodyCellAtHostPoint(e,t){const s=this.tableModel,i=s.getBodyModel().getRowCount(),r=s.getColumnCount();if(i<1||r<1)return[-1,-1];const l=s.getPadding(),a=this.getLayoutWidth(),c=this.getLayoutHeight()-l.top-l.bottom,h=Math.min(Math.max(t-l.top,0),Math.max(0,c-1))+this.contentScrollTop,d=this.getBodyRowIndexAtY(h),u=s.getFixedLeftColumnCount(),f=s.getFixedRightColumnCount();let g,p,m;if(u>0&&e<l.left)[g,p,m]=[0,u-1,e];else if(f>0&&e>=a-l.right){const y=r-f;[g,p,m]=[y,r-1,e-(a-l.right)+s.getXPosByColumnIndex(y)]}else{const y=a-l.right,C=Math.min(Math.max(e,l.left),Math.max(l.left,y-1));[g,p,m]=[u,r-f-1,C+this.getContentScrollLeft()]}let b=p;for(let y=g;y<=p;y++)if(m<s.getXPosByColumnIndex(y)+s.getColumnWidth(y)){b=y;break}return[d,Math.min(r-1,Math.max(g,b))]}getBodyRowLayout(){var o,i;const e=this.tableModel.getBodyModel(),t=e.getRowCount(),s=this.bodyRowLayout;if(this.bodyRowLayoutDirty||this.bodyRowLayoutModel!==e||s.getRowCount()!==t){this.bodyRowLayoutDirty=!1,this.bodyRowLayoutModel=e;const r=this.tableModel;s.setRows(t,a=>r.getRowHeight("body",a),(o=e.getConstantRowHeight)==null?void 0:o.call(e));const l=(i=this.masterDetailService)==null?void 0:i.computeExtras();s.setExtras((l==null?void 0:l.rowIndices)??[],(l==null?void 0:l.heights)??[])}return s}invalidateRowLayout(){this.bodyRowLayoutDirty=!0}setBodyRowExtra(e,t){const s=this.tableModel.getBodyModel();return this.bodyRowLayoutDirty||this.bodyRowLayoutModel!==s||this.bodyRowLayout.getRowCount()!==s.getRowCount()?!1:(this.bodyRowLayout.setExtra(e,t),!0)}hasBodyRowExtras(){var e;return!!((e=this.masterDetailService)!=null&&e.hasExpanded())&&this.getBodyRowLayout().getExtraCount()>0}getBodyRowTop(e){return this.getBodyRowLayout().getTop(e)}getBodyRowIndexAtY(e){return this.getBodyRowLayout().findIndexAt(e)}getScrollerToContentRatioY(){if(!this.isScrollHeightCapped())return 1;const e=this.getContentScrollRangeY(),t=this.getScrollerRangeY();return e>0&&t>0?t/e:1}isEditing(){var e;return this.editing||!!((e=this.cellEditorService)!=null&&e.isOpen())}getInCellEditorCell(){return this.editing&&this.editorRenderer&&(this.editorRendererRow??-1)>=0?[this.editorRendererRow,this.editorRendererColumn]:void 0}setEditorDraft(e,t,s){if(this.editing&&this.editorRendererRow===e&&this.editorRendererColumn===t){let o=null,i=null;try{o=s.selectionStart,i=s.selectionEnd}catch{}this.editorDraft={rowIndex:e,columnIndex:t,value:s.value,start:o,end:i}}}shiftEditorRow(e){if(this.editing&&this.editorRenderer&&(this.editorRendererRow??-1)>=0){const t=e.mapIndex(this.editorRendererRow);if(t<0){this.resetEditorRenderer();return}this.editorRendererRow=t}if(this.editorDraft){const t=e.mapIndex(this.editorDraft.rowIndex);this.editorDraft=t<0?void 0:{...this.editorDraft,rowIndex:t}}}resetEditorRenderer(){this.editorRenderer=void 0,this.editorRendererRow=-1,this.editorRendererColumn=-1,this.editing=!1,this.editorDraft=void 0}clearSelection(e=!1){if(this.getSelectionModel){const t=this.getSelectionModel();t==null||t.clear(),e&&this.repaint()}}initRenderEditor(e,t){var o;let s=(o=this.tableModel.getColumnDef(t))==null?void 0:o.getEditRenderer;if(s||(s=this.tableOptions.getEditRenderer),s)if(this.editorRenderer=s(e,t),this.editorRenderer){this.editorRendererRow=e,this.editorRendererColumn=t,this.editing=!0,this.repaint();const i=this.hostElement.querySelector("input.ge-table-cell-editor-input");i&&i.focus()}else this.resetEditorRenderer()}repaint(){this.adjustAfterScrolling()}invalidateAggregates(e){var t,s;e||this.invalidateRowLayout();for(const o of["header","body","footer"])(s=(t=this.tableModel.getAreaModel(o))==null?void 0:t.invalidateDerivedValues)==null||s.call(t,e)}repaintHard(e){var t;for(const s of["header","body","footer"])(t=this.colAndRowspanModels[s])==null||t.initIfRowCountChanged();this.tableModel.recalcHeightAndPadding(),this.invalidateRowLayout(),this.resetSizeOfWrapperDiv(),this.layoutContainers(),e&&this.setContentScrollPosition(e.px,e.py),this.adjustAfterScrolling()}rememberRenderedBodyRows(){const e=this.tableModel.getBodyModel().getRowCount();if(e<=0){this.renderedBodyRows={count:Math.max(0,e),first:0,offset:0,last:-1,atEnd:!0};return}const t=this.contentScrollTop,s=this.getBodyRowIndexAtY(t),o=this.getBodyRowIndexAtY(t+Math.max(0,this.areaBodyCenterGeo.height-1)),i=this.getContentScrollRangeY(),r=Math.max(1,this.tableModel.getRowHeight("body",e-1)/2);this.renderedBodyRows={count:e,first:s,offset:t-this.getBodyRowTop(s),last:o,atEnd:i<=0||t>=i-r}}updateRowCountWithoutRender(e){for(const s of["header","body","footer"]){const o=this.colAndRowspanModels[s];if(o==null||o.initIfRowCountChanged(),o!=null&&o.getRanges().length)return!1}const t=this.scrollViewport.clientWidth;return this.tableModel.recalcHeightAndPadding(),this.invalidateRowLayout(),this.resetSizeOfWrapperDiv(),this.layoutContainers(),this.scrollViewport.clientWidth!==t?!1:(this.setContentScrollPosition(void 0,e),this.renderedScrollTop=this.scrollViewport.scrollTop,this.scrollTop=this.scrollViewport.scrollTop,this.renderedBodyRows={...this.renderedBodyRows,count:this.tableModel.getBodyModel().getRowCount(),atEnd:!1},this.setHostAttribute("aria-rowcount",`${wt.create(this.tableModel).rowCount}`),!0)}setContentScrollPosition(e,t){const s=this.scrollViewport,o={};if(e!==void 0&&(o.left=Ii(e,this.isRtl())),t===void 0)return e!==void 0&&s.scrollTo(o),!1;const i=this.getContentScrollRangeY(),r=this.getScrollerRangeY();if(i>0&&r>0){const l=Math.min(i,Math.max(0,t));return o.top=l/i*r,s.scrollTo(o),this.pendingContentScroll={scrollTop:s.scrollTop,contentTop:l},!0}return o.top=t,s.scrollTo(o),!1}onViewportScroll(){this.scrollViewport.scrollTop===this.renderedScrollTop&&this.getViewportScrollLeft()===this.renderedScrollLeft||this.adjustAfterScrolling()}recalcColumnWidths(e){const t=this.getAvailableColumnWidth(e);t>0&&this.setParentWidth(t),this.tableModel.init(),this.repaintHard()}setParentWidth(e){this.relativeWidthsBase=e,this.tableModel.setParentWidth(e)}hasRelativeColumnWidths(){var e,t,s;return!!((s=(t=(e=this.tableModel).getColumnDefs)==null?void 0:t.call(e))!=null&&s.some(o=>{var i,r;return((i=o.width)==null?void 0:i.unit)==="weight"||((r=o.width)==null?void 0:r.unit)==="%"}))}layoutContainers(){super.layoutContainers(),this.adjustRelativeColumnWidthsToScrollBar()}adjustRelativeColumnWidthsToScrollBar(){if(this.adjustingRelativeWidths||!this.hasRelativeColumnWidths())return;const e=this.getAvailableColumnWidth();if(!(e<=0||e===this.relativeWidthsBase)){this.adjustingRelativeWidths=!0;try{this.setParentWidth(e),this.tableModel.init(),this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.layoutContainers()}finally{this.adjustingRelativeWidths=!1}}}getAvailableColumnWidth(e=this.hostElement.clientWidth){const t=Math.max(0,this.scrollViewport.offsetWidth-this.scrollViewport.clientWidth);return Math.max(0,e-this.tableModel.getPadding().left-t)}adjustAfterScrolling(){var i,r,l,a;if(!this.adjustingRowNumberWidth&&this.adjustRowNumberColumnWidth()){this.adjustingRowNumberWidth=!0;try{if((l=(r=(i=this.tableModel).getColumnDefs)==null?void 0:r.call(i))!=null&&l.some(c=>{var h,d;return((h=c.width)==null?void 0:h.unit)==="weight"||((d=c.width)==null?void 0:d.unit)==="%"})){this.tableModel.recalcPadding();const c=this.getAvailableColumnWidth();c>0&&(this.setParentWidth(c),this.tableModel.init())}this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}finally{this.adjustingRowNumberWidth=!1}return}for(const c of this.removables)c.remove();if(this.hideHoverRow(),this.hideHoverColumn(),this.scrollTop=this.scrollViewport.scrollTop,this.scrollLeft=this.getViewportScrollLeft(),this.scrollViewportLeft=this.scrollLeft,this.scrollFactorY=this.scrollTop/(this.scrollViewport.scrollHeight-this.scrollViewport.clientHeight),this.scrollFactorX=this.scrollLeft/(this.scrollViewport.scrollWidth-this.scrollViewport.clientWidth),isNaN(this.scrollFactorY)&&(this.scrollFactorY=0),this.pendingContentScroll){const c=this.getContentScrollRangeY();Math.abs(this.scrollTop-this.pendingContentScroll.scrollTop)<=1&&c>0?this.scrollFactorY=Math.min(1,Math.max(0,this.pendingContentScroll.contentTop/c)):this.pendingContentScroll=void 0}isNaN(this.scrollFactorX)&&(this.scrollFactorX=0);const e=this.hostElement.clientWidth,t=this.hostElement.clientHeight,s=this.areaBodyWest.child.clientWidth,o=this.areaHeaderCenter.child.clientHeight;this.areaHeightsOfRenderPass={body:this.areaBodyCenter.child.clientHeight,footer:this.areaFooterCenter.child.clientHeight,header:o},this.ariaGridInfo=wt.create(this.tableModel),this.ariaSelectionKind=this.getAriaSelectionKind(),this.ariaFocusedCell=void 0,this.renderedSpanCells.clear();try{this.adjustBody(),this.adjustArea("footer"),this.adjustArea("header")}finally{this.areaHeightsOfRenderPass=void 0}this.updateHostAria(),this.tableOptions.tableTopBorderVisible&&this.removables.push(this.dom.addHorizontalBorder(new Ee(0,e,1,0),this.hostElement,"ge-table-border")),this.tableOptions.tableBottomBorderVisible&&this.removables.push(this.dom.addHorizontalBorder(new Ee(0,e,1,t-1),this.hostElement,"ge-table-border")),this.tableModel.getFixedLeftColumnCount()>0&&this.tableOptions.fixedWestSeparatorBorderVisible!==!1&&this.removables.push(this.dom.addVerticalBorder(new Ee(s,1,t,0),this.hostElement,"ge-table-body-west-vertical-border")),this.tableModel.isHeaderVisibe()&&this.tableOptions.headerSeparatorBorderVisible!==!1&&this.removables.push(this.dom.addHorizontalBorder(new Ee(0,e,1,o),this.hostElement,"ge-table-body-west-vertical-border")),this.updateOverlay(),(a=this.rowNumberWidth)!=null&&a.approximate&&!this.rowNumberRemeasureScheduled&&this.findRowNumberLabel()&&(this.rowNumberRemeasureScheduled=!0,requestAnimationFrame(()=>{this.hostElement.isConnected&&this.repaint()})),this.rememberRenderedBodyRows(),this.afterRenderPass(),this.renderedScrollTop=this.scrollTop,this.renderedScrollLeft=this.scrollLeft}afterRenderPass(){}updateOverlay(){var r;const e=this.tableOverlay;if(!e)return;const t=this.tableModel.getBodyModel(),s=t.getRowCount(),o=s===0?(r=t.getUnfilteredRowCount)==null?void 0:r.call(t):void 0,i=e.update(s,o);i&&this.onOverlayChanged(i)}onOverlayChanged(e){}checkForScrollPosSaving(){this.afterRenderPass()}updateCells(e,t=!1){const s=this.tableModel.getBodyModel(),o=s.getRowCount(),i=this.tableSheet,r=()=>e.forEach(c=>{i&&c.area==="body"&&i.isFormulaInput(c.columnIndex,c.value)?this.setRawValue(c.rowIndex,c.columnIndex,c.value):this.tableModel.getAreaModel(c.area).setValue(c.rowIndex,c.columnIndex,c.value),!t&&!(i&&c.area==="body")&&this.rerenderCellContent(c)}),l=ne(s)?s.batch(r):(r(),!1),a=this.tableSheet?e.filter(c=>c.area==="body"):[];if(a.length&&(this.tableSheet.cellsWritten(a.map(c=>({row:void 0,rowIndex:c.rowIndex,columnIndex:c.columnIndex,property:"",oldValue:void 0,newValue:c.value}))),t=!0),l){this.invalidateAggregates(),this.repaintHard();return}if(e.length){const c=e[0].area;this.invalidateAggregates(e.every(h=>h.area===c)?{area:c,rowIndices:e.map(h=>h.rowIndex)}:void 0)}e.length&&s.getRowCount()!==o?this.repaintHard():t?this.repaint():e.length&&(this.rerenderDerivedFooterCells(e),this.rerenderGroupRowCells(),this.rerenderCalculatedCells())}setRawValue(e,t,s){const o=this.tableModel.getBodyModel(),i=this.tableModel.getColumnDef(t),r=i==null?void 0:i.editInputPipe;if(!i||!r||Object.isFrozen(i))return o.setValue(e,t,s);i.editInputPipe=void 0;try{return o.setValue(e,t,s)}finally{i.editInputPipe=r}}rerenderCalculatedCells(){var o;const e=this.tableModel.getBodyModel();if(!((o=e.hasDerivedColumns)!=null&&o.call(e)))return;const t=new Map;this.hostElement.querySelectorAll('div.ge-table-col-div[data-area="body"][data-row-index][data-col-index]').forEach(i=>{var a,c;const r=Number(i.getAttribute("data-row-index")),l=Number(i.getAttribute("data-col-index"));if(!t.has(l)){const h=(a=this.tableModel.getColumnDef(l))==null?void 0:a.property;t.set(l,h!==void 0&&!!((c=e.isDerivedProperty)!=null&&c.call(e,h)))}t.get(l)&&this.rerenderCellContent({area:"body",rowIndex:r,columnIndex:l,value:e.getValueAt(r,l)??""})})}rerenderGroupRowCells(){const e=this.tableModel.getBodyModel();if(!ne(e))return;this.hostElement.querySelectorAll('div.ge-table-col-div[data-area="body"][data-row-index][data-col-index]').forEach(s=>{const o=Number(s.getAttribute("data-row-index")),i=Number(s.getAttribute("data-col-index"));!e.isGroupRowIndex(o)||!e.getCellRenderer(o,i)||this.rerenderCellContent({area:"body",rowIndex:o,columnIndex:i,value:e.getValueAt(o,i)})})}rerenderDerivedFooterCells(e){const t=this.tableModel.getAreaModel("footer");if(!(t!=null&&t.invalidateDerivedValues)||e.every(o=>o.area==="footer"))return;this.hostElement.querySelectorAll('div.ge-table-col-div[data-area="footer"][data-row-index][data-col-index]').forEach(o=>{const i=Number(o.getAttribute("data-row-index")),r=Number(o.getAttribute("data-col-index"));this.rerenderCellContent({area:"footer",rowIndex:i,columnIndex:r,value:t.getValueAt(i,r)})})}rerenderCellContent({area:e,rowIndex:t,columnIndex:s,value:o,cssClasses:i}){const r=this.tableModel.getAreaModel(e),l='div[data-col-index="'+s+'"][data-row-index="'+t+'"][data-area="'+e+'"]',a=this.hostElement.querySelector(l);if(a){let c;const h=e==="body"&&this.editorRenderer&&this.editorRendererRow===t&&this.editorRendererColumn===s;let d;if(h?d=this.editorRenderer:d=r.getCellRenderer(t,s),a.innerText="",this.applyCssClasses(a,i),d)c=d.render(a,t,s,e,r,o,this.dom.domService),c&&this.cleanupFunctions[e].push(c);else{const g=`${o}`;this.dom.addLabelDiv(a,g,!1,t,s,e)}const u=r.getCustomClassesAt(t,s);u.length&&this.dom.addClasses(u,a);const f=r.getCustomStyleAt(t,s);if(f)for(const g in f)this.dom.domService.setStyle(a,g,f[g])}}getFirstVisibleRowIndex(){return this.firstVisibleRowIndex}getLastVisibleRowIndex(){return this.lastVisibleRowIndex}getFirstFullVisibleRowIndex(){return this.firstFullVisibleRowIndex}getLastFullVisibleRowIndex(){return this.lastFullVisibleRowIndex}getDisplayedRowCount(){return this.displayedRowCount}storeColumnWidths(){const e=this.tableModel.getColumnDefs();e!=null&&e.length&&(this.storedColumnWidths=e.map((t,s)=>this.tableModel.getColumnWidth(s)))}getAreaAndSideIdentByAttr(e){if(e){const t=this.getStringByAttr(e,"data-area"),s=this.getStringByAttr(e,"data-side");if(s&&t)return[t,s]}return[void 0,void 0]}getArea(e,t){if(e==="header"){if(t==="west")return this.areaHeaderWest;if(t==="center")return this.areaHeaderCenter;if(t==="east")return this.areaHeaderEast}else if(e==="body"){if(t==="west")return this.areaBodyWest;if(t==="center")return this.areaBodyCenter;if(t==="east")return this.areaBodyEast}else if(e==="footer"){if(t==="west")return this.areaFooterWest;if(t==="center")return this.areaFooterCenter;if(t==="east")return this.areaFooterEast}throw Error(`Wrong area identifier: row:${e}, col:${t}`)}snapToDevicePixel(e){const t=typeof window<"u"&&window.devicePixelRatio||1;return Math.round(e*t)/t}isScrollHeightCapped(){return this.getBodyContentHeight()+1>rs.maxScrollHeightInPx}adjustDetailLayerBounds(e,t,s,o){var i;(i=this.masterDetailService)==null||i.setBounds(e,t,s,o)}getBodyContentHeight(){var t;const e=this.tableModel.getContentHeightInPixel();return(t=this.masterDetailService)!=null&&t.hasExpanded()?e+this.getBodyRowLayout().getExtraTotal():e}getContentScrollRangeY(){return this.getBodyContentHeight()-this.areaBodyCenterGeo.height}getScrollerRangeY(){return this.scrollViewport.scrollHeight-this.scrollViewport.clientHeight}onWheel(e){if(e.ctrlKey||!this.isScrollHeightCapped())return;const t=this.getContentScrollRangeY(),s=this.getScrollerRangeY();if(t<=0||s<=0)return;const o=s/t,i=e.deltaMode===1?16:e.deltaMode===2?this.scrollViewport.clientHeight:1;e.preventDefault(),e.deltaY&&(this.scrollViewport.scrollTop+=e.deltaY*i*o),e.deltaX&&(this.scrollViewport.scrollLeft+=e.deltaX*i)}adjustBody(){const e=this.areaBodyCenterGeo.height-this.getBodyContentHeight(),t=this.snapToDevicePixel(this.scrollFactorY*e);this.contentScrollTop=-t,this.adjustArea("body",t)}getNumberByAttr(e,t){var s;if(e){const o=(s=e.closest("["+t+"]"))==null?void 0:s.getAttribute(t);if(o)return Number(o)}return-1}getStringByAttr(e,t){var s;if(e){const o=(s=e.closest("["+t+"]"))==null?void 0:s.getAttribute(t);if(o)return o}return""}adjustArea(e,t=0){var v,E,S,R,L;const s=this.getArea(e,"west"),o=this.getArea(e,"center"),i=this.getArea(e,"east"),r=((v=this.areaHeightsOfRenderPass)==null?void 0:v[e])??o.child.clientHeight;s.child.innerText="",o.child.innerText="",i.child.innerText="";const l=0,a=this.areaBodyCenterGeo.width,c=this.tableModel.getPadding(),h=this.tableModel.getAreaModel(e),d=h.getRowCount();for(;this.cleanupFunctions[e].length;){const x=this.cleanupFunctions[e].shift();x&&x()}if(e==="header"&&!this.tableModel.isHeaderVisibe()||e==="footer"&&!this.tableModel.isFooterVisibe()){this.updateRowGroupRoles(s,o,i);return}let u=t;const f=this.tableModel.getColumnCount(),g=this.tableModel.getFixedRightColumnCount(),p=this.tableModel.getFixedLeftColumnCount();e==="body"&&(this.firstVisibleRowIndex=-1,this.firstFullVisibleRowIndex=-1,this.lastVisibleRowIndex=-1,this.lastFullVisibleRowIndex=-1);let m=0;const b=e==="body"?this.getBodyRowLayout():void 0,y=!!b&&b.getExtraCount()>0,C=[];if(b)(E=this.masterDetailService)==null||E.startRenderPass(),u<0&&d>0&&(m=b.findIndexAt(-u),u=u+b.getTop(m));else{const x=(S=h.getConstantRowHeight)==null?void 0:S.call(h);if(x!==void 0&&x>0&&u<0){for(m=Math.min(d,Math.floor(-u/x));m>0&&u+m*x>0;)m--;u=u+m*x}}for(let x=m;x<d;x++){const D=u,k=x===d-1,P=this.tableModel.getRowHeight(e,x),V=y?b.getExtraHeight(x):0;if(V>0&&D+P+V>0&&C.push(x,D+P,V),D+P>0){e==="body"&&this.firstVisibleRowIndex===-1&&(this.firstVisibleRowIndex=x,this.firstFullVisibleRowIndex=D<-this.pixelLimitForFullVisible?this.firstVisibleRowIndex+1:this.firstVisibleRowIndex);let $={left:l,width:a,height:P,top:D,index:x},j=this.dom.addRowDiv(o,$,x,e,"center");this.applyRowAria(j,e,h,x);const _e=[j],H=p;this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"center",areaModel:h,geo:$,parent:j,rowIndex:x,columnIndexStart:H,columnIndexEnd:f-g-1,verticalFixed:!1,lastRowOfModel:k}),c.left>0&&($={left:l,width:this.areaBodyWestGeo.width,height:P,top:D,index:x},j=this.dom.addRowDiv(s,$,x,e,"west"),this.applyRowAria(j,e,h,x),_e.push(j),this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"west",areaModel:h,geo:$,parent:j,rowIndex:x,columnIndexStart:0,columnIndexEnd:H-1,verticalFixed:!0,lastRowOfModel:k})),c.right>0&&($={left:l,width:this.areaBodyEastGeo.width,height:P,top:D,index:x},j=this.dom.addRowDiv(i,$,x,e,"east"),this.applyRowAria(j,e,h,x),this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"east",areaModel:h,geo:$,parent:j,rowIndex:x,columnIndexStart:f-g,columnIndexEnd:f-1,verticalFixed:!0,lastRowOfModel:k}));const O=e==="header"&&this.tree&&x===d-1?this.findCellDiv(_e,this.getTreeArrowColumnIndex()):void 0;if(O!=null&&O.parentElement){const ue=this.dom.getInlineStart(O)+16,te=this.dom.applyStyle(this.dom.setAttribute(this.dom.addDiv(O.parentElement,new Ee(ue,20,20,8)),"data-ge-action","toggleExpandCollapseAll"),{cursor:"pointer"}),F=this.tableOptions.treeOptions.arrowExpandCollapseAll;if(F){const Y=this.dom.domService.createText(F.content);this.dom.domService.appendChild(te,Y),F.style&&this.dom.applyStyleString(te,F.style)}}}if(u=u+P+V,u>r){if(e==="body"){const $=u-V;$<=0&&this.firstVisibleRowIndex===-1?this.displayedRowCount=0:(this.lastVisibleRowIndex=x,this.lastFullVisibleRowIndex=r-$<-this.pixelLimitForFullVisible?x-1:x,this.displayedRowCount=this.lastFullVisibleRowIndex-this.firstFullVisibleRowIndex+1)}break}}if(b&&((R=this.masterDetailService)==null||R.layoutVisible(C)),e==="body"&&this.firstVisibleRowIndex>-1&&this.lastVisibleRowIndex===-1&&(this.lastVisibleRowIndex=d-1,this.lastFullVisibleRowIndex=d-1,this.displayedRowCount=this.lastFullVisibleRowIndex-this.firstFullVisibleRowIndex+1),this.loggingActive&&e==="body"&&console.log("render scope: this.firstVisibleRowIndex <- "+this.firstVisibleRowIndex+`
@@ -68,7 +68,7 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
68
68
  `&&n[s]!=="\r";)s++;l=n.slice(c,s)}if(t.push(l),i=!1,s>=o){e.push(t);break}const a=n[s];if(a===" "){if(s++,s===o){t.push(""),e.push(t);break}continue}if(s+=a==="\r"&&n[s+1]===`
69
69
  `?2:1,e.push(t),t=[],i=!0,s>=o)break}i&&e.length===0&&e.push([""]);const r=e.reduce((l,a)=>Math.max(l,a.length),0);for(const l of e)for(;l.length<r;)l.push("");return e}function Ml(n){return`<meta charset="utf-8"><table><tbody>${n.map(t=>"<tr>"+t.map(s=>`<td${s.num!==void 0&&Number.isFinite(s.num)?` x:num="${s.num}"`:""}>${X(s.text).replace(/\r\n|\n|\r/g,"<br>")}</td>`).join("")+"</tr>").join("")}</tbody></table>`}function Tl(n){if(typeof DOMParser>"u")return[];const e=new DOMParser().parseFromString(n,"text/html"),t=e.querySelector("table");if(!t)return[];for(const i of Array.from(t.querySelectorAll("script, style, template, noscript")))i.remove();for(const i of Array.from(t.querySelectorAll("br")))i.replaceWith(e.createTextNode(`
70
70
  `));const s=[];for(const i of Array.from(t.querySelectorAll("tr"))){if(i.closest("table")!==t)continue;const r=[];for(const l of Array.from(i.children)){if(l.tagName!=="TD"&&l.tagName!=="TH")continue;r.push(String(l.textContent).replace(/ /g," ").trim());const a=Math.min(1e3,Math.max(1,Number(l.getAttribute("colspan"))||1));for(let c=1;c<a;c++)r.push("")}s.push(r)}const o=s.reduce((i,r)=>Math.max(i,r.length),0);for(const i of s)for(;i.length<o;)i.push("");return s}function Il(n){const{matrix:e,anchorRow:t,shownColumns:s,rowCount:o}=n,i=e.length,r=e.reduce((C,v)=>Math.max(C,v.length),0),l=s.indexOf(n.anchorColumn),a={cells:[],range:new M(t,n.anchorColumn,t,n.anchorColumn),skipped:0,clipped:0,addRows:0};if(!i||!r||l<0||t<0)return a;const{rows:c,columns:h}=Li(i,r,n.selection),d=s.length-l,u=Math.min(h,d);let f=(h-u)*c;const g=o-t;let p=c,m=0;c>g&&(n.canAddRows?m=c-Math.max(0,g):(p=Math.max(0,g),f+=(c-p)*u));const b=[];let y=0;for(let C=0;C<p;C++){const v=t+C,E=e[C%i];for(let S=0;S<u;S++){const R=s[l+S];if(v<o&&n.isWritable&&!n.isWritable(v,R)){y++;continue}const L=E[S%r]??"";b.push({rowIndex:v,columnIndex:R,value:L})}}return!p||!u?{...a,clipped:f}:{cells:b,range:new M(t,n.anchorColumn,t+p-1,s[l+u-1]),skipped:y,clipped:f,addRows:m}}function Li(n,e,t){return t&&(t.rows>1||t.columns>1)&&n>0&&e>0&&(n===1&&e===1||t.rows%n===0&&t.columns%e===0)?{rows:t.rows,columns:t.columns}:{rows:n,columns:e}}const Tr=n=>n.replace(/\r\n?/g,`
71
- `).replace(/\n$/,"");class Ko{constructor(e,t,s){this.tableScope=e,this.options=t;const o=e.listenerAbortController.signal;if(s){const i=e.hostElement.ownerDocument;i.addEventListener("copy",r=>this.onClipboardEvent(r,"copy"),{signal:o}),i.addEventListener("cut",r=>this.onClipboardEvent(r,"cut"),{signal:o}),i.addEventListener("paste",r=>this.onClipboardEvent(r,"paste"),{signal:o})}e.hostElement.addEventListener("keydown",i=>{var r;i.key==="Escape"&&((r=this.memory)!=null&&r.cut)&&i.target===e.hostElement&&!e.isEditing()&&this.cancelCut()},{signal:o}),e.subscribe({onModelChanged:i=>{var r;i.source!=="cut"&&((r=this.memory)!=null&&r.cut)&&this.cancelCut()}})}isCutMarked(){var e;return!!((e=this.memory)!=null&&e.cut)}arm(e){const t=this.tableScope;if(t.isEditing()||t.getHeaderFocus()||!t.getActiveBodyCell()||e!=="paste"&&!this.hasBuiltInCopyService()||e!=="copy"&&t.isOverlayBlocking())return!1;const s=this.ensureProxy();return s.value=" ",s.select(),s.focus({preventScroll:!0}),this.armedKind=e,clearTimeout(this.restoreTimer),this.restoreTimer=setTimeout(()=>this.restoreFocus(),0),!0}getSelectionAsText(){var e;return((e=this.buildCopy(!1))==null?void 0:e.text)??""}async writeSelection(e){const t=this.buildCopy(e);if(!t)return;const s=typeof navigator<"u"?navigator.clipboard:void 0,o=globalThis.ClipboardItem;if(s!=null&&s.write&&o&&t.html)await s.write([new o({"text/plain":new Blob([t.text],{type:"text/plain"}),"text/html":new Blob([t.html],{type:"text/html"})})]);else if(s!=null&&s.writeText)await s.writeText(t.text);else return;this.remember(t,e)}async runWithoutKey(e){var t,s;try{if(e==="paste"){const o=await((s=(t=navigator.clipboard)==null?void 0:t.readText)==null?void 0:s.call(t));o&&this.paste(o)}else await this.writeSelection(e==="cut")}catch(o){console.warn("GuiExpert Table – clipboard:",o)}}paste(e,t,s){var j,_e;const o=this.tableScope,i=e?El(e):t?Tl(t):[];if(!i.length||!i[0].length)return[];const r=this.memory&&e&&Tr(e)===this.memory.text?this.memory:void 0,l=r==null?void 0:r.cut,a=o.tableModel.getBodyModel(),c=a.getRowCount(),h=this.getPasteColumns(),d=this.getPasteAnchor(h,s);if(!d||!h.length)return[];const[u,f]=d,g=l?void 0:d[2],p=i[0].length,m=h.indexOf(f),b=h[Math.min(h.length-1,m+p-1)],y=o.isBatchEditActive();let C=r&&!y?r.values:r?i.map((H,O)=>H.map((ue,te)=>{var F;return((F=r.values[O])==null?void 0:F[te])instanceof Jt?r.values[O][te]:ue})):i,v=!!r&&!y;const E=this.options.processPaste;if(E){const H={text:e,html:t,matrix:i,target:new M(u,f,u+i.length-1,b),internal:!!r},O=E(H);if(O===!1)return[];Array.isArray(O)&&(C=O,v=!1)}const S=this.options.maxPasteCells,R=Li(C.length,C.reduce((H,O)=>Math.max(H,O.length),0),g);if(R.rows*R.columns>S)return o.announce(o.getSheetTexts().pasteTooLarge(S)),[];const L=this.options.pasteAddsRows&&!!this.options.createRow&&!y&&this.canAppendRows(),x=((_e=(j=o.tableModel).getColumnDefs)==null?void 0:_e.call(j))??[],D=Il({matrix:C,anchorRow:u,anchorColumn:f,shownColumns:h,rowCount:c,selection:g,canAddRows:L,isWritable:(H,O)=>a.isEditable(H,O)&&!N(x[O])});if(D.addRows&&this.appendRows(D.addRows),r)for(const H of D.cells)H.value=o.resolvePastedValue(H.value,H.rowIndex,H.columnIndex,!!l);const k=[];let P="paste";if(l){P="cut";const H=new Map(h.map((te,F)=>[te,F])),O=[],ue=new Set;for(const{rowIndex:te,columnIndex:F,value:Y}of D.cells){const Vt=v?Y:this.convertPastedText(Y,te,F);o.checkPastedValue(te,F,Vt,v)||(k.push({rowIndex:te,column:F,value:Vt}),O.push([te-u,H.get(F)-m]),ue.add(`${te}:${F}`))}for(const te of this.cutSourceChanges(l,O,ue))k.push(te)}else for(const{rowIndex:H,columnIndex:O,value:ue}of D.cells)k.push({rowIndex:H,column:O,value:v?ue:this.convertPastedText(ue,H,O)});const V=k.length?o.writePastedCells(k,P,v):[];l&&(this.memory=void 0,this.removeCutFrame()),D.addRows&&o.repaintHard();let $=V.length;if(l){const H=new Set(D.cells.map(O=>`${O.rowIndex}:${O.columnIndex}`));$=V.filter(O=>H.has(`${O.rowIndex}:${O.columnIndex}`)).length}return o.selectBodyRange(D.range),o.announce(o.getSheetTexts().cellsPasted($,D.skipped+D.clipped+Math.max(0,D.cells.length-$))),V}cancelCut(){var e;(e=this.memory)!=null&&e.cut&&(this.memory={...this.memory,cut:void 0}),this.removeCutFrame()}update(){var u;const e=(u=this.memory)==null?void 0:u.cut,t=this.cutFrame;if(!e||!t)return;const s=this.tableScope,o=s.tableModel.getBodyModel(),{range:i}=e;if(i.r2>=o.getRowCount()||this.rowObjectAt(i.r1)!==e.rows[0]||this.rowObjectAt(i.r2)!==e.rows[e.rows.length-1]){this.removeCutFrame();return}const r=s.getBodyCellRectInHost(i.r1,i.c1),l=s.getBodyCellRectInHost(i.r2,i.c2),a=Math.max(r.top,r.clipTop),c=Math.min(l.top+l.height,l.clipBottom),h=Math.max(r.left,r.clipLeft),d=Math.min(l.left+l.width,l.clipRight);s.getDomService().applyStyle(t,{display:c>a&&d>h?"block":"none",left:`${h}px`,top:`${a}px`,width:`${Math.max(0,d-h)}px`,height:`${Math.max(0,c-a)}px`})}destroy(){var e;clearTimeout(this.restoreTimer),(e=this.proxy)==null||e.remove(),this.proxy=void 0,this.removeCutFrame(),this.memory=void 0}onClipboardEvent(e,t){var a;const s=this.tableScope,o=s.hostElement,i=typeof e.composedPath=="function"?e.composedPath()[0]:e.target,r=!!this.proxy&&i===this.proxy;if(!r&&(Ir(o)!==o||s.isEditing()||(a=s.isEventInDetail)!=null&&a.call(s,e))||!r&&(s.getHeaderFocus()||!s.getActiveBodyCell())||t!=="paste"&&!this.hasBuiltInCopyService())return;const l=e.clipboardData;try{if(!l||(e.preventDefault(),t!=="copy"&&s.isOverlayBlocking()))return;if(t==="paste")this.paste(l.getData("text/plain"),l.getData("text/html")||void 0);else{const c=this.buildCopy(t==="cut");c&&(l.setData("text/plain",c.text),c.html&&l.setData("text/html",c.html),this.remember(c,t==="cut"))}}finally{(r||this.armedKind)&&this.restoreFocus()}}restoreFocus(){clearTimeout(this.restoreTimer),this.armedKind=void 0;const e=this.proxy;e&&(e.value="",Ir(e)===e&&this.tableScope.hostElement.focus({preventScroll:!0}))}ensureProxy(){if(!this.proxy||!this.proxy.isConnected){const e=this.tableScope.getDomService().domService,t=e.createElement("textarea");e.addClass(t,"ge-table-clipboard-proxy"),e.setAttribute(t,"aria-hidden","true"),e.setAttribute(t,"tabindex","-1"),e.setAttribute(t,"autocomplete","off"),e.appendChild(this.tableScope.hostElement,t),this.proxy=t}return this.proxy}remember(e,t){var r;const s=this.tableScope;this.cancelCut(),this.memory=e.processed?void 0:{text:Tr(e.text),values:e.values,cut:t?{range:e.range,columns:e.columns,rows:this.rowObjectsOf(e.range)}:void 0},(r=this.memory)!=null&&r.cut&&this.showCutFrame();const o=s.getSheetTexts(),i=t?o.cutMarked(e.cellCount):s.ariaTexts.copied(e.cellCount);s.announce(e.lastRangeOnly?`${i}. ${o.copiedLastRangeOnly()}`:i)}buildCopy(e){var E;const t=this.tableScope,s=t.tableModel,o=s.getBodyModel(),i=o.getRowCount(),r=s.getColumnCount();if(!i||!r)return;const l=t.selectionModel();let a,c=!1;if(l!=null&&l.isAllSelected())a=new M(0,0,i-1,r-1);else if(l!=null&&l.hasSelection()&&l.getRanges().length){const S=l.getRanges(),R=S[S.length-1];c=S.length>1,a=new M(Math.max(0,R.r1),Math.max(0,R.c1),Math.min(i-1,R.r2),Math.min(r-1,R.c2))}else{const S=t.getActiveBodyCell();a=S?M.singleCell(S[0],S[1]):void 0}if(!a||a.r2<a.r1||a.c2<a.c1)return;const h=[];for(let S=a.c1;S<=a.c2;S++){const R=s.getColumnDef(S);((E=R==null?void 0:R.isVisible)==null?void 0:E.call(R))===!1||s.getColumnWidth(S)<=0||N(R)&&!R.options.exported||h.push(S)}const d=(a.r2-a.r1+1)*h.length;if(!h.length)return;if(d>Se.maxCopyCells){t.announce(t.getSheetTexts().copyTooLarge(Se.maxCopyCells));return}const u=this.options.copyValue==="raw",f=!!(l!=null&&l.hasSelection())&&!l.isAllSelected(),g=[],p=[],m=[];if(this.options.copyHeaders&&!e){const S=h.map(R=>t.getColumnAriaLabel(R));g.push(S),p.push(S),m.push(S.map(R=>({text:R})))}for(let S=a.r1;S<=a.r2;S++){const R=[],L=[],x=[];for(const D of h){const k=s.getColumnDef(D);let P,V;if(f&&!l.isSelected(S,D))P="",V="";else if(N(k))P=k.getRowNumberText(S,o),V=P;else{V=t.getCopyValue(S,D);const j=V instanceof Jt?V.value:V;P=u||j===null||j===void 0||j instanceof Date?kh(j):o.getTextValueAt(S,D)}R.push(P),L.push(V);const $=V instanceof Jt?V.value:V;x.push(typeof $=="number"?{text:P,num:$}:{text:P})}g.push(R),p.push(L),m.push(x)}let b=g,y=!1;if(this.options.processCopy){const S=this.options.processCopy({ranges:[a],matrix:g,cut:e});Array.isArray(S)&&(b=S,y=!0)}const C=Al(b),v=this.options.html?Ml(y?b.map(S=>S.map(R=>({text:R}))):m):void 0;return{text:C,html:v,values:p,range:a,columns:h,cellCount:d,lastRangeOnly:c,processed:y}}getPasteColumns(){var o;const e=this.tableScope.tableModel,t=[],s=e.getColumnCount();for(let i=0;i<s;i++){const r=e.getColumnDef(i);e.getColumnWidth(i)>0&&((o=r==null?void 0:r.isVisible)==null?void 0:o.call(r))!==!1&&!N(r)&&t.push(i)}return t}getPasteAnchor(e,t){const s=this.tableScope,o=s.tableModel.getBodyModel().getRowCount(),i=h=>e.find(d=>d>=h);if(t){const h=i(t[1]);return h===void 0||t[0]<0||t[0]>=o?void 0:[t[0],h,void 0]}const r=s.selectionModel();let l;if(r!=null&&r.isAllSelected())l=new M(0,0,o-1,Number.MAX_SAFE_INTEGER);else if(r!=null&&r.hasSelection()&&r.getRanges().length){const h=r.getRanges();l=h[h.length-1]}if(l){const h=Math.max(0,l.r1),d=Math.min(o-1,l.r2),u=i(Math.max(0,l.c1));if(u!==void 0&&d>=h){const f=e.filter(g=>g>=l.c1&&g<=l.c2).length;return[h,u,{rows:d-h+1,columns:f}]}}const a=s.getActiveBodyCell();if(!a)return;const c=i(a[1]);return c===void 0?void 0:[a[0],c,void 0]}convertPastedText(e,t,s){if(typeof e!="string")return e;const o=this.tableScope,i=o.tableModel.getColumnDef(s);if(i!=null&&i.editInputPipe)return e;const r=t<o.tableModel.getBodyModel().getRowCount()?o.getTypedCellValue(t,s):void 0,l=e.trim();if(typeof r=="number"||(i==null?void 0:i.editor)==="number")return l!==""&&/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(l)?Number(l):e;if(typeof r=="boolean"){const a=l.toUpperCase();return a==="TRUE"?!0:a==="FALSE"?!1:e}if(r instanceof Date){const a=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/.exec(l);return a?a[4]===void 0?new Date(+a[1],+a[2]-1,+a[3],r.getHours(),r.getMinutes(),r.getSeconds()):new Date(+a[1],+a[2]-1,+a[3],+a[4],+a[5],+(a[6]??0)):e}return e}cutSourceChanges(e,t,s){var a;const o=this.tableScope,i=o.tableModel.getBodyModel(),r=this.rowIndexLookup(e),l=[];for(const[c,h]of t){if(c<0||h<0||c>=e.rows.length||h>=e.columns.length)continue;const d=r(c);if(d<0)continue;const u=e.columns[h],f=o.tableModel.getColumnDef(u);if(s.has(`${d}:${u}`)||N(f)||!i.isEditable(d,u))continue;const g=(f==null?void 0:f.emptyValue)!==void 0?f.emptyValue:((a=o.getEditingOptions())==null?void 0:a.emptyValue)??"";l.push({rowIndex:d,column:u,value:g})}return l}rowIndexLookup(e){const t=this.tableScope.tableModel.getBodyModel().getRowCount(),s=e.rows.every(r=>r!==null&&typeof r=="object"),o=e.rows.every((r,l)=>this.rowObjectAt(e.range.r1+l)===r);if(!s||o)return r=>e.range.r1+r<t?e.range.r1+r:-1;const i=new Map;for(let r=0;r<t;r++)i.set(this.rowObjectAt(r),r);return r=>i.get(e.rows[r])??-1}hasBuiltInCopyService(){const e=this.tableScope.copyService;return!!e&&Object.getPrototypeOf(e)===Se.prototype}rowObjectAt(e){const t=this.tableScope.tableModel.getBodyModel().getRowByIndex(e);return U(t)?t.data:t}rowObjectsOf(e){const t=[];for(let s=e.r1;s<=e.r2;s++)t.push(this.rowObjectAt(s));return t}canAppendRows(){const e=this.tableScope.tableModel.getBodyModel();return typeof e.getAllRows=="function"&&typeof e.getFilteredRows=="function"&&!this.tableScope.isRowGroupingOrTree()}appendRows(e){const t=this.tableScope.tableModel.getBodyModel(),s=t.getAllRows(),o=t.getFilteredRows(),i=o.length;for(let r=0;r<e;r++){const l=this.options.createRow(i+r);s.push(l),o!==s&&o.push(l)}this.tableScope.rowsAppended()}showCutFrame(){if(!this.cutFrame){const e=this.tableScope.getDomService();this.cutFrame=e.setAriaHidden(e.createDivWithClass("ge-table-cut-range",this.tableScope.hostElement))}this.update()}removeCutFrame(){var e;(e=this.cutFrame)==null||e.remove(),this.cutFrame=void 0}}function Ir(n){return n.getRootNode().activeElement??null}function kh(n){if(n==null)return"";if(n instanceof Date){if(Number.isNaN(n.getTime()))return"";const e=o=>String(o).padStart(2,"0"),t=`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())}`,s=n.getHours()||n.getMinutes()||n.getSeconds()?`T${e(n.getHours())}:${e(n.getMinutes())}:${e(n.getSeconds())}`:"";return t+s}return typeof n=="boolean"?n?"TRUE":"FALSE":typeof n=="object"?"":String(n)}function Dl(n){return n?{"meta+z":"UNDO","meta+shift+z":"REDO"}:{"ctrl+z":"UNDO","ctrl+y":"REDO","ctrl+shift+z":"REDO"}}class uo{constructor(){this.maxSteps=100,this.maxCells=1e6,this.onConflict="skip",this.recordApiChanges=!1}static create(e){if(!e)return;const t=new uo;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class kl{constructor(e,t){this.maxSteps=e,this.maxCells=t,this.undoSteps=[],this.redoSteps=[],this.cells=0}push(e){if(this.clearRedo(),e.cellCount>this.maxCells||this.maxSteps<1)return this.clear(),!1;for(this.undoSteps.push(e),this.cells+=e.cellCount;this.undoSteps.length>this.maxSteps||this.cells>this.maxCells;)this.cells-=this.undoSteps.shift().cellCount;return!0}undo(){const e=this.undoSteps.pop();return e&&this.redoSteps.push(e),e}redo(){const e=this.redoSteps.pop();return e&&this.undoSteps.push(e),e}peekUndo(){return this.undoSteps[this.undoSteps.length-1]}peekRedo(){return this.redoSteps[this.redoSteps.length-1]}canUndo(){return this.undoSteps.length>0}canRedo(){return this.redoSteps.length>0}size(){return this.undoSteps.length}cellCount(){return this.cells}clear(){this.undoSteps.length=0,this.redoSteps.length=0,this.cells=0}clearRedo(){for(const e of this.redoSteps)this.cells-=e.cellCount;this.redoSteps.length=0}}function Fl(n){var t,s;const e=n;return Z(n)?e.rows:((t=e.getAllRows)==null?void 0:t.call(e))??((s=e.getSourceRows)==null?void 0:s.call(e))??e.arr}function Fh(n){if(Z(n)){const t=new Set,s=o=>o==null?void 0:o.forEach(i=>{const r=i;t.add(r.data??r),s(r.children)});return s(n.rows),t}const e=Fl(n);return e?new Set(e):null}class jo{constructor(e,t,s){this.label=e,this.source=t,this.entries=s.map(o=>({row:o.row,rowIndex:o.rowIndex,columnIndex:o.columnIndex,property:o.property,oldValue:o.oldValue,newValue:o.newValue}))}get cellCount(){return this.entries.length}append(e){for(const t of e)this.entries.push({row:t.row,rowIndex:t.rowIndex,columnIndex:t.columnIndex,property:t.property,oldValue:t.oldValue,newValue:t.newValue})}undo(e){return this.apply(e,"undo")}redo(e){return this.apply(e,"redo")}apply(e,t){var C;const s=e.tableModel,o=s.getBodyModel(),i=o.getRowCount(),r=((C=e.getUndoOptions())==null?void 0:C.onConflict)==="overwrite",l=v=>{const E=o.getRowByIndex(v);return U(E)?E.data:E};let a,c;const h=v=>{if(v.row===void 0||v.row===null||typeof v.row!="object")return v.rowIndex>=0&&v.rowIndex<i?v.rowIndex:-1;if(v.rowIndex>=0&&v.rowIndex<i&&l(v.rowIndex)===v.row)return v.rowIndex;if(!a){a=new Map;for(let E=0;E<i;E++)a.set(l(E),E)}return a.get(v.row)??-1},d=v=>(c===void 0&&(c=Fh(o)),!!c&&c.has(v)),u=v=>{var E;return!!v&&(zr(v)?!!o.defaultEditable:!!((E=v.editable)!=null&&E.call(v)))},f=[],g=[];let p=0;const m=t==="undo"?[...this.entries].reverse():this.entries;for(const v of m){const E=t==="undo"?v.newValue:v.oldValue,S=t==="undo"?v.oldValue:v.newValue,R=Lh(e,v);if(R<0){p++;continue}const L=h(v);if(L>=0){if(!o.isEditable(L,R)||!r&&!Dt(e.getCellInput(L,R),E)){p++;continue}f.push({rowIndex:L,columnIndex:R,value:S});continue}const x=s.getColumnDef(R),D=d(v.row)?Oh(v.row,x,R,E):void 0;if(!d(v.row)||!u(x)||!r&&!Dt(D,E)||!Kn(v.row,x,R,S)){p++;continue}g.push({row:v.row,rowIndex:-1,columnIndex:R,property:v.property,oldValue:D,newValue:S})}const b=e.writeUndoCells(f,g,t);let y;for(const v of b)v.rowIndex<0||(y?(y.r1=Math.min(y.r1,v.rowIndex),y.r2=Math.max(y.r2,v.rowIndex),y.c1=Math.min(y.c1,v.columnIndex),y.c2=Math.max(y.c2,v.columnIndex)):y=new M(v.rowIndex,v.columnIndex,v.rowIndex,v.columnIndex));return{applied:b.length,skipped:p+f.length+g.length-b.length,range:y}}}function Lh(n,e){const t=n.tableModel,s=i=>{var r;return((r=t.getColumnDef(i))==null?void 0:r.property)||`#${i}`};if(e.columnIndex>=0&&e.columnIndex<t.getColumnCount()&&s(e.columnIndex)===e.property)return e.columnIndex;const o=t.getColumnCount();for(let i=0;i<o;i++)if(s(i)===e.property)return i;return-1}function Oh(n,e,t,s){if(Array.isArray(n))return n[t];if(!(e!=null&&e.property)||n===null||typeof n!="object")return;if(e.valueGetter)return s;let o=n;for(const i of e.property.split("."))o=o==null?void 0:o[i];return o}class Ll{constructor(e,t,s){this.label=e,this.source=t,this.cells=s}get cellCount(){return this.cells.length}undo(e){return this.apply(e,"undo")}redo(e){return this.apply(e,"redo")}apply(e,t){var c;const s=e.batchEditService;if(!s)return{applied:0,skipped:this.cells.length};const o=((c=e.getUndoOptions())==null?void 0:c.onConflict)==="overwrite",i=[];let r=0;for(const h of this.cells){const d=t==="undo"?h.after:h.before,u=t==="undo"?h.before:h.after,f=s.getPendingEntry(h.rowKey,h.property);if(!(!f&&!d?!0:!!f&&!!d&&Dt(f.newValue,d.newValue))&&!o){r++;continue}i.push({rowKey:h.rowKey,property:h.property,entry:u})}const l=s.restorePending(i,!1);let a;for(const h of l)h.rowIndex<0||h.columnIndex<0||(a=a?new M(Math.min(a.r1,h.rowIndex),Math.min(a.c1,h.columnIndex),Math.max(a.r2,h.rowIndex),Math.max(a.c2,h.columnIndex)):new M(h.rowIndex,h.columnIndex,h.rowIndex,h.columnIndex));return e.repaint(),{applied:l.length,skipped:r,range:a}}}class Ol{constructor(e,t,s,o,i){this.canUndo=e,this.canRedo=t,this.undoLabel=s,this.redoLabel=o,this.size=i}}const Dr={edit:"Edit",fill:"Fill",paste:"Paste",cut:"Cut",clear:"Clear",api:"Change"};class Nh{constructor(e,t){this.label=e,this.steps=t,this.source=t[0].source}get cellCount(){return this.steps.reduce((e,t)=>e+t.cellCount,0)}undo(e){return kr([...this.steps].reverse().map(t=>t.undo(e)))}redo(e){return kr(this.steps.map(t=>t.redo(e)))}}function kr(n){let e;for(const t of n)t.range&&(e=e?new M(Math.min(e.r1,t.range.r1),Math.min(e.c1,t.range.c1),Math.max(e.r2,t.range.r2),Math.max(e.c2,t.range.c2)):t.range);return{applied:n.reduce((t,s)=>t+s.applied,0),skipped:n.reduce((t,s)=>t+s.skipped,0),range:e}}class Nl{constructor(e,t){this.tableScope=e,this.options=t,this.running=!1,this.foldDepth=0,this.stack=new kl(t.maxSteps,t.maxCells)}addStep(e){this.running||this.add(e)}record(e,t,s){if(this.running||t==="undo"||t==="redo"||!e.length||s===!1)return;if(this.folding instanceof jo&&t!=="commit"){this.folding.append(e),this.lastRecorded=this.folding;return}if(t==="commit"){this.clear();return}if(t==="api"&&!(s??this.options.recordApiChanges))return;const o=new jo(Dr[t]??"Change",t,e);this.lastRecorded=o,this.add(o)}beginFold(){this.foldDepth++===0&&(this.folding=this.lastRecorded)}endFold(){--this.foldDepth<=0&&(this.foldDepth=0,this.folding=void 0,this.lastRecorded=void 0)}recordPending(e,t,s){this.running||!e.length||s===!1||t==="api"&&!(s??this.options.recordApiChanges)||this.add(new Ll(Dr[t]??"Change",t,e))}batch(e,t){this.group?this.group.depth++:this.group={label:e,steps:[],depth:1};let s=!0;try{const o=t();return s=!1,o}finally{const o=this.group;--o.depth===0&&(this.group=void 0,o.steps.length&&!s&&this.add(o.steps.length===1&&o.steps[0].label===o.label?o.steps[0]:new Nh(o.label,o.steps)))}}undo(){return this.run("undo")}redo(){return this.run("redo")}canUndo(){return this.checkRows(!1),this.stack.canUndo()}canRedo(){return this.checkRows(!1),this.stack.canRedo()}getState(){var e,t;return this.checkRows(!1),new Ol(this.stack.canUndo(),this.stack.canRedo(),(e=this.stack.peekUndo())==null?void 0:e.label,(t=this.stack.peekRedo())==null?void 0:t.label,this.stack.size())}clear(e=!1){const t=this.stack.canUndo()||this.stack.canRedo();this.stack.clear(),this.rowsRef=void 0,this.lastRecorded=void 0,this.group&&(this.group.steps.length=0),t&&!e&&this.fire()}add(e){if(this.group){this.group.steps.push(e);return}if(this.checkRows(),this.rowsRef??(this.rowsRef=this.currentRows()),!this.stack.push(e)){const t=this.tableScope;t.announce(t.getUndoTexts().undoHistoryCleared(this.options.maxCells))}this.fire()}run(e){const t=this.tableScope;if(t.isEditing()||this.group)return!1;this.checkRows();const s=e==="undo"?this.stack.undo():this.stack.redo(),o=t.getUndoTexts();if(!s)return t.announce(e==="undo"?o.nothingToUndo():o.nothingToRedo()),!1;let i;this.running=!0;try{i=e==="undo"?s.undo(t):s.redo(t)}finally{this.running=!1}i.range&&(t.selectBodyRange(i.range),t.ensureColumnIsVisible(i.range.c1),t.ensureRowIsVisible(i.range.r1));const r=e==="undo"?o.undone(s.label,i.applied):o.redone(s.label,i.applied);return t.announce(i.skipped?`${r}. ${o.undoSkipped(i.skipped)}`:r),this.fire(),!0}checkRows(e=!0){this.rowsRef&&this.currentRows()!==this.rowsRef&&this.clear(!e)}currentRows(){return Fl(this.tableScope.tableModel.getBodyModel())}fire(){var e,t;(t=(e=this.tableScope.getEventListener()).onUndoStackChanged)==null||t.call(e,this.getState())}}function Pl(n,e,t,s,o,i,r,l=()=>!0){const a=(d,u)=>{const f=d+i;let g=u+r;for(;r!==0&&g>=0&&g<t&&!l(g);)g+=r;return f>=0&&f<e&&g>=0&&g<t?[f,g]:void 0};let c=a(s,o);if(!c)return[s,o];if(!n(s,o)&&!n(c[0],c[1])){let d=c;for(let u=a(d[0],d[1]);u&&!n(u[0],u[1]);u=a(u[0],u[1]))d=u;return d}let h=c;for(;n(c[0],c[1]);){const d=a(c[0],c[1]);if(!d)return h;h=c=d}return c}function Ph(n,e){return new Proxy(n,{get(t,s,o){const i=Reflect.get(t,s,o);return typeof s!="string"||!s.startsWith("on")||!e.size?i:(...r)=>{const l=typeof i=="function"?i.apply(t,r):void 0;for(const a of Array.from(e)){const c=a[s];if(typeof c=="function")try{c.apply(a,r)}catch(h){console.error(h)}}return l}}})}function Ze(n,e){const t=n==null?void 0:n[e],s=n==null?void 0:n.spreadsheet;if(t!==void 0||!s)return t;const o=typeof s=="object"?s[e]:void 0;if(o!==!1)return e==="editing"?{defaultEditable:!0,...typeof o=="object"?o:{}}:o??!0}function Vh(n){if(!(n!=null&&n.spreadsheet))return n;const e={...n};for(const t of["editing","clipboard","undo","cellFormulas","fillHandle"])e[t]=Ze(n,t);return e}class Vl{constructor(e=[],t=[]){this.removed=e,this.inserted=t,this.insertBefore=new Int32Array(t.length);for(let s=0;s<t.length;s++)this.insertBefore[s]=t[s]-s}isEmpty(){return this.removed.length===0&&this.inserted.length===0}getRemovedCount(){return this.removed.length}getInsertedCount(){return this.inserted.length}touchesUpTo(e){return this.removed.length&&this.removed[0]<=e?!0:this.insertBefore.length>0&&this.insertBefore[0]<=e}mapIndex(e){if(e<0)return-1;const t=ys(this.removed,e);if(t<this.removed.length&&this.removed[t]===e)return-1;const s=e-t;return s+Mo(this.insertBefore,s)}mapIndexOrNext(e){const t=Math.max(0,e-ys(this.removed,e));return t+Mo(this.insertBefore,t)}mapRange(e,t){e>t&&([e,t]=[t,e]);const s=t>=Number.MAX_SAFE_INTEGER,o=e-ys(this.removed,e),i=s?Number.MAX_SAFE_INTEGER:t-ys(this.removed,t+1);if(i<o)return[];const r=[];let l=o,a=Mo(this.insertBefore,o);for(let c=a;c<this.insertBefore.length&&this.insertBefore[c]<=i;c++){const h=this.insertBefore[c];h>l&&(r.push([l+a,h-1+a]),l=h),a++}return r.push([l+a,s?Number.MAX_SAFE_INTEGER:i+a]),r}}function ys(n,e){let t=0,s=n.length;for(;t<s;){const o=t+s>>>1;n[o]<e?t=o+1:s=o}return t}function Mo(n,e){let t=0,s=n.length;for(;t<s;){const o=t+s>>>1;n[o]<=e?t=o+1:s=o}return t}class fo{constructor(){this.doubleClick=!0,this.maxRows=1e4}static create(e){return{...new fo,...e??{}}}}const Gi=class Gi{constructor(e){this.ctx=null;const t=e.querySelector(".ge-table-label"),s=getComputedStyle(t??e);this.padding=t?(parseFloat(s.paddingLeft)||0)+(parseFloat(s.paddingRight)||0):20;try{this.ctx=document.createElement("canvas").getContext("2d")}catch{this.ctx=null}this.ctx&&(this.ctx.font=s.font||`${s.fontSize} ${s.fontFamily}`)}measureText(e){const t=this.ctx?this.ctx.measureText(e).width:e.length*8;return Math.ceil(t+this.padding+2)}measureWidest(e){let t=this.measureText("");return e.forEach(s=>{t=Math.max(t,this.measureText(s))}),Math.max(t,50)}};Gi.maxCandidates=30;let ot=Gi;function _h(n,e,t,s,o,i){var l,a;if(!n)return;const r=ot.maxCandidates;for(let c=e;c<=t;c++)for(let h=0;h<s.length;h++){const d=s[h],u=((l=n.getTextValueAt)==null?void 0:l.call(n,c,d))||(((a=n.getValueAt(c,d))==null?void 0:a.toString())??""),f=u.length;f>i[h]&&(i[h]=f,o[h].forEach(g=>{g.length<f-2&&o[h].delete(g)})),f>=i[h]-2&&o[h].size<r&&o[h].add(u)}}class _l{constructor(e,t,s,o,i,r,l,a){this.type=e,this.source=t,this.columnIndex=s,this.columnDef=o,this.property=i,this.oldWidth=r,this.newWidth=l,this.originalEvent=a}}class Bl{constructor(e,t,s,o,i,r,l){this.type=e,this.fromIndex=t,this.toIndex=s,this.columnDef=o,this.property=i,this.columnOrder=r,this.originalEvent=l}get moved(){return this.toIndex!==this.fromIndex}}const Ge=class Ge extends Mn{constructor(e,t,s,o,i,r=new Se,l=new Hn){var u;if(super(e,t,new As(s),o),this.eventListener=i,this.copyService=r,this.excelService=l,this.licenseManager=Qe.getInstance(),this.listenerAbortController=new AbortController,this.destroyed=!1,this.selectionService=new fe(this),this.api=new mn(this),this.initialized=!1,this.mouseStartAction="",this.mouseStartWidth=-1,this.mouseStartColumnIndex=-1,this.dragFrom=-1,this.dragTo=-1,this.lastDragFrom=-1,this.lastDragTo=-1,this.firstDraggingRendering=!0,this.editingOptions=lo.create(Ze(this.tableOptions,"editing")),this.subscribers=new Set,this.clipboardOptions=ls.create(Ze(this.tableOptions,"clipboard")),this.undoOptions=uo.create(Ze(this.tableOptions,"undo")),this.lastTabKeyTime=0,this.lastContextmenu=Date.now(),this.allExpanded=!0,this.selectionEventsHeld=0,t.setTableScope(this),this.liveAnnouncer=new Fs(e.ownerDocument,this.ariaIds.liveRegion(),s),this.eventListener=Ph(i??new Yt,this.subscribers),this.stateService=new ks(this),this.mouseHandler=new Wr(this),this.inputHandler=new Fn(this),this.resizeHandler=new $n(this,o.resizeEventDebounceDelay),this.shortcutService=new Vn(this),this.rowDragService=new Wn(this),this.batchEditService=new jn(this),this.fillHandleService=new il(this),this.editingOptions){this.cellEditorService=new gl(this,this.editingOptions);const f=t.getBodyModel();this.editingOptions.defaultEditable&&"defaultEditable"in f&&(f.defaultEditable=!0),this.setHostAriaAttribute("aria-description",this.getSheetTexts().gridEditingHint())}this.clipboardOptions&&(this.clipboardService=new Ko(this,this.clipboardOptions,!0)),this.undoOptions&&(this.undoService=new Nl(this,this.undoOptions));const a=kt.create(Ze(o,"cellFormulas"));if(a&&(o.masterDetail?console.warn("GuiExpert Table – cellFormulas: no cell formulas with master/detail."):this.tableSheet=ho.create(t,a)),o!=null&&o.masterDetail&&(this.masterDetailService=new rl(this,(f,g,p,m)=>new Ge(f,g,new $o,this.nestedTableOptions(p),m??new Yt)),this.masterDetailService.isActive())){const f=(e.getAttribute("aria-owns")??"").split(" ").filter(Boolean),g=f.findIndex(p=>p.startsWith(this.ariaIds.rowGroup("footer","west")));f.splice(g<0?f.length:g,0,this.ariaIds.detailRowGroup()),this.setHostAriaAttribute("aria-owns",f.join(" ")),this.setHostAriaAttribute("role","treegrid")}this.shortcutService.addListener(this.selectionService);const c=this.getSelectionModel?this.getSelectionModel():void 0;c&&c.addEventSelectionChangedListener(this);const h=this.getFocusModel?this.getFocusModel():void 0;h&&h.addEventFocusChangedListener(this);const d=this.listenerAbortController.signal;(u=e.ownerDocument)==null||u.addEventListener("keydown",f=>{f.key==="Tab"&&(this.lastTabKeyTime=Date.now())},{capture:!0,signal:d}),e.addEventListener("focus",()=>this.onHostKeyboardFocus(),{signal:d}),this.scrollViewport.addEventListener("focus",()=>this.hostElement.focus({preventScroll:!0}),{signal:d})}nestedTableOptions(e){return e?e.direction!==void 0||!this.isRtl()?e:Object.assign(Object.create(e),{direction:this.direction}):{...new je,direction:this.direction}}onHostKeyboardFocus(){const e=Date.now()-this.lastTabKeyTime<1e3,t=this.focusModel();if(!e||!t||this.headerFocus||this.isEditing())return;const[s,o]=t.getFocus(),i=this.tableModel.getBodyModel().getRowCount();if((s<0||o<0)&&i>0&&this.tableModel.getColumnCount()>0){const r=this.firstFullVisibleRowIndex>=0?this.firstFullVisibleRowIndex:Math.max(0,this.getBodyRowIndexAtY(this.contentScrollTop));this.setFocusCell(r,this.getFirstShownColumnIndex())}else i<1&&this.getAriaGridInfo().headerRowCount>0&&this.tableModel.getColumnCount()>0&&this.setHeaderFocus(this.getAriaGridInfo().headerRowCount-1,this.getFirstShownColumnIndex())}static create(e,t,s=new je,o=new Yt,i=new $o,r=new Se){return new Ge(e,t,i,s,o,r)}onActionTriggered(e){var o;if(!this.headerFocus&&this.tableOverlay.isBlocking()&&Ge.actionsBlockedWhileLoading.includes(e))return!0;if(this.headerFocus){const i=this.onHeaderAction(e);if(i!==void 0)return i}if(e==="FILL_DOWN"||e==="FILL_RIGHT")return!this.headerFocus&&this.fillByKeyboard(e==="FILL_DOWN"?"down":"right");const t=this.onSheetAction(e);if(t!==void 0)return t;if(e==="MOVE_ROW_UP"||e==="MOVE_ROW_DOWN")return!this.headerFocus&&!!((o=this.rowDragService)!=null&&o.moveByKeyboard(e==="MOVE_ROW_UP"?-1:1));if(e==="NAVIGATE_UP"&&this.moveFocusIntoHeader())return!0;const s=this.onBodyNavigation(e);if(s!==void 0)return s;if(e==="NAVIGATE_DOWN"&&this.changeFocusCell(0,1)||e==="NAVIGATE_UP"&&this.changeFocusCell(0,-1)||e==="NAVIGATE_LEFT"&&this.changeFocusCell(-1,0)||e==="NAVIGATE_RIGHT"&&this.changeFocusCell(1,0))return!0;if(e==="START_EDITING"&&this.getFocusModel){const i=this.getFocusModel();if(i){const[r,l]=i.getFocus();this.tableModel.getBodyModel().isEditable(r,l)&&this.startEditing(r,l,"edit","end")}return!0}if(this.undoService&&(e==="UNDO"||e==="REDO"))return e==="UNDO"?this.undoService.undo():this.undoService.redo(),!0;if(this.clipboardService&&this.clipboardOptions&&(e==="COPY_2_CLIPBOARD"||e==="CUT_2_CLIPBOARD"||e==="PASTE_FROM_CLIPBOARD")){const i=e==="COPY_2_CLIPBOARD"?"copy":e==="CUT_2_CLIPBOARD"?"cut":"paste";if(this.shortcutKeyEvent){if(this.clipboardService.arm(i)||i!=="copy")return!1}else if(i!=="copy"||Object.getPrototypeOf(this.copyService)===Se.prototype)return this.clipboardService.runWithoutKey(i),!0}if(e==="COPY_2_CLIPBOARD"){const i=this.getSelectionModel?this.getSelectionModel():void 0,r=this.getFocusModel?this.getFocusModel():void 0;this.copyService.createContent(this.tableModel,i,r).then(l=>this.copyService.copyContent(l).then(()=>this.announceCopied(l))).catch(l=>console.warn("GuiExpert Table – copy to clipboard failed:",l))}return!1}getEditingOptions(){return this.editingOptions}getShortcutLayers(e){const t=[],s=this.editingOptions;if(this.clipboardOptions&&t.push(ml(e)),this.undoOptions&&t.push(Dl(e)),!s)return t;const o=pl(e);return s.tabMoves||(delete o.tab,delete o["shift+tab"]),s.clearKeys||(delete o.delete,delete o.backspace),[o,...t]}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}startEditing(e,t,s="edit",o){var r,l,a;if((r=this.cellEditorService)!=null&&r.handlesColumn(t))return this.cellEditorService.start(e,t,{mode:s,textSelection:o});if(!this.tableModel.getBodyModel().isEditable(e,t))return!1;this.clearSelection(),this.initRenderEditor(e,t);const i=this.getInCellEditorCell();return i&&((a=(l=this.eventListener).onEditingChanged)==null||a.call(l,new yt("start",e,t,s))),!!i}canStartEditing(){var e,t;return!this.isDestroyed()&&!this.headerFocus&&!this.tableOverlay.isBlocking()&&!((e=this.rowDragService)!=null&&e.isDragging())&&!((t=this.fillHandleService)!=null&&t.isFilling())&&!this.editing}getShownCellValue(e,t){return this.batchEditService?this.batchEditService.getShownValue(e,t):this.getCellInput(e,t)}getActiveBodyCell(){const e=this.focusModel();if(!e||this.headerFocus)return;const[t,s]=e.getFocus(),o=this.tableModel.getBodyModel().getRowCount();return t>=0&&s>=0&&t<o&&s<this.tableModel.getColumnCount()?[t,s]:void 0}refreshAfterStructureChange(e){var r,l;const t=this.tableOptions.externalFilterFunction;if(t&&this.tableModel.externalFilterChanged(t),this.reapplySorting(),(r=this.batchEditService)==null||r.pruneOrphans(),e){for(const a of["header","body","footer"])(l=this.colAndRowspanModels[a])==null||l.init();this.firstInit(),this.stateService.markDirty("columns")}this.invalidateAggregates();const s=this.focusModel(),o=this.tableModel.getBodyModel().getRowCount(),i=this.tableModel.getColumnCount();if(s&&o>0&&i>0){const[a,c]=s.getFocus();if(a>=o||c>=i){const h=Math.min(Math.max(0,a),o-1),d=Math.min(Math.max(this.getFirstDataColumnIndex(),c),i-1);s.setFocus(h,d),this.selectionService.collapseTo(h,d)}}this.repaintHard()}nextShownColumn(e,t){return this.getNextShownColumnIndex(e,t,this.tableModel.getColumnCount())}hasShownColumnBeside(e,t){const s=this.getNextShownColumnIndex(e,t,this.tableModel.getColumnCount());return s!==e&&!N(this.tableModel.getColumnDef(s))}moveActiveCell(e,t,s,o){const i=this.focusModel();return i?(i.hasFocus(e,t)||i.setFocus(e,t),this.changeFocusCell(o,s)):!1}getSelectedBodyCells(e){return this.collectSelectedBodyCells(e)}collectSelectedBodyCells(e,t){const s=this.selectionModel();if(!t&&!(s!=null&&s.hasSelection())&&!(s!=null&&s.isAllSelected()))return[];const o=this.tableModel.getBodyModel().getRowCount(),i=this.tableModel.getColumnCount(),r=t??(s.isAllSelected()?[new M(0,0,o-1,i-1)]:s.getRanges()),l=h=>this.tableModel.getColumnWidth(h)>0&&!N(this.tableModel.getColumnDef(h)),a=[],c=r.length>1?new Set:void 0;for(const h of r){const d=Math.max(0,h.r1),u=Math.min(o-1,h.r2),f=Math.max(0,h.c1),g=Math.min(i-1,h.c2);if(u>=d&&g>=f&&(u-d+1)*(g-f+1)>e)return;for(let p=d;p<=u;p++)for(let m=f;m<=g;m++)if(!(!l(m)||!t&&!s.isSelected(p,m))){if(c){const b=p*i+m;if(c.has(b))continue;c.add(b)}if(a.push([p,m]),a.length>e)return}}return a}clearCells(e){var a,c;const t=((a=this.editingOptions)==null?void 0:a.maxClearCells)??Se.maxCopyCells,s=this.collectSelectedBodyCells(t,e);if(!s)return this.announce(this.getSheetTexts().clearTooLarge(t)),-1;if(!s.length&&!e){const h=this.getActiveBodyCell();h&&s.push(h)}const o=this.tableModel.getBodyModel(),i=h=>h==null||h==="",r=[];for(const[h,d]of s){if(h<0||d<0||h>=o.getRowCount()||d>=this.tableModel.getColumnCount()||!o.isEditable(h,d)||i(this.getShownCellValue(h,d)))continue;const u=this.tableModel.getColumnDef(d),f=(u==null?void 0:u.emptyValue)!==void 0?u.emptyValue:((c=this.editingOptions)==null?void 0:c.emptyValue)??"";r.push({rowIndex:h,column:d,value:f})}const l=r.length?this.applyCellChanges(r,"clear"):[];return this.announce(this.getSheetTexts().cellsCleared(l.length)),l.length}commitCellEditor(e,t,s){var l;const o=e.map(([a,c])=>({rowIndex:a,column:c,value:t})),i=this.resolveCellChanges(o,e.length>1);if(!i.length)return{written:0,invalid:0};if((l=this.batchEditService)!=null&&l.isActive())return this.markPending(i.map(a=>({rowIndex:a.rowIndex,column:a.columnIndex,value:a.value})),!0),s?this.debounceRepaint():this.repaint(),{written:i.length,invalid:0};const r=this.writeCellsInternal(i,"edit",{deferRepaint:s});return{written:r.changes.length,invalid:r.invalid,message:r.message}}toggleBooleanCell(e,t){this.applyCellChanges([{rowIndex:e,column:t,value:!this.getShownCellValue(e,t)}],"edit")}getSheetTexts(){const e=this.ariaTexts??{},t=new me;return{editingStarted:s=>(e.editingStarted??t.editingStarted).call(e,s),readOnlyCell:()=>(e.readOnlyCell??t.readOnlyCell).call(e),cellsCleared:s=>(e.cellsCleared??t.cellsCleared).call(e,s),clearTooLarge:s=>(e.clearTooLarge??t.clearTooLarge).call(e,s),rangeSelected:(s,o)=>(e.rangeSelected??t.rangeSelected).call(e,s,o),rowSelected:s=>(e.rowSelected??t.rowSelected).call(e,s),columnSelected:s=>(e.columnSelected??t.columnSelected).call(e,s),gridEditingHint:()=>(e.gridEditingHint??t.gridEditingHint).call(e),cellsPasted:(s,o)=>(e.cellsPasted??t.cellsPasted).call(e,s,o),pasteTooLarge:s=>(e.pasteTooLarge??t.pasteTooLarge).call(e,s),copyTooLarge:s=>(e.copyTooLarge??t.copyTooLarge).call(e,s),cutMarked:s=>(e.cutMarked??t.cutMarked).call(e,s),copiedLastRangeOnly:()=>(e.copiedLastRangeOnly??t.copiedLastRangeOnly).call(e)}}onSheetAction(e){var s,o;const t=this.editingOptions;if(t)switch(e){case"NAVIGATE_NEXT_CELL":case"NAVIGATE_PREVIOUS_CELL":{const i=this.getActiveBodyCell(),r=e==="NAVIGATE_NEXT_CELL"?1:-1;return!i||this.isEditing()||!this.hasShownColumnBeside(i[1],r)||r>0&&((s=this.masterDetailService)!=null&&s.hasTabTarget(i[0]))?!1:this.moveActiveCell(i[0],i[1],0,r)}case"EXTEND_SELECTION_UP":case"EXTEND_SELECTION_DOWN":case"EXTEND_SELECTION_LEFT":case"EXTEND_SELECTION_RIGHT":case"EXTEND_SELECTION_ROW_START":case"EXTEND_SELECTION_ROW_END":case"EXTEND_SELECTION_PAGE_UP":case"EXTEND_SELECTION_PAGE_DOWN":{const i=this.getSelectionExtent();if(!i||this.isEditing())return!1;const[r,l]=i,a=this.tableModel.getBodyModel().getRowCount(),c=this.tableModel.getColumnCount(),h=Math.max(1,this.displayedRowCount-1),d={EXTEND_SELECTION_UP:[Math.max(0,r-1),l],EXTEND_SELECTION_DOWN:[Math.min(a-1,r+1),l],EXTEND_SELECTION_LEFT:[r,this.getNextShownColumnIndex(l,-1,c)],EXTEND_SELECTION_RIGHT:[r,this.getNextShownColumnIndex(l,1,c)],EXTEND_SELECTION_ROW_START:[r,this.getFirstShownDataColumnIndex()],EXTEND_SELECTION_ROW_END:[r,this.getLastShownColumnIndex()],EXTEND_SELECTION_PAGE_UP:[Math.max(0,r-h),l],EXTEND_SELECTION_PAGE_DOWN:[Math.min(a-1,r+h),l]},[u,f]=d[e];return this.extendSelectionTo(u,N(this.tableModel.getColumnDef(f))?l:f)}case"NAVIGATE_DATA_EDGE_UP":case"NAVIGATE_DATA_EDGE_DOWN":case"NAVIGATE_DATA_EDGE_LEFT":case"NAVIGATE_DATA_EDGE_RIGHT":{const i=this.getActiveBodyCell();if(!i||this.isEditing())return!1;const[r,l]=this.dataEdge(i,e);return this.setFocusCell(r,l)}case"EXTEND_TO_DATA_EDGE_UP":case"EXTEND_TO_DATA_EDGE_DOWN":case"EXTEND_TO_DATA_EDGE_LEFT":case"EXTEND_TO_DATA_EDGE_RIGHT":{const i=this.getSelectionExtent();if(!i||this.isEditing())return!1;const[r,l]=this.dataEdge(i,e);return this.extendSelectionTo(r,l)}case"SELECT_ROW":case"SELECT_COLUMN":return this.selectWholeRowsOrColumns(e==="SELECT_ROW");case"CLEAR_CELLS":return!t.clearKeys||this.isEditing()||this.headerFocus?!1:(this.clearCells(),!0);case"CLEAR_AND_EDIT":{if(!t.clearKeys||this.isEditing()||this.headerFocus)return!1;const i=this.getActiveBodyCell(),r=this.collectSelectedBodyCells(1);return i&&r&&((o=this.cellEditorService)!=null&&o.handlesColumn(i[1]))&&this.tableModel.getBodyModel().isEditable(i[0],i[1])?(this.cellEditorService.start(i[0],i[1],{mode:"enter",typedText:""}),!0):(this.clearCells(),!0)}default:return}}getSelectionExtent(){if(!this.headerFocus)return this.selectionService.getExtent()??this.getActiveBodyCell()}getFirstShownDataColumnIndex(){const e=this.getFirstShownColumnIndex();return N(this.tableModel.getColumnDef(e))?this.getNextShownColumnIndex(e,1,this.tableModel.getColumnCount()):e}dataEdge(e,t){const s=t.endsWith("_UP")?-1:t.endsWith("_DOWN")?1:0,o=t.endsWith("_LEFT")?-1:t.endsWith("_RIGHT")?1:0;return Pl((r,l)=>{const a=this.getShownCellValue(r,l);return a==null||a===""},this.tableModel.getBodyModel().getRowCount(),this.tableModel.getColumnCount(),e[0],e[1],s,o,r=>this.tableModel.getColumnWidth(r)>0&&!N(this.tableModel.getColumnDef(r)))}extendSelectionTo(e,t){const s=this.selectionService.extendTo(e,t);if(!s)return!1;this.ensureColumnIsVisible(t),this.ensureRowIsVisible(e),this.repaint();let o=0;for(let i=s.c1;i<=s.c2;i++)this.tableModel.getColumnWidth(i)>0&&o++;return this.announce(this.getSheetTexts().rangeSelected(s.r2-s.r1+1,o)),!0}selectWholeRowsOrColumns(e){const t=this.selectionModel(),s=this.getActiveBodyCell();if(!t||!s||this.isEditing()||t.selectionType!=="range")return!1;const o=t.getRanges(),i=o.length?o[o.length-1]:M.singleCell(s[0],s[1]),r=e?new M(i.r1,0,i.r2,Number.MAX_SAFE_INTEGER):new M(0,i.c1,Number.MAX_SAFE_INTEGER,i.c2);this.holdSelectionEvents(()=>{t.clear(),t.addSelection(r),this.onSelectionChanged(t)}),this.repaint();const l=this.getSheetTexts();return this.announce(e?l.rowSelected(i.r2-i.r1+1):l.columnSelected(i.c2-i.c1+1)),!0}getEventListener(){return this.eventListener}afterRowsMoved(){this.lastSortCompareFn=void 0,this.invalidateAggregates()}announce(e,t){e&&!this.isDestroyed()&&this.liveAnnouncer.announce(e,t)}showLoadingOverlay(e){this.tableOverlay.showLoading(e)}showNoRowsOverlay(e){this.tableOverlay.showNoRows(e)}hideOverlay(){this.tableOverlay.hide()}getOverlayState(){return this.tableOverlay.getState()}onOverlayChanged(e){this.isDestroyed()||(e.kind==="loading"?(this.setHostAriaAttribute("aria-busy","true"),this.tableOverlay.isBlocking()&&(this.hideHoverRow(),this.hideHoverColumn())):e.previous==="loading"&&(this.restoreHostAriaAttribute("aria-busy"),this.liveAnnouncer.cancel(this.lastLoadingAnnouncement)),e.kind==="loading"&&(this.lastLoadingAnnouncement=e.text),(e.kind==="loading"||e.kind==="noRows"&&this.initialized)&&this.announce(e.text))}announceCopied(e){this.announce(this.ariaTexts.copied(this.countCopiedCells()))}countCopiedCells(){const e=this.selectionModel();if(!(e!=null&&e.hasSelection()))return 1;const t=this.tableModel.getBodyModel().getRowCount(),s=this.tableModel.getColumnCount(),o=u=>{var f,g;return((g=(f=this.tableModel.getColumnDef(u))==null?void 0:f.isVisible)==null?void 0:g.call(f))!==!1};let i=0;for(let u=0;u<s;u++)o(u)&&i++;if(e.isAllSelected())return t*i;const r=e.getRanges();if(!r.length)return 1;const l=Math.max(0,Math.min(...r.map(u=>u.r1))),a=Math.min(t-1,Math.max(...r.map(u=>u.r2))),c=Math.max(0,Math.min(...r.map(u=>u.c1))),h=Math.min(s-1,Math.max(...r.map(u=>u.c2)));if((a-l+1)*(h-c+1)>Se.maxCopyCells)return 0;let d=0;for(let u=l;u<=a;u++)for(let f=c;f<=h;f++)o(f)&&e.isSelected(u,f)&&d++;return d}getHeaderFocus(){return this.headerFocus?[this.headerFocus[0],this.headerFocus[1]]:void 0}setFocusCell(e,t){const s=this.focusModel();return s?(this.headerFocus=void 0,s.setFocus(e,t),this.ensureColumnIsVisible(t),this.ensureRowIsVisible(e),this.afterActiveCellMoved(e,t),this.repaint(),!0):!1}afterActiveCellMoved(e,t){var s;(s=this.editingOptions)!=null&&s.collapseSelectionOnNavigate&&this.selectionService.collapseTo(e,t)}getFirstShownColumnIndex(){return this.getNextShownColumnIndex(-1,1,this.tableModel.getColumnCount())}getLastShownColumnIndex(){const e=this.tableModel.getColumnCount();return this.getNextShownColumnIndex(e,-1,e)}onBodyNavigation(e){const t=this.focusModel();if(!["NAVIGATE_ROW_START","NAVIGATE_ROW_END","NAVIGATE_FIRST_CELL","NAVIGATE_LAST_CELL","NAVIGATE_PAGE_UP","NAVIGATE_PAGE_DOWN","ACTIVATE_CELL"].includes(e))return;if(!t||this.isEditing())return!1;const o=this.tableModel.getBodyModel().getRowCount();if(o<1||this.tableModel.getColumnCount()<1)return!1;const[i,r]=t.getFocus(),l=Math.min(Math.max(i,0),o-1),a=r<0?this.getFirstShownColumnIndex():r,c=Math.max(1,this.displayedRowCount-1);switch(e){case"NAVIGATE_ROW_START":return this.setFocusCell(l,this.getFirstShownColumnIndex());case"NAVIGATE_ROW_END":return this.setFocusCell(l,this.getLastShownColumnIndex());case"NAVIGATE_FIRST_CELL":return this.setFocusCell(0,this.getFirstShownColumnIndex());case"NAVIGATE_LAST_CELL":return this.setFocusCell(o-1,this.getLastShownColumnIndex());case"NAVIGATE_PAGE_UP":return this.setFocusCell(Math.max(0,l-c),a);case"NAVIGATE_PAGE_DOWN":return this.setFocusCell(Math.min(o-1,l+c),a);default:{if(i<0||r<0)return!1;if(this.activateBodyCell(i,r))return!0;const h=this.editingOptions;return h?h.enterKey==="moveDown"?this.moveActiveCell(i,r,1,0):this.tableModel.getBodyModel().isEditable(i,r)?this.startEditing(i,r,"edit"):!1:!1}}}activateBodyCell(e,t){var r;const s=this.tableModel.getBodyModel();if(s.isRowCheckable(e)&&(this.tableOptions.showCheckboxWihoutExtraColumn&&t===this.getFirstDataColumnIndex()||li(s.getCellRenderer(e,t))))return this.toggleRowCheckbox(e,t,"body"),!0;if((r=this.masterDetailService)!=null&&r.isMasterAt(e))return this.toggleDetail(e,"keyboard");const i=s.getRowByIndex(e);if(U(i)&&Z(s)&&s.hasDisplayedChildren(i)){const l=i;return this.setTreeRowExpanded(l,!l.expanded)}return!1}moveFocusIntoHeader(){const e=this.focusModel();if(!e||this.isEditing()||this.headerFocus)return!1;const[t,s]=e.getFocus(),o=this.getAriaGridInfo().headerRowCount,i=this.tableModel.getBodyModel().getRowCount()<1;return t!==0&&!i||o<1||this.tableModel.getColumnCount()<1?!1:(this.setHeaderFocus(o-1,s<0?this.getFirstShownColumnIndex():s),!0)}setHeaderFocus(e,t){var o;const s=(o=this.colAndRowspanModels.header)==null?void 0:o.getRanges().find(i=>i.isInRange(e,t));this.headerFocus=s?[s.r1,s.c1]:[e,t],this.ensureColumnIsVisible(this.headerFocus[1]),this.repaint()}onHeaderAction(e){const[t,s]=this.headerFocus,o=this.tableModel.getAreaModel("header"),i=this.getAriaGridInfo().headerRowCount,r=this.tableModel.getColumnCount(),l=Math.max(1,o.getColspanAt(t,s)||1),a=Math.max(1,o.getRowspanAt(t,s)||1);switch(e){case"NAVIGATE_LEFT":{const c=this.getNextShownColumnIndex(s,-1,r);return c!==s&&this.setHeaderFocus(t,c),!0}case"NAVIGATE_RIGHT":{const c=this.getNextShownColumnIndex(s+l-1,1,r);return c>s+l-1&&this.setHeaderFocus(t,c),!0}case"NAVIGATE_ROW_START":return this.setHeaderFocus(t,this.getFirstShownColumnIndex()),!0;case"NAVIGATE_ROW_END":return this.setHeaderFocus(t,this.getLastShownColumnIndex()),!0;case"NAVIGATE_UP":return t>0&&this.setHeaderFocus(t-1,s),!0;case"NAVIGATE_DOWN":return t+a<i?(this.setHeaderFocus(t+a,s),!0):this.tableModel.getBodyModel().getRowCount()<1?!0:this.setFocusCell(Math.max(0,this.firstFullVisibleRowIndex),s);case"NAVIGATE_FIRST_CELL":case"NAVIGATE_LAST_CELL":case"NAVIGATE_PAGE_UP":case"NAVIGATE_PAGE_DOWN":this.headerFocus=void 0;return;case"ACTIVATE_CELL":return this.activateHeaderCell(t,s,a,i);case"START_EDITING":case"TOGGLE_SELECTION":return!0;default:return}}activateHeaderCell(e,t,s,o){var a;const i=this.tableModel.getAreaModel("header"),r=i.getValueAt(e,t);if(r&&typeof r=="object"&&r.toggle&&r.visibility!=="always"&&"toggleHeaderGroup"in i){const c=new Es(null,this);return c.rowIdx=e,c.colIdx=t,c.areaIdent="header",c.areaModel=i,this.toggleHeaderGroup(c),this.setHeaderFocus(e,t),!0}const l=this.tableModel.getColumnDef(t);return e+s>=o&&((a=l==null?void 0:l.sortable)!=null&&a.call(l))?(this.sortByColumn(t),!0):!1}cancelEditing(e){var s,o;const t=this.getInCellEditorCell();if(t&&((o=(s=this.eventListener).onEditingChanged)==null||o.call(s,new yt("cancel",t[0],t[1],"edit"))),e instanceof HTMLSelectElement){const i=Array.from(e.options).find(r=>r.defaultSelected);e.selectedIndex=i?i.index:-1}else e&&(e.value=e.defaultValue);this.resetEditorRenderer(),this.hostElement.focus(),this.repaint()}updateModelValueAfterEdit(e,t,s,o){var l,a,c;if(e!=="body")return;this.getInCellEditorCell()&&((a=(l=this.eventListener).onEditingChanged)==null||a.call(l,new yt("commit",t,s,"edit",o)));const i=()=>{this.resetEditorRenderer()};if((c=this.batchEditService)!=null&&c.isActive()){i(),this.markPending([{rowIndex:t,column:s,value:o}],!1),this.repaint(),this.hostElement.focus();return}const r=this.writeCellsInternal([{rowIndex:t,columnIndex:s,value:o}],"edit",{beforeRepaint:i});(r.changes.length||r.invalid)&&(r.changes.length||(i(),this.repaint()),this.hostElement.focus())}applyCellChanges(e,t="api",s={}){var i;const o=this.resolveCellChanges(e);if(!o.length)return[];if((i=this.batchEditService)!=null&&i.isActive()){const r=this.markPending(o.map(l=>({rowIndex:l.rowIndex,column:l.columnIndex,value:l.value})),!0,!1,t,s.undoable);return this.repaint(),r}return this.writeCellsInternal(o,t,{undoable:s.undoable}).changes}writeCells(e,t,s={}){return this.writeCellsInternal(e,t,s).changes}writeCellsInternal(e,t,s){var p,m,b,y,C,v,E,S,R,L;const o=this.tableModel.getBodyModel(),i=o.getRowCount(),r=ne(o)?o.getBuildCount():0,l=[];let a=0,c="";const h=this.tableSheet,d=()=>{for(const{rowIndex:x,columnIndex:D,value:k}of e){const P=!!(h!=null&&h.isFormulaInput(D,k));if(!s.skipValidation){const $=P?this.checkFormulaSyntax(k):this.validateCellValue(x,D,s.raw?k:this.pipeCellValue(x,D,k));if($){a++,c=c||$;continue}}const V=this.getCellInput(x,D);(s.raw||P?this.setRawValue(x,D,k):o.setValue(x,D,k))&&l.push({row:this.rowObjectOf(x),rowIndex:x,columnIndex:D,property:this.batchEditService.propertyOf(D),oldValue:V,newValue:this.getCellInput(x,D)})}};ne(o)?o.batch(d):d(),a&&this.announce(this.getEditTexts().invalidValue(c));const u=(p=s.extraChanges)!=null&&p.length?[...l,...s.extraChanges]:l;if(!u.length)return{changes:u,invalid:a,message:c||void 0};h==null||h.cellsWritten(u),(m=this.undoService)==null||m.record(u,t,s.undoable),(b=s.beforeRepaint)==null||b.call(s);const f=(y=s.extraChanges)!=null&&y.length?void 0:{area:"body",rowIndices:l.map(x=>x.rowIndex)};this.invalidateAggregates(f),ne(o)&&o.getBuildCount()!==r||o.getRowCount()!==i||t==="commit"?this.repaintHard():s.deferRepaint?this.debounceRepaint():this.repaint(),this.invalidateAggregates(f),(C=this.undoService)==null||C.beginFold();try{if(t==="edit"&&u.length===1){const x=Xe.createSingle(u[0].rowIndex,u[0].columnIndex);x.changes=u,x.source=t,(E=(v=this.eventListener).onModelChanged)==null||E.call(v,x)}else(R=(S=this.eventListener).onModelChanged)==null||R.call(S,Xe.createForChanges(u,t))}finally{(L=this.undoService)==null||L.endFold()}return{changes:u,invalid:a,message:c||void 0}}writePastedCells(e,t,s){var i;const o=this.resolveCellChanges(e);if(!o.length)return[];if((i=this.batchEditService)!=null&&i.isActive()){const r=this.markPending(o.map(l=>({rowIndex:l.rowIndex,column:l.columnIndex,value:l.value})),!0,s,t);return this.repaint(),r}return this.writeCellsInternal(o,t,{raw:s}).changes}selectBodyRange(e){const t=this.focusModel();t&&(this.headerFocus=void 0,t.setFocus(e.r1,e.c1)),this.selectionService.collapseTo(e.r1,e.c1),(e.r2!==e.r1||e.c2!==e.c1)&&this.selectionService.extendTo(e.r2,e.c2),this.repaint()}checkPastedValue(e,t,s,o){var i;return(i=this.tableSheet)!=null&&i.isFormulaInput(t,s)?this.checkFormulaSyntax(s):this.validateCellValue(e,t,o?s:this.pipeCellValue(e,t,s))}getCellInput(e,t){const s=this.tableModel.getBodyModel();return this.tableSheet&&s.getInputValueAt?s.getInputValueAt(e,t):s.getValueAt(e,t)}getTypedCellValue(e,t){var o;const s=this.getShownCellValue(e,t);return(o=this.tableSheet)!=null&&o.isFormulaInput(t,s)?this.tableModel.getBodyModel().getValueAt(e,t):s}getFormulaErrorText(e){const t=this.ariaTexts??{};return(t.formulaError??new me().formulaError).call(t,e)}checkFormulaSyntax(e){const t=this.tableSheet;return t.options.rejectInvalidFormulas?t.syntaxError(e):void 0}resolvePastedValue(e,t,s,o){if(!(e instanceof Jt))return e;const i=this.tableSheet;return!i||!i.isFormulaColumnIndex(s)?e.value:o?e.input:i.moveFormula(e.input,e.row,e.col,t,s)??e.value}getCopyValue(e,t){var i;const s=this.tableSheet,o=this.getShownCellValue(e,t);return!s||(i=this.batchEditService)!=null&&i.getPendingAt(e,t)?o:s.copyOf(e,t,o,this.tableModel.getBodyModel().getValueAt(e,t))}isBatchEditActive(){var e;return!!((e=this.batchEditService)!=null&&e.isActive())}getUndoOptions(){return this.undoOptions}writeUndoCells(e,t,s){var r;if(!e.length&&!t.length)return[];const o=this.tableModel.getBodyModel();if((r=this.batchEditService)!=null&&r.isActive()){const l=e.length?this.markPending(e.map(a=>({rowIndex:a.rowIndex,column:a.columnIndex,value:a.value})),!0,!0,s):[];return this.repaint(),l}const i=this.writeCellsInternal(e,s,{raw:!0,skipValidation:!0,extraChanges:t}).changes;return t.length&&ne(o)&&(o.regroup(),this.invalidateAggregates(),this.repaintHard()),i}getUndoTexts(){const e=this.ariaTexts??{},t=new me;return{undone:(s,o)=>(e.undone??t.undone).call(e,s,o),redone:(s,o)=>(e.redone??t.redone).call(e,s,o),nothingToUndo:()=>(e.nothingToUndo??t.nothingToUndo).call(e),nothingToRedo:()=>(e.nothingToRedo??t.nothingToRedo).call(e),undoSkipped:s=>(e.undoSkipped??t.undoSkipped).call(e,s),undoHistoryCleared:s=>(e.undoHistoryCleared??t.undoHistoryCleared).call(e,s)}}isOverlayBlocking(){return this.tableOverlay.isBlocking()}rowsAppended(){this.invalidateAggregates()}isRowGroupingOrTree(){const e=this.tableModel.getBodyModel();return Z(e)||ne(e)||Rs(this.tableModel)}getClipboardService(){return this.clipboardService||(this.clipboardService=new Ko(this,ls.create(!0),!1)),this.clipboardService}markPending(e,t,s=!1,o="edit",i){const r=t?e.map(d=>({rowIndex:d.rowIndex,columnIndex:d.column,value:d.value})):this.resolveCellChanges(e,!1),l=this.batchEditService,a=this.undoService?r.map(({rowIndex:d,columnIndex:u})=>{const f=l.rowKeyOf(d),g=l.propertyOf(u),p=l.getPendingEntry(f,g);return{rowKey:f,property:g,before:p?{...p}:void 0}}):void 0,c=r.map(({rowIndex:d,columnIndex:u,value:f})=>{var m;if((m=this.tableSheet)!=null&&m.isFormulaInput(u,f)){const b=this.checkFormulaSyntax(f);return{rowIndex:d,columnIndex:u,value:f,rawValue:f,...b?{error:b}:{}}}const g=s?f:this.pipeCellValue(d,u,f),p=this.validateCellValue(d,u,g);return{rowIndex:d,columnIndex:u,value:g,rawValue:f,...p?{error:p}:{}}}),h=l.addPending(c);if(a&&h.length){for(const d of a){const u=l.getPendingEntry(d.rowKey,d.property);d.after=u?{...u}:void 0}this.undoService.recordPending(a.filter(d=>!d.before!=!d.after||!!d.before&&!!d.after&&!Dt(d.before.newValue,d.after.newValue)),o,i)}return h}resolveCellChanges(e,t=!0){var a,c;const s=this.tableModel.getBodyModel(),o=s.getRowCount(),i=this.tableModel.getColumnCount(),r=((c=(a=this.tableModel).getColumnDefs)==null?void 0:c.call(a))??[],l=[];for(const h of e){const d=typeof h.column=="number"?h.column:r.findIndex(f=>f.property===h.column),u=h.rowIndex;u>=0&&u<o&&d>=0&&d<i&&(t&&!s.isEditable(u,d)||l.push({rowIndex:u,columnIndex:d,value:h.value}))}return l}pipeCellValue(e,t,s){var i;const o=(i=this.tableModel.getColumnDef(t))==null?void 0:i.editInputPipe;return o?o(s,e,t):s}validateCellValue(e,t,s){var r;const o=(r=this.tableModel.getColumnDef(t))==null?void 0:r.validate;if(!o)return;const i=o(s,this.rowObjectOf(e));return i?String(i):void 0}rowObjectOf(e){const t=this.tableModel.getBodyModel().getRowByIndex(e);return U(t)?t.data:t}getFillHandleOptions(){return ns.create(Ze(this.tableOptions,"fillHandle"))}fillRange(e,t,s,o="auto",i){const r=this.getFillHandleOptions()??ns.create(!0),l=this.tableModel.getBodyModel(),a=l.getRowCount(),c=this.tableModel.getColumnCount(),h=this.normalizeRange(e,a,c);if(!h||s<1)return 0;const d=t==="down"?a-1-h.r2:t==="up"?h.r1:t==="right"?c-1-h.c2:h.c1,u=Math.min(s,d);if(u<1)return 0;const f=t==="down"||t==="up"?h.c2-h.c1+1:h.r2-h.r1+1;if(u*f>r.maxCells)return this.announce(this.getEditTexts().fillTooLarge(r.maxCells)),-1;const g=this.batchEditService,p=ol({source:h,direction:t,count:u,mode:o,getValue:(y,C)=>g.getShownValue(y,C),isFillable:(y,C)=>this.tableModel.getColumnWidth(C)>0&&l.isEditable(y,C),fillValue:r.fillValue,getCellInfo:(y,C)=>{var v;return{row:this.rowObjectOf(y),property:((v=this.tableModel.getColumnDef(C))==null?void 0:v.property)??""}}});this.tableSheet&&this.moveFilledFormulas(p,h,t);const m=this.applyCellChanges(p,"fill"),b=this.selectionModel();return b&&this.holdSelectionEvents(()=>{b.clear(),b.addSelection(i??ki(h,t,u)),this.onSelectionChanged(b)}),this.repaint(),this.announce(this.getEditTexts().cellsFilled(m.length)),m.length}moveFilledFormulas(e,t,s){const o=this.tableSheet,i=t.r2-t.r1+1,r=t.c2-t.c1+1,l=(a,c)=>(a%c+c)%c;for(const a of e){const c=a.rowIndex,h=a.column,d=s==="down"?t.r1+l(c-t.r2-1,i):s==="up"?t.r2-l(t.r1-1-c,i):c,u=s==="right"?t.c1+l(h-t.c2-1,r):s==="left"?t.c2-l(t.c1-1-h,r):h,f=this.getShownCellValue(d,u);if(!o.isFormulaInput(u,f))continue;const g=o.physicalRow(d),p=o.engineColumn(u);if(g===void 0||p===void 0)continue;const m=o.moveFormula(f,g,p,c,h);m!==void 0&&(a.value=m)}}getFillSourceRange(){const e=this.selectionModel();if(!e||e.selectionType!=="range"||e.isAllSelected())return;const t=e.getRanges();if(t.length)return this.normalizeRange(t[t.length-1],this.tableModel.getBodyModel().getRowCount(),this.tableModel.getColumnCount())}normalizeRange(e,t,s){const o=Math.max(0,Math.min(e.r1,e.r2)),i=Math.min(t-1,Math.max(e.r1,e.r2)),r=Math.max(0,Math.min(e.c1,e.c2)),l=Math.min(s-1,Math.max(e.c1,e.c2));return o<=i&&r<=l?new M(o,r,i,l):void 0}fillByKeyboard(e){var r;const t=this.getFillHandleOptions(),s=e==="down";if(!t||this.isEditing()||(r=this.fillHandleService)!=null&&r.isFilling()||t.direction===(s?"horizontal":"vertical"))return!1;const o=this.getFillSourceRange();if(!o)return!1;const i=s?o.r2-o.r1:o.c2-o.c1;if(i>0){const l=s?new M(o.r1,o.c1,o.r1,o.c2):new M(o.r1,o.c1,o.r2,o.c1);this.fillRange(l,e,i,"copy")}else if(s?o.r1>0:o.c1>0){const l=s?new M(o.r1-1,o.c1,o.r1-1,o.c2):new M(o.r1,o.c1-1,o.r2,o.c1-1);this.fillRange(l,e,1,"copy",o)}return!0}setHostKeyShortcuts(e){e===void 0?this.restoreHostAriaAttribute("aria-keyshortcuts"):this.setHostAriaAttribute("aria-keyshortcuts",e)}getEditTexts(){const e=this.ariaTexts,t=new me;return{cellsFilled:s=>(e.cellsFilled??t.cellsFilled).call(e,s),fillTooLarge:s=>(e.fillTooLarge??t.fillTooLarge).call(e,s),pendingChanges:s=>(e.pendingChanges??t.pendingChanges).call(e,s),changesCommitted:s=>(e.changesCommitted??t.changesCommitted).call(e,s),changesDiscarded:()=>(e.changesDiscarded??t.changesDiscarded).call(e),commitBlocked:s=>(e.commitBlocked??t.commitBlocked).call(e,s),invalidValue:s=>(e.invalidValue??t.invalidValue).call(e,s)}}getApi(){return this.api}firstInit(){var t;const e=this.getAvailableColumnWidth();return e>0&&this.setParentWidth(e),this.stateService.initBeforeModel(),this.tableModel.init(),this.stateService.initAfterModel(),(t=this.tableOptions)!=null&&t.externalFilterFunction&&this.externalFilterChanged(!1),this.stateService.initAfterFilter(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows(),this.stateService.initAfterLayout(),this.liveAnnouncer.getElement(),this.initialized=!0,this}destroy(){var s,o,i,r,l,a,c,h;if(this.destroyed)return;try{this.stateService.destroy()}catch(d){console.error(d)}(o=(s=this.columnDrag)==null?void 0:s.keyAbort)==null||o.abort(),this.columnDrag=void 0;try{(i=this.rowDragService)==null||i.destroy()}catch(d){console.error(d)}(r=this.fillHandleService)==null||r.destroy(),(l=this.cellEditorService)==null||l.destroy(),(a=this.clipboardService)==null||a.destroy(),(c=this.tableSheet)==null||c.destroy(),this.subscribers.clear();try{(h=this.masterDetailService)==null||h.destroy()}catch(d){console.error(d)}this.destroyed=!0,this.listenerAbortController.abort(),this.resizeHandler.disconnect();const e=this.getSelectionModel?this.getSelectionModel():void 0;e==null||e.removeEventSelectionChangedListener(this);const t=this.getFocusModel?this.getFocusModel():void 0;t==null||t.removeEventFocusChangedListener(this),this.disposeRendering(),this.tableOverlay.destroy(),this.liveAnnouncer.destroy(),this.removeHostAria(),this.hostElement.innerText=""}isEventInDetail(e){var t;return!!((t=this.masterDetailService)!=null&&t.isInLayer(e))}setDetailExpanded(e,t,s="api"){var o;return!!((o=this.masterDetailService)!=null&&o.setExpanded(e,t,s))}toggleDetail(e,t="api"){const s=this.masterDetailService;return!!s&&s.setExpanded(e,!s.isExpanded(e),t)}onDetailToggled(e,t,s,o,i=!0,r=!1){var l,a,c,h,d,u;if(r||this.invalidateRowLayout(),this.resetSizeOfWrapperDiv(),this.repaint(),i&&((a=(l=this.eventListener).onDetailExpandedChanged)==null||a.call(l,new nl(e,t,s,o))),o==="mouse"||o==="keyboard"){const f=s?(h=(c=this.ariaTexts).detailExpanded)==null?void 0:h.call(c):(u=(d=this.ariaTexts).detailCollapsed)==null?void 0:u.call(d);f&&this.announce(f)}this.stateService.markDirty("details")}onDetailHeightChanged(){this.destroyed||(this.resetSizeOfWrapperDiv(),this.adjustAfterScrolling())}takeFocusFromDetail(e){const t=this.focusModel();if(t&&e>=0){const s=t.getFocus()[1];this.headerFocus=void 0,t.setFocus(e,s>=0?s:this.getFirstShownColumnIndex())}this.hostElement.focus({preventScroll:!0})}focusDetailMaster(e){const t=this.focusModel();if(!t||e<0)return;const s=t.getFocus()[1];this.setFocusCell(e,s>=0?s:this.getFirstShownColumnIndex())}isDestroyed(){return this.destroyed}createGeMouseEvent(e){if(!e)return new es;const t=this.getMouseEventTarget(e),[s,o]=this.getAreaAndSideIdentByAttr(t);return this.createGeMouseEventForCell(e,{areaIdent:s,sideIdent:o,rowIndex:this.getNumberByAttr(t,"data-row-index"),columnIndex:this.getNumberByAttr(t,"data-col-index"),action:this.getStringByAttr(t,"data-ge-action")})}createGeMouseEventForCell(e,t){const s=new es;if(s.originalEvent=e,s.areaIdent=t.areaIdent,s.sideIdent=t.sideIdent,s.rowIndex=t.rowIndex,s.columnIndex=t.columnIndex,s.action=t.action,s.areaIdent){const o=this.tableModel.getAreaModel(s.areaIdent);s.rowTop=s.areaIdent==="body"?this.getBodyRowTop(s.rowIndex):o.getYPosByRowIndex(s.rowIndex)}return s.columnLeft=this.tableModel.getXPosByColumnIndex(s.columnIndex),s}getMouseEventTarget(e){const t=e.target;if((t===this.scrollViewport||t===this.contentWrapperDiv||t===this.contentDiv)&&this.tableModel.getPadding().bottom>0){const s=this.scrollViewport.getBoundingClientRect(),o=e.clientX-s.left,i=e.clientY-s.top>=this.scrollViewport.clientHeight||o<this.scrollViewport.clientLeft||o>=this.scrollViewport.clientLeft+this.scrollViewport.clientWidth,r=this.hostElement.getRootNode();if(!i&&r.elementsFromPoint){const l=r.elementsFromPoint(e.clientX,e.clientY).find(a=>this.hostElement.contains(a)&&a.closest(".ge-table-footer"));if(l)return l}}return t}onMouseDown(e){var o;this.selectionService.onMouseDown(),this.resetColumnDrag();const t=e.columnIndex,s=e.action==="resize-column";if(t>-1&&(s||e.action==="drag-column")&&(s?this.isColumnResizable(t):this.isColumnMovable(t))&&(this.mouseStartWidth=this.tableModel.getColumnWidth(t),this.mouseStartAction=e.action,this.mouseStartColumnIndex=t,this.mouseStartAction==="drag-column"&&(this.firstDraggingRendering=!0,this.dragFrom=this.mouseStartColumnIndex),s?this.tableOptions.columnsResizable:this.tableOptions.columnsDraggable&&((o=this.tableSheet)==null?void 0:o.allowsColumnDrag())!==!1)){const r=this.tableModel.getColumnDef(t);this.columnDrag={kind:s?"resize":"move",source:"mouse",columnIndex:t,currentIndex:t,columnDef:r,startWidth:this.mouseStartWidth,moves:[],started:!1,cancelled:!1}}}resetColumnDrag(){var e,t;(t=(e=this.columnDrag)==null?void 0:e.keyAbort)==null||t.abort(),this.columnDrag=void 0,this.mouseStartAction="",this.mouseStartWidth=-1,this.mouseStartColumnIndex=-1,this.dragFrom=-1,this.dragTo=-1,this.firstDraggingRendering=!0}beginColumnDrag(e){var l;const t=this.columnDrag;if(!t||t.cancelled)return!1;if(t.started)return!0;const s=e.draggingX||0,o=e.draggingY||0,i=((l=this.mouseHandler)==null?void 0:l.clickMoveTolerance)??4;if(s*s+o*o<=i*i)return!1;t.started=!0;const r=new AbortController;return t.keyAbort=r,(this.hostElement.ownerDocument??document).addEventListener("keydown",a=>{a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),this.cancelColumnDrag(a))},{capture:!0,signal:r.signal}),this.emitColumnDragEvent(t,"start",e.originalEvent),!t.cancelled&&this.columnDrag===t&&!this.isDestroyed()}isColumnDragging(){var e;return!!((e=this.columnDrag)!=null&&e.started)&&!this.columnDrag.cancelled}cancelColumnDrag(e){var s;const t=this.columnDrag;if(!(!t||!t.started||t.cancelled)){if(t.cancelled=!0,(s=t.keyAbort)==null||s.abort(),t.kind==="resize")this.tableModel.setColumnWidth(t.columnIndex,t.startWidth),this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows();else{this.hideDraggingColumn(),this.draggingTargetColumnIndex=-1;for(let o=t.moves.length-1;o>=0;o--){const[i,r]=t.moves[o];this.tableModel.changeColumnOrder(r,i)}t.moves=[],t.currentIndex=t.columnIndex,this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows(),this.stateService.markDirty("selection")}this.stateService.markDirty("columns"),this.emitColumnDragEvent(t,"cancel",e)}}emitColumnDragEvent(e,t,s){var i,r,l,a,c,h,d,u,f,g,p;const o=(i=e.columnDef)==null?void 0:i.property;if(e.kind==="resize"){const m=t==="start"?e.startWidth:this.tableModel.getColumnWidth(e.columnIndex),b=new _l(t,e.source,e.columnIndex,e.columnDef,o,e.startWidth,m,s);t==="start"?(l=(r=this.eventListener).onColumnResizeStart)==null||l.call(r,b):(c=(a=this.eventListener).onColumnResizeEnd)==null||c.call(a,b)}else{const m=(((d=(h=this.tableModel).getColumnDefs)==null?void 0:d.call(h))??[]).map(y=>y==null?void 0:y.property),b=new Bl(t,e.columnIndex,t==="start"?e.columnIndex:e.currentIndex,e.columnDef,o,m,s);t==="start"?(f=(u=this.eventListener).onColumnMoveStart)==null||f.call(u,b):(p=(g=this.eventListener).onColumnMoveEnd)==null||p.call(g,b)}}mouseDraggingOnFrame(e,t){var s,o;(o=(s=this.eventListener).onMouseDragging)==null||o.call(s,e),this.mouseEvent=e,!((this.mouseStartAction==="resize-column"||this.mouseStartAction==="drag-column")&&!this.beginColumnDrag(e))&&(this.mouseStartAction==="resize-column"?this.resizeColumn(e):!this.mouseStartAction&&this.selectionService.onMouseDragging(e,t)?this.repaint():this.mouseStartAction==="drag-column"&&e.columnIndex>-1&&(this.moveDraggedColumn(e.columnIndex),t&&(this.adjustDraggingColumn(e,this.dragFrom,this.firstDraggingRendering),this.firstDraggingRendering=!1),this.repaint()))}moveDraggedColumn(e){var i;const t=this.tableModel,s=t.getColumnCount();let o=Oc(this.dragFrom,e,s,t.getFixedLeftColumnCount(),t.getFixedRightColumnCount());for(;this.dragFrom>-1&&o!==this.dragFrom&&!this.isColumnMovable(o);)o+=o>this.dragFrom?-1:1;if(this.dragFrom>-1&&o!==this.dragFrom&&!(this.lastDragFrom===o&&this.lastDragTo===this.dragFrom)){const r=Array.from({length:s},(a,c)=>this.isColumnMovable(c)),l=Lc(r,this.dragFrom,o);l!=null&&l.length&&(l.forEach(([a,c])=>t.changeColumnOrder(a,c)),(i=this.columnDrag)==null||i.moves.push(...l),this.lastDragFrom=this.dragFrom,this.lastDragTo=o,this.dragFrom=o,this.columnDrag&&(this.columnDrag.currentIndex=o),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows())}this.draggingTargetColumnIndex=this.dragFrom,this.dragTo=this.dragFrom}mouseDraggingEndOnFrame(e){var o,i;(i=(o=this.eventListener).onMouseDraggingEnd)==null||i.call(o,e),this.draggingTargetColumnIndex=-1;const t=this.columnDrag;t&&this.beginColumnDrag(e);const s=!!t&&t.started&&!t.cancelled;this.mouseStartAction==="resize-column"?s&&(this.resizeColumn(e),this.stateService.markDirty("columns")):this.mouseStartAction==="drag-column"&&(s&&e.columnIndex>-1&&(this.moveDraggedColumn(e.columnIndex),this.draggingTargetColumnIndex=-1),this.hideDraggingColumn(),s&&(this.repaint(),this.stateService.markDirty("columns"),this.stateService.markDirty("selection"))),this.resetColumnDrag(),s&&this.emitColumnDragEvent(t,"end",e.originalEvent)}mouseMove(e){var t,s;(s=(t=this.eventListener).onMouseMoved)==null||s.call(t,e),this.adjustHoverRows(e),this.adjustHoverColumns(e)}contextmenu(e){var s,o,i,r;const t=Date.now();if(t-this.lastContextmenu<50){this.lastContextmenu=t,(s=e.originalEvent)==null||s.preventDefault(),(o=e.originalEvent)==null||o.stopImmediatePropagation();return}this.lastContextmenu=t,(r=(i=this.eventListener).onContextmenu)==null||r.call(i,e)}toggleExpandCollapseAll(e=!0){const t=this.tableModel.getBodyModel();Z(t)&&(t.toggleExpandCollapseAll(e),this.allExpanded=e,this.repaintHard(),this.stateService.markDirty("tree"))}setTreeRowExpanded(e,t){const s=this.tableModel.getBodyModel();return!Z(s)||e.expanded===t?!1:(e.expanded=t,s.recalcVisibleTreeRows(!1),this.repaintHard(),this.stateService.markDirty("tree"),!0)}setRowGroupBy(e){const t=this.tableModel.getBodyModel();return ne(t)?(t.setGroupBy(e),Ho(this.tableModel),this.invalidateAggregates(),this.tableModel.recalcPadding(),this.repaintHard(),this.stateService.markDirty("tree"),this.stateService.markDirty("columns"),!0):!1}setPivotConfig(e,t){var o,i;const s=this.tableModel;if(!Rs(s))return!1;s.setPivotConfig(e,t),(s.getColumnDefs()??[]).forEach(r=>r.sortState=void 0),this.lastSortCompareFn=void 0,this.clearSelection(),(o=this.getFocusModel?this.getFocusModel():void 0)==null||o.clear();for(const r of["header","body","footer"])(i=this.colAndRowspanModels[r])==null||i.init();return this.invalidateAggregates(),this.firstInit(),this.repaintHard(),this.stateService.markDirty("columns"),this.stateService.markDirty("sort"),this.stateService.markDirty("tree"),this.stateService.markDirty("headerGroups"),!0}toggleRowCheckbox(e,t,s){var a,c,h;const o=this.tableModel.getAreaModel(s),i=o.isRowChecked(e),r=i===void 0||i==="semi"||i==="none";o.setRowChecked(e,r),this.repaint();const l=(a=o.rowSelectionModel)==null?void 0:a.getCheckedRows();(h=(c=this.eventListener).onCheckboxChanged)==null||h.call(c,l?l.slice():[]),this.stateService.markDirty("checked")}onMouseClicked(e,t){if(this.headerFocus=void 0,e.clickCount>1)return!1;let s=this.selectionService.onMouseClicked(e,t);if(!s&&this.getFocusModel){this.resetEditorRenderer();const o=this.getFocusModel();o&&(s=o.hasChanged(),o.clearChanged())}return s}debounceRepaint(){this.debounce(this.repaint.bind(this),1)}cancelPendingRepaint(){return this.debounceTimeout?(clearTimeout(this.debounceTimeout),this.debounceTimeout=null,!0):!1}publishGeMouseEvent(e){var t,s;(s=(t=this.eventListener).onMouseClicked)==null||s.call(t,e)}onFocusChanged(e){var t,s;(s=(t=this.eventListener).onFocusChanged)==null||s.call(t,e)}stateChanged(e){var t,s;(s=(t=this.eventListener).onStateChanged)==null||s.call(t,e)}afterRenderPass(){var e,t,s,o;(e=this.stateService)==null||e.rendered(),(t=this.fillHandleService)==null||t.update(),(s=this.cellEditorService)==null||s.update(),(o=this.clipboardService)==null||o.update()}onSelectionChanged(e){var t,s,o;if((t=this.stateService)==null||t.markDirty("selection"),this.selectionEventsHeld>0){this.heldSelectionModel=e;return}(o=(s=this.eventListener).onSelectionChanged)==null||o.call(s,e)}holdSelectionEvents(e){var t,s;this.selectionEventsHeld++;try{e()}finally{if(this.selectionEventsHeld--,this.selectionEventsHeld===0&&this.heldSelectionModel){const o=this.heldSelectionModel;this.heldSelectionModel=void 0,(s=(t=this.eventListener).onSelectionChanged)==null||s.call(t,o)}}}externalFilterChanged(e=!0){const t=this.tableOptions.externalFilterFunction;if(t&&(e&&this.clearSelectionModel(),this.tableModel.externalFilterChanged(t),this.reapplySorting(),this.invalidateAggregates(),this.scrollViewport.scrollTo(0,0),this.tableModel.recalcHeightAndPadding(),this.resetSizeOfWrapperDiv(),this.repaint(),this.initialized)){const s=this.tableModel.getBodyModel().getRowCount();this.announce(this.ariaTexts.filtered(s),Ge.filterAnnouncementDelayInMs)}}onHeaderDblClicked(e,t,s){const o=this.tableModel.getColumnDef(s);o!=null&&o.sortable&&o.sortable()&&(e.preventDefault(),e.stopPropagation(),this.sortByColumn(s))}sortByColumn(e,t){var h;const s=typeof e=="number"?e:(this.tableModel.getColumnDefs()??[]).findIndex(d=>d.property===e),o=this.tableModel.getColumnDef(s);if(!o)return!1;const i=o.sortStatesOrder?o.sortStatesOrder:this.tableOptions.sortOrder,r=o.sortState??"",l=t??i[(i.indexOf(r)+1)%i.length],a=new jt(s,l),c=this.tableModel.doSort([a]);return c&&(this.invalidateAggregates(),this.lastSortCompareFn=void 0,(h=this.tableModel.getColumnDefs())==null||h.forEach(d=>d.sortState=""),o.sortState=l),this.repaint(),c&&this.stateService.sortedByColumn(l?o.property:void 0),c&&this.announce(this.ariaTexts.sorted(this.getColumnAriaLabel(s),l)),!0}scrollToPixel(e,t){this.setContentScrollPosition(e,t)&&this.adjustAfterScrolling()}scrollToIndex(e,t){const s=this.getBodyRowTop(t);this.scrollToPixel(this.getScrollLeftForColumnIndex(e),s)}getScrollLeftForColumnIndex(e){const t=this.scrollViewport,s=this.tableModel.getFixedLeftColumnCount(),o=this.tableModel.getColumnCount()-this.tableModel.getFixedRightColumnCount()-1;if(e>=0&&e<s)return 0;if(!(e>=s&&e<=o))return this.getViewportScrollLeft();let i=0;for(let a=s;a<e;a++)i+=this.tableModel.getColumnWidth(a);const r=this.tableModel.getContentWidthInPixel()-this.areaBodyCenterGeo.width,l=t.scrollWidth-t.clientWidth;return r<=0||l<=0?0:Math.min(1,i/r)*l}adjustAfterScrolling(){var t,s;if(super.adjustAfterScrolling(),this.adjustingRowNumberWidth)return;const e=this.scrollViewport;(s=(t=this.eventListener).onScroll)==null||s.call(t,new Ln(this.scrollTop,this.scrollLeft,e.scrollHeight,e.scrollWidth,e.clientHeight,e.clientWidth,this.scrollFactorY,this.scrollFactorX))}setSelectionModel(e,t=!1){var o;(o=this.selectionModel())==null||o.removeEventSelectionChangedListener(this),e.addEventSelectionChangedListener(this);const s=()=>e;this.tableOptions.getSelectionModel=s,this.getSelectionModel=s,this.selectionService.getSelectionModel=s,t&&this.repaint()}toggleHeaderGroup(e){const t=this.tableModel.getAreaModel("header");"columnDefs"in this.tableModel&&(this.tableModel.columnDefs=t.toggleHeaderGroup(e)),this.headerGroupsChanged()}setHeaderGroupCollapsed(e,t){var i;const s=this.tableModel.getAreaModel("header"),o=(i=s.setGroupClosed)==null?void 0:i.call(s,e,t);return o?("columnDefs"in this.tableModel&&(this.tableModel.columnDefs=o),this.headerGroupsChanged(),!0):!1}headerGroupsChanged(){this.firstInit(),this.stateService.markDirty("headerGroups"),this.stateService.markDirty("columns")}selectionModel(){if(this!=null&&this.getSelectionModel)return this.getSelectionModel()}focusModel(){if(this!=null&&this.getFocusModel)return this.getFocusModel()}setDragging(e){this.dragging=e,this.dragging?(this.storeColumnWidths(),this.lastDragFrom=-1,this.lastDragTo=-1):this.storedColumnWidths=[]}changeFocusCell(e,t){var s;if(!this.isEditing()&&this.getFocusModel){const o=this.getFocusModel();if(o){const i=this.tableModel.getBodyModel().getRowCount(),r=this.tableModel.getColumnCount();if(i<1||r<1)return!1;const[l,a]=o.getFocus(),c=Math.min(Math.max(l+t,0),i-1),h=this.getNextShownColumnIndex(a,e,r);return c!==l||h!==a?(o.setFocus(c,h),this.ensureColumnIsVisible(h),this.ensureRowIsVisible(c),this.afterActiveCellMoved(c,h),this.repaint()):(s=this.editingOptions)!=null&&s.collapseSelectionOnNavigate&&(this.afterActiveCellMoved(c,h),this.repaint()),!0}}return!1}getNextShownColumnIndex(e,t,s){if(!t){const l=Math.min(Math.max(e,0),s-1);return e<0&&this.tableModel.getColumnWidth(l)<=0?this.getNextShownColumnIndex(-1,1,s):l}const o=t>0?1:-1;let i=e,r=e;for(let l=Math.abs(t);l>0;l--){for(r+=o;r>=0&&r<s&&this.tableModel.getColumnWidth(r)<=0;)r+=o;if(r<0||r>=s)break;i=r}return Math.min(Math.max(i,0),s-1)}resizeColumn(e){const t=this.isRtl()?-e.draggingX:e.draggingX,s=this.clampToColumnWidthLimits(this.mouseStartColumnIndex,this.mouseStartWidth+t,this.mouseStartWidth);this.tableModel.setColumnWidth(this.mouseStartColumnIndex,s),this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}clampToColumnWidthLimits(e,t,s){var c,h,d;const o=(d=(h=(c=this.tableModel).getColumnDefs)==null?void 0:h.call(c))==null?void 0:d[e];if(!o)return t;const i=this.getAvailableColumnWidth(),r=u=>{if(!(!u||!Number.isFinite(u.value))){if(u.unit==="px")return u.value;if(u.unit==="%"&&i>0)return Math.floor(u.value*i/100)}};let l=r(o.minWidth),a=r(o.maxWidth);return l!==void 0&&a!==void 0&&l>a||(s!==void 0&&s>=0&&(l!==void 0&&(l=Math.min(l,s)),a!==void 0&&(a=Math.max(a,s))),l!==void 0&&(t=Math.max(l,t)),a!==void 0&&(t=Math.min(a,t))),t}clearSelectionModel(){var e;this.getSelectionModel&&((e=this.getSelectionModel())==null||e.clear())}calcAutoColumnWidths(){if(!this.tableModel.getBodyModel())return console.warn("Body model is not available."),[];const e=Array.from({length:this.tableModel.getColumnCount()},(t,s)=>s);return this.measureDefaultColumnWidths(e,new ot(this.hostElement))}measureDefaultColumnWidths(e,t){const s=e.map(()=>new Set),o=e.map(()=>0);return["header","body","footer"].forEach(i=>{const r=this.tableModel.getAreaModel(i),[l,a]=i==="body"?this.getMeasuredBodyRows():[0,((r==null?void 0:r.getRowCount())??0)-1];_h(r,l,a,e,s,o)}),s.map(i=>t.measureWidest(i))}getMeasuredBodyRows(){var i;const e=((i=this.tableModel.getBodyModel())==null?void 0:i.getRowCount())??0;if(e<=this.getColumnAutoWidthOptions().maxRows)return[0,e-1];const t=this.renderedBodyRows,s=Math.min(Math.max(0,t.first),e-1),o=t.last>=s?Math.min(t.last,e-1):Math.min(s+50,e-1);return[s,o]}getColumnAutoWidthOptions(){return fo.create(this.tableOptions.columnAutoWidth)}calcAutoColumnWidth(e,t,s,o){let i=o;const r=()=>(i===void 0&&(i=this.measureDefaultColumnWidths([e],s)[0]),i),l=this.getColumnAutoWidthOptions().getWidth;let a;if(l){const c=this.tableModel.getColumnDef(e),h={columnIndex:e,columnDef:c,property:c==null?void 0:c.property,source:t,firstRenderedRow:this.renderedBodyRows.first,lastRenderedRow:this.renderedBodyRows.last,measureText:u=>s.measureText(u),getDefaultWidth:r},d=l(h);a=typeof d=="number"&&Number.isFinite(d)&&d>=0?Math.round(d):void 0}return this.clampToColumnWidthLimits(e,a??r())}autoResizeColumn(e){const t=this.resolveColumnIndex(e);if(t<0||!this.isColumnAutoResizable(t))return;const s=this.calcAutoColumnWidth(t,"api",new ot(this.hostElement));return this.tableModel.setColumnWidth(t,s),this.recalcWrappers(),this.stateService.markDirty("columns"),s}autoResizeColumnByUser(e,t){if(!this.tableOptions.columnsResizable||!this.getColumnAutoWidthOptions().doubleClick||e<0||e>=this.tableModel.getColumnCount()||!this.isColumnAutoResizable(e))return!1;const s=this.tableModel.getColumnWidth(e),o=this.tableModel.getColumnDef(e),i={kind:"resize",source:"dblclick",columnIndex:e,currentIndex:e,columnDef:o,startWidth:s,moves:[],started:!0,cancelled:!1},r=this.calcAutoColumnWidth(e,"dblclick",new ot(this.hostElement)),l=this.columnDrag;this.columnDrag=i;try{if(this.emitColumnDragEvent(i,"start",t),i.cancelled||this.isDestroyed())return!0;this.tableModel.setColumnWidth(e,r),this.recalcWrappers(),this.stateService.markDirty("columns"),this.emitColumnDragEvent(i,"end",t)}finally{this.columnDrag===i&&(this.columnDrag=l)}return!0}isColumnAutoResizable(e){var s;const t=this.tableModel.getColumnDef(e);return this.isColumnResizable(e)&&!N(t)&&((s=t==null?void 0:t.isVisible)==null?void 0:s.call(t))!==!1}resolveColumnIndex(e){var o,i;const t=this.tableModel.getColumnCount();if(typeof e=="number")return Number.isInteger(e)&&e>=0&&e<t?e:-1;const s=((i=(o=this.tableModel).getColumnDefs)==null?void 0:i.call(o))??[];return typeof e=="string"?s.findIndex(r=>r.property===e):s.indexOf(e)}setColumnWidth(e,t){this.tableModel.setColumnWidth(e,t),this.stateService.markDirty("columns")}setColumnVisible(e,t){var s,o;return(o=(s=this.tableModel).setColumnVisible)!=null&&o.call(s,e,t)?(this.recalcWrappers(),this.stateService.markDirty("columns"),!0):!1}setHeaderVisible(e){this.setAreaVisible("header",e)}setFooterVisible(e){this.setAreaVisible("footer",e)}setAreaVisible(e,t){const s=this.tableModel,o=e==="header"?s.setHeaderVisible:s.setFooterVisible;if(!o){console.warn(`set${e==="header"?"Header":"Footer"}Visible() needs a table model with this method (e.g. TableModel), this one has none:`,s);return}o.call(s,t),e==="header"&&!t&&(this.headerFocus=void 0),this.recalcWrappers()}autoResizeColumns(e=!0){const t=this.tableModel.getColumnCount();if(!this.tableModel.getBodyModel()){console.warn("Body model is not available.");return}const s=new ot(this.hostElement),o=Array.from({length:t},(r,l)=>l),i=this.measureDefaultColumnWidths(o,s);for(let r=0;r<t;r++)this.isColumnAutoResizable(r)&&this.tableModel.setColumnWidth(r,this.calcAutoColumnWidth(r,"api",s,i[r]));e&&this.recalcWrappers(),this.stateService.markDirty("columns")}recalcWrappers(){this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}appendRows(e,t={}){const s=this.tableModel.getBodyModel();if(!s.appendRows||this.tableSheet||this.isRowGroupingOrTree())return console.warn("appendRows() works with an AreaModelObjectArray body (TableFactory.createTableModel({ rows })) without cell formulas – use rowsAppended() for an own area model. Nothing changed."),!1;const o=s.appendRows(e,{filter:this.tableOptions.externalFilterFunction,compare:this.getActiveSortComparator(),maxRows:t.maxRows});return o?this.afterRowsAppended(o,t.follow??"auto"):(console.warn("appendRows(): the body model did not append the rows."),!1)}notifyRowsAppended(e,t={}){const s=Math.max(0,this.tableModel.getBodyModel().getRowCount()),o=Math.max(0,Math.min(Math.floor(e)||0,s)),i=this.renderedBodyRows.count,r=Math.max(0,Math.min(Math.floor(t.removedAtStart??0)||0,i)),l=new Int32Array(r);for(let c=0;c<r;c++)l[c]=c;const a=new Int32Array(o);for(let c=0;c<o;c++)a[c]=s-o+c;return this.afterRowsAppended({added:o,shown:o,removed:r,removedPositions:l,insertedPositions:a},t.follow??"auto")}getActiveSortComparator(){var s,o;if(this.lastSortCompareFn)return this.lastSortCompareFn;const e=[];(s=this.tableModel.getColumnDefs())==null||s.forEach((i,r)=>{(i.sortState==="asc"||i.sortState==="desc")&&e.push(new jt(r,i.sortState))});const t=this.tableModel.getBodyModel();return e.length?(o=t.createSortComparator)==null?void 0:o.call(t,e):void 0}afterRowsAppended(e,t){var m,b,y,C,v,E;const s=new Vl(e.removedPositions,e.insertedPositions),o=this.renderedBodyRows,i=this.selectionModel(),r=((m=i==null?void 0:i.adjustForRowChanges)==null?void 0:m.call(i,s))??!1;(y=(b=this.focusModel())==null?void 0:b.adjustForRowChanges)==null||y.call(b,s),this.selectionService.adjustForRowChanges(s),this.mouseHandler.adjustForRowChanges(s),this.shiftEditorRow(s);const l=this.tableModel.getBodyModel().getRowCount(),a=this.focusModel();a&&l>0&&a.getFocus()[0]>=l&&a.setFocus(l-1,a.getFocus()[1]),e.removed&&((C=this.batchEditService)==null||C.pruneOrphans());const c=this.colAndRowspanModels.body;c&&!c.updateForInsertedRows(e.insertedPositions)&&!s.isEmpty()&&c.init(),this.invalidateAggregates();const h=this.mouseHandler.isButtonDown()||!!((v=this.rowDragService)!=null&&v.isDragging())||!!((E=this.fillHandleService)!=null&&E.isFilling()),d=this.followHeldAt,u=o.atEnd||d!==void 0&&Math.abs(this.contentScrollTop-d)<1,f=t===!0||t==="auto"&&u&&!h;let g;if(f)g=Number.MAX_SAFE_INTEGER;else if(o.count>0){const S=s.mapIndex(o.first)>=0,R=Math.min(s.mapIndexOrNext(o.first),Math.max(0,l-1));g=l>0?this.getBodyRowTop(R)+(S?o.offset:0):0}else g=0;return!f&&s.getRemovedCount()===0&&o.count>0&&o.last<o.count-1&&!s.touchesUpTo(o.last)&&this.canKeepDrawnRows()&&this.updateRowCountWithoutRender(g)||this.repaintHard({py:g}),this.followHeldAt=t==="auto"&&h&&u?this.contentScrollTop:void 0,r&&i&&this.onSelectionChanged(i),{added:e.added,shown:e.shown,removed:e.removed,following:f}}canKeepDrawnRows(){var s;if(this.getFirstDataColumnIndex()>0||this.masterDetailService||this.tableModel.isRowCheckboxVisible()||this.tableOptions.showCheckboxWihoutExtraColumn)return!1;const e=this.tableModel.getAreaModel("footer");if(e.getRowCount()>0&&e.invalidateDerivedValues)return!1;const t=this.tableModel.getBodyModel();return!((s=t.hasDerivedColumns)!=null&&s.call(t))}reSort(){this.reapplySorting(),this.invalidateAggregates(),this.repaint()}sort(e){var t;this.tableModel.sort(e),this.invalidateAggregates(),this.lastSortCompareFn=e,(t=this.tableModel.getColumnDefs())==null||t.forEach(s=>s.sortState=""),this.repaint(),this.stateService.sortedByColumn(void 0)}applySortItems(e){const t=this.tableModel.getColumnDefs();t==null||t.forEach(s=>s.sortState=""),e.forEach(s=>{const o=t==null?void 0:t[s.columnIndex];o&&(o.sortState=s.sortState)}),e.length&&(this.lastSortCompareFn=void 0,this.tableModel.doSort(e),this.invalidateAggregates())}reapplySorting(){var t;if(this.lastSortCompareFn){this.tableModel.sort(this.lastSortCompareFn);return}const e=[];(t=this.tableModel.getColumnDefs())==null||t.forEach((s,o)=>{s.sortState&&e.push(new jt(o,s.sortState))}),e.length&&this.tableModel.doSort(e)}ensureRowIsVisible(e){if(this.hasBodyRowExtras()){const i=this.getBodyRowTop(e),r=i+this.tableModel.getRowHeight("body",e),l=this.contentScrollTop,a=this.areaBodyCenterGeo.height;return i<l?(this.scrollToPixel(this.getViewportScrollLeft(),i),!0):r>l+a?(this.scrollToPixel(this.getViewportScrollLeft(),r-a),!0):!1}const t=this.getFirstFullVisibleRowIndex(),s=this.getLastFullVisibleRowIndex(),o=this.getDisplayedRowCount();return e<t?(this.scrollToIndex(-1,e),!0):e>s?(this.scrollToIndex(-1,e-o+1),!0):!1}ensureColumnIsVisible(e){const t=this.tableModel.getFixedLeftColumnCount(),s=this.tableModel.getColumnCount()-this.tableModel.getFixedRightColumnCount()-1;if(!(e>=t&&e<=s))return!1;const o=this.tableModel.getColumnWidth(e),i=this.scrollViewport,r=this.areaBodyCenterGeo.width,l=this.tableModel.getContentWidthInPixel()-r,a=i.scrollWidth-i.clientWidth;if(o<=0||l<=0||a<=0)return!1;let c=0;for(let f=t;f<e;f++)c+=this.tableModel.getColumnWidth(f);const h=Math.min(1,Math.max(0,this.getViewportScrollLeft()/a))*l;let d;if(c<h-.5)d=c;else if(c+o>h+r+.5)d=o>r?c:c+o-r;else return!1;const u=Math.min(1,Math.max(0,d/l))*a;return this.setViewportScrollLeft(d===c?Math.floor(u):Math.ceil(u)),this.adjustAfterScrolling(),!0}};Ge.actionsBlockedWhileLoading=["START_EDITING","TOGGLE_SELECTION","ACTIVATE_CELL","MOVE_ROW_UP","MOVE_ROW_DOWN","FILL_DOWN","FILL_RIGHT","CLEAR_CELLS","CLEAR_AND_EDIT","CUT_2_CLIPBOARD","PASTE_FROM_CLIPBOARD","UNDO","REDO"],Ge.filterAnnouncementDelayInMs=400;let Xo=Ge;class Bh extends Yt{constructor(e){super(),this.onCheckboxChangedCallback=e,super.onCheckboxChanged=t=>{this.onCheckboxChangedCallback(t)}}}const Ws=class Ws{};Ws.themes=["light","combat","paper","blackboard"],Ws.vars={light:`html[data-theme="light"] {
71
+ `).replace(/\n$/,"");class Ko{constructor(e,t,s){this.tableScope=e,this.options=t;const o=e.listenerAbortController.signal;if(s){const i=e.hostElement.ownerDocument;i.addEventListener("copy",r=>this.onClipboardEvent(r,"copy"),{signal:o}),i.addEventListener("cut",r=>this.onClipboardEvent(r,"cut"),{signal:o}),i.addEventListener("paste",r=>this.onClipboardEvent(r,"paste"),{signal:o})}e.hostElement.addEventListener("keydown",i=>{var r;i.key==="Escape"&&((r=this.memory)!=null&&r.cut)&&i.target===e.hostElement&&!e.isEditing()&&this.cancelCut()},{signal:o}),e.subscribe({onModelChanged:i=>{var r;i.source!=="cut"&&((r=this.memory)!=null&&r.cut)&&this.cancelCut()}})}isCutMarked(){var e;return!!((e=this.memory)!=null&&e.cut)}arm(e){const t=this.tableScope;if(t.isEditing()||t.getHeaderFocus()||!t.getActiveBodyCell()||e!=="paste"&&!this.hasBuiltInCopyService()||e!=="copy"&&t.isOverlayBlocking())return!1;const s=this.ensureProxy();return s.value=" ",s.select(),s.focus({preventScroll:!0}),this.armedKind=e,clearTimeout(this.restoreTimer),this.restoreTimer=setTimeout(()=>this.restoreFocus(),0),!0}getSelectionAsText(){var e;return((e=this.buildCopy(!1))==null?void 0:e.text)??""}async writeSelection(e){const t=this.buildCopy(e);if(!t)return;const s=typeof navigator<"u"?navigator.clipboard:void 0,o=globalThis.ClipboardItem;if(s!=null&&s.write&&o&&t.html)await s.write([new o({"text/plain":new Blob([t.text],{type:"text/plain"}),"text/html":new Blob([t.html],{type:"text/html"})})]);else if(s!=null&&s.writeText)await s.writeText(t.text);else return;this.remember(t,e)}async runWithoutKey(e){var t,s;try{if(e==="paste"){const o=await((s=(t=navigator.clipboard)==null?void 0:t.readText)==null?void 0:s.call(t));o&&this.paste(o)}else await this.writeSelection(e==="cut")}catch(o){console.warn("GuiExpert Table – clipboard:",o)}}paste(e,t,s){var j,_e;const o=this.tableScope,i=e?El(e):t?Tl(t):[];if(!i.length||!i[0].length)return[];const r=this.memory&&e&&Tr(e)===this.memory.text?this.memory:void 0,l=r==null?void 0:r.cut,a=o.tableModel.getBodyModel(),c=a.getRowCount(),h=this.getPasteColumns(),d=this.getPasteAnchor(h,s);if(!d||!h.length)return[];const[u,f]=d,g=l?void 0:d[2],p=i[0].length,m=h.indexOf(f),b=h[Math.min(h.length-1,m+p-1)],y=o.isBatchEditActive();let C=r&&!y?r.values:r?i.map((H,O)=>H.map((ue,te)=>{var F;return((F=r.values[O])==null?void 0:F[te])instanceof Jt?r.values[O][te]:ue})):i,v=!!r&&!y;const E=this.options.processPaste;if(E){const H={text:e,html:t,matrix:i,target:new M(u,f,u+i.length-1,b),internal:!!r},O=E(H);if(O===!1)return[];Array.isArray(O)&&(C=O,v=!1)}const S=this.options.maxPasteCells,R=Li(C.length,C.reduce((H,O)=>Math.max(H,O.length),0),g);if(R.rows*R.columns>S)return o.announce(o.getSheetTexts().pasteTooLarge(S)),[];const L=this.options.pasteAddsRows&&!!this.options.createRow&&!y&&this.canAppendRows(),x=((_e=(j=o.tableModel).getColumnDefs)==null?void 0:_e.call(j))??[],D=Il({matrix:C,anchorRow:u,anchorColumn:f,shownColumns:h,rowCount:c,selection:g,canAddRows:L,isWritable:(H,O)=>a.isEditable(H,O)&&!N(x[O])});if(D.addRows&&this.appendRows(D.addRows),r)for(const H of D.cells)H.value=o.resolvePastedValue(H.value,H.rowIndex,H.columnIndex,!!l);const k=[];let P="paste";if(l){P="cut";const H=new Map(h.map((te,F)=>[te,F])),O=[],ue=new Set;for(const{rowIndex:te,columnIndex:F,value:Y}of D.cells){const Vt=v?Y:this.convertPastedText(Y,te,F);o.checkPastedValue(te,F,Vt,v)||(k.push({rowIndex:te,column:F,value:Vt}),O.push([te-u,H.get(F)-m]),ue.add(`${te}:${F}`))}for(const te of this.cutSourceChanges(l,O,ue))k.push(te)}else for(const{rowIndex:H,columnIndex:O,value:ue}of D.cells)k.push({rowIndex:H,column:O,value:v?ue:this.convertPastedText(ue,H,O)});const V=k.length?o.writePastedCells(k,P,v):[];l&&(this.memory=void 0,this.removeCutFrame()),D.addRows&&o.repaintHard();let $=V.length;if(l){const H=new Set(D.cells.map(O=>`${O.rowIndex}:${O.columnIndex}`));$=V.filter(O=>H.has(`${O.rowIndex}:${O.columnIndex}`)).length}return o.selectBodyRange(D.range),o.announce(o.getSheetTexts().cellsPasted($,D.skipped+D.clipped+Math.max(0,D.cells.length-$))),V}cancelCut(){var e;(e=this.memory)!=null&&e.cut&&(this.memory={...this.memory,cut:void 0}),this.removeCutFrame()}update(){var u;const e=(u=this.memory)==null?void 0:u.cut,t=this.cutFrame;if(!e||!t)return;const s=this.tableScope,o=s.tableModel.getBodyModel(),{range:i}=e;if(i.r2>=o.getRowCount()||this.rowObjectAt(i.r1)!==e.rows[0]||this.rowObjectAt(i.r2)!==e.rows[e.rows.length-1]){this.removeCutFrame();return}const r=s.getBodyCellRectInHost(i.r1,i.c1),l=s.getBodyCellRectInHost(i.r2,i.c2),a=Math.max(r.top,r.clipTop),c=Math.min(l.top+l.height,l.clipBottom),h=Math.max(r.left,r.clipLeft),d=Math.min(l.left+l.width,l.clipRight);s.getDomService().applyStyle(t,{display:c>a&&d>h?"block":"none",left:`${h}px`,top:`${a}px`,width:`${Math.max(0,d-h)}px`,height:`${Math.max(0,c-a)}px`})}destroy(){var e;clearTimeout(this.restoreTimer),(e=this.proxy)==null||e.remove(),this.proxy=void 0,this.removeCutFrame(),this.memory=void 0}onClipboardEvent(e,t){var a;const s=this.tableScope,o=s.hostElement,i=typeof e.composedPath=="function"?e.composedPath()[0]:e.target,r=!!this.proxy&&i===this.proxy;if(!r&&(Ir(o)!==o||s.isEditing()||(a=s.isEventInDetail)!=null&&a.call(s,e))||!r&&(s.getHeaderFocus()||!s.getActiveBodyCell())||t!=="paste"&&!this.hasBuiltInCopyService())return;const l=e.clipboardData;try{if(!l||(e.preventDefault(),t!=="copy"&&s.isOverlayBlocking()))return;if(t==="paste")this.paste(l.getData("text/plain"),l.getData("text/html")||void 0);else{const c=this.buildCopy(t==="cut");c&&(l.setData("text/plain",c.text),c.html&&l.setData("text/html",c.html),this.remember(c,t==="cut"))}}finally{(r||this.armedKind)&&this.restoreFocus()}}restoreFocus(){clearTimeout(this.restoreTimer),this.armedKind=void 0;const e=this.proxy;e&&(e.value="",Ir(e)===e&&this.tableScope.hostElement.focus({preventScroll:!0}))}ensureProxy(){if(!this.proxy||!this.proxy.isConnected){const e=this.tableScope.getDomService().domService,t=e.createElement("textarea");e.addClass(t,"ge-table-clipboard-proxy"),e.setAttribute(t,"aria-hidden","true"),e.setAttribute(t,"tabindex","-1"),e.setAttribute(t,"autocomplete","off"),e.appendChild(this.tableScope.hostElement,t),this.proxy=t}return this.proxy}remember(e,t){var r;const s=this.tableScope;this.cancelCut(),this.memory=e.processed?void 0:{text:Tr(e.text),values:e.values,cut:t?{range:e.range,columns:e.columns,rows:this.rowObjectsOf(e.range)}:void 0},(r=this.memory)!=null&&r.cut&&this.showCutFrame();const o=s.getSheetTexts(),i=t?o.cutMarked(e.cellCount):s.ariaTexts.copied(e.cellCount);s.announce(e.lastRangeOnly?`${i}. ${o.copiedLastRangeOnly()}`:i)}buildCopy(e){var E;const t=this.tableScope,s=t.tableModel,o=s.getBodyModel(),i=o.getRowCount(),r=s.getColumnCount();if(!i||!r)return;const l=t.selectionModel();let a,c=!1;if(l!=null&&l.isAllSelected())a=new M(0,0,i-1,r-1);else if(l!=null&&l.hasSelection()&&l.getRanges().length){const S=l.getRanges(),R=S[S.length-1];c=S.length>1,a=new M(Math.max(0,R.r1),Math.max(0,R.c1),Math.min(i-1,R.r2),Math.min(r-1,R.c2))}else{const S=t.getActiveBodyCell();a=S?M.singleCell(S[0],S[1]):void 0}if(!a||a.r2<a.r1||a.c2<a.c1)return;const h=[];for(let S=a.c1;S<=a.c2;S++){const R=s.getColumnDef(S);((E=R==null?void 0:R.isVisible)==null?void 0:E.call(R))===!1||s.getColumnWidth(S)<=0||N(R)&&!R.options.exported||h.push(S)}const d=(a.r2-a.r1+1)*h.length;if(!h.length)return;if(d>Se.maxCopyCells){t.announce(t.getSheetTexts().copyTooLarge(Se.maxCopyCells));return}const u=this.options.copyValue==="raw",f=!!(l!=null&&l.hasSelection())&&!l.isAllSelected(),g=[],p=[],m=[];if(this.options.copyHeaders&&!e){const S=h.map(R=>t.getColumnAriaLabel(R));g.push(S),p.push(S),m.push(S.map(R=>({text:R})))}for(let S=a.r1;S<=a.r2;S++){const R=[],L=[],x=[];for(const D of h){const k=s.getColumnDef(D);let P,V;if(f&&!l.isSelected(S,D))P="",V="";else if(N(k))P=k.getRowNumberText(S,o),V=P;else{V=t.getCopyValue(S,D);const j=V instanceof Jt?V.value:V;P=u||j===null||j===void 0||j instanceof Date?kh(j):o.getTextValueAt(S,D)}R.push(P),L.push(V);const $=V instanceof Jt?V.value:V;x.push(typeof $=="number"?{text:P,num:$}:{text:P})}g.push(R),p.push(L),m.push(x)}let b=g,y=!1;if(this.options.processCopy){const S=this.options.processCopy({ranges:[a],matrix:g,cut:e});Array.isArray(S)&&(b=S,y=!0)}const C=Al(b),v=this.options.html?Ml(y?b.map(S=>S.map(R=>({text:R}))):m):void 0;return{text:C,html:v,values:p,range:a,columns:h,cellCount:d,lastRangeOnly:c,processed:y}}getPasteColumns(){var o;const e=this.tableScope.tableModel,t=[],s=e.getColumnCount();for(let i=0;i<s;i++){const r=e.getColumnDef(i);e.getColumnWidth(i)>0&&((o=r==null?void 0:r.isVisible)==null?void 0:o.call(r))!==!1&&!N(r)&&t.push(i)}return t}getPasteAnchor(e,t){const s=this.tableScope,o=s.tableModel.getBodyModel().getRowCount(),i=h=>e.find(d=>d>=h);if(t){const h=i(t[1]);return h===void 0||t[0]<0||t[0]>=o?void 0:[t[0],h,void 0]}const r=s.selectionModel();let l;if(r!=null&&r.isAllSelected())l=new M(0,0,o-1,Number.MAX_SAFE_INTEGER);else if(r!=null&&r.hasSelection()&&r.getRanges().length){const h=r.getRanges();l=h[h.length-1]}if(l){const h=Math.max(0,l.r1),d=Math.min(o-1,l.r2),u=i(Math.max(0,l.c1));if(u!==void 0&&d>=h){const f=e.filter(g=>g>=l.c1&&g<=l.c2).length;return[h,u,{rows:d-h+1,columns:f}]}}const a=s.getActiveBodyCell();if(!a)return;const c=i(a[1]);return c===void 0?void 0:[a[0],c,void 0]}convertPastedText(e,t,s){if(typeof e!="string")return e;const o=this.tableScope,i=o.tableModel.getColumnDef(s);if(i!=null&&i.editInputPipe)return e;const r=t<o.tableModel.getBodyModel().getRowCount()?o.getTypedCellValue(t,s):void 0,l=e.trim();if(typeof r=="number"||(i==null?void 0:i.editor)==="number")return l!==""&&/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(l)?Number(l):e;if(typeof r=="boolean"){const a=l.toUpperCase();return a==="TRUE"?!0:a==="FALSE"?!1:e}if(r instanceof Date){const a=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/.exec(l);return a?a[4]===void 0?new Date(+a[1],+a[2]-1,+a[3],r.getHours(),r.getMinutes(),r.getSeconds()):new Date(+a[1],+a[2]-1,+a[3],+a[4],+a[5],+(a[6]??0)):e}return e}cutSourceChanges(e,t,s){var a;const o=this.tableScope,i=o.tableModel.getBodyModel(),r=this.rowIndexLookup(e),l=[];for(const[c,h]of t){if(c<0||h<0||c>=e.rows.length||h>=e.columns.length)continue;const d=r(c);if(d<0)continue;const u=e.columns[h],f=o.tableModel.getColumnDef(u);if(s.has(`${d}:${u}`)||N(f)||!i.isEditable(d,u))continue;const g=(f==null?void 0:f.emptyValue)!==void 0?f.emptyValue:((a=o.getEditingOptions())==null?void 0:a.emptyValue)??"";l.push({rowIndex:d,column:u,value:g})}return l}rowIndexLookup(e){const t=this.tableScope.tableModel.getBodyModel().getRowCount(),s=e.rows.every(r=>r!==null&&typeof r=="object"),o=e.rows.every((r,l)=>this.rowObjectAt(e.range.r1+l)===r);if(!s||o)return r=>e.range.r1+r<t?e.range.r1+r:-1;const i=new Map;for(let r=0;r<t;r++)i.set(this.rowObjectAt(r),r);return r=>i.get(e.rows[r])??-1}hasBuiltInCopyService(){const e=this.tableScope.copyService;return!!e&&Object.getPrototypeOf(e)===Se.prototype}rowObjectAt(e){const t=this.tableScope.tableModel.getBodyModel().getRowByIndex(e);return U(t)?t.data:t}rowObjectsOf(e){const t=[];for(let s=e.r1;s<=e.r2;s++)t.push(this.rowObjectAt(s));return t}canAppendRows(){const e=this.tableScope.tableModel.getBodyModel();return typeof e.getAllRows=="function"&&typeof e.getFilteredRows=="function"&&!this.tableScope.isRowGroupingOrTree()}appendRows(e){const t=this.tableScope.tableModel.getBodyModel(),s=t.getAllRows(),o=t.getFilteredRows(),i=o.length;for(let r=0;r<e;r++){const l=this.options.createRow(i+r);s.push(l),o!==s&&o.push(l)}this.tableScope.rowsAppended()}showCutFrame(){if(!this.cutFrame){const e=this.tableScope.getDomService();this.cutFrame=e.setAriaHidden(e.createDivWithClass("ge-table-cut-range",this.tableScope.hostElement))}this.update()}removeCutFrame(){var e;(e=this.cutFrame)==null||e.remove(),this.cutFrame=void 0}}function Ir(n){return n.getRootNode().activeElement??null}function kh(n){if(n==null)return"";if(n instanceof Date){if(Number.isNaN(n.getTime()))return"";const e=o=>String(o).padStart(2,"0"),t=`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())}`,s=n.getHours()||n.getMinutes()||n.getSeconds()?`T${e(n.getHours())}:${e(n.getMinutes())}:${e(n.getSeconds())}`:"";return t+s}return typeof n=="boolean"?n?"TRUE":"FALSE":typeof n=="object"?"":String(n)}function Dl(n){return n?{"meta+z":"UNDO","meta+shift+z":"REDO"}:{"ctrl+z":"UNDO","ctrl+y":"REDO","ctrl+shift+z":"REDO"}}class uo{constructor(){this.maxSteps=100,this.maxCells=1e6,this.onConflict="skip",this.recordApiChanges=!1}static create(e){if(!e)return;const t=new uo;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class kl{constructor(e,t){this.maxSteps=e,this.maxCells=t,this.undoSteps=[],this.redoSteps=[],this.cells=0}push(e){if(this.clearRedo(),e.cellCount>this.maxCells||this.maxSteps<1)return this.clear(),!1;for(this.undoSteps.push(e),this.cells+=e.cellCount;this.undoSteps.length>this.maxSteps||this.cells>this.maxCells;)this.cells-=this.undoSteps.shift().cellCount;return!0}undo(){const e=this.undoSteps.pop();return e&&this.redoSteps.push(e),e}redo(){const e=this.redoSteps.pop();return e&&this.undoSteps.push(e),e}peekUndo(){return this.undoSteps[this.undoSteps.length-1]}peekRedo(){return this.redoSteps[this.redoSteps.length-1]}canUndo(){return this.undoSteps.length>0}canRedo(){return this.redoSteps.length>0}size(){return this.undoSteps.length}cellCount(){return this.cells}clear(){this.undoSteps.length=0,this.redoSteps.length=0,this.cells=0}clearRedo(){for(const e of this.redoSteps)this.cells-=e.cellCount;this.redoSteps.length=0}}function Fl(n){var t,s;const e=n;return Z(n)?e.rows:((t=e.getAllRows)==null?void 0:t.call(e))??((s=e.getSourceRows)==null?void 0:s.call(e))??e.arr}function Fh(n){if(Z(n)){const t=new Set,s=o=>o==null?void 0:o.forEach(i=>{const r=i;t.add(r.data??r),s(r.children)});return s(n.rows),t}const e=Fl(n);return e?new Set(e):null}class jo{constructor(e,t,s){this.label=e,this.source=t,this.entries=s.map(o=>({row:o.row,rowIndex:o.rowIndex,columnIndex:o.columnIndex,property:o.property,oldValue:o.oldValue,newValue:o.newValue}))}get cellCount(){return this.entries.length}append(e){for(const t of e)this.entries.push({row:t.row,rowIndex:t.rowIndex,columnIndex:t.columnIndex,property:t.property,oldValue:t.oldValue,newValue:t.newValue})}undo(e){return this.apply(e,"undo")}redo(e){return this.apply(e,"redo")}apply(e,t){var C;const s=e.tableModel,o=s.getBodyModel(),i=o.getRowCount(),r=((C=e.getUndoOptions())==null?void 0:C.onConflict)==="overwrite",l=v=>{const E=o.getRowByIndex(v);return U(E)?E.data:E};let a,c;const h=v=>{if(v.row===void 0||v.row===null||typeof v.row!="object")return v.rowIndex>=0&&v.rowIndex<i?v.rowIndex:-1;if(v.rowIndex>=0&&v.rowIndex<i&&l(v.rowIndex)===v.row)return v.rowIndex;if(!a){a=new Map;for(let E=0;E<i;E++)a.set(l(E),E)}return a.get(v.row)??-1},d=v=>(c===void 0&&(c=Fh(o)),!!c&&c.has(v)),u=v=>{var E;return!!v&&(zr(v)?!!o.defaultEditable:!!((E=v.editable)!=null&&E.call(v)))},f=[],g=[];let p=0;const m=t==="undo"?[...this.entries].reverse():this.entries;for(const v of m){const E=t==="undo"?v.newValue:v.oldValue,S=t==="undo"?v.oldValue:v.newValue,R=Lh(e,v);if(R<0){p++;continue}const L=h(v);if(L>=0){if(!o.isEditable(L,R)||!r&&!Dt(e.getCellInput(L,R),E)){p++;continue}f.push({rowIndex:L,columnIndex:R,value:S});continue}const x=s.getColumnDef(R),D=d(v.row)?Oh(v.row,x,R,E):void 0;if(!d(v.row)||!u(x)||!r&&!Dt(D,E)||!Kn(v.row,x,R,S)){p++;continue}g.push({row:v.row,rowIndex:-1,columnIndex:R,property:v.property,oldValue:D,newValue:S})}const b=e.writeUndoCells(f,g,t);let y;for(const v of b)v.rowIndex<0||(y?(y.r1=Math.min(y.r1,v.rowIndex),y.r2=Math.max(y.r2,v.rowIndex),y.c1=Math.min(y.c1,v.columnIndex),y.c2=Math.max(y.c2,v.columnIndex)):y=new M(v.rowIndex,v.columnIndex,v.rowIndex,v.columnIndex));return{applied:b.length,skipped:p+f.length+g.length-b.length,range:y}}}function Lh(n,e){const t=n.tableModel,s=i=>{var r;return((r=t.getColumnDef(i))==null?void 0:r.property)||`#${i}`};if(e.columnIndex>=0&&e.columnIndex<t.getColumnCount()&&s(e.columnIndex)===e.property)return e.columnIndex;const o=t.getColumnCount();for(let i=0;i<o;i++)if(s(i)===e.property)return i;return-1}function Oh(n,e,t,s){if(Array.isArray(n))return n[t];if(!(e!=null&&e.property)||n===null||typeof n!="object")return;if(e.valueGetter)return s;let o=n;for(const i of e.property.split("."))o=o==null?void 0:o[i];return o}class Ll{constructor(e,t,s){this.label=e,this.source=t,this.cells=s}get cellCount(){return this.cells.length}undo(e){return this.apply(e,"undo")}redo(e){return this.apply(e,"redo")}apply(e,t){var c;const s=e.batchEditService;if(!s)return{applied:0,skipped:this.cells.length};const o=((c=e.getUndoOptions())==null?void 0:c.onConflict)==="overwrite",i=[];let r=0;for(const h of this.cells){const d=t==="undo"?h.after:h.before,u=t==="undo"?h.before:h.after,f=s.getPendingEntry(h.rowKey,h.property);if(!(!f&&!d?!0:!!f&&!!d&&Dt(f.newValue,d.newValue))&&!o){r++;continue}i.push({rowKey:h.rowKey,property:h.property,entry:u})}const l=s.restorePending(i,!1);let a;for(const h of l)h.rowIndex<0||h.columnIndex<0||(a=a?new M(Math.min(a.r1,h.rowIndex),Math.min(a.c1,h.columnIndex),Math.max(a.r2,h.rowIndex),Math.max(a.c2,h.columnIndex)):new M(h.rowIndex,h.columnIndex,h.rowIndex,h.columnIndex));return e.repaint(),{applied:l.length,skipped:r,range:a}}}class Ol{constructor(e,t,s,o,i){this.canUndo=e,this.canRedo=t,this.undoLabel=s,this.redoLabel=o,this.size=i}}const Dr={edit:"Edit",fill:"Fill",paste:"Paste",cut:"Cut",clear:"Clear",api:"Change"};class Nh{constructor(e,t){this.label=e,this.steps=t,this.source=t[0].source}get cellCount(){return this.steps.reduce((e,t)=>e+t.cellCount,0)}undo(e){return kr([...this.steps].reverse().map(t=>t.undo(e)))}redo(e){return kr(this.steps.map(t=>t.redo(e)))}}function kr(n){let e;for(const t of n)t.range&&(e=e?new M(Math.min(e.r1,t.range.r1),Math.min(e.c1,t.range.c1),Math.max(e.r2,t.range.r2),Math.max(e.c2,t.range.c2)):t.range);return{applied:n.reduce((t,s)=>t+s.applied,0),skipped:n.reduce((t,s)=>t+s.skipped,0),range:e}}class Nl{constructor(e,t){this.tableScope=e,this.options=t,this.running=!1,this.foldDepth=0,this.stack=new kl(t.maxSteps,t.maxCells)}addStep(e){this.running||this.add(e)}record(e,t,s){if(this.running||t==="undo"||t==="redo"||!e.length||s===!1)return;if(this.folding instanceof jo&&t!=="commit"){this.folding.append(e),this.lastRecorded=this.folding;return}if(t==="commit"){this.clear();return}if(t==="api"&&!(s??this.options.recordApiChanges))return;const o=new jo(Dr[t]??"Change",t,e);this.lastRecorded=o,this.add(o)}beginFold(){this.foldDepth++===0&&(this.folding=this.lastRecorded)}endFold(){--this.foldDepth<=0&&(this.foldDepth=0,this.folding=void 0,this.lastRecorded=void 0)}recordPending(e,t,s){this.running||!e.length||s===!1||t==="api"&&!(s??this.options.recordApiChanges)||this.add(new Ll(Dr[t]??"Change",t,e))}batch(e,t){this.group?this.group.depth++:this.group={label:e,steps:[],depth:1};let s=!0;try{const o=t();return s=!1,o}finally{const o=this.group;--o.depth===0&&(this.group=void 0,o.steps.length&&!s&&this.add(o.steps.length===1&&o.steps[0].label===o.label?o.steps[0]:new Nh(o.label,o.steps)))}}undo(){return this.run("undo")}redo(){return this.run("redo")}canUndo(){return this.checkRows(!1),this.stack.canUndo()}canRedo(){return this.checkRows(!1),this.stack.canRedo()}getState(){var e,t;return this.checkRows(!1),new Ol(this.stack.canUndo(),this.stack.canRedo(),(e=this.stack.peekUndo())==null?void 0:e.label,(t=this.stack.peekRedo())==null?void 0:t.label,this.stack.size())}clear(e=!1){const t=this.stack.canUndo()||this.stack.canRedo();this.stack.clear(),this.rowsRef=void 0,this.lastRecorded=void 0,this.group&&(this.group.steps.length=0),t&&!e&&this.fire()}add(e){if(this.group){this.group.steps.push(e);return}if(this.checkRows(),this.rowsRef??(this.rowsRef=this.currentRows()),!this.stack.push(e)){const t=this.tableScope;t.announce(t.getUndoTexts().undoHistoryCleared(this.options.maxCells))}this.fire()}run(e){const t=this.tableScope;if(t.isEditing()||this.group)return!1;this.checkRows();const s=e==="undo"?this.stack.undo():this.stack.redo(),o=t.getUndoTexts();if(!s)return t.announce(e==="undo"?o.nothingToUndo():o.nothingToRedo()),!1;let i;this.running=!0;try{i=e==="undo"?s.undo(t):s.redo(t)}finally{this.running=!1}i.range&&(t.selectBodyRange(i.range),t.ensureColumnIsVisible(i.range.c1),t.ensureRowIsVisible(i.range.r1));const r=e==="undo"?o.undone(s.label,i.applied):o.redone(s.label,i.applied);return t.announce(i.skipped?`${r}. ${o.undoSkipped(i.skipped)}`:r),this.fire(),!0}checkRows(e=!0){this.rowsRef&&this.currentRows()!==this.rowsRef&&this.clear(!e)}currentRows(){return Fl(this.tableScope.tableModel.getBodyModel())}fire(){var e,t;(t=(e=this.tableScope.getEventListener()).onUndoStackChanged)==null||t.call(e,this.getState())}}function Pl(n,e,t,s,o,i,r,l=()=>!0){const a=(d,u)=>{const f=d+i;let g=u+r;for(;r!==0&&g>=0&&g<t&&!l(g);)g+=r;return f>=0&&f<e&&g>=0&&g<t?[f,g]:void 0};let c=a(s,o);if(!c)return[s,o];if(!n(s,o)&&!n(c[0],c[1])){let d=c;for(let u=a(d[0],d[1]);u&&!n(u[0],u[1]);u=a(u[0],u[1]))d=u;return d}let h=c;for(;n(c[0],c[1]);){const d=a(c[0],c[1]);if(!d)return h;h=c=d}return c}function Ph(n,e){return new Proxy(n,{get(t,s,o){const i=Reflect.get(t,s,o);return typeof s!="string"||!s.startsWith("on")||!e.size?i:(...r)=>{const l=typeof i=="function"?i.apply(t,r):void 0;for(const a of Array.from(e)){const c=a[s];if(typeof c=="function")try{c.apply(a,r)}catch(h){console.error(h)}}return l}}})}function Ze(n,e){const t=n==null?void 0:n[e],s=n==null?void 0:n.spreadsheet;if(t!==void 0||!s)return t;const o=typeof s=="object"?s[e]:void 0;if(o!==!1)return e==="editing"?{defaultEditable:!0,...typeof o=="object"?o:{}}:o??!0}function Vh(n){if(!(n!=null&&n.spreadsheet))return n;const e={...n};for(const t of["editing","clipboard","undo","cellFormulas","fillHandle"])e[t]=Ze(n,t);return e}class Vl{constructor(e=[],t=[]){this.removed=e,this.inserted=t,this.insertBefore=new Int32Array(t.length);for(let s=0;s<t.length;s++)this.insertBefore[s]=t[s]-s}isEmpty(){return this.removed.length===0&&this.inserted.length===0}getRemovedCount(){return this.removed.length}getInsertedCount(){return this.inserted.length}touchesUpTo(e){return this.removed.length&&this.removed[0]<=e?!0:this.insertBefore.length>0&&this.insertBefore[0]<=e}mapIndex(e){if(e<0)return-1;const t=ys(this.removed,e);if(t<this.removed.length&&this.removed[t]===e)return-1;const s=e-t;return s+Mo(this.insertBefore,s)}mapIndexOrNext(e){const t=Math.max(0,e-ys(this.removed,e));return t+Mo(this.insertBefore,t)}mapRange(e,t){e>t&&([e,t]=[t,e]);const s=t>=Number.MAX_SAFE_INTEGER,o=e-ys(this.removed,e),i=s?Number.MAX_SAFE_INTEGER:t-ys(this.removed,t+1);if(i<o)return[];const r=[];let l=o,a=Mo(this.insertBefore,o);for(let c=a;c<this.insertBefore.length&&this.insertBefore[c]<=i;c++){const h=this.insertBefore[c];h>l&&(r.push([l+a,h-1+a]),l=h),a++}return r.push([l+a,s?Number.MAX_SAFE_INTEGER:i+a]),r}}function ys(n,e){let t=0,s=n.length;for(;t<s;){const o=t+s>>>1;n[o]<e?t=o+1:s=o}return t}function Mo(n,e){let t=0,s=n.length;for(;t<s;){const o=t+s>>>1;n[o]<=e?t=o+1:s=o}return t}class fo{constructor(){this.doubleClick=!0,this.maxRows=1e4}static create(e){return{...new fo,...e??{}}}}const Gi=class Gi{constructor(e){this.ctx=null;const t=e.querySelector(".ge-table-label"),s=getComputedStyle(t??e);this.padding=t?(parseFloat(s.paddingLeft)||0)+(parseFloat(s.paddingRight)||0):20;try{this.ctx=document.createElement("canvas").getContext("2d")}catch{this.ctx=null}this.ctx&&(this.ctx.font=s.font||`${s.fontSize} ${s.fontFamily}`)}measureText(e){const t=this.ctx?this.ctx.measureText(e).width:e.length*8;return Math.ceil(t+this.padding+2)}measureWidest(e){let t=this.measureText("");return e.forEach(s=>{t=Math.max(t,this.measureText(s))}),Math.max(t,50)}};Gi.maxCandidates=30;let ot=Gi;function _h(n,e,t,s,o,i){var l,a;if(!n)return;const r=ot.maxCandidates;for(let c=e;c<=t;c++)for(let h=0;h<s.length;h++){const d=s[h],u=((l=n.getTextValueAt)==null?void 0:l.call(n,c,d))||(((a=n.getValueAt(c,d))==null?void 0:a.toString())??""),f=u.length;f>i[h]&&(i[h]=f,o[h].forEach(g=>{g.length<f-2&&o[h].delete(g)})),f>=i[h]-2&&o[h].size<r&&o[h].add(u)}}class _l{constructor(e,t,s,o,i,r,l,a){this.type=e,this.source=t,this.columnIndex=s,this.columnDef=o,this.property=i,this.oldWidth=r,this.newWidth=l,this.originalEvent=a}}class Bl{constructor(e,t,s,o,i,r,l){this.type=e,this.fromIndex=t,this.toIndex=s,this.columnDef=o,this.property=i,this.columnOrder=r,this.originalEvent=l}get moved(){return this.toIndex!==this.fromIndex}}const Ge=class Ge extends Mn{constructor(e,t,s,o,i,r=new Se,l=new Hn){var u;if(super(e,t,new As(s),o),this.eventListener=i,this.copyService=r,this.excelService=l,this.licenseManager=Qe.getInstance(),this.listenerAbortController=new AbortController,this.destroyed=!1,this.selectionService=new fe(this),this.api=new mn(this),this.initialized=!1,this.mouseStartAction="",this.mouseStartWidth=-1,this.mouseStartColumnIndex=-1,this.dragFrom=-1,this.lastDragFrom=-1,this.lastDragTo=-1,this.firstDraggingRendering=!0,this.editingOptions=lo.create(Ze(this.tableOptions,"editing")),this.subscribers=new Set,this.clipboardOptions=ls.create(Ze(this.tableOptions,"clipboard")),this.undoOptions=uo.create(Ze(this.tableOptions,"undo")),this.lastTabKeyTime=0,this.lastContextmenu=Date.now(),this.allExpanded=!0,this.selectionEventsHeld=0,t.setTableScope(this),this.liveAnnouncer=new Fs(e.ownerDocument,this.ariaIds.liveRegion(),s),this.eventListener=Ph(i??new Yt,this.subscribers),this.stateService=new ks(this),this.mouseHandler=new Wr(this),this.inputHandler=new Fn(this),this.resizeHandler=new $n(this,o.resizeEventDebounceDelay),this.shortcutService=new Vn(this),this.rowDragService=new Wn(this),this.batchEditService=new jn(this),this.fillHandleService=new il(this),this.editingOptions){this.cellEditorService=new gl(this,this.editingOptions);const f=t.getBodyModel();this.editingOptions.defaultEditable&&"defaultEditable"in f&&(f.defaultEditable=!0),this.setHostAriaAttribute("aria-description",this.getSheetTexts().gridEditingHint())}this.clipboardOptions&&(this.clipboardService=new Ko(this,this.clipboardOptions,!0)),this.undoOptions&&(this.undoService=new Nl(this,this.undoOptions));const a=kt.create(Ze(o,"cellFormulas"));if(a&&(o.masterDetail?console.warn("GuiExpert Table – cellFormulas: no cell formulas with master/detail."):this.tableSheet=ho.create(t,a)),o!=null&&o.masterDetail&&(this.masterDetailService=new rl(this,(f,g,p,m)=>new Ge(f,g,new $o,this.nestedTableOptions(p),m??new Yt)),this.masterDetailService.isActive())){const f=(e.getAttribute("aria-owns")??"").split(" ").filter(Boolean),g=f.findIndex(p=>p.startsWith(this.ariaIds.rowGroup("footer","west")));f.splice(g<0?f.length:g,0,this.ariaIds.detailRowGroup()),this.setHostAriaAttribute("aria-owns",f.join(" ")),this.setHostAriaAttribute("role","treegrid")}this.shortcutService.addListener(this.selectionService);const c=this.getSelectionModel?this.getSelectionModel():void 0;c&&c.addEventSelectionChangedListener(this);const h=this.getFocusModel?this.getFocusModel():void 0;h&&h.addEventFocusChangedListener(this);const d=this.listenerAbortController.signal;(u=e.ownerDocument)==null||u.addEventListener("keydown",f=>{f.key==="Tab"&&(this.lastTabKeyTime=Date.now())},{capture:!0,signal:d}),e.addEventListener("focus",()=>this.onHostKeyboardFocus(),{signal:d}),this.scrollViewport.addEventListener("focus",()=>this.hostElement.focus({preventScroll:!0}),{signal:d})}nestedTableOptions(e){return e?e.direction!==void 0||!this.isRtl()?e:Object.assign(Object.create(e),{direction:this.direction}):{...new je,direction:this.direction}}onHostKeyboardFocus(){const e=Date.now()-this.lastTabKeyTime<1e3,t=this.focusModel();if(!e||!t||this.headerFocus||this.isEditing())return;const[s,o]=t.getFocus(),i=this.tableModel.getBodyModel().getRowCount();if((s<0||o<0)&&i>0&&this.tableModel.getColumnCount()>0){const r=this.firstFullVisibleRowIndex>=0?this.firstFullVisibleRowIndex:Math.max(0,this.getBodyRowIndexAtY(this.contentScrollTop));this.setFocusCell(r,this.getFirstShownColumnIndex())}else i<1&&this.getAriaGridInfo().headerRowCount>0&&this.tableModel.getColumnCount()>0&&this.setHeaderFocus(this.getAriaGridInfo().headerRowCount-1,this.getFirstShownColumnIndex())}static create(e,t,s=new je,o=new Yt,i=new $o,r=new Se){return new Ge(e,t,i,s,o,r)}onActionTriggered(e){var o;if(!this.headerFocus&&this.tableOverlay.isBlocking()&&Ge.actionsBlockedWhileLoading.includes(e))return!0;if(this.headerFocus){const i=this.onHeaderAction(e);if(i!==void 0)return i}if(e==="FILL_DOWN"||e==="FILL_RIGHT")return!this.headerFocus&&this.fillByKeyboard(e==="FILL_DOWN"?"down":"right");const t=this.onSheetAction(e);if(t!==void 0)return t;if(e==="MOVE_ROW_UP"||e==="MOVE_ROW_DOWN")return!this.headerFocus&&!!((o=this.rowDragService)!=null&&o.moveByKeyboard(e==="MOVE_ROW_UP"?-1:1));if(e==="NAVIGATE_UP"&&this.moveFocusIntoHeader())return!0;const s=this.onBodyNavigation(e);if(s!==void 0)return s;if(e==="NAVIGATE_DOWN"&&this.changeFocusCell(0,1)||e==="NAVIGATE_UP"&&this.changeFocusCell(0,-1)||e==="NAVIGATE_LEFT"&&this.changeFocusCell(-1,0)||e==="NAVIGATE_RIGHT"&&this.changeFocusCell(1,0))return!0;if(e==="START_EDITING"&&this.getFocusModel){const i=this.getFocusModel();if(i){const[r,l]=i.getFocus();this.tableModel.getBodyModel().isEditable(r,l)&&this.startEditing(r,l,"edit","end")}return!0}if(this.undoService&&(e==="UNDO"||e==="REDO"))return e==="UNDO"?this.undoService.undo():this.undoService.redo(),!0;if(this.clipboardService&&this.clipboardOptions&&(e==="COPY_2_CLIPBOARD"||e==="CUT_2_CLIPBOARD"||e==="PASTE_FROM_CLIPBOARD")){const i=e==="COPY_2_CLIPBOARD"?"copy":e==="CUT_2_CLIPBOARD"?"cut":"paste";if(this.shortcutKeyEvent){if(this.clipboardService.arm(i)||i!=="copy")return!1}else if(i!=="copy"||Object.getPrototypeOf(this.copyService)===Se.prototype)return this.clipboardService.runWithoutKey(i),!0}if(e==="COPY_2_CLIPBOARD"){const i=this.getSelectionModel?this.getSelectionModel():void 0,r=this.getFocusModel?this.getFocusModel():void 0;this.copyService.createContent(this.tableModel,i,r).then(l=>this.copyService.copyContent(l).then(()=>this.announceCopied(l))).catch(l=>console.warn("GuiExpert Table – copy to clipboard failed:",l))}return!1}getEditingOptions(){return this.editingOptions}getShortcutLayers(e){const t=[],s=this.editingOptions;if(this.clipboardOptions&&t.push(ml(e)),this.undoOptions&&t.push(Dl(e)),!s)return t;const o=pl(e);return s.tabMoves||(delete o.tab,delete o["shift+tab"]),s.clearKeys||(delete o.delete,delete o.backspace),[o,...t]}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}startEditing(e,t,s="edit",o){var r,l,a;if((r=this.cellEditorService)!=null&&r.handlesColumn(t))return this.cellEditorService.start(e,t,{mode:s,textSelection:o});if(!this.tableModel.getBodyModel().isEditable(e,t))return!1;this.clearSelection(),this.initRenderEditor(e,t);const i=this.getInCellEditorCell();return i&&((a=(l=this.eventListener).onEditingChanged)==null||a.call(l,new yt("start",e,t,s))),!!i}canStartEditing(){var e,t;return!this.isDestroyed()&&!this.headerFocus&&!this.tableOverlay.isBlocking()&&!((e=this.rowDragService)!=null&&e.isDragging())&&!((t=this.fillHandleService)!=null&&t.isFilling())&&!this.editing}getShownCellValue(e,t){return this.batchEditService?this.batchEditService.getShownValue(e,t):this.getCellInput(e,t)}getActiveBodyCell(){const e=this.focusModel();if(!e||this.headerFocus)return;const[t,s]=e.getFocus(),o=this.tableModel.getBodyModel().getRowCount();return t>=0&&s>=0&&t<o&&s<this.tableModel.getColumnCount()?[t,s]:void 0}refreshAfterStructureChange(e){var r,l;const t=this.tableOptions.externalFilterFunction;if(t&&this.tableModel.externalFilterChanged(t),this.reapplySorting(),(r=this.batchEditService)==null||r.pruneOrphans(),e){for(const a of["header","body","footer"])(l=this.colAndRowspanModels[a])==null||l.init();this.firstInit(),this.stateService.markDirty("columns")}this.invalidateAggregates();const s=this.focusModel(),o=this.tableModel.getBodyModel().getRowCount(),i=this.tableModel.getColumnCount();if(s&&o>0&&i>0){const[a,c]=s.getFocus();if(a>=o||c>=i){const h=Math.min(Math.max(0,a),o-1),d=Math.min(Math.max(this.getFirstDataColumnIndex(),c),i-1);s.setFocus(h,d),this.selectionService.collapseTo(h,d)}}this.repaintHard()}nextShownColumn(e,t){return this.getNextShownColumnIndex(e,t,this.tableModel.getColumnCount())}hasShownColumnBeside(e,t){const s=this.getNextShownColumnIndex(e,t,this.tableModel.getColumnCount());return s!==e&&!N(this.tableModel.getColumnDef(s))}moveActiveCell(e,t,s,o){const i=this.focusModel();return i?(i.hasFocus(e,t)||i.setFocus(e,t),this.changeFocusCell(o,s)):!1}getSelectedBodyCells(e){return this.collectSelectedBodyCells(e)}collectSelectedBodyCells(e,t){const s=this.selectionModel();if(!t&&!(s!=null&&s.hasSelection())&&!(s!=null&&s.isAllSelected()))return[];const o=this.tableModel.getBodyModel().getRowCount(),i=this.tableModel.getColumnCount(),r=t??(s.isAllSelected()?[new M(0,0,o-1,i-1)]:s.getRanges()),l=h=>this.tableModel.getColumnWidth(h)>0&&!N(this.tableModel.getColumnDef(h)),a=[],c=r.length>1?new Set:void 0;for(const h of r){const d=Math.max(0,h.r1),u=Math.min(o-1,h.r2),f=Math.max(0,h.c1),g=Math.min(i-1,h.c2);if(u>=d&&g>=f&&(u-d+1)*(g-f+1)>e)return;for(let p=d;p<=u;p++)for(let m=f;m<=g;m++)if(!(!l(m)||!t&&!s.isSelected(p,m))){if(c){const b=p*i+m;if(c.has(b))continue;c.add(b)}if(a.push([p,m]),a.length>e)return}}return a}clearCells(e){var a,c;const t=((a=this.editingOptions)==null?void 0:a.maxClearCells)??Se.maxCopyCells,s=this.collectSelectedBodyCells(t,e);if(!s)return this.announce(this.getSheetTexts().clearTooLarge(t)),-1;if(!s.length&&!e){const h=this.getActiveBodyCell();h&&s.push(h)}const o=this.tableModel.getBodyModel(),i=h=>h==null||h==="",r=[];for(const[h,d]of s){if(h<0||d<0||h>=o.getRowCount()||d>=this.tableModel.getColumnCount()||!o.isEditable(h,d)||i(this.getShownCellValue(h,d)))continue;const u=this.tableModel.getColumnDef(d),f=(u==null?void 0:u.emptyValue)!==void 0?u.emptyValue:((c=this.editingOptions)==null?void 0:c.emptyValue)??"";r.push({rowIndex:h,column:d,value:f})}const l=r.length?this.applyCellChanges(r,"clear"):[];return this.announce(this.getSheetTexts().cellsCleared(l.length)),l.length}commitCellEditor(e,t,s){var l;const o=e.map(([a,c])=>({rowIndex:a,column:c,value:t})),i=this.resolveCellChanges(o,e.length>1);if(!i.length)return{written:0,invalid:0};if((l=this.batchEditService)!=null&&l.isActive())return this.markPending(i.map(a=>({rowIndex:a.rowIndex,column:a.columnIndex,value:a.value})),!0),s?this.debounceRepaint():this.repaint(),{written:i.length,invalid:0};const r=this.writeCellsInternal(i,"edit",{deferRepaint:s});return{written:r.changes.length,invalid:r.invalid,message:r.message}}toggleBooleanCell(e,t){this.applyCellChanges([{rowIndex:e,column:t,value:!this.getShownCellValue(e,t)}],"edit")}getSheetTexts(){const e=this.ariaTexts??{},t=new me;return{editingStarted:s=>(e.editingStarted??t.editingStarted).call(e,s),readOnlyCell:()=>(e.readOnlyCell??t.readOnlyCell).call(e),cellsCleared:s=>(e.cellsCleared??t.cellsCleared).call(e,s),clearTooLarge:s=>(e.clearTooLarge??t.clearTooLarge).call(e,s),rangeSelected:(s,o)=>(e.rangeSelected??t.rangeSelected).call(e,s,o),rowSelected:s=>(e.rowSelected??t.rowSelected).call(e,s),columnSelected:s=>(e.columnSelected??t.columnSelected).call(e,s),gridEditingHint:()=>(e.gridEditingHint??t.gridEditingHint).call(e),cellsPasted:(s,o)=>(e.cellsPasted??t.cellsPasted).call(e,s,o),pasteTooLarge:s=>(e.pasteTooLarge??t.pasteTooLarge).call(e,s),copyTooLarge:s=>(e.copyTooLarge??t.copyTooLarge).call(e,s),cutMarked:s=>(e.cutMarked??t.cutMarked).call(e,s),copiedLastRangeOnly:()=>(e.copiedLastRangeOnly??t.copiedLastRangeOnly).call(e)}}onSheetAction(e){var s,o;const t=this.editingOptions;if(t)switch(e){case"NAVIGATE_NEXT_CELL":case"NAVIGATE_PREVIOUS_CELL":{const i=this.getActiveBodyCell(),r=e==="NAVIGATE_NEXT_CELL"?1:-1;return!i||this.isEditing()||!this.hasShownColumnBeside(i[1],r)||r>0&&((s=this.masterDetailService)!=null&&s.hasTabTarget(i[0]))?!1:this.moveActiveCell(i[0],i[1],0,r)}case"EXTEND_SELECTION_UP":case"EXTEND_SELECTION_DOWN":case"EXTEND_SELECTION_LEFT":case"EXTEND_SELECTION_RIGHT":case"EXTEND_SELECTION_ROW_START":case"EXTEND_SELECTION_ROW_END":case"EXTEND_SELECTION_PAGE_UP":case"EXTEND_SELECTION_PAGE_DOWN":{const i=this.getSelectionExtent();if(!i||this.isEditing())return!1;const[r,l]=i,a=this.tableModel.getBodyModel().getRowCount(),c=this.tableModel.getColumnCount(),h=Math.max(1,this.displayedRowCount-1),d={EXTEND_SELECTION_UP:[Math.max(0,r-1),l],EXTEND_SELECTION_DOWN:[Math.min(a-1,r+1),l],EXTEND_SELECTION_LEFT:[r,this.getNextShownColumnIndex(l,-1,c)],EXTEND_SELECTION_RIGHT:[r,this.getNextShownColumnIndex(l,1,c)],EXTEND_SELECTION_ROW_START:[r,this.getFirstShownDataColumnIndex()],EXTEND_SELECTION_ROW_END:[r,this.getLastShownColumnIndex()],EXTEND_SELECTION_PAGE_UP:[Math.max(0,r-h),l],EXTEND_SELECTION_PAGE_DOWN:[Math.min(a-1,r+h),l]},[u,f]=d[e];return this.extendSelectionTo(u,N(this.tableModel.getColumnDef(f))?l:f)}case"NAVIGATE_DATA_EDGE_UP":case"NAVIGATE_DATA_EDGE_DOWN":case"NAVIGATE_DATA_EDGE_LEFT":case"NAVIGATE_DATA_EDGE_RIGHT":{const i=this.getActiveBodyCell();if(!i||this.isEditing())return!1;const[r,l]=this.dataEdge(i,e);return this.setFocusCell(r,l)}case"EXTEND_TO_DATA_EDGE_UP":case"EXTEND_TO_DATA_EDGE_DOWN":case"EXTEND_TO_DATA_EDGE_LEFT":case"EXTEND_TO_DATA_EDGE_RIGHT":{const i=this.getSelectionExtent();if(!i||this.isEditing())return!1;const[r,l]=this.dataEdge(i,e);return this.extendSelectionTo(r,l)}case"SELECT_ROW":case"SELECT_COLUMN":return this.selectWholeRowsOrColumns(e==="SELECT_ROW");case"CLEAR_CELLS":return!t.clearKeys||this.isEditing()||this.headerFocus?!1:(this.clearCells(),!0);case"CLEAR_AND_EDIT":{if(!t.clearKeys||this.isEditing()||this.headerFocus)return!1;const i=this.getActiveBodyCell(),r=this.collectSelectedBodyCells(1);return i&&r&&((o=this.cellEditorService)!=null&&o.handlesColumn(i[1]))&&this.tableModel.getBodyModel().isEditable(i[0],i[1])?(this.cellEditorService.start(i[0],i[1],{mode:"enter",typedText:""}),!0):(this.clearCells(),!0)}default:return}}getSelectionExtent(){if(!this.headerFocus)return this.selectionService.getExtent()??this.getActiveBodyCell()}getFirstShownDataColumnIndex(){const e=this.getFirstShownColumnIndex();return N(this.tableModel.getColumnDef(e))?this.getNextShownColumnIndex(e,1,this.tableModel.getColumnCount()):e}dataEdge(e,t){const s=t.endsWith("_UP")?-1:t.endsWith("_DOWN")?1:0,o=t.endsWith("_LEFT")?-1:t.endsWith("_RIGHT")?1:0;return Pl((r,l)=>{const a=this.getShownCellValue(r,l);return a==null||a===""},this.tableModel.getBodyModel().getRowCount(),this.tableModel.getColumnCount(),e[0],e[1],s,o,r=>this.tableModel.getColumnWidth(r)>0&&!N(this.tableModel.getColumnDef(r)))}extendSelectionTo(e,t){const s=this.selectionService.extendTo(e,t);if(!s)return!1;this.ensureColumnIsVisible(t),this.ensureRowIsVisible(e),this.repaint();let o=0;for(let i=s.c1;i<=s.c2;i++)this.tableModel.getColumnWidth(i)>0&&o++;return this.announce(this.getSheetTexts().rangeSelected(s.r2-s.r1+1,o)),!0}selectWholeRowsOrColumns(e){const t=this.selectionModel(),s=this.getActiveBodyCell();if(!t||!s||this.isEditing()||t.selectionType!=="range")return!1;const o=t.getRanges(),i=o.length?o[o.length-1]:M.singleCell(s[0],s[1]),r=e?new M(i.r1,0,i.r2,Number.MAX_SAFE_INTEGER):new M(0,i.c1,Number.MAX_SAFE_INTEGER,i.c2);this.holdSelectionEvents(()=>{t.clear(),t.addSelection(r),this.onSelectionChanged(t)}),this.repaint();const l=this.getSheetTexts();return this.announce(e?l.rowSelected(i.r2-i.r1+1):l.columnSelected(i.c2-i.c1+1)),!0}getEventListener(){return this.eventListener}afterRowsMoved(){this.lastSortCompareFn=void 0,this.invalidateAggregates()}announce(e,t){e&&!this.isDestroyed()&&this.liveAnnouncer.announce(e,t)}showLoadingOverlay(e){this.tableOverlay.showLoading(e)}showNoRowsOverlay(e){this.tableOverlay.showNoRows(e)}hideOverlay(){this.tableOverlay.hide()}getOverlayState(){return this.tableOverlay.getState()}onOverlayChanged(e){this.isDestroyed()||(e.kind==="loading"?(this.setHostAriaAttribute("aria-busy","true"),this.tableOverlay.isBlocking()&&(this.hideHoverRow(),this.hideHoverColumn())):e.previous==="loading"&&(this.restoreHostAriaAttribute("aria-busy"),this.liveAnnouncer.cancel(this.lastLoadingAnnouncement)),e.kind==="loading"&&(this.lastLoadingAnnouncement=e.text),(e.kind==="loading"||e.kind==="noRows"&&this.initialized)&&this.announce(e.text))}announceCopied(e){this.announce(this.ariaTexts.copied(this.countCopiedCells()))}countCopiedCells(){const e=this.selectionModel();if(!(e!=null&&e.hasSelection()))return 1;const t=this.tableModel.getBodyModel().getRowCount(),s=this.tableModel.getColumnCount(),o=u=>{var f,g;return((g=(f=this.tableModel.getColumnDef(u))==null?void 0:f.isVisible)==null?void 0:g.call(f))!==!1};let i=0;for(let u=0;u<s;u++)o(u)&&i++;if(e.isAllSelected())return t*i;const r=e.getRanges();if(!r.length)return 1;const l=Math.max(0,Math.min(...r.map(u=>u.r1))),a=Math.min(t-1,Math.max(...r.map(u=>u.r2))),c=Math.max(0,Math.min(...r.map(u=>u.c1))),h=Math.min(s-1,Math.max(...r.map(u=>u.c2)));if((a-l+1)*(h-c+1)>Se.maxCopyCells)return 0;let d=0;for(let u=l;u<=a;u++)for(let f=c;f<=h;f++)o(f)&&e.isSelected(u,f)&&d++;return d}getHeaderFocus(){return this.headerFocus?[this.headerFocus[0],this.headerFocus[1]]:void 0}setFocusCell(e,t){const s=this.focusModel();return s?(this.headerFocus=void 0,s.setFocus(e,t),this.ensureColumnIsVisible(t),this.ensureRowIsVisible(e),this.afterActiveCellMoved(e,t),this.repaint(),!0):!1}afterActiveCellMoved(e,t){var s;(s=this.editingOptions)!=null&&s.collapseSelectionOnNavigate&&this.selectionService.collapseTo(e,t)}getFirstShownColumnIndex(){return this.getNextShownColumnIndex(-1,1,this.tableModel.getColumnCount())}getLastShownColumnIndex(){const e=this.tableModel.getColumnCount();return this.getNextShownColumnIndex(e,-1,e)}onBodyNavigation(e){const t=this.focusModel();if(!["NAVIGATE_ROW_START","NAVIGATE_ROW_END","NAVIGATE_FIRST_CELL","NAVIGATE_LAST_CELL","NAVIGATE_PAGE_UP","NAVIGATE_PAGE_DOWN","ACTIVATE_CELL"].includes(e))return;if(!t||this.isEditing())return!1;const o=this.tableModel.getBodyModel().getRowCount();if(o<1||this.tableModel.getColumnCount()<1)return!1;const[i,r]=t.getFocus(),l=Math.min(Math.max(i,0),o-1),a=r<0?this.getFirstShownColumnIndex():r,c=Math.max(1,this.displayedRowCount-1);switch(e){case"NAVIGATE_ROW_START":return this.setFocusCell(l,this.getFirstShownColumnIndex());case"NAVIGATE_ROW_END":return this.setFocusCell(l,this.getLastShownColumnIndex());case"NAVIGATE_FIRST_CELL":return this.setFocusCell(0,this.getFirstShownColumnIndex());case"NAVIGATE_LAST_CELL":return this.setFocusCell(o-1,this.getLastShownColumnIndex());case"NAVIGATE_PAGE_UP":return this.setFocusCell(Math.max(0,l-c),a);case"NAVIGATE_PAGE_DOWN":return this.setFocusCell(Math.min(o-1,l+c),a);default:{if(i<0||r<0)return!1;if(this.activateBodyCell(i,r))return!0;const h=this.editingOptions;return h?h.enterKey==="moveDown"?this.moveActiveCell(i,r,1,0):this.tableModel.getBodyModel().isEditable(i,r)?this.startEditing(i,r,"edit"):!1:!1}}}activateBodyCell(e,t){var r;const s=this.tableModel.getBodyModel();if(s.isRowCheckable(e)&&(this.tableOptions.showCheckboxWihoutExtraColumn&&t===this.getFirstDataColumnIndex()||li(s.getCellRenderer(e,t))))return this.toggleRowCheckbox(e,t,"body"),!0;if((r=this.masterDetailService)!=null&&r.isMasterAt(e))return this.toggleDetail(e,"keyboard");const i=s.getRowByIndex(e);if(U(i)&&Z(s)&&s.hasDisplayedChildren(i)){const l=i;return this.setTreeRowExpanded(l,!l.expanded)}return!1}moveFocusIntoHeader(){const e=this.focusModel();if(!e||this.isEditing()||this.headerFocus)return!1;const[t,s]=e.getFocus(),o=this.getAriaGridInfo().headerRowCount,i=this.tableModel.getBodyModel().getRowCount()<1;return t!==0&&!i||o<1||this.tableModel.getColumnCount()<1?!1:(this.setHeaderFocus(o-1,s<0?this.getFirstShownColumnIndex():s),!0)}setHeaderFocus(e,t){var o;const s=(o=this.colAndRowspanModels.header)==null?void 0:o.getRanges().find(i=>i.isInRange(e,t));this.headerFocus=s?[s.r1,s.c1]:[e,t],this.ensureColumnIsVisible(this.headerFocus[1]),this.repaint()}onHeaderAction(e){const[t,s]=this.headerFocus,o=this.tableModel.getAreaModel("header"),i=this.getAriaGridInfo().headerRowCount,r=this.tableModel.getColumnCount(),l=Math.max(1,o.getColspanAt(t,s)||1),a=Math.max(1,o.getRowspanAt(t,s)||1);switch(e){case"NAVIGATE_LEFT":{const c=this.getNextShownColumnIndex(s,-1,r);return c!==s&&this.setHeaderFocus(t,c),!0}case"NAVIGATE_RIGHT":{const c=this.getNextShownColumnIndex(s+l-1,1,r);return c>s+l-1&&this.setHeaderFocus(t,c),!0}case"NAVIGATE_ROW_START":return this.setHeaderFocus(t,this.getFirstShownColumnIndex()),!0;case"NAVIGATE_ROW_END":return this.setHeaderFocus(t,this.getLastShownColumnIndex()),!0;case"NAVIGATE_UP":return t>0&&this.setHeaderFocus(t-1,s),!0;case"NAVIGATE_DOWN":return t+a<i?(this.setHeaderFocus(t+a,s),!0):this.tableModel.getBodyModel().getRowCount()<1?!0:this.setFocusCell(Math.max(0,this.firstFullVisibleRowIndex),s);case"NAVIGATE_FIRST_CELL":case"NAVIGATE_LAST_CELL":case"NAVIGATE_PAGE_UP":case"NAVIGATE_PAGE_DOWN":this.headerFocus=void 0;return;case"ACTIVATE_CELL":return this.activateHeaderCell(t,s,a,i);case"START_EDITING":case"TOGGLE_SELECTION":return!0;default:return}}activateHeaderCell(e,t,s,o){var a;const i=this.tableModel.getAreaModel("header"),r=i.getValueAt(e,t);if(r&&typeof r=="object"&&r.toggle&&r.visibility!=="always"&&"toggleHeaderGroup"in i){const c=new Es(null,this);return c.rowIdx=e,c.colIdx=t,c.areaIdent="header",c.areaModel=i,this.toggleHeaderGroup(c),this.setHeaderFocus(e,t),!0}const l=this.tableModel.getColumnDef(t);return e+s>=o&&((a=l==null?void 0:l.sortable)!=null&&a.call(l))?(this.sortByColumn(t),!0):!1}cancelEditing(e){var s,o;const t=this.getInCellEditorCell();if(t&&((o=(s=this.eventListener).onEditingChanged)==null||o.call(s,new yt("cancel",t[0],t[1],"edit"))),e instanceof HTMLSelectElement){const i=Array.from(e.options).find(r=>r.defaultSelected);e.selectedIndex=i?i.index:-1}else e&&(e.value=e.defaultValue);this.resetEditorRenderer(),this.hostElement.focus(),this.repaint()}updateModelValueAfterEdit(e,t,s,o){var l,a,c;if(e!=="body")return;this.getInCellEditorCell()&&((a=(l=this.eventListener).onEditingChanged)==null||a.call(l,new yt("commit",t,s,"edit",o)));const i=()=>{this.resetEditorRenderer()};if((c=this.batchEditService)!=null&&c.isActive()){i(),this.markPending([{rowIndex:t,column:s,value:o}],!1),this.repaint(),this.hostElement.focus();return}const r=this.writeCellsInternal([{rowIndex:t,columnIndex:s,value:o}],"edit",{beforeRepaint:i});(r.changes.length||r.invalid)&&(r.changes.length||(i(),this.repaint()),this.hostElement.focus())}applyCellChanges(e,t="api",s={}){var i;const o=this.resolveCellChanges(e);if(!o.length)return[];if((i=this.batchEditService)!=null&&i.isActive()){const r=this.markPending(o.map(l=>({rowIndex:l.rowIndex,column:l.columnIndex,value:l.value})),!0,!1,t,s.undoable);return this.repaint(),r}return this.writeCellsInternal(o,t,{undoable:s.undoable}).changes}writeCells(e,t,s={}){return this.writeCellsInternal(e,t,s).changes}writeCellsInternal(e,t,s){var p,m,b,y,C,v,E,S,R,L;const o=this.tableModel.getBodyModel(),i=o.getRowCount(),r=ne(o)?o.getBuildCount():0,l=[];let a=0,c="";const h=this.tableSheet,d=()=>{for(const{rowIndex:x,columnIndex:D,value:k}of e){const P=!!(h!=null&&h.isFormulaInput(D,k));if(!s.skipValidation){const $=P?this.checkFormulaSyntax(k):this.validateCellValue(x,D,s.raw?k:this.pipeCellValue(x,D,k));if($){a++,c=c||$;continue}}const V=this.getCellInput(x,D);(s.raw||P?this.setRawValue(x,D,k):o.setValue(x,D,k))&&l.push({row:this.rowObjectOf(x),rowIndex:x,columnIndex:D,property:this.batchEditService.propertyOf(D),oldValue:V,newValue:this.getCellInput(x,D)})}};ne(o)?o.batch(d):d(),a&&this.announce(this.getEditTexts().invalidValue(c));const u=(p=s.extraChanges)!=null&&p.length?[...l,...s.extraChanges]:l;if(!u.length)return{changes:u,invalid:a,message:c||void 0};h==null||h.cellsWritten(u),(m=this.undoService)==null||m.record(u,t,s.undoable),(b=s.beforeRepaint)==null||b.call(s);const f=(y=s.extraChanges)!=null&&y.length?void 0:{area:"body",rowIndices:l.map(x=>x.rowIndex)};this.invalidateAggregates(f),ne(o)&&o.getBuildCount()!==r||o.getRowCount()!==i||t==="commit"?this.repaintHard():s.deferRepaint?this.debounceRepaint():this.repaint(),this.invalidateAggregates(f),(C=this.undoService)==null||C.beginFold();try{if(t==="edit"&&u.length===1){const x=Xe.createSingle(u[0].rowIndex,u[0].columnIndex);x.changes=u,x.source=t,(E=(v=this.eventListener).onModelChanged)==null||E.call(v,x)}else(R=(S=this.eventListener).onModelChanged)==null||R.call(S,Xe.createForChanges(u,t))}finally{(L=this.undoService)==null||L.endFold()}return{changes:u,invalid:a,message:c||void 0}}writePastedCells(e,t,s){var i;const o=this.resolveCellChanges(e);if(!o.length)return[];if((i=this.batchEditService)!=null&&i.isActive()){const r=this.markPending(o.map(l=>({rowIndex:l.rowIndex,column:l.columnIndex,value:l.value})),!0,s,t);return this.repaint(),r}return this.writeCellsInternal(o,t,{raw:s}).changes}selectBodyRange(e){const t=this.focusModel();t&&(this.headerFocus=void 0,t.setFocus(e.r1,e.c1)),this.selectionService.collapseTo(e.r1,e.c1),(e.r2!==e.r1||e.c2!==e.c1)&&this.selectionService.extendTo(e.r2,e.c2),this.repaint()}checkPastedValue(e,t,s,o){var i;return(i=this.tableSheet)!=null&&i.isFormulaInput(t,s)?this.checkFormulaSyntax(s):this.validateCellValue(e,t,o?s:this.pipeCellValue(e,t,s))}getCellInput(e,t){const s=this.tableModel.getBodyModel();return this.tableSheet&&s.getInputValueAt?s.getInputValueAt(e,t):s.getValueAt(e,t)}getTypedCellValue(e,t){var o;const s=this.getShownCellValue(e,t);return(o=this.tableSheet)!=null&&o.isFormulaInput(t,s)?this.tableModel.getBodyModel().getValueAt(e,t):s}getFormulaErrorText(e){const t=this.ariaTexts??{};return(t.formulaError??new me().formulaError).call(t,e)}checkFormulaSyntax(e){const t=this.tableSheet;return t.options.rejectInvalidFormulas?t.syntaxError(e):void 0}resolvePastedValue(e,t,s,o){if(!(e instanceof Jt))return e;const i=this.tableSheet;return!i||!i.isFormulaColumnIndex(s)?e.value:o?e.input:i.moveFormula(e.input,e.row,e.col,t,s)??e.value}getCopyValue(e,t){var i;const s=this.tableSheet,o=this.getShownCellValue(e,t);return!s||(i=this.batchEditService)!=null&&i.getPendingAt(e,t)?o:s.copyOf(e,t,o,this.tableModel.getBodyModel().getValueAt(e,t))}isBatchEditActive(){var e;return!!((e=this.batchEditService)!=null&&e.isActive())}getUndoOptions(){return this.undoOptions}writeUndoCells(e,t,s){var r;if(!e.length&&!t.length)return[];const o=this.tableModel.getBodyModel();if((r=this.batchEditService)!=null&&r.isActive()){const l=e.length?this.markPending(e.map(a=>({rowIndex:a.rowIndex,column:a.columnIndex,value:a.value})),!0,!0,s):[];return this.repaint(),l}const i=this.writeCellsInternal(e,s,{raw:!0,skipValidation:!0,extraChanges:t}).changes;return t.length&&ne(o)&&(o.regroup(),this.invalidateAggregates(),this.repaintHard()),i}getUndoTexts(){const e=this.ariaTexts??{},t=new me;return{undone:(s,o)=>(e.undone??t.undone).call(e,s,o),redone:(s,o)=>(e.redone??t.redone).call(e,s,o),nothingToUndo:()=>(e.nothingToUndo??t.nothingToUndo).call(e),nothingToRedo:()=>(e.nothingToRedo??t.nothingToRedo).call(e),undoSkipped:s=>(e.undoSkipped??t.undoSkipped).call(e,s),undoHistoryCleared:s=>(e.undoHistoryCleared??t.undoHistoryCleared).call(e,s)}}isOverlayBlocking(){return this.tableOverlay.isBlocking()}rowsAppended(){this.invalidateAggregates()}isRowGroupingOrTree(){const e=this.tableModel.getBodyModel();return Z(e)||ne(e)||Rs(this.tableModel)}getClipboardService(){return this.clipboardService||(this.clipboardService=new Ko(this,ls.create(!0),!1)),this.clipboardService}markPending(e,t,s=!1,o="edit",i){const r=t?e.map(d=>({rowIndex:d.rowIndex,columnIndex:d.column,value:d.value})):this.resolveCellChanges(e,!1),l=this.batchEditService,a=this.undoService?r.map(({rowIndex:d,columnIndex:u})=>{const f=l.rowKeyOf(d),g=l.propertyOf(u),p=l.getPendingEntry(f,g);return{rowKey:f,property:g,before:p?{...p}:void 0}}):void 0,c=r.map(({rowIndex:d,columnIndex:u,value:f})=>{var m;if((m=this.tableSheet)!=null&&m.isFormulaInput(u,f)){const b=this.checkFormulaSyntax(f);return{rowIndex:d,columnIndex:u,value:f,rawValue:f,...b?{error:b}:{}}}const g=s?f:this.pipeCellValue(d,u,f),p=this.validateCellValue(d,u,g);return{rowIndex:d,columnIndex:u,value:g,rawValue:f,...p?{error:p}:{}}}),h=l.addPending(c);if(a&&h.length){for(const d of a){const u=l.getPendingEntry(d.rowKey,d.property);d.after=u?{...u}:void 0}this.undoService.recordPending(a.filter(d=>!d.before!=!d.after||!!d.before&&!!d.after&&!Dt(d.before.newValue,d.after.newValue)),o,i)}return h}resolveCellChanges(e,t=!0){var a,c;const s=this.tableModel.getBodyModel(),o=s.getRowCount(),i=this.tableModel.getColumnCount(),r=((c=(a=this.tableModel).getColumnDefs)==null?void 0:c.call(a))??[],l=[];for(const h of e){const d=typeof h.column=="number"?h.column:r.findIndex(f=>f.property===h.column),u=h.rowIndex;u>=0&&u<o&&d>=0&&d<i&&(t&&!s.isEditable(u,d)||l.push({rowIndex:u,columnIndex:d,value:h.value}))}return l}pipeCellValue(e,t,s){var i;const o=(i=this.tableModel.getColumnDef(t))==null?void 0:i.editInputPipe;return o?o(s,e,t):s}validateCellValue(e,t,s){var r;const o=(r=this.tableModel.getColumnDef(t))==null?void 0:r.validate;if(!o)return;const i=o(s,this.rowObjectOf(e));return i?String(i):void 0}rowObjectOf(e){const t=this.tableModel.getBodyModel().getRowByIndex(e);return U(t)?t.data:t}getFillHandleOptions(){return ns.create(Ze(this.tableOptions,"fillHandle"))}fillRange(e,t,s,o="auto",i){const r=this.getFillHandleOptions()??ns.create(!0),l=this.tableModel.getBodyModel(),a=l.getRowCount(),c=this.tableModel.getColumnCount(),h=this.normalizeRange(e,a,c);if(!h||s<1)return 0;const d=t==="down"?a-1-h.r2:t==="up"?h.r1:t==="right"?c-1-h.c2:h.c1,u=Math.min(s,d);if(u<1)return 0;const f=t==="down"||t==="up"?h.c2-h.c1+1:h.r2-h.r1+1;if(u*f>r.maxCells)return this.announce(this.getEditTexts().fillTooLarge(r.maxCells)),-1;const g=this.batchEditService,p=ol({source:h,direction:t,count:u,mode:o,getValue:(y,C)=>g.getShownValue(y,C),isFillable:(y,C)=>this.tableModel.getColumnWidth(C)>0&&l.isEditable(y,C),fillValue:r.fillValue,getCellInfo:(y,C)=>{var v;return{row:this.rowObjectOf(y),property:((v=this.tableModel.getColumnDef(C))==null?void 0:v.property)??""}}});this.tableSheet&&this.moveFilledFormulas(p,h,t);const m=this.applyCellChanges(p,"fill"),b=this.selectionModel();return b&&this.holdSelectionEvents(()=>{b.clear(),b.addSelection(i??ki(h,t,u)),this.onSelectionChanged(b)}),this.repaint(),this.announce(this.getEditTexts().cellsFilled(m.length)),m.length}moveFilledFormulas(e,t,s){const o=this.tableSheet,i=t.r2-t.r1+1,r=t.c2-t.c1+1,l=(a,c)=>(a%c+c)%c;for(const a of e){const c=a.rowIndex,h=a.column,d=s==="down"?t.r1+l(c-t.r2-1,i):s==="up"?t.r2-l(t.r1-1-c,i):c,u=s==="right"?t.c1+l(h-t.c2-1,r):s==="left"?t.c2-l(t.c1-1-h,r):h,f=this.getShownCellValue(d,u);if(!o.isFormulaInput(u,f))continue;const g=o.physicalRow(d),p=o.engineColumn(u);if(g===void 0||p===void 0)continue;const m=o.moveFormula(f,g,p,c,h);m!==void 0&&(a.value=m)}}getFillSourceRange(){const e=this.selectionModel();if(!e||e.selectionType!=="range"||e.isAllSelected())return;const t=e.getRanges();if(t.length)return this.normalizeRange(t[t.length-1],this.tableModel.getBodyModel().getRowCount(),this.tableModel.getColumnCount())}normalizeRange(e,t,s){const o=Math.max(0,Math.min(e.r1,e.r2)),i=Math.min(t-1,Math.max(e.r1,e.r2)),r=Math.max(0,Math.min(e.c1,e.c2)),l=Math.min(s-1,Math.max(e.c1,e.c2));return o<=i&&r<=l?new M(o,r,i,l):void 0}fillByKeyboard(e){var r;const t=this.getFillHandleOptions(),s=e==="down";if(!t||this.isEditing()||(r=this.fillHandleService)!=null&&r.isFilling()||t.direction===(s?"horizontal":"vertical"))return!1;const o=this.getFillSourceRange();if(!o)return!1;const i=s?o.r2-o.r1:o.c2-o.c1;if(i>0){const l=s?new M(o.r1,o.c1,o.r1,o.c2):new M(o.r1,o.c1,o.r2,o.c1);this.fillRange(l,e,i,"copy")}else if(s?o.r1>0:o.c1>0){const l=s?new M(o.r1-1,o.c1,o.r1-1,o.c2):new M(o.r1,o.c1-1,o.r2,o.c1-1);this.fillRange(l,e,1,"copy",o)}return!0}setHostKeyShortcuts(e){e===void 0?this.restoreHostAriaAttribute("aria-keyshortcuts"):this.setHostAriaAttribute("aria-keyshortcuts",e)}getEditTexts(){const e=this.ariaTexts,t=new me;return{cellsFilled:s=>(e.cellsFilled??t.cellsFilled).call(e,s),fillTooLarge:s=>(e.fillTooLarge??t.fillTooLarge).call(e,s),pendingChanges:s=>(e.pendingChanges??t.pendingChanges).call(e,s),changesCommitted:s=>(e.changesCommitted??t.changesCommitted).call(e,s),changesDiscarded:()=>(e.changesDiscarded??t.changesDiscarded).call(e),commitBlocked:s=>(e.commitBlocked??t.commitBlocked).call(e,s),invalidValue:s=>(e.invalidValue??t.invalidValue).call(e,s)}}getApi(){return this.api}firstInit(){var t;const e=this.getAvailableColumnWidth();return e>0&&this.setParentWidth(e),this.stateService.initBeforeModel(),this.tableModel.init(),this.stateService.initAfterModel(),(t=this.tableOptions)!=null&&t.externalFilterFunction&&this.externalFilterChanged(!1),this.stateService.initAfterFilter(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows(),this.stateService.initAfterLayout(),this.liveAnnouncer.getElement(),this.initialized=!0,this}destroy(){var s,o,i,r,l,a,c,h;if(this.destroyed)return;try{this.stateService.destroy()}catch(d){console.error(d)}(o=(s=this.columnDrag)==null?void 0:s.keyAbort)==null||o.abort(),this.columnDrag=void 0;try{(i=this.rowDragService)==null||i.destroy()}catch(d){console.error(d)}(r=this.fillHandleService)==null||r.destroy(),(l=this.cellEditorService)==null||l.destroy(),(a=this.clipboardService)==null||a.destroy(),(c=this.tableSheet)==null||c.destroy(),this.subscribers.clear();try{(h=this.masterDetailService)==null||h.destroy()}catch(d){console.error(d)}this.destroyed=!0,this.listenerAbortController.abort(),this.resizeHandler.disconnect();const e=this.getSelectionModel?this.getSelectionModel():void 0;e==null||e.removeEventSelectionChangedListener(this);const t=this.getFocusModel?this.getFocusModel():void 0;t==null||t.removeEventFocusChangedListener(this),this.disposeRendering(),this.tableOverlay.destroy(),this.liveAnnouncer.destroy(),this.removeHostAria(),this.hostElement.innerText=""}isEventInDetail(e){var t;return!!((t=this.masterDetailService)!=null&&t.isInLayer(e))}setDetailExpanded(e,t,s="api"){var o;return!!((o=this.masterDetailService)!=null&&o.setExpanded(e,t,s))}toggleDetail(e,t="api"){const s=this.masterDetailService;return!!s&&s.setExpanded(e,!s.isExpanded(e),t)}onDetailToggled(e,t,s,o,i=!0,r=!1){var l,a,c,h,d,u;if(r||this.invalidateRowLayout(),this.resetSizeOfWrapperDiv(),this.repaint(),i&&((a=(l=this.eventListener).onDetailExpandedChanged)==null||a.call(l,new nl(e,t,s,o))),o==="mouse"||o==="keyboard"){const f=s?(h=(c=this.ariaTexts).detailExpanded)==null?void 0:h.call(c):(u=(d=this.ariaTexts).detailCollapsed)==null?void 0:u.call(d);f&&this.announce(f)}this.stateService.markDirty("details")}onDetailHeightChanged(){this.destroyed||(this.resetSizeOfWrapperDiv(),this.adjustAfterScrolling())}takeFocusFromDetail(e){const t=this.focusModel();if(t&&e>=0){const s=t.getFocus()[1];this.headerFocus=void 0,t.setFocus(e,s>=0?s:this.getFirstShownColumnIndex())}this.hostElement.focus({preventScroll:!0})}focusDetailMaster(e){const t=this.focusModel();if(!t||e<0)return;const s=t.getFocus()[1];this.setFocusCell(e,s>=0?s:this.getFirstShownColumnIndex())}isDestroyed(){return this.destroyed}createGeMouseEvent(e){if(!e)return new es;const t=this.getMouseEventTarget(e),[s,o]=this.getAreaAndSideIdentByAttr(t);return this.createGeMouseEventForCell(e,{areaIdent:s,sideIdent:o,rowIndex:this.getNumberByAttr(t,"data-row-index"),columnIndex:this.getNumberByAttr(t,"data-col-index"),action:this.getStringByAttr(t,"data-ge-action")})}createGeMouseEventForCell(e,t){const s=new es;if(s.originalEvent=e,s.areaIdent=t.areaIdent,s.sideIdent=t.sideIdent,s.rowIndex=t.rowIndex,s.columnIndex=t.columnIndex,s.action=t.action,s.areaIdent){const o=this.tableModel.getAreaModel(s.areaIdent);s.rowTop=s.areaIdent==="body"?this.getBodyRowTop(s.rowIndex):o.getYPosByRowIndex(s.rowIndex)}return s.columnLeft=this.tableModel.getXPosByColumnIndex(s.columnIndex),s}getMouseEventTarget(e){let t=e.target;if(t instanceof Element&&!t.isConnected&&Number.isFinite(e.clientX)&&Number.isFinite(e.clientY)&&(t=this.getCellElementAtPoint(e.clientX,e.clientY)??t),(t===this.scrollViewport||t===this.contentWrapperDiv||t===this.contentDiv)&&this.tableModel.getPadding().bottom>0){const s=this.scrollViewport.getBoundingClientRect(),o=e.clientX-s.left,i=e.clientY-s.top>=this.scrollViewport.clientHeight||o<this.scrollViewport.clientLeft||o>=this.scrollViewport.clientLeft+this.scrollViewport.clientWidth,r=this.hostElement.getRootNode();if(!i&&r.elementsFromPoint){const l=r.elementsFromPoint(e.clientX,e.clientY).find(a=>this.hostElement.contains(a)&&a.closest(".ge-table-footer"));if(l)return l}}return t}getCellElementAtPoint(e,t){var o;const s=this.hostElement.getRootNode();return(o=s.elementsFromPoint)==null?void 0:o.call(s,e,t).find(i=>this.hostElement.contains(i)&&!!i.closest("[data-col-index]"))}onMouseDown(e){var o;this.selectionService.onMouseDown(),this.resetColumnDrag();const t=e.columnIndex,s=e.action==="resize-column";if(t>-1&&(s||e.action==="drag-column")&&(s?this.isColumnResizable(t):this.isColumnMovable(t))&&(this.mouseStartWidth=this.tableModel.getColumnWidth(t),this.mouseStartAction=e.action,this.mouseStartColumnIndex=t,this.mouseStartAction==="drag-column"&&(this.firstDraggingRendering=!0,this.dragFrom=this.mouseStartColumnIndex),s?this.tableOptions.columnsResizable:this.tableOptions.columnsDraggable&&((o=this.tableSheet)==null?void 0:o.allowsColumnDrag())!==!1)){const r=this.tableModel.getColumnDef(t);this.columnDrag={kind:s?"resize":"move",source:"mouse",columnIndex:t,currentIndex:t,columnDef:r,startWidth:this.mouseStartWidth,moves:[],started:!1,cancelled:!1}}}resetColumnDrag(){var e,t;(t=(e=this.columnDrag)==null?void 0:e.keyAbort)==null||t.abort(),this.columnDrag=void 0,this.mouseStartAction="",this.mouseStartWidth=-1,this.mouseStartColumnIndex=-1,this.dragFrom=-1,this.firstDraggingRendering=!0}beginColumnDrag(e){var l;const t=this.columnDrag;if(!t||t.cancelled)return!1;if(t.started)return!0;const s=e.draggingX||0,o=e.draggingY||0,i=((l=this.mouseHandler)==null?void 0:l.clickMoveTolerance)??4;if(s*s+o*o<=i*i)return!1;t.started=!0;const r=new AbortController;return t.keyAbort=r,(this.hostElement.ownerDocument??document).addEventListener("keydown",a=>{a.key==="Escape"&&(a.preventDefault(),a.stopPropagation(),this.cancelColumnDrag(a))},{capture:!0,signal:r.signal}),this.emitColumnDragEvent(t,"start",e.originalEvent),!t.cancelled&&this.columnDrag===t&&!this.isDestroyed()}isColumnDragging(){var e;return!!((e=this.columnDrag)!=null&&e.started)&&!this.columnDrag.cancelled}cancelColumnDrag(e){var s;const t=this.columnDrag;if(!(!t||!t.started||t.cancelled)){if(t.cancelled=!0,(s=t.keyAbort)==null||s.abort(),t.kind==="resize")this.tableModel.setColumnWidth(t.columnIndex,t.startWidth),this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows();else{this.hideDraggingColumn(),this.draggingTargetColumnIndex=-1;for(let o=t.moves.length-1;o>=0;o--){const[i,r]=t.moves[o];this.tableModel.changeColumnOrder(r,i)}t.moves=[],t.currentIndex=t.columnIndex,this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows(),this.stateService.markDirty("selection")}this.stateService.markDirty("columns"),this.emitColumnDragEvent(t,"cancel",e)}}emitColumnDragEvent(e,t,s){var i,r,l,a,c,h,d,u,f,g,p;const o=(i=e.columnDef)==null?void 0:i.property;if(e.kind==="resize"){const m=t==="start"?e.startWidth:this.tableModel.getColumnWidth(e.columnIndex),b=new _l(t,e.source,e.columnIndex,e.columnDef,o,e.startWidth,m,s);t==="start"?(l=(r=this.eventListener).onColumnResizeStart)==null||l.call(r,b):(c=(a=this.eventListener).onColumnResizeEnd)==null||c.call(a,b)}else{const m=(((d=(h=this.tableModel).getColumnDefs)==null?void 0:d.call(h))??[]).map(y=>y==null?void 0:y.property),b=new Bl(t,e.columnIndex,t==="start"?e.columnIndex:e.currentIndex,e.columnDef,o,m,s);t==="start"?(f=(u=this.eventListener).onColumnMoveStart)==null||f.call(u,b):(p=(g=this.eventListener).onColumnMoveEnd)==null||p.call(g,b)}}mouseDraggingOnFrame(e,t){var s,o;(o=(s=this.eventListener).onMouseDragging)==null||o.call(s,e),this.mouseEvent=e,!((this.mouseStartAction==="resize-column"||this.mouseStartAction==="drag-column")&&!this.beginColumnDrag(e))&&(this.mouseStartAction==="resize-column"?this.resizeColumn(e):!this.mouseStartAction&&this.selectionService.onMouseDragging(e,t)?this.repaint():this.mouseStartAction==="drag-column"&&e.columnIndex>-1&&(this.moveDraggedColumn(e.columnIndex),t&&(this.adjustDraggingColumn(e,this.dragFrom,this.firstDraggingRendering),this.firstDraggingRendering=!1),this.repaint()))}moveDraggedColumn(e){var i;const t=this.tableModel,s=t.getColumnCount();let o=Oc(this.dragFrom,e,s,t.getFixedLeftColumnCount(),t.getFixedRightColumnCount());for(;this.dragFrom>-1&&o!==this.dragFrom&&!this.isColumnMovable(o);)o+=o>this.dragFrom?-1:1;if(this.dragFrom>-1&&o!==this.dragFrom&&!(this.lastDragFrom===o&&this.lastDragTo===this.dragFrom)){const r=Array.from({length:s},(a,c)=>this.isColumnMovable(c)),l=Lc(r,this.dragFrom,o);l!=null&&l.length&&(l.forEach(([a,c])=>t.changeColumnOrder(a,c)),(i=this.columnDrag)==null||i.moves.push(...l),this.lastDragFrom=this.dragFrom,this.lastDragTo=o,this.dragFrom=o,this.columnDrag&&(this.columnDrag.currentIndex=o),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows())}this.draggingTargetColumnIndex=this.dragFrom}mouseDraggingEndOnFrame(e){var o,i;(i=(o=this.eventListener).onMouseDraggingEnd)==null||i.call(o,e),this.draggingTargetColumnIndex=-1;const t=this.columnDrag;t&&this.beginColumnDrag(e);const s=!!t&&t.started&&!t.cancelled;this.mouseStartAction==="resize-column"?s&&(this.resizeColumn(e),this.stateService.markDirty("columns")):this.mouseStartAction==="drag-column"&&(s&&e.columnIndex>-1&&(this.moveDraggedColumn(e.columnIndex),this.draggingTargetColumnIndex=-1),this.hideDraggingColumn(),s&&(this.repaint(),this.stateService.markDirty("columns"),this.stateService.markDirty("selection"))),this.resetColumnDrag(),s&&this.emitColumnDragEvent(t,"end",e.originalEvent)}mouseMove(e){var t,s;(s=(t=this.eventListener).onMouseMoved)==null||s.call(t,e),this.adjustHoverRows(e),this.adjustHoverColumns(e)}contextmenu(e){var s,o,i,r;const t=Date.now();if(t-this.lastContextmenu<50){this.lastContextmenu=t,(s=e.originalEvent)==null||s.preventDefault(),(o=e.originalEvent)==null||o.stopImmediatePropagation();return}this.lastContextmenu=t,(r=(i=this.eventListener).onContextmenu)==null||r.call(i,e)}toggleExpandCollapseAll(e=!0){const t=this.tableModel.getBodyModel();Z(t)&&(t.toggleExpandCollapseAll(e),this.allExpanded=e,this.repaintHard(),this.stateService.markDirty("tree"))}setTreeRowExpanded(e,t){const s=this.tableModel.getBodyModel();return!Z(s)||e.expanded===t?!1:(e.expanded=t,s.recalcVisibleTreeRows(!1),this.repaintHard(),this.stateService.markDirty("tree"),!0)}setRowGroupBy(e){const t=this.tableModel.getBodyModel();return ne(t)?(t.setGroupBy(e),Ho(this.tableModel),this.invalidateAggregates(),this.tableModel.recalcPadding(),this.repaintHard(),this.stateService.markDirty("tree"),this.stateService.markDirty("columns"),!0):!1}setPivotConfig(e,t){var o,i;const s=this.tableModel;if(!Rs(s))return!1;s.setPivotConfig(e,t),(s.getColumnDefs()??[]).forEach(r=>r.sortState=void 0),this.lastSortCompareFn=void 0,this.clearSelection(),(o=this.getFocusModel?this.getFocusModel():void 0)==null||o.clear();for(const r of["header","body","footer"])(i=this.colAndRowspanModels[r])==null||i.init();return this.invalidateAggregates(),this.firstInit(),this.repaintHard(),this.stateService.markDirty("columns"),this.stateService.markDirty("sort"),this.stateService.markDirty("tree"),this.stateService.markDirty("headerGroups"),!0}toggleRowCheckbox(e,t,s){var a,c,h;const o=this.tableModel.getAreaModel(s),i=o.isRowChecked(e),r=i===void 0||i==="semi"||i==="none";o.setRowChecked(e,r),this.repaint();const l=(a=o.rowSelectionModel)==null?void 0:a.getCheckedRows();(h=(c=this.eventListener).onCheckboxChanged)==null||h.call(c,l?l.slice():[]),this.stateService.markDirty("checked")}onMouseClicked(e,t){if(this.headerFocus=void 0,e.clickCount>1)return!1;let s=this.selectionService.onMouseClicked(e,t);if(!s&&this.getFocusModel){this.resetEditorRenderer();const o=this.getFocusModel();o&&(s=o.hasChanged(),o.clearChanged())}return s}debounceRepaint(){this.debounce(this.repaint.bind(this),1)}cancelPendingRepaint(){return this.debounceTimeout?(clearTimeout(this.debounceTimeout),this.debounceTimeout=null,!0):!1}publishGeMouseEvent(e){var t,s;(s=(t=this.eventListener).onMouseClicked)==null||s.call(t,e)}onFocusChanged(e){var t,s;(s=(t=this.eventListener).onFocusChanged)==null||s.call(t,e)}stateChanged(e){var t,s;(s=(t=this.eventListener).onStateChanged)==null||s.call(t,e)}afterRenderPass(){var e,t,s,o;(e=this.stateService)==null||e.rendered(),(t=this.fillHandleService)==null||t.update(),(s=this.cellEditorService)==null||s.update(),(o=this.clipboardService)==null||o.update()}onSelectionChanged(e){var t,s,o;if((t=this.stateService)==null||t.markDirty("selection"),this.selectionEventsHeld>0){this.heldSelectionModel=e;return}(o=(s=this.eventListener).onSelectionChanged)==null||o.call(s,e)}holdSelectionEvents(e){var t,s;this.selectionEventsHeld++;try{e()}finally{if(this.selectionEventsHeld--,this.selectionEventsHeld===0&&this.heldSelectionModel){const o=this.heldSelectionModel;this.heldSelectionModel=void 0,(s=(t=this.eventListener).onSelectionChanged)==null||s.call(t,o)}}}externalFilterChanged(e=!0){const t=this.tableOptions.externalFilterFunction;if(t&&(e&&this.clearSelectionModel(),this.tableModel.externalFilterChanged(t),this.reapplySorting(),this.invalidateAggregates(),this.scrollViewport.scrollTo(0,0),this.tableModel.recalcHeightAndPadding(),this.resetSizeOfWrapperDiv(),this.repaint(),this.initialized)){const s=this.tableModel.getBodyModel().getRowCount();this.announce(this.ariaTexts.filtered(s),Ge.filterAnnouncementDelayInMs)}}onHeaderDblClicked(e,t,s){const o=this.tableModel.getColumnDef(s);o!=null&&o.sortable&&o.sortable()&&(e.preventDefault(),e.stopPropagation(),this.sortByColumn(s))}sortByColumn(e,t){var h;const s=typeof e=="number"?e:(this.tableModel.getColumnDefs()??[]).findIndex(d=>d.property===e),o=this.tableModel.getColumnDef(s);if(!o)return!1;const i=o.sortStatesOrder?o.sortStatesOrder:this.tableOptions.sortOrder,r=o.sortState??"",l=t??i[(i.indexOf(r)+1)%i.length],a=new jt(s,l),c=this.tableModel.doSort([a]);return c&&(this.invalidateAggregates(),this.lastSortCompareFn=void 0,(h=this.tableModel.getColumnDefs())==null||h.forEach(d=>d.sortState=""),o.sortState=l),this.repaint(),c&&this.stateService.sortedByColumn(l?o.property:void 0),c&&this.announce(this.ariaTexts.sorted(this.getColumnAriaLabel(s),l)),!0}scrollToPixel(e,t){this.setContentScrollPosition(e,t)&&this.adjustAfterScrolling()}scrollToIndex(e,t){const s=this.getBodyRowTop(t);this.scrollToPixel(this.getScrollLeftForColumnIndex(e),s)}getScrollLeftForColumnIndex(e){const t=this.scrollViewport,s=this.tableModel.getFixedLeftColumnCount(),o=this.tableModel.getColumnCount()-this.tableModel.getFixedRightColumnCount()-1;if(e>=0&&e<s)return 0;if(!(e>=s&&e<=o))return this.getViewportScrollLeft();let i=0;for(let a=s;a<e;a++)i+=this.tableModel.getColumnWidth(a);const r=this.tableModel.getContentWidthInPixel()-this.areaBodyCenterGeo.width,l=t.scrollWidth-t.clientWidth;return r<=0||l<=0?0:Math.min(1,i/r)*l}adjustAfterScrolling(){var t,s;if(super.adjustAfterScrolling(),this.adjustingRowNumberWidth)return;const e=this.scrollViewport;(s=(t=this.eventListener).onScroll)==null||s.call(t,new Ln(this.scrollTop,this.scrollLeft,e.scrollHeight,e.scrollWidth,e.clientHeight,e.clientWidth,this.scrollFactorY,this.scrollFactorX))}setSelectionModel(e,t=!1){var o;(o=this.selectionModel())==null||o.removeEventSelectionChangedListener(this),e.addEventSelectionChangedListener(this);const s=()=>e;this.tableOptions.getSelectionModel=s,this.getSelectionModel=s,this.selectionService.getSelectionModel=s,t&&this.repaint()}toggleHeaderGroup(e){const t=this.tableModel.getAreaModel("header");"columnDefs"in this.tableModel&&(this.tableModel.columnDefs=t.toggleHeaderGroup(e)),this.headerGroupsChanged()}setHeaderGroupCollapsed(e,t){var i;const s=this.tableModel.getAreaModel("header"),o=(i=s.setGroupClosed)==null?void 0:i.call(s,e,t);return o?("columnDefs"in this.tableModel&&(this.tableModel.columnDefs=o),this.headerGroupsChanged(),!0):!1}headerGroupsChanged(){this.firstInit(),this.stateService.markDirty("headerGroups"),this.stateService.markDirty("columns")}selectionModel(){if(this!=null&&this.getSelectionModel)return this.getSelectionModel()}focusModel(){if(this!=null&&this.getFocusModel)return this.getFocusModel()}setDragging(e){this.dragging=e,this.dragging?(this.storeColumnWidths(),this.lastDragFrom=-1,this.lastDragTo=-1):this.storedColumnWidths=[]}changeFocusCell(e,t){var s;if(!this.isEditing()&&this.getFocusModel){const o=this.getFocusModel();if(o){const i=this.tableModel.getBodyModel().getRowCount(),r=this.tableModel.getColumnCount();if(i<1||r<1)return!1;const[l,a]=o.getFocus(),c=Math.min(Math.max(l+t,0),i-1),h=this.getNextShownColumnIndex(a,e,r);return c!==l||h!==a?(o.setFocus(c,h),this.ensureColumnIsVisible(h),this.ensureRowIsVisible(c),this.afterActiveCellMoved(c,h),this.repaint()):(s=this.editingOptions)!=null&&s.collapseSelectionOnNavigate&&(this.afterActiveCellMoved(c,h),this.repaint()),!0}}return!1}getNextShownColumnIndex(e,t,s){if(!t){const l=Math.min(Math.max(e,0),s-1);return e<0&&this.tableModel.getColumnWidth(l)<=0?this.getNextShownColumnIndex(-1,1,s):l}const o=t>0?1:-1;let i=e,r=e;for(let l=Math.abs(t);l>0;l--){for(r+=o;r>=0&&r<s&&this.tableModel.getColumnWidth(r)<=0;)r+=o;if(r<0||r>=s)break;i=r}return Math.min(Math.max(i,0),s-1)}resizeColumn(e){const t=this.isRtl()?-e.draggingX:e.draggingX,s=this.clampToColumnWidthLimits(this.mouseStartColumnIndex,this.mouseStartWidth+t,this.mouseStartWidth);this.tableModel.setColumnWidth(this.mouseStartColumnIndex,s),this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}clampToColumnWidthLimits(e,t,s){var c,h,d;const o=(d=(h=(c=this.tableModel).getColumnDefs)==null?void 0:h.call(c))==null?void 0:d[e];if(!o)return t;const i=this.getAvailableColumnWidth(),r=u=>{if(!(!u||!Number.isFinite(u.value))){if(u.unit==="px")return u.value;if(u.unit==="%"&&i>0)return Math.floor(u.value*i/100)}};let l=r(o.minWidth),a=r(o.maxWidth);return l!==void 0&&a!==void 0&&l>a||(s!==void 0&&s>=0&&(l!==void 0&&(l=Math.min(l,s)),a!==void 0&&(a=Math.max(a,s))),l!==void 0&&(t=Math.max(l,t)),a!==void 0&&(t=Math.min(a,t))),t}clearSelectionModel(){var e;this.getSelectionModel&&((e=this.getSelectionModel())==null||e.clear())}calcAutoColumnWidths(){if(!this.tableModel.getBodyModel())return console.warn("Body model is not available."),[];const e=Array.from({length:this.tableModel.getColumnCount()},(t,s)=>s);return this.measureDefaultColumnWidths(e,new ot(this.hostElement))}measureDefaultColumnWidths(e,t){const s=e.map(()=>new Set),o=e.map(()=>0);return["header","body","footer"].forEach(i=>{const r=this.tableModel.getAreaModel(i),[l,a]=i==="body"?this.getMeasuredBodyRows():[0,((r==null?void 0:r.getRowCount())??0)-1];_h(r,l,a,e,s,o)}),s.map(i=>t.measureWidest(i))}getMeasuredBodyRows(){var i;const e=((i=this.tableModel.getBodyModel())==null?void 0:i.getRowCount())??0;if(e<=this.getColumnAutoWidthOptions().maxRows)return[0,e-1];const t=this.renderedBodyRows,s=Math.min(Math.max(0,t.first),e-1),o=t.last>=s?Math.min(t.last,e-1):Math.min(s+50,e-1);return[s,o]}getColumnAutoWidthOptions(){return fo.create(this.tableOptions.columnAutoWidth)}calcAutoColumnWidth(e,t,s,o){let i=o;const r=()=>(i===void 0&&(i=this.measureDefaultColumnWidths([e],s)[0]),i),l=this.getColumnAutoWidthOptions().getWidth;let a;if(l){const c=this.tableModel.getColumnDef(e),h={columnIndex:e,columnDef:c,property:c==null?void 0:c.property,source:t,firstRenderedRow:this.renderedBodyRows.first,lastRenderedRow:this.renderedBodyRows.last,measureText:u=>s.measureText(u),getDefaultWidth:r},d=l(h);a=typeof d=="number"&&Number.isFinite(d)&&d>=0?Math.round(d):void 0}return this.clampToColumnWidthLimits(e,a??r())}autoResizeColumn(e){const t=this.resolveColumnIndex(e);if(t<0||!this.isColumnAutoResizable(t))return;const s=this.calcAutoColumnWidth(t,"api",new ot(this.hostElement));return this.tableModel.setColumnWidth(t,s),this.recalcWrappers(),this.stateService.markDirty("columns"),s}autoResizeColumnByUser(e,t){if(!this.tableOptions.columnsResizable||!this.getColumnAutoWidthOptions().doubleClick||e<0||e>=this.tableModel.getColumnCount()||!this.isColumnAutoResizable(e))return!1;const s=this.tableModel.getColumnWidth(e),o=this.tableModel.getColumnDef(e),i={kind:"resize",source:"dblclick",columnIndex:e,currentIndex:e,columnDef:o,startWidth:s,moves:[],started:!0,cancelled:!1},r=this.calcAutoColumnWidth(e,"dblclick",new ot(this.hostElement)),l=this.columnDrag;this.columnDrag=i;try{if(this.emitColumnDragEvent(i,"start",t),i.cancelled||this.isDestroyed())return!0;this.tableModel.setColumnWidth(e,r),this.recalcWrappers(),this.stateService.markDirty("columns"),this.emitColumnDragEvent(i,"end",t)}finally{this.columnDrag===i&&(this.columnDrag=l)}return!0}isColumnAutoResizable(e){var s;const t=this.tableModel.getColumnDef(e);return this.isColumnResizable(e)&&!N(t)&&((s=t==null?void 0:t.isVisible)==null?void 0:s.call(t))!==!1}resolveColumnIndex(e){var o,i;const t=this.tableModel.getColumnCount();if(typeof e=="number")return Number.isInteger(e)&&e>=0&&e<t?e:-1;const s=((i=(o=this.tableModel).getColumnDefs)==null?void 0:i.call(o))??[];return typeof e=="string"?s.findIndex(r=>r.property===e):s.indexOf(e)}setColumnWidth(e,t){this.tableModel.setColumnWidth(e,t),this.stateService.markDirty("columns")}setColumnVisible(e,t){var s,o;return(o=(s=this.tableModel).setColumnVisible)!=null&&o.call(s,e,t)?(this.recalcWrappers(),this.stateService.markDirty("columns"),!0):!1}setHeaderVisible(e){this.setAreaVisible("header",e)}setFooterVisible(e){this.setAreaVisible("footer",e)}setAreaVisible(e,t){const s=this.tableModel,o=e==="header"?s.setHeaderVisible:s.setFooterVisible;if(!o){console.warn(`set${e==="header"?"Header":"Footer"}Visible() needs a table model with this method (e.g. TableModel), this one has none:`,s);return}o.call(s,t),e==="header"&&!t&&(this.headerFocus=void 0),this.recalcWrappers()}autoResizeColumns(e=!0){const t=this.tableModel.getColumnCount();if(!this.tableModel.getBodyModel()){console.warn("Body model is not available.");return}const s=new ot(this.hostElement),o=Array.from({length:t},(r,l)=>l),i=this.measureDefaultColumnWidths(o,s);for(let r=0;r<t;r++)this.isColumnAutoResizable(r)&&this.tableModel.setColumnWidth(r,this.calcAutoColumnWidth(r,"api",s,i[r]));e&&this.recalcWrappers(),this.stateService.markDirty("columns")}recalcWrappers(){this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}appendRows(e,t={}){const s=this.tableModel.getBodyModel();if(!s.appendRows||this.tableSheet||this.isRowGroupingOrTree())return console.warn("appendRows() works with an AreaModelObjectArray body (TableFactory.createTableModel({ rows })) without cell formulas – use rowsAppended() for an own area model. Nothing changed."),!1;const o=s.appendRows(e,{filter:this.tableOptions.externalFilterFunction,compare:this.getActiveSortComparator(),maxRows:t.maxRows});return o?this.afterRowsAppended(o,t.follow??"auto"):(console.warn("appendRows(): the body model did not append the rows."),!1)}notifyRowsAppended(e,t={}){const s=Math.max(0,this.tableModel.getBodyModel().getRowCount()),o=Math.max(0,Math.min(Math.floor(e)||0,s)),i=this.renderedBodyRows.count,r=Math.max(0,Math.min(Math.floor(t.removedAtStart??0)||0,i)),l=new Int32Array(r);for(let c=0;c<r;c++)l[c]=c;const a=new Int32Array(o);for(let c=0;c<o;c++)a[c]=s-o+c;return this.afterRowsAppended({added:o,shown:o,removed:r,removedPositions:l,insertedPositions:a},t.follow??"auto")}getActiveSortComparator(){var s,o;if(this.lastSortCompareFn)return this.lastSortCompareFn;const e=[];(s=this.tableModel.getColumnDefs())==null||s.forEach((i,r)=>{(i.sortState==="asc"||i.sortState==="desc")&&e.push(new jt(r,i.sortState))});const t=this.tableModel.getBodyModel();return e.length?(o=t.createSortComparator)==null?void 0:o.call(t,e):void 0}afterRowsAppended(e,t){var m,b,y,C,v,E;const s=new Vl(e.removedPositions,e.insertedPositions),o=this.renderedBodyRows,i=this.selectionModel(),r=((m=i==null?void 0:i.adjustForRowChanges)==null?void 0:m.call(i,s))??!1;(y=(b=this.focusModel())==null?void 0:b.adjustForRowChanges)==null||y.call(b,s),this.selectionService.adjustForRowChanges(s),this.mouseHandler.adjustForRowChanges(s),this.shiftEditorRow(s);const l=this.tableModel.getBodyModel().getRowCount(),a=this.focusModel();a&&l>0&&a.getFocus()[0]>=l&&a.setFocus(l-1,a.getFocus()[1]),e.removed&&((C=this.batchEditService)==null||C.pruneOrphans());const c=this.colAndRowspanModels.body;c&&!c.updateForInsertedRows(e.insertedPositions)&&!s.isEmpty()&&c.init(),this.invalidateAggregates();const h=this.mouseHandler.isButtonDown()||!!((v=this.rowDragService)!=null&&v.isDragging())||!!((E=this.fillHandleService)!=null&&E.isFilling()),d=this.followHeldAt,u=o.atEnd||d!==void 0&&Math.abs(this.contentScrollTop-d)<1,f=t===!0||t==="auto"&&u&&!h;let g;if(f)g=Number.MAX_SAFE_INTEGER;else if(o.count>0){const S=s.mapIndex(o.first)>=0,R=Math.min(s.mapIndexOrNext(o.first),Math.max(0,l-1));g=l>0?this.getBodyRowTop(R)+(S?o.offset:0):0}else g=0;return!f&&s.getRemovedCount()===0&&o.count>0&&o.last<o.count-1&&!s.touchesUpTo(o.last)&&this.canKeepDrawnRows()&&this.updateRowCountWithoutRender(g)||this.repaintHard({py:g}),this.followHeldAt=t==="auto"&&h&&u?this.contentScrollTop:void 0,r&&i&&this.onSelectionChanged(i),{added:e.added,shown:e.shown,removed:e.removed,following:f}}canKeepDrawnRows(){var s;if(this.getFirstDataColumnIndex()>0||this.masterDetailService||this.tableModel.isRowCheckboxVisible()||this.tableOptions.showCheckboxWihoutExtraColumn)return!1;const e=this.tableModel.getAreaModel("footer");if(e.getRowCount()>0&&e.invalidateDerivedValues)return!1;const t=this.tableModel.getBodyModel();return!((s=t.hasDerivedColumns)!=null&&s.call(t))}reSort(){this.reapplySorting(),this.invalidateAggregates(),this.repaint()}sort(e){var t;this.tableModel.sort(e),this.invalidateAggregates(),this.lastSortCompareFn=e,(t=this.tableModel.getColumnDefs())==null||t.forEach(s=>s.sortState=""),this.repaint(),this.stateService.sortedByColumn(void 0)}applySortItems(e){const t=this.tableModel.getColumnDefs();t==null||t.forEach(s=>s.sortState=""),e.forEach(s=>{const o=t==null?void 0:t[s.columnIndex];o&&(o.sortState=s.sortState)}),e.length&&(this.lastSortCompareFn=void 0,this.tableModel.doSort(e),this.invalidateAggregates())}reapplySorting(){var t;if(this.lastSortCompareFn){this.tableModel.sort(this.lastSortCompareFn);return}const e=[];(t=this.tableModel.getColumnDefs())==null||t.forEach((s,o)=>{s.sortState&&e.push(new jt(o,s.sortState))}),e.length&&this.tableModel.doSort(e)}ensureRowIsVisible(e){if(this.hasBodyRowExtras()){const i=this.getBodyRowTop(e),r=i+this.tableModel.getRowHeight("body",e),l=this.contentScrollTop,a=this.areaBodyCenterGeo.height;return i<l?(this.scrollToPixel(this.getViewportScrollLeft(),i),!0):r>l+a?(this.scrollToPixel(this.getViewportScrollLeft(),r-a),!0):!1}const t=this.getFirstFullVisibleRowIndex(),s=this.getLastFullVisibleRowIndex(),o=this.getDisplayedRowCount();return e<t?(this.scrollToIndex(-1,e),!0):e>s?(this.scrollToIndex(-1,e-o+1),!0):!1}ensureColumnIsVisible(e){const t=this.tableModel.getFixedLeftColumnCount(),s=this.tableModel.getColumnCount()-this.tableModel.getFixedRightColumnCount()-1;if(!(e>=t&&e<=s))return!1;const o=this.tableModel.getColumnWidth(e),i=this.scrollViewport,r=this.areaBodyCenterGeo.width,l=this.tableModel.getContentWidthInPixel()-r,a=i.scrollWidth-i.clientWidth;if(o<=0||l<=0||a<=0)return!1;let c=0;for(let f=t;f<e;f++)c+=this.tableModel.getColumnWidth(f);const h=Math.min(1,Math.max(0,this.getViewportScrollLeft()/a))*l;let d;if(c<h-.5)d=c;else if(c+o>h+r+.5)d=o>r?c:c+o-r;else return!1;const u=Math.min(1,Math.max(0,d/l))*a;return this.setViewportScrollLeft(d===c?Math.floor(u):Math.ceil(u)),this.adjustAfterScrolling(),!0}};Ge.actionsBlockedWhileLoading=["START_EDITING","TOGGLE_SELECTION","ACTIVATE_CELL","MOVE_ROW_UP","MOVE_ROW_DOWN","FILL_DOWN","FILL_RIGHT","CLEAR_CELLS","CLEAR_AND_EDIT","CUT_2_CLIPBOARD","PASTE_FROM_CLIPBOARD","UNDO","REDO"],Ge.filterAnnouncementDelayInMs=400;let Xo=Ge;class Bh extends Yt{constructor(e){super(),this.onCheckboxChangedCallback=e,super.onCheckboxChanged=t=>{this.onCheckboxChangedCallback(t)}}}const Ws=class Ws{};Ws.themes=["light","combat","paper","blackboard"],Ws.vars={light:`html[data-theme="light"] {
72
72
  --ge-table-bg: rgba(255,255,255, 0.5);
73
73
  --ge-table-header-west-bg: rgba(233, 233, 233, 0.5);
74
74
  --ge-table-header-center-bg: rgba(233, 233, 233, 0.5);