@guiexpert/table 1.1.103 → 1.1.105
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 +13 -13
- package/index.js +423 -354
- package/lib/table/ele-scope.d.ts +33 -0
- package/lib/table/render-scope.d.ts +16 -0
- package/package.json +3 -2
package/index.cjs
CHANGED
|
@@ -38,14 +38,14 @@ export class ${t} implements CellRendererIf {
|
|
|
38
38
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
`)}}class Ao{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 kr{constructor(){this.property="",this.value="",this.path="",this.propertyItem=new oi("",[new si("")])}toString(){var e;return`${this.path} -> : ${((e=this.propertyItem)==null?void 0:e.toString())??""}`}}const Eo="Entity";function Fr(n){let e=Lr(Or(n));return e.includes(Eo)||(e=e+Eo),e}function Lr(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 Or(n){return!n||n.length===0?"":n[0].toUpperCase()+n.slice(1)}class ga{constructor(){this.debugging=!1}json2PropertyType(e,t=""){let s;if(typeof e=="string"){const o=new Ao().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 Ao().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=>!Yt.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 Ce&&(l=!0,c.properties.push(o.propertyItem))}if(!l)for(const c of o.propertyItem.types)r.propertyItem.types.push(c)}}}return t||new si("")}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===Ct)||i.propertyItem.types.push(new ms(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 kr;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===St&&!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 oi(t,[this.createPropertyType(e,t)])}createPropertyType(e,t){return e===null?new Mr(t):e===void 0?new ms(t):typeof e===ei?new Tr(t):typeof e===Us&&!isNaN(e)?new Ir(t):typeof e===Ks?new Dr(t):Array.isArray(e)?new We(t):typeof e===St?new Ce(t,Fr(t)):new ms(t)}}class pa{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 Ce){const i=o;i!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(i)}}else if(e instanceof Ce){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 Ce)c!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(c);else if(c instanceof We)for(const h of c.items)h instanceof Ce&&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!==Ct).sort((i,r)=>Yt.includes(i)?100:Yt.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 Ce?e.className:e.type}containsUndefinedPropertyType(e){for(const t of e.types)if(t.type===Ct)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 ii(n){return!!n&&n.type==="CheckboxCellRenderer"}function me(n){return n&&n.type==="CheckboxColumnDef"}function O(n){return!!n&&n.type==="RowNumberColumnDef"}function Pr(n){return!!n&&n.type==="AreaModelAggregateFooter"}function le(n){return!!n&&n.type==="RowGroup"}function Mo(n){return U(n)&&le(n.data)}function ne(n){return!!n&&n.kind==="AreaModelRowGroups"}function ot(n){return!!n&&n.type==="RowGroupColumnDef"}function Cs(n){return!!n&&n.kind==="PivotTableModel"}function To(n){return!!n&&n.kind==="AreaModelPivot"}function zs(n){return!!n&&n.type==="PivotColumnDef"}function Nr(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 Vr(n,e){const t=n.scrollLeft;return e?Math.max(0,-t):t}function _r(n,e,t){n.scrollLeft=t?-e:e}function Ss(n,e){return e&&n!==0?-n:n}function Br(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 $r(n,e,t,s){return s?e+t-n:n-e}function Hr(n){return n.split(" ").map(e=>e==="left"?"right":e==="right"?"left":e).join(" ")}class js{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 js(this.rowIndex,this.rowTop,this.columnIndex,this.columnLeft,this.areaIdent,this.sideIdent,this.originalEvent,this.clickCount,this.draggingX,this.draggingY,this.action)}}class Ee{constructor(e=">",t="",s=[]){this.content=e,this.style=t,this.classes=s}}class ri{constructor(e=new Ee(">","transform: rotate(90deg) translate(66%, -66%); transform-origin: 0 0;",["gt-table-tree-arrow-expanded"]),t=new Ee(">","",["ge-table-tree-arrow-collapsed"]),s=new Ee(">","color:transparent;",["gt-table-tree-arrow-hidden"]),o=new Ee("↕","",["gt-table-tree-arrow-expanded-all"])){this.arrowExpanded=e,this.arrowCollapsed=t,this.arrowPlaceholder=s,this.arrowExpandCollapseAll=o}}class ni{constructor(e=new Ee("↑","",["ge-header-sorted-asc"]),t=new Ee("↓","",["ge-header-sorted-desc"]),s=new Ee("↑","color:transparent;",[])){this.iconAsc=e,this.iconDesc=t,this.iconPlaceholder=s}}const Ns=class Ns{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 ni,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 ri,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=Ns.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)}};Ns.focusBorderWidthInPx=2;let xs=Ns;const rs=n=>n==="header"?"header":n==="footer"?"footer":"body";class vs{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=rs(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 Gr{constructor(e){this.tableScope=e,this.doubleClickDelay=500,this.lastClickedCellKey="",this.mouseDown=!1,this.repaintAfterMouseUp=!1,this.dragging=!1,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}),this.tableScope.hostElement._MouseHandler="true",this.tableScope.scrollViewport.addEventListener("scroll",this.tableScope.adjustAfterScrolling.bind(this.tableScope),{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.mouseEvent=e;const t=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.contextmenu(t)}onHostElementClicked(e){var l;if(this.isBlocked(e))return;const t=Date.now(),s=this.tableScope.getMouseEventTarget(e),o=this.getCellKey(s),i=e.detail>=2||e.detail===0&&t-this.lastClicked<this.doubleClickDelay&&o===this.lastClickedCellKey;this.lastClicked=t,this.lastClickedCellKey=o;const r=new vs(s,this.tableScope);if(i&&(this.reportedDoubleClick={time:t,cellKey:o}),i&&!this.isClickAction(r)){this.publishGeMouseEvent(e,2);return}if(r.action==="toggleExpandCollapseAll")this.tableScope.toggleExpandCollapseAll(!this.tableScope.allExpanded),e.preventDefault(),e.stopPropagation();else if(r.action==="toggle-detail")this.tableScope.toggleDetail(r.rowIdx,"mouse"),e.preventDefault(),e.stopPropagation();else if(r.action==="toggleHeaderGroup")this.tableScope.toggleHeaderGroup(r),e.preventDefault(),e.stopPropagation();else if(r.inputType==="checkbox"&&r.areaIdent)this.tableScope.toggleRowCheckbox(r.rowIdx,r.colIdx,r.areaIdent),e.preventDefault(),e.stopPropagation();else if(U(r.row)&&r.areaModel){const a=r.colIdx===this.getArrowColumnIndex()&&e.altKey,c=r.className.includes("ge-table-tree-arrow-div");if(a||c){e.preventDefault(),e.stopPropagation();const h=r.row;this.tableScope.setTreeRowExpanded(h,!h.expanded)}}r.areaIdent==="body"&&((l=this.tableScope.focusModel())==null||l.setFocus(r.rowIdx,r.colIdx)),this.publishGeMouseEvent(e,i?2:1)}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){var i,r,l;if(this.isBlocked(e))return;this.lastClicked=Date.now();const t=this.tableScope.getMouseEventTarget(e),s=this.tableScope.createGeMouseEvent(e);if(t instanceof HTMLElement&&!this.isClickAction(new vs(t,this.tableScope))){const a=t.closest("[data-col-index]")??t,c=((i=a.closest("[data-area]"))==null?void 0:i.getAttribute("data-area"))??null,h=rs(c),d=Number((r=a.closest("[data-row-index]"))==null?void 0:r.getAttribute("data-row-index")),u=Number(a.getAttribute("data-col-index")),f=this.tableScope.tableModel.getAreaModel(h);if(c&&h==="header"){const g=(l=f.isColumnLetterRow)==null?void 0:l.call(f,d);this.tableScope.tableModel.isSortable(u)&&!g&&(this.tableScope.clearSelection(),this.tableScope.onHeaderDblClicked(e,d,u))}else if(a.getAttribute("data-row-index")){const g=f.getRowByIndex(d);if(c&&h==="body"&&f.isEditable(d,u)&&this.tableScope.startEditing(d,u,"edit"),U(g)&&u===this.getArrowColumnIndex()){e.preventDefault(),e.stopPropagation();const p=g;this.tableScope.setTreeRowExpanded(p,!p.expanded)}}}const o=this.reportedDoubleClick;(!o||Date.now()-o.time>this.doubleClickDelay||o.cellKey!==this.getCellKey(t))&&this.publishGeMouseEvent(e,2,s),this.reportedDoubleClick=void 0}publishGeMouseEvent(e,t,s){var i;this.mouseEvent=e,this.geMouseEventOld=(i=this.geMouseEvent)==null?void 0:i.clone(),this.geMouseEvent=s??this.tableScope.createGeMouseEvent(e),this.geMouseEvent&&(this.geMouseEvent.clickCount=t);const o=this.tableScope.onMouseClicked(this.geMouseEvent,this.geMouseEventOld);this.tableScope.publishGeMouseEvent(this.geMouseEvent),o&&!this.isInteractiveCellElement(e.target)&&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){this.isBlocked(e)||(this.tableScope.cancelPendingRepaint()&&(this.repaintAfterMouseUp=!0),this.dragging||(this.mouseEvent=e,this.startMouseEvent=this.tableScope.createGeMouseEvent(this.mouseEvent),this.tableScope.onMouseDown(this.startMouseEvent),this.mouseDown=!0))}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}!this.mouseDown&&this.isBlocked(e)||(this.mouseEvent=e,this.mouseDown?(this.dragging||(this.dragging=!0,this.tableScope.setDragging(!0)),requestAnimationFrame(this.mouseDraggingOnFrame.bind(this))):requestAnimationFrame(this.mouseMoveOnFrame.bind(this)))}onMouseUp(e){var t,s;!this.mouseDown&&((s=(t=this.tableScope).isEventInDetail)!=null&&s.call(t,e))||(this.mouseEvent=e,this.repaintAfterMouseUp&&(this.repaintAfterMouseUp=!1,this.tableScope.debounceRepaint()),this.dragging&&requestAnimationFrame(this.mouseDraggingEndOnFrame.bind(this)),this.mouseDown=!1,this.dragging=!1,this.tableScope.setDragging(!1))}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)}}mouseDraggingEndOnFrame(){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.mouseDraggingEndOnFrame(t)}}mouseMoveOnFrame(){if(this.mouseEvent){const e=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.mouseMove(e)}}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 Wr=()=>!1;function Ur(n){return n.editable===void 0||n.editable===Wr}function li(n){return typeof n=="number"&&!Number.isNaN(n)}function ma(n){if(li(n))return n;if(n instanceof Date){const e=n.getTime();return Number.isNaN(e)?void 0:e}}function ai(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 zr(n,e){ai(n,e.sum),n.compensation+=e.compensation}const ba={name:"sum",init:()=>({sum:0,compensation:0}),add:(n,e)=>(li(e)&&ai(n,e),n),merge:(n,e)=>(zr(n,e),n),result:n=>Kr(n)},wa={name:"count",init:()=>0,add:n=>n+1,merge:(n,e)=>n+e,result:n=>n},ya={name:"avg",init:()=>({sum:0,compensation:0,count:0}),add:(n,e)=>(li(e)&&(ai(n,e),n.count++),n),merge:(n,e)=>(zr(n,e),n.count+=e.count,n),result:n=>n.count?Kr(n)/n.count:void 0};function Vi(n,e){return{name:n,init:()=>({has:!1,value:void 0,key:0}),add:(t,s)=>{const o=ma(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 Ca={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},Sa={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},xa={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:ba,count:wa,avg:ya,min:Vi("min",(n,e)=>n<e),max:Vi("max",(n,e)=>n>e),countDistinct:Ca,first:Sa,last:xa});function Xs(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 ns(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 ls(n,e){const t=typeof e=="string"||!("aggregator"in e)?{aggregator:e}:e,s=Xs(t.aggregator),o=t.value??n;return{key:n,aggregator:s,value:o,getValue:s===Oe.count?void 0:ns(o),format:t.format}}function Ys(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 va(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 Ra(n,e,t){const s=ls("",{aggregator:t,value:e}),[o]=Ys(n,[s]);return s.aggregator.result(o)}function Aa(n,e){const t=Object.keys(e).map(i=>ls(i,e[i])),s=Ys(n,t),o={};return t.forEach((i,r)=>o[i.key]=i.aggregator.result(s[r])),o}const Ea=new Intl.NumberFormat("en-US",{maximumFractionDigits:2});function It(n){return n==null?"":typeof n=="number"?Number.isFinite(n)?Ea.format(n):String(n):n instanceof Date?Number.isNaN(n.getTime())?"":n.toLocaleDateString("en-US"):String(n)}const Ma=new Set(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal"]),_i=new Map,Ta=new Intl.NumberFormat("en-US",{maximumFractionDigits:0});function Dt(n){if(!n)return;const e=typeof n=="string"?{mode:n}:n;return jr.includes(e.mode)?e:void 0}const jr=Object.freeze(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal","differenceFromPrevious","runningTotal","rank"]);function ci(n){return!!n&&Ma.has(n)}function Js(n,e){const t=Dt(e);if(typeof n!="number"||Number.isNaN(n)||!t)return n==null?"":`${n}`;if(t.format)return`${t.format(n)??""}`;if(ci(t.mode)){const s=Bi(t.fractionDigits??1);let o=_i.get(s);return o||(o=new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:s,maximumFractionDigits:s}),_i.set(s,o)),o.format(n)}if(t.mode==="rank")return Ta.format(n);if(t.fractionDigits!==void 0){const s=Bi(t.fractionDigits);return new Intl.NumberFormat("en-US",{minimumFractionDigits:s,maximumFractionDigits:s}).format(n)}return It(n)}function Bi(n){return Math.min(10,Math.max(0,Math.trunc(Number(n)||0)))}function at(n){return typeof n=="number"&&!Number.isNaN(n)}function qs(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 hi(n,e){const t=n.length,s=new Array(t);switch(e){case"percentOfColumnTotal":case"percentOfGrandTotal":case"percentOfParentTotal":{const o=qs(n);for(let i=0;i<t;i++)s[i]=Ia(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]=at(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]=at(i)&&at(r)?i-r:void 0}return s;case"rank":{const o=[];for(let r=0;r<t;r++)at(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]=at(n[o])?n[o]:void 0;return s}}function Ia(n,e){return at(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 Da{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=Xs(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=Dt(i.showValuesAs);r&&s.set(i.property,r)}return this.getters=t,this.showValuesAs=s,this.properties=o,this.defsLength=e.length,t}}class kt{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 as{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){return this.defaultRowHeight>0?this.defaultRowHeight*e:this.yPositions[e]}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&&Ur(s)?!me(s)&&!O(s)&&!ot(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 Da({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 Js(t,o);if(i)return t==null?"":`${t}`}getCalculatedRenderer(e){if(e!==void 0&&this.getColumnValues().getShowValuesAs(e))return this.calcTextRenderer??(this.calcTextRenderer=new kt)}addCalculatedClasses(e,t,s){return t!==void 0&&this.getColumnValues().isCalculated(t)&&w(s())?[...e,"ge-table-cell-error"]:e}}class di{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 it(n,e){return ka(n,e)?n:Array.from(new Set(n)).filter(t=>Number.isInteger(t)&&t>=0&&t<e).sort((t,s)=>t-s)}function ka(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 ui(n){return n.position==="before"?n.rowIndex:n.rowIndex+1}function Io(n,e){if(!n.length)return-1;const t=ui(e);return t-n.filter(s=>s<t).length}function Xr(n,e,t){const s=it(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 fi(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 gi(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 Yr(n,e,t,s){const o=fi(e);if(!gi(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,Jr(a,i?i.deep+1:0);return!0}function Jr(n,e){n.deep=e;for(const t of n.children??[])Jr(t,e+1)}function Zs(n,e,t,s){return n===e&&s.position!=="inside"&&Number.isInteger(s.rowIndex)&&s.rowIndex>=0&&s.rowIndex<n&&it(t,n).length>0}function pi(n,e,t,s){if(!Zs(n.length,e.length,t,s))return!1;if(Xr(n,it(t,n.length),ui(s)),e!==n)for(let o=0;o<n.length;o++)e[o]=n[o];return!0}function Fa(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}class K extends as{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 di,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.showValuesCache.clear()}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 Zs(this.filteredRows.length,this.rows.length,e,t)}moveRows(e,t){const s=pi(this.filteredRows,this.rows,e,t);return s&&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=qs(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=hi(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===K.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.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(),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.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 Vs=class Vs{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)>Vs.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 S=o.getValueAt(y,C);typeof S=="number"&&!Number.isNaN(S)&&(s.numericCount++,u=c.add(u,S),f=h.add(f,S),g=d.add(g,S))}}),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||O(l)||me(l)||o.push(r)}return o}};Vs.maxCells=1e6;let Rs=Vs;function La(n){const e=Dt(n);if(!e||!ci(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 Pe(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 mt(n,e,t={}){const s=Pe(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 qr(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 Oa=["<=",">=","<>","!=","==","+","-","*","/","^","&","=","<",">"],Pa=["<=",">=","<>","+","-","*","/","^","&","=","<",">",":","%"],Na=/^#(REF!|N\/A|DIV\/0!|VALUE!|NAME\?|NUM!|NULL!|CIRC!|ERROR!)/i,Va={n:`
|
|
41
|
+
`)}}class Ao{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 kr{constructor(){this.property="",this.value="",this.path="",this.propertyItem=new oi("",[new si("")])}toString(){var e;return`${this.path} -> : ${((e=this.propertyItem)==null?void 0:e.toString())??""}`}}const Eo="Entity";function Lr(n){let e=Fr(Or(n));return e.includes(Eo)||(e=e+Eo),e}function Fr(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 Or(n){return!n||n.length===0?"":n[0].toUpperCase()+n.slice(1)}class ga{constructor(){this.debugging=!1}json2PropertyType(e,t=""){let s;if(typeof e=="string"){const o=new Ao().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 Ao().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=>!Yt.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 Ce&&(l=!0,c.properties.push(o.propertyItem))}if(!l)for(const c of o.propertyItem.types)r.propertyItem.types.push(c)}}}return t||new si("")}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===Ct)||i.propertyItem.types.push(new ms(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 kr;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===St&&!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 oi(t,[this.createPropertyType(e,t)])}createPropertyType(e,t){return e===null?new Mr(t):e===void 0?new ms(t):typeof e===ei?new Tr(t):typeof e===Us&&!isNaN(e)?new Ir(t):typeof e===Ks?new Dr(t):Array.isArray(e)?new We(t):typeof e===St?new Ce(t,Lr(t)):new ms(t)}}class pa{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 Ce){const i=o;i!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(i)}}else if(e instanceof Ce){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 Ce)c!==this.rootPropertyType&&this.renderTypeScriptInterfacesFifo.push(c);else if(c instanceof We)for(const h of c.items)h instanceof Ce&&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!==Ct).sort((i,r)=>Yt.includes(i)?100:Yt.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 Ce?e.className:e.type}containsUndefinedPropertyType(e){for(const t of e.types)if(t.type===Ct)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 ii(n){return!!n&&n.type==="CheckboxCellRenderer"}function me(n){return n&&n.type==="CheckboxColumnDef"}function O(n){return!!n&&n.type==="RowNumberColumnDef"}function Pr(n){return!!n&&n.type==="AreaModelAggregateFooter"}function le(n){return!!n&&n.type==="RowGroup"}function Mo(n){return U(n)&&le(n.data)}function ne(n){return!!n&&n.kind==="AreaModelRowGroups"}function ot(n){return!!n&&n.type==="RowGroupColumnDef"}function Cs(n){return!!n&&n.kind==="PivotTableModel"}function To(n){return!!n&&n.kind==="AreaModelPivot"}function zs(n){return!!n&&n.type==="PivotColumnDef"}function Nr(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 Vr(n,e){const t=n.scrollLeft;return e?Math.max(0,-t):t}function _r(n,e,t){n.scrollLeft=t?-e:e}function Ss(n,e){return e&&n!==0?-n:n}function Br(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 $r(n,e,t,s){return s?e+t-n:n-e}function Hr(n){return n.split(" ").map(e=>e==="left"?"right":e==="right"?"left":e).join(" ")}class js{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 js(this.rowIndex,this.rowTop,this.columnIndex,this.columnLeft,this.areaIdent,this.sideIdent,this.originalEvent,this.clickCount,this.draggingX,this.draggingY,this.action)}}class Ee{constructor(e=">",t="",s=[]){this.content=e,this.style=t,this.classes=s}}class ri{constructor(e=new Ee(">","transform: rotate(90deg) translate(66%, -66%); transform-origin: 0 0;",["gt-table-tree-arrow-expanded"]),t=new Ee(">","",["ge-table-tree-arrow-collapsed"]),s=new Ee(">","color:transparent;",["gt-table-tree-arrow-hidden"]),o=new Ee("↕","",["gt-table-tree-arrow-expanded-all"])){this.arrowExpanded=e,this.arrowCollapsed=t,this.arrowPlaceholder=s,this.arrowExpandCollapseAll=o}}class ni{constructor(e=new Ee("↑","",["ge-header-sorted-asc"]),t=new Ee("↓","",["ge-header-sorted-desc"]),s=new Ee("↑","color:transparent;",[])){this.iconAsc=e,this.iconDesc=t,this.iconPlaceholder=s}}const Ns=class Ns{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 ni,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 ri,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=Ns.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)}};Ns.focusBorderWidthInPx=2;let xs=Ns;const rs=n=>n==="header"?"header":n==="footer"?"footer":"body";class vs{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=rs(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 Gr{constructor(e){this.tableScope=e,this.doubleClickDelay=500,this.lastClickedCellKey="",this.mouseDown=!1,this.repaintAfterMouseUp=!1,this.dragging=!1,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}),this.tableScope.hostElement._MouseHandler="true",this.tableScope.scrollViewport.addEventListener("scroll",this.tableScope.adjustAfterScrolling.bind(this.tableScope),{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.mouseEvent=e;const t=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.contextmenu(t)}onHostElementClicked(e){var l;if(this.isBlocked(e))return;const t=Date.now(),s=this.tableScope.getMouseEventTarget(e),o=this.getCellKey(s),i=e.detail>=2||e.detail===0&&t-this.lastClicked<this.doubleClickDelay&&o===this.lastClickedCellKey;this.lastClicked=t,this.lastClickedCellKey=o;const r=new vs(s,this.tableScope);if(i&&(this.reportedDoubleClick={time:t,cellKey:o}),i&&!this.isClickAction(r)){this.publishGeMouseEvent(e,2);return}if(r.action==="toggleExpandCollapseAll")this.tableScope.toggleExpandCollapseAll(!this.tableScope.allExpanded),e.preventDefault(),e.stopPropagation();else if(r.action==="toggle-detail")this.tableScope.toggleDetail(r.rowIdx,"mouse"),e.preventDefault(),e.stopPropagation();else if(r.action==="toggleHeaderGroup")this.tableScope.toggleHeaderGroup(r),e.preventDefault(),e.stopPropagation();else if(r.inputType==="checkbox"&&r.areaIdent)this.tableScope.toggleRowCheckbox(r.rowIdx,r.colIdx,r.areaIdent),e.preventDefault(),e.stopPropagation();else if(U(r.row)&&r.areaModel){const a=r.colIdx===this.getArrowColumnIndex()&&e.altKey,c=r.className.includes("ge-table-tree-arrow-div");if(a||c){e.preventDefault(),e.stopPropagation();const h=r.row;this.tableScope.setTreeRowExpanded(h,!h.expanded)}}r.areaIdent==="body"&&((l=this.tableScope.focusModel())==null||l.setFocus(r.rowIdx,r.colIdx)),this.publishGeMouseEvent(e,i?2:1)}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){var i,r,l;if(this.isBlocked(e))return;this.lastClicked=Date.now();const t=this.tableScope.getMouseEventTarget(e),s=this.tableScope.createGeMouseEvent(e);if(t instanceof HTMLElement&&!this.isClickAction(new vs(t,this.tableScope))){const a=t.closest("[data-col-index]")??t,c=((i=a.closest("[data-area]"))==null?void 0:i.getAttribute("data-area"))??null,h=rs(c),d=Number((r=a.closest("[data-row-index]"))==null?void 0:r.getAttribute("data-row-index")),u=Number(a.getAttribute("data-col-index")),f=this.tableScope.tableModel.getAreaModel(h);if(c&&h==="header"){const g=(l=f.isColumnLetterRow)==null?void 0:l.call(f,d);this.tableScope.tableModel.isSortable(u)&&!g&&(this.tableScope.clearSelection(),this.tableScope.onHeaderDblClicked(e,d,u))}else if(a.getAttribute("data-row-index")){const g=f.getRowByIndex(d);if(c&&h==="body"&&f.isEditable(d,u)&&this.tableScope.startEditing(d,u,"edit"),U(g)&&u===this.getArrowColumnIndex()){e.preventDefault(),e.stopPropagation();const p=g;this.tableScope.setTreeRowExpanded(p,!p.expanded)}}}const o=this.reportedDoubleClick;(!o||Date.now()-o.time>this.doubleClickDelay||o.cellKey!==this.getCellKey(t))&&this.publishGeMouseEvent(e,2,s),this.reportedDoubleClick=void 0}publishGeMouseEvent(e,t,s){var i;this.mouseEvent=e,this.geMouseEventOld=(i=this.geMouseEvent)==null?void 0:i.clone(),this.geMouseEvent=s??this.tableScope.createGeMouseEvent(e),this.geMouseEvent&&(this.geMouseEvent.clickCount=t);const o=this.tableScope.onMouseClicked(this.geMouseEvent,this.geMouseEventOld);this.tableScope.publishGeMouseEvent(this.geMouseEvent),o&&!this.isInteractiveCellElement(e.target)&&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){this.isBlocked(e)||(this.tableScope.cancelPendingRepaint()&&(this.repaintAfterMouseUp=!0),this.dragging||(this.mouseEvent=e,this.startMouseEvent=this.tableScope.createGeMouseEvent(this.mouseEvent),this.tableScope.onMouseDown(this.startMouseEvent),this.mouseDown=!0))}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}!this.mouseDown&&this.isBlocked(e)||(this.mouseEvent=e,this.mouseDown?(this.dragging||(this.dragging=!0,this.tableScope.setDragging(!0)),requestAnimationFrame(this.mouseDraggingOnFrame.bind(this))):requestAnimationFrame(this.mouseMoveOnFrame.bind(this)))}onMouseUp(e){var t,s;!this.mouseDown&&((s=(t=this.tableScope).isEventInDetail)!=null&&s.call(t,e))||(this.mouseEvent=e,this.repaintAfterMouseUp&&(this.repaintAfterMouseUp=!1,this.tableScope.debounceRepaint()),this.dragging&&requestAnimationFrame(this.mouseDraggingEndOnFrame.bind(this)),this.mouseDown=!1,this.dragging=!1,this.tableScope.setDragging(!1))}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)}}mouseDraggingEndOnFrame(){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.mouseDraggingEndOnFrame(t)}}mouseMoveOnFrame(){if(this.mouseEvent){const e=this.tableScope.createGeMouseEvent(this.mouseEvent);this.tableScope.mouseMove(e)}}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 Wr=()=>!1;function Ur(n){return n.editable===void 0||n.editable===Wr}function li(n){return typeof n=="number"&&!Number.isNaN(n)}function ma(n){if(li(n))return n;if(n instanceof Date){const e=n.getTime();return Number.isNaN(e)?void 0:e}}function ai(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 zr(n,e){ai(n,e.sum),n.compensation+=e.compensation}const ba={name:"sum",init:()=>({sum:0,compensation:0}),add:(n,e)=>(li(e)&&ai(n,e),n),merge:(n,e)=>(zr(n,e),n),result:n=>Kr(n)},wa={name:"count",init:()=>0,add:n=>n+1,merge:(n,e)=>n+e,result:n=>n},ya={name:"avg",init:()=>({sum:0,compensation:0,count:0}),add:(n,e)=>(li(e)&&(ai(n,e),n.count++),n),merge:(n,e)=>(zr(n,e),n.count+=e.count,n),result:n=>n.count?Kr(n)/n.count:void 0};function Vi(n,e){return{name:n,init:()=>({has:!1,value:void 0,key:0}),add:(t,s)=>{const o=ma(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 Ca={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},Sa={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},xa={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:ba,count:wa,avg:ya,min:Vi("min",(n,e)=>n<e),max:Vi("max",(n,e)=>n>e),countDistinct:Ca,first:Sa,last:xa});function Xs(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 ns(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 ls(n,e){const t=typeof e=="string"||!("aggregator"in e)?{aggregator:e}:e,s=Xs(t.aggregator),o=t.value??n;return{key:n,aggregator:s,value:o,getValue:s===Oe.count?void 0:ns(o),format:t.format}}function Ys(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 va(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 Ra(n,e,t){const s=ls("",{aggregator:t,value:e}),[o]=Ys(n,[s]);return s.aggregator.result(o)}function Aa(n,e){const t=Object.keys(e).map(i=>ls(i,e[i])),s=Ys(n,t),o={};return t.forEach((i,r)=>o[i.key]=i.aggregator.result(s[r])),o}const Ea=new Intl.NumberFormat("en-US",{maximumFractionDigits:2});function It(n){return n==null?"":typeof n=="number"?Number.isFinite(n)?Ea.format(n):String(n):n instanceof Date?Number.isNaN(n.getTime())?"":n.toLocaleDateString("en-US"):String(n)}const Ma=new Set(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal"]),_i=new Map,Ta=new Intl.NumberFormat("en-US",{maximumFractionDigits:0});function Dt(n){if(!n)return;const e=typeof n=="string"?{mode:n}:n;return jr.includes(e.mode)?e:void 0}const jr=Object.freeze(["percentOfColumnTotal","percentOfGrandTotal","percentOfParentTotal","percentOfRowTotal","differenceFromPrevious","runningTotal","rank"]);function ci(n){return!!n&&Ma.has(n)}function Js(n,e){const t=Dt(e);if(typeof n!="number"||Number.isNaN(n)||!t)return n==null?"":`${n}`;if(t.format)return`${t.format(n)??""}`;if(ci(t.mode)){const s=Bi(t.fractionDigits??1);let o=_i.get(s);return o||(o=new Intl.NumberFormat("en-US",{style:"percent",minimumFractionDigits:s,maximumFractionDigits:s}),_i.set(s,o)),o.format(n)}if(t.mode==="rank")return Ta.format(n);if(t.fractionDigits!==void 0){const s=Bi(t.fractionDigits);return new Intl.NumberFormat("en-US",{minimumFractionDigits:s,maximumFractionDigits:s}).format(n)}return It(n)}function Bi(n){return Math.min(10,Math.max(0,Math.trunc(Number(n)||0)))}function at(n){return typeof n=="number"&&!Number.isNaN(n)}function qs(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 hi(n,e){const t=n.length,s=new Array(t);switch(e){case"percentOfColumnTotal":case"percentOfGrandTotal":case"percentOfParentTotal":{const o=qs(n);for(let i=0;i<t;i++)s[i]=Ia(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]=at(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]=at(i)&&at(r)?i-r:void 0}return s;case"rank":{const o=[];for(let r=0;r<t;r++)at(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]=at(n[o])?n[o]:void 0;return s}}function Ia(n,e){return at(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 Da{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=Xs(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=Dt(i.showValuesAs);r&&s.set(i.property,r)}return this.getters=t,this.showValuesAs=s,this.properties=o,this.defsLength=e.length,t}}class kt{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 as{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){return this.defaultRowHeight>0?this.defaultRowHeight*e:this.yPositions[e]}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&&Ur(s)?!me(s)&&!O(s)&&!ot(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 Da({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 Js(t,o);if(i)return t==null?"":`${t}`}getCalculatedRenderer(e){if(e!==void 0&&this.getColumnValues().getShowValuesAs(e))return this.calcTextRenderer??(this.calcTextRenderer=new kt)}addCalculatedClasses(e,t,s){return t!==void 0&&this.getColumnValues().isCalculated(t)&&w(s())?[...e,"ge-table-cell-error"]:e}}class di{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 it(n,e){return ka(n,e)?n:Array.from(new Set(n)).filter(t=>Number.isInteger(t)&&t>=0&&t<e).sort((t,s)=>t-s)}function ka(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 ui(n){return n.position==="before"?n.rowIndex:n.rowIndex+1}function Io(n,e){if(!n.length)return-1;const t=ui(e);return t-n.filter(s=>s<t).length}function Xr(n,e,t){const s=it(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 fi(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 gi(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 Yr(n,e,t,s){const o=fi(e);if(!gi(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,Jr(a,i?i.deep+1:0);return!0}function Jr(n,e){n.deep=e;for(const t of n.children??[])Jr(t,e+1)}function Zs(n,e,t,s){return n===e&&s.position!=="inside"&&Number.isInteger(s.rowIndex)&&s.rowIndex>=0&&s.rowIndex<n&&it(t,n).length>0}function pi(n,e,t,s){if(!Zs(n.length,e.length,t,s))return!1;if(Xr(n,it(t,n.length),ui(s)),e!==n)for(let o=0;o<n.length;o++)e[o]=n[o];return!0}function La(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}class K extends as{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 di,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.showValuesCache.clear()}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 Zs(this.filteredRows.length,this.rows.length,e,t)}moveRows(e,t){const s=pi(this.filteredRows,this.rows,e,t);return s&&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=qs(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=hi(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===K.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.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(),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.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 Vs=class Vs{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)>Vs.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 S=o.getValueAt(y,C);typeof S=="number"&&!Number.isNaN(S)&&(s.numericCount++,u=c.add(u,S),f=h.add(f,S),g=d.add(g,S))}}),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||O(l)||me(l)||o.push(r)}return o}};Vs.maxCells=1e6;let Rs=Vs;function Fa(n){const e=Dt(n);if(!e||!ci(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 Pe(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 Le(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 mt(n,e,t={}){const s=Pe(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=Le(e[2]),s=Number(e[4])-1;if(!(t<0||s>=ie))return{row:s,col:t,absRow:e[3]==="$",absCol:e[1]==="$"}}function qr(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=Le(i[2]),h=Le(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 Oa=["<=",">=","<>","!=","==","+","-","*","/","^","&","=","<",">"],Pa=["<=",">=","<>","+","-","*","/","^","&","=","<",">",":","%"],Na=/^#(REF!|N\/A|DIV\/0!|VALUE!|NAME\?|NUM!|NULL!|CIRC!|ERROR!)/i,Va={n:`
|
|
42
42
|
`,t:" ",r:"\r","\\":"\\",'"':'"',"'":"'"};function he(n){return n>="0"&&n<="9"}function Jt(n){return n>="a"&&n<="z"||n>="A"&&n<="Z"||n==="_"}function Zr(n){return Jt(n)||he(n)||n==="."}function _a(n,e=!1){if(e)return Ba(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&&(Jt(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+=Va[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(Jt(i)){for(;o<s&&Zr(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=Oa.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 Ba(n){const e=[],t=n.length;let s=0;for(;s<t;){const o=n[s];if(o===" "||o===" "||o===`
|
|
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&&(Jt(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=Na.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(Jt(o)||o==="$"){for(;s<t&&(Zr(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=Pa.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 uo=1e4,$i=64,Hi=1e3,$a={"=":{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:"^"}},Ha=50,Ga=75,Wa=70,Ua=80;class Ka{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>$i)throw new B(`Nested too deeply (more than ${$i} levels)`,e)}expression(e){let t=this.prefix();for(;;){const s=this.peek();if(s.kind!=="op")break;if(this.references&&s.text==="%"){if(Wa<=e)break;this.next(),t={kind:"unary",op:"%",operand:t};continue}if(this.references&&s.text===":"){if(Ua<=e)break;this.next(),t=this.range(t,s.pos);continue}const o=$a[s.text];if(!o||o.bp<=e)break;if(this.next(),++this.operators>Hi)throw new B(`Too many operators (more than ${Hi})`,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?Ga:Ha);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 cs(n,e=!1){if(n.length>uo)throw new B(`Formula too long (more than ${uo} characters)`,uo);return new Ka(_a(n,e),e).parse()}const za=/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;function ut(n){return n===null||n===""}function As(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(za.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 Do(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 ja(n,e){if(w(n))return n;if(w(e))return e;if(ut(n)&&ut(e))return 0;const t=typeof n=="string"&&!ut(n),s=typeof e=="string"&&!ut(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 Qr={IF:{min:2,max:3},IFERROR:{min:2,max:2},AND:{min:1,max:255},OR:{min:1,max:255}},Xa={SUM:"sum",AVG:"avg",AVERAGE:"avg",MIN:"min",MAX:"max",COUNT:"count"};function us(n){const e=[];for(const t of n){if(ut(t))continue;const s=oe(t);if(w(s))return s;e.push(s)}return e}function fo(n){return{min:1,max:1,fn:e=>{const t=oe(e[0]);return w(t)?t:de(n(t))}}}function mi(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 qt={ABS:fo(Math.abs),FLOOR:fo(Math.floor),CEILING:fo(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(mi(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=us(n);return w(e)?e:de(e.reduce((t,s)=>t+s,0))}},AVG:{min:1,max:255,fn:n=>{const e=us(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=us(n);return w(e)?e:e.length?Math.min(...e):0}},MAX:{min:1,max:255,fn:n=>{const e=us(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=Do(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=>ut(n[0])}};qt.AVERAGE=qt.AVG;const Ya=new Set(["__proto__","constructor","prototype"]),Ja=(n,e)=>Object.prototype.hasOwnProperty.call(n,e);function qa(n,e,t,s=e.split(".")){if(t!=null&&t.isCalculated(e))return As(t.getValue(n,e),e,!0);if(s.some(i=>Ya.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(!Ja(o,s[i]))return i===0&&!(t!=null&&t.hasColumn(e))?new I("#NAME?",`Unknown field [${e}]`):null;o=o[s[i]]}return As(o,e)}function Gi(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=ja(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 Za(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?As(n,e):new I("#VALUE!",`${e} returned no number, text or boolean`)}function Wi(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 Qa{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)=>qa(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):Gi(o,l,a)}:(i,r)=>Gi(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=Wi(a,c,h);if(w(d))return d;try{return Za(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=Do(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=Do(u(h,d));if(w(f))return f;if(a&&!f)return!1;if(!a&&f)return!0}return a}}}const o=Xa[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:As(d,a,!0)}}const r=qt[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=Wi(l,a,c);return w(h)?h:r.fn(h)}}}const ec=Object.freeze([...Object.keys(qt),...Object.keys(Qr)].sort());function _t(n,e,t,s){switch(n.kind){case"literal":return;case"field":t.includes(n.name)||t.push(n.name);return;case"unary":return _t(n.operand,e,t,s);case"binary":return _t(n.left,e,t,s)??_t(n.right,e,t,s);case"call":{if(!e.has(n.name)){const o=qt[n.name]??Qr[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=_t(o,e,t,s);if(i)return i}return}default:return new I("#ERROR!","Cell references are not allowed in column formulas")}}function bi(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=cs(c.startsWith("=")&&!c.startsWith("==")?c.slice(1):t),i=_t(o,s,r,l),i||(a=new Qa(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 wi(n,e){const t=typeof n=="string"?bi(n,e):n;return(s,o)=>t.evaluate(s,o)}const tc={"=":10,"<>":10,"<":10,"<=":10,">":10,">=":10,"&":20,"+":30,"-":30,"*":40,"/":40,"^":60};function go(n){return n.row<0?`${n.absCol?"$":""}${Pe(n.col)}`:n.col<0?`${n.absRow?"$":""}${n.row+1}`:n.row>=ie||n.col>=q?"#REF!":`${n.absCol?"$":""}${Pe(n.col)}${n.absRow?"$":""}${n.row+1}`}function sc(n){return String(n)}function ct(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":sc(n.value);case"field":return`[${n.name}]`;case"ref":return go(n);case"range":return`${go(n.from)}:${go(n.to)}`;case"error":return n.text??n.code;case"call":return`${n.name}(${n.args.map(t=>ct(t,0)).join(",")})`;case"unary":{if(n.op==="%")return`${ct(n.operand,70)}%`;const t=ct(n.operand,75);return`${n.op}${t}`}case"binary":{const t=tc[n.op],s=`${ct(n.left,t)}${n.op}${ct(n.right,t+1)}`;return t<e?`(${s})`:s}}}function Gt(n){return ct(n,0)}const oc=new Set(["XLOOKUP","IFS","SWITCH","TEXTJOIN","CONCAT","IFNA","XOR"]);function ic(n,e){let t;try{t=cs(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:oc.has(l.name)?`_xlfn.${l.name}`:l.name,args:l.args.map(i)};default:return l}},r=i(t);return s?Gt(r):void 0}class Q extends as{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 Zs(this.filteredArr.length,this.arr.length,e,t)}moveRows(e,t){return pi(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 xt{constructor(e){this.serial=e,this.type="SheetDate"}toDate(){return yi(this.serial)}}function G(n){return!!n&&typeof n=="object"&&n.type==="SheetDate"&&typeof n.serial=="number"}const en=864e5,tn=Date.UTC(1899,11,30);function Ft(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())-tn)/en;return s<61&&(s-=1),s}function yi(n){const e=n<60?n+1:n>=60&&n<61?61+(n-60):n,t=new Date(tn+Math.round(e*en));return new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds())}function Wt(n,e,t){return Ft(new Date(n,e-1,t))}function et(n){if(Math.floor(n)===60)return{y:1900,m:2,d:29};const e=yi(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 Ui=/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i,rc=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function vt(n){const e=rc.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 Ft(t)}function sn(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=Ft(n);return Number.isNaN(e)?null:new xt(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 z(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(Ui.test(s)){const o=Number(s);if(Number.isFinite(o))return o}if(s.endsWith("%")&&Ui.test(s.slice(0,-1).trim()))return Number(s.slice(0,-1).trim())/100;if(e.isoDatesAsDates){const o=vt(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 Ki(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"?Ki(e):typeof e=="boolean"?e?"TRUE":"FALSE":G(e)?Ki(e.serial):e}function ft(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 hs(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 ko(n){return n===null||n===""}function ji(n){return G(n)?n.toDate():Ye(n)?_(n):n}class Ne extends as{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(!Pt(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&&!Pt(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(Pt(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=hs(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=>!Pt(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(!Pt(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 Pt(n){return n==null||n===""}class Es{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 on{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 Rt{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 nc{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 Rt){this.getTopTreeRows().forEach(o=>s.checkRow(o,t));return}this.checkAll(t?this.getBodyRows():[])}isRowChecked(e){const t=this.bodyAreaModel.rowSelectionModel;if(t instanceof Rt){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 Zt(n){return n!=null&&n.length&&O(n[0])?1:0}class T{constructor(e=100,t="px"){this.value=e,this.unit=t}}const Lt=()=>!0,rn=()=>!1,At=new WeakSet,Ms=new WeakMap;function nn(n,e){e?At.delete(n):At.add(n),ln(n)}function po(n,e){e?Ms.set(n,e):Ms.delete(n),ln(n)}function Fo(n){var e;return Ms.has(n)?!At.has(n):!At.has(n)&&((e=n.isVisible)==null?void 0:e.call(n))!==!1}function ln(n){const e=Ms.get(n),t=!At.has(n);e?n.isVisible=()=>!At.has(n)&&e():n.isVisible=t?Lt:rn}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 Es(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[Zt(this.columnDefs)];me(g)&&!t.rowSelectionModel&&(t.rowSelectionModel=new on),me(g)&&!e.rowSelectionModel&&(e.rowSelectionModel=new nc(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 Es(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){const t=this.getModel(e),s=t.getRowCount();if(this.defaultRowHeights[e])return s*this.defaultRowHeights[e];let o=0;for(let i=0;i<s;i++)o=o+t.getRowHeight(i);return o}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;nn(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){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 Ke=_s;class ee{constructor(e,t,s){this.header=e,this.body=t,this.footer=s}}class be{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??Wr,r=e.isVisible??e.isVisible??Lt,l=new be(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=wi(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),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 an{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 Lo{constructor(){this.mode="display",this.format=lc,this.headerLabel="#",this.exported=!1,this.minWidthInPx=36}}function lc(n){return String(n)}class ds{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=Lt,this.options={...new Lo,...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 an(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 Lo().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 cn{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 Qs{constructor(e=new Ee("❯","",["gt-table-icon-expanded"]),t=new Ee("❯","transform: rotate(180deg) translate(-100%, -100%); transform-origin: 0 0;",["ge-table-icon-collapsed"])){this.iconExpanded=e,this.iconCollapsed=t}}const Ci=(n,e)=>new cn;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 ri,this.headerGroupOptions=new Qs,this.showCheckboxWihoutExtraColumn=!1,this.externalFilterFunction=void 0,this.sortedOptions=new ni,this.sortOrder=["asc","desc"],this.shortcutActionsDisabled=!1,this.resizeEventDebounceDelay=500,this.getEditRenderer=Ci,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.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 Me{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()}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=>Me.intersects(c,i));for(let c=r;c<=l;c++)!o.has(c)&&(!a.length||!Me.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=>Me.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 Si{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())}hasFocus(e,t){return this.rowIndex===e&&this.columnIndex===t}getFocus(){return[this.rowIndex,this.columnIndex]}}function ac(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 mo;function hn(n){var e;if(!mo){let t=[];try{t=((e=Intl.supportedValuesOf)==null?void 0:e.call(Intl,"currency"))??[]}catch{t=[]}mo=new Set(t.length?t:["EUR","USD","GBP","CHF","JPY","CNY","CAD","AUD","SEK","NOK","DKK","PLN","CZK"])}return mo.has(n)}function Xi(n){return n.replace(new RegExp("^\\p{Sc}\\s*","u"),"").replace(/^([A-Z]{3})\s+/u,(e,t)=>hn(t)?"":e)}function dn(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=Xi(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)=>hn(h)?"":c),(t.startsWith("-")||t.startsWith("+"))&&(s=s!==t.startsWith("-"),t=Xi(t.slice(1).trim()));const{decimal:i,group:r}=ac(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 hc(n){return e=>typeof e!="string"?e:e.trim()===""?"":dn(e,n)??e}function dc(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 un(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 Yi(+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=dc(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),Yi(a,l.month,l.day,+(o[5]??0),+(o[6]??0),+(o[7]??0))}function Yi(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 uc(n){return e=>typeof e!="string"?e:e.trim()===""?"":un(e,n)??e}const fc=["true","yes","1","x","wahr","ja"],gc=["false","no","0","falsch","nein"],pc=n=>{if(typeof n!="string")return n;const e=n.trim().toLowerCase();return e===""?"":fc.includes(e)?!0:gc.includes(e)?!1:n};function xi(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=dn(t,n);return o!==void 0?o:un(t,n)??e}}class vi 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 Ri extends Ke{constructor(e,t,s,o,i,r,l=xi()){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=fn(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 fn(n,e,t,s=[],o){const i=Array.from({length:n},(r,l)=>be.create({editInputPipe:o,property:Pe(l),headerLabel:Pe(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 ds({mode:"original"}),a=xi(e.locale),c=fn(o,r,l,[],a),h=new vi("header",[c.map(m=>m.headerLabel)],i,c),d=new Ne("body",t,s,o,i,c,l?1:0),u=new Ri(h,d,l,c,i,r,a),f=new Me("range","multi"),g=new Si("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 eo(n){return n instanceof Ri}class Oo{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 Oo(o.rowIndex,o.columnIndex));return new Xe(s,e,t)}static createSingle(e,t){return new Xe([new Oo(e,t)])}}class pe{static create(e){const t=new pe;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 bc={insertRows:"Insert rows",deleteRows:"Delete rows",insertColumns:"Insert columns",deleteColumns:"Delete columns"};function gt(n,e,t={}){var m,b,y,C,S;const s=n.tableModel,o=s.getBodyModel(),i=e.kind==="insertColumns"||e.kind==="deleteColumns",r=o instanceof Ne?o:void 0,l=o instanceof K||o instanceof Q;if(!(e.count>=1)||!(e.at>=0)||(i?!r||!eo(s):!r&&!l)||n.isBatchEditActive())return!1;const a=i?r.getSheetColumnCount():r?r.getUnfilteredRowCount():Ai(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=wc(n,d,t.rows),p=[];if(u){const E=u.rowsArray();for(const{row:x,col:R,input:L}of f){const v=E?E[x]:r==null?void 0:r.getRowArray(x),D=u.inputAt(x,R);if(v&&typeof v=="object"){const N=d.kind==="insertColumns"?R>=d.at+h?R-h:R:d.kind==="deleteColumns"&&R>=d.at?R+h:R;g.inputs.push({row:v,col:N,old:D})}u.writeInput(x,R,L);const k=u.modelColumn(R);p.push({row:v,rowIndex:u.displayRow(x),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 Sc(d,g))),n.announce(Cc(n,d)),(S=(C=n.getEventListener()).onModelChanged)==null||S.call(C,Xe.createForChanges(p,t.source??"structure")),!0}function wc(n,e,t){const s=n.tableModel,o=s.getBodyModel(),{at:i,count:r}=e,l={inputs:[]};if(o instanceof Ne){if(e.kind==="insertRows")o.insertRows(i,r);else if(e.kind==="deleteRows")l.sheetRows=o.deleteRows(i,r);else if(eo(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=Ai(o);if(e.kind==="insertRows"){const c=t??Array.from({length:r},(h,d)=>yc(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 gn(o,a),l}function Ai(n){return n instanceof K?n.getAllRows():n.arr}function gn(n,e){n instanceof K?n.setRows(e):n instanceof Q&&(n.filteredArr=[...e])}function yc(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 Cc(n,e){const t=n.ariaTexts,s=new pe;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 Sc{constructor(e,t){var s,o;this.edit=e,this.delta=t,this.source="structure",this.label=bc[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 Ne)r==="insertRows"?s.deleteRows(o,i):r==="deleteRows"?s.restoreRows(o,i,l.sheetRows):eo(t)&&(r==="insertColumns"?s.deleteColumns(o,i):s.restoreColumns(o,i,l.sheetColumns),t.setDataColumns(s.getSheetColumnCount(),l.widths));else{const f=Ai(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]);gn(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 gt(e,this.edit,{record:!1,rows:this.edit.kind==="insertRows"?this.delta.rows:void 0,source:"redo"}),{applied:this.edit.count,skipped:0}}}class pn{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(){this.tableScope.invalidateAggregates(),this.tableScope.repaintHard()}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&&(O(p)&&!p.options.exported||r.push(g))}const l=i.getBodyModel(),a=l instanceof Ne?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"&&Ji(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++)Ji(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=ic(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(O(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=zs(r)?r.pivot.value.showValuesAs:t==="body"?r==null?void 0:r.showValuesAs:void 0,c=La(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 Rs().aggregate(this.tableScope.tableModel,this.getSelectionModel())}autoResizeColumns(e=!0){this.tableScope.autoResizeColumns(e)}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 K?(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)}addRows(e){const t=this.getBodyModel();if(t instanceof K){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 K){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 K){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 K?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 K)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 K)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 K){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 Cs(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&&!Dt(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=bi(t,s),r=wi(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 gt(this.tableScope,{kind:"insertRows",at:e,count:t})}deleteRows(e,t=1){return gt(this.tableScope,{kind:"deleteRows",at:e,count:t})}insertColumns(e,t=1){return gt(this.tableScope,{kind:"insertColumns",at:e,count:t})}deleteColumns(e,t=1){return gt(this.tableScope,{kind:"deleteColumns",at:e,count:t})}getSheetData(){const e=this.tableScope.tableModel.getBodyModel();return e instanceof Ne?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 Ji(n,e){var t;return!!((t=n==null?void 0:n.isColumnLetterRow)!=null&&t.call(n,e))}class Ae{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 Xt=class Xt{constructor(e){this.prefix=e}static createPrefix(e){const t=(e??"").trim();return t?`ge-${t.replace(/\s+/g,"_")}`:(Xt.counter++,`ge-t${Xt.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`}};Xt.counter=0;let Qt=Xt;class to{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 to;if(e)for(const s of Object.keys(e))e[s]!==void 0&&(t[s]=e[s]);return t}}function Po(n){return n.manual?n.manual:!n.autoNoRows||n.rowCount!==0?"none":(n.unfilteredRowCount??0)>0?"noMatches":"noRows"}const qi={none:"",loading:"ge-table-overlay-loading",noRows:"ge-table-overlay-no-rows",noMatches:"ge-table-overlay-no-matches"};class mn{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=to.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?Po({rowCount:e,unfilteredRowCount:t,autoNoRows:s}):Po({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(qi[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 ${qi[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)}}const Bs=class Bs{constructor(e,t,s,o){this.hostElement=e,this.tableModel=t,this.dom=s,this.tableOptions=o,this.scrollTop=0,this.areaBodyWestGeo=new Ae,this.areaBodyCenterGeo=new Ae,this.areaBodyEastGeo=new Ae,this.hostAttributesBefore=new Map;const i=this.hostElement;i.innerText="",this.direction=Nr(o==null?void 0:o.direction,i),this.dom.setDirection(this.direction),this.dom.setAttribute(i,"tabindex","0"),this.ariaIds=new Qt(Qt.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))),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 mn(i,s,o==null?void 0:o.overlayOptions,()=>this.updateOverlay())}isRtl(){return this.direction==="rtl"}getViewportScrollLeft(){return Vr(this.scrollViewport,this.isRtl())}setViewportScrollLeft(e){_r(this.scrollViewport,e,this.isRtl())}clientXToHostX(e){const t=this.hostElement,s=t.getBoundingClientRect();return $r(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(){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.scrollTop=this.scrollViewport.scrollTop,this.dom.applyStyle(this.contentDiv,{width:`${this.scrollViewport.clientWidth}px`,height:`${this.scrollViewport.clientHeight}px`,top:`${this.scrollTop}px`,left:`${this.getViewportScrollLeft()}px`}),this.areaBodyWestGeo.width=e.left,this.areaBodyWestGeo.height=s-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=s-e.top-e.bottom,this.areaBodyEastGeo.top=e.top,this.areaBodyEastGeo.left=t-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=t-e.left-e.right,this.areaBodyCenterGeo.height=s-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:`${t-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:`${t-e.right}px`}),this.borderHeaderBottom&&this.tableModel.isHeaderVisibe()?this.dom.applyDisplayBlockStyle(this.dom.applyStyle(this.borderHeaderBottom,{width:`${t}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:`${s-e.bottom}px`,left:"0"}),this.dom.applyStyle(this.areaFooterCenter.parent,{width:`${t-e.left-e.right}px`,height:`${e.bottom}px`,top:`${s-e.bottom}px`,left:`${e.left}px`}),this.dom.applyStyle(this.areaFooterEast.parent,{width:`${e.right}px`,height:`${e.bottom}px`,top:`${s-e.bottom}px`,left:`${t-e.right}px`}),this.borderFooterTop&&this.tableModel.isFooterVisibe()?this.dom.applyDisplayBlockStyle(this.dom.applyStyle(this.borderFooterTop,{width:`${t}px`,height:"1px",top:`${s-e.bottom}px`,left:"0px"})):this.borderFooterTop&&this.dom.applyDisplayNoneStyle(this.borderFooterTop),this.tableOverlay.setBounds(0,e.top,Math.min(t,e.left+this.scrollViewport.clientWidth),s-e.top-e.bottom),this.adjustDetailLayerBounds(0,e.top,Math.min(t,e.left+this.scrollViewport.clientWidth),Math.max(0,Math.min(s-e.top-e.bottom,this.scrollViewport.clientHeight))),this.adjustAfterScrolling()}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,Bs.maxScrollHeightInPx)}px`;this.dom.setStyle(this.contentWrapperDiv,"width",e),this.dom.setStyle(this.contentWrapperDiv,"height",s)}};Bs.maxScrollHeightInPx=8e6;let es=Bs;class bn{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(),t=this.tableModel.getColumnCount();for(let s=0;s<e;s++)for(let o=0;o<t;o++){let i=this.areaModel.getColspanAt(s,o),r=this.areaModel.getRowspanAt(s,o);if(i>1||r>1){i===0&&(i=1),r===0&&(r=1);const l="gammaCells"in this.areaModel;this.colAndRowspanRanges.push(new M(s,o,s+r-1,o+i-1,l))}}}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 ts{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 ts(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 wn{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 yn{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 Cn extends es{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.removables=[],this.treeAriaInfo=new wn,this.ariaSelectionKind="none",this.renderedSpanCells=new Set,this.bodyRowLayout=new yn,this.bodyRowLayoutDirty=!0,this.adjustingRowNumberWidth=!1,this.rowNumberRemeasureScheduled=!1,this.ariaTexts=pe.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 Me("range","multi"):new Me;this.getSelectionModel=()=>d}if((h=this.tableOptions)!=null&&h.getFocusModel)this.getFocusModel=this.tableOptions.getFocusModel;else{const d=new Si("cell");this.getFocusModel=()=>d}Z(t.getAreaModel("body"))&&(this.tree=!0),["header","body","footer"].forEach(d=>{var u;this.colAndRowspanModels[d]=new bn(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.hostElement.clientWidth,l=this.hostElement.clientHeight,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.hostElement.clientWidth,c=this.hostElement.clientHeight-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.hasBodyRowExtras()?this.getBodyRowLayout().getTop(e):this.tableModel.getBodyModel().getYPosByRowIndex(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}}}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(){var e;for(const t of["header","body","footer"])(e=this.colAndRowspanModels[t])==null||e.initIfRowCountChanged();this.tableModel.recalcHeightAndPadding(),this.invalidateRowLayout(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows(),this.adjustAfterScrolling()}recalcColumnWidths(e){const t=this.getAvailableColumnWidth(e);t>0&&this.tableModel.setParentWidth(t),this.tableModel.init(),this.repaintHard()}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.tableModel.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=ts.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 Ae(0,e,1,0),this.hostElement,"ge-table-border")),this.tableOptions.tableBottomBorderVisible&&this.removables.push(this.dom.addHorizontalBorder(new Ae(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 Ae(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 Ae(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.afterRenderPass()}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>es.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.dom.setStyle(this.contentDiv,"top",`${this.scrollTop}px`);const s=this.areaHeightsOfRenderPass?this.scrollLeft:this.getViewportScrollLeft();this.dom.setStyle(this.contentDiv,"left",`${s}px`),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 S,E,x,R,L;const s=this.getArea(e,"west"),o=this.getArea(e,"center"),i=this.getArea(e,"east"),r=((S=this.areaHeightsOfRenderPass)==null?void 0:S[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 v=this.cleanupFunctions[e].shift();v&&v()}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 v=(x=h.getConstantRowHeight)==null?void 0:x.call(h);if(v!==void 0&&v>0&&u<0){for(m=Math.min(d,Math.floor(-u/v));m>0&&u+m*v>0;)m--;u=u+m*v}}for(let v=m;v<d;v++){const D=u,k=v===d-1,N=this.tableModel.getRowHeight(e,v),V=y?b.getExtraHeight(v):0;if(V>0&&D+N+V>0&&C.push(v,D+N,V),D+N>0){e==="body"&&this.firstVisibleRowIndex===-1&&(this.firstVisibleRowIndex=v,this.firstFullVisibleRowIndex=D<-this.pixelLimitForFullVisible?this.firstVisibleRowIndex+1:this.firstVisibleRowIndex);let $={left:l,width:a,height:N,top:D,index:v},j=this.dom.addRowDiv(o,$,v,e,"center");this.applyRowAria(j,e,h,v);const _e=[j],H=p;this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"center",areaModel:h,geo:$,parent:j,rowIndex:v,columnIndexStart:H,columnIndexEnd:f-g-1,verticalFixed:!1,lastRowOfModel:k}),c.left>0&&($={left:l,width:this.areaBodyWestGeo.width,height:N,top:D,index:v},j=this.dom.addRowDiv(s,$,v,e,"west"),this.applyRowAria(j,e,h,v),_e.push(j),this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"west",areaModel:h,geo:$,parent:j,rowIndex:v,columnIndexStart:0,columnIndexEnd:H-1,verticalFixed:!0,lastRowOfModel:k})),c.right>0&&($={left:l,width:this.areaBodyEastGeo.width,height:N,top:D,index:v},j=this.dom.addRowDiv(i,$,v,e,"east"),this.applyRowAria(j,e,h,v),this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"east",areaModel:h,geo:$,parent:j,rowIndex:v,columnIndexStart:f-g,columnIndexEnd:f-1,verticalFixed:!0,lastRowOfModel:k}));const P=e==="header"&&this.tree&&v===d-1?this.findCellDiv(_e,this.getTreeArrowColumnIndex()):void 0;if(P!=null&&P.parentElement){const ue=this.dom.getInlineStart(P)+16,te=this.dom.applyStyle(this.dom.setAttribute(this.dom.addDiv(P.parentElement,new Ae(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+N+V,u>r){if(e==="body"){const $=u-V;$<=0&&this.firstVisibleRowIndex===-1?this.displayedRowCount=0:(this.lastVisibleRowIndex=v,this.lastFullVisibleRowIndex=r-$<-this.pixelLimitForFullVisible?v-1:v,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+`
|
|
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&&(Jt(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=Na.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(Jt(o)||o==="$"){for(;s<t&&(Zr(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=Pa.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 uo=1e4,$i=64,Hi=1e3,$a={"=":{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:"^"}},Ha=50,Ga=75,Wa=70,Ua=80;class Ka{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>$i)throw new B(`Nested too deeply (more than ${$i} levels)`,e)}expression(e){let t=this.prefix();for(;;){const s=this.peek();if(s.kind!=="op")break;if(this.references&&s.text==="%"){if(Wa<=e)break;this.next(),t={kind:"unary",op:"%",operand:t};continue}if(this.references&&s.text===":"){if(Ua<=e)break;this.next(),t=this.range(t,s.pos);continue}const o=$a[s.text];if(!o||o.bp<=e)break;if(this.next(),++this.operators>Hi)throw new B(`Too many operators (more than ${Hi})`,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?Ga:Ha);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&&Le(i[2])>=0)return{kind:"ref",row:-1,col:Le(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&&Le(s[2])>=0)return{kind:"ref",row:-1,col:Le(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 cs(n,e=!1){if(n.length>uo)throw new B(`Formula too long (more than ${uo} characters)`,uo);return new Ka(_a(n,e),e).parse()}const za=/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;function ut(n){return n===null||n===""}function As(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(za.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 Do(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 ja(n,e){if(w(n))return n;if(w(e))return e;if(ut(n)&&ut(e))return 0;const t=typeof n=="string"&&!ut(n),s=typeof e=="string"&&!ut(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 Qr={IF:{min:2,max:3},IFERROR:{min:2,max:2},AND:{min:1,max:255},OR:{min:1,max:255}},Xa={SUM:"sum",AVG:"avg",AVERAGE:"avg",MIN:"min",MAX:"max",COUNT:"count"};function us(n){const e=[];for(const t of n){if(ut(t))continue;const s=oe(t);if(w(s))return s;e.push(s)}return e}function fo(n){return{min:1,max:1,fn:e=>{const t=oe(e[0]);return w(t)?t:de(n(t))}}}function mi(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 qt={ABS:fo(Math.abs),FLOOR:fo(Math.floor),CEILING:fo(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(mi(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=us(n);return w(e)?e:de(e.reduce((t,s)=>t+s,0))}},AVG:{min:1,max:255,fn:n=>{const e=us(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=us(n);return w(e)?e:e.length?Math.min(...e):0}},MAX:{min:1,max:255,fn:n=>{const e=us(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=Do(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=>ut(n[0])}};qt.AVERAGE=qt.AVG;const Ya=new Set(["__proto__","constructor","prototype"]),Ja=(n,e)=>Object.prototype.hasOwnProperty.call(n,e);function qa(n,e,t,s=e.split(".")){if(t!=null&&t.isCalculated(e))return As(t.getValue(n,e),e,!0);if(s.some(i=>Ya.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(!Ja(o,s[i]))return i===0&&!(t!=null&&t.hasColumn(e))?new I("#NAME?",`Unknown field [${e}]`):null;o=o[s[i]]}return As(o,e)}function Gi(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=ja(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 Za(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?As(n,e):new I("#VALUE!",`${e} returned no number, text or boolean`)}function Wi(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 Qa{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)=>qa(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):Gi(o,l,a)}:(i,r)=>Gi(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=Wi(a,c,h);if(w(d))return d;try{return Za(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=Do(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=Do(u(h,d));if(w(f))return f;if(a&&!f)return!1;if(!a&&f)return!0}return a}}}const o=Xa[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:As(d,a,!0)}}const r=qt[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=Wi(l,a,c);return w(h)?h:r.fn(h)}}}const ec=Object.freeze([...Object.keys(qt),...Object.keys(Qr)].sort());function _t(n,e,t,s){switch(n.kind){case"literal":return;case"field":t.includes(n.name)||t.push(n.name);return;case"unary":return _t(n.operand,e,t,s);case"binary":return _t(n.left,e,t,s)??_t(n.right,e,t,s);case"call":{if(!e.has(n.name)){const o=qt[n.name]??Qr[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=_t(o,e,t,s);if(i)return i}return}default:return new I("#ERROR!","Cell references are not allowed in column formulas")}}function bi(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=cs(c.startsWith("=")&&!c.startsWith("==")?c.slice(1):t),i=_t(o,s,r,l),i||(a=new Qa(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 wi(n,e){const t=typeof n=="string"?bi(n,e):n;return(s,o)=>t.evaluate(s,o)}const tc={"=":10,"<>":10,"<":10,"<=":10,">":10,">=":10,"&":20,"+":30,"-":30,"*":40,"/":40,"^":60};function go(n){return n.row<0?`${n.absCol?"$":""}${Pe(n.col)}`:n.col<0?`${n.absRow?"$":""}${n.row+1}`:n.row>=ie||n.col>=q?"#REF!":`${n.absCol?"$":""}${Pe(n.col)}${n.absRow?"$":""}${n.row+1}`}function sc(n){return String(n)}function ct(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":sc(n.value);case"field":return`[${n.name}]`;case"ref":return go(n);case"range":return`${go(n.from)}:${go(n.to)}`;case"error":return n.text??n.code;case"call":return`${n.name}(${n.args.map(t=>ct(t,0)).join(",")})`;case"unary":{if(n.op==="%")return`${ct(n.operand,70)}%`;const t=ct(n.operand,75);return`${n.op}${t}`}case"binary":{const t=tc[n.op],s=`${ct(n.left,t)}${n.op}${ct(n.right,t+1)}`;return t<e?`(${s})`:s}}}function Gt(n){return ct(n,0)}const oc=new Set(["XLOOKUP","IFS","SWITCH","TEXTJOIN","CONCAT","IFNA","XOR"]);function ic(n,e){let t;try{t=cs(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:oc.has(l.name)?`_xlfn.${l.name}`:l.name,args:l.args.map(i)};default:return l}},r=i(t);return s?Gt(r):void 0}class Q extends as{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 Zs(this.filteredArr.length,this.arr.length,e,t)}moveRows(e,t){return pi(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 xt{constructor(e){this.serial=e,this.type="SheetDate"}toDate(){return yi(this.serial)}}function G(n){return!!n&&typeof n=="object"&&n.type==="SheetDate"&&typeof n.serial=="number"}const en=864e5,tn=Date.UTC(1899,11,30);function Lt(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())-tn)/en;return s<61&&(s-=1),s}function yi(n){const e=n<60?n+1:n>=60&&n<61?61+(n-60):n,t=new Date(tn+Math.round(e*en));return new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds())}function Wt(n,e,t){return Lt(new Date(n,e-1,t))}function et(n){if(Math.floor(n)===60)return{y:1900,m:2,d:29};const e=yi(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 Ui=/^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i,rc=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;function vt(n){const e=rc.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 Lt(t)}function sn(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=Lt(n);return Number.isNaN(e)?null:new xt(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 z(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(Ui.test(s)){const o=Number(s);if(Number.isFinite(o))return o}if(s.endsWith("%")&&Ui.test(s.slice(0,-1).trim()))return Number(s.slice(0,-1).trim())/100;if(e.isoDatesAsDates){const o=vt(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 Ki(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"?Ki(e):typeof e=="boolean"?e?"TRUE":"FALSE":G(e)?Ki(e.serial):e}function ft(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 hs(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 ko(n){return n===null||n===""}function ji(n){return G(n)?n.toDate():Ye(n)?_(n):n}class Ne extends as{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(!Pt(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&&!Pt(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(Pt(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=hs(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=>!Pt(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(!Pt(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 Pt(n){return n==null||n===""}class Es{constructor(e=0,t=0,s=0,o=0){this.top=e,this.right=t,this.bottom=s,this.left=o}}class Fe{constructor(e=34,t=34,s=34){this.header=e,this.body=t,this.footer=s}}class on{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 Rt{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 nc{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 Rt){this.getTopTreeRows().forEach(o=>s.checkRow(o,t));return}this.checkAll(t?this.getBodyRows():[])}isRowChecked(e){const t=this.bodyAreaModel.rowSelectionModel;if(t instanceof Rt){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 Zt(n){return n!=null&&n.length&&O(n[0])?1:0}class T{constructor(e=100,t="px"){this.value=e,this.unit=t}}const Ft=()=>!0,rn=()=>!1,At=new WeakSet,Ms=new WeakMap;function nn(n,e){e?At.delete(n):At.add(n),ln(n)}function po(n,e){e?Ms.set(n,e):Ms.delete(n),ln(n)}function Lo(n){var e;return Ms.has(n)?!At.has(n):!At.has(n)&&((e=n.isVisible)==null?void 0:e.call(n))!==!1}function ln(n){const e=Ms.get(n),t=!At.has(n);e?n.isVisible=()=>!At.has(n)&&e():n.isVisible=t?Ft:rn}const _s=class _s{constructor(e,t,s,o=0,i=0,r=!1,l=new Fe,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 Es(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[Zt(this.columnDefs)];me(g)&&!t.rowSelectionModel&&(t.rowSelectionModel=new on),me(g)&&!e.rowSelectionModel&&(e.rowSelectionModel=new nc(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 Es(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){const t=this.getModel(e),s=t.getRowCount();if(this.defaultRowHeights[e])return s*this.defaultRowHeights[e];let o=0;for(let i=0;i<s;i++)o=o+t.getRowHeight(i);return o}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;nn(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){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 Ke=_s;class ee{constructor(e,t,s){this.header=e,this.body=t,this.footer=s}}class be{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??Wr,r=e.isVisible??e.isVisible??Ft,l=new be(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=wi(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),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 an{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 Fo{constructor(){this.mode="display",this.format=lc,this.headerLabel="#",this.exported=!1,this.minWidthInPx=36}}function lc(n){return String(n)}class ds{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=Ft,this.options={...new Fo,...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 an(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 Fo().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 cn{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 Qs{constructor(e=new Ee("❯","",["gt-table-icon-expanded"]),t=new Ee("❯","transform: rotate(180deg) translate(-100%, -100%); transform-origin: 0 0;",["ge-table-icon-collapsed"])){this.iconExpanded=e,this.iconCollapsed=t}}const Ci=(n,e)=>new cn;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 ri,this.headerGroupOptions=new Qs,this.showCheckboxWihoutExtraColumn=!1,this.externalFilterFunction=void 0,this.sortedOptions=new ni,this.sortOrder=["asc","desc"],this.shortcutActionsDisabled=!1,this.resizeEventDebounceDelay=500,this.getEditRenderer=Ci,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.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 Me{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()}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=>Me.intersects(c,i));for(let c=r;c<=l;c++)!o.has(c)&&(!a.length||!Me.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=>Me.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 Si{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())}hasFocus(e,t){return this.rowIndex===e&&this.columnIndex===t}getFocus(){return[this.rowIndex,this.columnIndex]}}function ac(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 mo;function hn(n){var e;if(!mo){let t=[];try{t=((e=Intl.supportedValuesOf)==null?void 0:e.call(Intl,"currency"))??[]}catch{t=[]}mo=new Set(t.length?t:["EUR","USD","GBP","CHF","JPY","CNY","CAD","AUD","SEK","NOK","DKK","PLN","CZK"])}return mo.has(n)}function Xi(n){return n.replace(new RegExp("^\\p{Sc}\\s*","u"),"").replace(/^([A-Z]{3})\s+/u,(e,t)=>hn(t)?"":e)}function dn(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=Xi(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)=>hn(h)?"":c),(t.startsWith("-")||t.startsWith("+"))&&(s=s!==t.startsWith("-"),t=Xi(t.slice(1).trim()));const{decimal:i,group:r}=ac(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 hc(n){return e=>typeof e!="string"?e:e.trim()===""?"":dn(e,n)??e}function dc(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 un(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 Yi(+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=dc(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),Yi(a,l.month,l.day,+(o[5]??0),+(o[6]??0),+(o[7]??0))}function Yi(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 uc(n){return e=>typeof e!="string"?e:e.trim()===""?"":un(e,n)??e}const fc=["true","yes","1","x","wahr","ja"],gc=["false","no","0","falsch","nein"],pc=n=>{if(typeof n!="string")return n;const e=n.trim().toLowerCase();return e===""?"":fc.includes(e)?!0:gc.includes(e)?!1:n};function xi(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=dn(t,n);return o!==void 0?o:un(t,n)??e}}class vi 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 Ri extends Ke{constructor(e,t,s,o,i,r,l=xi()){super(e,t,new ae("footer"),s?1:0,0,!1,new Fe(i,i,i),o),this.sheetBody=t,this.rowNumberColumn=s,this.columnWidth=r,this.inputPipe=l}setDataColumns(e,t=[]){const s=fn(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 fn(n,e,t,s=[],o){const i=Array.from({length:n},(r,l)=>be.create({editInputPipe:o,property:Pe(l),headerLabel:Pe(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 ds({mode:"original"}),a=xi(e.locale),c=fn(o,r,l,[],a),h=new vi("header",[c.map(m=>m.headerLabel)],i,c),d=new Ne("body",t,s,o,i,c,l?1:0),u=new Ri(h,d,l,c,i,r,a),f=new Me("range","multi"),g=new Si("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 eo(n){return n instanceof Ri}class Oo{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 Oo(o.rowIndex,o.columnIndex));return new Xe(s,e,t)}static createSingle(e,t){return new Xe([new Oo(e,t)])}}class pe{static create(e){const t=new pe;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 bc={insertRows:"Insert rows",deleteRows:"Delete rows",insertColumns:"Insert columns",deleteColumns:"Delete columns"};function gt(n,e,t={}){var m,b,y,C,S;const s=n.tableModel,o=s.getBodyModel(),i=e.kind==="insertColumns"||e.kind==="deleteColumns",r=o instanceof Ne?o:void 0,l=o instanceof K||o instanceof Q;if(!(e.count>=1)||!(e.at>=0)||(i?!r||!eo(s):!r&&!l)||n.isBatchEditActive())return!1;const a=i?r.getSheetColumnCount():r?r.getUnfilteredRowCount():Ai(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=wc(n,d,t.rows),p=[];if(u){const E=u.rowsArray();for(const{row:x,col:R,input:F}of f){const v=E?E[x]:r==null?void 0:r.getRowArray(x),D=u.inputAt(x,R);if(v&&typeof v=="object"){const N=d.kind==="insertColumns"?R>=d.at+h?R-h:R:d.kind==="deleteColumns"&&R>=d.at?R+h:R;g.inputs.push({row:v,col:N,old:D})}u.writeInput(x,R,F);const k=u.modelColumn(R);p.push({row:v,rowIndex:u.displayRow(x),columnIndex:k,property:((b=s.getColumnDef(k))==null?void 0:b.property)??"",oldValue:D,newValue:F})}u.recalculate()}return n.refreshAfterStructureChange(i),t.record!==!1&&((y=n.undoService)==null||y.addStep(new Sc(d,g))),n.announce(Cc(n,d)),(S=(C=n.getEventListener()).onModelChanged)==null||S.call(C,Xe.createForChanges(p,t.source??"structure")),!0}function wc(n,e,t){const s=n.tableModel,o=s.getBodyModel(),{at:i,count:r}=e,l={inputs:[]};if(o instanceof Ne){if(e.kind==="insertRows")o.insertRows(i,r);else if(e.kind==="deleteRows")l.sheetRows=o.deleteRows(i,r);else if(eo(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=Ai(o);if(e.kind==="insertRows"){const c=t??Array.from({length:r},(h,d)=>yc(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 gn(o,a),l}function Ai(n){return n instanceof K?n.getAllRows():n.arr}function gn(n,e){n instanceof K?n.setRows(e):n instanceof Q&&(n.filteredArr=[...e])}function yc(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 Cc(n,e){const t=n.ariaTexts,s=new pe;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 Sc{constructor(e,t){var s,o;this.edit=e,this.delta=t,this.source="structure",this.label=bc[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 Ne)r==="insertRows"?s.deleteRows(o,i):r==="deleteRows"?s.restoreRows(o,i,l.sheetRows):eo(t)&&(r==="insertColumns"?s.deleteColumns(o,i):s.restoreColumns(o,i,l.sheetColumns),t.setDataColumns(s.getSheetColumnCount(),l.widths));else{const f=Ai(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]);gn(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 gt(e,this.edit,{record:!1,rows:this.edit.kind==="insertRows"?this.delta.rows:void 0,source:"redo"}),{applied:this.edit.count,skipped:0}}}class pn{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(){this.tableScope.invalidateAggregates(),this.tableScope.repaintHard()}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&&(O(p)&&!p.options.exported||r.push(g))}const l=i.getBodyModel(),a=l instanceof Ne?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"&&Ji(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++)Ji(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=ic(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(O(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=zs(r)?r.pivot.value.showValuesAs:t==="body"?r==null?void 0:r.showValuesAs:void 0,c=Fa(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 Rs().aggregate(this.tableScope.tableModel,this.getSelectionModel())}autoResizeColumns(e=!0){this.tableScope.autoResizeColumns(e)}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 K?(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)}addRows(e){const t=this.getBodyModel();if(t instanceof K){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 K){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 K){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 K?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 K)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 K)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 K){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 Cs(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&&!Dt(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=bi(t,s),r=wi(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 gt(this.tableScope,{kind:"insertRows",at:e,count:t})}deleteRows(e,t=1){return gt(this.tableScope,{kind:"deleteRows",at:e,count:t})}insertColumns(e,t=1){return gt(this.tableScope,{kind:"insertColumns",at:e,count:t})}deleteColumns(e,t=1){return gt(this.tableScope,{kind:"deleteColumns",at:e,count:t})}getSheetData(){const e=this.tableScope.tableModel.getBodyModel();return e instanceof Ne?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 Ji(n,e){var t;return!!((t=n==null?void 0:n.isColumnLetterRow)!=null&&t.call(n,e))}class Ae{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 Xt=class Xt{constructor(e){this.prefix=e}static createPrefix(e){const t=(e??"").trim();return t?`ge-${t.replace(/\s+/g,"_")}`:(Xt.counter++,`ge-t${Xt.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`}};Xt.counter=0;let Qt=Xt;class to{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 to;if(e)for(const s of Object.keys(e))e[s]!==void 0&&(t[s]=e[s]);return t}}function Po(n){return n.manual?n.manual:!n.autoNoRows||n.rowCount!==0?"none":(n.unfilteredRowCount??0)>0?"noMatches":"noRows"}const qi={none:"",loading:"ge-table-overlay-loading",noRows:"ge-table-overlay-no-rows",noMatches:"ge-table-overlay-no-matches"};class mn{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=to.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?Po({rowCount:e,unfilteredRowCount:t,autoNoRows:s}):Po({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(qi[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 ${qi[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)}}const Bs=class Bs{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 Ae,this.areaBodyCenterGeo=new Ae,this.areaBodyEastGeo=new Ae,this.hostAttributesBefore=new Map;const i=this.hostElement;i.innerText="",this.direction=Nr(o==null?void 0:o.direction,i),this.dom.setDirection(this.direction),this.dom.setAttribute(i,"tabindex","0"),this.ariaIds=new Qt(Qt.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))),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 mn(i,s,o==null?void 0:o.overlayOptions,()=>this.updateOverlay())}isRtl(){return this.direction==="rtl"}getViewportScrollLeft(){return Vr(this.scrollViewport,this.isRtl())}setViewportScrollLeft(e){_r(this.scrollViewport,e,this.isRtl())}clientXToHostX(e){const t=this.hostElement,s=t.getBoundingClientRect();return $r(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(){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`,top:`${this.scrollTop}px`,left:`${this.getViewportScrollLeft()}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))),this.adjustAfterScrolling()}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,Bs.maxScrollHeightInPx)}px`;this.dom.setStyle(this.contentWrapperDiv,"width",e),this.dom.setStyle(this.contentWrapperDiv,"height",s)}};Bs.maxScrollHeightInPx=8e6;let es=Bs;class bn{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(),t=this.tableModel.getColumnCount();for(let s=0;s<e;s++)for(let o=0;o<t;o++){let i=this.areaModel.getColspanAt(s,o),r=this.areaModel.getRowspanAt(s,o);if(i>1||r>1){i===0&&(i=1),r===0&&(r=1);const l="gammaCells"in this.areaModel;this.colAndRowspanRanges.push(new M(s,o,s+r-1,o+i-1,l))}}}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 ts{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 ts(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 wn{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 yn{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 Cn extends es{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.removables=[],this.treeAriaInfo=new wn,this.ariaSelectionKind="none",this.renderedSpanCells=new Set,this.bodyRowLayout=new yn,this.bodyRowLayoutDirty=!0,this.adjustingRowNumberWidth=!1,this.adjustingRelativeWidths=!1,this.relativeWidthsBase=-1,this.rowNumberRemeasureScheduled=!1,this.ariaTexts=pe.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 Me("range","multi"):new Me;this.getSelectionModel=()=>d}if((h=this.tableOptions)!=null&&h.getFocusModel)this.getFocusModel=this.tableOptions.getFocusModel;else{const d=new Si("cell");this.getFocusModel=()=>d}Z(t.getAreaModel("body"))&&(this.tree=!0),["header","body","footer"].forEach(d=>{var u;this.colAndRowspanModels[d]=new bn(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.hasBodyRowExtras()?this.getBodyRowLayout().getTop(e):this.tableModel.getBodyModel().getYPosByRowIndex(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}}}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(){var e;for(const t of["header","body","footer"])(e=this.colAndRowspanModels[t])==null||e.initIfRowCountChanged();this.tableModel.recalcHeightAndPadding(),this.invalidateRowLayout(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows(),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)==="%"}))}adjustContainersAndRows(){super.adjustContainersAndRows(),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.adjustContainersAndRows()}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=ts.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 Ae(0,e,1,0),this.hostElement,"ge-table-border")),this.tableOptions.tableBottomBorderVisible&&this.removables.push(this.dom.addHorizontalBorder(new Ae(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 Ae(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 Ae(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.afterRenderPass()}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>es.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.dom.setStyle(this.contentDiv,"top",`${this.scrollTop}px`);const s=this.areaHeightsOfRenderPass?this.scrollLeft:this.getViewportScrollLeft();this.dom.setStyle(this.contentDiv,"left",`${s}px`),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 S,E,x,R,F;const s=this.getArea(e,"west"),o=this.getArea(e,"center"),i=this.getArea(e,"east"),r=((S=this.areaHeightsOfRenderPass)==null?void 0:S[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 v=this.cleanupFunctions[e].shift();v&&v()}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 v=(x=h.getConstantRowHeight)==null?void 0:x.call(h);if(v!==void 0&&v>0&&u<0){for(m=Math.min(d,Math.floor(-u/v));m>0&&u+m*v>0;)m--;u=u+m*v}}for(let v=m;v<d;v++){const D=u,k=v===d-1,N=this.tableModel.getRowHeight(e,v),V=y?b.getExtraHeight(v):0;if(V>0&&D+N+V>0&&C.push(v,D+N,V),D+N>0){e==="body"&&this.firstVisibleRowIndex===-1&&(this.firstVisibleRowIndex=v,this.firstFullVisibleRowIndex=D<-this.pixelLimitForFullVisible?this.firstVisibleRowIndex+1:this.firstVisibleRowIndex);let $={left:l,width:a,height:N,top:D,index:v},j=this.dom.addRowDiv(o,$,v,e,"center");this.applyRowAria(j,e,h,v);const _e=[j],H=p;this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"center",areaModel:h,geo:$,parent:j,rowIndex:v,columnIndexStart:H,columnIndexEnd:f-g-1,verticalFixed:!1,lastRowOfModel:k}),c.left>0&&($={left:l,width:this.areaBodyWestGeo.width,height:N,top:D,index:v},j=this.dom.addRowDiv(s,$,v,e,"west"),this.applyRowAria(j,e,h,v),_e.push(j),this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"west",areaModel:h,geo:$,parent:j,rowIndex:v,columnIndexStart:0,columnIndexEnd:H-1,verticalFixed:!0,lastRowOfModel:k})),c.right>0&&($={left:l,width:this.areaBodyEastGeo.width,height:N,top:D,index:v},j=this.dom.addRowDiv(i,$,v,e,"east"),this.applyRowAria(j,e,h,v),this.adjustColumnsToRowParent({areaIdent:e,sideIdent:"east",areaModel:h,geo:$,parent:j,rowIndex:v,columnIndexStart:f-g,columnIndexEnd:f-1,verticalFixed:!0,lastRowOfModel:k}));const P=e==="header"&&this.tree&&v===d-1?this.findCellDiv(_e,this.getTreeArrowColumnIndex()):void 0;if(P!=null&&P.parentElement){const ue=this.dom.getInlineStart(P)+16,te=this.dom.applyStyle(this.dom.setAttribute(this.dom.addDiv(P.parentElement,new Ae(ue,20,20,8)),"data-ge-action","toggleExpandCollapseAll"),{cursor:"pointer"}),L=this.tableOptions.treeOptions.arrowExpandCollapseAll;if(L){const Y=this.dom.domService.createText(L.content);this.dom.domService.appendChild(te,Y),L.style&&this.dom.applyStyleString(te,L.style)}}}if(u=u+N+V,u>r){if(e==="body"){const $=u-V;$<=0&&this.firstVisibleRowIndex===-1?this.displayedRowCount=0:(this.lastVisibleRowIndex=v,this.lastFullVisibleRowIndex=r-$<-this.pixelLimitForFullVisible?v-1:v,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+`
|
|
45
45
|
render scope: this.firstFullVisibleRowIndex <- `+this.firstFullVisibleRowIndex+`
|
|
46
46
|
render scope: this.lastVisibleRowIndex <- `+this.lastVisibleRowIndex+`
|
|
47
|
-
render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),this.pruneRowDivCache(s),this.pruneRowDivCache(o),this.pruneRowDivCache(i),this.colAndRowspanModels&&this.colAndRowspanModels[e]){const v=((L=this.colAndRowspanModels[e])==null?void 0:L.getRanges())??[];if(v.length)for(const D of v){if(D.r1>=d||D.c1>=f)continue;let k=0,N=o.child,V="center";if(D.c1<p)N=s.child,V="west";else if(g>0&&D.c1>=f-g)N=i.child,V="east";else{const $=this.areaBodyCenterGeo.width-this.tableModel.getContentWidthInPixel();k=this.snapToDevicePixel(this.scrollFactorX*$)-this.areaBodyWestGeo.width,V="center"}this.drawBigCell(D,k,t,h,N,V)}}this.updateRowGroupRoles(s,o,i)}getAriaGridInfo(){return this.ariaGridInfo||(this.ariaGridInfo=ts.create(this.tableModel)),this.ariaGridInfo}applyRowAria(e,t,s,o,i=!0){var l,a;const r=this.dom.domService;if(r.setAttribute(e,"role","row"),r.setAttribute(e,"aria-rowindex",`${this.getAriaGridInfo().rowIndex(t,o)}`),!(t!=="body"||!i)){if(this.tree&&Z(s)){const c=this.treeAriaInfo.get(s,o);c&&(r.setAttribute(e,"aria-level",`${c.level}`),r.setAttribute(e,"aria-setsize",`${c.setSize}`),r.setAttribute(e,"aria-posinset",`${c.posInSet}`),c.expanded===void 0?this.dom.removeAttribute(e,"aria-expanded"):r.setAttribute(e,"aria-expanded",`${c.expanded}`))}if((l=this.masterDetailService)!=null&&l.isActive()&&(this.masterDetailService.isMasterAt(o)?r.setAttribute(e,"aria-expanded",`${this.masterDetailService.isExpandedAt(o)}`):e.hasAttribute("aria-expanded")&&this.dom.removeAttribute(e,"aria-expanded")),this.ariaSelectionKind==="row"){const c=(a=this.getSelectionModel)==null?void 0:a.call(this);r.setAttribute(e,"aria-selected",c&&c.getSelectionCount(o,0)>0?"true":"false")}else e.hasAttribute("aria-selected")&&this.dom.removeAttribute(e,"aria-selected")}}applyCellAria(e,t,s,o,i){var f,g;const r=this.dom.domService,l=this.getAriaGridInfo(),a=t==="header",c=t==="body"&&O(this.tableModel.getColumnDef(i))||t==="footer"&&Pr(s)&&s.isLabelCell(o,i)||t==="body"&&ne(s)&&s.isGroupLabelCell(o,i)||!a&&!!((f=s.isRowHeaderCell)!=null&&f.call(s,o,i));r.setAttribute(e,"role",a?"columnheader":c?"rowheader":"gridcell");const h=l.colIndex(i);h>0&&r.setAttribute(e,"aria-colindex",`${h}`);const d=Math.max(1,s.getRowspanAt(o,i)||1),u=Math.max(1,s.getColspanAt(o,i)||1);if(u>1&&r.setAttribute(e,"aria-colspan",`${l.colSpan(i,u)}`),d>1&&r.setAttribute(e,"aria-rowspan",`${d}`),(d>1||u>1)&&this.renderedSpanCells.add(`${t}:${o}:${i}`),a&&o+d>=l.headerRowCount&&u===1){const p=this.tableModel.getColumnDef(i);if((g=p==null?void 0:p.sortable)!=null&&g.call(p)){const m=p.sortState;r.setAttribute(e,"aria-sort",m==="asc"?"ascending":m==="desc"?"descending":"none")}}return[d,u]}updateRowGroupRoles(...e){for(const t of e){let s=0;for(const i of Array.from(t.child.children)){if(!i.classList.contains("ge-table-row-div")||i.classList.contains("ge-table-span-row")){i.getAttribute("role")==="row"&&s++;continue}i.querySelector(':scope > [role="gridcell"], :scope > [role="columnheader"], :scope > [role="rowheader"]')?s++:i.getAttribute("role")==="row"&&(this.dom.domService.setAttribute(i,"role","presentation"),this.dom.removeAttribute(i,"aria-rowindex"))}const o=t.child.firstElementChild&&s?"rowgroup":"presentation";t.child.getAttribute("role")!==o&&this.dom.domService.setAttribute(t.child,"role",o)}}setHostAttribute(e,t){this.setHostAriaAttribute(e,t)}updateHostAria(){var i;const e=this.getAriaGridInfo();this.setHostAttribute("aria-rowcount",`${e.rowCount}`),this.setHostAttribute("aria-colcount",`${e.colCount}`);const t=(i=this.getSelectionModel)==null?void 0:i.call(this),s=this.ariaSelectionKind!=="none"&&(t==null?void 0:t.selectionMode)==="multi";this.setHostAttribute("aria-multiselectable",s?"true":void 0);const o=this.ariaFocusedCell;if(o){const r=this.ariaIds.cell(o.area,o.rowIndex,o.columnIndex);this.dom.domService.setAttribute(o.element,"id",r),this.setHostAttribute("aria-activedescendant",r)}else this.setHostAttribute("aria-activedescendant",void 0)}setAriaFocusedCell(e,t,s,o){const i=this.ariaFocusedCell;i&&i.area===t&&i.rowIndex===s&&i.columnIndex===o||(this.ariaFocusedCell={element:e,area:t,rowIndex:s,columnIndex:o})}getAriaSelectionKind(){var s;const e=(s=this.getSelectionModel)==null?void 0:s.call(this);if(!e)return"none";const t=e.selectionType;return t==="none"?"none":t==="row"?"row":"cell"}getColumnAriaLabel(e){const t=this.tableModel.getColumnDef(e);if(t!=null&&t.headerLabel)return`${t.headerLabel}`;const s=this.tableModel.getAreaModel("header"),o=(s==null?void 0:s.getRowCount())??0;if(o>0){const i=s.getValueAt(o-1,e),r=i&&typeof i=="object"&&"data"in i?i.data:i;if(typeof r=="string"&&r.trim()||typeof r=="number")return`${r}`}return(t==null?void 0:t.property)||`Column ${e+1}`}getCheckboxAriaLabel(e,t){return e==="header"?this.ariaTexts.selectAllRows():this.ariaTexts.selectRow(t+1)}labelControl(e,t){t&&!e.hasAttribute("aria-label")&&!e.hasAttribute("aria-labelledby")&&this.dom.domService.setAttribute(e,"aria-label",t)}labelRendererControls(e,t,s,o,i){if(ii(t)||e.classList.contains("ge-table-row-checkbox-div")){const l=e.querySelector("input.ge-table-row-checkbox");if(l){this.labelControl(l,this.getCheckboxAriaLabel(s,o));return}const a=e.querySelector("input.ge-input-checkbox");a&&this.labelControl(a,this.getColumnAriaLabel(i));return}const r=this.tableOptions.ariaTexts;if(s==="header"&&(r!=null&&r.expandGroup||r!=null&&r.collapseGroup)){const l=e.querySelector('.ge-table-toggle-icon-div[role="button"]');if(l){const a=l.getAttribute("data-ge-group-label")??"",c=l.getAttribute("aria-expanded")==="true";this.dom.domService.setAttribute(l,"aria-label",c?this.ariaTexts.collapseGroup(a):this.ariaTexts.expandGroup(a))}}}findCellDiv(e,t){for(const s of e){const o=s.querySelector(`:scope > .ge-table-col-div[data-col-index="${t}"]`);if(o)return o}}pruneRowDivCache(e){const t=e.cache;for(const s in t)t[s].parentNode!==e.child&&delete t[s]}drawBigCell(e,t,s,o,i,r){const l=s+(o.areaIdent==="body"?this.getBodyRowLayout().getTop(e.r1):this.getRowHeights(0,e.r1-1,o).reduce((y,C)=>y+C,0)),a=this.tableModel.getColumnCount(),c=this.tableModel.getFixedRightColumnCount();let h=0;c>0&&e.c1>=a-c&&(h=a-c);const d=t+this.getColumnWidths(h,e.c1-1).reduce((y,C)=>y+C,0),u=this.getRowHeights(e.r1,e.r2,o).reduce((y,C)=>y+C,0),f=this.getColumnWidths(e.c1,e.c2).reduce((y,C)=>y+C,0);let g=!1;const p=this.getSelectionModel?this.getSelectionModel():void 0;p&&(g=p.getSelectionCount(e.r1,e.c1)>0);const m=o.areaIdent,b=this.dom.applyStyle(this.dom.createDivWithClass("ge-table-span-row",i),{position:"absolute",left:"0",top:"0",width:"0",height:"0",overflow:"visible"});this.renderedSpanCells.has(`${m}:${e.r1}:${e.c1}`)?this.dom.setAriaHidden(b):this.applyRowAria(b,m,o,e.r1,!1),i=b,e.gammaRange?this.renderCell({areaModel:o,areaIdent:o.areaIdent,sideIdent:r,rowIndex:e.r1,columnIndex:e.c1,left:d,top:l,width:f,height:u,parent:i,cellSelected:g,lastRowOfModel:!0,gammaRange:e.gammaRange}):this.renderCell({areaModel:o,areaIdent:o.areaIdent,sideIdent:r,rowIndex:e.r1,columnIndex:e.c1,left:d,top:l,width:f,height:u,parent:i,cellSelected:g,lastRowOfModel:!0,gammaRange:e.gammaRange}),o.areaIdent==="header"&&this.tableOptions.columnsResizable&&this.isColumnResizable(e.c1)&&this.renderHeaderCellResizeHandle({rowIndex:e.r1,columnIndex:e.c1,cellLeft:d,cellTop:l,cellWidth:f,cellHeight:u,parent:i})}findRowOfImportantRowspanCell(e,t,s){const o=e.getMaxRowspan();for(let i=t-1;i>-1;i--){const r=e.getRowspanAt(i,s);if(r>1&&i+r+1>=t)return i;if(t-i>o)return-1}return-1}adjustColumnsToRowParent({areaIdent:e,sideIdent:t,areaModel:s,geo:o,parent:i,rowIndex:r,columnIndexStart:l,columnIndexEnd:a,verticalFixed:c=!1,lastRowOfModel:h=!1}){var p;let d=0;if(!c){const m=this.areaBodyCenterGeo.width-this.tableModel.getContentWidthInPixel();d=this.snapToDevicePixel(this.scrollFactorX*m)}const u=0,f=!!(e==="body"&&t);let g=d;for(let m=l;m<=a;m++){const b=g,y=this.tableModel.getColumnWidth(m);if(y>0&&b+y>0){let C=o.height;const S=s.getRowspanAt(r,m),E=s.getColspanAt(r,m);S>1&&(C=this.getRowHeights(r,r+S-1,s).reduce((L,v)=>L+v,0));let x=y;E>1&&(x=this.getColumnWidths(m,m+E-1).reduce((L,v)=>L+v,0));let R=!1;if(this.colAndRowspanModels&&this.colAndRowspanModels[e]&&(p=this.colAndRowspanModels[e])!=null&&p.isInRange(r,m)&&(R=!0),this.draggingTargetColumnIndex===m&&e!=="header"){this.renderDragTargetDiv(i,b,u,x,C);const L={left:b,top:u,width:x,height:C};this.dom.addColumnBorderDivs(this.tableOptions,i,L,e,t)}else{const L=this.renderSelectedBackgroundDiv(R,f,t,s,r,m,i,b,u,x,C);"gammaCells"in s&&s.getValueAt(r,m)&&(R=!1),R||this.renderCell({areaModel:s,areaIdent:e,sideIdent:t,rowIndex:r,columnIndex:m,left:b,top:u,width:x,height:C,parent:i,cellSelected:L,lastRowOfModel:h,gammaRange:!0}),e==="header"&&this.tableOptions.columnsResizable&&this.isColumnResizable(m)&&this.renderHeaderCellResizeHandle({rowIndex:r,columnIndex:m,cellLeft:b,cellTop:u,cellWidth:x,cellHeight:C,parent:i})}}if(g=g+y,g>this.areaBodyCenterGeo.width)break}this.tableOptions.verticalBorderVisible&&this.dom.addVerticalBorder(new Ae(g-1,1,o.height,0),i)}getTreeArrowColumnIndex(){const e=this.getFirstDataColumnIndex();return this.tableOptions.showCheckboxWihoutExtraColumn?e:this.tableModel.isRowCheckboxVisible()?e+1:e}getFirstDataColumnIndex(){var e,t;return Zt((t=(e=this.tableModel).getColumnDefs)==null?void 0:t.call(e))}isColumnResizable(e){return!O(this.tableModel.getColumnDef(e))}adjustRowNumberColumnWidth(){var i,r;if(!this.getFirstDataColumnIndex()||this.tableModel.overridingColumnWidth>-1)return!1;const e=this.tableModel.getColumnDef(0),t=e.getWidestText(this.tableModel.getBodyModel()),s=this.rowNumberWidth;let o=(s==null?void 0:s.text)===t?s.width:-1;if(o<0||s!=null&&s.approximate&&this.findRowNumberLabel()){const[l,a]=this.measureRowNumberText(t);o=Math.max(e.options.minWidthInPx,l),this.rowNumberWidth={text:t,width:o,approximate:a}}return this.tableModel.getColumnWidth(0)===o||((r=(i=this.tableModel).isColumnVisible)==null?void 0:r.call(i,0))===!1?!1:(this.tableModel.setColumnWidth(0,o),this.tableModel.getColumnWidth(0)===o)}findRowNumberLabel(){return this.hostElement.querySelector(".ge-table-row-number .ge-table-label")}measureRowNumberText(e){const t=this.findRowNumberLabel(),s=getComputedStyle(t??this.hostElement),i=(t?(parseFloat(s.paddingLeft)||0)+(parseFloat(s.paddingRight)||0):12)+4,r=e.replace(/[0-9]/g,"0");let l=null;try{l=document.createElement("canvas").getContext("2d")}catch{l=null}return l?(l.font=s.font||`${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,[Math.ceil(l.measureText(r).width+i),!t]):[Math.ceil(e.length*8+i),!t]}addAndRenderCellDiv({areaModel:e,areaIdent:t,sideIdent:s,rowIndex:o,index:i,left:r,width:l,height:a,top:c,parent:h,lastRowOfModel:d}){var P,ue,te;const u=t==="body"&&this.editorRenderer&&this.editorRendererRow===o&&this.editorRendererColumn===i,f=this.tableModel.getColumnDef(i),g=O(f),p=u?this.editorRenderer:(g&&t==="body"?f.rendererMap.body:void 0)??e.getCellRenderer(o,i),m={left:r,width:l,height:a,top:c,index:i},b=e.getRowByIndex(o);let y="none";if(i===this.getTreeArrowColumnIndex()&&U(b)){const F=b;("hasDisplayedChildren"in e&&typeof e.hasDisplayedChildren=="function"?e.hasDisplayedChildren(F):!!((P=F.children)!=null&&P.length))?F.expanded?y="expanded":y="collapsed":y="hidden"}let S;t==="header"&&(!(f!=null&&f.sortIconVisible)||f!=null&&f.sortIconVisible())&&(S=f==null?void 0:f.sortState);const E=t==="body"&&((ue=this.batchEditService)!=null&&ue.hasPending())?this.batchEditService.getPendingAt(o,i):void 0,x=E?E.newValue:e.getValueAt(o,i),R=p||g&&t==="footer"?"":`${x??""}`,L=e.isRowChecked(o),v=this.getFirstDataColumnIndex(),D=this.tableOptions.showCheckboxWihoutExtraColumn&&i===v&&L?this.getCheckboxAriaLabel(t,o):void 0,k=this.dom.addColumnDiv({parent:h,geo:m,rowIndex:o,columnIndex:i,areaIdent:t,sideIdent:s,text:R,treeArrow:y,tableOptions:this.tableOptions,checkedType:L,sortState:S,checkboxAriaLabel:D,firstDataColumnIndex:v}),[N,V]=this.applyCellAria(k,t,e,o,i),$=(E==null?void 0:E.error)||e.getTooltipAt(o,i);$&&this.dom.setAttribute(k,"title",$),E&&(this.dom.addClass("ge-table-cell-pending",k),E.error&&(this.dom.addClass("ge-table-cell-invalid",k),this.dom.setAttribute(k,"aria-invalid","true"))),f&&f.classes[t]&&this.dom.addClasses(f.classes[t],k);let j;if(p)if(j=p.render(k,o,i,t,e,x,this.dom.domService),u){const F=k.querySelector("input, select");if(F){this.labelControl(F,this.getColumnAriaLabel(i));const Y=this.editorDraft;if(Y&&Y.rowIndex===o&&Y.columnIndex===i&&F instanceof HTMLInputElement&&(F.value=Y.value,this.dom.setAttribute(F,"data-ge-restored","true")),F.contains(document.activeElement)||F.focus(),Y&&Y.rowIndex===o&&Y.columnIndex===i&&F instanceof HTMLInputElement&&Y.start!==null&&Y.end!==null)try{F.setSelectionRange(Y.start,Y.end)}catch{}}}else this.labelRendererControls(k,p,t,o,i);const _e=e.getCustomClassesAt(o,i);if(_e.length&&this.dom.addClasses(_e,k),t==="body"&&this.cellEditorService&&!g){e.isEditable(o,i)||this.dom.setAttribute(k,"aria-readonly","true");const F=this.cellEditorService.getOwnedEditorId(o,i);F&&this.dom.setAttribute(k,"aria-owns",F)}if(this.dom.addColumnBorderDivs(this.tableOptions,h,m,t,s),d&&this.dom.addHorizontalBorder({left:r,width:l,height:a,top:c+a},h),this.getFocusModel&&t==="body"&&!this.headerFocus){const F=this.getFocusModel();if(F!=null&&F.hasFocus(o,i))this.dom.addFocusBorderDivs(h,m,{}),this.setAriaFocusedCell(k,t,o,i);else if(F&&(N>1||V>1)){const[Y,Ot]=F.getFocus();Y>=o&&Y<o+N&&Ot>=i&&Ot<i+V&&this.setAriaFocusedCell(k,t,o,i)}}else t==="header"&&this.headerFocus&&this.headerFocus[0]===o&&this.headerFocus[1]===i&&(this.dom.addFocusBorderDivs(h,m,{}),this.setAriaFocusedCell(k,t,o,i));t==="header"&&!g&&this.dom.setAttribute(k,"data-ge-action","drag-column"),t==="body"&&((te=this.masterDetailService)!=null&&te.isActive())&&this.masterDetailService.decorateCell(k,o,i),t==="body"&&this.rowDragService&&!u&&(f!=null&&f.rowDrag&&this.rowDragService.decorateCell(k,this.rowDragService.getHandleState(o,f,e)),this.rowDragService.isDragSourceRow(o)&&this.dom.addClass("ge-table-row-dragging",k));const H=e.getCustomStyleAt(o,i);if(H)for(const F in H)this.dom.domService.setStyle(k,F,H[F]);return[k,j]}applyCssClasses(e,t={}){e&&Object.entries(t).forEach(([s,o])=>{o?this.dom.addClass(s,e):this.dom.removeClass(s,e)})}getColumnWidths(e,t){const s=[];for(let o=e;o<=t;o++)s.push(this.tableModel.getColumnWidth(o));return s}getRowHeights(e,t,s){const o=[];for(let i=e;i<=t;i++)o.push(s.getRowHeight(i));return o}adjustHoverRows(e){if(this.tableOptions.hoverRowVisible&&e.rowIndex>-1&&e.areaIdent==="body"){const t=this.hostElement.clientWidth,s=this.tableModel.getAreaModel("body").getRowHeight(e.rowIndex),o=this.contentScrollTop,i=e.rowTop+this.areaHeaderCenter.parent.clientHeight-o;this.dom.applyStyle(this.hoverRow,{left:"0",top:i+"px",width:t+"px",height:s+"px",display:"block"})}else this.hideHoverRow()}hideHover(){this.hideHoverRow(),this.hideHoverColumn()}hideHoverRow(){this.dom.applyStyle(this.hoverRow,{display:"none"})}adjustHoverColumns(e){if(this.tableOptions.hoverColumnVisible&&e.rowIndex>-1){const t=this.hostElement.clientHeight,s=this.tableModel.getColumnWidth(e.columnIndex),o=this.getColumnLeftInHost(e.columnIndex,e.columnLeft);this.dom.applyStyle(this.hoverColumn,{left:o+"px",top:"0px",width:s+"px",height:t+"px",display:"block"})}else this.hideHoverColumn()}getColumnLeftInHost(e,t){const s=this.tableModel.getColumnCount(),o=this.tableModel.getFixedLeftColumnCount(),i=this.tableModel.getFixedRightColumnCount();if(e<o)return t;if(i>0&&e>=s-i){const r=this.tableModel.getXPosByColumnIndex(s-i);return this.areaBodyEastGeo.left+t-r}return t-this.getContentScrollLeft()}getContentScrollLeft(){const e=this.areaBodyCenterGeo.width-this.tableModel.getContentWidthInPixel();return-this.snapToDevicePixel(this.scrollFactorX*e)}hideHoverColumn(){this.dom.applyStyle(this.hoverColumn,{display:"none"})}disposeRendering(){this.debounceTimeout&&(clearTimeout(this.debounceTimeout),this.debounceTimeout=null);for(const e of["header","body","footer"])for(;this.cleanupFunctions[e].length;){const t=this.cleanupFunctions[e].shift();t&&t()}}debounce(e,t=1e3){this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.debounceTimeout=null,e.call(this)},t)}adjustDraggingColumn(e,t,s){var o;if(this.dragging){const i=this.hostElement.clientHeight,r=this.tableModel.getColumnWidth(t);if((o=e.originalEvent)!=null&&o.clientX){const c={left:(this.isRtl()?this.clientXToHostX(e.originalEvent.clientX):e.originalEvent.clientX)-r/2,width:r,height:i,top:0,index:t};this.dom.applyStyle(this.draggingColumn,{background:"rgba(128,128,128,0.2)",display:"block",overflow:"hidden"}),this.dom.applyStyleInPx(this.draggingColumn,c),s&&this.renderContentOfDraggingColumn(c)}}else this.hideDraggingColumn()}renderContentOfDraggingColumn(e){const t=this.renderContentOfDraggingColumnForArea(e,"header",0),s=Math.max(0,this.firstVisibleRowIndex),o=t+this.getBodyRowTop(s)-this.contentScrollTop;this.renderContentOfDraggingColumnForArea(e,"body",o,s,this.hostElement.clientHeight)}renderContentOfDraggingColumnForArea(e,t,s=0,o=0,i=Number.POSITIVE_INFINITY){const r="center",l=this.tableModel.getAreaModel(t),a=l==null?void 0:l.getRowCount();if(a){const c=e.index??0,h=this.draggingColumn;for(let d=o;d<a&&s<i;d++){const u=s,f=l.getRowHeight(d),g={left:0,width:e.width,height:f,top:u,index:d},p=l.getValueAt(d,c),m=l.getCellRenderer(d,c),b=m?"":`${p??""}`,y={parent:h,geo:g,rowIndex:d,columnIndex:c,areaIdent:t,sideIdent:r,text:b},C=this.dom.addColumnDiv(y);let S;m&&(S=m.render(C,d,c,t,l,p,this.dom.domService),S&&this.cleanupFunctions[t].push(S));const E=l.getCustomClassesAt(d,c);E.length&&this.dom.addClasses(E,C);const x=this.tableModel.getColumnDef(c);x&&x.classes[t]&&this.dom.addClasses(x.classes[t],C),this.dom.addColumnBorderDivs(this.tableOptions,h,g,t,r);const R=l.getCustomStyleAt(d,c);if(R)for(const L in R)this.dom.domService.setStyle(C,L,R[L]);s=s+f}}return s}hideDraggingColumn(){this.dom.applyStyle(this.draggingColumn,{display:"none"})}renderDragTargetDiv(e,t,s,o,i){const r=this.dom.applyStylePosistionAbsolute(this.dom.setAriaHidden(this.dom.createDivWithClass("ge-table-drop-zone",e)));return this.dom.setStyle(r,"left",`${t}px`),this.dom.setStyle(r,"top",`${s}px`),this.dom.setStyle(r,"width",`${o}px`),this.dom.setStyle(r,"height",`${i}px`),r}renderSelectedBackgroundDiv(e,t,s,o,i,r,l,a,c,h,d){let u=!1;if(!e&&t&&o.isSelectable(i,r)&&this.getSelectionModel){const f=this.getSelectionModel();if(f){const g=f.getSelectionCount(i,r);u=g>0;for(let p=0;p<g;p++){const m=this.dom.applyStylePosistionAbsolute(this.dom.setAriaHidden(this.dom.createDivWithClass(`ge-table-${o.areaIdent}-${s}-selected-range`,l)));this.dom.setStyle(m,"left",`${a}px`),this.dom.setStyle(m,"top",`${c}px`),this.dom.setStyle(m,"width",`${h}px`),this.dom.setStyle(m,"height",`${d}px`)}}}return u}renderCell({areaModel:e,areaIdent:t,sideIdent:s,rowIndex:o,columnIndex:i,left:r,top:l,width:a,height:c,parent:h,cellSelected:d,lastRowOfModel:u}){const[f,g]=this.addAndRenderCellDiv({areaModel:e,areaIdent:t,sideIdent:s,rowIndex:o,index:i,left:r,width:a,height:c,top:l,parent:h,lastRowOfModel:u});d&&this.dom.addClass(`ge-table-${t}-${s}-selected-range`,f),t==="body"&&this.ariaSelectionKind==="cell"&&this.dom.domService.setAttribute(f,"aria-selected",d?"true":"false"),g&&this.cleanupFunctions[t].push(g)}renderHeaderCellResizeHandle({rowIndex:e,columnIndex:t,cellLeft:s,cellTop:o,cellWidth:i,cellHeight:r,parent:l}){const a=this.dom.domService,c=this.tableOptions.columnResizeHandleWidthInPx??2,h=a.createElement("div");a.setAttribute(h,"data-col-index",`${t}`),a.setAttribute(h,"data-row-index",`${e}`),a.setAttribute(h,"data-area","header"),a.setAttribute(h,"data-ge-action","resize-column"),a.addClass(h,"ge-table-column-resize-handle"),a.setAttribute(h,"aria-hidden","true"),a.setStyle(h,"display","clip"),a.setStyle(h,"position","absolute"),a.setStyle(h,"cursor","col-resize"),this.dom.setStyle(h,"left",`${s+i-c}px`),a.setStyle(h,"top",`${o}px`),a.setStyle(h,"width",`${c}px`),a.setStyle(h,"height",`${r}px`),a.appendChild(l,h)}}class Ts{constructor(e,t){this.columnIndex=e,this.sortState=t}}const Sn=new WeakSet;function xc(n){return Sn.add(n),n}function xn(n){return typeof n=="function"&&Sn.has(n)}class vn{constructor(e,t){this.state=e,this.changedParts=t}}const Be=Object.freeze(["headerGroups","columns","tree","sort","checked","selection","details","scroll","custom"]),vc=["sortingState","scrollState","collapsedExpandedState"];function bo(n,e){try{const t=n.getItem(e);return t?JSON.parse(t):void 0}catch{return}}function Rn(n,e,t){const s={version:1};let o=!1;const i=bo(n,e+"sortingState");Array.isArray(i)&&(o=!0,s.sort=i.filter(a=>a&&typeof a.columnIndex=="number"&&(a.sortState==="asc"||a.sortState==="desc")).map(a=>{const c=t[a.columnIndex],h=a.sortState;return c?{property:c,sortState:h}:{columnIndex:a.columnIndex,sortState:h}}));const r=bo(n,e+"scrollState");Array.isArray(r)&&typeof r[0]=="number"&&typeof r[1]=="number"&&(o=!0,s.scroll={left:r[0],top:r[1]});const l=bo(n,e+"collapsedExpandedState");if(l&&typeof l=="object"){o=!0;let a;l.allExpanded?a={collapsedRowIds:[]}:l.allCollapsed?a={expandedRowIds:[]}:l.mode==="expanded"?a={expandedRowIds:l.rowIds??[]}:a={collapsedRowIds:l.rowIds??[]},s.tree=a}return o?s:void 0}function No(n,e){for(const t of vc)try{n.removeItem(e+t)}catch{}}const Rc={headerGroups:"autoRestoreHeaderGroupState",columns:"autoRestoreColumnLayout",tree:"autoRestoreCollapsedExpandedState",sort:"autoRestoreSortingState",checked:"autoRestoreCheckedState",selection:"autoRestoreSelectedState",scroll:"autoRestoreScrollPosition",custom:"autoRestoreCustomState",details:"autoRestoreDetailState"},Je=n=>n==="checked"?"checkedRowIds":n==="details"?"detailRowIds":n,Te=Number.MAX_SAFE_INTEGER,Ie=class Ie{constructor(e){this.scope=e,this.restoring=!1,this.started=!1,this.destroyed=!1,this.dirty=new Set,this.lastReported=new Map,this.reported={version:1},this.legacyRemoved=!1,this.sortPriority=[],this.initialWidths=new Map,this.startState={},this.custom=void 0,this.warnedNoRowObject=!1,this.warnedNoId=!1,this.warnWithoutStorageKey()}initBeforeModel(){this.started||(this.started=!0,this.restoring=!0,this.startState=this.readStartState(),this.defaultState={version:1},this.computePart("headerGroups",this.defaultState),this.startState.headerGroups&&this.applyHeaderGroups(this.startState.headerGroups))}initAfterModel(){if(!this.restoring)return;for(const s of this.columnDefs())this.initialWidths.set(s,s.width);this.sortPriority=this.columnDefs().filter(s=>s.sortState&&s.property).map(s=>s.property);const e=s=>this.persistedParts().includes(s)||this.startState[Je(s)]!==void 0,t=this.getState(Be.filter(s=>s!=="headerGroups"&&s!=="scroll"&&s!=="custom"&&(!Ie.EXPENSIVE.includes(s)||e(s))));this.defaultState={...this.defaultState,...t,scroll:{left:0,top:0}},this.startState.columns&&this.applyColumns(this.startState.columns,!1)}initAfterFilter(){if(!this.restoring)return;const e=this.startState;e.tree&&this.applyTree(e.tree),e.sort&&this.applySort(e.sort),e.checkedRowIds&&this.applyChecked(e.checkedRowIds),e.selection&&this.applySelection(e.selection),e.detailRowIds&&this.applyDetails(e.detailRowIds),"custom"in e&&(this.custom=e.custom)}initAfterLayout(){this.restoring&&(this.startState.scroll&&this.applyScroll(this.startState.scroll),this.restoring=!1,this.rememberAsReported(this.getState(Be.filter(e=>!Ie.EXPENSIVE.includes(e)))))}getState(e=Be){const t={version:1};for(const s of e)this.computePart(s,t);return t}applyState(e,t=Be){if(!e||typeof e!="object")return;const s=r=>t.includes(r)&&e[Je(r)]!==void 0,o=[];let i=!1;s("headerGroups")&&this.applyHeaderGroups(e.headerGroups)&&o.push("headerGroups"),s("columns")&&(i=this.applyColumns(e.columns,!0),o.push("columns")),s("tree")&&(this.applyTree(e.tree),o.push("tree")),s("sort")&&(this.applySort(e.sort),o.push("sort")),s("checked")&&(this.applyChecked(e.checkedRowIds),o.push("checked")),s("selection")&&(this.applySelection(e.selection),o.push("selection")),s("details")&&(this.applyDetails(e.detailRowIds),o.push("details")),t.includes("custom")&&"custom"in e&&(this.custom=e.custom,o.push("custom")),o.includes("headerGroups")?this.scope.headerGroupsChanged():i?this.scope.recalcColumnWidths():o.length&&(this.scope.tableModel.recalcHeightAndPadding(),this.scope.recalcWrappers(),this.scope.repaintHard()),s("scroll")&&(this.applyScroll(e.scroll),o.push("scroll")),o.forEach(r=>this.markDirty(r))}resetState(){if(!this.defaultState)return;this.applyState(this.defaultState),this.custom=void 0,this.markDirty("custom"),this.flush();const e=this.storageKey(),t=this.storage();if(e&&t)try{t.removeItem(e+Ie.STORAGE_SUFFIX),No(t,e)}catch{}this.lastPersisted=void 0}setCustomState(e){this.custom=e,this.markDirty("custom")}sortedByColumn(e){this.sortPriority=e?[e]:[],this.markDirty("sort")}markDirty(e){!this.started||this.restoring||this.destroyed||(this.dirty.add(e),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>this.flush(),this.scope.tableOptions.stateChangedDebounceDelay??300))}rendered(){if(this.restoring||!this.started)return;const e=this.scope.scrollViewport,t=this.reportedScroll;(!t||t.left!==this.scope.getViewportScrollLeft()||t.top!==e.scrollTop)&&this.markDirty("scroll")}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=void 0),!this.dirty.size||!this.started||this.restoring)return;this.persistedParts().includes("checked")&&this.dirty.add("checked");const e=Be.filter(t=>this.dirty.has(t));this.dirty.clear();try{const t=this.getState(e),s=e.filter(i=>this.partJson(t,i)!==this.lastReported.get(i));if(!s.length)return;const o={...this.reported};for(const i of e){const r=Je(i);t[r]===void 0?delete o[r]:o[r]=t[r],this.lastReported.set(i,this.partJson(t,i))}this.reported=o,t.scroll&&(this.reportedScroll={left:t.scroll.left,top:t.scroll.top}),this.persist(o),this.scope.stateChanged(new vn(JSON.parse(JSON.stringify(o)),s))}catch(t){console.error("GuiExpert Table: the table state could not be stored or reported",t)}}destroy(){if(!this.destroyed){this.started&&!this.restoring&&this.persistedParts().includes("checked")&&this.dirty.add("checked");try{this.flush()}finally{this.destroyed=!0}}}storageKey(){var s;const e=(s=this.scope.tableOptions.autoRestoreOptions)==null?void 0:s.getStorageKeyFn;return(e?e():void 0)||void 0}storage(){var t;const e=(t=this.scope.tableOptions.autoRestoreOptions)==null?void 0:t.storage;if(e)return e;try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}persistedParts(){const e=this.scope.tableOptions.autoRestoreOptions;return e?Be.filter(t=>!!e[Rc[t]]):[]}warnWithoutStorageKey(){this.scope.tableOptions.autoRestoreOptions&&this.persistedParts().length&&!this.storageKey()&&console.warn("GuiExpert Table: autoRestoreOptions are ignored without getStorageKeyFn (nothing is stored).")}readStartState(){const e=this.scope.tableOptions.initialState??{},t=this.persistedParts(),s=this.storageKey(),o=this.storage();if(!t.length||!s||!o)return{...e};let i;try{const l=o.getItem(s+Ie.STORAGE_SUFFIX);if(l){const a=JSON.parse(l);a&&typeof a=="object"&&a.version===1&&(i=a,this.lastPersisted=l)}}catch{}i||(i=Rn(o,s,this.columnDefs().map(l=>l.property)));const r={...e};if(i)for(const l of t){const a=Je(l);a in i&&(r[a]=i[a])}return r}persist(e){const t=this.persistedParts(),s=this.storageKey(),o=this.storage();if(!t.length||!s||!o)return;const i={version:1};for(const l of t){const a=Je(l);e[a]!==void 0&&(i[a]=e[a])}const r=JSON.stringify(i);if(r!==this.lastPersisted)try{o.setItem(s+Ie.STORAGE_SUFFIX,r),this.lastPersisted=r,this.legacyRemoved||(No(o,s),this.legacyRemoved=!0)}catch{}}rememberAsReported(e){this.reported=e,e.scroll&&(this.reportedScroll={left:e.scroll.left,top:e.scroll.top});for(const t of Be)Je(t)in e&&this.lastReported.set(t,this.partJson(e,t))}partJson(e,t){const s=e[Je(t)];return s===void 0?"":JSON.stringify(s)}computePart(e,t){var s;switch(e){case"headerGroups":{const o=(s=this.headerGroupModel())==null?void 0:s.getToggleGroupStates();o!=null&&o.length&&(t.headerGroups=o);break}case"columns":{const o=this.computeColumns();o&&(t.columns=o);break}case"sort":{const o=this.computeSort();o&&(t.sort=o);break}case"scroll":t.scroll=this.computeScroll();break;case"tree":{const o=this.computeTree();o&&(t.tree=o);break}case"checked":{const o=this.computeChecked();o&&(t.checkedRowIds=o);break}case"selection":{const o=this.computeSelection();o&&(t.selection=o);break}case"custom":this.custom!==void 0&&(t.custom=this.custom);break;case"details":{const o=this.computeDetails();o&&(t.detailRowIds=o);break}}}computeColumns(){const e=this.columnDefs();if(!e.length)return;const t=new Set,s=[];for(const o of e){if(!o.property||t.has(o.property))continue;t.add(o.property);const i={property:o.property},r=this.initialWidths.get(o);r&&o.width&&(r.value!==o.width.value||r.unit!==o.width.unit)&&o.width.unit==="px"&&(i.width=o.width.value),i.visible=Fo(o),s.push(i)}return s}computeSort(){const e=this.columnDefs();if(!e.length)return;const t=s=>{const o=this.sortPriority.indexOf(s.property);return o<0?Te:o};return e.filter(s=>s.sortState&&s.property).map((s,o)=>({cd:s,index:o})).sort((s,o)=>t(s.cd)-t(o.cd)||s.index-o.index).map(({cd:s})=>({property:s.property,sortState:s.sortState}))}computeScroll(){const e=this.scope.scrollViewport,t={left:this.scope.getViewportScrollLeft(),top:e.scrollTop},s=this.scope.getFirstVisibleRowIndex();if(s>-1&&this.body().getRowCount()>0){const o=this.idAt(s,this.warns("scroll"));o!==void 0&&(t.firstRowId=o)}return t}computeTree(){const e=this.body();if(!Z(e))return;const t=[],s=[],o=this.warns("tree");return this.walkTree(e,i=>{var r;if((r=i.children)!=null&&r.length){const l=this.idOfRow(i,-1,o);l!==void 0&&(i.expanded?t:s).push(l)}}),t.length<=s.length?{expandedRowIds:t}:{collapsedRowIds:s}}computeChecked(){const e=this.body().rowSelectionModel;if(!e)return;const t=this.warns("checked"),s=[];for(const o of e.getCheckedRows()??[]){const i=this.idOfRow(o,-1,t);i!==void 0&&s.push(i)}return s}computeDetails(){const e=this.scope.masterDetailService;if(!(e!=null&&e.isActive()))return;const t=this.warns("details"),s=[];for(const o of e.getExpandedRows()){const i=this.idOfRow(o,-1,t);i!==void 0&&s.push(i)}return s}applyDetails(e){const t=this.scope.masterDetailService;if(!(t!=null&&t.isActive())||!Array.isArray(e))return;const s=new Set(e),o=this.body(),i=o,r=i.getAllRows?i.getAllRows():Array.from({length:o.getRowCount()},(l,a)=>o.getRowByIndex(a));t.setExpandedRows(r.filter((l,a)=>{const c=this.idOfRow(l,i.getAllRows?-1:a,!1);return c!==void 0&&s.has(c)}),"state")}computeSelection(){const e=this.scope.selectionModel();if(!e||!e.selectionType||e.selectionType==="none")return;const t=e.createSnapshot?e.createSnapshot():{ranges:e.getRanges(),negativeRanges:[],allSelected:e.isAllSelected()},s=this.warns("selection"),o=r=>r.map(l=>this.toStateRange(l,s)).filter(l=>!!l),i={ranges:o(t.ranges)};return t.negativeRanges.length&&(i.negativeRanges=o(t.negativeRanges)),t.allSelected&&(i.allSelected=!0),i}toStateRange(e,t){var a,c;const s={},o=Math.min(e.r1,e.r2),i=Math.max(e.r1,e.r2);if(!(o<=0&&i>=Te)){const h=this.idAt(o,t);if(h===void 0)return;if(s.fromRowId=h,i<Te){const d=this.idAt(i,t);if(d===void 0)return;s.toRowId=d}}const r=Math.min(e.c1,e.c2),l=Math.max(e.c1,e.c2);if(!(r<=0&&l>=Te)){const h=this.columnDefs(),d=(a=h[r])==null?void 0:a.property;if(!d)return;if(s.fromProperty=d,l<Te){const u=(c=h[l])==null?void 0:c.property;if(!u)return;s.toProperty=u}}return s}applyHeaderGroups(e){const t=this.scope.tableModel.getAreaModel("header");if(!t.setGroupClosed||!t.getToggleGroupStates||!Array.isArray(e))return!1;const s=new Map(t.getToggleGroupStates().map(i=>[i.id,i.closed]));let o=!1;for(const i of e)if(i&&s.has(i.id)&&s.get(i.id)!==!!i.closed){const r=t.setGroupClosed(i.id,!!i.closed);r&&"columnDefs"in this.scope.tableModel&&(this.scope.tableModel.columnDefs=r),o=!0}return o}applyColumns(e,t){const s=this.scope.tableModel,o=this.columnDefs();if(!o.length||!Array.isArray(e))return!1;const i=new Map;for(const d of e)d&&typeof d.property=="string"&&!i.has(d.property)&&o.some(u=>u.property===d.property)&&i.set(d.property,d);const r=o.map(d=>d.property),l=Array.from(i.keys()),a=new Set;r.forEach((d,u)=>{if(i.has(d)&&!a.has(d)){a.add(d);return}const f=u>0?l.lastIndexOf(r[u-1]):-1;l.splice(f+1,0,d)});for(let d=0;d<l.length;d++){const f=s.getColumnDefs().map(g=>g.property).indexOf(l[d],d);f>d&&s.changeColumnOrder(f,d)}let c=!1;return this.columnDefs().forEach((d,u)=>{var g;const f=i.get(d.property);if(f){if(typeof f.visible=="boolean"&&Fo(d)!==f.visible&&((g=s.setColumnVisible)==null||g.call(s,u,f.visible)),typeof f.width=="number"&&f.width>=0)s.setColumnWidth(u,f.width);else if(t){const p=this.initialWidths.get(d);p&&(p.value!==d.width.value||p.unit!==d.width.unit)&&(p.unit==="px"?s.setColumnWidth(u,p.value):c=!0,d.width=p)}}}),c}applyTree(e){const t=this.body();if(!Z(t)||!e)return;const s=Array.isArray(e.expandedRowIds);if(!s&&!Array.isArray(e.collapsedRowIds))return;const o=new Set((s?e.expandedRowIds:e.collapsedRowIds)??[]),i=t;this.walkTree(i,r=>{var l;if((l=r.children)!=null&&l.length){const a=this.idOfRow(r,-1,!1);a!==void 0&&(r.expanded=s?o.has(a):!o.has(a))}}),i.recalcVisibleTreeRows(!1)}applySort(e){var i;if(!Array.isArray(e))return;const t=this.columnDefs(),s=[],o=[];for(const r of e){if(!r||r.sortState!=="asc"&&r.sortState!=="desc")continue;const l=typeof r.property=="string"?t.findIndex(a=>a.property===r.property):typeof r.columnIndex=="number"?r.columnIndex:-1;l<0||l>=this.scope.tableModel.getColumnCount()||s.some(a=>a.columnIndex===l)||(s.push(new Ts(l,r.sortState)),(i=t[l])!=null&&i.property&&o.push(t[l].property))}this.scope.applySortItems(s),this.sortPriority=o}applyChecked(e){const t=this.body(),s=t.rowSelectionModel;if(!s||!Array.isArray(e))return;const o=new Set(e);if(Z(t)){const l=t;this.walkTree(l,a=>{a.checked=!1}),this.walkTree(l,a=>{const c=this.idOfRow(a,-1,!1);c!==void 0&&o.has(c)&&!a.checked&&s.checkRow(a,!0)});return}const i=t,r=i.getAllRows?i.getAllRows():Array.from({length:t.getRowCount()},(l,a)=>t.getRowByIndex(a));s.setCheckedRows(r.filter((l,a)=>{const c=this.idOfRow(l,i.getAllRows?-1:a,!1);return c!==void 0&&o.has(c)}))}applySelection(e){const t=this.scope.selectionModel();if(!t||!e||!Array.isArray(e.ranges))return;const o=[...e.ranges,...e.negativeRanges??[]].some(c=>c&&(c.fromRowId!==void 0||c.toRowId!==void 0))?this.rowIndexMap():new Map,i=this.columnDefs(),r=c=>{if(!c)return;let h=0,d=Te,u=0,f=Te;if(c.fromRowId!==void 0||c.toRowId!==void 0){const g=o.get(c.fromRowId??c.toRowId),p=c.toRowId===void 0?Te:o.get(c.toRowId);if(g===void 0||p===void 0)return;h=Math.min(g,p),d=Math.max(g,p)}if(c.fromProperty!==void 0||c.toProperty!==void 0){const g=i.findIndex(m=>m.property===(c.fromProperty??c.toProperty)),p=c.toProperty===void 0?Te:i.findIndex(m=>m.property===c.toProperty);if(g<0||p<0)return;u=Math.min(g,p),f=Math.max(g,p)}return new M(h,u,d,f)},l=c=>(c??[]).map(r).filter(h=>!!h),a={ranges:l(e.ranges),negativeRanges:l(e.negativeRanges),allSelected:!!e.allSelected};t.restoreSnapshot?t.restoreSnapshot(a):(t.clear(),a.ranges.forEach(c=>t.addSelection(c)))}applyScroll(e){if(!e||typeof e.top!="number"||typeof e.left!="number"||(this.scope.scrollViewport.scrollTo(Ss(e.left,this.scope.isRtl()),e.top),this.scope.adjustAfterScrolling(),e.firstRowId===void 0))return;const t=this.scope.getFirstVisibleRowIndex();if(t>-1&&this.idAt(t,!1)===e.firstRowId)return;const s=this.rowIndexMap().get(e.firstRowId);s!==void 0&&(this.scope.scrollToIndex(-1,s),this.scope.adjustAfterScrolling())}columnDefs(){return this.scope.tableModel.getColumnDefs()??[]}body(){return this.scope.tableModel.getBodyModel()}headerGroupModel(){const e=this.scope.tableModel.getAreaModel("header");return e&&typeof e.getToggleGroupStates=="function"?e:void 0}warns(e){return this.persistedParts().includes(e)}ownGetRowId(){var t;const e=(t=this.scope.tableOptions.autoRestoreOptions)==null?void 0:t.getRowId;return e&&!xn(e)?e:void 0}idAt(e,t){return this.idOfRow(this.body().getRowByIndex(e),e,t)}idOfRow(e,t,s){const o=this.ownGetRowId();if(e==null){if(o&&o.length>=2&&t>-1)return o(void 0,t);s&&!this.warnedNoRowObject&&(this.warnedNoRowObject=!0,console.warn("GuiExpert Table: the body model has no row objects – these rows are not stored. Set autoRestoreOptions.getRowId = (_row, rowIndex) => rowIndex to store them by index."));return}const i=U(e)?e.data:e;if(le(i))return i.id;if(o)return o(i,t);if(i&&typeof i=="object")for(const r of["id","uuid"]){const l=i[r];if(typeof l=="string"||typeof l=="number")return l}s&&!this.warnedNoId&&(this.warnedNoId=!0,console.warn("GuiExpert Table: rows without 'id' or 'uuid' are not stored – set autoRestoreOptions.getRowId."))}rowIndexMap(){const e=this.body(),t=new Map,s=e.getRowCount();for(let o=0;o<s;o++){const i=this.idAt(o,!1);i!==void 0&&!t.has(i)&&t.set(i,o)}return t}walkTree(e,t){const s=o=>o==null?void 0:o.forEach(i=>{t(i),s(i.children)});s(e.rows)}};Ie.STORAGE_SUFFIX="tableState",Ie.EXPENSIVE=["tree","checked","selection"];let Is=Ie;class An{constructor(e){this.tableScope=e,this.tableScope.hostElement.addEventListener("change",this.onHostElementChanged.bind(this),{signal:this.tableScope.listenerAbortController.signal}),this.tableScope.hostElement.addEventListener("keydown",this.onHostElementKeyDown.bind(this),{signal:this.tableScope.listenerAbortController.signal}),this.tableScope.hostElement.addEventListener("input",this.onHostElementInput.bind(this),{signal:this.tableScope.listenerAbortController.signal}),this.tableScope.hostElement.addEventListener("focusout",this.onHostElementFocusOut.bind(this),{signal:this.tableScope.listenerAbortController.signal})}onHostElementFocusOut(e){var s,o;const t=e.target;t instanceof HTMLInputElement&&t.isConnected&&t.getAttribute("data-ge-restored")==="true"&&((o=(s=this.tableScope).getInCellEditorCell)!=null&&o.call(s))&&this.commitInCellEditor(t)}commitInCellEditor(e){const t=Number(e.getAttribute("data-row-index")),s=Number(e.getAttribute("data-col-index"));this.tableScope.updateModelValueAfterEdit("body",t,s,e.value)}onHostElementInput(e){const t=e.target;if(!this.tableScope.isEditing()||!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)||t.getAttribute("data-area")!=="body")return;const s=Number(t.getAttribute("data-row-index")),o=Number(t.getAttribute("data-col-index"));this.tableScope.setEditorDraft(s,o,t)}onHostElementKeyDown(e){var o,i;if((i=(o=this.tableScope).isEventInDetail)!=null&&i.call(o,e)||!this.tableScope.isEditing())return;const t=e.target;if(e.key==="Enter"&&!e.isComposing&&e.keyCode!==229&&t instanceof HTMLInputElement&&t.getAttribute("data-area")==="body"&&t.getAttribute("data-ge-restored")==="true"){e.preventDefault(),this.commitInCellEditor(t);return}if(e.key!=="Escape")return;const s=e.target;(s instanceof HTMLInputElement||s instanceof HTMLSelectElement||s instanceof HTMLTextAreaElement)&&s.getAttribute("data-area")==="body"&&(e.preventDefault(),e.stopPropagation(),this.tableScope.cancelEditing(s))}onHostElementChanged(e){var t,s,o,i;if(!((s=(t=this.tableScope).isEventInDetail)!=null&&s.call(t,e))&&(e.target instanceof HTMLInputElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLTextAreaElement)){const r=e.target,l=r.getAttribute("data-area"),a=r.getAttribute("data-row-index"),c=r.getAttribute("data-col-index");if((r.classList.contains("ge-table-cell-editor-input")||r.classList.contains("ge-table-cell-editor-select"))&&!((i=(o=this.tableScope).getInCellEditorCell)!=null&&i.call(o)))return;if(l&&a&&c){const d=rs(l),u=Number(a),f=Number(c);this.tableScope.updateModelValueAfterEdit(d,u,f,r.value)}}}}class En{constructor(e,t,s,o,i,r,l,a){this.scrollTop=e,this.scrollLeft=t,this.scrollHeight=s,this.scrollWidth=o,this.clientHeight=i,this.clientWidth=r,this.scrollFactorY=l,this.scrollFactorX=a}}class fe{constructor(e){this.tableScope=e,this.ignoreNextClick=!1,this.anchorRanges=[],this.getSelectionModel=()=>this.tableScope.selectionModel(),this.getFocusModel=()=>this.tableScope.focusModel()}onMouseDown(){this.ignoreNextClick=!1,this.dragSnapshot=void 0}onMouseDragging(e,t){var o;if(!t||t.action||t.areaIdent!=="body"||e.areaIdent!=="body"||t.rowIndex<0||t.columnIndex<0||e.rowIndex<0||e.columnIndex<0)return!1;const s=(o=this.getSelectionModel)==null?void 0:o.call(this);return!s||!("selectionType"in s)||s.selectionType!=="range"?!1:(this.batch(()=>{var l,a,c;!!((l=t.originalEvent)!=null&&l.ctrlKey||(a=t.originalEvent)!=null&&a.metaKey)&&fe.hasSnapshots(s)?(this.dragSnapshot=this.dragSnapshot??s.createSnapshot(),s.restoreSnapshot(this.dragSnapshot)):s.clear(),s.addSelection(this.createRangeByEvents(e,t));const r=(c=this.getFocusModel)==null?void 0:c.call(this);r&&!r.hasFocus(t.rowIndex,t.columnIndex)&&r.setFocus(t.rowIndex,t.columnIndex),this.previousEvt=t.clone(),this.anchor=[t.rowIndex,t.columnIndex],this.extent=[e.rowIndex,e.columnIndex],this.anchorRanges=[],this.ignoreNextClick=e.rowIndex!==t.rowIndex||e.columnIndex!==t.columnIndex,this.tableScope.onSelectionChanged(s)}),!0)}onMouseClicked(e,t){if(this.ignoreNextClick)return this.ignoreNextClick=!1,!1;if(e.areaIdent==="header"&&e.clickCount===1&&this.isRowNumberColumn(e.columnIndex)&&e.rowIndex===this.tableScope.tableModel.getAreaModel("header").getRowCount()-1)return this.selectAllByRowNumberHeader();if(e.areaIdent==="header"&&e.clickCount===1&&e.columnIndex>-1&&this.isColumnLetterCell(e))return this.clickColumnLetter(e);if(e.areaIdent!=="body"||e.rowIndex<0||e.columnIndex<0||e.clickCount>1)return!1;let s=!1;if(this.getSelectionModel&&this.getFocusModel){const o=this.getSelectionModel(),i=this.getFocusModel();o&&i&&(this.batch(()=>{var d,u,f,g;i.hasFocus(e.rowIndex,e.columnIndex)||i.setFocus(e.rowIndex,e.columnIndex);const r=!!((d=e.originalEvent)!=null&&d.shiftKey),l=!!((u=e.originalEvent)!=null&&u.ctrlKey||(f=e.originalEvent)!=null&&f.metaKey),a=!!((g=e.originalEvent)!=null&&g.altKey),c=this.isRowNumberColumn(e.columnIndex)&&fe.isRangeSelection(o);if(r&&(this.anchor||this.previousEvt)){if(this.anchorRanges.length&&fe.hasSnapshots(o)){const y=o.createSnapshot();o.restoreSnapshot({...y,ranges:y.ranges.filter(C=>!this.anchorRanges.includes(C))})}const[p,m]=this.anchor??[this.previousEvt.rowIndex,this.previousEvt.columnIndex],b=fe.rangeBetween(e.rowIndex,e.columnIndex,p,m);this.extent=[e.rowIndex,e.columnIndex],c&&(b.c1=0,b.c2=Number.MAX_SAFE_INTEGER),o.addSelection(b),this.anchorRanges=[b],this.tableScope.onSelectionChanged(o);return}const h=o.getRanges().slice();c?this.clickRowNumber(o,e.rowIndex,e.columnIndex,r,l,a):l&&a?o.removeSelection(M.singleCell(e.rowIndex,e.columnIndex)):l?o.togglePoint(e.rowIndex,e.columnIndex):(!r&&o.hasSelection()&&o.clear(),o.firstClick(e.rowIndex,e.columnIndex)),this.anchorRanges=o.getRanges().filter(p=>!h.includes(p)),this.previousEvt=e.clone(),this.anchor=[e.rowIndex,e.columnIndex],this.letterAnchor=void 0,this.extent=void 0,this.tableScope.onSelectionChanged(o)}),s=!0)}return s}onActionTriggered(e){var t,s;if(this.getSelectionModel&&this.getFocusModel){const o=this.getSelectionModel(),i=this.getFocusModel();if(o&&i){if(e==="SELECT_ALL")return o.selectAll(),this.tableScope.repaint(),this.announce(r=>r.allSelected()),!0;if(e==="DESELECT_ALL")return o.clear(),this.tableScope.repaint(),this.announce(r=>r.selectionCleared()),!0;if(e==="TOGGLE_SELECTION"&&((s=(t=this.tableScope).getHeaderFocus)!=null&&s.call(t)))return!1;if(e==="TOGGLE_SELECTION"){const[r,l]=i.getFocus();return this.isRowNumberColumn(l)&&fe.isRangeSelection(o)?(this.clickRowNumber(o,r,l,!1,!0,!1),this.tableScope.onSelectionChanged(o),this.tableScope.repaint(),!0):(o.togglePoint(r,l),this.tableScope.repaint(),!0)}}}return!1}getAnchor(){return this.anchor?[this.anchor[0],this.anchor[1]]:void 0}getExtent(){var r;const e=(r=this.getFocusModel)==null?void 0:r.call(this),[t,s]=e?e.getFocus():[-1,-1],o=this.extent??this.anchor,i=this.anchor;return t>=0&&s>=0&&!(i&&i[0]===t&&i[1]===s)&&!(o&&o[0]===t&&o[1]===s)?[t,s]:o?[o[0],o[1]]:void 0}collapseTo(e,t){var i;const s=(i=this.getSelectionModel)==null?void 0:i.call(this);this.anchor=[e,t],this.extent=void 0,this.anchorRanges=[];const o=s==null?void 0:s.selectionType;!s||o!=="range"&&o!=="cell"||this.batch(()=>{const r=s.getRanges();r.length===1&&r[0].r1===e&&r[0].r2===e&&r[0].c1===t&&r[0].c2===t&&!s.isAllSelected()||(s.clear(),s.addSelection(M.singleCell(e,t)),this.tableScope.onSelectionChanged(s)),this.anchorRanges=s.getRanges().slice()})}extendTo(e,t){var h,d;const s=(h=this.getSelectionModel)==null?void 0:h.call(this);if(!s||!fe.isRangeSelection(s))return;const o=(d=this.getFocusModel)==null?void 0:d.call(this),[i,r]=o?o.getFocus():[-1,-1],l=this.extent??this.anchor,a=this.anchor&&this.anchor[0]===i&&this.anchor[1]===r||l&&l[0]===i&&l[1]===r;if((!this.anchor||!a)&&i>=0&&r>=0&&(this.anchor=[i,r],this.extent=void 0,this.anchorRanges=[]),!this.anchor)return;const c=fe.rangeBetween(e,t,this.anchor[0],this.anchor[1]);return this.batch(()=>{if(fe.hasSnapshots(s)){const u=s.createSnapshot();s.restoreSnapshot({...u,ranges:u.ranges.filter(f=>!this.anchorRanges.includes(f))})}else s.clear();s.addSelection(c),this.anchorRanges=[c],this.extent=[e,t],this.tableScope.onSelectionChanged(s)}),c}static rangeBetween(e,t,s,o){return new M(Math.min(e,s),Math.min(t,o),Math.max(e,s),Math.max(t,o))}isRowNumberColumn(e){var t;return e>-1&&O((t=this.tableScope.tableModel)==null?void 0:t.getColumnDef(e))}isColumnLetterCell(e){var s;const t=this.tableScope.tableModel.getAreaModel("header");return!!((s=t.isColumnLetterRow)!=null&&s.call(t,e.rowIndex))&&!this.isRowNumberColumn(e.columnIndex)&&!me(this.tableScope.tableModel.getColumnDef(e.columnIndex))}clickColumnLetter(e){var l,a,c,h,d;const t=(l=this.getSelectionModel)==null?void 0:l.call(this),s=(a=this.getFocusModel)==null?void 0:a.call(this);if(!t||!fe.isRangeSelection(t))return!1;const o=e.columnIndex,i=!!((c=e.originalEvent)!=null&&c.shiftKey),r=!!((h=e.originalEvent)!=null&&h.ctrlKey||(d=e.originalEvent)!=null&&d.metaKey);return this.batch(()=>{const u=i?this.letterAnchor??(s==null?void 0:s.getFocus()[1])??o:o,f=new M(0,Math.min(u,o),Number.MAX_SAFE_INTEGER,Math.max(u,o));if(!r&&t.hasSelection()&&t.clear(),t.addSelection(f),i||(this.letterAnchor=o),s){const g=Math.max(0,s.getFocus()[0]);s.setFocus(g,o)}this.anchor=[0,o],this.extent=void 0,this.tableScope.onSelectionChanged(t)}),!0}selectAllByRowNumberHeader(){var s;const e=(s=this.getSelectionModel)==null?void 0:s.call(this),t=e==null?void 0:e.selectionType;return!e||t!=="row"&&t!=="range"?!1:(this.batch(()=>{e.selectAll(),this.tableScope.onSelectionChanged(e)}),this.announce(o=>o.allSelected()),!0)}clickRowNumber(e,t,s,o,i,r){const l=new M(t,0,t,Number.MAX_SAFE_INTEGER);i&&r?e.removeSelection(l):i?e.isSelected(t,s)?e.removeSelection(l):e.addSelection(l):(!o&&e.hasSelection()&&e.clear(),e.addSelection(l))}static isRangeSelection(e){return e.selectionType==="range"}announce(e){var s;const t=(s=this.getSelectionModel)==null?void 0:s.call(this);(t==null?void 0:t.selectionType)!=="none"&&this.tableScope.ariaTexts&&typeof this.tableScope.announce=="function"&&this.tableScope.announce(e(this.tableScope.ariaTexts))}batch(e){typeof this.tableScope.holdSelectionEvents=="function"?this.tableScope.holdSelectionEvents(e):e()}static hasSnapshots(e){return typeof e.createSnapshot=="function"&&typeof e.restoreSnapshot=="function"}createRangeByEvents(e,t){t||(t=e);const s=Math.min(e.rowIndex,t==null?void 0:t.rowIndex),o=Math.max(e.rowIndex,t==null?void 0:t.rowIndex),i=Math.min(e.columnIndex,t==null?void 0:t.columnIndex),r=Math.max(e.columnIndex,t==null?void 0:t.columnIndex);return M.create({rowIndex1:s,columnIndex1:i,rowIndex2:o,columnIndex2:r})}}class Mn{get(){return{f2:"START_EDITING",space:"TOGGLE_SELECTION","ctrl+num_add":"SELECT_ALL","ctrl+a":"SELECT_ALL","ctrl+shift+a":"DESELECT_ALL","ctrl+x":"DESELECT_ALL","ctrl+num_subtract":"DESELECT_ALL","meta -":"DESELECT_ALL",arrowup:"NAVIGATE_UP",arrowdown:"NAVIGATE_DOWN",arrowleft:"NAVIGATE_LEFT",arrowright:"NAVIGATE_RIGHT",home:"NAVIGATE_ROW_START",end:"NAVIGATE_ROW_END","ctrl+home":"NAVIGATE_FIRST_CELL","ctrl+end":"NAVIGATE_LAST_CELL",pageup:"NAVIGATE_PAGE_UP",pagedown:"NAVIGATE_PAGE_DOWN",enter:"ACTIVATE_CELL","ctrl+alt+up":"MOVE_ROW_UP","ctrl+alt+down":"MOVE_ROW_DOWN","ctrl+d":"FILL_DOWN","ctrl+r":"FILL_RIGHT","meta+c":"COPY_2_CLIPBOARD","ctrl+c":"COPY_2_CLIPBOARD"}}}class Tn{get(){return{f2:"START_EDITING",space:"TOGGLE_SELECTION","ctrl+num_add":"SELECT_ALL","meta+a":"SELECT_ALL","ctrl+a":"SELECT_ALL","meta+x":"DESELECT_ALL","meta+shift+a":"DESELECT_ALL","ctrl+shift+a":"DESELECT_ALL","ctrl+num_subtract":"DESELECT_ALL","ctrl -":"DESELECT_ALL",arrowup:"NAVIGATE_UP",arrowdown:"NAVIGATE_DOWN",arrowleft:"NAVIGATE_LEFT",arrowright:"NAVIGATE_RIGHT",home:"NAVIGATE_ROW_START",end:"NAVIGATE_ROW_END","meta+left":"NAVIGATE_ROW_START","meta+right":"NAVIGATE_ROW_END","ctrl+home":"NAVIGATE_FIRST_CELL","ctrl+end":"NAVIGATE_LAST_CELL","meta+up":"NAVIGATE_FIRST_CELL","meta+down":"NAVIGATE_LAST_CELL",pageup:"NAVIGATE_PAGE_UP",pagedown:"NAVIGATE_PAGE_DOWN",enter:"ACTIVATE_CELL","ctrl+alt+up":"MOVE_ROW_UP","ctrl+alt+down":"MOVE_ROW_DOWN","meta+d":"FILL_DOWN","meta+r":"FILL_RIGHT","meta+c":"COPY_2_CLIPBOARD","ctrl+c":"COPY_2_CLIPBOARD"}}}const Ac={arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right"};function Ut(n){return n.trim().replace(/\+/g," ").replace(/ +/g," ").replace(/⌫/g,"backspace").replace(/↩/g,"enter").replace(/⇧/g,"shift").replace(/⌥/g,"alt").replace(/option/g,"alt").replace(/opt/g,"alt").replace(/⌃/g,"ctrl").replace(/control/g,"ctrl").replace(/command/g,"cmd").replace(/meta/g,"cmd").replace(/escape/g,"esc").replace(/⌘/g,"cmd").replace(/\*/g,"multiply").split(" ").filter(e=>e).map(e=>Ac[e]??e).filter((e,t,s)=>s.indexOf(e)===t).sort((e,t)=>{const s={cmd:1,ctrl:2,alt:3,shift:4},o=s[e]||5,i=s[t]||5;return o!==i?o-i:e.localeCompare(t)}).join(" ")}function In(n){let e=n.key.toLowerCase();if(e===" "&&(e="space"),e==="arrowleft"&&(e="left"),e==="arrowright"&&(e="right"),e==="arrowup"&&(e="up"),e==="arrowdown"&&(e="down"),e==="delete"&&n.code==="Delete"&&(e="delete"),e==="backspace"&&(e="backspace"),e==="escape"&&(e="esc"),e==="return"&&(e="enter"),n.code.startsWith("Numpad")){const s=n.code.replace("Numpad","").toLowerCase();s==="add"?e="num_add":s==="subtract"?e="num_subtract":s==="multiply"?e="num_multiply":s==="divide"?e="num_divide":s==="decimal"?e="num_decimal":s==="enter"?e="num_enter":e="num_"+s}n.code.match(/^F\d+$/)&&(e=n.code.toLowerCase()),n.code.match(/^Digit\d+$/)&&(e=n.code.replace(/Digit/g,""));let t="";return n.ctrlKey&&(t+=" ctrl"),n.altKey&&(t+=t+" alt"),n.shiftKey&&(t+=t+" shift"),n.metaKey&&(t+=t+" cmd"),Ut(t+" "+e)}class Dn{constructor(e){this.tableScope=e,this.shortcutActionIdMapping={},this.listener=[],this.listener.push(e),this.init()}addListener(e){this.listener.includes(e)||this.listener.push(e)}init(){var e,t,s,o;if((t=(e=this.tableScope)==null?void 0:e.tableOptions)!=null&&t.shortcutActionsDisabled)this.isDebug()&&console.debug("ShortcutService skipped.");else{this.assignPredefinedSystemShortcutMappings();for(const i of((o=(s=this.tableScope).getShortcutLayers)==null?void 0:o.call(s,this.isMacintosh()))??[])this.assignMapping(i);this.assignMapping(this.tableScope.tableOptions.shortcutActionIdMapping),this.isDebug()&&console.debug("ShortcutService",this.shortcutActionIdMapping),this.tableScope.hostElement.addEventListener("keydown",this.onKeyDown.bind(this),{signal:this.tableScope.listenerAbortController.signal})}}assignPredefinedSystemShortcutMappings(){this.isMacintosh()?this.assignMapping(new Tn().get()):this.assignMapping(new Mn().get())}assignMapping(e){if(e)for(const t of Object.keys(e)){const s=Ut(t);for(const o of Object.keys(this.shortcutActionIdMapping))o!==t&&Ut(o)===s&&delete this.shortcutActionIdMapping[o];this.shortcutActionIdMapping[t]=e[t]}}isMacintosh(){return navigator.platform.indexOf("Mac")>-1}isDebug(){return this.isLocalhost()}isLocalhost(){return location.hostname==="localhost"||location.hostname==="127.0.0.1"}onKeyDown(e){var o,i;if((i=(o=this.tableScope).isEventInDetail)!=null&&i.call(o,e))return;const t=e.target;if(t&&(t.isContentEditable||["INPUT","SELECT","TEXTAREA","BUTTON","A"].includes(t.tagName)))return;const s=this.findEntity(e);if(s){this.tableScope.shortcutKeyEvent=e;let r;try{r=this.emit(s)}finally{this.tableScope.shortcutKeyEvent=void 0}r&&(e.preventDefault(),e.stopPropagation())}}emit(e){this.isDebug()&&console.debug("ShortcutService emit :",e);let t=!1;for(const s of this.listener)s.onActionTriggered(e)&&(t=!0);return t}findEntity(e){var s,o;let t=In(e);(o=(s=this.tableScope).isRtl)!=null&&o.call(s)&&(t=Hr(t)),this.isDebug()&&console.debug("ShortcutService shortcut :",t);for(const i in this.shortcutActionIdMapping)if(Ut(i)===t)return this.isDebug()&&console.debug("ShortcutService action :",this.shortcutActionIdMapping[i]),this.shortcutActionIdMapping[i]}getShortcutActionMapping(){return this.shortcutActionIdMapping}}class Kt{onCheckboxChanged(e){}onContextmenu(e){}onModelChanged(e){}onMouseClicked(e){}onMouseDragging(e){}onMouseDraggingEnd(e){}onMouseMoved(e){}onScroll(e){}onSelectionChanged(e){}onFocusChanged(e){}onStateChanged(e){}onRowDragStart(e){}onRowDragMove(e){}onRowDragEnd(e){}onBatchEditChanged(e){}onDetailExpandedChanged(e){}onEditingChanged(e){}onUndoStackChanged(e){}}class Vo{setStyle(e,t,s){return e.style[t]=s,e}appendText(e,t){const s=this.createText(t);return this.appendChild(e,s),s}addClass(e,t){return t.includes(" ")?t.split(" ").forEach(s=>e.classList.add(s)):e.classList.add(t),e}removeClass(e,t){return t.includes(" ")?t.split(" ").forEach(s=>e.classList.remove(s)):e.classList.remove(t),e}appendChild(e,t){e.appendChild(t)}createElement(e){return document.createElement(e)}createText(e){return document.createTextNode(e)}setAttribute(e,t,s){e.setAttribute(t,s)}removeAttribute(e,t){e.removeAttribute(t)}}const Ec=null;function Et(n){return n==null||n===""}const Zi=new Intl.Collator("en",{numeric:!0});function Qi(n){return typeof n=="number"||typeof n=="bigint"?0:n instanceof Date?1:typeof n=="boolean"?2:typeof n=="string"?3:4}function er(n,e){const t=Qi(n),s=Qi(e);if(t!==s)return t-s;switch(t){case 0:{const o=n,i=e,r=typeof o=="number"&&Number.isNaN(o),l=typeof i=="number"&&Number.isNaN(i);return r||l?r===l?0:r?1:-1:o<i?-1:o>i?1:0}case 1:{const o=n.getTime(),i=e.getTime();return(Number.isNaN(o)?1/0:o)-(Number.isNaN(i)?1/0:i)||0}case 2:return(n?1:0)-(e?1:0);case 3:return Zi.compare(n,e);default:return Zi.compare(String(n),String(e))}}function fs(n){return(e,t)=>{const s=Et(e),o=Et(t);return s||o?s===o?0:s?1:-1:n(e,t)}}function Mc(n,e){const t=typeof n=="string"||typeof n=="function"?{value:n}:n;if(!t||typeof t.value!="string"&&typeof t.value!="function")throw new Error(`Row grouping: level ${e} has no value (a property path or a function).`);const s=typeof t.value=="string"?t.value:void 0,o=t.order??"asc";let i;return o==="asc"?i=fs(er):o==="desc"?i=fs((r,l)=>er(l,r)):typeof o=="function"?i=fs(o):i=fs(()=>0),{name:t.name??s??`level${e}`,label:t.label,path:s,getKey:ns(t.value),format:t.format,compare:i}}function Ve(n){return(n??[]).map((e,t)=>Mc(e,t))}const tr=new WeakMap;let Tc=1;function st(n){if(Et(n))return"empty";switch(typeof n){case"string":return"s:"+n;case"number":return"n:"+String(n);case"boolean":return"b:"+n;case"bigint":return"i:"+String(n);case"symbol":return"y:"+(n.description??"");case"function":case"object":{if(n instanceof Date)return"d:"+n.getTime();let e=tr.get(n);return e===void 0&&(e=Tc++,tr.set(n,e)),"o:"+e}default:return"u:"+String(n)}}function Ic(n,e){return Et(n)?e:n instanceof Date?Number.isNaN(n.getTime())?"Invalid Date":n.toLocaleDateString("en-US"):String(n)}function kn(n,e){return n.map(t=>t.label??(t.path!==void 0?e(t.path):void 0)??t.name)}function Fn(n,e){const t=kn(Ve(n),s=>{var o;return(o=e.find(i=>i.property===s&&!ot(i)))==null?void 0:o.headerLabel});return t.length?t.join(" › "):"Group"}function _o(n){var a,c;const e=n.getBodyModel();if(!ne(e))return!1;const t=n.getColumnDefs()??[],s=e.getGroupBy(),o=e.options.hideGroupedColumns===!1?[]:Ve(s).map(h=>h.path).filter(h=>h!==void 0&&t.some(d=>d.property===h&&!ot(d))),i=e.hiddenColumnProperties.filter(h=>o.includes(h));for(const h of e.hiddenColumnProperties)o.includes(h)||(a=n.setColumnVisible)==null||a.call(n,h,!0);for(const h of o)i.includes(h)||!Dc(t,h)||((c=n.setColumnVisible)==null||c.call(n,h,!1),i.push(h));e.hiddenColumnProperties=i;const r=t.findIndex(ot),l=t[r];if(l&&ot(l)&&l.autoHeaderLabel){const h=Fn(s,t);l.headerLabel=h;const d=n.getAreaModel("header"),u=d.getRowCount()-1;u>=0&&d.getValueAt(u,r)!==h&&d.setValue(u,r,h)}return!0}function Dc(n,e){var t,s;return((s=(t=n.find(o=>o.property===e))==null?void 0:t.isVisible)==null?void 0:s.call(t))!==!1}const De=class De{createContent(e,t,s){return new Promise((o,i)=>{var r;if(t!=null&&t.hasSelection()){const l=t.isAllSelected()?new M(0,0,Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER):this.mergeRanges(t.getRanges());if(l){l.c2=Math.min(l.c2,e.getColumnCount()-1),l.r2=Math.min(l.r2,e.getBodyModel().getRowCount()-1);const a=Math.max(0,l.r2-l.r1+1)*Math.max(0,l.c2-l.c1+1);if(a>De.maxCopyCells)return i(`Cannot copy ${a} cells – more than CopyService.maxCopyCells (${De.maxCopyCells}).`);const c=[];for(let h=l.r1;h<=l.r2;h++){const d=[];for(let u=l.c1;u<=l.c2;u++){const f=e.getColumnDef(u);if(((r=f==null?void 0:f.isVisible)==null?void 0:r.call(f))===!1)continue;const g=O(f)?f:void 0;if(g&&!g.options.exported)continue;const p=t.isSelected(h,u),m=e.getBodyModel(),b=p?g?g.getRowNumberText(h,m):m.getTextValueAt(h,u):"";d.push(b)}c.push(d.join(De.columnSeparatorChar))}return o(c.join(De.rowSeparatorChar))}}if(s){const[l,a]=s.getFocus(),c=e.getColumnDef(a),h=O(c)?c.getRowNumberText(l,e.getBodyModel()):e.getBodyModel().getTextValueAt(l,a);return o(h)}i("Cannot copy, neither selection nor focus defined.")})}copyContent(e){return navigator.clipboard.writeText(e)}copyToClipboard(e,t,s){return new Promise((o,i)=>{this.createContent(e,t,s).then(r=>{r?this.copyContent(r).then(l=>{o(r)}).catch(l=>{i()}):o("")}).catch(r=>{i()})})}mergeRanges(e){let t;for(const s of e)t?(t.r1=Math.min(t.r1,s.r1),t.c1=Math.min(t.c1,s.c1),t.r2=Math.max(t.r2,s.r2),t.c2=Math.max(t.c2,s.c2)):t=new M(s.r1,s.c1,s.r2,s.c2);return t}};De.maxCopyCells=1e6,De.columnSeparatorChar=" ",De.rowSeparatorChar=`
|
|
48
|
-
`;let Se=De;class
|
|
47
|
+
render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),this.pruneRowDivCache(s),this.pruneRowDivCache(o),this.pruneRowDivCache(i),this.colAndRowspanModels&&this.colAndRowspanModels[e]){const v=((F=this.colAndRowspanModels[e])==null?void 0:F.getRanges())??[];if(v.length)for(const D of v){if(D.r1>=d||D.c1>=f)continue;let k=0,N=o.child,V="center";if(D.c1<p)N=s.child,V="west";else if(g>0&&D.c1>=f-g)N=i.child,V="east";else{const $=this.areaBodyCenterGeo.width-this.tableModel.getContentWidthInPixel();k=this.snapToDevicePixel(this.scrollFactorX*$)-this.areaBodyWestGeo.width,V="center"}this.drawBigCell(D,k,t,h,N,V)}}this.updateRowGroupRoles(s,o,i)}getAriaGridInfo(){return this.ariaGridInfo||(this.ariaGridInfo=ts.create(this.tableModel)),this.ariaGridInfo}applyRowAria(e,t,s,o,i=!0){var l,a;const r=this.dom.domService;if(r.setAttribute(e,"role","row"),r.setAttribute(e,"aria-rowindex",`${this.getAriaGridInfo().rowIndex(t,o)}`),!(t!=="body"||!i)){if(this.tree&&Z(s)){const c=this.treeAriaInfo.get(s,o);c&&(r.setAttribute(e,"aria-level",`${c.level}`),r.setAttribute(e,"aria-setsize",`${c.setSize}`),r.setAttribute(e,"aria-posinset",`${c.posInSet}`),c.expanded===void 0?this.dom.removeAttribute(e,"aria-expanded"):r.setAttribute(e,"aria-expanded",`${c.expanded}`))}if((l=this.masterDetailService)!=null&&l.isActive()&&(this.masterDetailService.isMasterAt(o)?r.setAttribute(e,"aria-expanded",`${this.masterDetailService.isExpandedAt(o)}`):e.hasAttribute("aria-expanded")&&this.dom.removeAttribute(e,"aria-expanded")),this.ariaSelectionKind==="row"){const c=(a=this.getSelectionModel)==null?void 0:a.call(this);r.setAttribute(e,"aria-selected",c&&c.getSelectionCount(o,0)>0?"true":"false")}else e.hasAttribute("aria-selected")&&this.dom.removeAttribute(e,"aria-selected")}}applyCellAria(e,t,s,o,i){var f,g;const r=this.dom.domService,l=this.getAriaGridInfo(),a=t==="header",c=t==="body"&&O(this.tableModel.getColumnDef(i))||t==="footer"&&Pr(s)&&s.isLabelCell(o,i)||t==="body"&&ne(s)&&s.isGroupLabelCell(o,i)||!a&&!!((f=s.isRowHeaderCell)!=null&&f.call(s,o,i));r.setAttribute(e,"role",a?"columnheader":c?"rowheader":"gridcell");const h=l.colIndex(i);h>0&&r.setAttribute(e,"aria-colindex",`${h}`);const d=Math.max(1,s.getRowspanAt(o,i)||1),u=Math.max(1,s.getColspanAt(o,i)||1);if(u>1&&r.setAttribute(e,"aria-colspan",`${l.colSpan(i,u)}`),d>1&&r.setAttribute(e,"aria-rowspan",`${d}`),(d>1||u>1)&&this.renderedSpanCells.add(`${t}:${o}:${i}`),a&&o+d>=l.headerRowCount&&u===1){const p=this.tableModel.getColumnDef(i);if((g=p==null?void 0:p.sortable)!=null&&g.call(p)){const m=p.sortState;r.setAttribute(e,"aria-sort",m==="asc"?"ascending":m==="desc"?"descending":"none")}}return[d,u]}updateRowGroupRoles(...e){for(const t of e){let s=0;for(const i of Array.from(t.child.children)){if(!i.classList.contains("ge-table-row-div")||i.classList.contains("ge-table-span-row")){i.getAttribute("role")==="row"&&s++;continue}i.querySelector(':scope > [role="gridcell"], :scope > [role="columnheader"], :scope > [role="rowheader"]')?s++:i.getAttribute("role")==="row"&&(this.dom.domService.setAttribute(i,"role","presentation"),this.dom.removeAttribute(i,"aria-rowindex"))}const o=t.child.firstElementChild&&s?"rowgroup":"presentation";t.child.getAttribute("role")!==o&&this.dom.domService.setAttribute(t.child,"role",o)}}setHostAttribute(e,t){this.setHostAriaAttribute(e,t)}updateHostAria(){var i;const e=this.getAriaGridInfo();this.setHostAttribute("aria-rowcount",`${e.rowCount}`),this.setHostAttribute("aria-colcount",`${e.colCount}`);const t=(i=this.getSelectionModel)==null?void 0:i.call(this),s=this.ariaSelectionKind!=="none"&&(t==null?void 0:t.selectionMode)==="multi";this.setHostAttribute("aria-multiselectable",s?"true":void 0);const o=this.ariaFocusedCell;if(o){const r=this.ariaIds.cell(o.area,o.rowIndex,o.columnIndex);this.dom.domService.setAttribute(o.element,"id",r),this.setHostAttribute("aria-activedescendant",r)}else this.setHostAttribute("aria-activedescendant",void 0)}setAriaFocusedCell(e,t,s,o){const i=this.ariaFocusedCell;i&&i.area===t&&i.rowIndex===s&&i.columnIndex===o||(this.ariaFocusedCell={element:e,area:t,rowIndex:s,columnIndex:o})}getAriaSelectionKind(){var s;const e=(s=this.getSelectionModel)==null?void 0:s.call(this);if(!e)return"none";const t=e.selectionType;return t==="none"?"none":t==="row"?"row":"cell"}getColumnAriaLabel(e){const t=this.tableModel.getColumnDef(e);if(t!=null&&t.headerLabel)return`${t.headerLabel}`;const s=this.tableModel.getAreaModel("header"),o=(s==null?void 0:s.getRowCount())??0;if(o>0){const i=s.getValueAt(o-1,e),r=i&&typeof i=="object"&&"data"in i?i.data:i;if(typeof r=="string"&&r.trim()||typeof r=="number")return`${r}`}return(t==null?void 0:t.property)||`Column ${e+1}`}getCheckboxAriaLabel(e,t){return e==="header"?this.ariaTexts.selectAllRows():this.ariaTexts.selectRow(t+1)}labelControl(e,t){t&&!e.hasAttribute("aria-label")&&!e.hasAttribute("aria-labelledby")&&this.dom.domService.setAttribute(e,"aria-label",t)}labelRendererControls(e,t,s,o,i){if(ii(t)||e.classList.contains("ge-table-row-checkbox-div")){const l=e.querySelector("input.ge-table-row-checkbox");if(l){this.labelControl(l,this.getCheckboxAriaLabel(s,o));return}const a=e.querySelector("input.ge-input-checkbox");a&&this.labelControl(a,this.getColumnAriaLabel(i));return}const r=this.tableOptions.ariaTexts;if(s==="header"&&(r!=null&&r.expandGroup||r!=null&&r.collapseGroup)){const l=e.querySelector('.ge-table-toggle-icon-div[role="button"]');if(l){const a=l.getAttribute("data-ge-group-label")??"",c=l.getAttribute("aria-expanded")==="true";this.dom.domService.setAttribute(l,"aria-label",c?this.ariaTexts.collapseGroup(a):this.ariaTexts.expandGroup(a))}}}findCellDiv(e,t){for(const s of e){const o=s.querySelector(`:scope > .ge-table-col-div[data-col-index="${t}"]`);if(o)return o}}pruneRowDivCache(e){const t=e.cache;for(const s in t)t[s].parentNode!==e.child&&delete t[s]}drawBigCell(e,t,s,o,i,r){const l=s+(o.areaIdent==="body"?this.getBodyRowLayout().getTop(e.r1):this.getRowHeights(0,e.r1-1,o).reduce((y,C)=>y+C,0)),a=this.tableModel.getColumnCount(),c=this.tableModel.getFixedRightColumnCount();let h=0;c>0&&e.c1>=a-c&&(h=a-c);const d=t+this.getColumnWidths(h,e.c1-1).reduce((y,C)=>y+C,0),u=this.getRowHeights(e.r1,e.r2,o).reduce((y,C)=>y+C,0),f=this.getColumnWidths(e.c1,e.c2).reduce((y,C)=>y+C,0);let g=!1;const p=this.getSelectionModel?this.getSelectionModel():void 0;p&&(g=p.getSelectionCount(e.r1,e.c1)>0);const m=o.areaIdent,b=this.dom.applyStyle(this.dom.createDivWithClass("ge-table-span-row",i),{position:"absolute",left:"0",top:"0",width:"0",height:"0",overflow:"visible"});this.renderedSpanCells.has(`${m}:${e.r1}:${e.c1}`)?this.dom.setAriaHidden(b):this.applyRowAria(b,m,o,e.r1,!1),i=b,e.gammaRange?this.renderCell({areaModel:o,areaIdent:o.areaIdent,sideIdent:r,rowIndex:e.r1,columnIndex:e.c1,left:d,top:l,width:f,height:u,parent:i,cellSelected:g,lastRowOfModel:!0,gammaRange:e.gammaRange}):this.renderCell({areaModel:o,areaIdent:o.areaIdent,sideIdent:r,rowIndex:e.r1,columnIndex:e.c1,left:d,top:l,width:f,height:u,parent:i,cellSelected:g,lastRowOfModel:!0,gammaRange:e.gammaRange}),o.areaIdent==="header"&&this.tableOptions.columnsResizable&&this.isColumnResizable(e.c1)&&this.renderHeaderCellResizeHandle({rowIndex:e.r1,columnIndex:e.c1,cellLeft:d,cellTop:l,cellWidth:f,cellHeight:u,parent:i})}findRowOfImportantRowspanCell(e,t,s){const o=e.getMaxRowspan();for(let i=t-1;i>-1;i--){const r=e.getRowspanAt(i,s);if(r>1&&i+r+1>=t)return i;if(t-i>o)return-1}return-1}adjustColumnsToRowParent({areaIdent:e,sideIdent:t,areaModel:s,geo:o,parent:i,rowIndex:r,columnIndexStart:l,columnIndexEnd:a,verticalFixed:c=!1,lastRowOfModel:h=!1}){var p;let d=0;if(!c){const m=this.areaBodyCenterGeo.width-this.tableModel.getContentWidthInPixel();d=this.snapToDevicePixel(this.scrollFactorX*m)}const u=0,f=!!(e==="body"&&t);let g=d;for(let m=l;m<=a;m++){const b=g,y=this.tableModel.getColumnWidth(m);if(y>0&&b+y>0){let C=o.height;const S=s.getRowspanAt(r,m),E=s.getColspanAt(r,m);S>1&&(C=this.getRowHeights(r,r+S-1,s).reduce((F,v)=>F+v,0));let x=y;E>1&&(x=this.getColumnWidths(m,m+E-1).reduce((F,v)=>F+v,0));let R=!1;if(this.colAndRowspanModels&&this.colAndRowspanModels[e]&&(p=this.colAndRowspanModels[e])!=null&&p.isInRange(r,m)&&(R=!0),this.draggingTargetColumnIndex===m&&e!=="header"){this.renderDragTargetDiv(i,b,u,x,C);const F={left:b,top:u,width:x,height:C};this.dom.addColumnBorderDivs(this.tableOptions,i,F,e,t)}else{const F=this.renderSelectedBackgroundDiv(R,f,t,s,r,m,i,b,u,x,C);"gammaCells"in s&&s.getValueAt(r,m)&&(R=!1),R||this.renderCell({areaModel:s,areaIdent:e,sideIdent:t,rowIndex:r,columnIndex:m,left:b,top:u,width:x,height:C,parent:i,cellSelected:F,lastRowOfModel:h,gammaRange:!0}),e==="header"&&this.tableOptions.columnsResizable&&this.isColumnResizable(m)&&this.renderHeaderCellResizeHandle({rowIndex:r,columnIndex:m,cellLeft:b,cellTop:u,cellWidth:x,cellHeight:C,parent:i})}}if(g=g+y,g>this.areaBodyCenterGeo.width)break}this.tableOptions.verticalBorderVisible&&this.dom.addVerticalBorder(new Ae(g-1,1,o.height,0),i)}getTreeArrowColumnIndex(){const e=this.getFirstDataColumnIndex();return this.tableOptions.showCheckboxWihoutExtraColumn?e:this.tableModel.isRowCheckboxVisible()?e+1:e}getFirstDataColumnIndex(){var e,t;return Zt((t=(e=this.tableModel).getColumnDefs)==null?void 0:t.call(e))}isColumnResizable(e){return!O(this.tableModel.getColumnDef(e))}adjustRowNumberColumnWidth(){var i,r;if(!this.getFirstDataColumnIndex()||this.tableModel.overridingColumnWidth>-1)return!1;const e=this.tableModel.getColumnDef(0),t=e.getWidestText(this.tableModel.getBodyModel()),s=this.rowNumberWidth;let o=(s==null?void 0:s.text)===t?s.width:-1;if(o<0||s!=null&&s.approximate&&this.findRowNumberLabel()){const[l,a]=this.measureRowNumberText(t);o=Math.max(e.options.minWidthInPx,l),this.rowNumberWidth={text:t,width:o,approximate:a}}return this.tableModel.getColumnWidth(0)===o||((r=(i=this.tableModel).isColumnVisible)==null?void 0:r.call(i,0))===!1?!1:(this.tableModel.setColumnWidth(0,o),this.tableModel.getColumnWidth(0)===o)}findRowNumberLabel(){return this.hostElement.querySelector(".ge-table-row-number .ge-table-label")}measureRowNumberText(e){const t=this.findRowNumberLabel(),s=getComputedStyle(t??this.hostElement),i=(t?(parseFloat(s.paddingLeft)||0)+(parseFloat(s.paddingRight)||0):12)+4,r=e.replace(/[0-9]/g,"0");let l=null;try{l=document.createElement("canvas").getContext("2d")}catch{l=null}return l?(l.font=s.font||`${s.fontWeight} ${s.fontSize} ${s.fontFamily}`,[Math.ceil(l.measureText(r).width+i),!t]):[Math.ceil(e.length*8+i),!t]}addAndRenderCellDiv({areaModel:e,areaIdent:t,sideIdent:s,rowIndex:o,index:i,left:r,width:l,height:a,top:c,parent:h,lastRowOfModel:d}){var P,ue,te;const u=t==="body"&&this.editorRenderer&&this.editorRendererRow===o&&this.editorRendererColumn===i,f=this.tableModel.getColumnDef(i),g=O(f),p=u?this.editorRenderer:(g&&t==="body"?f.rendererMap.body:void 0)??e.getCellRenderer(o,i),m={left:r,width:l,height:a,top:c,index:i},b=e.getRowByIndex(o);let y="none";if(i===this.getTreeArrowColumnIndex()&&U(b)){const L=b;("hasDisplayedChildren"in e&&typeof e.hasDisplayedChildren=="function"?e.hasDisplayedChildren(L):!!((P=L.children)!=null&&P.length))?L.expanded?y="expanded":y="collapsed":y="hidden"}let S;t==="header"&&(!(f!=null&&f.sortIconVisible)||f!=null&&f.sortIconVisible())&&(S=f==null?void 0:f.sortState);const E=t==="body"&&((ue=this.batchEditService)!=null&&ue.hasPending())?this.batchEditService.getPendingAt(o,i):void 0,x=E?E.newValue:e.getValueAt(o,i),R=p||g&&t==="footer"?"":`${x??""}`,F=e.isRowChecked(o),v=this.getFirstDataColumnIndex(),D=this.tableOptions.showCheckboxWihoutExtraColumn&&i===v&&F?this.getCheckboxAriaLabel(t,o):void 0,k=this.dom.addColumnDiv({parent:h,geo:m,rowIndex:o,columnIndex:i,areaIdent:t,sideIdent:s,text:R,treeArrow:y,tableOptions:this.tableOptions,checkedType:F,sortState:S,checkboxAriaLabel:D,firstDataColumnIndex:v}),[N,V]=this.applyCellAria(k,t,e,o,i),$=(E==null?void 0:E.error)||e.getTooltipAt(o,i);$&&this.dom.setAttribute(k,"title",$),E&&(this.dom.addClass("ge-table-cell-pending",k),E.error&&(this.dom.addClass("ge-table-cell-invalid",k),this.dom.setAttribute(k,"aria-invalid","true"))),f&&f.classes[t]&&this.dom.addClasses(f.classes[t],k);let j;if(p)if(j=p.render(k,o,i,t,e,x,this.dom.domService),u){const L=k.querySelector("input, select");if(L){this.labelControl(L,this.getColumnAriaLabel(i));const Y=this.editorDraft;if(Y&&Y.rowIndex===o&&Y.columnIndex===i&&L instanceof HTMLInputElement&&(L.value=Y.value,this.dom.setAttribute(L,"data-ge-restored","true")),L.contains(document.activeElement)||L.focus(),Y&&Y.rowIndex===o&&Y.columnIndex===i&&L instanceof HTMLInputElement&&Y.start!==null&&Y.end!==null)try{L.setSelectionRange(Y.start,Y.end)}catch{}}}else this.labelRendererControls(k,p,t,o,i);const _e=e.getCustomClassesAt(o,i);if(_e.length&&this.dom.addClasses(_e,k),t==="body"&&this.cellEditorService&&!g){e.isEditable(o,i)||this.dom.setAttribute(k,"aria-readonly","true");const L=this.cellEditorService.getOwnedEditorId(o,i);L&&this.dom.setAttribute(k,"aria-owns",L)}if(this.dom.addColumnBorderDivs(this.tableOptions,h,m,t,s),d&&this.dom.addHorizontalBorder({left:r,width:l,height:a,top:c+a},h),this.getFocusModel&&t==="body"&&!this.headerFocus){const L=this.getFocusModel();if(L!=null&&L.hasFocus(o,i))this.dom.addFocusBorderDivs(h,m,{}),this.setAriaFocusedCell(k,t,o,i);else if(L&&(N>1||V>1)){const[Y,Ot]=L.getFocus();Y>=o&&Y<o+N&&Ot>=i&&Ot<i+V&&this.setAriaFocusedCell(k,t,o,i)}}else t==="header"&&this.headerFocus&&this.headerFocus[0]===o&&this.headerFocus[1]===i&&(this.dom.addFocusBorderDivs(h,m,{}),this.setAriaFocusedCell(k,t,o,i));t==="header"&&!g&&this.dom.setAttribute(k,"data-ge-action","drag-column"),t==="body"&&((te=this.masterDetailService)!=null&&te.isActive())&&this.masterDetailService.decorateCell(k,o,i),t==="body"&&this.rowDragService&&!u&&(f!=null&&f.rowDrag&&this.rowDragService.decorateCell(k,this.rowDragService.getHandleState(o,f,e)),this.rowDragService.isDragSourceRow(o)&&this.dom.addClass("ge-table-row-dragging",k));const H=e.getCustomStyleAt(o,i);if(H)for(const L in H)this.dom.domService.setStyle(k,L,H[L]);return[k,j]}applyCssClasses(e,t={}){e&&Object.entries(t).forEach(([s,o])=>{o?this.dom.addClass(s,e):this.dom.removeClass(s,e)})}getColumnWidths(e,t){const s=[];for(let o=e;o<=t;o++)s.push(this.tableModel.getColumnWidth(o));return s}getRowHeights(e,t,s){const o=[];for(let i=e;i<=t;i++)o.push(s.getRowHeight(i));return o}adjustHoverRows(e){if(this.tableOptions.hoverRowVisible&&e.rowIndex>-1&&e.areaIdent==="body"){const t=this.hostElement.clientWidth,s=this.tableModel.getAreaModel("body").getRowHeight(e.rowIndex),o=this.contentScrollTop,i=e.rowTop+this.areaHeaderCenter.parent.clientHeight-o;this.dom.applyStyle(this.hoverRow,{left:"0",top:i+"px",width:t+"px",height:s+"px",display:"block"})}else this.hideHoverRow()}hideHover(){this.hideHoverRow(),this.hideHoverColumn()}hideHoverRow(){this.dom.applyStyle(this.hoverRow,{display:"none"})}adjustHoverColumns(e){if(this.tableOptions.hoverColumnVisible&&e.rowIndex>-1){const t=this.hostElement.clientHeight,s=this.tableModel.getColumnWidth(e.columnIndex),o=this.getColumnLeftInHost(e.columnIndex,e.columnLeft);this.dom.applyStyle(this.hoverColumn,{left:o+"px",top:"0px",width:s+"px",height:t+"px",display:"block"})}else this.hideHoverColumn()}getColumnLeftInHost(e,t){const s=this.tableModel.getColumnCount(),o=this.tableModel.getFixedLeftColumnCount(),i=this.tableModel.getFixedRightColumnCount();if(e<o)return t;if(i>0&&e>=s-i){const r=this.tableModel.getXPosByColumnIndex(s-i);return this.areaBodyEastGeo.left+t-r}return t-this.getContentScrollLeft()}getContentScrollLeft(){const e=this.areaBodyCenterGeo.width-this.tableModel.getContentWidthInPixel();return-this.snapToDevicePixel(this.scrollFactorX*e)}hideHoverColumn(){this.dom.applyStyle(this.hoverColumn,{display:"none"})}disposeRendering(){this.debounceTimeout&&(clearTimeout(this.debounceTimeout),this.debounceTimeout=null);for(const e of["header","body","footer"])for(;this.cleanupFunctions[e].length;){const t=this.cleanupFunctions[e].shift();t&&t()}}debounce(e,t=1e3){this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.debounceTimeout=null,e.call(this)},t)}adjustDraggingColumn(e,t,s){var o;if(this.dragging){const i=this.hostElement.clientHeight,r=this.tableModel.getColumnWidth(t);if((o=e.originalEvent)!=null&&o.clientX){const c={left:(this.isRtl()?this.clientXToHostX(e.originalEvent.clientX):e.originalEvent.clientX)-r/2,width:r,height:i,top:0,index:t};this.dom.applyStyle(this.draggingColumn,{background:"rgba(128,128,128,0.2)",display:"block",overflow:"hidden"}),this.dom.applyStyleInPx(this.draggingColumn,c),s&&this.renderContentOfDraggingColumn(c)}}else this.hideDraggingColumn()}renderContentOfDraggingColumn(e){const t=this.renderContentOfDraggingColumnForArea(e,"header",0),s=Math.max(0,this.firstVisibleRowIndex),o=t+this.getBodyRowTop(s)-this.contentScrollTop;this.renderContentOfDraggingColumnForArea(e,"body",o,s,this.hostElement.clientHeight)}renderContentOfDraggingColumnForArea(e,t,s=0,o=0,i=Number.POSITIVE_INFINITY){const r="center",l=this.tableModel.getAreaModel(t),a=l==null?void 0:l.getRowCount();if(a){const c=e.index??0,h=this.draggingColumn;for(let d=o;d<a&&s<i;d++){const u=s,f=l.getRowHeight(d),g={left:0,width:e.width,height:f,top:u,index:d},p=l.getValueAt(d,c),m=l.getCellRenderer(d,c),b=m?"":`${p??""}`,y={parent:h,geo:g,rowIndex:d,columnIndex:c,areaIdent:t,sideIdent:r,text:b},C=this.dom.addColumnDiv(y);let S;m&&(S=m.render(C,d,c,t,l,p,this.dom.domService),S&&this.cleanupFunctions[t].push(S));const E=l.getCustomClassesAt(d,c);E.length&&this.dom.addClasses(E,C);const x=this.tableModel.getColumnDef(c);x&&x.classes[t]&&this.dom.addClasses(x.classes[t],C),this.dom.addColumnBorderDivs(this.tableOptions,h,g,t,r);const R=l.getCustomStyleAt(d,c);if(R)for(const F in R)this.dom.domService.setStyle(C,F,R[F]);s=s+f}}return s}hideDraggingColumn(){this.dom.applyStyle(this.draggingColumn,{display:"none"})}renderDragTargetDiv(e,t,s,o,i){const r=this.dom.applyStylePosistionAbsolute(this.dom.setAriaHidden(this.dom.createDivWithClass("ge-table-drop-zone",e)));return this.dom.setStyle(r,"left",`${t}px`),this.dom.setStyle(r,"top",`${s}px`),this.dom.setStyle(r,"width",`${o}px`),this.dom.setStyle(r,"height",`${i}px`),r}renderSelectedBackgroundDiv(e,t,s,o,i,r,l,a,c,h,d){let u=!1;if(!e&&t&&o.isSelectable(i,r)&&this.getSelectionModel){const f=this.getSelectionModel();if(f){const g=f.getSelectionCount(i,r);u=g>0;for(let p=0;p<g;p++){const m=this.dom.applyStylePosistionAbsolute(this.dom.setAriaHidden(this.dom.createDivWithClass(`ge-table-${o.areaIdent}-${s}-selected-range`,l)));this.dom.setStyle(m,"left",`${a}px`),this.dom.setStyle(m,"top",`${c}px`),this.dom.setStyle(m,"width",`${h}px`),this.dom.setStyle(m,"height",`${d}px`)}}}return u}renderCell({areaModel:e,areaIdent:t,sideIdent:s,rowIndex:o,columnIndex:i,left:r,top:l,width:a,height:c,parent:h,cellSelected:d,lastRowOfModel:u}){const[f,g]=this.addAndRenderCellDiv({areaModel:e,areaIdent:t,sideIdent:s,rowIndex:o,index:i,left:r,width:a,height:c,top:l,parent:h,lastRowOfModel:u});d&&this.dom.addClass(`ge-table-${t}-${s}-selected-range`,f),t==="body"&&this.ariaSelectionKind==="cell"&&this.dom.domService.setAttribute(f,"aria-selected",d?"true":"false"),g&&this.cleanupFunctions[t].push(g)}renderHeaderCellResizeHandle({rowIndex:e,columnIndex:t,cellLeft:s,cellTop:o,cellWidth:i,cellHeight:r,parent:l}){const a=this.dom.domService,c=this.tableOptions.columnResizeHandleWidthInPx??2,h=a.createElement("div");a.setAttribute(h,"data-col-index",`${t}`),a.setAttribute(h,"data-row-index",`${e}`),a.setAttribute(h,"data-area","header"),a.setAttribute(h,"data-ge-action","resize-column"),a.addClass(h,"ge-table-column-resize-handle"),a.setAttribute(h,"aria-hidden","true"),a.setStyle(h,"display","clip"),a.setStyle(h,"position","absolute"),a.setStyle(h,"cursor","col-resize"),this.dom.setStyle(h,"left",`${s+i-c}px`),a.setStyle(h,"top",`${o}px`),a.setStyle(h,"width",`${c}px`),a.setStyle(h,"height",`${r}px`),a.appendChild(l,h)}}class Ts{constructor(e,t){this.columnIndex=e,this.sortState=t}}const Sn=new WeakSet;function xc(n){return Sn.add(n),n}function xn(n){return typeof n=="function"&&Sn.has(n)}class vn{constructor(e,t){this.state=e,this.changedParts=t}}const Be=Object.freeze(["headerGroups","columns","tree","sort","checked","selection","details","scroll","custom"]),vc=["sortingState","scrollState","collapsedExpandedState"];function bo(n,e){try{const t=n.getItem(e);return t?JSON.parse(t):void 0}catch{return}}function Rn(n,e,t){const s={version:1};let o=!1;const i=bo(n,e+"sortingState");Array.isArray(i)&&(o=!0,s.sort=i.filter(a=>a&&typeof a.columnIndex=="number"&&(a.sortState==="asc"||a.sortState==="desc")).map(a=>{const c=t[a.columnIndex],h=a.sortState;return c?{property:c,sortState:h}:{columnIndex:a.columnIndex,sortState:h}}));const r=bo(n,e+"scrollState");Array.isArray(r)&&typeof r[0]=="number"&&typeof r[1]=="number"&&(o=!0,s.scroll={left:r[0],top:r[1]});const l=bo(n,e+"collapsedExpandedState");if(l&&typeof l=="object"){o=!0;let a;l.allExpanded?a={collapsedRowIds:[]}:l.allCollapsed?a={expandedRowIds:[]}:l.mode==="expanded"?a={expandedRowIds:l.rowIds??[]}:a={collapsedRowIds:l.rowIds??[]},s.tree=a}return o?s:void 0}function No(n,e){for(const t of vc)try{n.removeItem(e+t)}catch{}}const Rc={headerGroups:"autoRestoreHeaderGroupState",columns:"autoRestoreColumnLayout",tree:"autoRestoreCollapsedExpandedState",sort:"autoRestoreSortingState",checked:"autoRestoreCheckedState",selection:"autoRestoreSelectedState",scroll:"autoRestoreScrollPosition",custom:"autoRestoreCustomState",details:"autoRestoreDetailState"},Je=n=>n==="checked"?"checkedRowIds":n==="details"?"detailRowIds":n,Te=Number.MAX_SAFE_INTEGER,Ie=class Ie{constructor(e){this.scope=e,this.restoring=!1,this.started=!1,this.destroyed=!1,this.dirty=new Set,this.lastReported=new Map,this.reported={version:1},this.legacyRemoved=!1,this.sortPriority=[],this.initialWidths=new Map,this.startState={},this.custom=void 0,this.warnedNoRowObject=!1,this.warnedNoId=!1,this.warnWithoutStorageKey()}initBeforeModel(){this.started||(this.started=!0,this.restoring=!0,this.startState=this.readStartState(),this.defaultState={version:1},this.computePart("headerGroups",this.defaultState),this.startState.headerGroups&&this.applyHeaderGroups(this.startState.headerGroups))}initAfterModel(){if(!this.restoring)return;for(const s of this.columnDefs())this.initialWidths.set(s,s.width);this.sortPriority=this.columnDefs().filter(s=>s.sortState&&s.property).map(s=>s.property);const e=s=>this.persistedParts().includes(s)||this.startState[Je(s)]!==void 0,t=this.getState(Be.filter(s=>s!=="headerGroups"&&s!=="scroll"&&s!=="custom"&&(!Ie.EXPENSIVE.includes(s)||e(s))));this.defaultState={...this.defaultState,...t,scroll:{left:0,top:0}},this.startState.columns&&this.applyColumns(this.startState.columns,!1)}initAfterFilter(){if(!this.restoring)return;const e=this.startState;e.tree&&this.applyTree(e.tree),e.sort&&this.applySort(e.sort),e.checkedRowIds&&this.applyChecked(e.checkedRowIds),e.selection&&this.applySelection(e.selection),e.detailRowIds&&this.applyDetails(e.detailRowIds),"custom"in e&&(this.custom=e.custom)}initAfterLayout(){this.restoring&&(this.startState.scroll&&this.applyScroll(this.startState.scroll),this.restoring=!1,this.rememberAsReported(this.getState(Be.filter(e=>!Ie.EXPENSIVE.includes(e)))))}getState(e=Be){const t={version:1};for(const s of e)this.computePart(s,t);return t}applyState(e,t=Be){if(!e||typeof e!="object")return;const s=r=>t.includes(r)&&e[Je(r)]!==void 0,o=[];let i=!1;s("headerGroups")&&this.applyHeaderGroups(e.headerGroups)&&o.push("headerGroups"),s("columns")&&(i=this.applyColumns(e.columns,!0),o.push("columns")),s("tree")&&(this.applyTree(e.tree),o.push("tree")),s("sort")&&(this.applySort(e.sort),o.push("sort")),s("checked")&&(this.applyChecked(e.checkedRowIds),o.push("checked")),s("selection")&&(this.applySelection(e.selection),o.push("selection")),s("details")&&(this.applyDetails(e.detailRowIds),o.push("details")),t.includes("custom")&&"custom"in e&&(this.custom=e.custom,o.push("custom")),o.includes("headerGroups")?this.scope.headerGroupsChanged():i?this.scope.recalcColumnWidths():o.length&&(this.scope.tableModel.recalcHeightAndPadding(),this.scope.recalcWrappers(),this.scope.repaintHard()),s("scroll")&&(this.applyScroll(e.scroll),o.push("scroll")),o.forEach(r=>this.markDirty(r))}resetState(){if(!this.defaultState)return;this.applyState(this.defaultState),this.custom=void 0,this.markDirty("custom"),this.flush();const e=this.storageKey(),t=this.storage();if(e&&t)try{t.removeItem(e+Ie.STORAGE_SUFFIX),No(t,e)}catch{}this.lastPersisted=void 0}setCustomState(e){this.custom=e,this.markDirty("custom")}sortedByColumn(e){this.sortPriority=e?[e]:[],this.markDirty("sort")}markDirty(e){!this.started||this.restoring||this.destroyed||(this.dirty.add(e),this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>this.flush(),this.scope.tableOptions.stateChangedDebounceDelay??300))}rendered(){if(this.restoring||!this.started)return;const e=this.scope.scrollViewport,t=this.reportedScroll;(!t||t.left!==this.scope.getViewportScrollLeft()||t.top!==e.scrollTop)&&this.markDirty("scroll")}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=void 0),!this.dirty.size||!this.started||this.restoring)return;this.persistedParts().includes("checked")&&this.dirty.add("checked");const e=Be.filter(t=>this.dirty.has(t));this.dirty.clear();try{const t=this.getState(e),s=e.filter(i=>this.partJson(t,i)!==this.lastReported.get(i));if(!s.length)return;const o={...this.reported};for(const i of e){const r=Je(i);t[r]===void 0?delete o[r]:o[r]=t[r],this.lastReported.set(i,this.partJson(t,i))}this.reported=o,t.scroll&&(this.reportedScroll={left:t.scroll.left,top:t.scroll.top}),this.persist(o),this.scope.stateChanged(new vn(JSON.parse(JSON.stringify(o)),s))}catch(t){console.error("GuiExpert Table: the table state could not be stored or reported",t)}}destroy(){if(!this.destroyed){this.started&&!this.restoring&&this.persistedParts().includes("checked")&&this.dirty.add("checked");try{this.flush()}finally{this.destroyed=!0}}}storageKey(){var s;const e=(s=this.scope.tableOptions.autoRestoreOptions)==null?void 0:s.getStorageKeyFn;return(e?e():void 0)||void 0}storage(){var t;const e=(t=this.scope.tableOptions.autoRestoreOptions)==null?void 0:t.storage;if(e)return e;try{return typeof localStorage>"u"?void 0:localStorage}catch{return}}persistedParts(){const e=this.scope.tableOptions.autoRestoreOptions;return e?Be.filter(t=>!!e[Rc[t]]):[]}warnWithoutStorageKey(){this.scope.tableOptions.autoRestoreOptions&&this.persistedParts().length&&!this.storageKey()&&console.warn("GuiExpert Table: autoRestoreOptions are ignored without getStorageKeyFn (nothing is stored).")}readStartState(){const e=this.scope.tableOptions.initialState??{},t=this.persistedParts(),s=this.storageKey(),o=this.storage();if(!t.length||!s||!o)return{...e};let i;try{const l=o.getItem(s+Ie.STORAGE_SUFFIX);if(l){const a=JSON.parse(l);a&&typeof a=="object"&&a.version===1&&(i=a,this.lastPersisted=l)}}catch{}i||(i=Rn(o,s,this.columnDefs().map(l=>l.property)));const r={...e};if(i)for(const l of t){const a=Je(l);a in i&&(r[a]=i[a])}return r}persist(e){const t=this.persistedParts(),s=this.storageKey(),o=this.storage();if(!t.length||!s||!o)return;const i={version:1};for(const l of t){const a=Je(l);e[a]!==void 0&&(i[a]=e[a])}const r=JSON.stringify(i);if(r!==this.lastPersisted)try{o.setItem(s+Ie.STORAGE_SUFFIX,r),this.lastPersisted=r,this.legacyRemoved||(No(o,s),this.legacyRemoved=!0)}catch{}}rememberAsReported(e){this.reported=e,e.scroll&&(this.reportedScroll={left:e.scroll.left,top:e.scroll.top});for(const t of Be)Je(t)in e&&this.lastReported.set(t,this.partJson(e,t))}partJson(e,t){const s=e[Je(t)];return s===void 0?"":JSON.stringify(s)}computePart(e,t){var s;switch(e){case"headerGroups":{const o=(s=this.headerGroupModel())==null?void 0:s.getToggleGroupStates();o!=null&&o.length&&(t.headerGroups=o);break}case"columns":{const o=this.computeColumns();o&&(t.columns=o);break}case"sort":{const o=this.computeSort();o&&(t.sort=o);break}case"scroll":t.scroll=this.computeScroll();break;case"tree":{const o=this.computeTree();o&&(t.tree=o);break}case"checked":{const o=this.computeChecked();o&&(t.checkedRowIds=o);break}case"selection":{const o=this.computeSelection();o&&(t.selection=o);break}case"custom":this.custom!==void 0&&(t.custom=this.custom);break;case"details":{const o=this.computeDetails();o&&(t.detailRowIds=o);break}}}computeColumns(){const e=this.columnDefs();if(!e.length)return;const t=new Set,s=[];for(const o of e){if(!o.property||t.has(o.property))continue;t.add(o.property);const i={property:o.property},r=this.initialWidths.get(o);r&&o.width&&(r.value!==o.width.value||r.unit!==o.width.unit)&&o.width.unit==="px"&&(i.width=o.width.value),i.visible=Lo(o),s.push(i)}return s}computeSort(){const e=this.columnDefs();if(!e.length)return;const t=s=>{const o=this.sortPriority.indexOf(s.property);return o<0?Te:o};return e.filter(s=>s.sortState&&s.property).map((s,o)=>({cd:s,index:o})).sort((s,o)=>t(s.cd)-t(o.cd)||s.index-o.index).map(({cd:s})=>({property:s.property,sortState:s.sortState}))}computeScroll(){const e=this.scope.scrollViewport,t={left:this.scope.getViewportScrollLeft(),top:e.scrollTop},s=this.scope.getFirstVisibleRowIndex();if(s>-1&&this.body().getRowCount()>0){const o=this.idAt(s,this.warns("scroll"));o!==void 0&&(t.firstRowId=o)}return t}computeTree(){const e=this.body();if(!Z(e))return;const t=[],s=[],o=this.warns("tree");return this.walkTree(e,i=>{var r;if((r=i.children)!=null&&r.length){const l=this.idOfRow(i,-1,o);l!==void 0&&(i.expanded?t:s).push(l)}}),t.length<=s.length?{expandedRowIds:t}:{collapsedRowIds:s}}computeChecked(){const e=this.body().rowSelectionModel;if(!e)return;const t=this.warns("checked"),s=[];for(const o of e.getCheckedRows()??[]){const i=this.idOfRow(o,-1,t);i!==void 0&&s.push(i)}return s}computeDetails(){const e=this.scope.masterDetailService;if(!(e!=null&&e.isActive()))return;const t=this.warns("details"),s=[];for(const o of e.getExpandedRows()){const i=this.idOfRow(o,-1,t);i!==void 0&&s.push(i)}return s}applyDetails(e){const t=this.scope.masterDetailService;if(!(t!=null&&t.isActive())||!Array.isArray(e))return;const s=new Set(e),o=this.body(),i=o,r=i.getAllRows?i.getAllRows():Array.from({length:o.getRowCount()},(l,a)=>o.getRowByIndex(a));t.setExpandedRows(r.filter((l,a)=>{const c=this.idOfRow(l,i.getAllRows?-1:a,!1);return c!==void 0&&s.has(c)}),"state")}computeSelection(){const e=this.scope.selectionModel();if(!e||!e.selectionType||e.selectionType==="none")return;const t=e.createSnapshot?e.createSnapshot():{ranges:e.getRanges(),negativeRanges:[],allSelected:e.isAllSelected()},s=this.warns("selection"),o=r=>r.map(l=>this.toStateRange(l,s)).filter(l=>!!l),i={ranges:o(t.ranges)};return t.negativeRanges.length&&(i.negativeRanges=o(t.negativeRanges)),t.allSelected&&(i.allSelected=!0),i}toStateRange(e,t){var a,c;const s={},o=Math.min(e.r1,e.r2),i=Math.max(e.r1,e.r2);if(!(o<=0&&i>=Te)){const h=this.idAt(o,t);if(h===void 0)return;if(s.fromRowId=h,i<Te){const d=this.idAt(i,t);if(d===void 0)return;s.toRowId=d}}const r=Math.min(e.c1,e.c2),l=Math.max(e.c1,e.c2);if(!(r<=0&&l>=Te)){const h=this.columnDefs(),d=(a=h[r])==null?void 0:a.property;if(!d)return;if(s.fromProperty=d,l<Te){const u=(c=h[l])==null?void 0:c.property;if(!u)return;s.toProperty=u}}return s}applyHeaderGroups(e){const t=this.scope.tableModel.getAreaModel("header");if(!t.setGroupClosed||!t.getToggleGroupStates||!Array.isArray(e))return!1;const s=new Map(t.getToggleGroupStates().map(i=>[i.id,i.closed]));let o=!1;for(const i of e)if(i&&s.has(i.id)&&s.get(i.id)!==!!i.closed){const r=t.setGroupClosed(i.id,!!i.closed);r&&"columnDefs"in this.scope.tableModel&&(this.scope.tableModel.columnDefs=r),o=!0}return o}applyColumns(e,t){const s=this.scope.tableModel,o=this.columnDefs();if(!o.length||!Array.isArray(e))return!1;const i=new Map;for(const d of e)d&&typeof d.property=="string"&&!i.has(d.property)&&o.some(u=>u.property===d.property)&&i.set(d.property,d);const r=o.map(d=>d.property),l=Array.from(i.keys()),a=new Set;r.forEach((d,u)=>{if(i.has(d)&&!a.has(d)){a.add(d);return}const f=u>0?l.lastIndexOf(r[u-1]):-1;l.splice(f+1,0,d)});for(let d=0;d<l.length;d++){const f=s.getColumnDefs().map(g=>g.property).indexOf(l[d],d);f>d&&s.changeColumnOrder(f,d)}let c=!1;return this.columnDefs().forEach((d,u)=>{var g;const f=i.get(d.property);if(f){if(typeof f.visible=="boolean"&&Lo(d)!==f.visible&&((g=s.setColumnVisible)==null||g.call(s,u,f.visible)),typeof f.width=="number"&&f.width>=0)s.setColumnWidth(u,f.width);else if(t){const p=this.initialWidths.get(d);p&&(p.value!==d.width.value||p.unit!==d.width.unit)&&(p.unit==="px"?s.setColumnWidth(u,p.value):c=!0,d.width=p)}}}),c}applyTree(e){const t=this.body();if(!Z(t)||!e)return;const s=Array.isArray(e.expandedRowIds);if(!s&&!Array.isArray(e.collapsedRowIds))return;const o=new Set((s?e.expandedRowIds:e.collapsedRowIds)??[]),i=t;this.walkTree(i,r=>{var l;if((l=r.children)!=null&&l.length){const a=this.idOfRow(r,-1,!1);a!==void 0&&(r.expanded=s?o.has(a):!o.has(a))}}),i.recalcVisibleTreeRows(!1)}applySort(e){var i;if(!Array.isArray(e))return;const t=this.columnDefs(),s=[],o=[];for(const r of e){if(!r||r.sortState!=="asc"&&r.sortState!=="desc")continue;const l=typeof r.property=="string"?t.findIndex(a=>a.property===r.property):typeof r.columnIndex=="number"?r.columnIndex:-1;l<0||l>=this.scope.tableModel.getColumnCount()||s.some(a=>a.columnIndex===l)||(s.push(new Ts(l,r.sortState)),(i=t[l])!=null&&i.property&&o.push(t[l].property))}this.scope.applySortItems(s),this.sortPriority=o}applyChecked(e){const t=this.body(),s=t.rowSelectionModel;if(!s||!Array.isArray(e))return;const o=new Set(e);if(Z(t)){const l=t;this.walkTree(l,a=>{a.checked=!1}),this.walkTree(l,a=>{const c=this.idOfRow(a,-1,!1);c!==void 0&&o.has(c)&&!a.checked&&s.checkRow(a,!0)});return}const i=t,r=i.getAllRows?i.getAllRows():Array.from({length:t.getRowCount()},(l,a)=>t.getRowByIndex(a));s.setCheckedRows(r.filter((l,a)=>{const c=this.idOfRow(l,i.getAllRows?-1:a,!1);return c!==void 0&&o.has(c)}))}applySelection(e){const t=this.scope.selectionModel();if(!t||!e||!Array.isArray(e.ranges))return;const o=[...e.ranges,...e.negativeRanges??[]].some(c=>c&&(c.fromRowId!==void 0||c.toRowId!==void 0))?this.rowIndexMap():new Map,i=this.columnDefs(),r=c=>{if(!c)return;let h=0,d=Te,u=0,f=Te;if(c.fromRowId!==void 0||c.toRowId!==void 0){const g=o.get(c.fromRowId??c.toRowId),p=c.toRowId===void 0?Te:o.get(c.toRowId);if(g===void 0||p===void 0)return;h=Math.min(g,p),d=Math.max(g,p)}if(c.fromProperty!==void 0||c.toProperty!==void 0){const g=i.findIndex(m=>m.property===(c.fromProperty??c.toProperty)),p=c.toProperty===void 0?Te:i.findIndex(m=>m.property===c.toProperty);if(g<0||p<0)return;u=Math.min(g,p),f=Math.max(g,p)}return new M(h,u,d,f)},l=c=>(c??[]).map(r).filter(h=>!!h),a={ranges:l(e.ranges),negativeRanges:l(e.negativeRanges),allSelected:!!e.allSelected};t.restoreSnapshot?t.restoreSnapshot(a):(t.clear(),a.ranges.forEach(c=>t.addSelection(c)))}applyScroll(e){if(!e||typeof e.top!="number"||typeof e.left!="number"||(this.scope.scrollViewport.scrollTo(Ss(e.left,this.scope.isRtl()),e.top),this.scope.adjustAfterScrolling(),e.firstRowId===void 0))return;const t=this.scope.getFirstVisibleRowIndex();if(t>-1&&this.idAt(t,!1)===e.firstRowId)return;const s=this.rowIndexMap().get(e.firstRowId);s!==void 0&&(this.scope.scrollToIndex(-1,s),this.scope.adjustAfterScrolling())}columnDefs(){return this.scope.tableModel.getColumnDefs()??[]}body(){return this.scope.tableModel.getBodyModel()}headerGroupModel(){const e=this.scope.tableModel.getAreaModel("header");return e&&typeof e.getToggleGroupStates=="function"?e:void 0}warns(e){return this.persistedParts().includes(e)}ownGetRowId(){var t;const e=(t=this.scope.tableOptions.autoRestoreOptions)==null?void 0:t.getRowId;return e&&!xn(e)?e:void 0}idAt(e,t){return this.idOfRow(this.body().getRowByIndex(e),e,t)}idOfRow(e,t,s){const o=this.ownGetRowId();if(e==null){if(o&&o.length>=2&&t>-1)return o(void 0,t);s&&!this.warnedNoRowObject&&(this.warnedNoRowObject=!0,console.warn("GuiExpert Table: the body model has no row objects – these rows are not stored. Set autoRestoreOptions.getRowId = (_row, rowIndex) => rowIndex to store them by index."));return}const i=U(e)?e.data:e;if(le(i))return i.id;if(o)return o(i,t);if(i&&typeof i=="object")for(const r of["id","uuid"]){const l=i[r];if(typeof l=="string"||typeof l=="number")return l}s&&!this.warnedNoId&&(this.warnedNoId=!0,console.warn("GuiExpert Table: rows without 'id' or 'uuid' are not stored – set autoRestoreOptions.getRowId."))}rowIndexMap(){const e=this.body(),t=new Map,s=e.getRowCount();for(let o=0;o<s;o++){const i=this.idAt(o,!1);i!==void 0&&!t.has(i)&&t.set(i,o)}return t}walkTree(e,t){const s=o=>o==null?void 0:o.forEach(i=>{t(i),s(i.children)});s(e.rows)}};Ie.STORAGE_SUFFIX="tableState",Ie.EXPENSIVE=["tree","checked","selection"];let Is=Ie;class An{constructor(e){this.tableScope=e,this.tableScope.hostElement.addEventListener("change",this.onHostElementChanged.bind(this),{signal:this.tableScope.listenerAbortController.signal}),this.tableScope.hostElement.addEventListener("keydown",this.onHostElementKeyDown.bind(this),{signal:this.tableScope.listenerAbortController.signal}),this.tableScope.hostElement.addEventListener("input",this.onHostElementInput.bind(this),{signal:this.tableScope.listenerAbortController.signal}),this.tableScope.hostElement.addEventListener("focusout",this.onHostElementFocusOut.bind(this),{signal:this.tableScope.listenerAbortController.signal})}onHostElementFocusOut(e){var s,o;const t=e.target;t instanceof HTMLInputElement&&t.isConnected&&t.getAttribute("data-ge-restored")==="true"&&((o=(s=this.tableScope).getInCellEditorCell)!=null&&o.call(s))&&this.commitInCellEditor(t)}commitInCellEditor(e){const t=Number(e.getAttribute("data-row-index")),s=Number(e.getAttribute("data-col-index"));this.tableScope.updateModelValueAfterEdit("body",t,s,e.value)}onHostElementInput(e){const t=e.target;if(!this.tableScope.isEditing()||!(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)||t.getAttribute("data-area")!=="body")return;const s=Number(t.getAttribute("data-row-index")),o=Number(t.getAttribute("data-col-index"));this.tableScope.setEditorDraft(s,o,t)}onHostElementKeyDown(e){var o,i;if((i=(o=this.tableScope).isEventInDetail)!=null&&i.call(o,e)||!this.tableScope.isEditing())return;const t=e.target;if(e.key==="Enter"&&!e.isComposing&&e.keyCode!==229&&t instanceof HTMLInputElement&&t.getAttribute("data-area")==="body"&&t.getAttribute("data-ge-restored")==="true"){e.preventDefault(),this.commitInCellEditor(t);return}if(e.key!=="Escape")return;const s=e.target;(s instanceof HTMLInputElement||s instanceof HTMLSelectElement||s instanceof HTMLTextAreaElement)&&s.getAttribute("data-area")==="body"&&(e.preventDefault(),e.stopPropagation(),this.tableScope.cancelEditing(s))}onHostElementChanged(e){var t,s,o,i;if(!((s=(t=this.tableScope).isEventInDetail)!=null&&s.call(t,e))&&(e.target instanceof HTMLInputElement||e.target instanceof HTMLSelectElement||e.target instanceof HTMLTextAreaElement)){const r=e.target,l=r.getAttribute("data-area"),a=r.getAttribute("data-row-index"),c=r.getAttribute("data-col-index");if((r.classList.contains("ge-table-cell-editor-input")||r.classList.contains("ge-table-cell-editor-select"))&&!((i=(o=this.tableScope).getInCellEditorCell)!=null&&i.call(o)))return;if(l&&a&&c){const d=rs(l),u=Number(a),f=Number(c);this.tableScope.updateModelValueAfterEdit(d,u,f,r.value)}}}}class En{constructor(e,t,s,o,i,r,l,a){this.scrollTop=e,this.scrollLeft=t,this.scrollHeight=s,this.scrollWidth=o,this.clientHeight=i,this.clientWidth=r,this.scrollFactorY=l,this.scrollFactorX=a}}class fe{constructor(e){this.tableScope=e,this.ignoreNextClick=!1,this.anchorRanges=[],this.getSelectionModel=()=>this.tableScope.selectionModel(),this.getFocusModel=()=>this.tableScope.focusModel()}onMouseDown(){this.ignoreNextClick=!1,this.dragSnapshot=void 0}onMouseDragging(e,t){var o;if(!t||t.action||t.areaIdent!=="body"||e.areaIdent!=="body"||t.rowIndex<0||t.columnIndex<0||e.rowIndex<0||e.columnIndex<0)return!1;const s=(o=this.getSelectionModel)==null?void 0:o.call(this);return!s||!("selectionType"in s)||s.selectionType!=="range"?!1:(this.batch(()=>{var l,a,c;!!((l=t.originalEvent)!=null&&l.ctrlKey||(a=t.originalEvent)!=null&&a.metaKey)&&fe.hasSnapshots(s)?(this.dragSnapshot=this.dragSnapshot??s.createSnapshot(),s.restoreSnapshot(this.dragSnapshot)):s.clear(),s.addSelection(this.createRangeByEvents(e,t));const r=(c=this.getFocusModel)==null?void 0:c.call(this);r&&!r.hasFocus(t.rowIndex,t.columnIndex)&&r.setFocus(t.rowIndex,t.columnIndex),this.previousEvt=t.clone(),this.anchor=[t.rowIndex,t.columnIndex],this.extent=[e.rowIndex,e.columnIndex],this.anchorRanges=[],this.ignoreNextClick=e.rowIndex!==t.rowIndex||e.columnIndex!==t.columnIndex,this.tableScope.onSelectionChanged(s)}),!0)}onMouseClicked(e,t){if(this.ignoreNextClick)return this.ignoreNextClick=!1,!1;if(e.areaIdent==="header"&&e.clickCount===1&&this.isRowNumberColumn(e.columnIndex)&&e.rowIndex===this.tableScope.tableModel.getAreaModel("header").getRowCount()-1)return this.selectAllByRowNumberHeader();if(e.areaIdent==="header"&&e.clickCount===1&&e.columnIndex>-1&&this.isColumnLetterCell(e))return this.clickColumnLetter(e);if(e.areaIdent!=="body"||e.rowIndex<0||e.columnIndex<0||e.clickCount>1)return!1;let s=!1;if(this.getSelectionModel&&this.getFocusModel){const o=this.getSelectionModel(),i=this.getFocusModel();o&&i&&(this.batch(()=>{var d,u,f,g;i.hasFocus(e.rowIndex,e.columnIndex)||i.setFocus(e.rowIndex,e.columnIndex);const r=!!((d=e.originalEvent)!=null&&d.shiftKey),l=!!((u=e.originalEvent)!=null&&u.ctrlKey||(f=e.originalEvent)!=null&&f.metaKey),a=!!((g=e.originalEvent)!=null&&g.altKey),c=this.isRowNumberColumn(e.columnIndex)&&fe.isRangeSelection(o);if(r&&(this.anchor||this.previousEvt)){if(this.anchorRanges.length&&fe.hasSnapshots(o)){const y=o.createSnapshot();o.restoreSnapshot({...y,ranges:y.ranges.filter(C=>!this.anchorRanges.includes(C))})}const[p,m]=this.anchor??[this.previousEvt.rowIndex,this.previousEvt.columnIndex],b=fe.rangeBetween(e.rowIndex,e.columnIndex,p,m);this.extent=[e.rowIndex,e.columnIndex],c&&(b.c1=0,b.c2=Number.MAX_SAFE_INTEGER),o.addSelection(b),this.anchorRanges=[b],this.tableScope.onSelectionChanged(o);return}const h=o.getRanges().slice();c?this.clickRowNumber(o,e.rowIndex,e.columnIndex,r,l,a):l&&a?o.removeSelection(M.singleCell(e.rowIndex,e.columnIndex)):l?o.togglePoint(e.rowIndex,e.columnIndex):(!r&&o.hasSelection()&&o.clear(),o.firstClick(e.rowIndex,e.columnIndex)),this.anchorRanges=o.getRanges().filter(p=>!h.includes(p)),this.previousEvt=e.clone(),this.anchor=[e.rowIndex,e.columnIndex],this.letterAnchor=void 0,this.extent=void 0,this.tableScope.onSelectionChanged(o)}),s=!0)}return s}onActionTriggered(e){var t,s;if(this.getSelectionModel&&this.getFocusModel){const o=this.getSelectionModel(),i=this.getFocusModel();if(o&&i){if(e==="SELECT_ALL")return o.selectAll(),this.tableScope.repaint(),this.announce(r=>r.allSelected()),!0;if(e==="DESELECT_ALL")return o.clear(),this.tableScope.repaint(),this.announce(r=>r.selectionCleared()),!0;if(e==="TOGGLE_SELECTION"&&((s=(t=this.tableScope).getHeaderFocus)!=null&&s.call(t)))return!1;if(e==="TOGGLE_SELECTION"){const[r,l]=i.getFocus();return this.isRowNumberColumn(l)&&fe.isRangeSelection(o)?(this.clickRowNumber(o,r,l,!1,!0,!1),this.tableScope.onSelectionChanged(o),this.tableScope.repaint(),!0):(o.togglePoint(r,l),this.tableScope.repaint(),!0)}}}return!1}getAnchor(){return this.anchor?[this.anchor[0],this.anchor[1]]:void 0}getExtent(){var r;const e=(r=this.getFocusModel)==null?void 0:r.call(this),[t,s]=e?e.getFocus():[-1,-1],o=this.extent??this.anchor,i=this.anchor;return t>=0&&s>=0&&!(i&&i[0]===t&&i[1]===s)&&!(o&&o[0]===t&&o[1]===s)?[t,s]:o?[o[0],o[1]]:void 0}collapseTo(e,t){var i;const s=(i=this.getSelectionModel)==null?void 0:i.call(this);this.anchor=[e,t],this.extent=void 0,this.anchorRanges=[];const o=s==null?void 0:s.selectionType;!s||o!=="range"&&o!=="cell"||this.batch(()=>{const r=s.getRanges();r.length===1&&r[0].r1===e&&r[0].r2===e&&r[0].c1===t&&r[0].c2===t&&!s.isAllSelected()||(s.clear(),s.addSelection(M.singleCell(e,t)),this.tableScope.onSelectionChanged(s)),this.anchorRanges=s.getRanges().slice()})}extendTo(e,t){var h,d;const s=(h=this.getSelectionModel)==null?void 0:h.call(this);if(!s||!fe.isRangeSelection(s))return;const o=(d=this.getFocusModel)==null?void 0:d.call(this),[i,r]=o?o.getFocus():[-1,-1],l=this.extent??this.anchor,a=this.anchor&&this.anchor[0]===i&&this.anchor[1]===r||l&&l[0]===i&&l[1]===r;if((!this.anchor||!a)&&i>=0&&r>=0&&(this.anchor=[i,r],this.extent=void 0,this.anchorRanges=[]),!this.anchor)return;const c=fe.rangeBetween(e,t,this.anchor[0],this.anchor[1]);return this.batch(()=>{if(fe.hasSnapshots(s)){const u=s.createSnapshot();s.restoreSnapshot({...u,ranges:u.ranges.filter(f=>!this.anchorRanges.includes(f))})}else s.clear();s.addSelection(c),this.anchorRanges=[c],this.extent=[e,t],this.tableScope.onSelectionChanged(s)}),c}static rangeBetween(e,t,s,o){return new M(Math.min(e,s),Math.min(t,o),Math.max(e,s),Math.max(t,o))}isRowNumberColumn(e){var t;return e>-1&&O((t=this.tableScope.tableModel)==null?void 0:t.getColumnDef(e))}isColumnLetterCell(e){var s;const t=this.tableScope.tableModel.getAreaModel("header");return!!((s=t.isColumnLetterRow)!=null&&s.call(t,e.rowIndex))&&!this.isRowNumberColumn(e.columnIndex)&&!me(this.tableScope.tableModel.getColumnDef(e.columnIndex))}clickColumnLetter(e){var l,a,c,h,d;const t=(l=this.getSelectionModel)==null?void 0:l.call(this),s=(a=this.getFocusModel)==null?void 0:a.call(this);if(!t||!fe.isRangeSelection(t))return!1;const o=e.columnIndex,i=!!((c=e.originalEvent)!=null&&c.shiftKey),r=!!((h=e.originalEvent)!=null&&h.ctrlKey||(d=e.originalEvent)!=null&&d.metaKey);return this.batch(()=>{const u=i?this.letterAnchor??(s==null?void 0:s.getFocus()[1])??o:o,f=new M(0,Math.min(u,o),Number.MAX_SAFE_INTEGER,Math.max(u,o));if(!r&&t.hasSelection()&&t.clear(),t.addSelection(f),i||(this.letterAnchor=o),s){const g=Math.max(0,s.getFocus()[0]);s.setFocus(g,o)}this.anchor=[0,o],this.extent=void 0,this.tableScope.onSelectionChanged(t)}),!0}selectAllByRowNumberHeader(){var s;const e=(s=this.getSelectionModel)==null?void 0:s.call(this),t=e==null?void 0:e.selectionType;return!e||t!=="row"&&t!=="range"?!1:(this.batch(()=>{e.selectAll(),this.tableScope.onSelectionChanged(e)}),this.announce(o=>o.allSelected()),!0)}clickRowNumber(e,t,s,o,i,r){const l=new M(t,0,t,Number.MAX_SAFE_INTEGER);i&&r?e.removeSelection(l):i?e.isSelected(t,s)?e.removeSelection(l):e.addSelection(l):(!o&&e.hasSelection()&&e.clear(),e.addSelection(l))}static isRangeSelection(e){return e.selectionType==="range"}announce(e){var s;const t=(s=this.getSelectionModel)==null?void 0:s.call(this);(t==null?void 0:t.selectionType)!=="none"&&this.tableScope.ariaTexts&&typeof this.tableScope.announce=="function"&&this.tableScope.announce(e(this.tableScope.ariaTexts))}batch(e){typeof this.tableScope.holdSelectionEvents=="function"?this.tableScope.holdSelectionEvents(e):e()}static hasSnapshots(e){return typeof e.createSnapshot=="function"&&typeof e.restoreSnapshot=="function"}createRangeByEvents(e,t){t||(t=e);const s=Math.min(e.rowIndex,t==null?void 0:t.rowIndex),o=Math.max(e.rowIndex,t==null?void 0:t.rowIndex),i=Math.min(e.columnIndex,t==null?void 0:t.columnIndex),r=Math.max(e.columnIndex,t==null?void 0:t.columnIndex);return M.create({rowIndex1:s,columnIndex1:i,rowIndex2:o,columnIndex2:r})}}class Mn{get(){return{f2:"START_EDITING",space:"TOGGLE_SELECTION","ctrl+num_add":"SELECT_ALL","ctrl+a":"SELECT_ALL","ctrl+shift+a":"DESELECT_ALL","ctrl+x":"DESELECT_ALL","ctrl+num_subtract":"DESELECT_ALL","meta -":"DESELECT_ALL",arrowup:"NAVIGATE_UP",arrowdown:"NAVIGATE_DOWN",arrowleft:"NAVIGATE_LEFT",arrowright:"NAVIGATE_RIGHT",home:"NAVIGATE_ROW_START",end:"NAVIGATE_ROW_END","ctrl+home":"NAVIGATE_FIRST_CELL","ctrl+end":"NAVIGATE_LAST_CELL",pageup:"NAVIGATE_PAGE_UP",pagedown:"NAVIGATE_PAGE_DOWN",enter:"ACTIVATE_CELL","ctrl+alt+up":"MOVE_ROW_UP","ctrl+alt+down":"MOVE_ROW_DOWN","ctrl+d":"FILL_DOWN","ctrl+r":"FILL_RIGHT","meta+c":"COPY_2_CLIPBOARD","ctrl+c":"COPY_2_CLIPBOARD"}}}class Tn{get(){return{f2:"START_EDITING",space:"TOGGLE_SELECTION","ctrl+num_add":"SELECT_ALL","meta+a":"SELECT_ALL","ctrl+a":"SELECT_ALL","meta+x":"DESELECT_ALL","meta+shift+a":"DESELECT_ALL","ctrl+shift+a":"DESELECT_ALL","ctrl+num_subtract":"DESELECT_ALL","ctrl -":"DESELECT_ALL",arrowup:"NAVIGATE_UP",arrowdown:"NAVIGATE_DOWN",arrowleft:"NAVIGATE_LEFT",arrowright:"NAVIGATE_RIGHT",home:"NAVIGATE_ROW_START",end:"NAVIGATE_ROW_END","meta+left":"NAVIGATE_ROW_START","meta+right":"NAVIGATE_ROW_END","ctrl+home":"NAVIGATE_FIRST_CELL","ctrl+end":"NAVIGATE_LAST_CELL","meta+up":"NAVIGATE_FIRST_CELL","meta+down":"NAVIGATE_LAST_CELL",pageup:"NAVIGATE_PAGE_UP",pagedown:"NAVIGATE_PAGE_DOWN",enter:"ACTIVATE_CELL","ctrl+alt+up":"MOVE_ROW_UP","ctrl+alt+down":"MOVE_ROW_DOWN","meta+d":"FILL_DOWN","meta+r":"FILL_RIGHT","meta+c":"COPY_2_CLIPBOARD","ctrl+c":"COPY_2_CLIPBOARD"}}}const Ac={arrowup:"up",arrowdown:"down",arrowleft:"left",arrowright:"right"};function Ut(n){return n.trim().replace(/\+/g," ").replace(/ +/g," ").replace(/⌫/g,"backspace").replace(/↩/g,"enter").replace(/⇧/g,"shift").replace(/⌥/g,"alt").replace(/option/g,"alt").replace(/opt/g,"alt").replace(/⌃/g,"ctrl").replace(/control/g,"ctrl").replace(/command/g,"cmd").replace(/meta/g,"cmd").replace(/escape/g,"esc").replace(/⌘/g,"cmd").replace(/\*/g,"multiply").split(" ").filter(e=>e).map(e=>Ac[e]??e).filter((e,t,s)=>s.indexOf(e)===t).sort((e,t)=>{const s={cmd:1,ctrl:2,alt:3,shift:4},o=s[e]||5,i=s[t]||5;return o!==i?o-i:e.localeCompare(t)}).join(" ")}function In(n){let e=n.key.toLowerCase();if(e===" "&&(e="space"),e==="arrowleft"&&(e="left"),e==="arrowright"&&(e="right"),e==="arrowup"&&(e="up"),e==="arrowdown"&&(e="down"),e==="delete"&&n.code==="Delete"&&(e="delete"),e==="backspace"&&(e="backspace"),e==="escape"&&(e="esc"),e==="return"&&(e="enter"),n.code.startsWith("Numpad")){const s=n.code.replace("Numpad","").toLowerCase();s==="add"?e="num_add":s==="subtract"?e="num_subtract":s==="multiply"?e="num_multiply":s==="divide"?e="num_divide":s==="decimal"?e="num_decimal":s==="enter"?e="num_enter":e="num_"+s}n.code.match(/^F\d+$/)&&(e=n.code.toLowerCase()),n.code.match(/^Digit\d+$/)&&(e=n.code.replace(/Digit/g,""));let t="";return n.ctrlKey&&(t+=" ctrl"),n.altKey&&(t+=t+" alt"),n.shiftKey&&(t+=t+" shift"),n.metaKey&&(t+=t+" cmd"),Ut(t+" "+e)}class Dn{constructor(e){this.tableScope=e,this.shortcutActionIdMapping={},this.listener=[],this.listener.push(e),this.init()}addListener(e){this.listener.includes(e)||this.listener.push(e)}init(){var e,t,s,o;if((t=(e=this.tableScope)==null?void 0:e.tableOptions)!=null&&t.shortcutActionsDisabled)this.isDebug()&&console.debug("ShortcutService skipped.");else{this.assignPredefinedSystemShortcutMappings();for(const i of((o=(s=this.tableScope).getShortcutLayers)==null?void 0:o.call(s,this.isMacintosh()))??[])this.assignMapping(i);this.assignMapping(this.tableScope.tableOptions.shortcutActionIdMapping),this.isDebug()&&console.debug("ShortcutService",this.shortcutActionIdMapping),this.tableScope.hostElement.addEventListener("keydown",this.onKeyDown.bind(this),{signal:this.tableScope.listenerAbortController.signal})}}assignPredefinedSystemShortcutMappings(){this.isMacintosh()?this.assignMapping(new Tn().get()):this.assignMapping(new Mn().get())}assignMapping(e){if(e)for(const t of Object.keys(e)){const s=Ut(t);for(const o of Object.keys(this.shortcutActionIdMapping))o!==t&&Ut(o)===s&&delete this.shortcutActionIdMapping[o];this.shortcutActionIdMapping[t]=e[t]}}isMacintosh(){return navigator.platform.indexOf("Mac")>-1}isDebug(){return this.isLocalhost()}isLocalhost(){return location.hostname==="localhost"||location.hostname==="127.0.0.1"}onKeyDown(e){var o,i;if((i=(o=this.tableScope).isEventInDetail)!=null&&i.call(o,e))return;const t=e.target;if(t&&(t.isContentEditable||["INPUT","SELECT","TEXTAREA","BUTTON","A"].includes(t.tagName)))return;const s=this.findEntity(e);if(s){this.tableScope.shortcutKeyEvent=e;let r;try{r=this.emit(s)}finally{this.tableScope.shortcutKeyEvent=void 0}r&&(e.preventDefault(),e.stopPropagation())}}emit(e){this.isDebug()&&console.debug("ShortcutService emit :",e);let t=!1;for(const s of this.listener)s.onActionTriggered(e)&&(t=!0);return t}findEntity(e){var s,o;let t=In(e);(o=(s=this.tableScope).isRtl)!=null&&o.call(s)&&(t=Hr(t)),this.isDebug()&&console.debug("ShortcutService shortcut :",t);for(const i in this.shortcutActionIdMapping)if(Ut(i)===t)return this.isDebug()&&console.debug("ShortcutService action :",this.shortcutActionIdMapping[i]),this.shortcutActionIdMapping[i]}getShortcutActionMapping(){return this.shortcutActionIdMapping}}class Kt{onCheckboxChanged(e){}onContextmenu(e){}onModelChanged(e){}onMouseClicked(e){}onMouseDragging(e){}onMouseDraggingEnd(e){}onMouseMoved(e){}onScroll(e){}onSelectionChanged(e){}onFocusChanged(e){}onStateChanged(e){}onRowDragStart(e){}onRowDragMove(e){}onRowDragEnd(e){}onBatchEditChanged(e){}onDetailExpandedChanged(e){}onEditingChanged(e){}onUndoStackChanged(e){}}class Vo{setStyle(e,t,s){return e.style[t]=s,e}appendText(e,t){const s=this.createText(t);return this.appendChild(e,s),s}addClass(e,t){return t.includes(" ")?t.split(" ").forEach(s=>e.classList.add(s)):e.classList.add(t),e}removeClass(e,t){return t.includes(" ")?t.split(" ").forEach(s=>e.classList.remove(s)):e.classList.remove(t),e}appendChild(e,t){e.appendChild(t)}createElement(e){return document.createElement(e)}createText(e){return document.createTextNode(e)}setAttribute(e,t,s){e.setAttribute(t,s)}removeAttribute(e,t){e.removeAttribute(t)}}const Ec=null;function Et(n){return n==null||n===""}const Zi=new Intl.Collator("en",{numeric:!0});function Qi(n){return typeof n=="number"||typeof n=="bigint"?0:n instanceof Date?1:typeof n=="boolean"?2:typeof n=="string"?3:4}function er(n,e){const t=Qi(n),s=Qi(e);if(t!==s)return t-s;switch(t){case 0:{const o=n,i=e,r=typeof o=="number"&&Number.isNaN(o),l=typeof i=="number"&&Number.isNaN(i);return r||l?r===l?0:r?1:-1:o<i?-1:o>i?1:0}case 1:{const o=n.getTime(),i=e.getTime();return(Number.isNaN(o)?1/0:o)-(Number.isNaN(i)?1/0:i)||0}case 2:return(n?1:0)-(e?1:0);case 3:return Zi.compare(n,e);default:return Zi.compare(String(n),String(e))}}function fs(n){return(e,t)=>{const s=Et(e),o=Et(t);return s||o?s===o?0:s?1:-1:n(e,t)}}function Mc(n,e){const t=typeof n=="string"||typeof n=="function"?{value:n}:n;if(!t||typeof t.value!="string"&&typeof t.value!="function")throw new Error(`Row grouping: level ${e} has no value (a property path or a function).`);const s=typeof t.value=="string"?t.value:void 0,o=t.order??"asc";let i;return o==="asc"?i=fs(er):o==="desc"?i=fs((r,l)=>er(l,r)):typeof o=="function"?i=fs(o):i=fs(()=>0),{name:t.name??s??`level${e}`,label:t.label,path:s,getKey:ns(t.value),format:t.format,compare:i}}function Ve(n){return(n??[]).map((e,t)=>Mc(e,t))}const tr=new WeakMap;let Tc=1;function st(n){if(Et(n))return"empty";switch(typeof n){case"string":return"s:"+n;case"number":return"n:"+String(n);case"boolean":return"b:"+n;case"bigint":return"i:"+String(n);case"symbol":return"y:"+(n.description??"");case"function":case"object":{if(n instanceof Date)return"d:"+n.getTime();let e=tr.get(n);return e===void 0&&(e=Tc++,tr.set(n,e)),"o:"+e}default:return"u:"+String(n)}}function Ic(n,e){return Et(n)?e:n instanceof Date?Number.isNaN(n.getTime())?"Invalid Date":n.toLocaleDateString("en-US"):String(n)}function kn(n,e){return n.map(t=>t.label??(t.path!==void 0?e(t.path):void 0)??t.name)}function Ln(n,e){const t=kn(Ve(n),s=>{var o;return(o=e.find(i=>i.property===s&&!ot(i)))==null?void 0:o.headerLabel});return t.length?t.join(" › "):"Group"}function _o(n){var a,c;const e=n.getBodyModel();if(!ne(e))return!1;const t=n.getColumnDefs()??[],s=e.getGroupBy(),o=e.options.hideGroupedColumns===!1?[]:Ve(s).map(h=>h.path).filter(h=>h!==void 0&&t.some(d=>d.property===h&&!ot(d))),i=e.hiddenColumnProperties.filter(h=>o.includes(h));for(const h of e.hiddenColumnProperties)o.includes(h)||(a=n.setColumnVisible)==null||a.call(n,h,!0);for(const h of o)i.includes(h)||!Dc(t,h)||((c=n.setColumnVisible)==null||c.call(n,h,!1),i.push(h));e.hiddenColumnProperties=i;const r=t.findIndex(ot),l=t[r];if(l&&ot(l)&&l.autoHeaderLabel){const h=Ln(s,t);l.headerLabel=h;const d=n.getAreaModel("header"),u=d.getRowCount()-1;u>=0&&d.getValueAt(u,r)!==h&&d.setValue(u,r,h)}return!0}function Dc(n,e){var t,s;return((s=(t=n.find(o=>o.property===e))==null?void 0:t.isVisible)==null?void 0:s.call(t))!==!1}const De=class De{createContent(e,t,s){return new Promise((o,i)=>{var r;if(t!=null&&t.hasSelection()){const l=t.isAllSelected()?new M(0,0,Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER):this.mergeRanges(t.getRanges());if(l){l.c2=Math.min(l.c2,e.getColumnCount()-1),l.r2=Math.min(l.r2,e.getBodyModel().getRowCount()-1);const a=Math.max(0,l.r2-l.r1+1)*Math.max(0,l.c2-l.c1+1);if(a>De.maxCopyCells)return i(`Cannot copy ${a} cells – more than CopyService.maxCopyCells (${De.maxCopyCells}).`);const c=[];for(let h=l.r1;h<=l.r2;h++){const d=[];for(let u=l.c1;u<=l.c2;u++){const f=e.getColumnDef(u);if(((r=f==null?void 0:f.isVisible)==null?void 0:r.call(f))===!1)continue;const g=O(f)?f:void 0;if(g&&!g.options.exported)continue;const p=t.isSelected(h,u),m=e.getBodyModel(),b=p?g?g.getRowNumberText(h,m):m.getTextValueAt(h,u):"";d.push(b)}c.push(d.join(De.columnSeparatorChar))}return o(c.join(De.rowSeparatorChar))}}if(s){const[l,a]=s.getFocus(),c=e.getColumnDef(a),h=O(c)?c.getRowNumberText(l,e.getBodyModel()):e.getBodyModel().getTextValueAt(l,a);return o(h)}i("Cannot copy, neither selection nor focus defined.")})}copyContent(e){return navigator.clipboard.writeText(e)}copyToClipboard(e,t,s){return new Promise((o,i)=>{this.createContent(e,t,s).then(r=>{r?this.copyContent(r).then(l=>{o(r)}).catch(l=>{i()}):o("")}).catch(r=>{i()})})}mergeRanges(e){let t;for(const s of e)t?(t.r1=Math.min(t.r1,s.r1),t.c1=Math.min(t.c1,s.c1),t.r2=Math.max(t.r2,s.r2),t.c2=Math.max(t.c2,s.c2)):t=new M(s.r1,s.c1,s.r2,s.c2);return t}};De.maxCopyCells=1e6,De.columnSeparatorChar=" ",De.rowSeparatorChar=`
|
|
48
|
+
`;let Se=De;class Fn{constructor(e,t=500){this.tableScope=e,this.debounceDelay=t,this.disconnected=!1,this.resizeObserver=new ResizeObserver(Er(this.handleResize.bind(this),t)),this.resizeObserver.observe(this.tableScope.hostElement)}disconnect(){this.disconnected=!0,this.resizeObserver.disconnect()}handleResize(e){if(this.disconnected)return;const t=e[0],{width:s}=t.contentRect;this.tableScope.recalcColumnWidths(s)}}function bs(n){return!!n&&typeof n=="object"&&typeof n.formula=="string"&&"value"in n}function ws(n){return!!n&&typeof n=="object"&&typeof n.value=="number"&&typeof n.numberFormat=="string"}const wo="yyyy-mm-dd";let gs;function sr(n){if(!gs){gs=new Uint32Array(256);for(let t=0;t<256;t++){let s=t;for(let o=0;o<8;o++)s=s&1?3988292384^s>>>1:s>>>1;gs[t]=s>>>0}}let e=4294967295;for(let t=0;t<n.length;t++)e=gs[(e^n[t])&255]^e>>>8;return(e^4294967295)>>>0}async function kc(n){const e=globalThis.CompressionStream;if(!(!e||typeof Response>"u"||typeof Blob>"u"))try{const t=new Blob([n]).stream().pipeThrough(new e("deflate-raw"));return new Uint8Array(await new Response(t).arrayBuffer())}catch{return}}class On{constructor(){this.supportsNumberFormats=!0,this.supportsFormulas=!0,this.numberFormatStyles=new Map}downloadExcel(e,t="file.xlsx",s="",o={}){if(!Array.isArray(e)||e.some(i=>!Array.isArray(i)))throw new Error("Invalid matrix format. Expected a 2D array.");if((t==null?void 0:t.trim())==="")throw new Error("Invalid filename. Filename must be a non-empty string.");return this.createExcelBlob(e,s,o).then(i=>{const r=URL.createObjectURL(i),l=document.createElement("a");l.href=r,l.download=t,document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(r),1e3)}).catch(i=>{throw console.error("Error generating Excel file:",i),new Error("Failed to download Excel file.")})}async createExcelBlob(e,t="",s={}){const o=await this.createZipCompressed(this.generateMap(e,t,s));return new Blob([o],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}generateMap(e,t="",s={}){const o=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
49
49
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>`,i=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
50
50
|
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><Application>Microsoft Macintosh Excel</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><HeadingPairs><vt:vector size="2" baseType="variant"><vt:variant><vt:lpstr>Worksheets</vt:lpstr></vt:variant><vt:variant><vt:i4>1</vt:i4></vt:variant></vt:vector></HeadingPairs><TitlesOfParts><vt:vector size="1" baseType="lpstr"><vt:lpstr>Sheet1</vt:lpstr></vt:vector></TitlesOfParts><Company></Company><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>16.0300</AppVersion></Properties>`,r=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
51
51
|
<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:creator>${this.escapeXml(t)}</dc:creator><cp:lastModifiedBy>${this.escapeXml(t)}</cp:lastModifiedBy><dcterms:created xsi:type="dcterms:W3CDTF">2024-12-13T19:45:08Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2024-12-13T19:45:35Z</dcterms:modified></cp:coreProperties>`,l=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
@@ -61,14 +61,14 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
|
|
|
61
61
|
<sheetView${t.rightToLeft?' rightToLeft="1"':""} tabSelected="1" workbookViewId="0"/></sheetViews>
|
|
62
62
|
<sheetFormatPr baseColWidth="10" defaultRowHeight="16" x14ac:dyDescent="0.2"/>
|
|
63
63
|
<sheetData>`);for(let r=0;r<e.length;r++){const l=e[r];i.push(`<row r="${r+1}" spans="1:${s}" x14ac:dyDescent="0.2">`);for(let a=0;a<l.length;a++){const c=l[a],h=this.getCellAddress(r,a);if(typeof c=="number"&&Number.isFinite(c))i.push(`<c r="${h}"><v>${c}</v></c>`);else if(bs(c))i.push(this.formulaCellXml(h,c.formula,c.value));else if(ws(c)&&Number.isFinite(c.value))i.push(`<c r="${h}" s="${this.numberFormatStyles.get(c.numberFormat)??0}"><v>${c.value}</v></c>`);else if(c instanceof Date&&!isNaN(c.getTime())){const d=c;i.push(`<c r="${h}" t="inlineStr"><is><t>${d.toISOString()}</t></is></c>`)}else{const d=ws(c)?c.value:c,u=d!=null?this.escapeXml(String(d)):"";i.push(`<c r="${h}" t="inlineStr"><is><t>${u}</t></is></c>`)}}i.push("</row>")}return i.push(""),i.push(""),i.push('</sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>'),i.push("</worksheet>"),i.join(`
|
|
64
|
-
`)}formulaCellXml(e,t,s){const o=`<f>${this.escapeXml(t)}</f>`;if(typeof s=="number"&&Number.isFinite(s))return`<c r="${e}">${o}<v>${s}</v></c>`;if(s instanceof Date&&!isNaN(s.getTime()))return`<c r="${e}" s="${this.numberFormatStyles.get(wo)??0}">${o}<v>${Ft(s)}</v></c>`;if(typeof s=="boolean")return`<c r="${e}" t="b">${o}<v>${s?1:0}</v></c>`;if(w(s)){const r=["#DIV/0!","#NAME?","#VALUE!","#REF!","#N/A","#NUM!","#NULL!"].includes(s.code)?s.code:"#VALUE!";return`<c r="${e}" t="e">${o}<v>${r}</v></c>`}const i=s==null?"":this.escapeXml(String(s));return`<c r="${e}" t="str">${o}<v>${i}</v></c>`}withNumberFormats(e,t){const s=[];for(const r of t)for(const l of r)ws(l)&&!s.includes(l.numberFormat)&&s.push(l.numberFormat),bs(l)&&l.value instanceof Date&&!s.includes(wo)&&s.push(wo);if(this.numberFormatStyles=new Map(s.map((r,l)=>[r,l+1])),!s.length)return e;const o=`<numFmts count="${s.length}">`+s.map((r,l)=>`<numFmt numFmtId="${164+l}" formatCode="${this.escapeXml(r)}"/>`).join("")+"</numFmts>",i=`<cellXfs count="${s.length+1}"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>`+s.map((r,l)=>`<xf numFmtId="${164+l}" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>`).join("")+"</cellXfs>";return e.replace("<fonts ",`${o}<fonts `).replace('<cellXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/></cellXfs>',i)}escapeXml(e){return e==null?"":String(e).replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g,"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}getCellAddress(e,t){const s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";let o="";for(;t>=0;)o=s[t%26]+o,t=Math.floor(t/26)-1;return`${o}${e+1}`}createZip(e){const t=[];return e.forEach((s,o)=>{const i=new TextEncoder().encode(s);t.push({path:new TextEncoder().encode(o),data:i,size:i.length,crc:sr(i),method:0})}),this.assembleZip(t)}async createZipCompressed(e){const t=[];for(const[s,o]of Array.from(e.entries())){const i=new TextEncoder().encode(o),r=await kc(i),l=!!r&&r.length<i.length;t.push({path:new TextEncoder().encode(s),data:l?r:i,size:i.length,crc:sr(i),method:l?8:0})}return this.assembleZip(t)}assembleZip(e){const t=[],s=[];let o=0;for(const h of e){const d=new Uint8Array(30+h.path.length),u=new DataView(d.buffer);d.set([80,75,3,4],0),u.setUint16(4,20,!0),u.setUint16(6,0,!0),u.setUint16(8,h.method,!0),u.setUint16(10,0,!0),u.setUint16(12,33,!0),u.setUint32(14,h.crc,!0),u.setUint32(18,h.data.length,!0),u.setUint32(22,h.size,!0),u.setUint16(26,h.path.length,!0),u.setUint16(28,0,!0),d.set(h.path,30),t.push(d,h.data),s.push(o),o+=d.length+h.data.length}const i=o;e.forEach((h,d)=>{const u=new Uint8Array(46+h.path.length),f=new DataView(u.buffer);u.set([80,75,1,2],0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(8,0,!0),f.setUint16(10,h.method,!0),f.setUint16(12,0,!0),f.setUint16(14,33,!0),f.setUint32(16,h.crc,!0),f.setUint32(20,h.data.length,!0),f.setUint32(24,h.size,!0),f.setUint16(28,h.path.length,!0),f.setUint16(30,0,!0),f.setUint16(32,0,!0),f.setUint16(34,0,!0),f.setUint16(36,0,!0),f.setUint32(38,0,!0),f.setUint32(42,s[d],!0),u.set(h.path,46),t.push(u),o+=u.length});const r=new Uint8Array(22),l=new DataView(r.buffer);r.set([80,75,5,6],0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o-i,!0),l.setUint32(16,i,!0),t.push(r);const a=new Uint8Array(t.reduce((h,d)=>h+d.length,0));let c=0;for(const h of t)a.set(h,c),c+=h.length;return a}}const $s=class $s{constructor(e,t,s){this.document=e,this.id=t,this.domService=s}announce(e,t=$s.defaultDelayInMs){const s=this.getOrCreateElement();s&&(this.timeout&&clearTimeout(this.timeout),s.textContent="",this.pendingText=e,this.timeout=setTimeout(()=>{this.timeout=void 0,this.pendingText=void 0,s.textContent=e},Math.max(0,t)))}cancel(e){this.timeout&&(e===void 0||e===this.pendingText)&&(clearTimeout(this.timeout),this.timeout=void 0,this.pendingText=void 0)}getElement(){return this.getOrCreateElement()}destroy(){var e;this.timeout&&(clearTimeout(this.timeout),this.timeout=void 0),(e=this.element)==null||e.remove(),this.element=void 0}getOrCreateElement(){var i;if(this.element)return this.element;const e=(i=this.document)==null?void 0:i.body;if(!e)return;const t=this.domService,s=t.createElement("div");t.setAttribute(s,"id",this.id),t.setAttribute(s,"role","status"),t.setAttribute(s,"aria-live","polite"),t.setAttribute(s,"aria-atomic","true"),t.addClass(s,"ge-table-sr-only");const o={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)","white-space":"nowrap",border:"0"};for(const r in o)t.setStyle(s,r,o[r]);return t.appendChild(e,s),this.element=s,s}};$s.defaultDelayInMs=150;let Ds=$s;class so{constructor(){this.managed=!0,this.multiRow=!0,this.treeDropInside=!0,this.dragThresholdInPx=4,this.autoScrollZoneInPx=40,this.autoScrollMaxSpeedInPx=24,this.ghostText=void 0}static create(e){const t=new so;for(const[s,o]of Object.entries(e??{}))o!==void 0&&(t[s]=o);return t}}class Pn{constructor(e,t,s,o,i,r,l,a,c){this.type=e,this.source=t,this.rows=s,this.rowIndices=o,this.target=i,this.toIndex=r,this.outside=l,this.managed=a,this.originalEvent=c,this.moved=!1,this.prevented=!1}get defaultPrevented(){return this.prevented}preventDefault(){this.prevented=!0}}const yo="drag-row";class Nn{constructor(e){this.tableScope=e,this.autoScrollFrame=0,this.suppressClick=!1,this.warnedUnsupported=!1;const t=e.listenerAbortController.signal;e.hostElement.addEventListener("pointerdown",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onPointerDown(s)},{signal:t}),e.hostElement.addEventListener("click",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onClickCapture(s)},{capture:!0,signal:t}),e.hostElement.addEventListener("dblclick",s=>{var o;!((o=e.isEventInDetail)!=null&&o.call(e,s))&&s.target instanceof Element&&s.target.closest(`[data-ge-action="${yo}"]`)&&s.stopPropagation()},{capture:!0,signal:t})}get options(){return so.create(this.tableScope.tableOptions.rowDragOptions)}isDragging(){return!!this.session}isDragSourceRow(e){return!!this.session&&this.session.rowSet.has(e)}getBlockReason(){var s;if(!this.isManaged())return;if(this.tableScope.tableSheet)return"cellFormulas";if(this.isSorted())return"sorted";const e=this.tableScope.tableModel.getBodyModel(),t=(s=e.getUnfilteredRowCount)==null?void 0:s.call(e);if(t!==void 0&&t>e.getRowCount())return"filtered"}getHandleState(e,t,s){const o=t==null?void 0:t.rowDrag;if(!o||To(s))return"none";const i=s.getRowByIndex(e);return Mo(i)||typeof o=="function"&&!o(i,e)?"none":this.isManaged()&&!this.canModelMove(s)?(this.warnedUnsupported||(this.warnedUnsupported=!0,console.warn("GuiExpert Table: rowDrag is set, but the body model cannot move rows (no moveRows(), or row grouping / pivot). Use rowDragOptions: { managed: false } and move the rows yourself.")),"none"):this.getBlockReason()?"disabled":"enabled"}decorateCell(e,t){if(t==="none")return;const s=this.tableScope.getDomService().domService,o=s.createElement("span");s.addClass(o,"ge-table-row-drag-handle"),t==="disabled"&&s.addClass(o,"ge-table-row-drag-handle-disabled"),s.setAttribute(o,"data-ge-action",yo),s.setAttribute(o,"aria-hidden","true"),s.appendChild(e,o),s.addClass(e,"ge-table-row-drag-cell"),s.setAttribute(e,"aria-keyshortcuts","Control+Alt+ArrowUp Control+Alt+ArrowDown")}onPointerDown(e){var i;if(this.session||this.pending||e.pointerType==="mouse"&&e.button!==0)return;const t=e.target instanceof Element?e.target:null,s=t==null?void 0:t.closest(`[data-ge-action="${yo}"]`);if(!s||!this.tableScope.hostElement.contains(s)||this.tableScope.tableOverlay.isEventBlocked(e)||this.tableScope.isEditing())return;e.preventDefault();const o=Number((i=s.closest("[data-row-index]"))==null?void 0:i.getAttribute("data-row-index"));if(!(!Number.isInteger(o)||o<0)){if(s.classList.contains("ge-table-row-drag-handle-disabled")){this.announceNotPossible();return}this.pending={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,rowIndex:o},this.listenToDocument()}}listenToDocument(){this.sessionAbortController=new AbortController;const e=this.sessionAbortController.signal,t=this.tableScope.hostElement.ownerDocument;t.addEventListener("pointermove",s=>this.onPointerMove(s),{signal:e}),t.addEventListener("pointerup",s=>this.onPointerUp(s),{signal:e}),t.addEventListener("pointercancel",s=>this.onPointerCancel(s),{signal:e}),t.addEventListener("keydown",s=>this.onKeyDown(s),{capture:!0,signal:e}),this.tableScope.scrollViewport.addEventListener("scroll",()=>{var s;(s=this.session)!=null&&s.lastEvent&&!this.autoScrollFrame&&this.updateTarget(this.session.lastEvent)},{signal:e})}onPointerMove(e){if(!(!this.pending||e.pointerId!==this.pending.pointerId)){if(!this.session){const t=e.clientX-this.pending.startX,s=e.clientY-this.pending.startY;if(Math.hypot(t,s)<this.options.dragThresholdInPx||!this.startPointerDrag(e))return}e.preventDefault(),this.session&&this.updateTarget(e)}}onPointerUp(e){if(!(!this.pending||e.pointerId!==this.pending.pointerId)){if(!this.session){this.stopListening();return}this.updateTarget(e),this.suppressClick=!0,setTimeout(()=>this.suppressClick=!1,0),this.session&&this.drop(e)}}onPointerCancel(e){this.pending&&e.pointerId===this.pending.pointerId&&this.cancel(e)}onKeyDown(e){e.key==="Escape"&&(this.session||this.pending)&&(e.preventDefault(),e.stopPropagation(),this.cancel(e))}onClickCapture(e){this.suppressClick&&(this.suppressClick=!1,e.stopPropagation(),e.preventDefault())}startPointerDrag(e){var r,l;const t=this.pending,s=this.getDragRowIndices(t.rowIndex),o=this.getRows(s),i=this.createEvent("start","pointer",o,s,void 0,!1,e);return(l=(r=this.tableScope.getEventListener()).onRowDragStart)==null||l.call(r,i),i.defaultPrevented||this.pending!==t?(this.stopListening(),!1):(this.session={source:"pointer",rowIndices:s,rows:o,outside:!1,autoScrollSpeed:0,rowSet:new Set(s),options:this.options,scrollRemainder:0},this.createDragElements(o),this.tableScope.repaint(),this.tableScope.announce(this.texts().rowDragStarted(o.length)),!0)}updateTarget(e){var l,a;const t=this.session;t.lastEvent=e;const{target:s,outside:o}=this.computeTarget(e.clientX,e.clientY);let i=s&&this.isValidTarget(t.rowIndices,s)?s:void 0;if(!Fc(i,t.target)||o!==t.outside){const c=this.createEvent("move","pointer",t.rows,t.rowIndices,i,o,e);if((a=(l=this.tableScope.getEventListener()).onRowDragMove)==null||a.call(l,c),this.session!==t)return;c.defaultPrevented&&(i=void 0)}t.target=i,t.outside=o,this.renderDragElements(e),t.autoScrollSpeed=o?0:this.calcAutoScrollSpeed(e.clientY),t.autoScrollSpeed&&!this.autoScrollFrame?this.autoScrollFrame=requestAnimationFrame(()=>this.autoScrollStep()):t.autoScrollSpeed||(t.lastFrameTime=void 0,t.scrollRemainder=0)}autoScrollStep(){this.autoScrollFrame=0;const e=this.session;if(!e||!e.autoScrollSpeed)return;const t=this.tableScope.scrollViewport,s=t.scrollTop,o=performance.now(),i=e.lastFrameTime?Math.min(4,(o-e.lastFrameTime)/(1e3/60)):1;e.lastFrameTime=o;const r=e.autoScrollSpeed*i*this.tableScope.getScrollerToContentRatioY()+e.scrollRemainder,l=Math.trunc(r);e.scrollRemainder=r-l,t.scrollTop=s+l,t.scrollTop!==s&&this.tableScope.adjustAfterScrolling(),this.updateTarget(e.lastEvent)}calcAutoScrollSpeed(e){const{autoScrollZoneInPx:t,autoScrollMaxSpeedInPx:s}=this.session.options;if(t<=0||s<=0)return 0;const o=this.tableScope.getBodyViewport(),i=e-o.top,r=o.top+o.height-e,l=a=>Math.max(1,Math.round(s*Math.min(1,a/t)**2));return i<t?-l(t-i):r<t?l(t-r):0}computeTarget(e,t){var p;const s=this.tableScope.hostElement.getBoundingClientRect();if(e<s.left||e>s.right||t<s.top||t>s.bottom)return{outside:!0};const o=this.tableScope.tableModel.getBodyModel(),i=o.getRowCount();if(i<1)return{outside:!1};const r=this.tableScope.getBodyViewport(),a=Math.min(Math.max(t,r.top),r.top+Math.max(0,r.height-1))-r.top+r.contentScrollTop,c=this.tableScope.getBodyRowIndexAtY(a),h=this.tableScope.getBodyRowTop(c),d=Math.max(1,o.getRowHeight(c)),u=Math.min(1,Math.max(0,(a-h)/d));let f;const g=Z(o);if(g&&(((p=this.session)==null?void 0:p.options)??this.options).treeDropInside?f=u<.25?"before":u>.75?"after":"inside":f=u<.5?"before":"after",g&&f==="after"&&c+1<i){const m=o.getRowByIndex(c),b=o.getRowByIndex(c+1);if(b!=null&&b.parent&&b.parent===m)return{target:{rowIndex:c+1,position:"before"},outside:!1}}return{target:{rowIndex:c,position:f},outside:!1}}isValidTarget(e,t){if(!this.isManaged())return!0;const s=this.tableScope.tableModel.getBodyModel();return!!s.moveRows&&!this.tableScope.tableSheet&&(s.canMoveRows?s.canMoveRows(e,t):!0)}drop(e){var r,l;const t=this.session,s=t.outside?void 0:t.target,o=this.createEvent("end",t.source,t.rows,t.rowIndices,s,t.outside,e);this.stopListening();const i=s&&this.isManaged()?this.moveRows(t.rowIndices,s,!0):-1;i>-1?(o.moved=!0,o.toIndex=i):this.tableScope.repaint(),(l=(r=this.tableScope.getEventListener()).onRowDragEnd)==null||l.call(r,o)}cancel(e){var s,o;const t=this.session;if(this.stopListening(),t){this.tableScope.repaint(),this.tableScope.announce(this.texts().rowDragCancelled());const i=this.createEvent("cancel",t.source,t.rows,t.rowIndices,void 0,t.outside,e);(o=(s=this.tableScope.getEventListener()).onRowDragEnd)==null||o.call(s,i)}}stopListening(){var t,s,o;(t=this.sessionAbortController)==null||t.abort(),this.sessionAbortController=void 0,this.pending=void 0,this.session=void 0,this.autoScrollFrame&&(cancelAnimationFrame(this.autoScrollFrame),this.autoScrollFrame=0),(s=this.ghost)==null||s.remove(),(o=this.indicator)==null||o.remove(),this.ghost=void 0,this.indicator=void 0,this.tableScope.hostElement.classList.remove("ge-table-row-drag-active","ge-table-row-drag-invalid")}destroy(){this.cancel()}createDragElements(e){const t=this.tableScope.getDomService(),s=this.tableScope.hostElement;this.ghost=t.setAriaHidden(t.createDivWithClass("ge-table-row-drag-ghost",s)),this.ghost.textContent=this.getGhostText(e),this.indicator=t.setAriaHidden(t.createDivWithClass("ge-table-row-drop-indicator",s)),s.classList.add("ge-table-row-drag-active")}getGhostText(e){const t=this.session.options.ghostText;if(t)return String(t(e)??"");const s=this.session.rowIndices[0],o=this.tableScope.tableModel.getBodyModel(),i=this.getHandleColumnIndex(s),l=(i>-1?o.getTextValueAt(s,i):"")||`Row ${s+1}`;return e.length>1?`${l} (+${e.length-1})`:l}renderDragElements(e){const t=this.session,s=this.ghost,o=this.indicator,i=this.tableScope.hostElement,r=i.getBoundingClientRect(),l=this.tableScope.getDomService();l.setStyle(s,"left",`${this.tableScope.clientXToHostX(e.clientX)+12}px`),s.style.top=`${e.clientY-r.top-i.clientTop+8}px`,i.classList.toggle("ge-table-row-drag-invalid",!t.target&&!t.outside);const a=t.target,c=this.tableScope.getBodyViewport();if(!a){o.style.display="none";return}const h=this.tableScope.tableModel.getBodyModel(),d=this.tableScope.getBodyRowTop(a.rowIndex),u=h.getRowHeight(a.rowIndex)+(a.position==="after"?this.tableScope.getBodyRowLayout().getExtraHeight(a.rowIndex):0),f=c.top-r.top-i.clientTop,g=a.position==="inside",p=f+d-c.contentScrollTop+(a.position==="after"?u:0),m=g?p:p-1,b=g?u:2,y=m+b>=f&&m<=f+c.height;o.classList.toggle("ge-table-row-drop-indicator-inside",g),l.applyStyle(o,{display:y?"block":"none",left:"0px",width:`${this.getMarkerWidth(c.width)}px`,top:`${m}px`,height:`${b}px`})}getMarkerWidth(e){const t=this.tableScope.tableModel,s=t.getPadding(),o=s.left+t.getContentWidthInPixel()+s.right;return o>0?Math.min(e,o):e}moveRows(e,t,s=!0){const o=this.tableScope,i=o.tableModel.getBodyModel(),r=it(e,i.getRowCount());if(!r.length||!i.moveRows||this.isSorted()||o.tableSheet||i.canMoveRows&&!i.canMoveRows(r,t))return-1;const l=Z(i),a=Io(r,t),c=r[r.length-1]-r[0]===r.length-1;if(!l&&c&&a===r[0])return-1;const h=l?r.map(p=>i.getRowByIndex(p)):[];if(!i.moveRows(r,t))return-1;o.afterRowsMoved();const d=l?this.findDisplayIndices(i,h):[];let u=l?-1:a;for(const p of d)(u<0||p<u)&&(u=p);const f=o.selectionModel();if(f&&f.hasSelection()&&(f.clear(),s&&r.length>1)){const p=o.tableModel.getColumnCount()-1;l?d.forEach(m=>f.addSelection(new M(m,0,m,p))):f.addSelection(new M(a,0,a+r.length-1,p))}const g=o.focusModel();if(g&&u>-1){const[,p]=g.getFocus();g.setFocus(u,p>-1?p:Math.max(0,this.getHandleColumnIndex(u)))}return o.repaintHard(),u>-1&&o.ensureRowIsVisible(u),o.stateService.markDirty("selection"),o.announce(this.texts().rowMoved(u+1,i.getRowCount())),u}findDisplayIndices(e,t){const s=new Set(t),o=[],i=e.getRowCount();for(let r=0;r<i&&o.length<s.size;r++)s.has(e.getRowByIndex(r))&&o.push(r);return o}moveByKeyboard(e){var p,m,b,y,C,S;const t=this.tableScope;if(this.session||t.isEditing())return!1;const s=t.focusModel(),o=t.tableModel.getBodyModel(),[i]=(s==null?void 0:s.getFocus())??[-1,-1],r=i<0||i>=o.getRowCount()?-1:this.getHandleColumnIndex(i);if(r<0)return!1;if(this.getHandleStateOfRow(i,r)==="disabled")return this.announceNotPossible(),!0;const l=Z(o),a=l?[i]:this.getDragRowIndices(i),c=l?this.getTreeKeyboardTarget(o,i,e):this.getFlatKeyboardTarget(a,e,o.getRowCount());if(!c)return!0;const h=this.getRows(a),d=this.createEvent("start","keyboard",h,a,void 0,!1);if((m=(p=t.getEventListener()).onRowDragStart)==null||m.call(p,d),d.defaultPrevented)return!0;const u=this.createEvent("move","keyboard",h,a,c,!1);(y=(b=t.getEventListener()).onRowDragMove)==null||y.call(b,u);const f=!u.defaultPrevented&&this.isValidTarget(a,c),g=this.createEvent("end","keyboard",h,a,f?c:void 0,!1);if(f&&this.isManaged()){const E=this.moveRows(a,c,!0);g.moved=E>-1,g.moved&&(g.toIndex=E)}return(S=(C=t.getEventListener()).onRowDragEnd)==null||S.call(C,g),!0}getFlatKeyboardTarget(e,t,s){if(t<0){const i=e[0];return i>0?{rowIndex:i-1,position:"before"}:void 0}const o=e[e.length-1];return o<s-1?{rowIndex:o+1,position:"after"}:void 0}getTreeKeyboardTarget(e,t,s){const o=e.getRowByIndex(t),i=e.rows??[],r=o!=null&&o.parent?o.parent.children??[]:i,l=r[r.indexOf(o)+s];if(!l)return;const[a]=this.findDisplayIndices(e,[l]);return a===void 0?void 0:{rowIndex:a,position:s<0?"before":"after"}}getDragRowIndices(e){const t=this.tableScope.tableModel.getBodyModel().getRowCount(),s=this.tableScope.selectionModel();if(this.options.multiRow&&(s!=null&&s.hasSelection())){const o=it(s.getMergedRowIndices(t),t);if(o.includes(e))return o}return[e]}getRows(e){const t=this.tableScope.tableModel.getBodyModel(),s=ne(t);return e.map(o=>{const i=t.getRowByIndex(o);return s&&U(i)&&!Mo(i)?i.data:i})}getHandleColumnIndex(e){const t=this.tableScope.tableModel,s=t.getBodyModel(),o=t.getColumnCount();for(let i=0;i<o;i++){const r=t.getColumnDef(i);if(r!=null&&r.rowDrag&&this.getHandleState(e,r,s)!=="none")return i}return-1}getHandleStateOfRow(e,t){const s=this.tableScope.tableModel;return this.getHandleState(e,s.getColumnDef(t),s.getBodyModel())}isSorted(){var e,t,s;return!!((s=(t=(e=this.tableScope.tableModel).getColumnDefs)==null?void 0:t.call(e))!=null&&s.some(o=>o.sortState==="asc"||o.sortState==="desc"))}isManaged(){var e;return((e=this.tableScope.tableOptions.rowDragOptions)==null?void 0:e.managed)!==!1}canModelMove(e){return!!e.moveRows&&!ne(e)&&!To(e)}createEvent(e,t,s,o,i,r,l){const a=Z(this.tableScope.tableModel.getBodyModel()),c=i&&!a?Io(o,i):-1;return new Pn(e,t,s,[...o],i?{...i}:void 0,c,r,this.isManaged(),l)}announceNotPossible(){this.tableScope.announce(this.texts().rowMoveNotPossible())}texts(){const e=this.tableScope.ariaTexts,t=new pe;return{rowDragStarted:s=>(e.rowDragStarted??t.rowDragStarted).call(e,s),rowMoved:(s,o)=>(e.rowMoved??t.rowMoved).call(e,s,o),rowMoveNotPossible:()=>(e.rowMoveNotPossible??t.rowMoveNotPossible).call(e),rowDragCancelled:()=>(e.rowDragCancelled??t.rowDragCancelled).call(e)}}}function Fc(n,e){return n===e||!!n&&!!e&&n.rowIndex===e.rowIndex&&n.position===e.position}class oo{constructor(){this.blockCommitOnInvalid=!0}static create(e){const t=new oo;return e&&typeof e=="object"&&e.blockCommitOnInvalid!==void 0&&(t.blockCommitOnInvalid=e.blockCommitOnInvalid),t}}function Mt(n,e){if(Object.is(n,e))return!0;const t=s=>s==null||s==="";return t(n)||t(e)?t(n)&&t(e):n instanceof Date&&e instanceof Date?n.getTime()===e.getTime()||isNaN(n.getTime())&&isNaN(e.getTime()):typeof n=="number"&&typeof e=="string"||typeof n=="string"&&typeof e=="number"?String(n)===String(e):!1}class Vn{constructor(){this.rows=new Map,this.count=0}set(e,t,s,o,i,r){let l=this.rows.get(e);const a=l==null?void 0:l.get(t),c=a?a.oldValue:s;return Mt(c,o)?a?(l.delete(t),l.size||this.rows.delete(e),this.count--,"removed"):"unchanged":(l||(l=new Map,this.rows.set(e,l)),l.set(t,{rowKey:e,property:t,oldValue:c,newValue:o,rawValue:i,error:r||void 0}),a?"changed":(this.count++,"added"))}put(e){let t=this.rows.get(e.rowKey);t||(t=new Map,this.rows.set(e.rowKey,t)),t.has(e.property)||this.count++,t.set(e.property,{...e})}get(e,t){var s;return this.count?(s=this.rows.get(e))==null?void 0:s.get(t):void 0}remove(e,t){const s=this.rows.get(e);return s!=null&&s.delete(t)?(s.size||this.rows.delete(e),this.count--,!0):!1}hasRow(e){return this.rows.has(e)}size(){return this.count}isEmpty(){return this.count===0}invalidCount(){let e=0;return this.rows.forEach(t=>t.forEach(s=>{s.error&&e++})),e}entries(){const e=[];return this.rows.forEach(t=>t.forEach(s=>e.push(s))),e}clear(){this.rows.clear(),this.count=0}}class _n{constructor(e,t,s,o,i=()=>[]){this.type=e,this.changes=t,this.pendingCount=s,this.invalidCount=o,this.pendingProvider=i}get pendingChanges(){return this.pendingProvider()}}function Bn(n,e,t,s){if(n===null||typeof n!="object")return!1;if(Array.isArray(n))return n[t]=s,!0;if(!(e!=null&&e.property))return!1;if(e.valueGetter)return!!e.valueSetter&&e.valueSetter(n,s)!==!1;const o=e.property.split(".");let i=n;for(let r=0;r<o.length-1;r++)if(i=i==null?void 0:i[o[r]],i===null||typeof i!="object")return!1;return i[o[o.length-1]]=s,!0}class $n{constructor(e){this.tableScope=e,this.pending=new Vn,this.started=!1}get options(){return oo.create(this.tableScope.tableOptions.batchEdit)}isPermanent(){return!!this.tableScope.tableOptions.batchEdit}isActive(){return this.started||this.isPermanent()}hasPending(){return!this.pending.isEmpty()}start(){return this.isActive()?!1:(this.started=!0,this.fire("start",[]),!0)}rowKeyOf(e){const t=this.tableScope.tableModel.getBodyModel().getRowByIndex(e);return t==null?e:U(t)?t.data??t:t}propertyOf(e){var t;return((t=this.tableScope.tableModel.getColumnDef(e))==null?void 0:t.property)||`#${e}`}getPendingAt(e,t){if(!this.pending.isEmpty())return this.pending.get(this.rowKeyOf(e),this.propertyOf(t))}getShownValue(e,t){const s=this.getPendingAt(e,t);return s?s.newValue:this.tableScope.getCellInput(e,t)}addPending(e){const t=[];for(const s of e){const o=this.rowKeyOf(s.rowIndex),i=this.propertyOf(s.columnIndex),r=this.tableScope.getCellInput(s.rowIndex,s.columnIndex);if(this.pending.set(o,i,r,s.value,s.rawValue,s.error)!=="unchanged"){const a=this.pending.get(o,i);t.push({row:typeof o=="number"?void 0:o,rowIndex:s.rowIndex,columnIndex:s.columnIndex,property:i,oldValue:a?a.oldValue:r,newValue:s.value,...s.error?{error:s.error}:{}})}}return t.length&&(this.fire("change",t),this.tableScope.announce(this.texts().pendingChanges(this.pending.size()))),t}getPendingEntry(e,t){return this.pending.get(e,t)}restorePending(e,t=!0){for(const a of e)a.entry?this.pending.put(a.entry):this.pending.remove(a.rowKey,a.property);if(!e.length)return[];const s=this.tableScope.tableModel.getBodyModel(),o=new Set(e.map(a=>a.rowKey)),i=new Map,r=s.getRowCount();for(let a=0;a<r&&i.size<o.size;a++){const c=this.rowKeyOf(a);o.has(c)&&!i.has(c)&&i.set(c,a)}const l=e.map(a=>{const c=typeof a.rowKey=="number"?a.rowKey:i.get(a.rowKey)??-1,h=this.findColumnIndex(a.property),d=c>=0&&h>=0?this.tableScope.getCellInput(c,h):void 0;return{row:typeof a.rowKey=="number"?void 0:a.rowKey,rowIndex:c,columnIndex:h,property:a.property,oldValue:a.entry?a.entry.oldValue:d,newValue:a.entry?a.entry.newValue:d}});return this.fire("change",l),t&&this.tableScope.announce(this.texts().pendingChanges(this.pending.size())),l}getPendingChanges(){if(this.pruneOrphans(),this.pending.isEmpty())return[];const e=this.createRowIndexMap();return this.pending.entries().map(t=>this.toChange(t,e))}commit(){var h;const e=this.tableScope;this.pruneOrphans();const t=this.pending.invalidCount();if(t&&this.options.blockCommitOnInvalid)return e.announce(this.texts().commitBlocked(t)),!1;const s=this.pending.entries(),o=s.length?this.createRowIndexMap():new Map,i=e.tableModel,r=[],l=[];for(const d of s){const u=this.findColumnIndex(d.property);if(u<0)continue;const f=typeof d.rowKey=="number"?d.rowKey:o.get(d.rowKey)??-1;if(f>-1)r.push({rowIndex:f,columnIndex:u,value:d.rawValue});else if(Bn(d.rowKey,i.getColumnDef(u),u,d.newValue)){const g=this.toChange(d,o);delete g.error,l.push(g)}}this.pending.clear(),this.isPermanent()||(this.started=!1),(h=e.undoService)==null||h.clear();const a=e.writeCells(r,"commit",{extraChanges:l,skipValidation:!0}),c=i.getBodyModel();return l.length&&ne(c)&&(c.regroup(),e.invalidateAggregates(),e.repaintHard()),this.fire("commit",a),e.announce(this.texts().changesCommitted(a.length)),!0}cancel(){var s;const e=this.getPendingChanges(),t=this.started;this.pending.clear(),(s=this.tableScope.undoService)==null||s.clear(),this.isPermanent()||(this.started=!1),this.tableScope.repaint(),(e.length||t)&&(this.fire("cancel",e),this.tableScope.announce(this.texts().changesDiscarded()))}pruneOrphans(){if(this.pending.isEmpty())return 0;const e=this.collectRowKeys();if(!e)return 0;let t=0;for(const s of this.pending.entries())typeof s.rowKey!="number"&&!e.has(s.rowKey)&&(this.pending.remove(s.rowKey,s.property),t++);return t}collectRowKeys(){const e=this.tableScope.tableModel.getBodyModel();if(Z(e)){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(e.rows),t}return typeof e.getAllRows=="function"?new Set(e.getAllRows()):void 0}toChange(e,t){const s=typeof e.rowKey=="number"?e.rowKey:t.get(e.rowKey)??-1;return{row:typeof e.rowKey=="number"?void 0:e.rowKey,rowIndex:s,columnIndex:this.findColumnIndex(e.property),property:e.property,oldValue:e.oldValue,newValue:e.newValue,...e.error?{error:e.error}:{}}}findColumnIndex(e){const s=this.tableScope.tableModel.getColumnCount();for(let o=0;o<s;o++)if(this.propertyOf(o)===e)return o;return-1}createRowIndexMap(){const e=new Map,t=this.tableScope.tableModel.getBodyModel().getRowCount();for(let s=0;s<t;s++){const o=this.rowKeyOf(s);this.pending.hasRow(o)&&!e.has(o)&&e.set(o,s)}return e}fire(e,t){var o,i;const s=new _n(e,t,this.pending.size(),this.pending.invalidCount(),()=>this.getPendingChanges());(i=(o=this.tableScope.getEventListener()).onBatchEditChanged)==null||i.call(o,s)}texts(){return this.tableScope.getEditTexts()}}const Hn=/^(\d{4})-(\d{2})-(\d{2})$/,Lc=/^-?\d+(\.\d+)?$/,Gn=/^(.*\D)(\d+)$/,Oc=864e5;function Wn(n,e,t=!1,s="auto"){const o=n.length;if(e<1||o<1)return[];const i=Array.from({length:e},(a,c)=>t?-(c+1):c+1),r=()=>i.map(a=>Pc(n,a));if(s==="copy")return r();const l=Kn(n,s==="alternate");return l?i.map(l):r()}function Un(n,e="auto"){return e!=="copy"&&n.length>0&&!!Kn(n,e==="alternate")}function Pc(n,e){const t=n.length;return e>0?n[(e-1)%t]:n[t-1-(-e-1)%t]}function Kn(n,e){const s=n.length===1?e:!e,o=!e;if(n.every(Nc))return s?ir(n,i=>i):void 0;if(n.every(i=>typeof i=="string"&&Lc.test(i))){const i=n;if(i.some(c=>!Number.isSafeInteger(Math.trunc(Number(c)))))return;const r=Math.max(...i.map(c=>{var h;return((h=c.split(".")[1])==null?void 0:h.length)??0})),l=Math.max(...i.map(c=>{const h=c.replace("-","").split(".")[0];return h.length>1&&h.startsWith("0")?h.length:0})),a=c=>{const h=c.toFixed(r);if(!l)return h;const d=h.startsWith("-"),[u,f]=h.replace("-","").split(".");return(d?"-":"")+u.padStart(l,"0")+(f!==void 0?"."+f:"")};return s?ir(i.map(Number),a):void 0}if(n.every(or))return o?_c(n):void 0;if(n.every(i=>typeof i=="string"&&Hn.test(i)&&or(Yn(i))))return o?Bc(n):void 0;if(n.every(i=>typeof i=="string"&&Gn.test(i)))return o?$c(n):void 0}function Nc(n){return typeof n=="number"&&Number.isFinite(n)}function or(n){return n instanceof Date&&!isNaN(n.getTime())}function Co(n){const e=Number(n.toPrecision(15));return e===0?0:e}function ir(n,e){const t=n.length,s=n[t-1];if(t===1)return u=>e(Co(s+u));const o=n[1]-n[0];if(n.every((u,f)=>f===0||Math.abs(u-n[f-1]-o)<=1e-9*Math.max(1,Math.abs(o))))return u=>e(Co(u>0?s+o*u:n[0]+o*u));const r=(t-1)/2,l=n.reduce((u,f)=>u+f,0)/t;let a=0,c=0;n.forEach((u,f)=>{a+=(f-r)*(u-l),c+=(f-r)**2});const h=a/c,d=l-h*r;return u=>{const f=u>0?t-1+u:u;return e(Co(d+h*f))}}function Vc(n){return n.d===zn(n.y,n.m)}function zn(n,e){return io(n,e+1,0).getUTCDate()}function io(n,e,t){const s=new Date(0);return s.setUTCFullYear(n,e,t),s}function Bt(n){return n.y*12+n.m}function rr(n){return Math.round(io(n.y,n.m,n.d).getTime()/Oc)}function jn(n){const e=n.length;if(e===1)return{months:0,days:1,monthEnd:!1};const t=n.every(Vc),s=n.every(r=>r.d===n[0].d),o=Bt(n[1])-Bt(n[0]);if((s||t)&&o!==0&&n.every((r,l)=>l===0||Bt(r)-Bt(n[l-1])===o))return{months:o,days:0,monthEnd:t&&!s};const i=rr(n[e-1])-rr(n[0]);return{months:0,days:Math.round(i/(e-1)),monthEnd:!1}}function Xn(n,e,t){const s=e>0?n[n.length-1]:n[0];if(t.months){const i=Bt(s)+t.months*e,r=Math.floor(i/12),l=i-r*12,a=zn(r,l);return{y:r,m:l,d:t.monthEnd?a:Math.min(s.d,a)}}const o=io(s.y,s.m,s.d+t.days*e);return{y:o.getUTCFullYear(),m:o.getUTCMonth(),d:o.getUTCDate()}}function _c(n){const e=n.map(s=>({y:s.getFullYear(),m:s.getMonth(),d:s.getDate()})),t=jn(e);return s=>{const o=Xn(e,s,t),i=n[s>0?n.length-1:0];return new Date(o.y,o.m,o.d,i.getHours(),i.getMinutes(),i.getSeconds(),i.getMilliseconds())}}function Yn(n){const[,e,t,s]=Hn.exec(n),o=io(Number(e),Number(t)-1,Number(s));return o.getUTCDate()===Number(s)&&o.getUTCMonth()===Number(t)-1?o:new Date(NaN)}function Bc(n){const e=n.map(s=>{const o=Yn(s);return{y:o.getUTCFullYear(),m:o.getUTCMonth(),d:o.getUTCDate()}}),t=jn(e);return s=>{const o=Xn(e,s,t);return`${String(o.y).padStart(4,"0")}-${String(o.m+1).padStart(2,"0")}-${String(o.d).padStart(2,"0")}`}}function $c(n){const e=n.map(r=>{const[,l,a]=Gn.exec(r);return{prefix:l,digits:a,num:Number(a)}}),t=e[0].prefix;if(e.some(r=>r.prefix!==t)||e.some(r=>!Number.isSafeInteger(r.num)))return;const s=e.length,o=s===1?1:(e[s-1].num-e[0].num)/(s-1);if(!Number.isInteger(o))return;const i=Math.max(...e.map(r=>r.digits.length>1&&r.digits.startsWith("0")?r.digits.length:0));return r=>{const l=r>0?e[s-1].num:e[0].num,a=Math.abs(l+o*r);return t+String(a).padStart(i,"0")}}function Ei(n,e,t){const{r1:s,c1:o,r2:i,c2:r}=n;switch(e){case"down":return new M(s,o,i+t,r);case"up":return new M(s-t,o,i,r);case"right":return new M(s,o,i,r+t);default:return new M(s,o-t,i,r)}}function Jn(n){var f;const{source:e,direction:t,count:s,getValue:o}=n,i=n.mode??"auto",r=t==="down"||t==="up",l=t==="up"||t==="left",a=[];if(s<1)return a;const[c,h]=r?[e.c1,e.c2]:[e.r1,e.r2],[d,u]=r?[e.r1,e.r2]:[e.c1,e.c2];for(let g=c;g<=h;g++){const p=C=>r?[C,g]:[g,C],m=[];for(let C=d;C<=u;C++)m.push(o(...p(C)));const b=Wn(m,s,l,i),y=Un(m,i);for(let C=0;C<s;C++){const S=l?d-1-C:u+1+C,[E,x]=p(S);if(n.isFillable&&!n.isFillable(E,x))continue;let R=b[C];if(n.fillValue){const L=((f=n.getCellInfo)==null?void 0:f.call(n,E,x))??{row:void 0,property:""},v=n.fillValue({sourceValues:m,step:l?-(C+1):C+1,direction:t,rowIndex:E,columnIndex:x,property:L.property,row:L.row,defaultValue:R,copy:!y});v!==void 0&&(R=v)}a.push({rowIndex:E,column:x,value:R})}}return a}const nr="fill-handle";class qn{constructor(e){this.tableScope=e,this.autoScrollFrame=0,this.suppressClick=!1,this.shortcutsSet=!1;const t=e.listenerAbortController.signal;e.hostElement.addEventListener("pointerdown",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onPointerDown(s)},{signal:t}),e.hostElement.addEventListener("click",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onClickCapture(s)},{capture:!0,signal:t}),e.hostElement.addEventListener("dblclick",s=>{var o;!((o=e.isEventInDetail)!=null&&o.call(e,s))&&this.isHandle(s.target)&&s.stopPropagation()},{capture:!0,signal:t})}isFilling(){return!!this.session}update(){var r,l;const e=this.tableScope,t=e.getFillHandleOptions();if(!t){this.removeHandle(),this.shortcutsSet&&(this.shortcutsSet=!1,this.tableScope.setHostKeyShortcuts(void 0));return}this.updateHostShortcuts(t);const s=((r=this.session)==null?void 0:r.source)??e.getFillSourceRange(),o=s&&!e.isEditing()&&!e.tableOverlay.isBlocking()&&!((l=e.rowDragService)!=null&&l.isDragging())?this.getCornerOf(s):void 0;if(!o){this.handle&&(this.handle.style.display="none");return}const i=this.ensureHandle();i.style.display="block",e.getDomService().setStyle(i,"left",`${o.x}px`),i.style.top=`${o.y}px`,this.session&&this.renderPreview()}getCornerOf(e){const t=this.tableScope;let s=e.c2;for(;s>e.c1&&t.tableModel.getColumnWidth(s)<=0;)s--;if(t.tableModel.getColumnWidth(s)<=0)return;const o=t.getBodyCellRectInHost(e.r2,s),i=o.left+o.width,r=o.top+o.height;return i>=o.clipLeft&&i<=o.clipRight+.5&&r>=o.clipTop&&r<=o.clipBottom+.5?{x:i,y:r}:void 0}ensureHandle(){if(!this.handle||!this.handle.isConnected){const e=this.tableScope.getDomService();this.handle=e.setAriaHidden(e.createDivWithClass("ge-table-fill-handle",this.tableScope.hostElement)),e.domService.setAttribute(this.handle,"data-ge-action",nr)}return this.handle}removeHandle(){var e;(e=this.handle)==null||e.remove(),this.handle=void 0}updateHostShortcuts(e){const s=typeof navigator<"u"&&navigator.platform.indexOf("Mac")>-1?"Meta":"Control",o=[];e.direction!=="horizontal"&&o.push(`${s}+D`),e.direction!=="vertical"&&o.push(`${s}+R`),this.tableScope.setHostKeyShortcuts(o.join(" ")),this.shortcutsSet=!0}isHandle(e){return e instanceof Element&&!!e.closest(`[data-ge-action="${nr}"]`)&&this.tableScope.hostElement.contains(e)}onPointerDown(e){if(this.session||this.pending||e.pointerType==="mouse"&&e.button!==0||!this.isHandle(e.target))return;e.preventDefault();const t=this.tableScope.getFillSourceRange();!t||this.tableScope.isEditing()||(this.pending={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,source:t},this.listenToDocument())}listenToDocument(){this.sessionAbortController=new AbortController;const e=this.sessionAbortController.signal,t=this.tableScope.hostElement.ownerDocument;t.addEventListener("pointermove",s=>this.onPointerMove(s),{signal:e}),t.addEventListener("pointerup",s=>this.onPointerUp(s),{signal:e}),t.addEventListener("pointercancel",s=>{this.pending&&s.pointerId===this.pending.pointerId&&this.cancel()},{signal:e}),t.addEventListener("keydown",s=>{s.key==="Escape"&&(this.session||this.pending)&&(s.preventDefault(),s.stopPropagation(),this.cancel())},{capture:!0,signal:e}),this.tableScope.scrollViewport.addEventListener("scroll",()=>{var s;(s=this.session)!=null&&s.lastEvent&&!this.autoScrollFrame&&this.updateTarget(this.session.lastEvent)},{signal:e})}onPointerMove(e){if(!(!this.pending||e.pointerId!==this.pending.pointerId)){if(!this.session){const t=this.tableScope.getFillHandleOptions();if(!t){this.stopListening();return}if(Math.hypot(e.clientX-this.pending.startX,e.clientY-this.pending.startY)<t.dragThresholdInPx)return;this.session={source:this.pending.source,options:t,count:0,speedX:0,speedY:0,remainderX:0,remainderY:0};const s=this.tableScope.getDomService();this.preview=s.setAriaHidden(s.createDivWithClass("ge-table-fill-preview",this.tableScope.hostElement)),this.tableScope.hostElement.classList.add("ge-table-fill-active")}e.preventDefault(),this.updateTarget(e)}}onPointerUp(e){if(!this.pending||e.pointerId!==this.pending.pointerId)return;const t=this.session;if(!t){this.stopListening(),this.suppressNextClick();return}this.updateTarget(e),this.suppressNextClick();const{source:s,direction:o,count:i}=t;this.stopListening(),o&&i>0&&!this.tableScope.tableOverlay.isBlocking()&&!this.tableScope.isEditing()?this.tableScope.fillRange(s,o,i,e.altKey||e.ctrlKey?"alternate":"auto"):this.tableScope.repaint()}suppressNextClick(){this.suppressClick=!0,setTimeout(()=>this.suppressClick=!1,0)}onClickCapture(e){(this.suppressClick||this.isHandle(e.target))&&(this.suppressClick=!1,e.stopPropagation(),e.preventDefault())}updateTarget(e){const t=this.session;t.lastEvent=e;const s=this.tableScope,o=s.hostElement,i=o.getBoundingClientRect(),r=s.clientXToHostX(e.clientX),l=e.clientY-i.top-o.clientTop,[a,c]=s.getBodyCellAtHostPoint(r,l),h=t.source,d=a>h.r2?a-h.r2:a<h.r1?a-h.r1:0,u=c>h.c2?c-h.c2:c<h.c1?c-h.c1:0,f=t.options.direction,g=f==="vertical"||f==="both"&&Math.abs(d)>=Math.abs(u),p=g?d:u;t.direction=p===0?void 0:g?p>0?"down":"up":p>0?"right":"left",t.count=Math.abs(p),this.renderPreview(),this.updateAutoScroll(r,l)}renderPreview(){const e=this.session,t=this.preview;if(!e||!t)return;const s=e.direction?Ei(e.source,e.direction,e.count):e.source,o=this.tableScope,i=o.getBodyCellRectInHost(s.r1,s.c1),r=o.getBodyCellRectInHost(s.r2,s.c2),l=Math.max(i.top,i.clipTop),a=Math.min(r.top+r.height,r.clipBottom),c=Math.max(i.left,i.clipLeft),h=Math.min(r.left+r.width,r.clipRight);o.getDomService().applyStyle(t,{display:a>l&&h>c?"block":"none",left:`${c}px`,top:`${l}px`,width:`${Math.max(0,h-c)}px`,height:`${Math.max(0,a-l)}px`})}updateAutoScroll(e,t){const s=this.session,{autoScrollZoneInPx:o,autoScrollMaxSpeedInPx:i}=s.options,r=this.tableScope,l=r.tableModel.getPadding(),a=r.hostElement,c=g=>Math.max(1,Math.round(i*Math.min(1,g/o)**2)),h=l.top,d=a.clientHeight-l.bottom,u=l.left,f=a.clientWidth-l.right;s.speedY=o<=0||i<=0?0:t<h+o?-c(h+o-t):t>d-o?c(t-(d-o)):0,s.speedX=o<=0||i<=0?0:e<u+o&&e>=u-o?-c(u+o-e):e>f-o?c(e-(f-o)):0,(s.speedX||s.speedY)&&!this.autoScrollFrame?this.autoScrollFrame=requestAnimationFrame(()=>this.autoScrollStep()):!s.speedX&&!s.speedY&&(s.lastFrameTime=void 0,s.remainderX=0,s.remainderY=0)}autoScrollStep(){this.autoScrollFrame=0;const e=this.session;if(!e||!e.speedX&&!e.speedY)return;const t=this.tableScope.scrollViewport,s=performance.now(),o=e.lastFrameTime?Math.min(4,(s-e.lastFrameTime)/(1e3/60)):1;e.lastFrameTime=s;const i=e.speedY*o*this.tableScope.getScrollerToContentRatioY()+e.remainderY,r=e.speedX*o+e.remainderX,l=Math.trunc(i),a=Math.trunc(r);e.remainderY=i-l,e.remainderX=r-a;const c=this.tableScope,h=t.scrollTop,d=c.getViewportScrollLeft();t.scrollTop=h+l,c.setViewportScrollLeft(d+a),(t.scrollTop!==h||c.getViewportScrollLeft()!==d)&&this.tableScope.adjustAfterScrolling(),this.updateTarget(e.lastEvent)}cancel(){const e=!!this.session;this.stopListening(),e&&this.tableScope.repaint()}stopListening(){var e,t;(e=this.sessionAbortController)==null||e.abort(),this.sessionAbortController=void 0,this.pending=void 0,this.session=void 0,this.autoScrollFrame&&(cancelAnimationFrame(this.autoScrollFrame),this.autoScrollFrame=0),(t=this.preview)==null||t.remove(),this.preview=void 0,this.tableScope.hostElement.classList.remove("ge-table-fill-active")}destroy(){this.stopListening(),this.removeHandle()}}class ro{constructor(){this.detailRenderer=()=>{},this.isMaster=void 0,this.detailHeight="auto",this.estimatedDetailHeight=200,this.toggleColumn=void 0,this.maxRenderedDetails=50,this.getRowId=void 0}static create(e){const t=new ro;for(const[s,o]of Object.entries(e??{}))o!==void 0&&(t[s]=o);return t}}const Hc="a[href], button, input, select, textarea, iframe, [contenteditable]:not([contenteditable='false']), [tabindex]";class Zn{constructor(e,t){var i;this.scope=e,this.createNestedScope=t,this.entries=new Map,this.byIndex=new Map,this.visibleNow=new Set,this.renderPass=0,this.renderedCount=0,this.toggleColumnIndex=-1,this.resizeFrame=0,this.destroyed=!1;const s=(i=e.tableOptions)==null?void 0:i.masterDetail;this.options=ro.create(s);const o=Z(e.tableModel.getBodyModel());s&&o&&console.warn("GuiExpert Table – masterDetail is ignored: it works only with flat body models (no tree, row grouping or pivot table)."),s&&!s.detailRenderer&&console.warn("GuiExpert Table – masterDetail without a detailRenderer: the detail rows stay empty."),this.active=!!s&&!o,this.active&&this.createLayer()}isActive(){return this.active}hasExpanded(){return this.active&&this.entries.size>0}getLayer(){return this.layer}isInLayer(e){var o;const t=this.layer;if(!t)return!1;const s=(o=e.composedPath)==null?void 0:o.call(e);return s!=null&&s.length?s.includes(t):e.target instanceof Node&&t.contains(e.target)}keyOf(e,t){var s,o;if(e!=null){const i=(o=(s=this.scope.tableOptions)==null?void 0:s.autoRestoreOptions)==null?void 0:o.getRowId,r=this.options.getRowId??(i&&!xn(i)?i:void 0);if(r)try{const l=r(e,t);if(l!=null)return l}catch{}if(typeof e=="object"||typeof e=="function")return e}return t}isMasterAt(e){if(!this.active||e<0)return!1;const t=this.getBody();if(e>=t.getRowCount())return!1;const s=this.options.isMaster;if(!s)return!0;try{return!!s(t.getRowByIndex(e),e)}catch(o){return console.error(o),!1}}isExpandedAt(e){return!this.hasExpanded()||e<0?!1:this.entries.has(this.keyOf(this.getBody().getRowByIndex(e),e))}isExpanded(e){const[t,s]=this.resolve(e);return this.hasExpanded()&&this.entries.has(this.keyOf(t,s))}setExpanded(e,t,s="api"){if(!this.active)return!1;const[o,i]=this.resolve(e),r=this.keyOf(o,i);if(t){if(this.entries.has(r)||o===void 0&&i<0||(i>=0?!this.isMasterAt(i):!this.isMasterRow(o)))return!1;const l={key:r,row:o,rowIndex:i,lastSeen:0,renderCount:0};this.entries.set(r,l);const a=i>=0&&this.scope.setBodyRowExtra(i,this.heightOf(l));a&&this.byIndex.set(i,l),this.scope.onDetailToggled(o,i,t,s,!0,a)}else{const l=this.entries.get(r);if(!l)return!1;this.destroyContent(l),this.entries.delete(r);const a=l.rowIndex>=0&&this.byIndex.get(l.rowIndex)===l&&this.scope.setBodyRowExtra(l.rowIndex,0);a&&this.byIndex.delete(l.rowIndex),this.scope.onDetailToggled(o,i,t,s,!0,a)}return!0}expandAll(){if(!this.active)return 0;const e=this.getBody(),t=e.getRowCount();let s=0;for(let o=0;o<t;o++){if(!this.isMasterAt(o))continue;const i=e.getRowByIndex(o),r=this.keyOf(i,o);this.entries.has(r)||(this.entries.set(r,{key:r,row:i,rowIndex:o,lastSeen:0,renderCount:0}),s++)}return s&&this.scope.onDetailToggled(void 0,-1,!0,"api",!1),s}collapseAll(){const e=this.entries.size;return e?(this.clearAll(),this.scope.onDetailToggled(void 0,-1,!1,"api",!1),e):0}getExpandedRows(){return Array.from(this.entries.values(),e=>e.row)}setExpandedRows(e,t="api"){if(!this.active)return!1;const s=new Map;for(const i of e)s.set(this.keyOf(i,-1),i);let o=!1;for(const[i,r]of Array.from(this.entries))s.has(i)||(this.destroyContent(r),this.entries.delete(i),o=!0);for(const[i,r]of Array.from(s))!this.entries.has(i)&&this.isMasterRow(r)&&(this.entries.set(i,{key:i,row:r,rowIndex:-1,lastSeen:0,renderCount:0}),o=!0);return o&&this.scope.onDetailToggled(void 0,-1,!0,t,!1),o}refresh(e){const[t,s]=this.resolve(e),o=this.entries.get(this.keyOf(t,s));return o?(this.destroyContent(o),this.scope.repaint(),!0):!1}getDetailElement(e){var o,i;const[t,s]=this.resolve(e);return(i=(o=this.entries.get(this.keyOf(t,s)))==null?void 0:o.content)==null?void 0:i.cell}getMasterRowIndexOf(e){var t,s;if(!e||!((t=this.layer)!=null&&t.contains(e)))return-1;for(const o of Array.from(this.entries.values()))if((s=o.content)!=null&&s.rowDiv.contains(e))return o.rowIndex;return-1}computeExtras(){var a;if(this.byIndex=new Map,!this.hasExpanded())return;const e=this.getBody(),t=e.getRowCount();for(const c of Array.from(this.entries.values()))c.rowIndex=-1;const s=[],o=[];let i=0;const r=(a=e.getFilteredRows)==null?void 0:a.call(e),l=Array.isArray(r)&&r.length===t?c=>r[c]:c=>e.getRowByIndex(c);for(let c=0;c<t&&i<this.entries.size;c++){const h=l(c),d=this.entries.get(this.keyOf(h,c));!d||d.rowIndex>=0||this.options.isMaster&&!this.isMasterAt(c)||(i++,d.rowIndex=c,d.row=h,this.byIndex.set(c,d),s.push(c),o.push(this.heightOf(d)))}return i<this.entries.size&&this.pruneRemovedRows(e),{rowIndices:s,heights:o}}startRenderPass(){this.toggleColumnIndex=this.active?this.computeToggleColumnIndex():-1}layoutVisible(e){if(!this.active||this.destroyed)return;this.renderPass++;const t=new Set;for(let o=0;o+2<e.length;o+=3){const i=this.byIndex.get(e[o]);if(!i)continue;i.content&&i.content.row!==i.row&&this.destroyContent(i);const r=i.content??this.createContent(i,e[o+1],e[o+2]);this.place(r,e[o+1],e[o+2]),i.lastSeen=this.renderPass,t.add(i)}for(const o of Array.from(this.visibleNow))!t.has(o)&&o.content&&this.park(o.content,o.rowIndex);this.visibleNow=t,this.enforceLimit();const s=t.size?"rowgroup":"presentation";this.layer&&this.layer.getAttribute("role")!==s&&this.scope.getDomService().domService.setAttribute(this.layer,"role",s)}setBounds(e,t,s,o){const i=this.layer;if(!i)return;const r=i.style;this.scope.getDomService().setStyle(i,"left",`${e}px`),r.top=`${t}px`,r.width=`${Math.max(0,s)}px`,r.height=`${Math.max(0,o)}px`}decorateCell(e,t,s){if(s!==this.toggleColumnIndex||!this.isMasterAt(t))return;const o=this.isExpandedAt(t),i=this.scope.getDomService(),r=i.domService;r.addClass(e,"ge-table-detail-toggle-cell");const l=r.createElement("div");r.addClass(l,"ge-table-detail-toggle"),o&&r.addClass(l,"ge-table-detail-toggle-expanded"),r.setAttribute(l,"data-ge-action","toggle-detail"),r.setAttribute(l,"data-area","body"),r.setAttribute(l,"data-row-index",`${t}`),r.setAttribute(l,"data-col-index",`${s}`),i.setAriaHidden(l),e.insertBefore(l,e.firstChild)}destroy(){var e;this.destroyed||(this.destroyed=!0,this.resizeFrame&&(cancelAnimationFrame(this.resizeFrame),this.resizeFrame=0),this.clearAll(),(e=this.layer)==null||e.remove(),this.layer=void 0)}getBody(){return this.scope.tableModel.getBodyModel()}getAllRows(e){var s;const t=(s=e.getAllRows)==null?void 0:s.call(e);return Array.isArray(t)?t:void 0}isMasterRow(e){const t=this.options.isMaster;try{return e!==void 0&&(!t||!!t(e,-1))}catch(s){return console.error(s),!1}}resolve(e){var r;const t=this.getBody();if(typeof e=="number")return e<0||e>=t.getRowCount()?[void 0,-1]:[t.getRowByIndex(e),e];const s=this.entries.get(this.keyOf(e,-1));if(s&&s.rowIndex>=0&&t.getRowByIndex(s.rowIndex)===e)return[e,s.rowIndex];const o=(r=t.getFilteredRows)==null?void 0:r.call(t);if(Array.isArray(o)&&o.length===t.getRowCount())return[e,o.indexOf(e)];const i=t.getRowCount();for(let l=0;l<i;l++)if(t.getRowByIndex(l)===e)return[e,l];return[e,-1]}heightOf(e){const t=this.detailHeightOf(e);return t==="auto"?e.measuredHeight??this.options.estimatedDetailHeight:Math.max(0,t)}detailHeightOf(e){const t=this.options.detailHeight;if(typeof t=="function")try{const s=t(e.row,e.rowIndex);return s==="auto"||typeof s=="number"&&isFinite(s)?s:"auto"}catch(s){return console.error(s),"auto"}return t==="auto"||typeof t=="number"&&isFinite(t)?t:"auto"}computeToggleColumnIndex(){var o,i;const e=this.options.toggleColumn,t=this.scope.tableModel;if(typeof e=="number")return e;if(typeof e=="string")return(((o=t.getColumnDefs)==null?void 0:o.call(t))??[]).findIndex(r=>r.property===e);const s=this.scope.getFirstDataColumnIndex();return(i=this.scope.tableOptions)!=null&&i.showCheckboxWihoutExtraColumn?s:t.isRowCheckboxVisible()?s+1:s}pruneRemovedRows(e){const t=this.getAllRows(e);if(!t)return;const s=new Set;t.forEach((o,i)=>s.add(this.keyOf(o,i)));for(const[o,i]of Array.from(this.entries))i.rowIndex<0&&!s.has(o)&&(this.destroyContent(i),this.entries.delete(o))}createLayer(){const e=this.scope,s=e.getDomService().domService,o=s.createElement("div");s.addClass(o,"ge-table-detail-layer"),s.setAttribute(o,"id",e.ariaIds.detailRowGroup()),s.setAttribute(o,"role","presentation"),s.appendChild(e.hostElement,o),this.layer=o;const i=e.listenerAbortController.signal;o.addEventListener("wheel",r=>this.onWheel(r),{passive:!1,signal:i}),e.hostElement.addEventListener("keydown",r=>this.onHostKeyDown(r),{signal:i}),e.hostElement.addEventListener("focus",r=>this.onHostFocus(r),{signal:i})}createContent(e,t,s){const o=this.scope,i=o.getDomService().domService,r=i.createElement("div");i.addClass(r,"ge-table-detail-row"),i.setAttribute(r,"role","row");const l=i.createElement("div");i.addClass(l,"ge-table-detail-cell"),i.setAttribute(l,"role","gridcell"),i.setAttribute(l,"aria-colspan",`${Math.max(1,o.getAriaGridInfo().colCount)}`),i.appendChild(r,l);const a=this.detailHeightOf(e)==="auto";a&&i.addClass(r,"ge-table-detail-row-auto"),i.appendChild(this.layer,r);const c={rowDiv:r,cell:l,row:e.row,auto:a,abort:new AbortController,tables:[],parked:!1};e.content=c,this.place(c,t,s),this.renderedCount++;const h=e.renderCount>0;e.renderCount++;const d=this,u={row:e.row,rowIndex:e.rowIndex,tableApi:o.getApi(),recreated:h,signal:c.abort.signal,createTable(f){return d.createNestedTable(c,a,f)}};try{const f=this.options.detailRenderer,g=typeof f=="function"?f(l,e.row,u):f==null?void 0:f.render(l,e.row,u);typeof g=="function"&&(c.cleanup=g)}catch(f){console.error(f)}return a&&typeof ResizeObserver<"u"&&(c.resizeObserver=new ResizeObserver(f=>this.onResize(e,c,f)),c.resizeObserver.observe(r)),c}createNestedTable(e,t,s){const o=this.scope.getDomService().domService,i=o.createElement("div");o.addClass(i,"ge-table-detail-table");const r=s.height??(t?this.options.estimatedDetailHeight:"100%");i.style.height=typeof r=="number"?`${r}px`:r,o.appendChild(e.cell,i);const l=this.createNestedScope(i,s.tableModel,s.tableOptions,s.eventListener);return e.tables.push(l),l.firstInit(),l.getApi()}place(e,t,s){const o=e.rowDiv.style;e.parked&&(e.parked=!1,e.rowDiv.classList.remove("ge-table-detail-row-parked")),e.top!==t&&(e.top=t,o.top=`${t}px`),!e.auto&&e.height!==s&&(e.height=s,o.height=`${s}px`)}park(e,t=-1){e.parked||(this.releaseFocus(e,t),e.parked=!0,e.rowDiv.classList.add("ge-table-detail-row-parked"))}releaseFocus(e,t){var o;const s=(o=e.rowDiv.ownerDocument)==null?void 0:o.activeElement;s&&e.rowDiv.contains(s)&&this.scope.takeFocusFromDetail(t)}onResize(e,t,s){var a,c;if(t.parked||e.content!==t||this.destroyed)return;const o=s[s.length-1],i=(a=o==null?void 0:o.borderBoxSize)==null?void 0:a[0],r=i?i.blockSize:((c=o==null?void 0:o.target)==null?void 0:c.offsetHeight)??0,l=Math.max(1,Math.ceil(r));e.measuredHeight!==l&&(e.measuredHeight=l,e.rowIndex>=0&&this.scope.getBodyRowLayout().setExtraHeight(e.rowIndex,l),this.resizeFrame||(this.resizeFrame=requestAnimationFrame(()=>{this.resizeFrame=0,this.destroyed||this.scope.onDetailHeightChanged()})))}enforceLimit(){const e=Math.max(0,this.options.maxRenderedDetails);if(this.renderedCount<=e||this.renderedCount<=this.visibleNow.size)return;const t=Array.from(this.entries.values()).filter(s=>s.content&&!this.visibleNow.has(s)).sort((s,o)=>s.lastSeen-o.lastSeen);for(const s of t){if(this.renderedCount<=e)break;this.destroyContent(s)}}destroyContent(e){var s,o;const t=e.content;if(t){e.content=void 0,this.renderedCount--,this.visibleNow.delete(e),this.destroyed||this.releaseFocus(t,e.rowIndex),(s=t.resizeObserver)==null||s.disconnect();try{(o=t.cleanup)==null||o.call(t)}catch(i){console.error(i)}t.abort.abort();for(const i of t.tables)try{i.destroy()}catch(r){console.error(r)}t.rowDiv.remove()}}clearAll(){for(const e of Array.from(this.entries.values()))this.destroyContent(e);this.entries.clear(),this.byIndex.clear(),this.visibleNow.clear()}onWheel(e){if(e.defaultPrevented||e.ctrlKey)return;const t=this.scope.scrollViewport,s=e.deltaMode===1?16:e.deltaMode===2?t.clientHeight:1,o=e.deltaY*s,i=e.deltaX*s;if(this.canScrollInside(e.target,i,o))return;const r=t.scrollTop,l=t.scrollLeft;o&&(t.scrollTop=r+o*this.scope.getScrollerToContentRatioY()),i&&(t.scrollLeft=l+i),(t.scrollTop!==r||t.scrollLeft!==l)&&e.preventDefault()}canScrollInside(e,t,s){let o=e instanceof Element?e:null;for(;o&&o!==this.layer;){if(o instanceof HTMLElement){const i=getComputedStyle(o);if(s&&/(auto|scroll)/.test(i.overflowY)&&o.scrollHeight>o.clientHeight&&(s>0?o.scrollTop+o.clientHeight<o.scrollHeight-1:o.scrollTop>0)||t&&/(auto|scroll)/.test(i.overflowX)&&o.scrollWidth>o.clientWidth&&Br(o,t,i.direction==="rtl"))return!0}o=o.parentElement}return!1}hasTabTarget(e){var o;const t=(o=this.byIndex.get(e))==null?void 0:o.content,s=this.byIndex.get(e);return!!s&&!!t&&!t.parked&&this.visibleNow.has(s)&&!!this.findFocusable(t.cell)}onHostKeyDown(e){var r;if(e.key!=="Tab"||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||e.defaultPrevented||e.target!==this.scope.hostElement||this.isInLayer(e))return;const t=(r=this.scope.focusModel())==null?void 0:r.getFocus(),s=t?this.byIndex.get(t[0]):void 0,o=s==null?void 0:s.content;if(!o||o.parked||!this.visibleNow.has(s))return;const i=this.findFocusable(o.cell);i&&(e.preventDefault(),i.focus())}onHostFocus(e){const t=e.relatedTarget instanceof Node?e.relatedTarget:null,s=this.getMasterRowIndexOf(t);s>=0&&this.scope.focusDetailMaster(s)}findFocusable(e){for(const t of Array.from(e.querySelectorAll(Hc))){const s=t.getAttribute("tabindex");if(!(s!==null&&Number(s)<0||t.disabled)&&t.getClientRects().length)return t}}}class Qn{constructor(e,t,s,o){this.row=e,this.rowIndex=t,this.expanded=s,this.source=o}}class ss{constructor(){this.direction="both",this.fillValue=void 0,this.maxCells=1e5,this.dragThresholdInPx=3,this.autoScrollZoneInPx=40,this.autoScrollMaxSpeedInPx=24}static create(e){if(!e)return;const t=new ss;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class no{constructor(){this.startOnType=!0,this.enterKey="edit",this.enterMoves="down",this.tabMoves=!0,this.arrowKeysCommit=!0,this.textSelection="all",this.clearKeys=!0,this.ctrlEnterFillsSelection=!0,this.collapseSelectionOnNavigate=!0,this.emptyValue="",this.defaultEditable=!1,this.maxClearCells=1e6}static create(e){if(!e)return;const t=new no;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class lo{constructor(){this.composing=!1,this.abort=new AbortController,this.focusedOnce=!1}open(e,t){this.ctx=t;const s=t.domService,o=s.createElement("input");this.input=o,s.setAttribute(o,"type",this.inputType()),s.setAttribute(o,"autocomplete","off"),s.setAttribute(o,"spellcheck","false"),s.setAttribute(o,"aria-label",t.ariaLabel),s.addClass(o,"ge-table-cell-editor-field"),this.decorate(o,t),o.value=t.typedText!==void 0?t.typedText:this.toText(t);const i=this.abort.signal;o.addEventListener("compositionstart",()=>this.composing=!0,{signal:i}),o.addEventListener("compositionend",()=>this.composing=!1,{signal:i}),o.addEventListener("input",()=>t.inputChanged(),{signal:i}),s.appendChild(e,o)}inputType(){return"text"}decorate(e,t){}toText(e){return e.input}getValue(){var e;return((e=this.input)==null?void 0:e.value)??""}getText(){var e;return((e=this.input)==null?void 0:e.value)??""}setText(e){this.input&&(this.input.value=e,this.input.setSelectionRange(e.length,e.length))}focus(){const e=this.input;if(!e)return;e.ownerDocument.activeElement!==e&&e.focus({preventScroll:!0});const t=this.ctx;if(t&&!this.focusedOnce){this.focusedOnce=!0;const s=e.value.length;try{t.typedText===void 0&&t.textSelection==="all"&&t.mode==="edit"?e.setSelectionRange(0,s):e.setSelectionRange(s,s)}catch{}}}getFocusElement(){return this.input}setMode(e){}isComposing(){return this.composing}wantsKey(e,t){return!1}close(){var e;this.abort.abort(),(e=this.input)==null||e.remove(),this.input=void 0}}class el extends lo{decorate(e,t){t.domService.setAttribute(e,"inputmode","decimal"),t.domService.addClass(e,"ge-table-cell-editor-number")}getValue(){var s,o;const e=String(super.getValue());if((o=(s=this.ctx)==null?void 0:s.columnDef)!=null&&o.editInputPipe)return e;const t=e.trim();return t!==""&&/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(t)?Number(t):e}}class tl extends lo{constructor(){super(...arguments),this.originalText=""}inputType(){return"date"}toText(e){const t=e.value;if(t instanceof Date&&!Number.isNaN(t.getTime())){const o=i=>String(i).padStart(2,"0");return`${t.getFullYear()}-${o(t.getMonth()+1)}-${o(t.getDate())}`}const s=e.input;return/^\d{4}-\d{2}-\d{2}/.test(s)?s.slice(0,10):""}open(e,t){this.original=t.value,this.originalText=this.toText(t),super.open(e,{...t,typedText:t.typedText===""?"":void 0})}getValue(){const e=String(super.getValue());if(!e)return"";const t=this.original;if(e===this.originalText&&(t instanceof Date||typeof t=="string"))return t;const[s,o,i]=e.split("-").map(Number);if(t instanceof Date&&!Number.isNaN(t.getTime()))return new Date(s,o-1,i,t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds());const r=typeof t=="string"&&/^\d{4}-\d{2}-\d{2}./.test(t)?t.slice(10):"";return t instanceof Date?new Date(s,o-1,i):e+r}wantsKey(e,t){return e.key.startsWith("Arrow")}}class bt{constructor(e,t,s,o,i){this.type=e,this.rowIndex=t,this.columnIndex=s,this.mode=o,this.input=i}}const sl=function(n,e,t){return n===""||n===null||n===void 0?"":Number(n)},A=(n,e,t,s)=>Object.freeze({name:e,signature:`${e}(${t})`,description:s,group:n}),ol=Object.freeze([A("Math","ABS","number","The absolute value"),A("Logic","AND","logical1, [logical2], …","TRUE if all arguments are TRUE"),A("Math","AVERAGE","number1, [number2], …","The average of the numbers"),A("Conditional","AVERAGEIF","range, criteria, [average_range]","The average of the cells that match a criterion"),A("Conditional","AVERAGEIFS","average_range, criteria_range1, criteria1, …","The average of the cells that match all criteria"),A("Math","CEILING","number, significance","Rounds up to a multiple of significance"),A("Text","CONCAT","text1, [text2], …","Joins texts and ranges"),A("Math","COUNT","value1, [value2], …","Counts the numbers"),A("Math","COUNTA","value1, [value2], …","Counts the non-empty cells"),A("Math","COUNTBLANK","range","Counts the empty cells"),A("Conditional","COUNTIF","range, criteria","Counts the cells that match a criterion"),A("Conditional","COUNTIFS","criteria_range1, criteria1, …","Counts the cells that match all criteria"),A("Date","DATE","year, month, day","A date"),A("Date","DATEDIF","start_date, end_date, unit",'Days ("d"), months ("m") or years ("y") between two dates'),A("Date","DAY","date","The day of a date (1–31)"),A("Date","EOMONTH","start_date, months","The last day of the month, months before or after"),A("Text","FIND","find_text, within_text, [start_num]","The position of a text (case-sensitive)"),A("Math","FLOOR","number, significance","Rounds down to a multiple of significance"),A("Lookup","HLOOKUP","lookup_value, table_array, row_index_num, [range_lookup]","Looks up in the first row of a table"),A("Logic","IF","logical_test, value_if_true, [value_if_false]","One value or another"),A("Logic","IFERROR","value, value_if_error","The value, or another one if it is an error"),A("Logic","IFNA","value, value_if_na","The value, or another one if it is #N/A"),A("Logic","IFS","logical_test1, value1, …","The value of the first true condition"),A("Lookup","INDEX","array, row_num, [column_num]","The value at a position of a range"),A("Math","INT","number","Rounds down to an integer"),A("Info","ISBLANK","value","TRUE for an empty cell"),A("Info","ISERROR","value","TRUE for an error value"),A("Info","ISNA","value","TRUE for #N/A"),A("Info","ISNUMBER","value","TRUE for a number or date"),A("Info","ISTEXT","value","TRUE for a text"),A("Text","LEFT","text, [num_chars]","The first characters"),A("Text","LEN","text","The number of characters"),A("Text","LOWER","text","Lower case"),A("Lookup","MATCH","lookup_value, lookup_array, [match_type]","The position of a value in a range"),A("Math","MAX","number1, [number2], …","The largest number"),A("Text","MID","text, start_num, num_chars","Characters from the middle"),A("Math","MIN","number1, [number2], …","The smallest number"),A("Math","MOD","number, divisor","The remainder (sign of the divisor)"),A("Date","MONTH","date","The month of a date (1–12)"),A("Info","NA","","The error #N/A"),A("Logic","NOT","logical","The opposite"),A("Date","NOW","","Date and time now (recalculated)"),A("Logic","OR","logical1, [logical2], …","TRUE if any argument is TRUE"),A("Math","POWER","number, power","A number to a power"),A("Math","PRODUCT","number1, [number2], …","The product of the numbers"),A("Math","RAND","","A random number 0 … 1 (recalculated)"),A("Math","RANDBETWEEN","bottom, top","A random integer (recalculated)"),A("Text","RIGHT","text, [num_chars]","The last characters"),A("Math","ROUND","number, num_digits","Rounds half away from zero"),A("Math","ROUNDDOWN","number, num_digits","Rounds toward zero"),A("Math","ROUNDUP","number, num_digits","Rounds away from zero"),A("Text","SEARCH","find_text, within_text, [start_num]","The position of a text (case-insensitive, * and ?)"),A("Math","SQRT","number","The square root"),A("Text","SUBSTITUTE","text, old_text, new_text, [instance_num]","Replaces text"),A("Math","SUM","number1, [number2], …","The sum of the numbers"),A("Conditional","SUMIF","range, criteria, [sum_range]","The sum of the cells that match a criterion"),A("Conditional","SUMIFS","sum_range, criteria_range1, criteria1, …","The sum of the cells that match all criteria"),A("Math","SUMPRODUCT","array1, [array2], …","The sum of the products of ranges"),A("Logic","SWITCH","expression, value1, result1, …, [default]","The result of the matching value"),A("Text","TEXT","value, format_text","A number or date as text (0, 0.00, #,##0, 0%, yyyy-mm-dd, dd.mm.yyyy)"),A("Text","TEXTJOIN","delimiter, ignore_empty, text1, …","Joins texts with a delimiter"),A("Date","TODAY","","Today's date (recalculated)"),A("Text","TRIM","text","Removes extra spaces"),A("Text","UPPER","text","Upper case"),A("Text","VALUE","text","A text as number"),A("Lookup","VLOOKUP","lookup_value, table_array, col_index_num, [range_lookup]","Looks up in the first column of a table"),A("Date","WEEKDAY","date, [return_type]","The day of the week"),A("Lookup","XLOOKUP","lookup_value, lookup_array, return_array, [if_not_found]","Looks up a value and returns the matching one"),A("Logic","XOR","logical1, [logical2], …","TRUE if an odd number of arguments is TRUE"),A("Date","YEAR","date","The year of a date")]),lr=String.raw`\$?[A-Za-z]{1,3}\$?[1-9][0-9]*`,ar=new RegExp(String.raw`(?:${lr}(?::${lr})?|\$?[A-Za-z]{1,3}:\$?[A-Za-z]{1,3}|\$?[0-9]+:\$?[0-9]+)`,"y"),$t=/[A-Za-z0-9_.$]/,Gc=new Set(["=","(",",",";","+","-","*","/","^","&","<",">"]);function cr(n){const e=[];if(!n.startsWith("="))return e;let t=1;for(;t<n.length;){const s=n[t];if(s==='"'){t=Mi(n,t);continue}if(s==="["){const o=n.indexOf("]",t);t=o<0?n.length:o+1;continue}if($t.test(s)&&(t===0||!$t.test(n[t-1]))){ar.lastIndex=t;const o=ar.exec(n),i=o?t+o[0].length:-1;if(o&&Wc(o[0])&&(i>=n.length||!$t.test(n[i])&&n[i]!=="("&&n[i]!==":")){e.push({start:t,end:i,text:o[0],key:o[0].replace(/\$/g,"").toUpperCase()}),t=i;continue}for(;t<n.length&&$t.test(n[t]);)t++;continue}t++}return e}function Wc(n){return(n.match(/[A-Za-z]+/g)??[]).every(e=>Fe(e)>=0)}function Mi(n,e){let t=e+1;for(;t<n.length;){if(n[t]==='"'){if(n[t+1]==='"'){t+=2;continue}return t+1}t++}return t}function il(n,e){let t=1;for(;t<e;){if(n[t]==='"'){const s=Mi(n,t),o=s-1>t&&n[s-1]==='"';if(s>e||s===e&&!o)return!0;t=s;continue}if(n[t]==="["){const s=n.indexOf("]",t);if(s<0||s>=e)return!0;t=s+1;continue}t++}return!1}function Uc(n,e){return e<n.length&&$t.test(n[e])?!1:rl(n,e)}function rl(n,e){if(!n.startsWith("=")||e<1||il(n,e))return!1;let t=e-1;for(;t>0&&n[t]===" ";)t--;return Gc.has(n[t])}function Kc(n){const e=n.split(":"),t=/^(\$?)([A-Za-z]*)(\$?)([0-9]*)$/.exec(e[0]);if(!t)return n;const s=t[2]&&t[4]?t[1]?t[3]?1:3:t[3]?2:0:t[1]||t[3]?1:0,o=t[2]&&t[4]?(s+1)%4:(s+1)%2,i=o===1||o===3,r=o===1||o===2;return e.map(l=>{const a=/^\$?([A-Za-z]*)\$?([0-9]*)$/.exec(l);if(!a)return l;const[,c,h]=a;return c&&h?`${i?"$":""}${c}${r?"$":""}${h}`:c?`${o?"$":""}${c}`:`${o?"$":""}${h}`}).join(":")}function hr(n,e){if(!n.startsWith("=")||il(n,e)||e<n.length&&/[A-Za-z0-9_.(]/.test(n[e]))return;let t=e;for(;t>1&&/[A-Za-z0-9_.]/.test(n[t-1]);)t--;const s=n.slice(t,e);if(!(!/^[A-Za-z][A-Za-z0-9_.]*$/.test(s)||!rl(n,t)))return{start:t,prefix:s}}function zc(n,e){if(!n.startsWith("="))return;const t=[];let s=1;for(;s<e;){const o=n[s];if(o==='"'){const i=Mi(n,s);if(i>e)return So(t);s=i;continue}if(o==="["){const i=n.indexOf("]",s);if(i<0||i>=e)return So(t);s=i+1;continue}if(o==="("){let i=s;for(;i>1&&/[A-Za-z0-9_.]/.test(n[i-1]);)i--;t.push({name:n.slice(i,s).toUpperCase(),argument:0})}else o===")"?t.pop():(o===","||o===";")&&t.length&&t[t.length-1].argument++;s++}return So(t)}function So(n){for(let e=n.length-1;e>=0;e--)if(n[e].name)return n[e]}function jc(n){const e=n.indexOf("("),t=n.slice(e+1,n.lastIndexOf(")"));return t.trim()?t.split(",").map(s=>s.trim()):[]}const Xc=8,Yc=50;class nl{constructor(e,t,s,o,i,r,l){this.scope=e,this.sheet=t,this.input=s,this.editedCell=i,this.changed=r,this.frames=[],this.suggestions=[],this.active=0,this.listClosed=!1,this.composing=!1,this.abort=new AbortController,this.ids={list:`${l}-functions`,hint:`${l}-hint`,option:d=>`${l}-fn-${d.replace(/[^A-Za-z0-9_-]/g,"_")}`};const a=Object.keys(t.options.functions??{}).map(d=>d.toUpperCase());this.functions=[...ol.filter(d=>!a.includes(d.name)),...a.map(d=>({name:d,signature:`${d}(…)`,description:"",group:"Math"}))].sort((d,u)=>d.name.localeCompare(u.name));const c=e.getDomService().domService;this.mirror=c.createElement("div"),c.addClass(this.mirror,"ge-table-formula-mirror"),c.setAttribute(this.mirror,"aria-hidden","true"),o.insertBefore(this.mirror,s),this.list=c.createElement("div"),c.addClass(this.list,"ge-table-formula-list"),c.setAttribute(this.list,"id",this.ids.list),c.setAttribute(this.list,"role","listbox"),c.setAttribute(this.list,"aria-label",this.texts().functionSuggestions()),this.list.style.display="none",c.appendChild(o,this.list),this.hint=c.createElement("div"),c.addClass(this.hint,"ge-table-formula-hint"),c.setAttribute(this.hint,"id",this.ids.hint),c.setAttribute(this.hint,"role","tooltip"),this.hint.style.display="none",c.appendChild(o,this.hint);const h=this.abort.signal;s.addEventListener("input",()=>this.onInput(),{signal:h}),s.addEventListener("compositionstart",()=>{this.composing=!0,this.refresh()},{signal:h}),s.addEventListener("compositionend",()=>{this.composing=!1,this.refresh()},{signal:h}),s.addEventListener("keydown",()=>requestAnimationFrame(()=>this.syncScroll()),{signal:h});for(const d of["keyup","click","select","scroll"])s.addEventListener(d,()=>this.refreshCaret(),{signal:h});this.list.addEventListener("pointerdown",d=>{var g,p;d.preventDefault();const u=(p=(g=d.target).closest)==null?void 0:p.call(g,".ge-table-formula-option"),f=u?Number(u.getAttribute("data-index")):-1;f>=0&&this.accept(f)},{signal:h}),this.refresh()}onKeyDown(e,t){var u,f;if(!this.input.value.startsWith("="))return!1;const o=!e.ctrlKey&&!e.metaKey&&!e.altKey;if(this.isListOpen()&&o)switch(e.key){case"ArrowDown":case"ArrowUp":return this.active=(this.active+(e.key==="ArrowDown"?1:-1)+this.suggestions.length)%this.suggestions.length,this.renderList(),!0;case"Enter":case"Tab":return e.shiftKey?!1:(this.accept(this.active),!0);case"Escape":return this.listClosed=!0,this.refresh(),!0}if(e.key==="F2")return this.pointer=void 0,!1;if(e.key==="F4"&&o)return this.toggleReferenceAtCaret();const r={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(!r||!o||!this.canPoint(t))return!1;let[l,a]=r;this.scope.isRtl()&&(a=-a);const c=((u=this.pointer)==null?void 0:u.cell)??this.editedCell(),h=this.step(c,l,a),d=e.shiftKey?((f=this.pointer)==null?void 0:f.anchor)??c:h;return this.point(d,h),!0}onPointerDown(e){var l,a;if(e.button!==0||!this.input.value.startsWith("=")||!this.canPoint("enter"))return!1;const t=(a=(l=e.target)==null?void 0:l.closest)==null?void 0:a.call(l,'.ge-table-col-div[data-area="body"]'),s=Number(t==null?void 0:t.getAttribute("data-row-index")),o=Number(t==null?void 0:t.getAttribute("data-col-index"));if(!t||!(s>=0)||!(o>=0)||this.sheet.engineColumn(o)===void 0)return!1;const i=[s,o],r=e.shiftKey&&this.pointer?this.pointer.anchor:i;return this.point(r,i,!1),this.startDrag(r),!0}getOwnedIds(){return[this.ids.list,this.ids.hint]}update(){this.renderFrames()}destroy(){var e;this.abort.abort(),(e=this.drag)==null||e.abort(),this.mirror.remove(),this.list.remove(),this.hint.remove();for(const t of this.frames)t.remove();this.frames=[],this.input.classList.remove("ge-table-formula-input");for(const t of["role","aria-expanded","aria-controls","aria-autocomplete","aria-activedescendant","aria-describedby"])this.input.removeAttribute(t)}texts(){const e=this.scope.ariaTexts??{},t=new pe;return{functionSuggestions:()=>(e.functionSuggestions??t.functionSuggestions).call(e),referenceInserted:s=>(e.referenceInserted??t.referenceInserted).call(e,s)}}onInput(){this.pointer=void 0,this.listClosed=!1,this.refresh()}caret(){return this.input.selectionStart??this.input.value.length}collapsed(){return this.input.selectionStart===this.input.selectionEnd}canPoint(e){const t=this.input.value;if(!this.collapsed()||this.composing)return!1;const s=this.caret();return this.pointer&&s===this.pointer.end?!0:e==="enter"&&Uc(t,s)}step(e,t,s){const o=this.scope.tableModel.getBodyModel().getRowCount(),i=Math.min(Math.max(0,e[0]+t),o-1);let r=e[1];if(s){const l=this.scope.nextShownColumn(r,s);this.sheet.engineColumn(l)!==void 0&&(r=l)}return[i,r]}referenceText(e,t){const s=this.sheet.physicalRow(e[0]),o=this.sheet.physicalRow(t[0]),i=this.sheet.engineColumn(e[1]),r=this.sheet.engineColumn(t[1]);if(s===void 0||o===void 0||i===void 0||r===void 0||s!==o&&!this.isContiguous(e[0],t[0],s,o))return;const l=mt(Math.min(s,o),Math.min(i,r)),a=mt(Math.max(s,o),Math.max(i,r));return l===a?l:`${l}:${a}`}isContiguous(e,t,s,o){if(Math.abs(e-t)!==Math.abs(s-o))return!1;const i=Math.min(s,o),r=Math.max(s,o);for(let l=Math.min(e,t);l<=Math.max(e,t);l++){const a=this.sheet.physicalRow(l);if(a===void 0||a<i||a>r)return!1}return!0}point(e,t,s=!0){const o=this.referenceText(e,t);if(!o)return;const i=this.input.value,r=this.caret(),l=this.pointer&&r===this.pointer.end,a=l?this.pointer.start:r,c=l?this.pointer.end:r;this.input.value=i.slice(0,a)+o+i.slice(c);const h=a+o.length;this.input.setSelectionRange(h,h),this.pointer={start:a,end:h,anchor:e,cell:t},this.scope.ensureRowIsVisible(t[0]),this.scope.ensureColumnIsVisible(t[1]),s&&this.scope.announce(this.texts().referenceInserted(o)),this.listClosed=!1,this.refresh(),this.changed()}startDrag(e){var l,a;(l=this.drag)==null||l.abort();const t=new AbortController;this.drag=t;const s=this.input.ownerDocument,o=this.scope.hostElement;let i=(a=this.pointer)==null?void 0:a.cell;s.addEventListener("pointermove",c=>{const h=o.getBoundingClientRect(),d=this.scope.getBodyCellAtHostPoint(this.scope.clientXToHostX(c.clientX),c.clientY-h.top-o.clientTop);d[0]<0||this.sheet.engineColumn(d[1])===void 0||i&&i[0]===d[0]&&i[1]===d[1]||(i=d,this.point(e,d,!1))},{signal:t.signal});const r=()=>{t.abort();const c=this.pointer?this.input.value.slice(this.pointer.start,this.pointer.end):"";c&&this.scope.announce(this.texts().referenceInserted(c))};s.addEventListener("pointerup",r,{signal:t.signal}),s.addEventListener("pointercancel",r,{signal:t.signal})}toggleReferenceAtCaret(){const e=this.input.value,t=this.caret(),s=cr(e).find(r=>t>=r.start&&t<=r.end);if(!s)return!1;const o=Kc(s.text);this.input.value=e.slice(0,s.start)+o+e.slice(s.end);const i=s.start+o.length;return this.input.setSelectionRange(i,i),this.pointer&&this.pointer.start===s.start&&(this.pointer.end=i),this.refresh(),this.changed(),!0}isListOpen(){return this.list.style.display!=="none"&&this.suggestions.length>0}accept(e){const t=this.suggestions[e],s=hr(this.input.value,this.caret());if(!t||!s)return;const o=this.input.value,i=`${t.name}(`;this.input.value=o.slice(0,s.start)+i+o.slice(s.start+s.prefix.length);const r=s.start+i.length;this.input.setSelectionRange(r,r),this.pointer=void 0,this.refresh(),this.changed()}refreshCaret(){this.syncScroll(),this.renderPopups()}refresh(){this.renderMirror(),this.renderFrames(),this.renderPopups()}syncScroll(){this.mirror.scrollLeft=this.input.scrollLeft}colored(){const e=new Map;return cr(this.input.value).map(t=>{let s=e.get(t.key);return s===void 0&&e.set(t.key,s=e.size%Xc),{...t,color:s}})}renderMirror(){const e=this.input.value,t=e.startsWith("=")&&!this.composing,s=this.mirror;if(s.textContent="",this.input.classList.toggle("ge-table-formula-input",t),s.style.display=t?"":"none",!t)return;const o=this.scope.getDomService().domService,i=o.createElement("span");s.appendChild(i);let r=0;for(const l of this.colored()){l.start>r&&i.appendChild(o.createText(e.slice(r,l.start)));const a=o.createElement("span");o.addClass(a,`ge-table-formula-ref-text-${l.color}`),a.textContent=l.text,i.appendChild(a),r=l.end}r<e.length&&i.appendChild(o.createText(e.slice(r))),this.syncScroll()}renderFrames(){const e=[];if(this.input.value.startsWith("=")){const s=new Set;for(const o of this.colored()){if(s.has(o.key))continue;s.add(o.key);const i=this.frameRect(o.text);i&&e.push({color:o.color,rect:i})}}const t=this.scope.getDomService();for(;this.frames.length>e.length;)this.frames.pop().remove();for(;this.frames.length<e.length;){const s=t.createDivWithClass("ge-table-formula-ref",this.scope.hostElement);t.domService.setAttribute(s,"aria-hidden","true"),this.frames.push(s)}e.forEach(({color:s,rect:o},i)=>{const r=this.frames[i];r.className=`ge-table-formula-ref ge-table-formula-ref-${s}`,t.setStyle(r,"left",`${o.left}px`),r.style.top=`${o.top}px`,r.style.width=`${o.width}px`,r.style.height=`${o.height}px`})}frameRect(e){const t=this.frameCells(e);if(!t)return;const[s,o,i,r]=t,l=this.scope.getBodyCellRectInHost(Math.min(s,o),Math.min(i,r)),a=this.scope.getBodyCellRectInHost(Math.max(s,o),Math.max(i,r)),c=Math.max(Math.min(l.left,a.left),Math.min(l.clipLeft,a.clipLeft)),h=Math.min(Math.max(l.left+l.width,a.left+a.width),Math.max(l.clipRight,a.clipRight)),d=Math.max(l.top,l.clipTop),u=Math.min(a.top+a.height,a.clipBottom);return h>c&&u>d?{left:c,top:d,width:h-c,height:u-d}:void 0}frameCells(e){const t=this.scope.tableModel.getBodyModel(),s=t.getRowCount(),o=[this.input.value,s,s?t.getRowByIndex(0):void 0,s?t.getRowByIndex(s-1):void 0];(!this.cellCache||this.cellCache.signature.some((a,c)=>a!==o[c]))&&(this.cellCache={signature:o,cells:new Map});const i=this.cellCache.cells;if(i.has(e))return i.get(e);const r=qr(e);let l;if(r){const a=r.wholeColumns?0:this.sheet.displayRow(r.from.row),c=r.wholeColumns?s-1:this.sheet.displayRow(Math.min(r.to.row,this.sheetRows()-1)),h=r.wholeRows?this.firstDataColumn():this.sheet.modelColumn(r.from.col),d=r.wholeRows?this.lastDataColumn():this.sheet.modelColumn(r.to.col);l=a<0||c<0||h<0||d<0?void 0:[a,c,h,d]}return i.set(e,l),l}sheetRows(){return this.sheet.rowCount()}firstDataColumn(){for(let e=0;e<this.scope.tableModel.getColumnCount();e++)if(this.sheet.engineColumn(e)!==void 0)return e;return-1}lastDataColumn(){let e=-1;for(let t=0;t<this.scope.tableModel.getColumnCount();t++)this.sheet.engineColumn(t)!==void 0&&(e=t);return e}renderPopups(){const e=this.scope.getDomService().domService,t=this.input,s=t.value,o=s.startsWith("="),i=this.caret(),r=o&&this.collapsed()&&!this.composing?hr(s,i):void 0,l=r==null?void 0:r.prefix.toUpperCase(),a=this.suggestions.map(p=>p.name).join();this.suggestions=l?this.functions.filter(p=>p.name.startsWith(l)).slice(0,Yc):[],this.suggestions.map(p=>p.name).join()!==a&&(this.active=0);const c=this.suggestions.length>0&&!this.listClosed;e.setAttribute(t,"role","combobox"),e.setAttribute(t,"aria-autocomplete","list"),e.setAttribute(t,"aria-controls",this.ids.list),e.setAttribute(t,"aria-expanded",String(c)),this.list.style.display=c?"":"none",c?this.renderList():t.removeAttribute("aria-activedescendant");const h=o&&!c&&!this.composing?zc(s,i):void 0,d=h?this.functions.find(p=>p.name===h.name):void 0;if(this.hint.textContent="",!d){this.hint.style.display="none",t.removeAttribute("aria-describedby");return}const u=jc(d.signature),g=u[u.length-1]==="…"&&h.argument>=u.length-1?u.length-2:h.argument;this.hint.appendChild(e.createText(`${d.name}(`)),u.forEach((p,m)=>{if(m&&this.hint.appendChild(e.createText(", ")),m===g){const b=e.createElement("b");b.textContent=p,this.hint.appendChild(b)}else this.hint.appendChild(e.createText(p))}),this.hint.appendChild(e.createText(")")),this.hint.style.display="",e.setAttribute(t,"aria-describedby",this.ids.hint)}renderList(){var o;const e=this.scope.getDomService().domService,t=this.list;t.textContent="",this.suggestions.forEach((i,r)=>{const l=e.createElement("div");e.addClass(l,"ge-table-formula-option"),e.setAttribute(l,"id",this.ids.option(i.name)),e.setAttribute(l,"role","option"),e.setAttribute(l,"data-index",String(r)),e.setAttribute(l,"aria-selected",String(r===this.active));const a=e.createElement("span");if(e.addClass(a,"ge-table-formula-option-name"),a.textContent=i.name,l.appendChild(a),i.description){const c=e.createElement("span");e.addClass(c,"ge-table-formula-option-description"),c.textContent=i.description,l.appendChild(c)}t.appendChild(l)}),e.setAttribute(this.input,"aria-activedescendant",this.ids.option(this.suggestions[this.active].name));const s=t.children[this.active];(o=s==null?void 0:s.scrollIntoView)==null||o.call(s,{block:"nearest"})}}function Jc(n){if(n==null)return"";if(n instanceof Date){if(Number.isNaN(n.getTime()))return"";const e=t=>String(t).padStart(2,"0");return`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())}`}return String(n)}class ll{constructor(e,t){this.tableScope=e,this.options=t,this.tabStartColumn=-1,this.blockClick=!1,this.editorId=`${e.ariaIds.prefix}-editor`;const s=e.listenerAbortController.signal,o=e.hostElement;o.addEventListener("keydown",i=>this.onKeyDown(i),{capture:!0,signal:s}),o.addEventListener("pointerdown",i=>this.onPointerDown(i),{capture:!0,signal:s}),o.addEventListener("focusout",i=>this.onFocusOut(i),{signal:s});for(const i of["mousedown","mouseup","click","dblclick"])o.addEventListener(i,r=>this.onBlockedMouse(r),{capture:!0,signal:s})}isOpen(){return!!this.session}getCell(){return this.session?[this.session.rowIndex,this.session.columnIndex]:void 0}getOwnedEditorId(e,t){var o;const s=this.session;if(!(!s||s.rowIndex!==e||s.columnIndex!==t||!((o=this.editor)!=null&&o.getFocusElement())))return this.assist?[this.editorId,...this.assist.getOwnedIds()].join(" "):this.editorId}handlesColumn(e){const t=this.tableScope.tableModel.getColumnDef(e);if(t!=null&&t.editor)return!0;if(t!=null&&t.getEditRenderer)return!1;const s=this.tableScope.tableOptions.getEditRenderer;return!s||s===Ci}start(e,t,s={}){const o=this.tableScope;if(this.session){if(this.session.rowIndex===e&&this.session.columnIndex===t)return!0;if(!this.commit("none"))return!1}const i=o.tableModel.getBodyModel();if(e<0||t<0||e>=i.getRowCount()||t>=o.tableModel.getColumnCount()||!i.isEditable(e,t)||O(o.tableModel.getColumnDef(t))||!o.canStartEditing())return!1;const r=s.mode??"edit",l=o.tableModel.getColumnDef(t),a=o.getShownCellValue(e,t),c=i.getRowByIndex(e),h=U(c)?c.data:c,d=Jc(a);o.ensureColumnIsVisible(t),o.ensureRowIsVisible(e);const u=this.ensureContainer(),f={rowIndex:e,columnIndex:t,row:c,columnDef:l,value:a,input:d,typedText:s.typedText,mode:r,textSelection:s.textSelection??this.options.textSelection,direction:o.isRtl()?"rtl":"ltr",ariaLabel:o.getColumnAriaLabel(t),domService:o.getDomService().domService,commit:y=>{this.commit(y??"none")},cancel:()=>this.cancel(),inputChanged:()=>{this.session&&(this.session.hadInput=!0),this.fire("input")}},g=this.createEditor(f);this.editor=g;const p=!!s.imeStart;this.session={rowIndex:e,columnIndex:t,row:h??c,mode:r,initialText:d,typed:s.typedText!==void 0&&!p,columnDef:l,pendingInput:p,hadInput:!1},g.open(u,f);const m=g.getFocusElement();m&&o.getDomService().domService.setAttribute(m,"id",this.editorId);const b=o.tableSheet;return b!=null&&b.isFormulaColumnIndex(t)&&(m==null?void 0:m.tagName)==="INPUT"&&m.type==="text"&&(this.assist=new nl(o,b,m,u,()=>this.session?[this.session.rowIndex,this.session.columnIndex]:[e,t],()=>f.inputChanged(),this.editorId)),u.style.display="block",this.update(),g.focus(),this.fire("start"),o.announce(o.getSheetTexts().editingStarted(o.getColumnAriaLabel(t))),o.repaint(),g.focus(),!0}commit(e="none",t={}){var u;const s=this.session,o=this.editor;if(!s||!o)return!0;const i=this.tableScope,r=((u=o.getText)==null?void 0:u.call(o))??String(o.getValue()??""),l=s.pendingInput&&!s.hadInput||!s.typed&&r===s.initialText;if(!l||t.fillSelection){const f=o.getValue(),g=t.fillSelection?i.getSelectedBodyCells(this.options.maxClearCells):[];if(!g)return i.announce(i.getSheetTexts().clearTooLarge(this.options.maxClearCells)),o.focus(),!1;g.length||g.push([s.rowIndex,s.columnIndex]);const p=i.commitCellEditor(g,f,!!t.deferRepaint);if(p.invalid&&!p.written){const m=o.getFocusElement();if(m){const b=i.getDomService().domService;b.setAttribute(m,"aria-invalid","true"),b.setAttribute(m,"title",p.message??"")}return o.focus(),!1}}const{rowIndex:a,columnIndex:c}=s,h=i.tableSheet,d=!l&&(h!=null&&h.isFormulaInput(c,r))?h.syntaxError(r):void 0;return this.close("commit",r,!!t.deferRepaint),d&&i.announce(i.getFormulaErrorText(d)),this.moveAfterCommit(a,c,e,!!t.tab),!0}cancel(){this.session&&this.close("cancel")}update(){var g,p;const e=this.session,t=this.container;if(!e||!t)return;const s=this.tableScope;if(!this.followColumn(e)||!this.followRow(e)){this.close("cancel");return}const o=s.getBodyCellRectInHost(e.rowIndex,e.columnIndex);s.getDomService().setStyle(t,"left",`${o.left}px`),t.style.top=`${o.top}px`,t.style.width=`${Math.max(0,o.width)}px`,t.style.height=`${Math.max(0,o.height)}px`;const r=Math.max(0,o.clipTop-o.top),l=Math.max(0,o.top+o.height-o.clipBottom),a=Math.max(0,o.clipLeft-o.left),c=Math.max(0,o.left+o.width-o.clipRight),h=r+l>=o.height||a+c>=o.width;t.classList.toggle("ge-table-cell-editor-clipped",h);const[d,u]=s.isRtl()?[c,a]:[a,c];t.style.clipPath=h?"inset(50%)":r||l||d||u?`inset(${r}px ${u}px ${l}px ${d}px)`:"",(g=this.assist)==null||g.update(),t.ownerDocument.activeElement===s.hostElement&&((p=this.editor)==null||p.focus())}destroy(){var e,t,s;(e=this.assist)==null||e.destroy(),this.assist=void 0,(t=this.editor)==null||t.close(),this.editor=void 0,this.session=void 0,(s=this.container)==null||s.remove(),this.container=void 0}ensureContainer(){if(!this.container||!this.container.isConnected){const e=this.tableScope.getDomService();this.container=e.createDivWithClass("ge-table-cell-editor",this.tableScope.hostElement),e.domService.setAttribute(this.container,"role","presentation")}return this.container}createEditor(e){var r,l;const t=(r=e.columnDef)==null?void 0:r.editor;if(typeof t=="function")return t(e);const s=this.tableScope.getTypedCellValue(e.rowIndex,e.columnIndex),o=s!==e.value,i=t??(s instanceof Date&&!o?"date":typeof s=="number"||((l=e.columnDef)==null?void 0:l.editInputPipe)===sl?"number":"text");return i==="number"?new el:i==="date"?new tl:new lo}followRow(e){const t=this.tableScope.tableModel.getBodyModel(),s=i=>{const r=t.getRowByIndex(i);return U(r)?r.data:r};if(e.row===void 0||e.row===null||typeof e.row!="object")return e.rowIndex<t.getRowCount();if(e.rowIndex<t.getRowCount()&&s(e.rowIndex)===e.row)return!0;if(e.rowIndex<t.getRowCount()&&s(e.rowIndex)!==s(e.rowIndex))return e.row=void 0,!0;const o=t.getRowCount();for(let i=0;i<o;i++)if(s(i)===e.row)return e.rowIndex=i,!0;return!1}followColumn(e){const t=this.tableScope.tableModel;if(t.getColumnDef(e.columnIndex)===e.columnDef)return!0;const s=t.getColumnCount();for(let o=0;o<s;o++)if(t.getColumnDef(o)===e.columnDef)return e.columnIndex=o,!0;return!1}close(e,t,s=!1){var l,a,c,h;const o=this.session,i=this.container,r=!!(i!=null&&i.contains(i.ownerDocument.activeElement));(l=this.assist)==null||l.destroy(),this.assist=void 0,(a=this.editor)==null||a.close(),this.editor=void 0,i&&(i.style.display="none",i.style.clipPath=""),this.session=void 0,o&&((h=(c=this.tableScope.getEventListener()).onEditingChanged)==null||h.call(c,new bt(e,o.rowIndex,o.columnIndex,o.mode,t))),r&&this.tableScope.hostElement.focus({preventScroll:!0}),e==="cancel"&&!s&&this.tableScope.repaint()}fire(e){var s,o,i,r;const t=this.session;t&&((r=(i=this.tableScope.getEventListener()).onEditingChanged)==null||r.call(i,new bt(e,t.rowIndex,t.columnIndex,t.mode,(o=(s=this.editor)==null?void 0:s.getText)==null?void 0:o.call(s))))}moveAfterCommit(e,t,s,o){const i=this.tableScope;if(s==="none")return;if(s==="right"||s==="left"){o&&this.tabStartColumn<0&&(this.tabStartColumn=t),o||(this.tabStartColumn=-1),i.moveActiveCell(e,t,0,s==="right"?1:-1);return}const r=s==="down"?1:-1,l=s==="down"&&this.tabStartColumn>=0?this.tabStartColumn:t;this.tabStartColumn=-1,i.moveActiveCell(e,l,r,0)}onPointerDown(e){var s;const t=this.container;if(!(!this.session||!t||t.contains(e.target))&&e.target!==this.tableScope.scrollViewport){if(this.blockClick=!1,(s=this.assist)!=null&&s.onPointerDown(e)){e.preventDefault(),e.stopPropagation(),this.blockClick=!0;return}this.commit("none",{deferRepaint:!0})||(e.preventDefault(),e.stopPropagation(),this.blockClick=!0)}}onBlockedMouse(e){var t;!this.blockClick||(t=this.container)!=null&&t.contains(e.target)||(e.preventDefault(),e.stopPropagation(),(e.type==="click"||e.type==="dblclick")&&(this.blockClick=e.type==="click",e.type==="click"&&setTimeout(()=>this.blockClick=!1,500)))}onFocusOut(e){const t=this.container,s=e.relatedTarget;if(!(!this.session||!t||!t.contains(e.target))){if(!s){const o=t.ownerDocument;setTimeout(()=>{this.session&&o.hasFocus()&&!this.tableScope.hostElement.contains(o.activeElement)&&this.commit("none")});return}this.tableScope.hostElement.contains(s)||this.commit("none")}}onKeyDown(e){var o;const t=this.tableScope;if((o=t.isEventInDetail)!=null&&o.call(t,e))return;const s=this.container;if(this.session&&s&&s.contains(e.target)){this.onEditorKeyDown(e);return}this.session||e.target!==t.hostElement||!this.options.startOnType||this.onTypeToEdit(e)}isMac(){return typeof navigator<"u"&&/Mac/.test(navigator.platform)}onTypeToEdit(e){const t=this.tableScope,s=typeof e.getModifierState=="function"&&e.getModifierState("AltGraph");if((e.ctrlKey||e.metaKey)&&!s||e.altKey&&!s&&!this.isMac())return;const o=e.isComposing||e.key==="Process"||e.keyCode===229,i=e.key==="Dead",r=e.key.length===1&&!(e.key===" "&&(e.shiftKey||e.ctrlKey));if(!r&&!o&&!i)return;const l=t.getActiveBodyCell();if(!l||!t.canStartEditing())return;const[a,c]=l;if(!t.tableModel.getBodyModel().isEditable(a,c)||O(t.tableModel.getColumnDef(c))){r&&e.key!==" "&&t.announce(t.getSheetTexts().readOnlyCell());return}if(typeof t.getShownCellValue(a,c)=="boolean"){e.key===" "&&(e.preventDefault(),e.stopImmediatePropagation(),t.toggleBooleanCell(a,c));return}this.handlesColumn(c)&&(r?(e.preventDefault(),e.stopImmediatePropagation(),this.start(a,c,{mode:"enter",typedText:e.key})):(e.stopImmediatePropagation(),this.start(a,c,{mode:"enter",typedText:"",imeStart:!0})))}onEditorKeyDown(e){var r,l,a,c;const t=this.editor,s=this.session;if(!t||!s||e.isComposing||e.key==="Process"||e.keyCode===229||(r=t.isComposing)!=null&&r.call(t))return;const o=()=>{e.preventDefault(),e.stopPropagation()};if((l=this.assist)!=null&&l.onKeyDown(e,s.mode)){o();return}if((a=t.wantsKey)!=null&&a.call(t,e,s.mode))return;const i=this.tableScope.isRtl();switch(e.key){case"Escape":o(),this.cancel();return;case"Enter":{if(e.altKey)return;if(o(),(e.ctrlKey||e.metaKey)&&this.options.ctrlEnterFillsSelection){this.commit("none",{fillSelection:!0});return}const h=this.options.enterMoves==="right"?"right":this.options.enterMoves==="none"?"none":"down",d=h==="right"?"left":h==="down"?"up":"none";this.commit(e.shiftKey?d:h);return}case"Tab":{if(!this.options.tabMoves||e.ctrlKey||e.metaKey||e.altKey)return;const h=e.shiftKey?-1:1;this.tableScope.hasShownColumnBeside(s.columnIndex,h)?(o(),this.commit(h>0?"right":"left",{tab:!0})):this.commit("none")?this.tabStartColumn=-1:o();return}case"F2":o(),s.mode=s.mode==="enter"?"edit":"enter",(c=t.setMode)==null||c.call(t,s.mode);return;case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":{if(s.mode!=="enter"||!this.options.arrowKeysCommit||e.ctrlKey||e.metaKey||e.altKey||e.shiftKey)return;o();let h=e.key==="ArrowUp"?"up":e.key==="ArrowDown"?"down":e.key==="ArrowLeft"?"left":"right";i&&(h==="left"||h==="right")&&(h=h==="left"?"right":"left"),this.commit(h);return}default:return}}}function al(n){const e=n?"meta":"ctrl";return{tab:"NAVIGATE_NEXT_CELL","shift+tab":"NAVIGATE_PREVIOUS_CELL","shift+arrowup":"EXTEND_SELECTION_UP","shift+arrowdown":"EXTEND_SELECTION_DOWN","shift+arrowleft":"EXTEND_SELECTION_LEFT","shift+arrowright":"EXTEND_SELECTION_RIGHT","shift+home":"EXTEND_SELECTION_ROW_START","shift+end":"EXTEND_SELECTION_ROW_END","shift+pageup":"EXTEND_SELECTION_PAGE_UP","shift+pagedown":"EXTEND_SELECTION_PAGE_DOWN",[`${e}+arrowup`]:"NAVIGATE_DATA_EDGE_UP",[`${e}+arrowdown`]:"NAVIGATE_DATA_EDGE_DOWN",[`${e}+arrowleft`]:"NAVIGATE_DATA_EDGE_LEFT",[`${e}+arrowright`]:"NAVIGATE_DATA_EDGE_RIGHT",[`${e}+shift+arrowup`]:"EXTEND_TO_DATA_EDGE_UP",[`${e}+shift+arrowdown`]:"EXTEND_TO_DATA_EDGE_DOWN",[`${e}+shift+arrowleft`]:"EXTEND_TO_DATA_EDGE_LEFT",[`${e}+shift+arrowright`]:"EXTEND_TO_DATA_EDGE_RIGHT","shift+space":"SELECT_ROW","ctrl+space":"SELECT_COLUMN",delete:"CLEAR_CELLS",backspace:"CLEAR_AND_EDIT"}}function cl(n){return n?{"meta+c":"COPY_2_CLIPBOARD","meta+x":"CUT_2_CLIPBOARD","meta+v":"PASTE_FROM_CLIPBOARD"}:{"ctrl+c":"COPY_2_CLIPBOARD","ctrl+x":"CUT_2_CLIPBOARD","ctrl+v":"PASTE_FROM_CLIPBOARD","ctrl+insert":"COPY_2_CLIPBOARD","shift+delete":"CUT_2_CLIPBOARD","shift+insert":"PASTE_FROM_CLIPBOARD"}}class os{constructor(){this.copyHeaders=!1,this.copyValue="text",this.html=!0,this.pasteAddsRows=!1,this.createRow=void 0,this.maxPasteCells=1e6,this.processCopy=void 0,this.processPaste=void 0}static create(e){if(!e)return;const t=new os;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}const ht=()=>new I("#N/A","Not found"),se=n=>new I("#VALUE!",n),we=n=>new I("#NUM!",n),nt=n=>new I("#DIV/0!",n);function dt(n,e){for(const t of n)if(Ye(t))for(let s=0;s<t.rows;s++)for(let o=0;o<t.cols;o++){const i=e(t.get(s,o),!0);if(i!==void 0)return i}else{const s=e(t,!1);if(s!==void 0)return s}}function Nt(n,e){const t=[];for(const s of n)if(Ye(s))for(let o=0;o<s.rows;o++)for(let i=0;i<s.cols;i++){const r=s.get(o,i);if(typeof r=="number")t.push(r);else if(r!==null&&typeof r=="object"){if(w(r))return r;G(r)&&t.push(r.serial)}}else{if(w(s))return s;if(typeof s=="number")t.push(s);else if(G(s))t.push(s.serial);else if(s!==null){const o=z(s,e);if(w(o))return o;t.push(o)}}return t}function qc(n,e){return z(n,e)}function ve(n,e){const t=[];for(const s of n){const o=z(s,e);if(w(o))return o;t.push(o)}return t}function Zc(n){return re(n)}function dr(n,e,t){const s=Math.pow(10,Math.trunc(e)),o=xe(Math.abs(n)*s),i=(t?Math.ceil(o):Math.floor(o))/s;return n<0?-i:i}function Qc(n,e){const t=_(n);if(w(t))return()=>!1;const s=h=>{if(typeof h=="number")return h;if(G(h))return h.serial;if(typeof h=="string"&&h.trim()!==""){const d=z(h,e);return w(d)?void 0:d}};if(typeof t=="number"||G(t)){const h=G(t)?t.serial:t;return d=>s(d)===h}if(typeof t=="boolean")return h=>h===t;const o=t===null?"":t,i=/^(<=|>=|<>|<|>|=)?(.*)$/s.exec(o),r=i[1]??"",l=i[2];if(l===""&&(r===""||r==="="))return h=>ko(h);if(l===""&&r==="<>")return h=>!ko(h);const a=s(l);if(a!==void 0&&!(r===""&&!/^[\s\d.+-]/.test(l)))return h=>{const d=s(h);if(d===void 0)return r==="<>";const u=xe(d)-xe(a);switch(r){case"<":return u<0;case"<=":return u<=0;case">":return u>0;case">=":return u>=0;case"<>":return u!==0;default:return u===0}};if(r===""||r==="="||r==="<>"){const h=dl(l);return d=>{const u=typeof d=="string"?d:typeof d=="boolean"?d?"TRUE":"FALSE":void 0,f=u!==void 0&&u!==""&&h(u);return r==="<>"?!f:f}}const c=l.toLowerCase();return h=>{if(typeof h!="string")return!1;const d=h.toLowerCase();switch(r){case"<":return d<c;case"<=":return d<=c;case">":return d>c;default:return d>=c}}}function hl(n){var t;const e=[];for(let s=0;s<n.length;s++){const o=n[s];o==="~"&&(n[s+1]==="*"||n[s+1]==="?"||n[s+1]==="~")?e.push({kind:"char",ch:n[++s]}):o==="*"?((t=e[e.length-1])==null?void 0:t.kind)!=="star"&&e.push({kind:"star"}):o==="?"?e.push({kind:"any"}):e.push({kind:"char",ch:o.toLowerCase()})}return e}function Bo(n,e,t=0){const s=e.toLowerCase();let o=0,i=t,r=-1,l=0;for(;i<s.length;){const a=n[o];if(a&&(a.kind==="any"||a.kind==="char"&&a.ch===s[i]))o++,i++;else if(a&&a.kind==="star")r=o++,l=i;else if(r>=0)o=r+1,i=++l;else return!1}for(;o<n.length&&n[o].kind==="star";)o++;return o===n.length}function dl(n){const e=hl(n);return t=>Bo(e,t)}function eh(n){return/(^|[^~])[*?]/.test(n)}function ge(n){return Ye(n)?n:new tt(0,0,1,1,()=>n)}function lt(n,e,t,s){const o=n.map(([l])=>ge(l)),i=n.map(([,l])=>Qc(l,t)),r=o[0];for(const l of o)if(l.rows!==r.rows||l.cols!==r.cols)return se("The ranges have different sizes");for(let l=0;l<r.rows;l++)for(let a=0;a<r.cols;a++){let c=!0;for(let h=0;h<o.length&&c;h++){const d=o[h].get(l,a);c=!w(d)&&i[h](d)}if(c){const h=s(e?e.get(l,a):o[0].get(l,a));if(h)return h}}}function $o(n,e){const t=_(n);if(typeof t=="string"&&e&&eh(t)){const s=dl(t);return o=>typeof o=="string"&&s(o)}return s=>!w(s)&&s!==null&&hs(s,t)===0}function ur(n){return typeof n=="string"?1:typeof n=="boolean"?2:0}function ul(n,e,t=!1){const s=_(e),o=ur(s);let i=-1;for(let r=0;r<n.length;r++){const l=n.get(r);if(l===null||w(l)||ur(l)!==o)continue;const a=hs(l,s);if(!w(a))if(t?a>=0:a<=0)i=r;else break}return i}function Ho(n,e){for(let t=0;t<n.length;t++)if(e(n.get(t)))return t;return-1}function fl(n,e){return{length:n.rows,get:t=>n.get(t,e)}}function gl(n,e){return{length:n.cols,get:t=>n.get(e,t)}}function fr(n){const e=ge(n);return e.rows===1?gl(e,0):e.cols===1?fl(e,0):se("A range of one row or one column is needed")}function $e(n,e){const t=_(n);if(typeof t=="string"){const o=vt(t.trim());if(o!==void 0)return o}const s=z(t,e);return w(s)?s:s<0?we("A negative date"):s}function gr(n){return!Number.isFinite(n)||n<0||n>2958465?we("The date is out of range"):new xt(n)}function th(n,e,t){var h;const s=e.trim(),o=_(n);if(typeof o=="string"&&vt(o.trim())===void 0&&w(z(o,t)))return o;if(/^(yyyy|dd|mm)[-./](mm|dd)[-./](yyyy|dd)$/i.test(s)){const d=$e(n,t);if(w(d))return d;const{y:u,m:f,d:g}=et(d),p=m=>String(m).padStart(2,"0");return s.toLowerCase().replace("yyyy",String(u)).replace(/mm/,p(f)).replace("dd",p(g))}const i=/^(#,##)?0(\.(0+))?(%)?$/.exec(s);if(!i)return se(`TEXT: the format "${s}" is not supported`);let r=z(n,t);if(w(r))return r;i[4]&&(r*=100);const l=((h=i[3])==null?void 0:h.length)??0,a=mi(r,l);let c=Math.abs(a).toFixed(l);if(i[1]){const[d,u]=c.split(".");c=d.replace(/\B(?=(\d{3})+(?!\d))/g,",")+(u?"."+u:"")}return(a<0?"-":"")+c+(i[4]?"%":"")}function sh(n,e,t){if(n>e)return we("The start date is after the end date");const s=et(n),o=et(e);switch(t.toUpperCase()){case"D":return Math.floor(e)-Math.floor(n);case"M":{let i=(o.y-s.y)*12+(o.m-s.m);return o.d<s.d&&i--,i}case"Y":{let i=o.y-s.y;return(o.m<s.m||o.m===s.m&&o.d<s.d)&&i--,i}case"YM":return(o.m-s.m+12-(o.d<s.d?1:0))%12;case"MD":return o.d>=s.d?o.d-s.d:Math.floor(e)-Wt(o.y,o.m-1,s.d);case"YD":{let i=Wt(o.y,s.m,s.d);return i>Math.floor(e)&&(i=Wt(o.y-1,s.m,s.d)),Math.floor(e)-i}default:return we(`DATEDIF unit "${t}" is not supported (d, m, y, ym, md, yd)`)}}const xo=n=>({min:1,max:1,fn:(e,t)=>{const s=qc(e[0],t);if(w(s))return s;const o=n(s);return w(o)?o:W(o)}}),ps=n=>({min:1,max:1,fn:e=>{const t=Zc(e[0]);return w(t)?t:n(t)}}),oh={SUM:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:W(t.reduce((s,o)=>s+o,0))}},PRODUCT:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:W(t.length?t.reduce((s,o)=>s*o,1):0)}},AVERAGE:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:t.length?W(t.reduce((s,o)=>s+o,0)/t.length):nt("AVERAGE of no numbers")}},MIN:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:t.length?t.reduce((s,o)=>Math.min(s,o),1/0):0}},MAX:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:t.length?t.reduce((s,o)=>Math.max(s,o),-1/0):0}},COUNT:{min:1,max:255,fn:(n,e)=>{let t=0;return dt(n,(s,o)=>{(typeof s=="number"||G(s)||!o&&(typeof s=="boolean"||typeof s=="string"&&!w(z(s,e))))&&t++}),t}},COUNTA:{min:1,max:255,fn:n=>{let e=0;return dt(n,t=>{t!==null&&e++}),e}},COUNTBLANK:{min:1,max:1,fn:n=>{let e=0;return dt(n,t=>{ko(t)&&e++}),e}},SUMPRODUCT:{min:1,max:255,fn:n=>{const e=n.map(ge),t=e[0];if(e.some(o=>o.rows!==t.rows||o.cols!==t.cols))return se("SUMPRODUCT: the ranges have different sizes");let s=0;for(let o=0;o<t.rows;o++)for(let i=0;i<t.cols;i++){let r=1;for(const l of e){const a=l.get(o,i);if(w(a))return a;r*=typeof a=="number"?a:G(a)?a.serial:0}s+=r}return W(s)}},ROUND:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:W(mi(t[0],t[1]))}},ROUNDUP:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:W(dr(t[0],t[1],!0))}},ROUNDDOWN:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:W(dr(t[0],t[1],!1))}},INT:xo(n=>Math.floor(xe(n))),ABS:xo(Math.abs),SQRT:xo(n=>n<0?we("SQRT of a negative number"):Math.sqrt(n)),MOD:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:t[1]===0?nt("MOD by zero"):W(t[0]-t[1]*Math.floor(xe(t[0]/t[1])))}},POWER:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:t[0]===0&&t[1]===0?we("0^0"):t[0]===0&&t[1]<0?nt("0 to a negative power"):W(Math.pow(t[0],t[1]))}},FLOOR:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;const[s,o]=t;return o===0?s===0?0:nt("FLOOR with significance 0"):s>0&&o<0?we("FLOOR: a positive number with a negative significance"):W(Math.floor(xe(s/o))*o)}},CEILING:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;const[s,o]=t;return o===0?0:s>0&&o<0?we("CEILING: a positive number with a negative significance"):W(Math.ceil(xe(s/o))*o)}},RAND:{min:0,max:0,volatile:!0,fn:(n,e)=>e.random()},RANDBETWEEN:{min:2,max:2,volatile:!0,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;const s=Math.ceil(t[0]),o=Math.floor(t[1]);return s>o?we("RANDBETWEEN: bottom is greater than top"):s+Math.floor(e.random()*(o-s+1))}},SUMIF:{min:2,max:3,fn:(n,e)=>{let t=0;return lt([[n[0],n[1]]],n[2]!==void 0?ge(n[2]):void 0,e,o=>{if(w(o))return o;typeof o=="number"?t+=o:G(o)&&(t+=o.serial)})??W(t)}},SUMIFS:{min:3,max:255,fn:(n,e)=>{if((n.length-1)%2)return se("SUMIFS needs pairs of range and criterion");const t=[];for(let i=1;i<n.length;i+=2)t.push([n[i],n[i+1]]);let s=0;return lt(t,ge(n[0]),e,i=>{if(w(i))return i;typeof i=="number"?s+=i:G(i)&&(s+=i.serial)})??W(s)}},COUNTIF:{min:2,max:2,fn:(n,e)=>{let t=0;return lt([[n[0],n[1]]],void 0,e,()=>{t++})??t}},COUNTIFS:{min:2,max:254,fn:(n,e)=>{if(n.length%2)return se("COUNTIFS needs pairs of range and criterion");const t=[];for(let i=0;i<n.length;i+=2)t.push([n[i],n[i+1]]);let s=0;return lt(t,void 0,e,()=>{s++})??s}},AVERAGEIF:{min:2,max:3,fn:(n,e)=>{let t=0,s=0;return lt([[n[0],n[1]]],n[2]!==void 0?ge(n[2]):void 0,e,i=>{if(w(i))return i;(typeof i=="number"||G(i))&&(t+=typeof i=="number"?i:i.serial,s++)})??(s?W(t/s):nt("AVERAGEIF: no matching numbers"))}},AVERAGEIFS:{min:3,max:255,fn:(n,e)=>{if((n.length-1)%2)return se("AVERAGEIFS needs pairs of range and criterion");const t=[];for(let r=1;r<n.length;r+=2)t.push([n[r],n[r+1]]);let s=0,o=0;return lt(t,ge(n[0]),e,r=>{if(w(r))return r;(typeof r=="number"||G(r))&&(s+=typeof r=="number"?r:r.serial,o++)})??(o?W(s/o):nt("AVERAGEIFS: no matching numbers"))}},IF:{min:2,max:3,lazy:([n,e,t])=>{const s=ft(n());return w(s)?s:s?e():t?t():!1}},IFS:{min:2,max:254,lazy:n=>{if(n.length%2)return se("IFS needs pairs of condition and value");for(let e=0;e<n.length;e+=2){const t=ft(n[e]());if(w(t))return t;if(t)return n[e+1]()}return ht()}},IFERROR:{min:2,max:2,lazy:([n,e])=>{const t=_(n());return w(t)?e():t}},IFNA:{min:2,max:2,lazy:([n,e])=>{const t=_(n());return w(t)&&t.code==="#N/A"?e():t}},AND:{min:1,max:255,fn:n=>vo(n,e=>e.every(Boolean))},OR:{min:1,max:255,fn:n=>vo(n,e=>e.some(Boolean))},XOR:{min:1,max:255,fn:n=>vo(n,e=>e.filter(Boolean).length%2===1)},NOT:{min:1,max:1,fn:n=>{const e=ft(n[0]);return w(e)?e:!e}},SWITCH:{min:3,max:254,lazy:n=>{const e=_(n[0]());if(w(e))return e;const t=n.length-1;for(let s=1;s+1<n.length;s+=2){const o=_(n[s]());if(w(o))return o;if(hs(e,o)===0)return n[s+1]()}return t%2===1?n[n.length-1]():ht()}},VLOOKUP:{min:3,max:4,fn:(n,e)=>pr(n,e,!0)},HLOOKUP:{min:3,max:4,fn:(n,e)=>pr(n,e,!1)},XLOOKUP:{min:3,max:4,fn:n=>{const e=fr(n[1]);if(w(e))return e;const t=ge(n[2]),s=ge(n[1]).cols===1&&ge(n[1]).rows>1;if((s?t.rows:t.cols)!==e.length)return se("XLOOKUP: the result range must have the size of the lookup range");const o=Ho(e,$o(n[0],!1));return o<0?n.length>3?n[3]:ht():t.rows===1&&t.cols===1?t.get(0,0):s?t.cols===1?t.get(o,0):new tt(t.row+o,t.col,1,t.cols,(i,r)=>t.get(i-t.row,r-t.col)):t.rows===1?t.get(0,o):new tt(t.row,t.col+o,t.rows,1,(i,r)=>t.get(i-t.row,r-t.col))}},INDEX:{min:2,max:3,fn:(n,e)=>{const t=ge(n[0]),s=z(n[1],e);if(w(s))return s;let o=n.length>2?z(n[2],e):0;if(w(o))return o;let i=Math.trunc(s),r=Math.trunc(o);return n.length===2&&t.rows===1?(r=i,i=1):n.length===2&&t.cols===1&&(r=1),i<0||r<0||i>t.rows||r>t.cols?new I("#REF!","INDEX outside the range"):i===0&&r===0?t:i===0?new tt(t.row,t.col+r-1,t.rows,1,(l,a)=>t.get(l-t.row,a-t.col)):r===0?new tt(t.row+i-1,t.col,1,t.cols,(l,a)=>t.get(l-t.row,a-t.col)):t.get(i-1,r-1)}},MATCH:{min:2,max:3,fn:(n,e)=>{const t=fr(n[1]);if(w(t))return t;const s=n.length>2?z(n[2],e):1;if(w(s))return s;const o=_(n[0]);if(w(o))return o;let i;return s===0?i=Ho(t,$o(o,!0)):i=ul(t,o,s<0),i<0?ht():i+1}},CONCAT:{min:1,max:255,fn:n=>{let e="";return dt(n,s=>{const o=re(s);if(w(o))return o;e+=o})??e}},TEXTJOIN:{min:3,max:255,fn:n=>{const e=re(n[0]);if(w(e))return e;const t=ft(n[1]);if(w(t))return t;const s=[];return dt(n.slice(2),i=>{const r=re(i);if(w(r))return r;(!t||r!=="")&&s.push(r)})??s.join(e)}},LEFT:{min:1,max:2,fn:(n,e)=>mr(n,e,!0)},RIGHT:{min:1,max:2,fn:(n,e)=>mr(n,e,!1)},MID:{min:3,max:3,fn:(n,e)=>{const t=re(n[0]);if(w(t))return t;const s=ve(n.slice(1),e);if(w(s))return s;const[o,i]=[Math.trunc(s[0]),Math.trunc(s[1])];return o<1||i<0?se("MID: start must be ≥ 1 and the length ≥ 0"):t.substr(o-1,i)}},LEN:ps(n=>n.length),FIND:{min:2,max:3,fn:(n,e)=>br(n,e,!1)},SEARCH:{min:2,max:3,fn:(n,e)=>br(n,e,!0)},SUBSTITUTE:{min:3,max:4,fn:(n,e)=>{const t=re(n[0]);if(w(t))return t;const s=re(n[1]);if(w(s))return s;const o=re(n[2]);if(w(o))return o;if(s==="")return t;if(n.length<4)return t.split(s).join(o);const i=z(n[3],e);if(w(i))return i;if(i<1)return se("SUBSTITUTE: the instance must be ≥ 1");let r=-1;for(let l=0;l<Math.trunc(i);l++)if(r=t.indexOf(s,r+1),r<0)return t;return t.slice(0,r)+o+t.slice(r+s.length)}},UPPER:ps(n=>n.toUpperCase()),LOWER:ps(n=>n.toLowerCase()),TRIM:ps(n=>n.replace(/ +/g," ").trim()),VALUE:{min:1,max:1,fn:(n,e)=>{const t=_(n[0]);if(typeof t=="boolean")return se("VALUE of a boolean");if(typeof t=="string"){const o=vt(t.trim());if(o!==void 0)return o}const s=z(t,{isoDatesAsDates:e.isoDatesAsDates});return w(s)?s:W(s)}},TEXT:{min:2,max:2,fn:(n,e)=>{const t=re(n[1]);return w(t)?t:th(n[0],t,e)}},TODAY:{min:0,max:0,volatile:!0,fn:(n,e)=>new xt(Math.floor(e.now()))},NOW:{min:0,max:0,volatile:!0,fn:(n,e)=>new xt(e.now())},DATE:{min:3,max:3,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;let s=Math.trunc(t[0]);return s<0||s>9999?we("DATE: year out of range"):(s<1900&&(s+=1900),gr(Wt(s,Math.trunc(t[1]),1)+Math.trunc(t[2])-1))}},YEAR:{min:1,max:1,fn:(n,e)=>{const t=$e(n[0],e);return w(t)?t:et(t).y}},MONTH:{min:1,max:1,fn:(n,e)=>{const t=$e(n[0],e);return w(t)?t:et(t).m}},DAY:{min:1,max:1,fn:(n,e)=>{const t=$e(n[0],e);return w(t)?t:et(t).d}},WEEKDAY:{min:1,max:2,fn:(n,e)=>{const t=$e(n[0],e);if(w(t))return t;const s=n.length>1?z(n[1],e):1;if(w(s))return s;const o=Math.trunc(s),i=((Math.floor(t)-1)%7+7)%7,r=(i+6)%7;return o===1?i+1:o===2?r+1:o===3?r:o>=11&&o<=17?((r-(o-11))%7+7)%7+1:we("WEEKDAY: type must be 1, 2, 3 or 11–17")}},EOMONTH:{min:2,max:2,fn:(n,e)=>{const t=$e(n[0],e);if(w(t))return t;const s=z(n[1],e);if(w(s))return s;const{y:o,m:i}=et(t);return gr(Wt(o,i+Math.trunc(s)+1,0))}},DATEDIF:{min:3,max:3,fn:(n,e)=>{const t=$e(n[0],e);if(w(t))return t;const s=$e(n[1],e);if(w(s))return s;const o=re(n[2]);return w(o)?o:sh(t,s,o)}},ISBLANK:{min:1,max:1,acceptsErrors:!0,fn:n=>_(n[0])===null},ISNUMBER:{min:1,max:1,acceptsErrors:!0,fn:n=>{const e=_(n[0]);return typeof e=="number"||G(e)}},ISTEXT:{min:1,max:1,acceptsErrors:!0,fn:n=>typeof _(n[0])=="string"},ISERROR:{min:1,max:1,acceptsErrors:!0,fn:n=>w(_(n[0]))},ISNA:{min:1,max:1,acceptsErrors:!0,fn:n=>{const e=_(n[0]);return w(e)&&e.code==="#N/A"}},NA:{min:0,max:0,fn:()=>ht()}};function vo(n,e){const t=[],s=dt(n,(o,i)=>{if(w(o))return o;if(typeof o=="boolean")t.push(o);else if(typeof o=="number")t.push(o!==0);else if(G(o))t.push(o.serial!==0);else if(!i&&typeof o=="string"){const r=ft(o);if(w(r))return r;t.push(r)}});return s||(t.length?e(t):se("No logical values"))}function pr(n,e,t){const s=ge(n[1]),o=z(n[2],e);if(w(o))return o;const i=n.length>3?n[3]===null?!1:ft(n[3]):!0;if(w(i))return i;const r=Math.trunc(o);if(r<1)return se("The index must be ≥ 1");if(r>(t?s.cols:s.rows))return new I("#REF!","The index is beyond the table");const l=t?fl(s,0):gl(s,0),a=_(n[0]);if(w(a))return a;const c=i?ul(l,a):Ho(l,$o(a,!0));return c<0?ht():t?s.get(c,r-1):s.get(r-1,c)}function mr(n,e,t){const s=re(n[0]);if(w(s))return s;const o=n.length>1?z(n[1],e):1;if(w(o))return o;if(o<0)return se("The number of characters must be ≥ 0");const i=Math.trunc(o);return t?s.slice(0,i):i===0?"":s.slice(-i)}function br(n,e,t){const s=re(n[0]);if(w(s))return s;const o=re(n[1]);if(w(o))return o;const i=n.length>2?z(n[2],e):1;if(w(i))return i;const r=Math.trunc(i);if(r<1||r>o.length+1)return se("The start is outside the text");if(!t){const a=o.indexOf(s,r-1);return a<0?se(`"${s}" not found`):a+1}const l=ih(hl(s),o,r-1);return l<0?se(`"${s}" not found`):l+1}function ih(n,e,t){const s=n.concat({kind:"star"}),o=s.findIndex(h=>h.kind==="star"),i=s.slice(o);let r=t+o,l=e.length;if(r>l||!Bo(i,e,r))return-1;for(;r<l;){const h=Math.ceil((r+l)/2);Bo(i,e,h)?r=h:l=h-1}const a=r,c=e.toLowerCase();for(let h=t;h+o<=a;h++){let d=0;for(;d<o;){const u=s[d];if(u.kind==="char"&&u.ch!==c[h+d])break;d++}if(d===o)return h}return-1}const rh=new Set(["#ERROR!","#NAME?","#VALUE!","#DIV/0!","#NUM!","#CIRC!","#REF!","#N/A"]),nh=new Set(["SUM","AVERAGE","AVG","MIN","MAX","COUNT"]);function Re(n,e){return n*q+e}function lh(n){return n.replace(/^\s*=/,"")}function wr(n,e,t){let s;try{s=cs(lh(n),!0)}catch(o){const i=o instanceof B?o.toFormulaError():new I("#ERROR!","Invalid formula");return{evaluate:()=>i,singles:[],ranges:[],volatile:!1,error:i}}return new ah(t,e).compile(s)}class ah{constructor(e,t){this.env=e,this.row=t,this.singles=new Set,this.ranges=[],this.volatile=!1}compile(e){const t=this.node(e);return{evaluate:()=>{try{const o=t(),i=Ye(o)?_(o):o;return i===null?0:typeof i=="number"?W(i):i}catch(o){return new I("#VALUE!",o instanceof Error?o.message.slice(0,200):"Evaluation failed")}},singles:Array.from(this.singles),ranges:this.ranges,volatile:this.volatile}}ref(e,t){this.singles.add(Re(e,t));const s=this.env;return()=>s.read(e,t)}node(e){switch(e.kind){case"literal":{const t=e.value;return()=>t}case"ref":return e.row<0||e.col<0||e.row>=ie||e.col>=q?this.fail("#REF!","Invalid reference"):this.ref(e.row,e.col);case"range":return this.range(e.from,e.to);case"field":{const t=this.env.fieldColumn(e.name);return t<0?this.fail("#NAME?",`[${e.name}] is no column of the sheet`):this.ref(this.row,t)}case"error":{const t=rh.has(e.code)?e.code:"#ERROR!";return this.fail(t,e.message??(t==="#REF!"?"A reference to a deleted cell":e.code))}case"unary":{const t=this.node(e.operand),s=this.env;return e.op==="%"?()=>{const o=z(t(),s.fn);return w(o)?o:W(o/100)}:e.op==="+"?()=>_(t()):()=>{const o=_(t()),i=z(o,s.fn);return w(i)?i:W(-i)}}case"binary":return this.binary(e.op,this.node(e.left),this.node(e.right));case"call":return this.call(e.name,e.args)}}fail(e,t){const s=new I(e,t);return()=>s}range(e,t){const s=e.row<0?0:e.row,o=t.row<0?ie-1:t.row,i=e.col<0?0:e.col,r=t.col<0?q-1:t.col;if(s>o||i>r||o>=ie||r>=q)return this.fail("#REF!","Invalid range");this.ranges.push({r1:s,c1:i,r2:o,c2:r});const l=this.env,a=r-i+1;return()=>{const c=Math.max(0,Math.min(o,l.rowCount()-1)-s+1);return c*a>l.maxRangeCells?new I("#ERROR!",`The range has more than ${l.maxRangeCells} cells`):new tt(s,i,c,a,l.read)}}binary(e,t,s){const o=this.env;return e==="&"?()=>{const i=re(t());if(w(i))return i;const r=re(s());return w(r)?r:i+r}:e==="="||e==="<>"||e==="<"||e==="<="||e===">"||e===">="?()=>{const i=hs(t(),s());if(w(i))return i;switch(e){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 i=_(t());if(w(i))return i;const r=_(s());if(w(r))return r;const l=z(i,o.fn);if(w(l))return l;const a=z(r,o.fn);if(w(a))return a;switch(e){case"+":case"-":{const c=e==="+"?l+a:l-a,h=G(i)||o.fn.isoDatesAsDates&&typeof i=="string"&&vt(i.trim())!==void 0,d=G(r)||o.fn.isoDatesAsDates&&typeof r=="string"&&vt(r.trim())!==void 0;if(h&&!d||e==="+"&&d&&!h){const u=W(c);return w(u)?u:new xt(u)}return W(c)}case"*":return W(l*a);case"/":return a===0?new I("#DIV/0!","Division by zero"):W(l/a);default:return l===0&&a===0?new I("#NUM!","0^0"):l===0&&a<0?new I("#DIV/0!","0 to a negative power"):W(Math.pow(l,a))}}}call(e,t){if(nh.has(e)&&t.length===1&&t[0].kind==="field"){const c=t[0].name;return this.fail("#NAME?",`${e}([${c}]) is a column formula – in a cell use a range, e.g. ${e}(D:D)`)}const s=this.env.functions.get(e);if(s){const c=t.map(h=>this.node(h));return()=>{const h=[];for(const d of c){const u=d();if(w(u))return u;h.push(G(u)?u.serial:u)}try{return hh(s(...h),e)}catch(d){return new I("#VALUE!",`${e}: ${d instanceof Error?d.message.slice(0,200):"failed"}`)}}}const o=oh[e];if(!o)return this.fail("#NAME?",`Unknown function ${e}`);if(t.length<o.min||t.length>o.max){const c=o.min===o.max?`${o.min}`:o.max>=254?`at least ${o.min}`:`${o.min} to ${o.max}`;return this.fail("#ERROR!",`${e} needs ${c} argument${o.max===1?"":"s"}, got ${t.length}`)}o.volatile&&(this.volatile=!0),(e==="SUMIF"||e==="AVERAGEIF")&&t.length===3&&(t=[t[0],t[1],ch(t[2],t[0])]);const i=t.map(c=>this.node(c)),r=this.env.fn;if(o.lazy){const c=o.lazy;return()=>c(i,r)}const l=o.fn,a=!!o.acceptsErrors;return()=>{const c=new Array(i.length);for(let h=0;h<i.length;h++){const d=i[h]();if(!a&&w(d))return d;c[h]=d}return l(c,r)}}}function ch(n,e){const t=n.kind==="range"?n.from:n.kind==="ref"?n:void 0;if(!t||e.kind!=="range"||t.row<0||t.col<0)return n;const s=e.to.row-e.from.row,o=e.to.col-e.from.col;return e.from.row<0||e.from.col<0?e.from.row<0?{kind:"range",from:{...t,row:-1},to:{...t,row:-1,col:t.col+o}}:{kind:"range",from:{...t,col:-1},to:{...t,col:-1,row:t.row+s}}:{kind:"range",from:t,to:{...t,row:t.row+s,col:t.col+o}}}function hh(n,e){if(n===void 0)return null;if(typeof n=="number")return Number.isNaN(n)?new I("#NUM!",`${e} returned NaN`):n;if(Ye(n))return n;const t=sn(n);return w(t)&&!w(n)?new I("#VALUE!",`${e} returned no number, text or boolean`):t}function Ht(n,e){switch(n.kind){case"unary":return{...n,operand:Ht(n.operand,e)};case"binary":return{...n,left:Ht(n.left,e),right:Ht(n.right,e)};case"call":return{...n,args:n.args.map(t=>Ht(t,e))};case"ref":case"range":return e(n)??n;default:return n}}function Go(n,e,t=!1){let s;try{s=cs(n,!0)}catch{return n}let o=!1;const i=Ht(s,r=>{const l=e(r);return l&&Gt(l)!==Gt(r)&&(o=!0),l});return t&&!o?n:Gt(i)}const ks={kind:"error",code:"#REF!"};function dh(n,e){return n<ie&&e<q&&n>=-1&&e>=-1}function Ro(n,e,t,s){const o=n.row<0||n.absRow&&!s?n.row:n.row+e,i=n.col<0||n.absCol&&!s?n.col:n.col+t;if(!(n.row>=0&&o<0||n.col>=0&&i<0||!dh(o,i)))return{...n,row:o,col:i}}function pl(n,e,t,s){return Go(n,o=>{if(o.kind==="ref")return Ro(o,e,t,s)??ks;if(o.kind==="range"){const i=Ro(o.from,e,t,s),r=Ro(o.to,e,t,s);return i&&r?{kind:"range",from:i,to:r}:ks}})}function ml(n,e,t){return pl(n,e,t,!1)}function uh(n,e,t){return pl(n,e,t,!0)}function fh(n,e,t,s){return{point(o){if(o<0)return o;if(t)return o<n?o:o+e<s?o+e:void 0;if(!(o>=n&&o<n+e))return o>=n+e?o-e:o},span(o,i){if(o<0)return[o,i];if(t){const c=o>=n?o+e:o;return c>=s?void 0:[c,Math.min(i>=n?i+e:i,s-1)]}const r=n+e-1;if(o>=n&&i<=r)return;const l=o<n?o:o>r?o-e:n,a=i<n?i:i>r?i-e:n-1;return[l,a]}}}function bl(n,e){if(e.kind==="moveCells"){const{from:o,to:i}=e,r=i[0]-o.r1,l=i[1]-o.c1,a=c=>c.row>=o.r1&&c.row<=o.r2&&c.col>=o.c1&&c.col<=o.c2;return Go(n,c=>{if(c.kind==="ref"&&a(c))return{...c,row:c.row+r,col:c.col+l};if(c.kind==="range"&&c.from.row>=0&&c.from.col>=0&&a(c.from)&&a(c.to))return{kind:"range",from:{...c.from,row:c.from.row+r,col:c.from.col+l},to:{...c.to,row:c.to.row+r,col:c.to.col+l}}},!0)}const t=e.kind==="insertRows"||e.kind==="deleteRows",s=fh(e.at,e.count,e.kind==="insertRows"||e.kind==="insertColumns",t?ie:q);return Go(n,o=>{if(o.kind==="ref"){const i=s.point(t?o.row:o.col);return i===void 0?ks:t?{...o,row:i}:{...o,col:i}}if(o.kind==="range"){const i=t?s.span(o.from.row,o.to.row):s.span(o.from.col,o.to.col);return i?t?{kind:"range",from:{...o.from,row:i[0]},to:{...o.to,row:i[1]}}:{kind:"range",from:{...o.from,col:i[0]},to:{...o.to,col:i[1]}}:ks}},!0)}class Tt{constructor(){this.functions={},this.isoDatesAsDates=!0,this.maxRangeCells=1e7,this.rejectInvalidFormulas=!1,this.columns=void 0}static create(e){if(!e)return;const t=new Tt;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&s in t&&(t[s]=o);return t}}const yr=64;function wt(n){return typeof n=="string"&&n.length>1&&n[0]==="="}class ao{constructor(e,t={}){this.source=e,this.formulas=new Map,this.singleDependents=new Map,this.rangeNodes=new Map,this.rangesByColumn=new Map,this.wideRanges=[],this.volatileCells=new Set,this.formulaColumns=new Map,this.fieldColumns=new Map,this.options=Tt.create(t)??new Tt;const s=new Map;for(const[l,a]of Object.entries(this.options.functions??{}))typeof a=="function"&&s.set(l.toUpperCase(),a);const o=t.now??(()=>new Date),i=t.random??Math.random,r=this.options.isoDatesAsDates;this.env={read:(l,a)=>this.read(l,a),rowCount:()=>this.source.getRowCount(),fieldColumn:l=>this.fieldColumn(l),functions:s,maxRangeCells:this.options.maxRangeCells,fn:{isoDatesAsDates:r,now:()=>Ft(o()),random:i}}}static fromArrays(e,t){const s=new ao({getRowCount:()=>e.length,getColumnCount:()=>e.reduce((o,i)=>Math.max(o,(i==null?void 0:i.length)??0),0),getInput:(o,i)=>{var r;return(r=e[o])==null?void 0:r[i]}},t);return s.rebuild(),s}rebuild(){this.formulas.clear(),this.singleDependents.clear(),this.rangeNodes.clear(),this.rangesByColumn.clear(),this.wideRanges.length=0,this.volatileCells.clear(),this.fieldColumns.clear(),this.formulaColumns.clear();const e=Math.min(this.source.getRowCount(),ie),t=Math.min(this.source.getColumnCount(),q),s=[],o=this.source;if(o.forEachInput)return o.forEachInput((i,r,l)=>{i<e&&r<t&&wt(l)&&(!o.isFormulaColumn||o.isFormulaColumn(r))&&(this.add(i,r,l,null),s.push(Re(i,r)))}),this.recalc(s,!0);for(let i=0;i<t;i++)if(!(o.isFormulaColumn&&!o.isFormulaColumn(i)))for(let r=0;r<e;r++){const l=o.getInput(r,i);wt(l)&&(this.add(r,i,l,null),s.push(Re(r,i)))}return this.recalc(s,!0)}inputsChanged(e){const t=[];for(const[s,o]of e){const i=Re(s,o),r=this.formulas.get(i),l=this.source.getInput(s,o),a=wt(l)&&(!this.source.isFormulaColumn||this.source.isFormulaColumn(o));if(r&&a&&r.source===l){t.push(i);continue}r&&this.remove(r),a&&this.add(s,o,l,r?r.value:this.dataValue(s,o)),t.push(i)}return this.volatileCells.forEach(s=>t.push(s)),this.recalc(t,!1)}recalculate(){return this.recalc(Array.from(this.volatileCells),!1)}getValue(e,t){return ji(this.read(e,t))}isFormula(e,t){return this.formulas.has(Re(e,t))}getFormulaCount(){return this.formulas.size}evaluate(e,t){const s=e.trim().startsWith("=")?e:`=${e}`;return ji(wr(s,(t==null?void 0:t[0])??0,this.env).evaluate())}getPrecedents(e,t){const s=this.formulas.get(Re(e,t));if(!s)return[];const o=s.compiled.singles.map(i=>M.singleCell(Math.floor(i/q),i%q));for(const i of s.compiled.ranges)o.push(new M(i.r1,i.c1,i.r2,i.c2));return o}getDependents(e,t){const s=new Set;return this.forEachDependent(Re(e,t),e,t,o=>s.add(o)),Array.from(s,o=>[Math.floor(o/q),o%q])}adjustForStructureChange(e){const t=[];for(const s of Array.from(this.formulas.values())){const o=gh(s.row,s.col,e);if(!o)continue;const i="="+bl(s.source.slice(1),e);i!==s.source&&t.push({row:o[0],col:o[1],input:i})}return t}read(e,t){if(this.formulaColumns.has(t)){const s=this.formulas.get(Re(e,t));if(s)return s.value}return this.dataValue(e,t)}dataValue(e,t){if(e>=this.source.getRowCount())return null;const s=this.source.getInput(e,t);return s===""?null:typeof s=="string"&&s.startsWith("'=")?s.slice(1):sn(s)}fieldColumn(e){var s,o;let t=this.fieldColumns.get(e);return t===void 0&&(t=((o=(s=this.source).getFieldColumn)==null?void 0:o.call(s,e))??-1,this.fieldColumns.set(e,t)),t}add(e,t,s,o){const i=Re(e,t),r=wr(s,e,this.env),l={row:e,col:t,source:s,compiled:r,value:o,rangeKeys:[]};this.formulas.set(i,l),this.formulaColumns.set(t,(this.formulaColumns.get(t)??0)+1);for(const a of r.singles){let c=this.singleDependents.get(a);c||(c=new Set,this.singleDependents.set(a,c)),c.add(i)}for(const a of r.ranges){const c=`${a.r1}:${a.c1}:${a.r2}:${a.c2}`;let h=this.rangeNodes.get(c);if(!h)if(h={...a,key:c,dependents:new Set},this.rangeNodes.set(c,h),a.c2-a.c1+1>yr)this.wideRanges.push(h);else for(let d=a.c1;d<=a.c2;d++){let u=this.rangesByColumn.get(d);u||(u=[],this.rangesByColumn.set(d,u)),ph(u,h)}h.dependents.add(i),l.rangeKeys.push(c)}r.volatile&&this.volatileCells.add(i)}remove(e){const t=Re(e.row,e.col);this.formulas.delete(t);const s=this.formulaColumns.get(e.col)-1;s?this.formulaColumns.set(e.col,s):this.formulaColumns.delete(e.col),this.volatileCells.delete(t);for(const o of e.compiled.singles){const i=this.singleDependents.get(o);i==null||i.delete(t),i&&!i.size&&this.singleDependents.delete(o)}for(const o of e.rangeKeys){const i=this.rangeNodes.get(o);if(i&&(i.dependents.delete(t),!i.dependents.size))if(this.rangeNodes.delete(o),i.c2-i.c1+1>yr)this.wideRanges.splice(this.wideRanges.indexOf(i),1);else for(let r=i.c1;r<=i.c2;r++){const l=this.rangesByColumn.get(r);l.splice(l.indexOf(i),1),l.length||this.rangesByColumn.delete(r)}}}forEachDependent(e,t,s,o){const i=this.singleDependents.get(e);i&&i.forEach(o);const r=this.rangesByColumn.get(s);if(r)for(const l of r){if(l.r2<t)break;t>=l.r1&&l.dependents.forEach(o)}for(const l of this.wideRanges)t>=l.r1&&t<=l.r2&&s>=l.c1&&s<=l.c2&&l.dependents.forEach(o)}dependentsOfKey(e,t){this.forEachDependent(e,Math.floor(e/q),e%q,t)}recalc(e,t){const s=new Map,o=f=>{let g=s.get(f);if(!g){const p=[];this.dependentsOfKey(f,m=>p.push(m)),s.set(f,g=p)}return g},i=new Set,r=new Set(e),l=[...e];for(let f=0;f<l.length;f++){const g=l[f];if(this.formulas.has(g)&&i.add(g),!t)for(const p of o(g))r.has(p)||(r.add(p),l.push(p))}const a=[];let c=0;const h=f=>{const g=this.formulas.get(f),p=g.value;g.value=g.compiled.evaluate(),c++,Cr(p,g.value)||a.push([g.row,g.col])},d=new Set,u=f=>{const g=new Map;f.forEach(m=>g.set(m,0)),f.forEach(m=>{for(const b of o(m))f.has(b)&&g.set(b,g.get(b)+1)});const p=[];g.forEach((m,b)=>{m===0&&p.push(b)});for(let m=0;m<p.length;m++){const b=p[m];h(b),d.add(b);for(const y of o(b)){if(!f.has(y)||d.has(y))continue;const C=g.get(y)-1;g.set(y,C),C===0&&p.push(y)}}};if(u(i),d.size<i.size){const f=new Set(Array.from(i).filter(p=>!d.has(p))),g=new I("#CIRC!","Circular reference");for(const p of this.cycles(f,o)){const m=this.formulas.get(p),b=m.value;m.value=g,c++,Cr(b,g)||a.push([m.row,m.col]),d.add(p),f.delete(p)}u(f)}return{changedCells:a,evaluated:c}}cycles(e,t){const s=new Map,o=new Map,i=new Set,r=[],l=[];let a=0;const c=h=>t(h).filter(d=>e.has(d));for(const h of Array.from(e)){if(s.has(h))continue;const d=[],u=f=>{s.set(f,a),o.set(f,a),a++,r.push(f),i.add(f),d.push({k:f,next:c(f),i:0})};for(u(h);d.length;){const f=d[d.length-1];if(f.i<f.next.length){const g=f.next[f.i++];s.has(g)?i.has(g)&&o.set(f.k,Math.min(o.get(f.k),s.get(g))):u(g);continue}if(d.pop(),d.length){const g=d[d.length-1].k;o.set(g,Math.min(o.get(g),o.get(f.k)))}if(o.get(f.k)===s.get(f.k)){const g=[];let p;do p=r.pop(),i.delete(p),g.push(p);while(p!==f.k);(g.length>1||f.next.includes(f.k))&&l.push(...g)}}}return l}}function Cr(n,e){return Object.is(n,e)?!0:w(n)&&w(e)?n.code===e.code&&n.message===e.message:G(n)&&G(e)?n.serial===e.serial:!1}function gh(n,e,t){switch(t.kind){case"insertRows":return[n>=t.at?n+t.count:n,e];case"deleteRows":return n>=t.at&&n<t.at+t.count?void 0:[n>=t.at+t.count?n-t.count:n,e];case"insertColumns":return[n,e>=t.at?e+t.count:e];case"deleteColumns":return e>=t.at&&e<t.at+t.count?void 0:[n,e>=t.at+t.count?e-t.count:e];case"moveCells":{const{from:s,to:o}=t;return n>=s.r1&&n<=s.r2&&e>=s.c1&&e<=s.c2?[n+o[0]-s.r1,e+o[1]-s.c1]:[n,e]}}}function ph(n,e){let t=0,s=n.length;for(;t<s;){const o=t+s>>1;n[o].r2>=e.r2?t=o+1:s=o}n.splice(t,0,e)}class zt{constructor(e,t,s,o){this.input=e,this.row=t,this.col=s,this.value=o}}class co{constructor(e,t,s){this.tableModel=e,this.body=t,this.options=s,this.dataColumns=[],this.engineColumns=new Map,this.properties=[],this.propertyColumns=new Map,this.formulaColumns=[],this.calculatedColumns=[],this.rowIndex=new Map,this.rowsLength=-1,this.columnCount=-1,this.syncing=!1;const o=t instanceof Ne?t:void 0;this.sheetBody=o,this.engine=new ao({getRowCount:()=>this.rowCountOf(),getColumnCount:()=>this.dataColumns.length,getInput:(i,r)=>this.readInput(i,r),isFormulaColumn:i=>this.formulaColumns[i],getFieldColumn:i=>this.propertyColumns.get(i)??-1,...o?{forEachInput:i=>o.forEachCell(i)}:{}},s)}static create(e,t){const s=e.getBodyModel();if(!(s instanceof K)&&!(s instanceof Q)&&!(s instanceof Ne)){console.warn("GuiExpert Table – cellFormulas: only a flat body (an object array or an array of arrays) has cell formulas; a tree, a row grouping or a pivot table has none.");return}const o=new co(e,s,t);return o.sync(),s.sheetCells=o,o}destroy(){this.body.sheetCells===this&&(this.body.sheetCells=void 0)}valueAt(e,t,s){return this.valueOf(e,this.columnOf(t),s)}valueOfProperty(e,t,s){return this.valueOf(e,this.propertyColumns.get(t),s)}isFormulaProperty(e){const t=this.propertyColumns.get(e);return t!==void 0&&this.formulaColumns[t]}isFormulaColumnIndex(e){const t=this.columnOf(e);return t!==void 0&&this.formulaColumns[t]}isFormulaInput(e,t){return wt(t)&&this.isFormulaColumnIndex(e)}syntaxError(e){try{cs(e.slice(1),!0);return}catch(t){return t instanceof Error?t.message:String(t)}}cellsWritten(e){if(this.sync())return;const t=[],s=new Set;for(const o of e){const i=this.columnOf(o.columnIndex),r=o.row!==void 0&&o.row!==null&&typeof o.row=="object"?this.physicalOfRow(o.row):this.physicalRow(o.rowIndex);i!==void 0&&r!==void 0&&t.push([r,i]),r!==void 0&&s.add(r)}s.forEach(o=>{for(const i of this.calculatedColumns)t.push([o,i])}),t.length&&this.engine.inputsChanged(t)}recalculate(){this.sync()||this.engine.rebuild()}cellValue(e,t){return this.sync(),this.engine.getValue(e,t)}evaluate(e){return this.sync(),this.engine.evaluate(e)}inputAt(e,t){return this.readInput(e,t)}writeInput(e,t,s){if(this.sheetBody){const l=typeof e=="number"?e:this.sheetBody.getPhysicalRowOfArray(e);l!==void 0&&this.sheetBody.setCell(l,t,s);return}const o=typeof e=="number"?this.rows()[e]:e;if(o==null)return;if(!(this.body instanceof K)){o[this.dataColumns[t]]=s;return}const i=this.properties[t].split(".");let r=o;for(let l=0;l<i.length-1;l++){if(r[i[l]]===null||r[i[l]]===void 0)return;r=r[i[l]]}r[i[i.length-1]]=s}rowsArray(){return this.sheetBody?void 0:this.rows()}rowCount(){return this.sync(),this.rowCountOf()}physicalRow(e){if(this.sync(),!(e<0||e>=this.body.getRowCount()))return this.sheetBody?this.sheetBody.getPhysicalRowIndex(e):this.rowIndex.get(this.body.getRowByIndex(e))}displayRow(e){if(this.sync(),this.sheetBody)return this.sheetBody.getDisplayRowIndex(e);const t=this.rows()[e];if(t===void 0)return-1;const s=this.body.getRowCount();if(e<s&&this.body.getRowByIndex(e)===t)return e;for(let o=0;o<s;o++)if(this.body.getRowByIndex(o)===t)return o;return-1}engineColumn(e){return this.sync(),this.columnOf(e)}modelColumn(e){var o;if(this.sync(),!(this.body instanceof K))return this.dataColumns[e]??-1;const t=this.properties[e];if(t===void 0)return-1;const s=this.tableModel.getColumnCount();for(let i=0;i<s;i++)if(((o=this.tableModel.getColumnDef(i))==null?void 0:o.property)===t&&this.columnOf(i)===e)return i;return-1}address(e,t){const s=this.physicalRow(e),o=this.columnOf(t);return s===void 0||o===void 0?void 0:mt(s,o)}cellOfAddress(e){const t=Ue(e);if(!t)return;const s=this.modelColumn(t.col);if(!(s<0||t.row>=this.rowCountOf()))return[this.displayRow(t.row),s]}moveFormula(e,t,s,o,i){const r=this.physicalRow(o),l=this.columnOf(i);if(!(r===void 0||l===void 0||!this.formulaColumns[l]))return"="+ml(e.slice(1),r-t,l-s)}copyOf(e,t,s,o){if(typeof s=="string"&&s.startsWith("'=")&&this.isFormulaColumnIndex(t))return s;if(!this.isFormulaInput(t,s))return o;const i=this.physicalRow(e),r=this.columnOf(t);return i===void 0?o:new zt(s,i,r,o)}precedents(e,t){const s=this.physicalRow(e),o=this.columnOf(t);return s===void 0||o===void 0?[]:this.engine.getPrecedents(s,o).map(i=>{if(i.r1===0&&i.r2>=ie-1)return`${Pe(i.c1)}:${Pe(i.c2)}`;if(i.c1===0&&i.c2>=q-1)return`${i.r1+1}:${i.r2+1}`;const r=mt(i.r1,i.c1);return i.r1===i.r2&&i.c1===i.c2?r:`${r}:${mt(i.r2,i.c2)}`})}dependents(e,t){const s=this.physicalRow(e),o=this.columnOf(t);if(s===void 0||o===void 0)return[];const i=this.engine.getDependents(s,o);if(!i.length)return[];if(this.sheetBody)return i.map(([d,u])=>[this.sheetBody.getDisplayRowIndex(d),this.modelColumn(u)]).filter(([d,u])=>d>=0&&u>=0);const r=new Map,l=this.body.getRowCount();for(let d=0;d<l;d++)r.set(this.body.getRowByIndex(d),d);const a=new Map,c=this.rows(),h=[];for(const[d,u]of i){let f=a.get(u);f===void 0&&a.set(u,f=this.modelColumn(u));const g=r.get(c[d]);g!==void 0&&f>=0&&h.push([g,f])}return h}allowsColumnDrag(){return this.body instanceof K}columnOf(e){if(!(this.body instanceof K))return this.engineColumns.get(e);const t=this.tableModel.getColumnDef(e);if(!(!t||O(t)||me(t)))return this.propertyColumns.get(t.property)}valueOf(e,t,s){if(t===void 0||!this.formulaColumns[t])return s;if(s.startsWith("'="))return s.slice(1);if(!wt(s)||this.syncing)return s;this.sync();const o=this.physicalOfRow(e);return o===void 0?s:this.engine.getValue(o,t)}physicalOfRow(e){return this.sheetBody?this.sheetBody.getPhysicalRowOfArray(e):this.rowIndex.get(e)}rowCountOf(){return this.sheetBody?this.sheetBody.getUnfilteredRowCount():this.rows().length}rows(){return this.body instanceof K?this.body.getAllRows():this.body instanceof Q?this.body.arr:[]}readInput(e,t){if(this.sheetBody)return this.sheetBody.getCell(e,t);const s=this.rows()[e];if(s==null)return;if(!(this.body instanceof K))return s[this.dataColumns[t]];const o=this.properties[t];if(this.body.isCalculatedProperty(o)&&!this.formulaColumns[t])return this.body.getRowValue(s,o);let i=s;for(const r of o.split(".")){if(i==null)return;i=i[r]}return i}sync(){var i,r;if(this.syncing)return!1;const e=this.sheetBody?this.sheetBody.version:this.rows(),t=this.rowCountOf(),s=((r=(i=this.tableModel).getColumnDefs)==null?void 0:r.call(i))??[],o=this.tableModel.getColumnCount();if(e===this.rowsRef&&t===this.rowsLength&&s===this.columnDefsRef&&o===this.columnCount)return!1;this.syncing=!0;try{(s!==this.columnDefsRef||o!==this.columnCount)&&this.buildColumns(s,o),this.rowsRef=e,this.rowsLength=t,this.rowIndex=new Map;const l=this.rows();for(let a=l.length-1;a>=0;a--)this.rowIndex.set(l[a],a);this.engine.rebuild()}finally{this.syncing=!1}return!0}buildColumns(e,t){this.columnDefsRef=e,this.columnCount=t,this.dataColumns=[],this.properties=[],this.formulaColumns=[],this.calculatedColumns=[],this.engineColumns.clear(),this.propertyColumns.clear();const s=this.options.columns;for(let o=0;o<t;o++){const i=e[o]??this.tableModel.getColumnDef(o);if(O(i)||me(i))continue;const r=this.dataColumns.length,l=(i==null?void 0:i.property)??"";this.dataColumns.push(o),this.properties.push(l),this.engineColumns.set(o,r),l&&!this.propertyColumns.has(l)&&this.propertyColumns.set(l,r);const a=!!(i!=null&&i.valueGetter);a&&this.calculatedColumns.push(r),this.formulaColumns.push(!a&&(i==null?void 0:i.cellFormulas)!==!1&&(!s||s.includes(l)))}}}function wl(n){const e=n.map(s=>s.map(mh).join(" ")).join(`
|
|
64
|
+
`)}formulaCellXml(e,t,s){const o=`<f>${this.escapeXml(t)}</f>`;if(typeof s=="number"&&Number.isFinite(s))return`<c r="${e}">${o}<v>${s}</v></c>`;if(s instanceof Date&&!isNaN(s.getTime()))return`<c r="${e}" s="${this.numberFormatStyles.get(wo)??0}">${o}<v>${Lt(s)}</v></c>`;if(typeof s=="boolean")return`<c r="${e}" t="b">${o}<v>${s?1:0}</v></c>`;if(w(s)){const r=["#DIV/0!","#NAME?","#VALUE!","#REF!","#N/A","#NUM!","#NULL!"].includes(s.code)?s.code:"#VALUE!";return`<c r="${e}" t="e">${o}<v>${r}</v></c>`}const i=s==null?"":this.escapeXml(String(s));return`<c r="${e}" t="str">${o}<v>${i}</v></c>`}withNumberFormats(e,t){const s=[];for(const r of t)for(const l of r)ws(l)&&!s.includes(l.numberFormat)&&s.push(l.numberFormat),bs(l)&&l.value instanceof Date&&!s.includes(wo)&&s.push(wo);if(this.numberFormatStyles=new Map(s.map((r,l)=>[r,l+1])),!s.length)return e;const o=`<numFmts count="${s.length}">`+s.map((r,l)=>`<numFmt numFmtId="${164+l}" formatCode="${this.escapeXml(r)}"/>`).join("")+"</numFmts>",i=`<cellXfs count="${s.length+1}"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>`+s.map((r,l)=>`<xf numFmtId="${164+l}" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>`).join("")+"</cellXfs>";return e.replace("<fonts ",`${o}<fonts `).replace('<cellXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/></cellXfs>',i)}escapeXml(e){return e==null?"":String(e).replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g,"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}getCellAddress(e,t){const s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";let o="";for(;t>=0;)o=s[t%26]+o,t=Math.floor(t/26)-1;return`${o}${e+1}`}createZip(e){const t=[];return e.forEach((s,o)=>{const i=new TextEncoder().encode(s);t.push({path:new TextEncoder().encode(o),data:i,size:i.length,crc:sr(i),method:0})}),this.assembleZip(t)}async createZipCompressed(e){const t=[];for(const[s,o]of Array.from(e.entries())){const i=new TextEncoder().encode(o),r=await kc(i),l=!!r&&r.length<i.length;t.push({path:new TextEncoder().encode(s),data:l?r:i,size:i.length,crc:sr(i),method:l?8:0})}return this.assembleZip(t)}assembleZip(e){const t=[],s=[];let o=0;for(const h of e){const d=new Uint8Array(30+h.path.length),u=new DataView(d.buffer);d.set([80,75,3,4],0),u.setUint16(4,20,!0),u.setUint16(6,0,!0),u.setUint16(8,h.method,!0),u.setUint16(10,0,!0),u.setUint16(12,33,!0),u.setUint32(14,h.crc,!0),u.setUint32(18,h.data.length,!0),u.setUint32(22,h.size,!0),u.setUint16(26,h.path.length,!0),u.setUint16(28,0,!0),d.set(h.path,30),t.push(d,h.data),s.push(o),o+=d.length+h.data.length}const i=o;e.forEach((h,d)=>{const u=new Uint8Array(46+h.path.length),f=new DataView(u.buffer);u.set([80,75,1,2],0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(8,0,!0),f.setUint16(10,h.method,!0),f.setUint16(12,0,!0),f.setUint16(14,33,!0),f.setUint32(16,h.crc,!0),f.setUint32(20,h.data.length,!0),f.setUint32(24,h.size,!0),f.setUint16(28,h.path.length,!0),f.setUint16(30,0,!0),f.setUint16(32,0,!0),f.setUint16(34,0,!0),f.setUint16(36,0,!0),f.setUint32(38,0,!0),f.setUint32(42,s[d],!0),u.set(h.path,46),t.push(u),o+=u.length});const r=new Uint8Array(22),l=new DataView(r.buffer);r.set([80,75,5,6],0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o-i,!0),l.setUint32(16,i,!0),t.push(r);const a=new Uint8Array(t.reduce((h,d)=>h+d.length,0));let c=0;for(const h of t)a.set(h,c),c+=h.length;return a}}const $s=class $s{constructor(e,t,s){this.document=e,this.id=t,this.domService=s}announce(e,t=$s.defaultDelayInMs){const s=this.getOrCreateElement();s&&(this.timeout&&clearTimeout(this.timeout),s.textContent="",this.pendingText=e,this.timeout=setTimeout(()=>{this.timeout=void 0,this.pendingText=void 0,s.textContent=e},Math.max(0,t)))}cancel(e){this.timeout&&(e===void 0||e===this.pendingText)&&(clearTimeout(this.timeout),this.timeout=void 0,this.pendingText=void 0)}getElement(){return this.getOrCreateElement()}destroy(){var e;this.timeout&&(clearTimeout(this.timeout),this.timeout=void 0),(e=this.element)==null||e.remove(),this.element=void 0}getOrCreateElement(){var i;if(this.element)return this.element;const e=(i=this.document)==null?void 0:i.body;if(!e)return;const t=this.domService,s=t.createElement("div");t.setAttribute(s,"id",this.id),t.setAttribute(s,"role","status"),t.setAttribute(s,"aria-live","polite"),t.setAttribute(s,"aria-atomic","true"),t.addClass(s,"ge-table-sr-only");const o={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)","white-space":"nowrap",border:"0"};for(const r in o)t.setStyle(s,r,o[r]);return t.appendChild(e,s),this.element=s,s}};$s.defaultDelayInMs=150;let Ds=$s;class so{constructor(){this.managed=!0,this.multiRow=!0,this.treeDropInside=!0,this.dragThresholdInPx=4,this.autoScrollZoneInPx=40,this.autoScrollMaxSpeedInPx=24,this.ghostText=void 0}static create(e){const t=new so;for(const[s,o]of Object.entries(e??{}))o!==void 0&&(t[s]=o);return t}}class Pn{constructor(e,t,s,o,i,r,l,a,c){this.type=e,this.source=t,this.rows=s,this.rowIndices=o,this.target=i,this.toIndex=r,this.outside=l,this.managed=a,this.originalEvent=c,this.moved=!1,this.prevented=!1}get defaultPrevented(){return this.prevented}preventDefault(){this.prevented=!0}}const yo="drag-row";class Nn{constructor(e){this.tableScope=e,this.autoScrollFrame=0,this.suppressClick=!1,this.warnedUnsupported=!1;const t=e.listenerAbortController.signal;e.hostElement.addEventListener("pointerdown",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onPointerDown(s)},{signal:t}),e.hostElement.addEventListener("click",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onClickCapture(s)},{capture:!0,signal:t}),e.hostElement.addEventListener("dblclick",s=>{var o;!((o=e.isEventInDetail)!=null&&o.call(e,s))&&s.target instanceof Element&&s.target.closest(`[data-ge-action="${yo}"]`)&&s.stopPropagation()},{capture:!0,signal:t})}get options(){return so.create(this.tableScope.tableOptions.rowDragOptions)}isDragging(){return!!this.session}isDragSourceRow(e){return!!this.session&&this.session.rowSet.has(e)}getBlockReason(){var s;if(!this.isManaged())return;if(this.tableScope.tableSheet)return"cellFormulas";if(this.isSorted())return"sorted";const e=this.tableScope.tableModel.getBodyModel(),t=(s=e.getUnfilteredRowCount)==null?void 0:s.call(e);if(t!==void 0&&t>e.getRowCount())return"filtered"}getHandleState(e,t,s){const o=t==null?void 0:t.rowDrag;if(!o||To(s))return"none";const i=s.getRowByIndex(e);return Mo(i)||typeof o=="function"&&!o(i,e)?"none":this.isManaged()&&!this.canModelMove(s)?(this.warnedUnsupported||(this.warnedUnsupported=!0,console.warn("GuiExpert Table: rowDrag is set, but the body model cannot move rows (no moveRows(), or row grouping / pivot). Use rowDragOptions: { managed: false } and move the rows yourself.")),"none"):this.getBlockReason()?"disabled":"enabled"}decorateCell(e,t){if(t==="none")return;const s=this.tableScope.getDomService().domService,o=s.createElement("span");s.addClass(o,"ge-table-row-drag-handle"),t==="disabled"&&s.addClass(o,"ge-table-row-drag-handle-disabled"),s.setAttribute(o,"data-ge-action",yo),s.setAttribute(o,"aria-hidden","true"),s.appendChild(e,o),s.addClass(e,"ge-table-row-drag-cell"),s.setAttribute(e,"aria-keyshortcuts","Control+Alt+ArrowUp Control+Alt+ArrowDown")}onPointerDown(e){var i;if(this.session||this.pending||e.pointerType==="mouse"&&e.button!==0)return;const t=e.target instanceof Element?e.target:null,s=t==null?void 0:t.closest(`[data-ge-action="${yo}"]`);if(!s||!this.tableScope.hostElement.contains(s)||this.tableScope.tableOverlay.isEventBlocked(e)||this.tableScope.isEditing())return;e.preventDefault();const o=Number((i=s.closest("[data-row-index]"))==null?void 0:i.getAttribute("data-row-index"));if(!(!Number.isInteger(o)||o<0)){if(s.classList.contains("ge-table-row-drag-handle-disabled")){this.announceNotPossible();return}this.pending={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,rowIndex:o},this.listenToDocument()}}listenToDocument(){this.sessionAbortController=new AbortController;const e=this.sessionAbortController.signal,t=this.tableScope.hostElement.ownerDocument;t.addEventListener("pointermove",s=>this.onPointerMove(s),{signal:e}),t.addEventListener("pointerup",s=>this.onPointerUp(s),{signal:e}),t.addEventListener("pointercancel",s=>this.onPointerCancel(s),{signal:e}),t.addEventListener("keydown",s=>this.onKeyDown(s),{capture:!0,signal:e}),this.tableScope.scrollViewport.addEventListener("scroll",()=>{var s;(s=this.session)!=null&&s.lastEvent&&!this.autoScrollFrame&&this.updateTarget(this.session.lastEvent)},{signal:e})}onPointerMove(e){if(!(!this.pending||e.pointerId!==this.pending.pointerId)){if(!this.session){const t=e.clientX-this.pending.startX,s=e.clientY-this.pending.startY;if(Math.hypot(t,s)<this.options.dragThresholdInPx||!this.startPointerDrag(e))return}e.preventDefault(),this.session&&this.updateTarget(e)}}onPointerUp(e){if(!(!this.pending||e.pointerId!==this.pending.pointerId)){if(!this.session){this.stopListening();return}this.updateTarget(e),this.suppressClick=!0,setTimeout(()=>this.suppressClick=!1,0),this.session&&this.drop(e)}}onPointerCancel(e){this.pending&&e.pointerId===this.pending.pointerId&&this.cancel(e)}onKeyDown(e){e.key==="Escape"&&(this.session||this.pending)&&(e.preventDefault(),e.stopPropagation(),this.cancel(e))}onClickCapture(e){this.suppressClick&&(this.suppressClick=!1,e.stopPropagation(),e.preventDefault())}startPointerDrag(e){var r,l;const t=this.pending,s=this.getDragRowIndices(t.rowIndex),o=this.getRows(s),i=this.createEvent("start","pointer",o,s,void 0,!1,e);return(l=(r=this.tableScope.getEventListener()).onRowDragStart)==null||l.call(r,i),i.defaultPrevented||this.pending!==t?(this.stopListening(),!1):(this.session={source:"pointer",rowIndices:s,rows:o,outside:!1,autoScrollSpeed:0,rowSet:new Set(s),options:this.options,scrollRemainder:0},this.createDragElements(o),this.tableScope.repaint(),this.tableScope.announce(this.texts().rowDragStarted(o.length)),!0)}updateTarget(e){var l,a;const t=this.session;t.lastEvent=e;const{target:s,outside:o}=this.computeTarget(e.clientX,e.clientY);let i=s&&this.isValidTarget(t.rowIndices,s)?s:void 0;if(!Lc(i,t.target)||o!==t.outside){const c=this.createEvent("move","pointer",t.rows,t.rowIndices,i,o,e);if((a=(l=this.tableScope.getEventListener()).onRowDragMove)==null||a.call(l,c),this.session!==t)return;c.defaultPrevented&&(i=void 0)}t.target=i,t.outside=o,this.renderDragElements(e),t.autoScrollSpeed=o?0:this.calcAutoScrollSpeed(e.clientY),t.autoScrollSpeed&&!this.autoScrollFrame?this.autoScrollFrame=requestAnimationFrame(()=>this.autoScrollStep()):t.autoScrollSpeed||(t.lastFrameTime=void 0,t.scrollRemainder=0)}autoScrollStep(){this.autoScrollFrame=0;const e=this.session;if(!e||!e.autoScrollSpeed)return;const t=this.tableScope.scrollViewport,s=t.scrollTop,o=performance.now(),i=e.lastFrameTime?Math.min(4,(o-e.lastFrameTime)/(1e3/60)):1;e.lastFrameTime=o;const r=e.autoScrollSpeed*i*this.tableScope.getScrollerToContentRatioY()+e.scrollRemainder,l=Math.trunc(r);e.scrollRemainder=r-l,t.scrollTop=s+l,t.scrollTop!==s&&this.tableScope.adjustAfterScrolling(),this.updateTarget(e.lastEvent)}calcAutoScrollSpeed(e){const{autoScrollZoneInPx:t,autoScrollMaxSpeedInPx:s}=this.session.options;if(t<=0||s<=0)return 0;const o=this.tableScope.getBodyViewport(),i=e-o.top,r=o.top+o.height-e,l=a=>Math.max(1,Math.round(s*Math.min(1,a/t)**2));return i<t?-l(t-i):r<t?l(t-r):0}computeTarget(e,t){var p;const s=this.tableScope.hostElement.getBoundingClientRect();if(e<s.left||e>s.right||t<s.top||t>s.bottom)return{outside:!0};const o=this.tableScope.tableModel.getBodyModel(),i=o.getRowCount();if(i<1)return{outside:!1};const r=this.tableScope.getBodyViewport(),a=Math.min(Math.max(t,r.top),r.top+Math.max(0,r.height-1))-r.top+r.contentScrollTop,c=this.tableScope.getBodyRowIndexAtY(a),h=this.tableScope.getBodyRowTop(c),d=Math.max(1,o.getRowHeight(c)),u=Math.min(1,Math.max(0,(a-h)/d));let f;const g=Z(o);if(g&&(((p=this.session)==null?void 0:p.options)??this.options).treeDropInside?f=u<.25?"before":u>.75?"after":"inside":f=u<.5?"before":"after",g&&f==="after"&&c+1<i){const m=o.getRowByIndex(c),b=o.getRowByIndex(c+1);if(b!=null&&b.parent&&b.parent===m)return{target:{rowIndex:c+1,position:"before"},outside:!1}}return{target:{rowIndex:c,position:f},outside:!1}}isValidTarget(e,t){if(!this.isManaged())return!0;const s=this.tableScope.tableModel.getBodyModel();return!!s.moveRows&&!this.tableScope.tableSheet&&(s.canMoveRows?s.canMoveRows(e,t):!0)}drop(e){var r,l;const t=this.session,s=t.outside?void 0:t.target,o=this.createEvent("end",t.source,t.rows,t.rowIndices,s,t.outside,e);this.stopListening();const i=s&&this.isManaged()?this.moveRows(t.rowIndices,s,!0):-1;i>-1?(o.moved=!0,o.toIndex=i):this.tableScope.repaint(),(l=(r=this.tableScope.getEventListener()).onRowDragEnd)==null||l.call(r,o)}cancel(e){var s,o;const t=this.session;if(this.stopListening(),t){this.tableScope.repaint(),this.tableScope.announce(this.texts().rowDragCancelled());const i=this.createEvent("cancel",t.source,t.rows,t.rowIndices,void 0,t.outside,e);(o=(s=this.tableScope.getEventListener()).onRowDragEnd)==null||o.call(s,i)}}stopListening(){var t,s,o;(t=this.sessionAbortController)==null||t.abort(),this.sessionAbortController=void 0,this.pending=void 0,this.session=void 0,this.autoScrollFrame&&(cancelAnimationFrame(this.autoScrollFrame),this.autoScrollFrame=0),(s=this.ghost)==null||s.remove(),(o=this.indicator)==null||o.remove(),this.ghost=void 0,this.indicator=void 0,this.tableScope.hostElement.classList.remove("ge-table-row-drag-active","ge-table-row-drag-invalid")}destroy(){this.cancel()}createDragElements(e){const t=this.tableScope.getDomService(),s=this.tableScope.hostElement;this.ghost=t.setAriaHidden(t.createDivWithClass("ge-table-row-drag-ghost",s)),this.ghost.textContent=this.getGhostText(e),this.indicator=t.setAriaHidden(t.createDivWithClass("ge-table-row-drop-indicator",s)),s.classList.add("ge-table-row-drag-active")}getGhostText(e){const t=this.session.options.ghostText;if(t)return String(t(e)??"");const s=this.session.rowIndices[0],o=this.tableScope.tableModel.getBodyModel(),i=this.getHandleColumnIndex(s),l=(i>-1?o.getTextValueAt(s,i):"")||`Row ${s+1}`;return e.length>1?`${l} (+${e.length-1})`:l}renderDragElements(e){const t=this.session,s=this.ghost,o=this.indicator,i=this.tableScope.hostElement,r=i.getBoundingClientRect(),l=this.tableScope.getDomService();l.setStyle(s,"left",`${this.tableScope.clientXToHostX(e.clientX)+12}px`),s.style.top=`${e.clientY-r.top-i.clientTop+8}px`,i.classList.toggle("ge-table-row-drag-invalid",!t.target&&!t.outside);const a=t.target,c=this.tableScope.getBodyViewport();if(!a){o.style.display="none";return}const h=this.tableScope.tableModel.getBodyModel(),d=this.tableScope.getBodyRowTop(a.rowIndex),u=h.getRowHeight(a.rowIndex)+(a.position==="after"?this.tableScope.getBodyRowLayout().getExtraHeight(a.rowIndex):0),f=c.top-r.top-i.clientTop,g=a.position==="inside",p=f+d-c.contentScrollTop+(a.position==="after"?u:0),m=g?p:p-1,b=g?u:2,y=m+b>=f&&m<=f+c.height;o.classList.toggle("ge-table-row-drop-indicator-inside",g),l.applyStyle(o,{display:y?"block":"none",left:"0px",width:`${this.getMarkerWidth(c.width)}px`,top:`${m}px`,height:`${b}px`})}getMarkerWidth(e){const t=this.tableScope.tableModel,s=t.getPadding(),o=s.left+t.getContentWidthInPixel()+s.right;return o>0?Math.min(e,o):e}moveRows(e,t,s=!0){const o=this.tableScope,i=o.tableModel.getBodyModel(),r=it(e,i.getRowCount());if(!r.length||!i.moveRows||this.isSorted()||o.tableSheet||i.canMoveRows&&!i.canMoveRows(r,t))return-1;const l=Z(i),a=Io(r,t),c=r[r.length-1]-r[0]===r.length-1;if(!l&&c&&a===r[0])return-1;const h=l?r.map(p=>i.getRowByIndex(p)):[];if(!i.moveRows(r,t))return-1;o.afterRowsMoved();const d=l?this.findDisplayIndices(i,h):[];let u=l?-1:a;for(const p of d)(u<0||p<u)&&(u=p);const f=o.selectionModel();if(f&&f.hasSelection()&&(f.clear(),s&&r.length>1)){const p=o.tableModel.getColumnCount()-1;l?d.forEach(m=>f.addSelection(new M(m,0,m,p))):f.addSelection(new M(a,0,a+r.length-1,p))}const g=o.focusModel();if(g&&u>-1){const[,p]=g.getFocus();g.setFocus(u,p>-1?p:Math.max(0,this.getHandleColumnIndex(u)))}return o.repaintHard(),u>-1&&o.ensureRowIsVisible(u),o.stateService.markDirty("selection"),o.announce(this.texts().rowMoved(u+1,i.getRowCount())),u}findDisplayIndices(e,t){const s=new Set(t),o=[],i=e.getRowCount();for(let r=0;r<i&&o.length<s.size;r++)s.has(e.getRowByIndex(r))&&o.push(r);return o}moveByKeyboard(e){var p,m,b,y,C,S;const t=this.tableScope;if(this.session||t.isEditing())return!1;const s=t.focusModel(),o=t.tableModel.getBodyModel(),[i]=(s==null?void 0:s.getFocus())??[-1,-1],r=i<0||i>=o.getRowCount()?-1:this.getHandleColumnIndex(i);if(r<0)return!1;if(this.getHandleStateOfRow(i,r)==="disabled")return this.announceNotPossible(),!0;const l=Z(o),a=l?[i]:this.getDragRowIndices(i),c=l?this.getTreeKeyboardTarget(o,i,e):this.getFlatKeyboardTarget(a,e,o.getRowCount());if(!c)return!0;const h=this.getRows(a),d=this.createEvent("start","keyboard",h,a,void 0,!1);if((m=(p=t.getEventListener()).onRowDragStart)==null||m.call(p,d),d.defaultPrevented)return!0;const u=this.createEvent("move","keyboard",h,a,c,!1);(y=(b=t.getEventListener()).onRowDragMove)==null||y.call(b,u);const f=!u.defaultPrevented&&this.isValidTarget(a,c),g=this.createEvent("end","keyboard",h,a,f?c:void 0,!1);if(f&&this.isManaged()){const E=this.moveRows(a,c,!0);g.moved=E>-1,g.moved&&(g.toIndex=E)}return(S=(C=t.getEventListener()).onRowDragEnd)==null||S.call(C,g),!0}getFlatKeyboardTarget(e,t,s){if(t<0){const i=e[0];return i>0?{rowIndex:i-1,position:"before"}:void 0}const o=e[e.length-1];return o<s-1?{rowIndex:o+1,position:"after"}:void 0}getTreeKeyboardTarget(e,t,s){const o=e.getRowByIndex(t),i=e.rows??[],r=o!=null&&o.parent?o.parent.children??[]:i,l=r[r.indexOf(o)+s];if(!l)return;const[a]=this.findDisplayIndices(e,[l]);return a===void 0?void 0:{rowIndex:a,position:s<0?"before":"after"}}getDragRowIndices(e){const t=this.tableScope.tableModel.getBodyModel().getRowCount(),s=this.tableScope.selectionModel();if(this.options.multiRow&&(s!=null&&s.hasSelection())){const o=it(s.getMergedRowIndices(t),t);if(o.includes(e))return o}return[e]}getRows(e){const t=this.tableScope.tableModel.getBodyModel(),s=ne(t);return e.map(o=>{const i=t.getRowByIndex(o);return s&&U(i)&&!Mo(i)?i.data:i})}getHandleColumnIndex(e){const t=this.tableScope.tableModel,s=t.getBodyModel(),o=t.getColumnCount();for(let i=0;i<o;i++){const r=t.getColumnDef(i);if(r!=null&&r.rowDrag&&this.getHandleState(e,r,s)!=="none")return i}return-1}getHandleStateOfRow(e,t){const s=this.tableScope.tableModel;return this.getHandleState(e,s.getColumnDef(t),s.getBodyModel())}isSorted(){var e,t,s;return!!((s=(t=(e=this.tableScope.tableModel).getColumnDefs)==null?void 0:t.call(e))!=null&&s.some(o=>o.sortState==="asc"||o.sortState==="desc"))}isManaged(){var e;return((e=this.tableScope.tableOptions.rowDragOptions)==null?void 0:e.managed)!==!1}canModelMove(e){return!!e.moveRows&&!ne(e)&&!To(e)}createEvent(e,t,s,o,i,r,l){const a=Z(this.tableScope.tableModel.getBodyModel()),c=i&&!a?Io(o,i):-1;return new Pn(e,t,s,[...o],i?{...i}:void 0,c,r,this.isManaged(),l)}announceNotPossible(){this.tableScope.announce(this.texts().rowMoveNotPossible())}texts(){const e=this.tableScope.ariaTexts,t=new pe;return{rowDragStarted:s=>(e.rowDragStarted??t.rowDragStarted).call(e,s),rowMoved:(s,o)=>(e.rowMoved??t.rowMoved).call(e,s,o),rowMoveNotPossible:()=>(e.rowMoveNotPossible??t.rowMoveNotPossible).call(e),rowDragCancelled:()=>(e.rowDragCancelled??t.rowDragCancelled).call(e)}}}function Lc(n,e){return n===e||!!n&&!!e&&n.rowIndex===e.rowIndex&&n.position===e.position}class oo{constructor(){this.blockCommitOnInvalid=!0}static create(e){const t=new oo;return e&&typeof e=="object"&&e.blockCommitOnInvalid!==void 0&&(t.blockCommitOnInvalid=e.blockCommitOnInvalid),t}}function Mt(n,e){if(Object.is(n,e))return!0;const t=s=>s==null||s==="";return t(n)||t(e)?t(n)&&t(e):n instanceof Date&&e instanceof Date?n.getTime()===e.getTime()||isNaN(n.getTime())&&isNaN(e.getTime()):typeof n=="number"&&typeof e=="string"||typeof n=="string"&&typeof e=="number"?String(n)===String(e):!1}class Vn{constructor(){this.rows=new Map,this.count=0}set(e,t,s,o,i,r){let l=this.rows.get(e);const a=l==null?void 0:l.get(t),c=a?a.oldValue:s;return Mt(c,o)?a?(l.delete(t),l.size||this.rows.delete(e),this.count--,"removed"):"unchanged":(l||(l=new Map,this.rows.set(e,l)),l.set(t,{rowKey:e,property:t,oldValue:c,newValue:o,rawValue:i,error:r||void 0}),a?"changed":(this.count++,"added"))}put(e){let t=this.rows.get(e.rowKey);t||(t=new Map,this.rows.set(e.rowKey,t)),t.has(e.property)||this.count++,t.set(e.property,{...e})}get(e,t){var s;return this.count?(s=this.rows.get(e))==null?void 0:s.get(t):void 0}remove(e,t){const s=this.rows.get(e);return s!=null&&s.delete(t)?(s.size||this.rows.delete(e),this.count--,!0):!1}hasRow(e){return this.rows.has(e)}size(){return this.count}isEmpty(){return this.count===0}invalidCount(){let e=0;return this.rows.forEach(t=>t.forEach(s=>{s.error&&e++})),e}entries(){const e=[];return this.rows.forEach(t=>t.forEach(s=>e.push(s))),e}clear(){this.rows.clear(),this.count=0}}class _n{constructor(e,t,s,o,i=()=>[]){this.type=e,this.changes=t,this.pendingCount=s,this.invalidCount=o,this.pendingProvider=i}get pendingChanges(){return this.pendingProvider()}}function Bn(n,e,t,s){if(n===null||typeof n!="object")return!1;if(Array.isArray(n))return n[t]=s,!0;if(!(e!=null&&e.property))return!1;if(e.valueGetter)return!!e.valueSetter&&e.valueSetter(n,s)!==!1;const o=e.property.split(".");let i=n;for(let r=0;r<o.length-1;r++)if(i=i==null?void 0:i[o[r]],i===null||typeof i!="object")return!1;return i[o[o.length-1]]=s,!0}class $n{constructor(e){this.tableScope=e,this.pending=new Vn,this.started=!1}get options(){return oo.create(this.tableScope.tableOptions.batchEdit)}isPermanent(){return!!this.tableScope.tableOptions.batchEdit}isActive(){return this.started||this.isPermanent()}hasPending(){return!this.pending.isEmpty()}start(){return this.isActive()?!1:(this.started=!0,this.fire("start",[]),!0)}rowKeyOf(e){const t=this.tableScope.tableModel.getBodyModel().getRowByIndex(e);return t==null?e:U(t)?t.data??t:t}propertyOf(e){var t;return((t=this.tableScope.tableModel.getColumnDef(e))==null?void 0:t.property)||`#${e}`}getPendingAt(e,t){if(!this.pending.isEmpty())return this.pending.get(this.rowKeyOf(e),this.propertyOf(t))}getShownValue(e,t){const s=this.getPendingAt(e,t);return s?s.newValue:this.tableScope.getCellInput(e,t)}addPending(e){const t=[];for(const s of e){const o=this.rowKeyOf(s.rowIndex),i=this.propertyOf(s.columnIndex),r=this.tableScope.getCellInput(s.rowIndex,s.columnIndex);if(this.pending.set(o,i,r,s.value,s.rawValue,s.error)!=="unchanged"){const a=this.pending.get(o,i);t.push({row:typeof o=="number"?void 0:o,rowIndex:s.rowIndex,columnIndex:s.columnIndex,property:i,oldValue:a?a.oldValue:r,newValue:s.value,...s.error?{error:s.error}:{}})}}return t.length&&(this.fire("change",t),this.tableScope.announce(this.texts().pendingChanges(this.pending.size()))),t}getPendingEntry(e,t){return this.pending.get(e,t)}restorePending(e,t=!0){for(const a of e)a.entry?this.pending.put(a.entry):this.pending.remove(a.rowKey,a.property);if(!e.length)return[];const s=this.tableScope.tableModel.getBodyModel(),o=new Set(e.map(a=>a.rowKey)),i=new Map,r=s.getRowCount();for(let a=0;a<r&&i.size<o.size;a++){const c=this.rowKeyOf(a);o.has(c)&&!i.has(c)&&i.set(c,a)}const l=e.map(a=>{const c=typeof a.rowKey=="number"?a.rowKey:i.get(a.rowKey)??-1,h=this.findColumnIndex(a.property),d=c>=0&&h>=0?this.tableScope.getCellInput(c,h):void 0;return{row:typeof a.rowKey=="number"?void 0:a.rowKey,rowIndex:c,columnIndex:h,property:a.property,oldValue:a.entry?a.entry.oldValue:d,newValue:a.entry?a.entry.newValue:d}});return this.fire("change",l),t&&this.tableScope.announce(this.texts().pendingChanges(this.pending.size())),l}getPendingChanges(){if(this.pruneOrphans(),this.pending.isEmpty())return[];const e=this.createRowIndexMap();return this.pending.entries().map(t=>this.toChange(t,e))}commit(){var h;const e=this.tableScope;this.pruneOrphans();const t=this.pending.invalidCount();if(t&&this.options.blockCommitOnInvalid)return e.announce(this.texts().commitBlocked(t)),!1;const s=this.pending.entries(),o=s.length?this.createRowIndexMap():new Map,i=e.tableModel,r=[],l=[];for(const d of s){const u=this.findColumnIndex(d.property);if(u<0)continue;const f=typeof d.rowKey=="number"?d.rowKey:o.get(d.rowKey)??-1;if(f>-1)r.push({rowIndex:f,columnIndex:u,value:d.rawValue});else if(Bn(d.rowKey,i.getColumnDef(u),u,d.newValue)){const g=this.toChange(d,o);delete g.error,l.push(g)}}this.pending.clear(),this.isPermanent()||(this.started=!1),(h=e.undoService)==null||h.clear();const a=e.writeCells(r,"commit",{extraChanges:l,skipValidation:!0}),c=i.getBodyModel();return l.length&&ne(c)&&(c.regroup(),e.invalidateAggregates(),e.repaintHard()),this.fire("commit",a),e.announce(this.texts().changesCommitted(a.length)),!0}cancel(){var s;const e=this.getPendingChanges(),t=this.started;this.pending.clear(),(s=this.tableScope.undoService)==null||s.clear(),this.isPermanent()||(this.started=!1),this.tableScope.repaint(),(e.length||t)&&(this.fire("cancel",e),this.tableScope.announce(this.texts().changesDiscarded()))}pruneOrphans(){if(this.pending.isEmpty())return 0;const e=this.collectRowKeys();if(!e)return 0;let t=0;for(const s of this.pending.entries())typeof s.rowKey!="number"&&!e.has(s.rowKey)&&(this.pending.remove(s.rowKey,s.property),t++);return t}collectRowKeys(){const e=this.tableScope.tableModel.getBodyModel();if(Z(e)){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(e.rows),t}return typeof e.getAllRows=="function"?new Set(e.getAllRows()):void 0}toChange(e,t){const s=typeof e.rowKey=="number"?e.rowKey:t.get(e.rowKey)??-1;return{row:typeof e.rowKey=="number"?void 0:e.rowKey,rowIndex:s,columnIndex:this.findColumnIndex(e.property),property:e.property,oldValue:e.oldValue,newValue:e.newValue,...e.error?{error:e.error}:{}}}findColumnIndex(e){const s=this.tableScope.tableModel.getColumnCount();for(let o=0;o<s;o++)if(this.propertyOf(o)===e)return o;return-1}createRowIndexMap(){const e=new Map,t=this.tableScope.tableModel.getBodyModel().getRowCount();for(let s=0;s<t;s++){const o=this.rowKeyOf(s);this.pending.hasRow(o)&&!e.has(o)&&e.set(o,s)}return e}fire(e,t){var o,i;const s=new _n(e,t,this.pending.size(),this.pending.invalidCount(),()=>this.getPendingChanges());(i=(o=this.tableScope.getEventListener()).onBatchEditChanged)==null||i.call(o,s)}texts(){return this.tableScope.getEditTexts()}}const Hn=/^(\d{4})-(\d{2})-(\d{2})$/,Fc=/^-?\d+(\.\d+)?$/,Gn=/^(.*\D)(\d+)$/,Oc=864e5;function Wn(n,e,t=!1,s="auto"){const o=n.length;if(e<1||o<1)return[];const i=Array.from({length:e},(a,c)=>t?-(c+1):c+1),r=()=>i.map(a=>Pc(n,a));if(s==="copy")return r();const l=Kn(n,s==="alternate");return l?i.map(l):r()}function Un(n,e="auto"){return e!=="copy"&&n.length>0&&!!Kn(n,e==="alternate")}function Pc(n,e){const t=n.length;return e>0?n[(e-1)%t]:n[t-1-(-e-1)%t]}function Kn(n,e){const s=n.length===1?e:!e,o=!e;if(n.every(Nc))return s?ir(n,i=>i):void 0;if(n.every(i=>typeof i=="string"&&Fc.test(i))){const i=n;if(i.some(c=>!Number.isSafeInteger(Math.trunc(Number(c)))))return;const r=Math.max(...i.map(c=>{var h;return((h=c.split(".")[1])==null?void 0:h.length)??0})),l=Math.max(...i.map(c=>{const h=c.replace("-","").split(".")[0];return h.length>1&&h.startsWith("0")?h.length:0})),a=c=>{const h=c.toFixed(r);if(!l)return h;const d=h.startsWith("-"),[u,f]=h.replace("-","").split(".");return(d?"-":"")+u.padStart(l,"0")+(f!==void 0?"."+f:"")};return s?ir(i.map(Number),a):void 0}if(n.every(or))return o?_c(n):void 0;if(n.every(i=>typeof i=="string"&&Hn.test(i)&&or(Yn(i))))return o?Bc(n):void 0;if(n.every(i=>typeof i=="string"&&Gn.test(i)))return o?$c(n):void 0}function Nc(n){return typeof n=="number"&&Number.isFinite(n)}function or(n){return n instanceof Date&&!isNaN(n.getTime())}function Co(n){const e=Number(n.toPrecision(15));return e===0?0:e}function ir(n,e){const t=n.length,s=n[t-1];if(t===1)return u=>e(Co(s+u));const o=n[1]-n[0];if(n.every((u,f)=>f===0||Math.abs(u-n[f-1]-o)<=1e-9*Math.max(1,Math.abs(o))))return u=>e(Co(u>0?s+o*u:n[0]+o*u));const r=(t-1)/2,l=n.reduce((u,f)=>u+f,0)/t;let a=0,c=0;n.forEach((u,f)=>{a+=(f-r)*(u-l),c+=(f-r)**2});const h=a/c,d=l-h*r;return u=>{const f=u>0?t-1+u:u;return e(Co(d+h*f))}}function Vc(n){return n.d===zn(n.y,n.m)}function zn(n,e){return io(n,e+1,0).getUTCDate()}function io(n,e,t){const s=new Date(0);return s.setUTCFullYear(n,e,t),s}function Bt(n){return n.y*12+n.m}function rr(n){return Math.round(io(n.y,n.m,n.d).getTime()/Oc)}function jn(n){const e=n.length;if(e===1)return{months:0,days:1,monthEnd:!1};const t=n.every(Vc),s=n.every(r=>r.d===n[0].d),o=Bt(n[1])-Bt(n[0]);if((s||t)&&o!==0&&n.every((r,l)=>l===0||Bt(r)-Bt(n[l-1])===o))return{months:o,days:0,monthEnd:t&&!s};const i=rr(n[e-1])-rr(n[0]);return{months:0,days:Math.round(i/(e-1)),monthEnd:!1}}function Xn(n,e,t){const s=e>0?n[n.length-1]:n[0];if(t.months){const i=Bt(s)+t.months*e,r=Math.floor(i/12),l=i-r*12,a=zn(r,l);return{y:r,m:l,d:t.monthEnd?a:Math.min(s.d,a)}}const o=io(s.y,s.m,s.d+t.days*e);return{y:o.getUTCFullYear(),m:o.getUTCMonth(),d:o.getUTCDate()}}function _c(n){const e=n.map(s=>({y:s.getFullYear(),m:s.getMonth(),d:s.getDate()})),t=jn(e);return s=>{const o=Xn(e,s,t),i=n[s>0?n.length-1:0];return new Date(o.y,o.m,o.d,i.getHours(),i.getMinutes(),i.getSeconds(),i.getMilliseconds())}}function Yn(n){const[,e,t,s]=Hn.exec(n),o=io(Number(e),Number(t)-1,Number(s));return o.getUTCDate()===Number(s)&&o.getUTCMonth()===Number(t)-1?o:new Date(NaN)}function Bc(n){const e=n.map(s=>{const o=Yn(s);return{y:o.getUTCFullYear(),m:o.getUTCMonth(),d:o.getUTCDate()}}),t=jn(e);return s=>{const o=Xn(e,s,t);return`${String(o.y).padStart(4,"0")}-${String(o.m+1).padStart(2,"0")}-${String(o.d).padStart(2,"0")}`}}function $c(n){const e=n.map(r=>{const[,l,a]=Gn.exec(r);return{prefix:l,digits:a,num:Number(a)}}),t=e[0].prefix;if(e.some(r=>r.prefix!==t)||e.some(r=>!Number.isSafeInteger(r.num)))return;const s=e.length,o=s===1?1:(e[s-1].num-e[0].num)/(s-1);if(!Number.isInteger(o))return;const i=Math.max(...e.map(r=>r.digits.length>1&&r.digits.startsWith("0")?r.digits.length:0));return r=>{const l=r>0?e[s-1].num:e[0].num,a=Math.abs(l+o*r);return t+String(a).padStart(i,"0")}}function Ei(n,e,t){const{r1:s,c1:o,r2:i,c2:r}=n;switch(e){case"down":return new M(s,o,i+t,r);case"up":return new M(s-t,o,i,r);case"right":return new M(s,o,i,r+t);default:return new M(s,o-t,i,r)}}function Jn(n){var f;const{source:e,direction:t,count:s,getValue:o}=n,i=n.mode??"auto",r=t==="down"||t==="up",l=t==="up"||t==="left",a=[];if(s<1)return a;const[c,h]=r?[e.c1,e.c2]:[e.r1,e.r2],[d,u]=r?[e.r1,e.r2]:[e.c1,e.c2];for(let g=c;g<=h;g++){const p=C=>r?[C,g]:[g,C],m=[];for(let C=d;C<=u;C++)m.push(o(...p(C)));const b=Wn(m,s,l,i),y=Un(m,i);for(let C=0;C<s;C++){const S=l?d-1-C:u+1+C,[E,x]=p(S);if(n.isFillable&&!n.isFillable(E,x))continue;let R=b[C];if(n.fillValue){const F=((f=n.getCellInfo)==null?void 0:f.call(n,E,x))??{row:void 0,property:""},v=n.fillValue({sourceValues:m,step:l?-(C+1):C+1,direction:t,rowIndex:E,columnIndex:x,property:F.property,row:F.row,defaultValue:R,copy:!y});v!==void 0&&(R=v)}a.push({rowIndex:E,column:x,value:R})}}return a}const nr="fill-handle";class qn{constructor(e){this.tableScope=e,this.autoScrollFrame=0,this.suppressClick=!1,this.shortcutsSet=!1;const t=e.listenerAbortController.signal;e.hostElement.addEventListener("pointerdown",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onPointerDown(s)},{signal:t}),e.hostElement.addEventListener("click",s=>{var o;(o=e.isEventInDetail)!=null&&o.call(e,s)||this.onClickCapture(s)},{capture:!0,signal:t}),e.hostElement.addEventListener("dblclick",s=>{var o;!((o=e.isEventInDetail)!=null&&o.call(e,s))&&this.isHandle(s.target)&&s.stopPropagation()},{capture:!0,signal:t})}isFilling(){return!!this.session}update(){var r,l;const e=this.tableScope,t=e.getFillHandleOptions();if(!t){this.removeHandle(),this.shortcutsSet&&(this.shortcutsSet=!1,this.tableScope.setHostKeyShortcuts(void 0));return}this.updateHostShortcuts(t);const s=((r=this.session)==null?void 0:r.source)??e.getFillSourceRange(),o=s&&!e.isEditing()&&!e.tableOverlay.isBlocking()&&!((l=e.rowDragService)!=null&&l.isDragging())?this.getCornerOf(s):void 0;if(!o){this.handle&&(this.handle.style.display="none");return}const i=this.ensureHandle();i.style.display="block",e.getDomService().setStyle(i,"left",`${o.x}px`),i.style.top=`${o.y}px`,this.session&&this.renderPreview()}getCornerOf(e){const t=this.tableScope;let s=e.c2;for(;s>e.c1&&t.tableModel.getColumnWidth(s)<=0;)s--;if(t.tableModel.getColumnWidth(s)<=0)return;const o=t.getBodyCellRectInHost(e.r2,s),i=o.left+o.width,r=o.top+o.height;return i>=o.clipLeft&&i<=o.clipRight+.5&&r>=o.clipTop&&r<=o.clipBottom+.5?{x:i,y:r}:void 0}ensureHandle(){if(!this.handle||!this.handle.isConnected){const e=this.tableScope.getDomService();this.handle=e.setAriaHidden(e.createDivWithClass("ge-table-fill-handle",this.tableScope.hostElement)),e.domService.setAttribute(this.handle,"data-ge-action",nr)}return this.handle}removeHandle(){var e;(e=this.handle)==null||e.remove(),this.handle=void 0}updateHostShortcuts(e){const s=typeof navigator<"u"&&navigator.platform.indexOf("Mac")>-1?"Meta":"Control",o=[];e.direction!=="horizontal"&&o.push(`${s}+D`),e.direction!=="vertical"&&o.push(`${s}+R`),this.tableScope.setHostKeyShortcuts(o.join(" ")),this.shortcutsSet=!0}isHandle(e){return e instanceof Element&&!!e.closest(`[data-ge-action="${nr}"]`)&&this.tableScope.hostElement.contains(e)}onPointerDown(e){if(this.session||this.pending||e.pointerType==="mouse"&&e.button!==0||!this.isHandle(e.target))return;e.preventDefault();const t=this.tableScope.getFillSourceRange();!t||this.tableScope.isEditing()||(this.pending={pointerId:e.pointerId,startX:e.clientX,startY:e.clientY,source:t},this.listenToDocument())}listenToDocument(){this.sessionAbortController=new AbortController;const e=this.sessionAbortController.signal,t=this.tableScope.hostElement.ownerDocument;t.addEventListener("pointermove",s=>this.onPointerMove(s),{signal:e}),t.addEventListener("pointerup",s=>this.onPointerUp(s),{signal:e}),t.addEventListener("pointercancel",s=>{this.pending&&s.pointerId===this.pending.pointerId&&this.cancel()},{signal:e}),t.addEventListener("keydown",s=>{s.key==="Escape"&&(this.session||this.pending)&&(s.preventDefault(),s.stopPropagation(),this.cancel())},{capture:!0,signal:e}),this.tableScope.scrollViewport.addEventListener("scroll",()=>{var s;(s=this.session)!=null&&s.lastEvent&&!this.autoScrollFrame&&this.updateTarget(this.session.lastEvent)},{signal:e})}onPointerMove(e){if(!(!this.pending||e.pointerId!==this.pending.pointerId)){if(!this.session){const t=this.tableScope.getFillHandleOptions();if(!t){this.stopListening();return}if(Math.hypot(e.clientX-this.pending.startX,e.clientY-this.pending.startY)<t.dragThresholdInPx)return;this.session={source:this.pending.source,options:t,count:0,speedX:0,speedY:0,remainderX:0,remainderY:0};const s=this.tableScope.getDomService();this.preview=s.setAriaHidden(s.createDivWithClass("ge-table-fill-preview",this.tableScope.hostElement)),this.tableScope.hostElement.classList.add("ge-table-fill-active")}e.preventDefault(),this.updateTarget(e)}}onPointerUp(e){if(!this.pending||e.pointerId!==this.pending.pointerId)return;const t=this.session;if(!t){this.stopListening(),this.suppressNextClick();return}this.updateTarget(e),this.suppressNextClick();const{source:s,direction:o,count:i}=t;this.stopListening(),o&&i>0&&!this.tableScope.tableOverlay.isBlocking()&&!this.tableScope.isEditing()?this.tableScope.fillRange(s,o,i,e.altKey||e.ctrlKey?"alternate":"auto"):this.tableScope.repaint()}suppressNextClick(){this.suppressClick=!0,setTimeout(()=>this.suppressClick=!1,0)}onClickCapture(e){(this.suppressClick||this.isHandle(e.target))&&(this.suppressClick=!1,e.stopPropagation(),e.preventDefault())}updateTarget(e){const t=this.session;t.lastEvent=e;const s=this.tableScope,o=s.hostElement,i=o.getBoundingClientRect(),r=s.clientXToHostX(e.clientX),l=e.clientY-i.top-o.clientTop,[a,c]=s.getBodyCellAtHostPoint(r,l),h=t.source,d=a>h.r2?a-h.r2:a<h.r1?a-h.r1:0,u=c>h.c2?c-h.c2:c<h.c1?c-h.c1:0,f=t.options.direction,g=f==="vertical"||f==="both"&&Math.abs(d)>=Math.abs(u),p=g?d:u;t.direction=p===0?void 0:g?p>0?"down":"up":p>0?"right":"left",t.count=Math.abs(p),this.renderPreview(),this.updateAutoScroll(r,l)}renderPreview(){const e=this.session,t=this.preview;if(!e||!t)return;const s=e.direction?Ei(e.source,e.direction,e.count):e.source,o=this.tableScope,i=o.getBodyCellRectInHost(s.r1,s.c1),r=o.getBodyCellRectInHost(s.r2,s.c2),l=Math.max(i.top,i.clipTop),a=Math.min(r.top+r.height,r.clipBottom),c=Math.max(i.left,i.clipLeft),h=Math.min(r.left+r.width,r.clipRight);o.getDomService().applyStyle(t,{display:a>l&&h>c?"block":"none",left:`${c}px`,top:`${l}px`,width:`${Math.max(0,h-c)}px`,height:`${Math.max(0,a-l)}px`})}updateAutoScroll(e,t){const s=this.session,{autoScrollZoneInPx:o,autoScrollMaxSpeedInPx:i}=s.options,r=this.tableScope,l=r.tableModel.getPadding(),a=f=>Math.max(1,Math.round(i*Math.min(1,f/o)**2)),c=l.top,h=r.getLayoutHeight()-l.bottom,d=l.left,u=r.getLayoutWidth()-l.right;s.speedY=o<=0||i<=0?0:t<c+o?-a(c+o-t):t>h-o?a(t-(h-o)):0,s.speedX=o<=0||i<=0?0:e<d+o&&e>=d-o?-a(d+o-e):e>u-o?a(e-(u-o)):0,(s.speedX||s.speedY)&&!this.autoScrollFrame?this.autoScrollFrame=requestAnimationFrame(()=>this.autoScrollStep()):!s.speedX&&!s.speedY&&(s.lastFrameTime=void 0,s.remainderX=0,s.remainderY=0)}autoScrollStep(){this.autoScrollFrame=0;const e=this.session;if(!e||!e.speedX&&!e.speedY)return;const t=this.tableScope.scrollViewport,s=performance.now(),o=e.lastFrameTime?Math.min(4,(s-e.lastFrameTime)/(1e3/60)):1;e.lastFrameTime=s;const i=e.speedY*o*this.tableScope.getScrollerToContentRatioY()+e.remainderY,r=e.speedX*o+e.remainderX,l=Math.trunc(i),a=Math.trunc(r);e.remainderY=i-l,e.remainderX=r-a;const c=this.tableScope,h=t.scrollTop,d=c.getViewportScrollLeft();t.scrollTop=h+l,c.setViewportScrollLeft(d+a),(t.scrollTop!==h||c.getViewportScrollLeft()!==d)&&this.tableScope.adjustAfterScrolling(),this.updateTarget(e.lastEvent)}cancel(){const e=!!this.session;this.stopListening(),e&&this.tableScope.repaint()}stopListening(){var e,t;(e=this.sessionAbortController)==null||e.abort(),this.sessionAbortController=void 0,this.pending=void 0,this.session=void 0,this.autoScrollFrame&&(cancelAnimationFrame(this.autoScrollFrame),this.autoScrollFrame=0),(t=this.preview)==null||t.remove(),this.preview=void 0,this.tableScope.hostElement.classList.remove("ge-table-fill-active")}destroy(){this.stopListening(),this.removeHandle()}}class ro{constructor(){this.detailRenderer=()=>{},this.isMaster=void 0,this.detailHeight="auto",this.estimatedDetailHeight=200,this.toggleColumn=void 0,this.maxRenderedDetails=50,this.getRowId=void 0}static create(e){const t=new ro;for(const[s,o]of Object.entries(e??{}))o!==void 0&&(t[s]=o);return t}}const Hc="a[href], button, input, select, textarea, iframe, [contenteditable]:not([contenteditable='false']), [tabindex]";class Zn{constructor(e,t){var i;this.scope=e,this.createNestedScope=t,this.entries=new Map,this.byIndex=new Map,this.visibleNow=new Set,this.renderPass=0,this.renderedCount=0,this.toggleColumnIndex=-1,this.resizeFrame=0,this.destroyed=!1;const s=(i=e.tableOptions)==null?void 0:i.masterDetail;this.options=ro.create(s);const o=Z(e.tableModel.getBodyModel());s&&o&&console.warn("GuiExpert Table – masterDetail is ignored: it works only with flat body models (no tree, row grouping or pivot table)."),s&&!s.detailRenderer&&console.warn("GuiExpert Table – masterDetail without a detailRenderer: the detail rows stay empty."),this.active=!!s&&!o,this.active&&this.createLayer()}isActive(){return this.active}hasExpanded(){return this.active&&this.entries.size>0}getLayer(){return this.layer}isInLayer(e){var o;const t=this.layer;if(!t)return!1;const s=(o=e.composedPath)==null?void 0:o.call(e);return s!=null&&s.length?s.includes(t):e.target instanceof Node&&t.contains(e.target)}keyOf(e,t){var s,o;if(e!=null){const i=(o=(s=this.scope.tableOptions)==null?void 0:s.autoRestoreOptions)==null?void 0:o.getRowId,r=this.options.getRowId??(i&&!xn(i)?i:void 0);if(r)try{const l=r(e,t);if(l!=null)return l}catch{}if(typeof e=="object"||typeof e=="function")return e}return t}isMasterAt(e){if(!this.active||e<0)return!1;const t=this.getBody();if(e>=t.getRowCount())return!1;const s=this.options.isMaster;if(!s)return!0;try{return!!s(t.getRowByIndex(e),e)}catch(o){return console.error(o),!1}}isExpandedAt(e){return!this.hasExpanded()||e<0?!1:this.entries.has(this.keyOf(this.getBody().getRowByIndex(e),e))}isExpanded(e){const[t,s]=this.resolve(e);return this.hasExpanded()&&this.entries.has(this.keyOf(t,s))}setExpanded(e,t,s="api"){if(!this.active)return!1;const[o,i]=this.resolve(e),r=this.keyOf(o,i);if(t){if(this.entries.has(r)||o===void 0&&i<0||(i>=0?!this.isMasterAt(i):!this.isMasterRow(o)))return!1;const l={key:r,row:o,rowIndex:i,lastSeen:0,renderCount:0};this.entries.set(r,l);const a=i>=0&&this.scope.setBodyRowExtra(i,this.heightOf(l));a&&this.byIndex.set(i,l),this.scope.onDetailToggled(o,i,t,s,!0,a)}else{const l=this.entries.get(r);if(!l)return!1;this.destroyContent(l),this.entries.delete(r);const a=l.rowIndex>=0&&this.byIndex.get(l.rowIndex)===l&&this.scope.setBodyRowExtra(l.rowIndex,0);a&&this.byIndex.delete(l.rowIndex),this.scope.onDetailToggled(o,i,t,s,!0,a)}return!0}expandAll(){if(!this.active)return 0;const e=this.getBody(),t=e.getRowCount();let s=0;for(let o=0;o<t;o++){if(!this.isMasterAt(o))continue;const i=e.getRowByIndex(o),r=this.keyOf(i,o);this.entries.has(r)||(this.entries.set(r,{key:r,row:i,rowIndex:o,lastSeen:0,renderCount:0}),s++)}return s&&this.scope.onDetailToggled(void 0,-1,!0,"api",!1),s}collapseAll(){const e=this.entries.size;return e?(this.clearAll(),this.scope.onDetailToggled(void 0,-1,!1,"api",!1),e):0}getExpandedRows(){return Array.from(this.entries.values(),e=>e.row)}setExpandedRows(e,t="api"){if(!this.active)return!1;const s=new Map;for(const i of e)s.set(this.keyOf(i,-1),i);let o=!1;for(const[i,r]of Array.from(this.entries))s.has(i)||(this.destroyContent(r),this.entries.delete(i),o=!0);for(const[i,r]of Array.from(s))!this.entries.has(i)&&this.isMasterRow(r)&&(this.entries.set(i,{key:i,row:r,rowIndex:-1,lastSeen:0,renderCount:0}),o=!0);return o&&this.scope.onDetailToggled(void 0,-1,!0,t,!1),o}refresh(e){const[t,s]=this.resolve(e),o=this.entries.get(this.keyOf(t,s));return o?(this.destroyContent(o),this.scope.repaint(),!0):!1}getDetailElement(e){var o,i;const[t,s]=this.resolve(e);return(i=(o=this.entries.get(this.keyOf(t,s)))==null?void 0:o.content)==null?void 0:i.cell}getMasterRowIndexOf(e){var t,s;if(!e||!((t=this.layer)!=null&&t.contains(e)))return-1;for(const o of Array.from(this.entries.values()))if((s=o.content)!=null&&s.rowDiv.contains(e))return o.rowIndex;return-1}computeExtras(){var a;if(this.byIndex=new Map,!this.hasExpanded())return;const e=this.getBody(),t=e.getRowCount();for(const c of Array.from(this.entries.values()))c.rowIndex=-1;const s=[],o=[];let i=0;const r=(a=e.getFilteredRows)==null?void 0:a.call(e),l=Array.isArray(r)&&r.length===t?c=>r[c]:c=>e.getRowByIndex(c);for(let c=0;c<t&&i<this.entries.size;c++){const h=l(c),d=this.entries.get(this.keyOf(h,c));!d||d.rowIndex>=0||this.options.isMaster&&!this.isMasterAt(c)||(i++,d.rowIndex=c,d.row=h,this.byIndex.set(c,d),s.push(c),o.push(this.heightOf(d)))}return i<this.entries.size&&this.pruneRemovedRows(e),{rowIndices:s,heights:o}}startRenderPass(){this.toggleColumnIndex=this.active?this.computeToggleColumnIndex():-1}layoutVisible(e){if(!this.active||this.destroyed)return;this.renderPass++;const t=new Set;for(let o=0;o+2<e.length;o+=3){const i=this.byIndex.get(e[o]);if(!i)continue;i.content&&i.content.row!==i.row&&this.destroyContent(i);const r=i.content??this.createContent(i,e[o+1],e[o+2]);this.place(r,e[o+1],e[o+2]),i.lastSeen=this.renderPass,t.add(i)}for(const o of Array.from(this.visibleNow))!t.has(o)&&o.content&&this.park(o.content,o.rowIndex);this.visibleNow=t,this.enforceLimit();const s=t.size?"rowgroup":"presentation";this.layer&&this.layer.getAttribute("role")!==s&&this.scope.getDomService().domService.setAttribute(this.layer,"role",s)}setBounds(e,t,s,o){const i=this.layer;if(!i)return;const r=i.style;this.scope.getDomService().setStyle(i,"left",`${e}px`),r.top=`${t}px`,r.width=`${Math.max(0,s)}px`,r.height=`${Math.max(0,o)}px`}decorateCell(e,t,s){if(s!==this.toggleColumnIndex||!this.isMasterAt(t))return;const o=this.isExpandedAt(t),i=this.scope.getDomService(),r=i.domService;r.addClass(e,"ge-table-detail-toggle-cell");const l=r.createElement("div");r.addClass(l,"ge-table-detail-toggle"),o&&r.addClass(l,"ge-table-detail-toggle-expanded"),r.setAttribute(l,"data-ge-action","toggle-detail"),r.setAttribute(l,"data-area","body"),r.setAttribute(l,"data-row-index",`${t}`),r.setAttribute(l,"data-col-index",`${s}`),i.setAriaHidden(l),e.insertBefore(l,e.firstChild)}destroy(){var e;this.destroyed||(this.destroyed=!0,this.resizeFrame&&(cancelAnimationFrame(this.resizeFrame),this.resizeFrame=0),this.clearAll(),(e=this.layer)==null||e.remove(),this.layer=void 0)}getBody(){return this.scope.tableModel.getBodyModel()}getAllRows(e){var s;const t=(s=e.getAllRows)==null?void 0:s.call(e);return Array.isArray(t)?t:void 0}isMasterRow(e){const t=this.options.isMaster;try{return e!==void 0&&(!t||!!t(e,-1))}catch(s){return console.error(s),!1}}resolve(e){var r;const t=this.getBody();if(typeof e=="number")return e<0||e>=t.getRowCount()?[void 0,-1]:[t.getRowByIndex(e),e];const s=this.entries.get(this.keyOf(e,-1));if(s&&s.rowIndex>=0&&t.getRowByIndex(s.rowIndex)===e)return[e,s.rowIndex];const o=(r=t.getFilteredRows)==null?void 0:r.call(t);if(Array.isArray(o)&&o.length===t.getRowCount())return[e,o.indexOf(e)];const i=t.getRowCount();for(let l=0;l<i;l++)if(t.getRowByIndex(l)===e)return[e,l];return[e,-1]}heightOf(e){const t=this.detailHeightOf(e);return t==="auto"?e.measuredHeight??this.options.estimatedDetailHeight:Math.max(0,t)}detailHeightOf(e){const t=this.options.detailHeight;if(typeof t=="function")try{const s=t(e.row,e.rowIndex);return s==="auto"||typeof s=="number"&&isFinite(s)?s:"auto"}catch(s){return console.error(s),"auto"}return t==="auto"||typeof t=="number"&&isFinite(t)?t:"auto"}computeToggleColumnIndex(){var o,i;const e=this.options.toggleColumn,t=this.scope.tableModel;if(typeof e=="number")return e;if(typeof e=="string")return(((o=t.getColumnDefs)==null?void 0:o.call(t))??[]).findIndex(r=>r.property===e);const s=this.scope.getFirstDataColumnIndex();return(i=this.scope.tableOptions)!=null&&i.showCheckboxWihoutExtraColumn?s:t.isRowCheckboxVisible()?s+1:s}pruneRemovedRows(e){const t=this.getAllRows(e);if(!t)return;const s=new Set;t.forEach((o,i)=>s.add(this.keyOf(o,i)));for(const[o,i]of Array.from(this.entries))i.rowIndex<0&&!s.has(o)&&(this.destroyContent(i),this.entries.delete(o))}createLayer(){const e=this.scope,s=e.getDomService().domService,o=s.createElement("div");s.addClass(o,"ge-table-detail-layer"),s.setAttribute(o,"id",e.ariaIds.detailRowGroup()),s.setAttribute(o,"role","presentation"),s.appendChild(e.hostElement,o),this.layer=o;const i=e.listenerAbortController.signal;o.addEventListener("wheel",r=>this.onWheel(r),{passive:!1,signal:i}),e.hostElement.addEventListener("keydown",r=>this.onHostKeyDown(r),{signal:i}),e.hostElement.addEventListener("focus",r=>this.onHostFocus(r),{signal:i})}createContent(e,t,s){const o=this.scope,i=o.getDomService().domService,r=i.createElement("div");i.addClass(r,"ge-table-detail-row"),i.setAttribute(r,"role","row");const l=i.createElement("div");i.addClass(l,"ge-table-detail-cell"),i.setAttribute(l,"role","gridcell"),i.setAttribute(l,"aria-colspan",`${Math.max(1,o.getAriaGridInfo().colCount)}`),i.appendChild(r,l);const a=this.detailHeightOf(e)==="auto";a&&i.addClass(r,"ge-table-detail-row-auto"),i.appendChild(this.layer,r);const c={rowDiv:r,cell:l,row:e.row,auto:a,abort:new AbortController,tables:[],parked:!1};e.content=c,this.place(c,t,s),this.renderedCount++;const h=e.renderCount>0;e.renderCount++;const d=this,u={row:e.row,rowIndex:e.rowIndex,tableApi:o.getApi(),recreated:h,signal:c.abort.signal,createTable(f){return d.createNestedTable(c,a,f)}};try{const f=this.options.detailRenderer,g=typeof f=="function"?f(l,e.row,u):f==null?void 0:f.render(l,e.row,u);typeof g=="function"&&(c.cleanup=g)}catch(f){console.error(f)}return a&&typeof ResizeObserver<"u"&&(c.resizeObserver=new ResizeObserver(f=>this.onResize(e,c,f)),c.resizeObserver.observe(r)),c}createNestedTable(e,t,s){const o=this.scope.getDomService().domService,i=o.createElement("div");o.addClass(i,"ge-table-detail-table");const r=s.height??(t?this.options.estimatedDetailHeight:"100%");i.style.height=typeof r=="number"?`${r}px`:r,o.appendChild(e.cell,i);const l=this.createNestedScope(i,s.tableModel,s.tableOptions,s.eventListener);return e.tables.push(l),l.firstInit(),l.getApi()}place(e,t,s){const o=e.rowDiv.style;e.parked&&(e.parked=!1,e.rowDiv.classList.remove("ge-table-detail-row-parked")),e.top!==t&&(e.top=t,o.top=`${t}px`),!e.auto&&e.height!==s&&(e.height=s,o.height=`${s}px`)}park(e,t=-1){e.parked||(this.releaseFocus(e,t),e.parked=!0,e.rowDiv.classList.add("ge-table-detail-row-parked"))}releaseFocus(e,t){var o;const s=(o=e.rowDiv.ownerDocument)==null?void 0:o.activeElement;s&&e.rowDiv.contains(s)&&this.scope.takeFocusFromDetail(t)}onResize(e,t,s){var a,c;if(t.parked||e.content!==t||this.destroyed)return;const o=s[s.length-1],i=(a=o==null?void 0:o.borderBoxSize)==null?void 0:a[0],r=i?i.blockSize:((c=o==null?void 0:o.target)==null?void 0:c.offsetHeight)??0,l=Math.max(1,Math.ceil(r));e.measuredHeight!==l&&(e.measuredHeight=l,e.rowIndex>=0&&this.scope.getBodyRowLayout().setExtraHeight(e.rowIndex,l),this.resizeFrame||(this.resizeFrame=requestAnimationFrame(()=>{this.resizeFrame=0,this.destroyed||this.scope.onDetailHeightChanged()})))}enforceLimit(){const e=Math.max(0,this.options.maxRenderedDetails);if(this.renderedCount<=e||this.renderedCount<=this.visibleNow.size)return;const t=Array.from(this.entries.values()).filter(s=>s.content&&!this.visibleNow.has(s)).sort((s,o)=>s.lastSeen-o.lastSeen);for(const s of t){if(this.renderedCount<=e)break;this.destroyContent(s)}}destroyContent(e){var s,o;const t=e.content;if(t){e.content=void 0,this.renderedCount--,this.visibleNow.delete(e),this.destroyed||this.releaseFocus(t,e.rowIndex),(s=t.resizeObserver)==null||s.disconnect();try{(o=t.cleanup)==null||o.call(t)}catch(i){console.error(i)}t.abort.abort();for(const i of t.tables)try{i.destroy()}catch(r){console.error(r)}t.rowDiv.remove()}}clearAll(){for(const e of Array.from(this.entries.values()))this.destroyContent(e);this.entries.clear(),this.byIndex.clear(),this.visibleNow.clear()}onWheel(e){if(e.defaultPrevented||e.ctrlKey)return;const t=this.scope.scrollViewport,s=e.deltaMode===1?16:e.deltaMode===2?t.clientHeight:1,o=e.deltaY*s,i=e.deltaX*s;if(this.canScrollInside(e.target,i,o))return;const r=t.scrollTop,l=t.scrollLeft;o&&(t.scrollTop=r+o*this.scope.getScrollerToContentRatioY()),i&&(t.scrollLeft=l+i),(t.scrollTop!==r||t.scrollLeft!==l)&&e.preventDefault()}canScrollInside(e,t,s){let o=e instanceof Element?e:null;for(;o&&o!==this.layer;){if(o instanceof HTMLElement){const i=getComputedStyle(o);if(s&&/(auto|scroll)/.test(i.overflowY)&&o.scrollHeight>o.clientHeight&&(s>0?o.scrollTop+o.clientHeight<o.scrollHeight-1:o.scrollTop>0)||t&&/(auto|scroll)/.test(i.overflowX)&&o.scrollWidth>o.clientWidth&&Br(o,t,i.direction==="rtl"))return!0}o=o.parentElement}return!1}hasTabTarget(e){var o;const t=(o=this.byIndex.get(e))==null?void 0:o.content,s=this.byIndex.get(e);return!!s&&!!t&&!t.parked&&this.visibleNow.has(s)&&!!this.findFocusable(t.cell)}onHostKeyDown(e){var r;if(e.key!=="Tab"||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||e.defaultPrevented||e.target!==this.scope.hostElement||this.isInLayer(e))return;const t=(r=this.scope.focusModel())==null?void 0:r.getFocus(),s=t?this.byIndex.get(t[0]):void 0,o=s==null?void 0:s.content;if(!o||o.parked||!this.visibleNow.has(s))return;const i=this.findFocusable(o.cell);i&&(e.preventDefault(),i.focus())}onHostFocus(e){const t=e.relatedTarget instanceof Node?e.relatedTarget:null,s=this.getMasterRowIndexOf(t);s>=0&&this.scope.focusDetailMaster(s)}findFocusable(e){for(const t of Array.from(e.querySelectorAll(Hc))){const s=t.getAttribute("tabindex");if(!(s!==null&&Number(s)<0||t.disabled)&&t.getClientRects().length)return t}}}class Qn{constructor(e,t,s,o){this.row=e,this.rowIndex=t,this.expanded=s,this.source=o}}class ss{constructor(){this.direction="both",this.fillValue=void 0,this.maxCells=1e5,this.dragThresholdInPx=3,this.autoScrollZoneInPx=40,this.autoScrollMaxSpeedInPx=24}static create(e){if(!e)return;const t=new ss;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class no{constructor(){this.startOnType=!0,this.enterKey="edit",this.enterMoves="down",this.tabMoves=!0,this.arrowKeysCommit=!0,this.textSelection="all",this.clearKeys=!0,this.ctrlEnterFillsSelection=!0,this.collapseSelectionOnNavigate=!0,this.emptyValue="",this.defaultEditable=!1,this.maxClearCells=1e6}static create(e){if(!e)return;const t=new no;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class lo{constructor(){this.composing=!1,this.abort=new AbortController,this.focusedOnce=!1}open(e,t){this.ctx=t;const s=t.domService,o=s.createElement("input");this.input=o,s.setAttribute(o,"type",this.inputType()),s.setAttribute(o,"autocomplete","off"),s.setAttribute(o,"spellcheck","false"),s.setAttribute(o,"aria-label",t.ariaLabel),s.addClass(o,"ge-table-cell-editor-field"),this.decorate(o,t),o.value=t.typedText!==void 0?t.typedText:this.toText(t);const i=this.abort.signal;o.addEventListener("compositionstart",()=>this.composing=!0,{signal:i}),o.addEventListener("compositionend",()=>this.composing=!1,{signal:i}),o.addEventListener("input",()=>t.inputChanged(),{signal:i}),s.appendChild(e,o)}inputType(){return"text"}decorate(e,t){}toText(e){return e.input}getValue(){var e;return((e=this.input)==null?void 0:e.value)??""}getText(){var e;return((e=this.input)==null?void 0:e.value)??""}setText(e){this.input&&(this.input.value=e,this.input.setSelectionRange(e.length,e.length))}focus(){const e=this.input;if(!e)return;e.ownerDocument.activeElement!==e&&e.focus({preventScroll:!0});const t=this.ctx;if(t&&!this.focusedOnce){this.focusedOnce=!0;const s=e.value.length;try{t.typedText===void 0&&t.textSelection==="all"&&t.mode==="edit"?e.setSelectionRange(0,s):e.setSelectionRange(s,s)}catch{}}}getFocusElement(){return this.input}setMode(e){}isComposing(){return this.composing}wantsKey(e,t){return!1}close(){var e;this.abort.abort(),(e=this.input)==null||e.remove(),this.input=void 0}}class el extends lo{decorate(e,t){t.domService.setAttribute(e,"inputmode","decimal"),t.domService.addClass(e,"ge-table-cell-editor-number")}getValue(){var s,o;const e=String(super.getValue());if((o=(s=this.ctx)==null?void 0:s.columnDef)!=null&&o.editInputPipe)return e;const t=e.trim();return t!==""&&/^[-+]?(\d+\.?\d*|\.\d+)(e[-+]?\d+)?$/i.test(t)?Number(t):e}}class tl extends lo{constructor(){super(...arguments),this.originalText=""}inputType(){return"date"}toText(e){const t=e.value;if(t instanceof Date&&!Number.isNaN(t.getTime())){const o=i=>String(i).padStart(2,"0");return`${t.getFullYear()}-${o(t.getMonth()+1)}-${o(t.getDate())}`}const s=e.input;return/^\d{4}-\d{2}-\d{2}/.test(s)?s.slice(0,10):""}open(e,t){this.original=t.value,this.originalText=this.toText(t),super.open(e,{...t,typedText:t.typedText===""?"":void 0})}getValue(){const e=String(super.getValue());if(!e)return"";const t=this.original;if(e===this.originalText&&(t instanceof Date||typeof t=="string"))return t;const[s,o,i]=e.split("-").map(Number);if(t instanceof Date&&!Number.isNaN(t.getTime()))return new Date(s,o-1,i,t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds());const r=typeof t=="string"&&/^\d{4}-\d{2}-\d{2}./.test(t)?t.slice(10):"";return t instanceof Date?new Date(s,o-1,i):e+r}wantsKey(e,t){return e.key.startsWith("Arrow")}}class bt{constructor(e,t,s,o,i){this.type=e,this.rowIndex=t,this.columnIndex=s,this.mode=o,this.input=i}}const sl=function(n,e,t){return n===""||n===null||n===void 0?"":Number(n)},A=(n,e,t,s)=>Object.freeze({name:e,signature:`${e}(${t})`,description:s,group:n}),ol=Object.freeze([A("Math","ABS","number","The absolute value"),A("Logic","AND","logical1, [logical2], …","TRUE if all arguments are TRUE"),A("Math","AVERAGE","number1, [number2], …","The average of the numbers"),A("Conditional","AVERAGEIF","range, criteria, [average_range]","The average of the cells that match a criterion"),A("Conditional","AVERAGEIFS","average_range, criteria_range1, criteria1, …","The average of the cells that match all criteria"),A("Math","CEILING","number, significance","Rounds up to a multiple of significance"),A("Text","CONCAT","text1, [text2], …","Joins texts and ranges"),A("Math","COUNT","value1, [value2], …","Counts the numbers"),A("Math","COUNTA","value1, [value2], …","Counts the non-empty cells"),A("Math","COUNTBLANK","range","Counts the empty cells"),A("Conditional","COUNTIF","range, criteria","Counts the cells that match a criterion"),A("Conditional","COUNTIFS","criteria_range1, criteria1, …","Counts the cells that match all criteria"),A("Date","DATE","year, month, day","A date"),A("Date","DATEDIF","start_date, end_date, unit",'Days ("d"), months ("m") or years ("y") between two dates'),A("Date","DAY","date","The day of a date (1–31)"),A("Date","EOMONTH","start_date, months","The last day of the month, months before or after"),A("Text","FIND","find_text, within_text, [start_num]","The position of a text (case-sensitive)"),A("Math","FLOOR","number, significance","Rounds down to a multiple of significance"),A("Lookup","HLOOKUP","lookup_value, table_array, row_index_num, [range_lookup]","Looks up in the first row of a table"),A("Logic","IF","logical_test, value_if_true, [value_if_false]","One value or another"),A("Logic","IFERROR","value, value_if_error","The value, or another one if it is an error"),A("Logic","IFNA","value, value_if_na","The value, or another one if it is #N/A"),A("Logic","IFS","logical_test1, value1, …","The value of the first true condition"),A("Lookup","INDEX","array, row_num, [column_num]","The value at a position of a range"),A("Math","INT","number","Rounds down to an integer"),A("Info","ISBLANK","value","TRUE for an empty cell"),A("Info","ISERROR","value","TRUE for an error value"),A("Info","ISNA","value","TRUE for #N/A"),A("Info","ISNUMBER","value","TRUE for a number or date"),A("Info","ISTEXT","value","TRUE for a text"),A("Text","LEFT","text, [num_chars]","The first characters"),A("Text","LEN","text","The number of characters"),A("Text","LOWER","text","Lower case"),A("Lookup","MATCH","lookup_value, lookup_array, [match_type]","The position of a value in a range"),A("Math","MAX","number1, [number2], …","The largest number"),A("Text","MID","text, start_num, num_chars","Characters from the middle"),A("Math","MIN","number1, [number2], …","The smallest number"),A("Math","MOD","number, divisor","The remainder (sign of the divisor)"),A("Date","MONTH","date","The month of a date (1–12)"),A("Info","NA","","The error #N/A"),A("Logic","NOT","logical","The opposite"),A("Date","NOW","","Date and time now (recalculated)"),A("Logic","OR","logical1, [logical2], …","TRUE if any argument is TRUE"),A("Math","POWER","number, power","A number to a power"),A("Math","PRODUCT","number1, [number2], …","The product of the numbers"),A("Math","RAND","","A random number 0 … 1 (recalculated)"),A("Math","RANDBETWEEN","bottom, top","A random integer (recalculated)"),A("Text","RIGHT","text, [num_chars]","The last characters"),A("Math","ROUND","number, num_digits","Rounds half away from zero"),A("Math","ROUNDDOWN","number, num_digits","Rounds toward zero"),A("Math","ROUNDUP","number, num_digits","Rounds away from zero"),A("Text","SEARCH","find_text, within_text, [start_num]","The position of a text (case-insensitive, * and ?)"),A("Math","SQRT","number","The square root"),A("Text","SUBSTITUTE","text, old_text, new_text, [instance_num]","Replaces text"),A("Math","SUM","number1, [number2], …","The sum of the numbers"),A("Conditional","SUMIF","range, criteria, [sum_range]","The sum of the cells that match a criterion"),A("Conditional","SUMIFS","sum_range, criteria_range1, criteria1, …","The sum of the cells that match all criteria"),A("Math","SUMPRODUCT","array1, [array2], …","The sum of the products of ranges"),A("Logic","SWITCH","expression, value1, result1, …, [default]","The result of the matching value"),A("Text","TEXT","value, format_text","A number or date as text (0, 0.00, #,##0, 0%, yyyy-mm-dd, dd.mm.yyyy)"),A("Text","TEXTJOIN","delimiter, ignore_empty, text1, …","Joins texts with a delimiter"),A("Date","TODAY","","Today's date (recalculated)"),A("Text","TRIM","text","Removes extra spaces"),A("Text","UPPER","text","Upper case"),A("Text","VALUE","text","A text as number"),A("Lookup","VLOOKUP","lookup_value, table_array, col_index_num, [range_lookup]","Looks up in the first column of a table"),A("Date","WEEKDAY","date, [return_type]","The day of the week"),A("Lookup","XLOOKUP","lookup_value, lookup_array, return_array, [if_not_found]","Looks up a value and returns the matching one"),A("Logic","XOR","logical1, [logical2], …","TRUE if an odd number of arguments is TRUE"),A("Date","YEAR","date","The year of a date")]),lr=String.raw`\$?[A-Za-z]{1,3}\$?[1-9][0-9]*`,ar=new RegExp(String.raw`(?:${lr}(?::${lr})?|\$?[A-Za-z]{1,3}:\$?[A-Za-z]{1,3}|\$?[0-9]+:\$?[0-9]+)`,"y"),$t=/[A-Za-z0-9_.$]/,Gc=new Set(["=","(",",",";","+","-","*","/","^","&","<",">"]);function cr(n){const e=[];if(!n.startsWith("="))return e;let t=1;for(;t<n.length;){const s=n[t];if(s==='"'){t=Mi(n,t);continue}if(s==="["){const o=n.indexOf("]",t);t=o<0?n.length:o+1;continue}if($t.test(s)&&(t===0||!$t.test(n[t-1]))){ar.lastIndex=t;const o=ar.exec(n),i=o?t+o[0].length:-1;if(o&&Wc(o[0])&&(i>=n.length||!$t.test(n[i])&&n[i]!=="("&&n[i]!==":")){e.push({start:t,end:i,text:o[0],key:o[0].replace(/\$/g,"").toUpperCase()}),t=i;continue}for(;t<n.length&&$t.test(n[t]);)t++;continue}t++}return e}function Wc(n){return(n.match(/[A-Za-z]+/g)??[]).every(e=>Le(e)>=0)}function Mi(n,e){let t=e+1;for(;t<n.length;){if(n[t]==='"'){if(n[t+1]==='"'){t+=2;continue}return t+1}t++}return t}function il(n,e){let t=1;for(;t<e;){if(n[t]==='"'){const s=Mi(n,t),o=s-1>t&&n[s-1]==='"';if(s>e||s===e&&!o)return!0;t=s;continue}if(n[t]==="["){const s=n.indexOf("]",t);if(s<0||s>=e)return!0;t=s+1;continue}t++}return!1}function Uc(n,e){return e<n.length&&$t.test(n[e])?!1:rl(n,e)}function rl(n,e){if(!n.startsWith("=")||e<1||il(n,e))return!1;let t=e-1;for(;t>0&&n[t]===" ";)t--;return Gc.has(n[t])}function Kc(n){const e=n.split(":"),t=/^(\$?)([A-Za-z]*)(\$?)([0-9]*)$/.exec(e[0]);if(!t)return n;const s=t[2]&&t[4]?t[1]?t[3]?1:3:t[3]?2:0:t[1]||t[3]?1:0,o=t[2]&&t[4]?(s+1)%4:(s+1)%2,i=o===1||o===3,r=o===1||o===2;return e.map(l=>{const a=/^\$?([A-Za-z]*)\$?([0-9]*)$/.exec(l);if(!a)return l;const[,c,h]=a;return c&&h?`${i?"$":""}${c}${r?"$":""}${h}`:c?`${o?"$":""}${c}`:`${o?"$":""}${h}`}).join(":")}function hr(n,e){if(!n.startsWith("=")||il(n,e)||e<n.length&&/[A-Za-z0-9_.(]/.test(n[e]))return;let t=e;for(;t>1&&/[A-Za-z0-9_.]/.test(n[t-1]);)t--;const s=n.slice(t,e);if(!(!/^[A-Za-z][A-Za-z0-9_.]*$/.test(s)||!rl(n,t)))return{start:t,prefix:s}}function zc(n,e){if(!n.startsWith("="))return;const t=[];let s=1;for(;s<e;){const o=n[s];if(o==='"'){const i=Mi(n,s);if(i>e)return So(t);s=i;continue}if(o==="["){const i=n.indexOf("]",s);if(i<0||i>=e)return So(t);s=i+1;continue}if(o==="("){let i=s;for(;i>1&&/[A-Za-z0-9_.]/.test(n[i-1]);)i--;t.push({name:n.slice(i,s).toUpperCase(),argument:0})}else o===")"?t.pop():(o===","||o===";")&&t.length&&t[t.length-1].argument++;s++}return So(t)}function So(n){for(let e=n.length-1;e>=0;e--)if(n[e].name)return n[e]}function jc(n){const e=n.indexOf("("),t=n.slice(e+1,n.lastIndexOf(")"));return t.trim()?t.split(",").map(s=>s.trim()):[]}const Xc=8,Yc=50;class nl{constructor(e,t,s,o,i,r,l){this.scope=e,this.sheet=t,this.input=s,this.editedCell=i,this.changed=r,this.frames=[],this.suggestions=[],this.active=0,this.listClosed=!1,this.composing=!1,this.abort=new AbortController,this.ids={list:`${l}-functions`,hint:`${l}-hint`,option:d=>`${l}-fn-${d.replace(/[^A-Za-z0-9_-]/g,"_")}`};const a=Object.keys(t.options.functions??{}).map(d=>d.toUpperCase());this.functions=[...ol.filter(d=>!a.includes(d.name)),...a.map(d=>({name:d,signature:`${d}(…)`,description:"",group:"Math"}))].sort((d,u)=>d.name.localeCompare(u.name));const c=e.getDomService().domService;this.mirror=c.createElement("div"),c.addClass(this.mirror,"ge-table-formula-mirror"),c.setAttribute(this.mirror,"aria-hidden","true"),o.insertBefore(this.mirror,s),this.list=c.createElement("div"),c.addClass(this.list,"ge-table-formula-list"),c.setAttribute(this.list,"id",this.ids.list),c.setAttribute(this.list,"role","listbox"),c.setAttribute(this.list,"aria-label",this.texts().functionSuggestions()),this.list.style.display="none",c.appendChild(o,this.list),this.hint=c.createElement("div"),c.addClass(this.hint,"ge-table-formula-hint"),c.setAttribute(this.hint,"id",this.ids.hint),c.setAttribute(this.hint,"role","tooltip"),this.hint.style.display="none",c.appendChild(o,this.hint);const h=this.abort.signal;s.addEventListener("input",()=>this.onInput(),{signal:h}),s.addEventListener("compositionstart",()=>{this.composing=!0,this.refresh()},{signal:h}),s.addEventListener("compositionend",()=>{this.composing=!1,this.refresh()},{signal:h}),s.addEventListener("keydown",()=>requestAnimationFrame(()=>this.syncScroll()),{signal:h});for(const d of["keyup","click","select","scroll"])s.addEventListener(d,()=>this.refreshCaret(),{signal:h});this.list.addEventListener("pointerdown",d=>{var g,p;d.preventDefault();const u=(p=(g=d.target).closest)==null?void 0:p.call(g,".ge-table-formula-option"),f=u?Number(u.getAttribute("data-index")):-1;f>=0&&this.accept(f)},{signal:h}),this.refresh()}onKeyDown(e,t){var u,f;if(!this.input.value.startsWith("="))return!1;const o=!e.ctrlKey&&!e.metaKey&&!e.altKey;if(this.isListOpen()&&o)switch(e.key){case"ArrowDown":case"ArrowUp":return this.active=(this.active+(e.key==="ArrowDown"?1:-1)+this.suggestions.length)%this.suggestions.length,this.renderList(),!0;case"Enter":case"Tab":return e.shiftKey?!1:(this.accept(this.active),!0);case"Escape":return this.listClosed=!0,this.refresh(),!0}if(e.key==="F2")return this.pointer=void 0,!1;if(e.key==="F4"&&o)return this.toggleReferenceAtCaret();const r={ArrowUp:[-1,0],ArrowDown:[1,0],ArrowLeft:[0,-1],ArrowRight:[0,1]}[e.key];if(!r||!o||!this.canPoint(t))return!1;let[l,a]=r;this.scope.isRtl()&&(a=-a);const c=((u=this.pointer)==null?void 0:u.cell)??this.editedCell(),h=this.step(c,l,a),d=e.shiftKey?((f=this.pointer)==null?void 0:f.anchor)??c:h;return this.point(d,h),!0}onPointerDown(e){var l,a;if(e.button!==0||!this.input.value.startsWith("=")||!this.canPoint("enter"))return!1;const t=(a=(l=e.target)==null?void 0:l.closest)==null?void 0:a.call(l,'.ge-table-col-div[data-area="body"]'),s=Number(t==null?void 0:t.getAttribute("data-row-index")),o=Number(t==null?void 0:t.getAttribute("data-col-index"));if(!t||!(s>=0)||!(o>=0)||this.sheet.engineColumn(o)===void 0)return!1;const i=[s,o],r=e.shiftKey&&this.pointer?this.pointer.anchor:i;return this.point(r,i,!1),this.startDrag(r),!0}getOwnedIds(){return[this.ids.list,this.ids.hint]}update(){this.renderFrames()}destroy(){var e;this.abort.abort(),(e=this.drag)==null||e.abort(),this.mirror.remove(),this.list.remove(),this.hint.remove();for(const t of this.frames)t.remove();this.frames=[],this.input.classList.remove("ge-table-formula-input");for(const t of["role","aria-expanded","aria-controls","aria-autocomplete","aria-activedescendant","aria-describedby"])this.input.removeAttribute(t)}texts(){const e=this.scope.ariaTexts??{},t=new pe;return{functionSuggestions:()=>(e.functionSuggestions??t.functionSuggestions).call(e),referenceInserted:s=>(e.referenceInserted??t.referenceInserted).call(e,s)}}onInput(){this.pointer=void 0,this.listClosed=!1,this.refresh()}caret(){return this.input.selectionStart??this.input.value.length}collapsed(){return this.input.selectionStart===this.input.selectionEnd}canPoint(e){const t=this.input.value;if(!this.collapsed()||this.composing)return!1;const s=this.caret();return this.pointer&&s===this.pointer.end?!0:e==="enter"&&Uc(t,s)}step(e,t,s){const o=this.scope.tableModel.getBodyModel().getRowCount(),i=Math.min(Math.max(0,e[0]+t),o-1);let r=e[1];if(s){const l=this.scope.nextShownColumn(r,s);this.sheet.engineColumn(l)!==void 0&&(r=l)}return[i,r]}referenceText(e,t){const s=this.sheet.physicalRow(e[0]),o=this.sheet.physicalRow(t[0]),i=this.sheet.engineColumn(e[1]),r=this.sheet.engineColumn(t[1]);if(s===void 0||o===void 0||i===void 0||r===void 0||s!==o&&!this.isContiguous(e[0],t[0],s,o))return;const l=mt(Math.min(s,o),Math.min(i,r)),a=mt(Math.max(s,o),Math.max(i,r));return l===a?l:`${l}:${a}`}isContiguous(e,t,s,o){if(Math.abs(e-t)!==Math.abs(s-o))return!1;const i=Math.min(s,o),r=Math.max(s,o);for(let l=Math.min(e,t);l<=Math.max(e,t);l++){const a=this.sheet.physicalRow(l);if(a===void 0||a<i||a>r)return!1}return!0}point(e,t,s=!0){const o=this.referenceText(e,t);if(!o)return;const i=this.input.value,r=this.caret(),l=this.pointer&&r===this.pointer.end,a=l?this.pointer.start:r,c=l?this.pointer.end:r;this.input.value=i.slice(0,a)+o+i.slice(c);const h=a+o.length;this.input.setSelectionRange(h,h),this.pointer={start:a,end:h,anchor:e,cell:t},this.scope.ensureRowIsVisible(t[0]),this.scope.ensureColumnIsVisible(t[1]),s&&this.scope.announce(this.texts().referenceInserted(o)),this.listClosed=!1,this.refresh(),this.changed()}startDrag(e){var l,a;(l=this.drag)==null||l.abort();const t=new AbortController;this.drag=t;const s=this.input.ownerDocument,o=this.scope.hostElement;let i=(a=this.pointer)==null?void 0:a.cell;s.addEventListener("pointermove",c=>{const h=o.getBoundingClientRect(),d=this.scope.getBodyCellAtHostPoint(this.scope.clientXToHostX(c.clientX),c.clientY-h.top-o.clientTop);d[0]<0||this.sheet.engineColumn(d[1])===void 0||i&&i[0]===d[0]&&i[1]===d[1]||(i=d,this.point(e,d,!1))},{signal:t.signal});const r=()=>{t.abort();const c=this.pointer?this.input.value.slice(this.pointer.start,this.pointer.end):"";c&&this.scope.announce(this.texts().referenceInserted(c))};s.addEventListener("pointerup",r,{signal:t.signal}),s.addEventListener("pointercancel",r,{signal:t.signal})}toggleReferenceAtCaret(){const e=this.input.value,t=this.caret(),s=cr(e).find(r=>t>=r.start&&t<=r.end);if(!s)return!1;const o=Kc(s.text);this.input.value=e.slice(0,s.start)+o+e.slice(s.end);const i=s.start+o.length;return this.input.setSelectionRange(i,i),this.pointer&&this.pointer.start===s.start&&(this.pointer.end=i),this.refresh(),this.changed(),!0}isListOpen(){return this.list.style.display!=="none"&&this.suggestions.length>0}accept(e){const t=this.suggestions[e],s=hr(this.input.value,this.caret());if(!t||!s)return;const o=this.input.value,i=`${t.name}(`;this.input.value=o.slice(0,s.start)+i+o.slice(s.start+s.prefix.length);const r=s.start+i.length;this.input.setSelectionRange(r,r),this.pointer=void 0,this.refresh(),this.changed()}refreshCaret(){this.syncScroll(),this.renderPopups()}refresh(){this.renderMirror(),this.renderFrames(),this.renderPopups()}syncScroll(){this.mirror.scrollLeft=this.input.scrollLeft}colored(){const e=new Map;return cr(this.input.value).map(t=>{let s=e.get(t.key);return s===void 0&&e.set(t.key,s=e.size%Xc),{...t,color:s}})}renderMirror(){const e=this.input.value,t=e.startsWith("=")&&!this.composing,s=this.mirror;if(s.textContent="",this.input.classList.toggle("ge-table-formula-input",t),s.style.display=t?"":"none",!t)return;const o=this.scope.getDomService().domService,i=o.createElement("span");s.appendChild(i);let r=0;for(const l of this.colored()){l.start>r&&i.appendChild(o.createText(e.slice(r,l.start)));const a=o.createElement("span");o.addClass(a,`ge-table-formula-ref-text-${l.color}`),a.textContent=l.text,i.appendChild(a),r=l.end}r<e.length&&i.appendChild(o.createText(e.slice(r))),this.syncScroll()}renderFrames(){const e=[];if(this.input.value.startsWith("=")){const s=new Set;for(const o of this.colored()){if(s.has(o.key))continue;s.add(o.key);const i=this.frameRect(o.text);i&&e.push({color:o.color,rect:i})}}const t=this.scope.getDomService();for(;this.frames.length>e.length;)this.frames.pop().remove();for(;this.frames.length<e.length;){const s=t.createDivWithClass("ge-table-formula-ref",this.scope.hostElement);t.domService.setAttribute(s,"aria-hidden","true"),this.frames.push(s)}e.forEach(({color:s,rect:o},i)=>{const r=this.frames[i];r.className=`ge-table-formula-ref ge-table-formula-ref-${s}`,t.setStyle(r,"left",`${o.left}px`),r.style.top=`${o.top}px`,r.style.width=`${o.width}px`,r.style.height=`${o.height}px`})}frameRect(e){const t=this.frameCells(e);if(!t)return;const[s,o,i,r]=t,l=this.scope.getBodyCellRectInHost(Math.min(s,o),Math.min(i,r)),a=this.scope.getBodyCellRectInHost(Math.max(s,o),Math.max(i,r)),c=Math.max(Math.min(l.left,a.left),Math.min(l.clipLeft,a.clipLeft)),h=Math.min(Math.max(l.left+l.width,a.left+a.width),Math.max(l.clipRight,a.clipRight)),d=Math.max(l.top,l.clipTop),u=Math.min(a.top+a.height,a.clipBottom);return h>c&&u>d?{left:c,top:d,width:h-c,height:u-d}:void 0}frameCells(e){const t=this.scope.tableModel.getBodyModel(),s=t.getRowCount(),o=[this.input.value,s,s?t.getRowByIndex(0):void 0,s?t.getRowByIndex(s-1):void 0];(!this.cellCache||this.cellCache.signature.some((a,c)=>a!==o[c]))&&(this.cellCache={signature:o,cells:new Map});const i=this.cellCache.cells;if(i.has(e))return i.get(e);const r=qr(e);let l;if(r){const a=r.wholeColumns?0:this.sheet.displayRow(r.from.row),c=r.wholeColumns?s-1:this.sheet.displayRow(Math.min(r.to.row,this.sheetRows()-1)),h=r.wholeRows?this.firstDataColumn():this.sheet.modelColumn(r.from.col),d=r.wholeRows?this.lastDataColumn():this.sheet.modelColumn(r.to.col);l=a<0||c<0||h<0||d<0?void 0:[a,c,h,d]}return i.set(e,l),l}sheetRows(){return this.sheet.rowCount()}firstDataColumn(){for(let e=0;e<this.scope.tableModel.getColumnCount();e++)if(this.sheet.engineColumn(e)!==void 0)return e;return-1}lastDataColumn(){let e=-1;for(let t=0;t<this.scope.tableModel.getColumnCount();t++)this.sheet.engineColumn(t)!==void 0&&(e=t);return e}renderPopups(){const e=this.scope.getDomService().domService,t=this.input,s=t.value,o=s.startsWith("="),i=this.caret(),r=o&&this.collapsed()&&!this.composing?hr(s,i):void 0,l=r==null?void 0:r.prefix.toUpperCase(),a=this.suggestions.map(p=>p.name).join();this.suggestions=l?this.functions.filter(p=>p.name.startsWith(l)).slice(0,Yc):[],this.suggestions.map(p=>p.name).join()!==a&&(this.active=0);const c=this.suggestions.length>0&&!this.listClosed;e.setAttribute(t,"role","combobox"),e.setAttribute(t,"aria-autocomplete","list"),e.setAttribute(t,"aria-controls",this.ids.list),e.setAttribute(t,"aria-expanded",String(c)),this.list.style.display=c?"":"none",c?this.renderList():t.removeAttribute("aria-activedescendant");const h=o&&!c&&!this.composing?zc(s,i):void 0,d=h?this.functions.find(p=>p.name===h.name):void 0;if(this.hint.textContent="",!d){this.hint.style.display="none",t.removeAttribute("aria-describedby");return}const u=jc(d.signature),g=u[u.length-1]==="…"&&h.argument>=u.length-1?u.length-2:h.argument;this.hint.appendChild(e.createText(`${d.name}(`)),u.forEach((p,m)=>{if(m&&this.hint.appendChild(e.createText(", ")),m===g){const b=e.createElement("b");b.textContent=p,this.hint.appendChild(b)}else this.hint.appendChild(e.createText(p))}),this.hint.appendChild(e.createText(")")),this.hint.style.display="",e.setAttribute(t,"aria-describedby",this.ids.hint)}renderList(){var o;const e=this.scope.getDomService().domService,t=this.list;t.textContent="",this.suggestions.forEach((i,r)=>{const l=e.createElement("div");e.addClass(l,"ge-table-formula-option"),e.setAttribute(l,"id",this.ids.option(i.name)),e.setAttribute(l,"role","option"),e.setAttribute(l,"data-index",String(r)),e.setAttribute(l,"aria-selected",String(r===this.active));const a=e.createElement("span");if(e.addClass(a,"ge-table-formula-option-name"),a.textContent=i.name,l.appendChild(a),i.description){const c=e.createElement("span");e.addClass(c,"ge-table-formula-option-description"),c.textContent=i.description,l.appendChild(c)}t.appendChild(l)}),e.setAttribute(this.input,"aria-activedescendant",this.ids.option(this.suggestions[this.active].name));const s=t.children[this.active];(o=s==null?void 0:s.scrollIntoView)==null||o.call(s,{block:"nearest"})}}function Jc(n){if(n==null)return"";if(n instanceof Date){if(Number.isNaN(n.getTime()))return"";const e=t=>String(t).padStart(2,"0");return`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())}`}return String(n)}class ll{constructor(e,t){this.tableScope=e,this.options=t,this.tabStartColumn=-1,this.blockClick=!1,this.editorId=`${e.ariaIds.prefix}-editor`;const s=e.listenerAbortController.signal,o=e.hostElement;o.addEventListener("keydown",i=>this.onKeyDown(i),{capture:!0,signal:s}),o.addEventListener("pointerdown",i=>this.onPointerDown(i),{capture:!0,signal:s}),o.addEventListener("focusout",i=>this.onFocusOut(i),{signal:s});for(const i of["mousedown","mouseup","click","dblclick"])o.addEventListener(i,r=>this.onBlockedMouse(r),{capture:!0,signal:s})}isOpen(){return!!this.session}getCell(){return this.session?[this.session.rowIndex,this.session.columnIndex]:void 0}getOwnedEditorId(e,t){var o;const s=this.session;if(!(!s||s.rowIndex!==e||s.columnIndex!==t||!((o=this.editor)!=null&&o.getFocusElement())))return this.assist?[this.editorId,...this.assist.getOwnedIds()].join(" "):this.editorId}handlesColumn(e){const t=this.tableScope.tableModel.getColumnDef(e);if(t!=null&&t.editor)return!0;if(t!=null&&t.getEditRenderer)return!1;const s=this.tableScope.tableOptions.getEditRenderer;return!s||s===Ci}start(e,t,s={}){const o=this.tableScope;if(this.session){if(this.session.rowIndex===e&&this.session.columnIndex===t)return!0;if(!this.commit("none"))return!1}const i=o.tableModel.getBodyModel();if(e<0||t<0||e>=i.getRowCount()||t>=o.tableModel.getColumnCount()||!i.isEditable(e,t)||O(o.tableModel.getColumnDef(t))||!o.canStartEditing())return!1;const r=s.mode??"edit",l=o.tableModel.getColumnDef(t),a=o.getShownCellValue(e,t),c=i.getRowByIndex(e),h=U(c)?c.data:c,d=Jc(a);o.ensureColumnIsVisible(t),o.ensureRowIsVisible(e);const u=this.ensureContainer(),f={rowIndex:e,columnIndex:t,row:c,columnDef:l,value:a,input:d,typedText:s.typedText,mode:r,textSelection:s.textSelection??this.options.textSelection,direction:o.isRtl()?"rtl":"ltr",ariaLabel:o.getColumnAriaLabel(t),domService:o.getDomService().domService,commit:y=>{this.commit(y??"none")},cancel:()=>this.cancel(),inputChanged:()=>{this.session&&(this.session.hadInput=!0),this.fire("input")}},g=this.createEditor(f);this.editor=g;const p=!!s.imeStart;this.session={rowIndex:e,columnIndex:t,row:h??c,mode:r,initialText:d,typed:s.typedText!==void 0&&!p,columnDef:l,pendingInput:p,hadInput:!1},g.open(u,f);const m=g.getFocusElement();m&&o.getDomService().domService.setAttribute(m,"id",this.editorId);const b=o.tableSheet;return b!=null&&b.isFormulaColumnIndex(t)&&(m==null?void 0:m.tagName)==="INPUT"&&m.type==="text"&&(this.assist=new nl(o,b,m,u,()=>this.session?[this.session.rowIndex,this.session.columnIndex]:[e,t],()=>f.inputChanged(),this.editorId)),u.style.display="block",this.update(),g.focus(),this.fire("start"),o.announce(o.getSheetTexts().editingStarted(o.getColumnAriaLabel(t))),o.repaint(),g.focus(),!0}commit(e="none",t={}){var u;const s=this.session,o=this.editor;if(!s||!o)return!0;const i=this.tableScope,r=((u=o.getText)==null?void 0:u.call(o))??String(o.getValue()??""),l=s.pendingInput&&!s.hadInput||!s.typed&&r===s.initialText;if(!l||t.fillSelection){const f=o.getValue(),g=t.fillSelection?i.getSelectedBodyCells(this.options.maxClearCells):[];if(!g)return i.announce(i.getSheetTexts().clearTooLarge(this.options.maxClearCells)),o.focus(),!1;g.length||g.push([s.rowIndex,s.columnIndex]);const p=i.commitCellEditor(g,f,!!t.deferRepaint);if(p.invalid&&!p.written){const m=o.getFocusElement();if(m){const b=i.getDomService().domService;b.setAttribute(m,"aria-invalid","true"),b.setAttribute(m,"title",p.message??"")}return o.focus(),!1}}const{rowIndex:a,columnIndex:c}=s,h=i.tableSheet,d=!l&&(h!=null&&h.isFormulaInput(c,r))?h.syntaxError(r):void 0;return this.close("commit",r,!!t.deferRepaint),d&&i.announce(i.getFormulaErrorText(d)),this.moveAfterCommit(a,c,e,!!t.tab),!0}cancel(){this.session&&this.close("cancel")}update(){var g,p;const e=this.session,t=this.container;if(!e||!t)return;const s=this.tableScope;if(!this.followColumn(e)||!this.followRow(e)){this.close("cancel");return}const o=s.getBodyCellRectInHost(e.rowIndex,e.columnIndex);s.getDomService().setStyle(t,"left",`${o.left}px`),t.style.top=`${o.top}px`,t.style.width=`${Math.max(0,o.width)}px`,t.style.height=`${Math.max(0,o.height)}px`;const r=Math.max(0,o.clipTop-o.top),l=Math.max(0,o.top+o.height-o.clipBottom),a=Math.max(0,o.clipLeft-o.left),c=Math.max(0,o.left+o.width-o.clipRight),h=r+l>=o.height||a+c>=o.width;t.classList.toggle("ge-table-cell-editor-clipped",h);const[d,u]=s.isRtl()?[c,a]:[a,c];t.style.clipPath=h?"inset(50%)":r||l||d||u?`inset(${r}px ${u}px ${l}px ${d}px)`:"",(g=this.assist)==null||g.update(),t.ownerDocument.activeElement===s.hostElement&&((p=this.editor)==null||p.focus())}destroy(){var e,t,s;(e=this.assist)==null||e.destroy(),this.assist=void 0,(t=this.editor)==null||t.close(),this.editor=void 0,this.session=void 0,(s=this.container)==null||s.remove(),this.container=void 0}ensureContainer(){if(!this.container||!this.container.isConnected){const e=this.tableScope.getDomService();this.container=e.createDivWithClass("ge-table-cell-editor",this.tableScope.hostElement),e.domService.setAttribute(this.container,"role","presentation")}return this.container}createEditor(e){var r,l;const t=(r=e.columnDef)==null?void 0:r.editor;if(typeof t=="function")return t(e);const s=this.tableScope.getTypedCellValue(e.rowIndex,e.columnIndex),o=s!==e.value,i=t??(s instanceof Date&&!o?"date":typeof s=="number"||((l=e.columnDef)==null?void 0:l.editInputPipe)===sl?"number":"text");return i==="number"?new el:i==="date"?new tl:new lo}followRow(e){const t=this.tableScope.tableModel.getBodyModel(),s=i=>{const r=t.getRowByIndex(i);return U(r)?r.data:r};if(e.row===void 0||e.row===null||typeof e.row!="object")return e.rowIndex<t.getRowCount();if(e.rowIndex<t.getRowCount()&&s(e.rowIndex)===e.row)return!0;if(e.rowIndex<t.getRowCount()&&s(e.rowIndex)!==s(e.rowIndex))return e.row=void 0,!0;const o=t.getRowCount();for(let i=0;i<o;i++)if(s(i)===e.row)return e.rowIndex=i,!0;return!1}followColumn(e){const t=this.tableScope.tableModel;if(t.getColumnDef(e.columnIndex)===e.columnDef)return!0;const s=t.getColumnCount();for(let o=0;o<s;o++)if(t.getColumnDef(o)===e.columnDef)return e.columnIndex=o,!0;return!1}close(e,t,s=!1){var l,a,c,h;const o=this.session,i=this.container,r=!!(i!=null&&i.contains(i.ownerDocument.activeElement));(l=this.assist)==null||l.destroy(),this.assist=void 0,(a=this.editor)==null||a.close(),this.editor=void 0,i&&(i.style.display="none",i.style.clipPath=""),this.session=void 0,o&&((h=(c=this.tableScope.getEventListener()).onEditingChanged)==null||h.call(c,new bt(e,o.rowIndex,o.columnIndex,o.mode,t))),r&&this.tableScope.hostElement.focus({preventScroll:!0}),e==="cancel"&&!s&&this.tableScope.repaint()}fire(e){var s,o,i,r;const t=this.session;t&&((r=(i=this.tableScope.getEventListener()).onEditingChanged)==null||r.call(i,new bt(e,t.rowIndex,t.columnIndex,t.mode,(o=(s=this.editor)==null?void 0:s.getText)==null?void 0:o.call(s))))}moveAfterCommit(e,t,s,o){const i=this.tableScope;if(s==="none")return;if(s==="right"||s==="left"){o&&this.tabStartColumn<0&&(this.tabStartColumn=t),o||(this.tabStartColumn=-1),i.moveActiveCell(e,t,0,s==="right"?1:-1);return}const r=s==="down"?1:-1,l=s==="down"&&this.tabStartColumn>=0?this.tabStartColumn:t;this.tabStartColumn=-1,i.moveActiveCell(e,l,r,0)}onPointerDown(e){var s;const t=this.container;if(!(!this.session||!t||t.contains(e.target))&&e.target!==this.tableScope.scrollViewport){if(this.blockClick=!1,(s=this.assist)!=null&&s.onPointerDown(e)){e.preventDefault(),e.stopPropagation(),this.blockClick=!0;return}this.commit("none",{deferRepaint:!0})||(e.preventDefault(),e.stopPropagation(),this.blockClick=!0)}}onBlockedMouse(e){var t;!this.blockClick||(t=this.container)!=null&&t.contains(e.target)||(e.preventDefault(),e.stopPropagation(),(e.type==="click"||e.type==="dblclick")&&(this.blockClick=e.type==="click",e.type==="click"&&setTimeout(()=>this.blockClick=!1,500)))}onFocusOut(e){const t=this.container,s=e.relatedTarget;if(!(!this.session||!t||!t.contains(e.target))){if(!s){const o=t.ownerDocument;setTimeout(()=>{this.session&&o.hasFocus()&&!this.tableScope.hostElement.contains(o.activeElement)&&this.commit("none")});return}this.tableScope.hostElement.contains(s)||this.commit("none")}}onKeyDown(e){var o;const t=this.tableScope;if((o=t.isEventInDetail)!=null&&o.call(t,e))return;const s=this.container;if(this.session&&s&&s.contains(e.target)){this.onEditorKeyDown(e);return}this.session||e.target!==t.hostElement||!this.options.startOnType||this.onTypeToEdit(e)}isMac(){return typeof navigator<"u"&&/Mac/.test(navigator.platform)}onTypeToEdit(e){const t=this.tableScope,s=typeof e.getModifierState=="function"&&e.getModifierState("AltGraph");if((e.ctrlKey||e.metaKey)&&!s||e.altKey&&!s&&!this.isMac())return;const o=e.isComposing||e.key==="Process"||e.keyCode===229,i=e.key==="Dead",r=e.key.length===1&&!(e.key===" "&&(e.shiftKey||e.ctrlKey));if(!r&&!o&&!i)return;const l=t.getActiveBodyCell();if(!l||!t.canStartEditing())return;const[a,c]=l;if(!t.tableModel.getBodyModel().isEditable(a,c)||O(t.tableModel.getColumnDef(c))){r&&e.key!==" "&&t.announce(t.getSheetTexts().readOnlyCell());return}if(typeof t.getShownCellValue(a,c)=="boolean"){e.key===" "&&(e.preventDefault(),e.stopImmediatePropagation(),t.toggleBooleanCell(a,c));return}this.handlesColumn(c)&&(r?(e.preventDefault(),e.stopImmediatePropagation(),this.start(a,c,{mode:"enter",typedText:e.key})):(e.stopImmediatePropagation(),this.start(a,c,{mode:"enter",typedText:"",imeStart:!0})))}onEditorKeyDown(e){var r,l,a,c;const t=this.editor,s=this.session;if(!t||!s||e.isComposing||e.key==="Process"||e.keyCode===229||(r=t.isComposing)!=null&&r.call(t))return;const o=()=>{e.preventDefault(),e.stopPropagation()};if((l=this.assist)!=null&&l.onKeyDown(e,s.mode)){o();return}if((a=t.wantsKey)!=null&&a.call(t,e,s.mode))return;const i=this.tableScope.isRtl();switch(e.key){case"Escape":o(),this.cancel();return;case"Enter":{if(e.altKey)return;if(o(),(e.ctrlKey||e.metaKey)&&this.options.ctrlEnterFillsSelection){this.commit("none",{fillSelection:!0});return}const h=this.options.enterMoves==="right"?"right":this.options.enterMoves==="none"?"none":"down",d=h==="right"?"left":h==="down"?"up":"none";this.commit(e.shiftKey?d:h);return}case"Tab":{if(!this.options.tabMoves||e.ctrlKey||e.metaKey||e.altKey)return;const h=e.shiftKey?-1:1;this.tableScope.hasShownColumnBeside(s.columnIndex,h)?(o(),this.commit(h>0?"right":"left",{tab:!0})):this.commit("none")?this.tabStartColumn=-1:o();return}case"F2":o(),s.mode=s.mode==="enter"?"edit":"enter",(c=t.setMode)==null||c.call(t,s.mode);return;case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":{if(s.mode!=="enter"||!this.options.arrowKeysCommit||e.ctrlKey||e.metaKey||e.altKey||e.shiftKey)return;o();let h=e.key==="ArrowUp"?"up":e.key==="ArrowDown"?"down":e.key==="ArrowLeft"?"left":"right";i&&(h==="left"||h==="right")&&(h=h==="left"?"right":"left"),this.commit(h);return}default:return}}}function al(n){const e=n?"meta":"ctrl";return{tab:"NAVIGATE_NEXT_CELL","shift+tab":"NAVIGATE_PREVIOUS_CELL","shift+arrowup":"EXTEND_SELECTION_UP","shift+arrowdown":"EXTEND_SELECTION_DOWN","shift+arrowleft":"EXTEND_SELECTION_LEFT","shift+arrowright":"EXTEND_SELECTION_RIGHT","shift+home":"EXTEND_SELECTION_ROW_START","shift+end":"EXTEND_SELECTION_ROW_END","shift+pageup":"EXTEND_SELECTION_PAGE_UP","shift+pagedown":"EXTEND_SELECTION_PAGE_DOWN",[`${e}+arrowup`]:"NAVIGATE_DATA_EDGE_UP",[`${e}+arrowdown`]:"NAVIGATE_DATA_EDGE_DOWN",[`${e}+arrowleft`]:"NAVIGATE_DATA_EDGE_LEFT",[`${e}+arrowright`]:"NAVIGATE_DATA_EDGE_RIGHT",[`${e}+shift+arrowup`]:"EXTEND_TO_DATA_EDGE_UP",[`${e}+shift+arrowdown`]:"EXTEND_TO_DATA_EDGE_DOWN",[`${e}+shift+arrowleft`]:"EXTEND_TO_DATA_EDGE_LEFT",[`${e}+shift+arrowright`]:"EXTEND_TO_DATA_EDGE_RIGHT","shift+space":"SELECT_ROW","ctrl+space":"SELECT_COLUMN",delete:"CLEAR_CELLS",backspace:"CLEAR_AND_EDIT"}}function cl(n){return n?{"meta+c":"COPY_2_CLIPBOARD","meta+x":"CUT_2_CLIPBOARD","meta+v":"PASTE_FROM_CLIPBOARD"}:{"ctrl+c":"COPY_2_CLIPBOARD","ctrl+x":"CUT_2_CLIPBOARD","ctrl+v":"PASTE_FROM_CLIPBOARD","ctrl+insert":"COPY_2_CLIPBOARD","shift+delete":"CUT_2_CLIPBOARD","shift+insert":"PASTE_FROM_CLIPBOARD"}}class os{constructor(){this.copyHeaders=!1,this.copyValue="text",this.html=!0,this.pasteAddsRows=!1,this.createRow=void 0,this.maxPasteCells=1e6,this.processCopy=void 0,this.processPaste=void 0}static create(e){if(!e)return;const t=new os;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}const ht=()=>new I("#N/A","Not found"),se=n=>new I("#VALUE!",n),we=n=>new I("#NUM!",n),nt=n=>new I("#DIV/0!",n);function dt(n,e){for(const t of n)if(Ye(t))for(let s=0;s<t.rows;s++)for(let o=0;o<t.cols;o++){const i=e(t.get(s,o),!0);if(i!==void 0)return i}else{const s=e(t,!1);if(s!==void 0)return s}}function Nt(n,e){const t=[];for(const s of n)if(Ye(s))for(let o=0;o<s.rows;o++)for(let i=0;i<s.cols;i++){const r=s.get(o,i);if(typeof r=="number")t.push(r);else if(r!==null&&typeof r=="object"){if(w(r))return r;G(r)&&t.push(r.serial)}}else{if(w(s))return s;if(typeof s=="number")t.push(s);else if(G(s))t.push(s.serial);else if(s!==null){const o=z(s,e);if(w(o))return o;t.push(o)}}return t}function qc(n,e){return z(n,e)}function ve(n,e){const t=[];for(const s of n){const o=z(s,e);if(w(o))return o;t.push(o)}return t}function Zc(n){return re(n)}function dr(n,e,t){const s=Math.pow(10,Math.trunc(e)),o=xe(Math.abs(n)*s),i=(t?Math.ceil(o):Math.floor(o))/s;return n<0?-i:i}function Qc(n,e){const t=_(n);if(w(t))return()=>!1;const s=h=>{if(typeof h=="number")return h;if(G(h))return h.serial;if(typeof h=="string"&&h.trim()!==""){const d=z(h,e);return w(d)?void 0:d}};if(typeof t=="number"||G(t)){const h=G(t)?t.serial:t;return d=>s(d)===h}if(typeof t=="boolean")return h=>h===t;const o=t===null?"":t,i=/^(<=|>=|<>|<|>|=)?(.*)$/s.exec(o),r=i[1]??"",l=i[2];if(l===""&&(r===""||r==="="))return h=>ko(h);if(l===""&&r==="<>")return h=>!ko(h);const a=s(l);if(a!==void 0&&!(r===""&&!/^[\s\d.+-]/.test(l)))return h=>{const d=s(h);if(d===void 0)return r==="<>";const u=xe(d)-xe(a);switch(r){case"<":return u<0;case"<=":return u<=0;case">":return u>0;case">=":return u>=0;case"<>":return u!==0;default:return u===0}};if(r===""||r==="="||r==="<>"){const h=dl(l);return d=>{const u=typeof d=="string"?d:typeof d=="boolean"?d?"TRUE":"FALSE":void 0,f=u!==void 0&&u!==""&&h(u);return r==="<>"?!f:f}}const c=l.toLowerCase();return h=>{if(typeof h!="string")return!1;const d=h.toLowerCase();switch(r){case"<":return d<c;case"<=":return d<=c;case">":return d>c;default:return d>=c}}}function hl(n){var t;const e=[];for(let s=0;s<n.length;s++){const o=n[s];o==="~"&&(n[s+1]==="*"||n[s+1]==="?"||n[s+1]==="~")?e.push({kind:"char",ch:n[++s]}):o==="*"?((t=e[e.length-1])==null?void 0:t.kind)!=="star"&&e.push({kind:"star"}):o==="?"?e.push({kind:"any"}):e.push({kind:"char",ch:o.toLowerCase()})}return e}function Bo(n,e,t=0){const s=e.toLowerCase();let o=0,i=t,r=-1,l=0;for(;i<s.length;){const a=n[o];if(a&&(a.kind==="any"||a.kind==="char"&&a.ch===s[i]))o++,i++;else if(a&&a.kind==="star")r=o++,l=i;else if(r>=0)o=r+1,i=++l;else return!1}for(;o<n.length&&n[o].kind==="star";)o++;return o===n.length}function dl(n){const e=hl(n);return t=>Bo(e,t)}function eh(n){return/(^|[^~])[*?]/.test(n)}function ge(n){return Ye(n)?n:new tt(0,0,1,1,()=>n)}function lt(n,e,t,s){const o=n.map(([l])=>ge(l)),i=n.map(([,l])=>Qc(l,t)),r=o[0];for(const l of o)if(l.rows!==r.rows||l.cols!==r.cols)return se("The ranges have different sizes");for(let l=0;l<r.rows;l++)for(let a=0;a<r.cols;a++){let c=!0;for(let h=0;h<o.length&&c;h++){const d=o[h].get(l,a);c=!w(d)&&i[h](d)}if(c){const h=s(e?e.get(l,a):o[0].get(l,a));if(h)return h}}}function $o(n,e){const t=_(n);if(typeof t=="string"&&e&&eh(t)){const s=dl(t);return o=>typeof o=="string"&&s(o)}return s=>!w(s)&&s!==null&&hs(s,t)===0}function ur(n){return typeof n=="string"?1:typeof n=="boolean"?2:0}function ul(n,e,t=!1){const s=_(e),o=ur(s);let i=-1;for(let r=0;r<n.length;r++){const l=n.get(r);if(l===null||w(l)||ur(l)!==o)continue;const a=hs(l,s);if(!w(a))if(t?a>=0:a<=0)i=r;else break}return i}function Ho(n,e){for(let t=0;t<n.length;t++)if(e(n.get(t)))return t;return-1}function fl(n,e){return{length:n.rows,get:t=>n.get(t,e)}}function gl(n,e){return{length:n.cols,get:t=>n.get(e,t)}}function fr(n){const e=ge(n);return e.rows===1?gl(e,0):e.cols===1?fl(e,0):se("A range of one row or one column is needed")}function $e(n,e){const t=_(n);if(typeof t=="string"){const o=vt(t.trim());if(o!==void 0)return o}const s=z(t,e);return w(s)?s:s<0?we("A negative date"):s}function gr(n){return!Number.isFinite(n)||n<0||n>2958465?we("The date is out of range"):new xt(n)}function th(n,e,t){var h;const s=e.trim(),o=_(n);if(typeof o=="string"&&vt(o.trim())===void 0&&w(z(o,t)))return o;if(/^(yyyy|dd|mm)[-./](mm|dd)[-./](yyyy|dd)$/i.test(s)){const d=$e(n,t);if(w(d))return d;const{y:u,m:f,d:g}=et(d),p=m=>String(m).padStart(2,"0");return s.toLowerCase().replace("yyyy",String(u)).replace(/mm/,p(f)).replace("dd",p(g))}const i=/^(#,##)?0(\.(0+))?(%)?$/.exec(s);if(!i)return se(`TEXT: the format "${s}" is not supported`);let r=z(n,t);if(w(r))return r;i[4]&&(r*=100);const l=((h=i[3])==null?void 0:h.length)??0,a=mi(r,l);let c=Math.abs(a).toFixed(l);if(i[1]){const[d,u]=c.split(".");c=d.replace(/\B(?=(\d{3})+(?!\d))/g,",")+(u?"."+u:"")}return(a<0?"-":"")+c+(i[4]?"%":"")}function sh(n,e,t){if(n>e)return we("The start date is after the end date");const s=et(n),o=et(e);switch(t.toUpperCase()){case"D":return Math.floor(e)-Math.floor(n);case"M":{let i=(o.y-s.y)*12+(o.m-s.m);return o.d<s.d&&i--,i}case"Y":{let i=o.y-s.y;return(o.m<s.m||o.m===s.m&&o.d<s.d)&&i--,i}case"YM":return(o.m-s.m+12-(o.d<s.d?1:0))%12;case"MD":return o.d>=s.d?o.d-s.d:Math.floor(e)-Wt(o.y,o.m-1,s.d);case"YD":{let i=Wt(o.y,s.m,s.d);return i>Math.floor(e)&&(i=Wt(o.y-1,s.m,s.d)),Math.floor(e)-i}default:return we(`DATEDIF unit "${t}" is not supported (d, m, y, ym, md, yd)`)}}const xo=n=>({min:1,max:1,fn:(e,t)=>{const s=qc(e[0],t);if(w(s))return s;const o=n(s);return w(o)?o:W(o)}}),ps=n=>({min:1,max:1,fn:e=>{const t=Zc(e[0]);return w(t)?t:n(t)}}),oh={SUM:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:W(t.reduce((s,o)=>s+o,0))}},PRODUCT:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:W(t.length?t.reduce((s,o)=>s*o,1):0)}},AVERAGE:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:t.length?W(t.reduce((s,o)=>s+o,0)/t.length):nt("AVERAGE of no numbers")}},MIN:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:t.length?t.reduce((s,o)=>Math.min(s,o),1/0):0}},MAX:{min:1,max:255,fn:(n,e)=>{const t=Nt(n,e);return w(t)?t:t.length?t.reduce((s,o)=>Math.max(s,o),-1/0):0}},COUNT:{min:1,max:255,fn:(n,e)=>{let t=0;return dt(n,(s,o)=>{(typeof s=="number"||G(s)||!o&&(typeof s=="boolean"||typeof s=="string"&&!w(z(s,e))))&&t++}),t}},COUNTA:{min:1,max:255,fn:n=>{let e=0;return dt(n,t=>{t!==null&&e++}),e}},COUNTBLANK:{min:1,max:1,fn:n=>{let e=0;return dt(n,t=>{ko(t)&&e++}),e}},SUMPRODUCT:{min:1,max:255,fn:n=>{const e=n.map(ge),t=e[0];if(e.some(o=>o.rows!==t.rows||o.cols!==t.cols))return se("SUMPRODUCT: the ranges have different sizes");let s=0;for(let o=0;o<t.rows;o++)for(let i=0;i<t.cols;i++){let r=1;for(const l of e){const a=l.get(o,i);if(w(a))return a;r*=typeof a=="number"?a:G(a)?a.serial:0}s+=r}return W(s)}},ROUND:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:W(mi(t[0],t[1]))}},ROUNDUP:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:W(dr(t[0],t[1],!0))}},ROUNDDOWN:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:W(dr(t[0],t[1],!1))}},INT:xo(n=>Math.floor(xe(n))),ABS:xo(Math.abs),SQRT:xo(n=>n<0?we("SQRT of a negative number"):Math.sqrt(n)),MOD:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:t[1]===0?nt("MOD by zero"):W(t[0]-t[1]*Math.floor(xe(t[0]/t[1])))}},POWER:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);return w(t)?t:t[0]===0&&t[1]===0?we("0^0"):t[0]===0&&t[1]<0?nt("0 to a negative power"):W(Math.pow(t[0],t[1]))}},FLOOR:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;const[s,o]=t;return o===0?s===0?0:nt("FLOOR with significance 0"):s>0&&o<0?we("FLOOR: a positive number with a negative significance"):W(Math.floor(xe(s/o))*o)}},CEILING:{min:2,max:2,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;const[s,o]=t;return o===0?0:s>0&&o<0?we("CEILING: a positive number with a negative significance"):W(Math.ceil(xe(s/o))*o)}},RAND:{min:0,max:0,volatile:!0,fn:(n,e)=>e.random()},RANDBETWEEN:{min:2,max:2,volatile:!0,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;const s=Math.ceil(t[0]),o=Math.floor(t[1]);return s>o?we("RANDBETWEEN: bottom is greater than top"):s+Math.floor(e.random()*(o-s+1))}},SUMIF:{min:2,max:3,fn:(n,e)=>{let t=0;return lt([[n[0],n[1]]],n[2]!==void 0?ge(n[2]):void 0,e,o=>{if(w(o))return o;typeof o=="number"?t+=o:G(o)&&(t+=o.serial)})??W(t)}},SUMIFS:{min:3,max:255,fn:(n,e)=>{if((n.length-1)%2)return se("SUMIFS needs pairs of range and criterion");const t=[];for(let i=1;i<n.length;i+=2)t.push([n[i],n[i+1]]);let s=0;return lt(t,ge(n[0]),e,i=>{if(w(i))return i;typeof i=="number"?s+=i:G(i)&&(s+=i.serial)})??W(s)}},COUNTIF:{min:2,max:2,fn:(n,e)=>{let t=0;return lt([[n[0],n[1]]],void 0,e,()=>{t++})??t}},COUNTIFS:{min:2,max:254,fn:(n,e)=>{if(n.length%2)return se("COUNTIFS needs pairs of range and criterion");const t=[];for(let i=0;i<n.length;i+=2)t.push([n[i],n[i+1]]);let s=0;return lt(t,void 0,e,()=>{s++})??s}},AVERAGEIF:{min:2,max:3,fn:(n,e)=>{let t=0,s=0;return lt([[n[0],n[1]]],n[2]!==void 0?ge(n[2]):void 0,e,i=>{if(w(i))return i;(typeof i=="number"||G(i))&&(t+=typeof i=="number"?i:i.serial,s++)})??(s?W(t/s):nt("AVERAGEIF: no matching numbers"))}},AVERAGEIFS:{min:3,max:255,fn:(n,e)=>{if((n.length-1)%2)return se("AVERAGEIFS needs pairs of range and criterion");const t=[];for(let r=1;r<n.length;r+=2)t.push([n[r],n[r+1]]);let s=0,o=0;return lt(t,ge(n[0]),e,r=>{if(w(r))return r;(typeof r=="number"||G(r))&&(s+=typeof r=="number"?r:r.serial,o++)})??(o?W(s/o):nt("AVERAGEIFS: no matching numbers"))}},IF:{min:2,max:3,lazy:([n,e,t])=>{const s=ft(n());return w(s)?s:s?e():t?t():!1}},IFS:{min:2,max:254,lazy:n=>{if(n.length%2)return se("IFS needs pairs of condition and value");for(let e=0;e<n.length;e+=2){const t=ft(n[e]());if(w(t))return t;if(t)return n[e+1]()}return ht()}},IFERROR:{min:2,max:2,lazy:([n,e])=>{const t=_(n());return w(t)?e():t}},IFNA:{min:2,max:2,lazy:([n,e])=>{const t=_(n());return w(t)&&t.code==="#N/A"?e():t}},AND:{min:1,max:255,fn:n=>vo(n,e=>e.every(Boolean))},OR:{min:1,max:255,fn:n=>vo(n,e=>e.some(Boolean))},XOR:{min:1,max:255,fn:n=>vo(n,e=>e.filter(Boolean).length%2===1)},NOT:{min:1,max:1,fn:n=>{const e=ft(n[0]);return w(e)?e:!e}},SWITCH:{min:3,max:254,lazy:n=>{const e=_(n[0]());if(w(e))return e;const t=n.length-1;for(let s=1;s+1<n.length;s+=2){const o=_(n[s]());if(w(o))return o;if(hs(e,o)===0)return n[s+1]()}return t%2===1?n[n.length-1]():ht()}},VLOOKUP:{min:3,max:4,fn:(n,e)=>pr(n,e,!0)},HLOOKUP:{min:3,max:4,fn:(n,e)=>pr(n,e,!1)},XLOOKUP:{min:3,max:4,fn:n=>{const e=fr(n[1]);if(w(e))return e;const t=ge(n[2]),s=ge(n[1]).cols===1&&ge(n[1]).rows>1;if((s?t.rows:t.cols)!==e.length)return se("XLOOKUP: the result range must have the size of the lookup range");const o=Ho(e,$o(n[0],!1));return o<0?n.length>3?n[3]:ht():t.rows===1&&t.cols===1?t.get(0,0):s?t.cols===1?t.get(o,0):new tt(t.row+o,t.col,1,t.cols,(i,r)=>t.get(i-t.row,r-t.col)):t.rows===1?t.get(0,o):new tt(t.row,t.col+o,t.rows,1,(i,r)=>t.get(i-t.row,r-t.col))}},INDEX:{min:2,max:3,fn:(n,e)=>{const t=ge(n[0]),s=z(n[1],e);if(w(s))return s;let o=n.length>2?z(n[2],e):0;if(w(o))return o;let i=Math.trunc(s),r=Math.trunc(o);return n.length===2&&t.rows===1?(r=i,i=1):n.length===2&&t.cols===1&&(r=1),i<0||r<0||i>t.rows||r>t.cols?new I("#REF!","INDEX outside the range"):i===0&&r===0?t:i===0?new tt(t.row,t.col+r-1,t.rows,1,(l,a)=>t.get(l-t.row,a-t.col)):r===0?new tt(t.row+i-1,t.col,1,t.cols,(l,a)=>t.get(l-t.row,a-t.col)):t.get(i-1,r-1)}},MATCH:{min:2,max:3,fn:(n,e)=>{const t=fr(n[1]);if(w(t))return t;const s=n.length>2?z(n[2],e):1;if(w(s))return s;const o=_(n[0]);if(w(o))return o;let i;return s===0?i=Ho(t,$o(o,!0)):i=ul(t,o,s<0),i<0?ht():i+1}},CONCAT:{min:1,max:255,fn:n=>{let e="";return dt(n,s=>{const o=re(s);if(w(o))return o;e+=o})??e}},TEXTJOIN:{min:3,max:255,fn:n=>{const e=re(n[0]);if(w(e))return e;const t=ft(n[1]);if(w(t))return t;const s=[];return dt(n.slice(2),i=>{const r=re(i);if(w(r))return r;(!t||r!=="")&&s.push(r)})??s.join(e)}},LEFT:{min:1,max:2,fn:(n,e)=>mr(n,e,!0)},RIGHT:{min:1,max:2,fn:(n,e)=>mr(n,e,!1)},MID:{min:3,max:3,fn:(n,e)=>{const t=re(n[0]);if(w(t))return t;const s=ve(n.slice(1),e);if(w(s))return s;const[o,i]=[Math.trunc(s[0]),Math.trunc(s[1])];return o<1||i<0?se("MID: start must be ≥ 1 and the length ≥ 0"):t.substr(o-1,i)}},LEN:ps(n=>n.length),FIND:{min:2,max:3,fn:(n,e)=>br(n,e,!1)},SEARCH:{min:2,max:3,fn:(n,e)=>br(n,e,!0)},SUBSTITUTE:{min:3,max:4,fn:(n,e)=>{const t=re(n[0]);if(w(t))return t;const s=re(n[1]);if(w(s))return s;const o=re(n[2]);if(w(o))return o;if(s==="")return t;if(n.length<4)return t.split(s).join(o);const i=z(n[3],e);if(w(i))return i;if(i<1)return se("SUBSTITUTE: the instance must be ≥ 1");let r=-1;for(let l=0;l<Math.trunc(i);l++)if(r=t.indexOf(s,r+1),r<0)return t;return t.slice(0,r)+o+t.slice(r+s.length)}},UPPER:ps(n=>n.toUpperCase()),LOWER:ps(n=>n.toLowerCase()),TRIM:ps(n=>n.replace(/ +/g," ").trim()),VALUE:{min:1,max:1,fn:(n,e)=>{const t=_(n[0]);if(typeof t=="boolean")return se("VALUE of a boolean");if(typeof t=="string"){const o=vt(t.trim());if(o!==void 0)return o}const s=z(t,{isoDatesAsDates:e.isoDatesAsDates});return w(s)?s:W(s)}},TEXT:{min:2,max:2,fn:(n,e)=>{const t=re(n[1]);return w(t)?t:th(n[0],t,e)}},TODAY:{min:0,max:0,volatile:!0,fn:(n,e)=>new xt(Math.floor(e.now()))},NOW:{min:0,max:0,volatile:!0,fn:(n,e)=>new xt(e.now())},DATE:{min:3,max:3,fn:(n,e)=>{const t=ve(n,e);if(w(t))return t;let s=Math.trunc(t[0]);return s<0||s>9999?we("DATE: year out of range"):(s<1900&&(s+=1900),gr(Wt(s,Math.trunc(t[1]),1)+Math.trunc(t[2])-1))}},YEAR:{min:1,max:1,fn:(n,e)=>{const t=$e(n[0],e);return w(t)?t:et(t).y}},MONTH:{min:1,max:1,fn:(n,e)=>{const t=$e(n[0],e);return w(t)?t:et(t).m}},DAY:{min:1,max:1,fn:(n,e)=>{const t=$e(n[0],e);return w(t)?t:et(t).d}},WEEKDAY:{min:1,max:2,fn:(n,e)=>{const t=$e(n[0],e);if(w(t))return t;const s=n.length>1?z(n[1],e):1;if(w(s))return s;const o=Math.trunc(s),i=((Math.floor(t)-1)%7+7)%7,r=(i+6)%7;return o===1?i+1:o===2?r+1:o===3?r:o>=11&&o<=17?((r-(o-11))%7+7)%7+1:we("WEEKDAY: type must be 1, 2, 3 or 11–17")}},EOMONTH:{min:2,max:2,fn:(n,e)=>{const t=$e(n[0],e);if(w(t))return t;const s=z(n[1],e);if(w(s))return s;const{y:o,m:i}=et(t);return gr(Wt(o,i+Math.trunc(s)+1,0))}},DATEDIF:{min:3,max:3,fn:(n,e)=>{const t=$e(n[0],e);if(w(t))return t;const s=$e(n[1],e);if(w(s))return s;const o=re(n[2]);return w(o)?o:sh(t,s,o)}},ISBLANK:{min:1,max:1,acceptsErrors:!0,fn:n=>_(n[0])===null},ISNUMBER:{min:1,max:1,acceptsErrors:!0,fn:n=>{const e=_(n[0]);return typeof e=="number"||G(e)}},ISTEXT:{min:1,max:1,acceptsErrors:!0,fn:n=>typeof _(n[0])=="string"},ISERROR:{min:1,max:1,acceptsErrors:!0,fn:n=>w(_(n[0]))},ISNA:{min:1,max:1,acceptsErrors:!0,fn:n=>{const e=_(n[0]);return w(e)&&e.code==="#N/A"}},NA:{min:0,max:0,fn:()=>ht()}};function vo(n,e){const t=[],s=dt(n,(o,i)=>{if(w(o))return o;if(typeof o=="boolean")t.push(o);else if(typeof o=="number")t.push(o!==0);else if(G(o))t.push(o.serial!==0);else if(!i&&typeof o=="string"){const r=ft(o);if(w(r))return r;t.push(r)}});return s||(t.length?e(t):se("No logical values"))}function pr(n,e,t){const s=ge(n[1]),o=z(n[2],e);if(w(o))return o;const i=n.length>3?n[3]===null?!1:ft(n[3]):!0;if(w(i))return i;const r=Math.trunc(o);if(r<1)return se("The index must be ≥ 1");if(r>(t?s.cols:s.rows))return new I("#REF!","The index is beyond the table");const l=t?fl(s,0):gl(s,0),a=_(n[0]);if(w(a))return a;const c=i?ul(l,a):Ho(l,$o(a,!0));return c<0?ht():t?s.get(c,r-1):s.get(r-1,c)}function mr(n,e,t){const s=re(n[0]);if(w(s))return s;const o=n.length>1?z(n[1],e):1;if(w(o))return o;if(o<0)return se("The number of characters must be ≥ 0");const i=Math.trunc(o);return t?s.slice(0,i):i===0?"":s.slice(-i)}function br(n,e,t){const s=re(n[0]);if(w(s))return s;const o=re(n[1]);if(w(o))return o;const i=n.length>2?z(n[2],e):1;if(w(i))return i;const r=Math.trunc(i);if(r<1||r>o.length+1)return se("The start is outside the text");if(!t){const a=o.indexOf(s,r-1);return a<0?se(`"${s}" not found`):a+1}const l=ih(hl(s),o,r-1);return l<0?se(`"${s}" not found`):l+1}function ih(n,e,t){const s=n.concat({kind:"star"}),o=s.findIndex(h=>h.kind==="star"),i=s.slice(o);let r=t+o,l=e.length;if(r>l||!Bo(i,e,r))return-1;for(;r<l;){const h=Math.ceil((r+l)/2);Bo(i,e,h)?r=h:l=h-1}const a=r,c=e.toLowerCase();for(let h=t;h+o<=a;h++){let d=0;for(;d<o;){const u=s[d];if(u.kind==="char"&&u.ch!==c[h+d])break;d++}if(d===o)return h}return-1}const rh=new Set(["#ERROR!","#NAME?","#VALUE!","#DIV/0!","#NUM!","#CIRC!","#REF!","#N/A"]),nh=new Set(["SUM","AVERAGE","AVG","MIN","MAX","COUNT"]);function Re(n,e){return n*q+e}function lh(n){return n.replace(/^\s*=/,"")}function wr(n,e,t){let s;try{s=cs(lh(n),!0)}catch(o){const i=o instanceof B?o.toFormulaError():new I("#ERROR!","Invalid formula");return{evaluate:()=>i,singles:[],ranges:[],volatile:!1,error:i}}return new ah(t,e).compile(s)}class ah{constructor(e,t){this.env=e,this.row=t,this.singles=new Set,this.ranges=[],this.volatile=!1}compile(e){const t=this.node(e);return{evaluate:()=>{try{const o=t(),i=Ye(o)?_(o):o;return i===null?0:typeof i=="number"?W(i):i}catch(o){return new I("#VALUE!",o instanceof Error?o.message.slice(0,200):"Evaluation failed")}},singles:Array.from(this.singles),ranges:this.ranges,volatile:this.volatile}}ref(e,t){this.singles.add(Re(e,t));const s=this.env;return()=>s.read(e,t)}node(e){switch(e.kind){case"literal":{const t=e.value;return()=>t}case"ref":return e.row<0||e.col<0||e.row>=ie||e.col>=q?this.fail("#REF!","Invalid reference"):this.ref(e.row,e.col);case"range":return this.range(e.from,e.to);case"field":{const t=this.env.fieldColumn(e.name);return t<0?this.fail("#NAME?",`[${e.name}] is no column of the sheet`):this.ref(this.row,t)}case"error":{const t=rh.has(e.code)?e.code:"#ERROR!";return this.fail(t,e.message??(t==="#REF!"?"A reference to a deleted cell":e.code))}case"unary":{const t=this.node(e.operand),s=this.env;return e.op==="%"?()=>{const o=z(t(),s.fn);return w(o)?o:W(o/100)}:e.op==="+"?()=>_(t()):()=>{const o=_(t()),i=z(o,s.fn);return w(i)?i:W(-i)}}case"binary":return this.binary(e.op,this.node(e.left),this.node(e.right));case"call":return this.call(e.name,e.args)}}fail(e,t){const s=new I(e,t);return()=>s}range(e,t){const s=e.row<0?0:e.row,o=t.row<0?ie-1:t.row,i=e.col<0?0:e.col,r=t.col<0?q-1:t.col;if(s>o||i>r||o>=ie||r>=q)return this.fail("#REF!","Invalid range");this.ranges.push({r1:s,c1:i,r2:o,c2:r});const l=this.env,a=r-i+1;return()=>{const c=Math.max(0,Math.min(o,l.rowCount()-1)-s+1);return c*a>l.maxRangeCells?new I("#ERROR!",`The range has more than ${l.maxRangeCells} cells`):new tt(s,i,c,a,l.read)}}binary(e,t,s){const o=this.env;return e==="&"?()=>{const i=re(t());if(w(i))return i;const r=re(s());return w(r)?r:i+r}:e==="="||e==="<>"||e==="<"||e==="<="||e===">"||e===">="?()=>{const i=hs(t(),s());if(w(i))return i;switch(e){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 i=_(t());if(w(i))return i;const r=_(s());if(w(r))return r;const l=z(i,o.fn);if(w(l))return l;const a=z(r,o.fn);if(w(a))return a;switch(e){case"+":case"-":{const c=e==="+"?l+a:l-a,h=G(i)||o.fn.isoDatesAsDates&&typeof i=="string"&&vt(i.trim())!==void 0,d=G(r)||o.fn.isoDatesAsDates&&typeof r=="string"&&vt(r.trim())!==void 0;if(h&&!d||e==="+"&&d&&!h){const u=W(c);return w(u)?u:new xt(u)}return W(c)}case"*":return W(l*a);case"/":return a===0?new I("#DIV/0!","Division by zero"):W(l/a);default:return l===0&&a===0?new I("#NUM!","0^0"):l===0&&a<0?new I("#DIV/0!","0 to a negative power"):W(Math.pow(l,a))}}}call(e,t){if(nh.has(e)&&t.length===1&&t[0].kind==="field"){const c=t[0].name;return this.fail("#NAME?",`${e}([${c}]) is a column formula – in a cell use a range, e.g. ${e}(D:D)`)}const s=this.env.functions.get(e);if(s){const c=t.map(h=>this.node(h));return()=>{const h=[];for(const d of c){const u=d();if(w(u))return u;h.push(G(u)?u.serial:u)}try{return hh(s(...h),e)}catch(d){return new I("#VALUE!",`${e}: ${d instanceof Error?d.message.slice(0,200):"failed"}`)}}}const o=oh[e];if(!o)return this.fail("#NAME?",`Unknown function ${e}`);if(t.length<o.min||t.length>o.max){const c=o.min===o.max?`${o.min}`:o.max>=254?`at least ${o.min}`:`${o.min} to ${o.max}`;return this.fail("#ERROR!",`${e} needs ${c} argument${o.max===1?"":"s"}, got ${t.length}`)}o.volatile&&(this.volatile=!0),(e==="SUMIF"||e==="AVERAGEIF")&&t.length===3&&(t=[t[0],t[1],ch(t[2],t[0])]);const i=t.map(c=>this.node(c)),r=this.env.fn;if(o.lazy){const c=o.lazy;return()=>c(i,r)}const l=o.fn,a=!!o.acceptsErrors;return()=>{const c=new Array(i.length);for(let h=0;h<i.length;h++){const d=i[h]();if(!a&&w(d))return d;c[h]=d}return l(c,r)}}}function ch(n,e){const t=n.kind==="range"?n.from:n.kind==="ref"?n:void 0;if(!t||e.kind!=="range"||t.row<0||t.col<0)return n;const s=e.to.row-e.from.row,o=e.to.col-e.from.col;return e.from.row<0||e.from.col<0?e.from.row<0?{kind:"range",from:{...t,row:-1},to:{...t,row:-1,col:t.col+o}}:{kind:"range",from:{...t,col:-1},to:{...t,col:-1,row:t.row+s}}:{kind:"range",from:t,to:{...t,row:t.row+s,col:t.col+o}}}function hh(n,e){if(n===void 0)return null;if(typeof n=="number")return Number.isNaN(n)?new I("#NUM!",`${e} returned NaN`):n;if(Ye(n))return n;const t=sn(n);return w(t)&&!w(n)?new I("#VALUE!",`${e} returned no number, text or boolean`):t}function Ht(n,e){switch(n.kind){case"unary":return{...n,operand:Ht(n.operand,e)};case"binary":return{...n,left:Ht(n.left,e),right:Ht(n.right,e)};case"call":return{...n,args:n.args.map(t=>Ht(t,e))};case"ref":case"range":return e(n)??n;default:return n}}function Go(n,e,t=!1){let s;try{s=cs(n,!0)}catch{return n}let o=!1;const i=Ht(s,r=>{const l=e(r);return l&&Gt(l)!==Gt(r)&&(o=!0),l});return t&&!o?n:Gt(i)}const ks={kind:"error",code:"#REF!"};function dh(n,e){return n<ie&&e<q&&n>=-1&&e>=-1}function Ro(n,e,t,s){const o=n.row<0||n.absRow&&!s?n.row:n.row+e,i=n.col<0||n.absCol&&!s?n.col:n.col+t;if(!(n.row>=0&&o<0||n.col>=0&&i<0||!dh(o,i)))return{...n,row:o,col:i}}function pl(n,e,t,s){return Go(n,o=>{if(o.kind==="ref")return Ro(o,e,t,s)??ks;if(o.kind==="range"){const i=Ro(o.from,e,t,s),r=Ro(o.to,e,t,s);return i&&r?{kind:"range",from:i,to:r}:ks}})}function ml(n,e,t){return pl(n,e,t,!1)}function uh(n,e,t){return pl(n,e,t,!0)}function fh(n,e,t,s){return{point(o){if(o<0)return o;if(t)return o<n?o:o+e<s?o+e:void 0;if(!(o>=n&&o<n+e))return o>=n+e?o-e:o},span(o,i){if(o<0)return[o,i];if(t){const c=o>=n?o+e:o;return c>=s?void 0:[c,Math.min(i>=n?i+e:i,s-1)]}const r=n+e-1;if(o>=n&&i<=r)return;const l=o<n?o:o>r?o-e:n,a=i<n?i:i>r?i-e:n-1;return[l,a]}}}function bl(n,e){if(e.kind==="moveCells"){const{from:o,to:i}=e,r=i[0]-o.r1,l=i[1]-o.c1,a=c=>c.row>=o.r1&&c.row<=o.r2&&c.col>=o.c1&&c.col<=o.c2;return Go(n,c=>{if(c.kind==="ref"&&a(c))return{...c,row:c.row+r,col:c.col+l};if(c.kind==="range"&&c.from.row>=0&&c.from.col>=0&&a(c.from)&&a(c.to))return{kind:"range",from:{...c.from,row:c.from.row+r,col:c.from.col+l},to:{...c.to,row:c.to.row+r,col:c.to.col+l}}},!0)}const t=e.kind==="insertRows"||e.kind==="deleteRows",s=fh(e.at,e.count,e.kind==="insertRows"||e.kind==="insertColumns",t?ie:q);return Go(n,o=>{if(o.kind==="ref"){const i=s.point(t?o.row:o.col);return i===void 0?ks:t?{...o,row:i}:{...o,col:i}}if(o.kind==="range"){const i=t?s.span(o.from.row,o.to.row):s.span(o.from.col,o.to.col);return i?t?{kind:"range",from:{...o.from,row:i[0]},to:{...o.to,row:i[1]}}:{kind:"range",from:{...o.from,col:i[0]},to:{...o.to,col:i[1]}}:ks}},!0)}class Tt{constructor(){this.functions={},this.isoDatesAsDates=!0,this.maxRangeCells=1e7,this.rejectInvalidFormulas=!1,this.columns=void 0}static create(e){if(!e)return;const t=new Tt;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&s in t&&(t[s]=o);return t}}const yr=64;function wt(n){return typeof n=="string"&&n.length>1&&n[0]==="="}class ao{constructor(e,t={}){this.source=e,this.formulas=new Map,this.singleDependents=new Map,this.rangeNodes=new Map,this.rangesByColumn=new Map,this.wideRanges=[],this.volatileCells=new Set,this.formulaColumns=new Map,this.fieldColumns=new Map,this.options=Tt.create(t)??new Tt;const s=new Map;for(const[l,a]of Object.entries(this.options.functions??{}))typeof a=="function"&&s.set(l.toUpperCase(),a);const o=t.now??(()=>new Date),i=t.random??Math.random,r=this.options.isoDatesAsDates;this.env={read:(l,a)=>this.read(l,a),rowCount:()=>this.source.getRowCount(),fieldColumn:l=>this.fieldColumn(l),functions:s,maxRangeCells:this.options.maxRangeCells,fn:{isoDatesAsDates:r,now:()=>Lt(o()),random:i}}}static fromArrays(e,t){const s=new ao({getRowCount:()=>e.length,getColumnCount:()=>e.reduce((o,i)=>Math.max(o,(i==null?void 0:i.length)??0),0),getInput:(o,i)=>{var r;return(r=e[o])==null?void 0:r[i]}},t);return s.rebuild(),s}rebuild(){this.formulas.clear(),this.singleDependents.clear(),this.rangeNodes.clear(),this.rangesByColumn.clear(),this.wideRanges.length=0,this.volatileCells.clear(),this.fieldColumns.clear(),this.formulaColumns.clear();const e=Math.min(this.source.getRowCount(),ie),t=Math.min(this.source.getColumnCount(),q),s=[],o=this.source;if(o.forEachInput)return o.forEachInput((i,r,l)=>{i<e&&r<t&&wt(l)&&(!o.isFormulaColumn||o.isFormulaColumn(r))&&(this.add(i,r,l,null),s.push(Re(i,r)))}),this.recalc(s,!0);for(let i=0;i<t;i++)if(!(o.isFormulaColumn&&!o.isFormulaColumn(i)))for(let r=0;r<e;r++){const l=o.getInput(r,i);wt(l)&&(this.add(r,i,l,null),s.push(Re(r,i)))}return this.recalc(s,!0)}inputsChanged(e){const t=[];for(const[s,o]of e){const i=Re(s,o),r=this.formulas.get(i),l=this.source.getInput(s,o),a=wt(l)&&(!this.source.isFormulaColumn||this.source.isFormulaColumn(o));if(r&&a&&r.source===l){t.push(i);continue}r&&this.remove(r),a&&this.add(s,o,l,r?r.value:this.dataValue(s,o)),t.push(i)}return this.volatileCells.forEach(s=>t.push(s)),this.recalc(t,!1)}recalculate(){return this.recalc(Array.from(this.volatileCells),!1)}getValue(e,t){return ji(this.read(e,t))}isFormula(e,t){return this.formulas.has(Re(e,t))}getFormulaCount(){return this.formulas.size}evaluate(e,t){const s=e.trim().startsWith("=")?e:`=${e}`;return ji(wr(s,(t==null?void 0:t[0])??0,this.env).evaluate())}getPrecedents(e,t){const s=this.formulas.get(Re(e,t));if(!s)return[];const o=s.compiled.singles.map(i=>M.singleCell(Math.floor(i/q),i%q));for(const i of s.compiled.ranges)o.push(new M(i.r1,i.c1,i.r2,i.c2));return o}getDependents(e,t){const s=new Set;return this.forEachDependent(Re(e,t),e,t,o=>s.add(o)),Array.from(s,o=>[Math.floor(o/q),o%q])}adjustForStructureChange(e){const t=[];for(const s of Array.from(this.formulas.values())){const o=gh(s.row,s.col,e);if(!o)continue;const i="="+bl(s.source.slice(1),e);i!==s.source&&t.push({row:o[0],col:o[1],input:i})}return t}read(e,t){if(this.formulaColumns.has(t)){const s=this.formulas.get(Re(e,t));if(s)return s.value}return this.dataValue(e,t)}dataValue(e,t){if(e>=this.source.getRowCount())return null;const s=this.source.getInput(e,t);return s===""?null:typeof s=="string"&&s.startsWith("'=")?s.slice(1):sn(s)}fieldColumn(e){var s,o;let t=this.fieldColumns.get(e);return t===void 0&&(t=((o=(s=this.source).getFieldColumn)==null?void 0:o.call(s,e))??-1,this.fieldColumns.set(e,t)),t}add(e,t,s,o){const i=Re(e,t),r=wr(s,e,this.env),l={row:e,col:t,source:s,compiled:r,value:o,rangeKeys:[]};this.formulas.set(i,l),this.formulaColumns.set(t,(this.formulaColumns.get(t)??0)+1);for(const a of r.singles){let c=this.singleDependents.get(a);c||(c=new Set,this.singleDependents.set(a,c)),c.add(i)}for(const a of r.ranges){const c=`${a.r1}:${a.c1}:${a.r2}:${a.c2}`;let h=this.rangeNodes.get(c);if(!h)if(h={...a,key:c,dependents:new Set},this.rangeNodes.set(c,h),a.c2-a.c1+1>yr)this.wideRanges.push(h);else for(let d=a.c1;d<=a.c2;d++){let u=this.rangesByColumn.get(d);u||(u=[],this.rangesByColumn.set(d,u)),ph(u,h)}h.dependents.add(i),l.rangeKeys.push(c)}r.volatile&&this.volatileCells.add(i)}remove(e){const t=Re(e.row,e.col);this.formulas.delete(t);const s=this.formulaColumns.get(e.col)-1;s?this.formulaColumns.set(e.col,s):this.formulaColumns.delete(e.col),this.volatileCells.delete(t);for(const o of e.compiled.singles){const i=this.singleDependents.get(o);i==null||i.delete(t),i&&!i.size&&this.singleDependents.delete(o)}for(const o of e.rangeKeys){const i=this.rangeNodes.get(o);if(i&&(i.dependents.delete(t),!i.dependents.size))if(this.rangeNodes.delete(o),i.c2-i.c1+1>yr)this.wideRanges.splice(this.wideRanges.indexOf(i),1);else for(let r=i.c1;r<=i.c2;r++){const l=this.rangesByColumn.get(r);l.splice(l.indexOf(i),1),l.length||this.rangesByColumn.delete(r)}}}forEachDependent(e,t,s,o){const i=this.singleDependents.get(e);i&&i.forEach(o);const r=this.rangesByColumn.get(s);if(r)for(const l of r){if(l.r2<t)break;t>=l.r1&&l.dependents.forEach(o)}for(const l of this.wideRanges)t>=l.r1&&t<=l.r2&&s>=l.c1&&s<=l.c2&&l.dependents.forEach(o)}dependentsOfKey(e,t){this.forEachDependent(e,Math.floor(e/q),e%q,t)}recalc(e,t){const s=new Map,o=f=>{let g=s.get(f);if(!g){const p=[];this.dependentsOfKey(f,m=>p.push(m)),s.set(f,g=p)}return g},i=new Set,r=new Set(e),l=[...e];for(let f=0;f<l.length;f++){const g=l[f];if(this.formulas.has(g)&&i.add(g),!t)for(const p of o(g))r.has(p)||(r.add(p),l.push(p))}const a=[];let c=0;const h=f=>{const g=this.formulas.get(f),p=g.value;g.value=g.compiled.evaluate(),c++,Cr(p,g.value)||a.push([g.row,g.col])},d=new Set,u=f=>{const g=new Map;f.forEach(m=>g.set(m,0)),f.forEach(m=>{for(const b of o(m))f.has(b)&&g.set(b,g.get(b)+1)});const p=[];g.forEach((m,b)=>{m===0&&p.push(b)});for(let m=0;m<p.length;m++){const b=p[m];h(b),d.add(b);for(const y of o(b)){if(!f.has(y)||d.has(y))continue;const C=g.get(y)-1;g.set(y,C),C===0&&p.push(y)}}};if(u(i),d.size<i.size){const f=new Set(Array.from(i).filter(p=>!d.has(p))),g=new I("#CIRC!","Circular reference");for(const p of this.cycles(f,o)){const m=this.formulas.get(p),b=m.value;m.value=g,c++,Cr(b,g)||a.push([m.row,m.col]),d.add(p),f.delete(p)}u(f)}return{changedCells:a,evaluated:c}}cycles(e,t){const s=new Map,o=new Map,i=new Set,r=[],l=[];let a=0;const c=h=>t(h).filter(d=>e.has(d));for(const h of Array.from(e)){if(s.has(h))continue;const d=[],u=f=>{s.set(f,a),o.set(f,a),a++,r.push(f),i.add(f),d.push({k:f,next:c(f),i:0})};for(u(h);d.length;){const f=d[d.length-1];if(f.i<f.next.length){const g=f.next[f.i++];s.has(g)?i.has(g)&&o.set(f.k,Math.min(o.get(f.k),s.get(g))):u(g);continue}if(d.pop(),d.length){const g=d[d.length-1].k;o.set(g,Math.min(o.get(g),o.get(f.k)))}if(o.get(f.k)===s.get(f.k)){const g=[];let p;do p=r.pop(),i.delete(p),g.push(p);while(p!==f.k);(g.length>1||f.next.includes(f.k))&&l.push(...g)}}}return l}}function Cr(n,e){return Object.is(n,e)?!0:w(n)&&w(e)?n.code===e.code&&n.message===e.message:G(n)&&G(e)?n.serial===e.serial:!1}function gh(n,e,t){switch(t.kind){case"insertRows":return[n>=t.at?n+t.count:n,e];case"deleteRows":return n>=t.at&&n<t.at+t.count?void 0:[n>=t.at+t.count?n-t.count:n,e];case"insertColumns":return[n,e>=t.at?e+t.count:e];case"deleteColumns":return e>=t.at&&e<t.at+t.count?void 0:[n,e>=t.at+t.count?e-t.count:e];case"moveCells":{const{from:s,to:o}=t;return n>=s.r1&&n<=s.r2&&e>=s.c1&&e<=s.c2?[n+o[0]-s.r1,e+o[1]-s.c1]:[n,e]}}}function ph(n,e){let t=0,s=n.length;for(;t<s;){const o=t+s>>1;n[o].r2>=e.r2?t=o+1:s=o}n.splice(t,0,e)}class zt{constructor(e,t,s,o){this.input=e,this.row=t,this.col=s,this.value=o}}class co{constructor(e,t,s){this.tableModel=e,this.body=t,this.options=s,this.dataColumns=[],this.engineColumns=new Map,this.properties=[],this.propertyColumns=new Map,this.formulaColumns=[],this.calculatedColumns=[],this.rowIndex=new Map,this.rowsLength=-1,this.columnCount=-1,this.syncing=!1;const o=t instanceof Ne?t:void 0;this.sheetBody=o,this.engine=new ao({getRowCount:()=>this.rowCountOf(),getColumnCount:()=>this.dataColumns.length,getInput:(i,r)=>this.readInput(i,r),isFormulaColumn:i=>this.formulaColumns[i],getFieldColumn:i=>this.propertyColumns.get(i)??-1,...o?{forEachInput:i=>o.forEachCell(i)}:{}},s)}static create(e,t){const s=e.getBodyModel();if(!(s instanceof K)&&!(s instanceof Q)&&!(s instanceof Ne)){console.warn("GuiExpert Table – cellFormulas: only a flat body (an object array or an array of arrays) has cell formulas; a tree, a row grouping or a pivot table has none.");return}const o=new co(e,s,t);return o.sync(),s.sheetCells=o,o}destroy(){this.body.sheetCells===this&&(this.body.sheetCells=void 0)}valueAt(e,t,s){return this.valueOf(e,this.columnOf(t),s)}valueOfProperty(e,t,s){return this.valueOf(e,this.propertyColumns.get(t),s)}isFormulaProperty(e){const t=this.propertyColumns.get(e);return t!==void 0&&this.formulaColumns[t]}isFormulaColumnIndex(e){const t=this.columnOf(e);return t!==void 0&&this.formulaColumns[t]}isFormulaInput(e,t){return wt(t)&&this.isFormulaColumnIndex(e)}syntaxError(e){try{cs(e.slice(1),!0);return}catch(t){return t instanceof Error?t.message:String(t)}}cellsWritten(e){if(this.sync())return;const t=[],s=new Set;for(const o of e){const i=this.columnOf(o.columnIndex),r=o.row!==void 0&&o.row!==null&&typeof o.row=="object"?this.physicalOfRow(o.row):this.physicalRow(o.rowIndex);i!==void 0&&r!==void 0&&t.push([r,i]),r!==void 0&&s.add(r)}s.forEach(o=>{for(const i of this.calculatedColumns)t.push([o,i])}),t.length&&this.engine.inputsChanged(t)}recalculate(){this.sync()||this.engine.rebuild()}cellValue(e,t){return this.sync(),this.engine.getValue(e,t)}evaluate(e){return this.sync(),this.engine.evaluate(e)}inputAt(e,t){return this.readInput(e,t)}writeInput(e,t,s){if(this.sheetBody){const l=typeof e=="number"?e:this.sheetBody.getPhysicalRowOfArray(e);l!==void 0&&this.sheetBody.setCell(l,t,s);return}const o=typeof e=="number"?this.rows()[e]:e;if(o==null)return;if(!(this.body instanceof K)){o[this.dataColumns[t]]=s;return}const i=this.properties[t].split(".");let r=o;for(let l=0;l<i.length-1;l++){if(r[i[l]]===null||r[i[l]]===void 0)return;r=r[i[l]]}r[i[i.length-1]]=s}rowsArray(){return this.sheetBody?void 0:this.rows()}rowCount(){return this.sync(),this.rowCountOf()}physicalRow(e){if(this.sync(),!(e<0||e>=this.body.getRowCount()))return this.sheetBody?this.sheetBody.getPhysicalRowIndex(e):this.rowIndex.get(this.body.getRowByIndex(e))}displayRow(e){if(this.sync(),this.sheetBody)return this.sheetBody.getDisplayRowIndex(e);const t=this.rows()[e];if(t===void 0)return-1;const s=this.body.getRowCount();if(e<s&&this.body.getRowByIndex(e)===t)return e;for(let o=0;o<s;o++)if(this.body.getRowByIndex(o)===t)return o;return-1}engineColumn(e){return this.sync(),this.columnOf(e)}modelColumn(e){var o;if(this.sync(),!(this.body instanceof K))return this.dataColumns[e]??-1;const t=this.properties[e];if(t===void 0)return-1;const s=this.tableModel.getColumnCount();for(let i=0;i<s;i++)if(((o=this.tableModel.getColumnDef(i))==null?void 0:o.property)===t&&this.columnOf(i)===e)return i;return-1}address(e,t){const s=this.physicalRow(e),o=this.columnOf(t);return s===void 0||o===void 0?void 0:mt(s,o)}cellOfAddress(e){const t=Ue(e);if(!t)return;const s=this.modelColumn(t.col);if(!(s<0||t.row>=this.rowCountOf()))return[this.displayRow(t.row),s]}moveFormula(e,t,s,o,i){const r=this.physicalRow(o),l=this.columnOf(i);if(!(r===void 0||l===void 0||!this.formulaColumns[l]))return"="+ml(e.slice(1),r-t,l-s)}copyOf(e,t,s,o){if(typeof s=="string"&&s.startsWith("'=")&&this.isFormulaColumnIndex(t))return s;if(!this.isFormulaInput(t,s))return o;const i=this.physicalRow(e),r=this.columnOf(t);return i===void 0?o:new zt(s,i,r,o)}precedents(e,t){const s=this.physicalRow(e),o=this.columnOf(t);return s===void 0||o===void 0?[]:this.engine.getPrecedents(s,o).map(i=>{if(i.r1===0&&i.r2>=ie-1)return`${Pe(i.c1)}:${Pe(i.c2)}`;if(i.c1===0&&i.c2>=q-1)return`${i.r1+1}:${i.r2+1}`;const r=mt(i.r1,i.c1);return i.r1===i.r2&&i.c1===i.c2?r:`${r}:${mt(i.r2,i.c2)}`})}dependents(e,t){const s=this.physicalRow(e),o=this.columnOf(t);if(s===void 0||o===void 0)return[];const i=this.engine.getDependents(s,o);if(!i.length)return[];if(this.sheetBody)return i.map(([d,u])=>[this.sheetBody.getDisplayRowIndex(d),this.modelColumn(u)]).filter(([d,u])=>d>=0&&u>=0);const r=new Map,l=this.body.getRowCount();for(let d=0;d<l;d++)r.set(this.body.getRowByIndex(d),d);const a=new Map,c=this.rows(),h=[];for(const[d,u]of i){let f=a.get(u);f===void 0&&a.set(u,f=this.modelColumn(u));const g=r.get(c[d]);g!==void 0&&f>=0&&h.push([g,f])}return h}allowsColumnDrag(){return this.body instanceof K}columnOf(e){if(!(this.body instanceof K))return this.engineColumns.get(e);const t=this.tableModel.getColumnDef(e);if(!(!t||O(t)||me(t)))return this.propertyColumns.get(t.property)}valueOf(e,t,s){if(t===void 0||!this.formulaColumns[t])return s;if(s.startsWith("'="))return s.slice(1);if(!wt(s)||this.syncing)return s;this.sync();const o=this.physicalOfRow(e);return o===void 0?s:this.engine.getValue(o,t)}physicalOfRow(e){return this.sheetBody?this.sheetBody.getPhysicalRowOfArray(e):this.rowIndex.get(e)}rowCountOf(){return this.sheetBody?this.sheetBody.getUnfilteredRowCount():this.rows().length}rows(){return this.body instanceof K?this.body.getAllRows():this.body instanceof Q?this.body.arr:[]}readInput(e,t){if(this.sheetBody)return this.sheetBody.getCell(e,t);const s=this.rows()[e];if(s==null)return;if(!(this.body instanceof K))return s[this.dataColumns[t]];const o=this.properties[t];if(this.body.isCalculatedProperty(o)&&!this.formulaColumns[t])return this.body.getRowValue(s,o);let i=s;for(const r of o.split(".")){if(i==null)return;i=i[r]}return i}sync(){var i,r;if(this.syncing)return!1;const e=this.sheetBody?this.sheetBody.version:this.rows(),t=this.rowCountOf(),s=((r=(i=this.tableModel).getColumnDefs)==null?void 0:r.call(i))??[],o=this.tableModel.getColumnCount();if(e===this.rowsRef&&t===this.rowsLength&&s===this.columnDefsRef&&o===this.columnCount)return!1;this.syncing=!0;try{(s!==this.columnDefsRef||o!==this.columnCount)&&this.buildColumns(s,o),this.rowsRef=e,this.rowsLength=t,this.rowIndex=new Map;const l=this.rows();for(let a=l.length-1;a>=0;a--)this.rowIndex.set(l[a],a);this.engine.rebuild()}finally{this.syncing=!1}return!0}buildColumns(e,t){this.columnDefsRef=e,this.columnCount=t,this.dataColumns=[],this.properties=[],this.formulaColumns=[],this.calculatedColumns=[],this.engineColumns.clear(),this.propertyColumns.clear();const s=this.options.columns;for(let o=0;o<t;o++){const i=e[o]??this.tableModel.getColumnDef(o);if(O(i)||me(i))continue;const r=this.dataColumns.length,l=(i==null?void 0:i.property)??"";this.dataColumns.push(o),this.properties.push(l),this.engineColumns.set(o,r),l&&!this.propertyColumns.has(l)&&this.propertyColumns.set(l,r);const a=!!(i!=null&&i.valueGetter);a&&this.calculatedColumns.push(r),this.formulaColumns.push(!a&&(i==null?void 0:i.cellFormulas)!==!1&&(!s||s.includes(l)))}}}function wl(n){const e=n.map(s=>s.map(mh).join(" ")).join(`
|
|
65
65
|
`),t=n[n.length-1];return t&&t.every(s=>s==="")?e+`
|
|
66
66
|
`:e}function mh(n){return/[\t\n\r"]/.test(n)?`"${n.replace(/"/g,'""')}"`:n}function yl(n){if(n.charCodeAt(0)===65279&&(n=n.slice(1)),n==="")return[];const e=[];let t=[],s=0;const o=n.length;let i=!1;for(;s<=o;){let l="";if(n[s]==='"'){for(s++;!(s>=o);){const c=n[s];if(c==='"'){if(n[s+1]==='"'){l+='"',s+=2;continue}s++;break}l+=c,s++}for(;s<o&&n[s]!==" "&&n[s]!==`
|
|
67
67
|
`&&n[s]!=="\r";)l+=n[s++]}else{const c=s;for(;s<o&&n[s]!==" "&&n[s]!==`
|
|
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 Cl(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 Sl(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
|
-
`));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 xl(n){const{matrix:e,anchorRow:t,shownColumns:s,rowCount:o}=n,i=e.length,r=e.reduce((C,S)=>Math.max(C,S.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}=Ti(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 S=t+C,E=e[C%i];for(let x=0;x<u;x++){const R=s[l+x];if(S<o&&n.isWritable&&!n.isWritable(S,R)){y++;continue}const
|
|
71
|
-
`).replace(/\n$/,"");class Wo{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?yl(e):t?Sl(t):[];if(!i.length||!i[0].length)return[];const r=this.memory&&e&&Sr(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,P)=>H.map((ue,te)=>{var F;return((F=r.values[P])==null?void 0:F[te])instanceof zt?r.values[P][te]:ue})):i,S=!!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},P=E(H);if(P===!1)return[];Array.isArray(P)&&(C=P,S=!1)}const x=this.options.maxPasteCells,R=Ti(C.length,C.reduce((H,P)=>Math.max(H,P.length),0),g);if(R.rows*R.columns>x)return o.announce(o.getSheetTexts().pasteTooLarge(x)),[];const L=this.options.pasteAddsRows&&!!this.options.createRow&&!y&&this.canAppendRows(),v=((_e=(j=o.tableModel).getColumnDefs)==null?void 0:_e.call(j))??[],D=xl({matrix:C,anchorRow:u,anchorColumn:f,shownColumns:h,rowCount:c,selection:g,canAddRows:L,isWritable:(H,P)=>a.isEditable(H,P)&&!O(v[P])});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 N="paste";if(l){N="cut";const H=new Map(h.map((te,F)=>[te,F])),P=[],ue=new Set;for(const{rowIndex:te,columnIndex:F,value:Y}of D.cells){const Ot=S?Y:this.convertPastedText(Y,te,F);o.checkPastedValue(te,F,Ot,S)||(k.push({rowIndex:te,column:F,value:Ot}),P.push([te-u,H.get(F)-m]),ue.add(`${te}:${F}`))}for(const te of this.cutSourceChanges(l,P,ue))k.push(te)}else for(const{rowIndex:H,columnIndex:P,value:ue}of D.cells)k.push({rowIndex:H,column:P,value:S?ue:this.convertPastedText(ue,H,P)});const V=k.length?o.writePastedCells(k,N,S):[];l&&(this.memory=void 0,this.removeCutFrame()),D.addRows&&o.repaintHard();let $=V.length;if(l){const H=new Set(D.cells.map(P=>`${P.rowIndex}:${P.columnIndex}`));$=V.filter(P=>H.has(`${P.rowIndex}:${P.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&&(xr(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="",xr(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:Sr(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 x=l.getRanges(),R=x[x.length-1];c=x.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 x=t.getActiveBodyCell();a=x?M.singleCell(x[0],x[1]):void 0}if(!a||a.r2<a.r1||a.c2<a.c1)return;const h=[];for(let x=a.c1;x<=a.c2;x++){const R=s.getColumnDef(x);((E=R==null?void 0:R.isVisible)==null?void 0:E.call(R))===!1||s.getColumnWidth(x)<=0||O(R)&&!R.options.exported||h.push(x)}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 x=h.map(R=>t.getColumnAriaLabel(R));g.push(x),p.push(x),m.push(x.map(R=>({text:R})))}for(let x=a.r1;x<=a.r2;x++){const R=[],L=[],v=[];for(const D of h){const k=s.getColumnDef(D);let N,V;if(f&&!l.isSelected(x,D))N="",V="";else if(O(k))N=k.getRowNumberText(x,o),V=N;else{V=t.getCopyValue(x,D);const j=V instanceof zt?V.value:V;N=u||j===null||j===void 0||j instanceof Date?bh(j):o.getTextValueAt(x,D)}R.push(N),L.push(V);const $=V instanceof zt?V.value:V;v.push(typeof $=="number"?{text:N,num:$}:{text:N})}g.push(R),p.push(L),m.push(v)}let b=g,y=!1;if(this.options.processCopy){const x=this.options.processCopy({ranges:[a],matrix:g,cut:e});Array.isArray(x)&&(b=x,y=!0)}const C=wl(b),S=this.options.html?Cl(y?b.map(x=>x.map(R=>({text:R}))):m):void 0;return{text:C,html:S,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&&!O(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}`)||O(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 xr(n){return n.getRootNode().activeElement??null}function bh(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 vl(n){return n?{"meta+z":"UNDO","meta+shift+z":"REDO"}:{"ctrl+z":"UNDO","ctrl+y":"REDO","ctrl+shift+z":"REDO"}}class ho{constructor(){this.maxSteps=100,this.maxCells=1e6,this.onConflict="skip",this.recordApiChanges=!1}static create(e){if(!e)return;const t=new ho;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class Rl{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 Al(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 wh(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=Al(n);return e?new Set(e):null}class Uo{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=S=>{const E=o.getRowByIndex(S);return U(E)?E.data:E};let a,c;const h=S=>{if(S.row===void 0||S.row===null||typeof S.row!="object")return S.rowIndex>=0&&S.rowIndex<i?S.rowIndex:-1;if(S.rowIndex>=0&&S.rowIndex<i&&l(S.rowIndex)===S.row)return S.rowIndex;if(!a){a=new Map;for(let E=0;E<i;E++)a.set(l(E),E)}return a.get(S.row)??-1},d=S=>(c===void 0&&(c=wh(o)),!!c&&c.has(S)),u=S=>{var E;return!!S&&(Ur(S)?!!o.defaultEditable:!!((E=S.editable)!=null&&E.call(S)))},f=[],g=[];let p=0;const m=t==="undo"?[...this.entries].reverse():this.entries;for(const S of m){const E=t==="undo"?S.newValue:S.oldValue,x=t==="undo"?S.oldValue:S.newValue,R=yh(e,S);if(R<0){p++;continue}const L=h(S);if(L>=0){if(!o.isEditable(L,R)||!r&&!Mt(e.getCellInput(L,R),E)){p++;continue}f.push({rowIndex:L,columnIndex:R,value:x});continue}const v=s.getColumnDef(R),D=d(S.row)?Ch(S.row,v,R,E):void 0;if(!d(S.row)||!u(v)||!r&&!Mt(D,E)||!Bn(S.row,v,R,x)){p++;continue}g.push({row:S.row,rowIndex:-1,columnIndex:R,property:S.property,oldValue:D,newValue:x})}const b=e.writeUndoCells(f,g,t);let y;for(const S of b)S.rowIndex<0||(y?(y.r1=Math.min(y.r1,S.rowIndex),y.r2=Math.max(y.r2,S.rowIndex),y.c1=Math.min(y.c1,S.columnIndex),y.c2=Math.max(y.c2,S.columnIndex)):y=new M(S.rowIndex,S.columnIndex,S.rowIndex,S.columnIndex));return{applied:b.length,skipped:p+f.length+g.length-b.length,range:y}}}function yh(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 Ch(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 El{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&&Mt(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 Ml{constructor(e,t,s,o,i){this.canUndo=e,this.canRedo=t,this.undoLabel=s,this.redoLabel=o,this.size=i}}const vr={edit:"Edit",fill:"Fill",paste:"Paste",cut:"Cut",clear:"Clear",api:"Change"};class Sh{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 Rr([...this.steps].reverse().map(t=>t.undo(e)))}redo(e){return Rr(this.steps.map(t=>t.redo(e)))}}function Rr(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 Tl{constructor(e,t){this.tableScope=e,this.options=t,this.running=!1,this.foldDepth=0,this.stack=new Rl(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 Uo&&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 Uo(vr[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 El(vr[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 Sh(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 Ml(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 Al(this.tableScope.tableModel.getBodyModel())}fire(){var e,t;(t=(e=this.tableScope.getEventListener()).onUndoStackChanged)==null||t.call(e,this.getState())}}function Il(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 xh(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}const Ge=class Ge extends Cn{constructor(e,t,s,o,i,r=new Se,l=new On){var u;if(super(e,t,new xs(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 pn(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=no.create(Ze(this.tableOptions,"editing")),this.subscribers=new Set,this.clipboardOptions=os.create(Ze(this.tableOptions,"clipboard")),this.undoOptions=ho.create(Ze(this.tableOptions,"undo")),this.lastTabKeyTime=0,this.lastContextmenu=Date.now(),this.allExpanded=!0,this.selectionEventsHeld=0,t.setTableScope(this),this.liveAnnouncer=new Ds(e.ownerDocument,this.ariaIds.liveRegion(),s),this.eventListener=xh(i??new Kt,this.subscribers),this.stateService=new Is(this),this.mouseHandler=new Gr(this),this.inputHandler=new An(this),this.resizeHandler=new Ln(this,o.resizeEventDebounceDelay),this.shortcutService=new Dn(this),this.rowDragService=new Nn(this),this.batchEditService=new $n(this),this.fillHandleService=new qn(this),this.editingOptions){this.cellEditorService=new ll(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 Wo(this,this.clipboardOptions,!0)),this.undoOptions&&(this.undoService=new Tl(this,this.undoOptions));const a=Tt.create(Ze(o,"cellFormulas"));if(a&&(o.masterDetail?console.warn("GuiExpert Table – cellFormulas: no cell formulas with master/detail."):this.tableSheet=co.create(t,a)),o!=null&&o.masterDetail&&(this.masterDetailService=new Zn(this,(f,g,p,m)=>new Ge(f,g,new Vo,this.nestedTableOptions(p),m??new Kt)),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 Kt,i=new Vo,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(cl(e)),this.undoOptions&&t.push(vl(e)),!s)return t;const o=al(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 bt("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&&!O(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&&!O(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 pe;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,O(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 O(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 Il((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&&!O(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()||ii(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 vs(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 bt("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 bt("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,S,E,x,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:v,columnIndex:D,value:k}of e){const N=!!(h!=null&&h.isFormulaInput(D,k));if(!s.skipValidation){const $=N?this.checkFormulaSyntax(k):this.validateCellValue(v,D,s.raw?k:this.pipeCellValue(v,D,k));if($){a++,c=c||$;continue}}const V=this.getCellInput(v,D);(s.raw||N?this.setRawValue(v,D,k):o.setValue(v,D,k))&&l.push({row:this.rowObjectOf(v),rowIndex:v,columnIndex:D,property:this.batchEditService.propertyOf(D),oldValue:V,newValue:this.getCellInput(v,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(v=>v.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 v=Xe.createSingle(u[0].rowIndex,u[0].columnIndex);v.changes=u,v.source=t,(E=(S=this.eventListener).onModelChanged)==null||E.call(S,v)}else(R=(x=this.eventListener).onModelChanged)==null||R.call(x,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 pe().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 zt))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 pe;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)||Cs(this.tableModel)}getClipboardService(){return this.clipboardService||(this.clipboardService=new Wo(this,os.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&&!Mt(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 ss.create(Ze(this.tableOptions,"fillHandle"))}fillRange(e,t,s,o="auto",i){const r=this.getFillHandleOptions()??ss.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=Jn({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 S;return{row:this.rowObjectOf(y),property:((S=this.tableModel.getColumnDef(C))==null?void 0:S.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??Ei(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 pe;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.tableModel.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;if(this.destroyed)return;try{this.stateService.destroy()}catch(c){console.error(c)}try{(s=this.rowDragService)==null||s.destroy()}catch(c){console.error(c)}(o=this.fillHandleService)==null||o.destroy(),(i=this.cellEditorService)==null||i.destroy(),(r=this.clipboardService)==null||r.destroy(),(l=this.tableSheet)==null||l.destroy(),this.subscribers.clear();try{(a=this.masterDetailService)==null||a.destroy()}catch(c){console.error(c)}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 Qn(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){const t=new js;if(t.originalEvent=e,e){const s=this.getMouseEventTarget(e);if([t.areaIdent,t.sideIdent]=this.getAreaAndSideIdentByAttr(s),t.rowIndex=this.getNumberByAttr(s,"data-row-index"),t.columnIndex=this.getNumberByAttr(s,"data-col-index"),t.action=this.getStringByAttr(s,"data-ge-action"),t.areaIdent){const o=this.tableModel.getAreaModel(t.areaIdent);t.rowTop=t.areaIdent==="body"?this.getBodyRowTop(t.rowIndex):o.getYPosByRowIndex(t.rowIndex)}t.columnLeft=this.tableModel.getXPosByColumnIndex(t.columnIndex)}return t}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){this.selectionService.onMouseDown(),e.columnIndex>-1&&e.action&&["resize-column","drag-column"].includes(e.action)&&!O(this.tableModel.getColumnDef(e.columnIndex))&&(this.mouseStartWidth=this.tableModel.getColumnWidth(e.columnIndex),this.mouseStartAction=e.action,this.mouseStartColumnIndex=e.columnIndex,this.mouseStartAction==="drag-column"&&(this.firstDraggingRendering=!0,this.dragFrom=this.mouseStartColumnIndex))}mouseDraggingOnFrame(e,t){var s,o,i;(o=(s=this.eventListener).onMouseDragging)==null||o.call(s,e),this.mouseEvent=e,this.mouseStartColumnIndex>-1&&this.mouseStartAction==="resize-column"&&this.tableOptions.columnsResizable?this.resizeColumn(e):!this.mouseStartAction&&this.selectionService.onMouseDragging(e,t)?this.repaint():this.mouseStartAction==="drag-column"&&e.columnIndex>-1&&this.tableOptions.columnsDraggable&&((i=this.tableSheet)==null?void 0:i.allowsColumnDrag())!==!1&&(this.draggingTargetColumnIndex=Math.max(e.columnIndex,this.getFirstDataColumnIndex()),this.dragTo=this.draggingTargetColumnIndex,this.dragFrom>-1&&this.dragTo>-1&&this.dragFrom!==this.dragTo&&(this.lastDragFrom===this.dragTo&&this.lastDragTo===this.dragFrom||(this.tableModel.changeColumnOrder(this.dragFrom,this.dragTo),this.lastDragFrom=this.dragFrom,this.lastDragTo=this.dragTo,this.dragFrom=this.dragTo,this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows())),t&&(this.adjustDraggingColumn(e,this.dragFrom,this.firstDraggingRendering),this.firstDraggingRendering=!1),this.repaint())}mouseDraggingEndOnFrame(e){var t,s;(s=(t=this.eventListener).onMouseDraggingEnd)==null||s.call(t,e),this.draggingTargetColumnIndex=-1,this.mouseStartAction==="resize-column"?(this.resizeColumn(e),this.stateService.markDirty("columns")):this.mouseStartAction==="drag-column"&&(this.hideDraggingColumn(),this.repaint(),this.stateService.markDirty("columns"),this.stateService.markDirty("selection")),this.mouseStartWidth=-1,this.mouseStartColumnIndex=-1,this.dragFrom=-1,this.dragTo=-1,this.firstDraggingRendering=!0,this.mouseStartAction=""}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),_o(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(!Cs(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 Ts(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){const s=this.getContentScrollRangeY(),o=this.getScrollerRangeY();if(s>0&&o>0){const i=Math.min(s,Math.max(0,t)),r=i/s*o;this.scrollViewport.scrollTo(Ss(e,this.isRtl()),r),this.pendingContentScroll={scrollTop:this.scrollViewport.scrollTop,contentTop:i},this.adjustAfterScrolling();return}this.scrollViewport.scrollTo(Ss(e,this.isRtl()),t)}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;super.adjustAfterScrolling();const e=this.scrollViewport;(s=(t=this.eventListener).onScroll)==null||s.call(t,new En(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(){const e=this.tableModel.getBodyModel(),t=this.tableModel.getColumnCount();if(!e)return console.warn("Body model is not available."),[];const s=30,o=Array.from({length:t},()=>new Set),i=new Array(t).fill(0),r=u=>{var p,m;const f=this.tableModel.getAreaModel(u),g=(f==null?void 0:f.getRowCount())??0;for(let b=0;b<g;b++)for(let y=0;y<t;y++){const C=((p=f.getTextValueAt)==null?void 0:p.call(f,b,y))||(((m=f.getValueAt(b,y))==null?void 0:m.toString())??""),S=C.length;S>i[y]&&(i[y]=S,o[y].forEach(E=>{E.length<S-2&&o[y].delete(E)})),S>=i[y]-2&&o[y].size<s&&o[y].add(C)}};r("header"),r("body"),r("footer");const l=this.hostElement.querySelector(".ge-table-label"),a=getComputedStyle(l??this.hostElement),c=l?(parseFloat(a.paddingLeft)||0)+(parseFloat(a.paddingRight)||0):20;let h=null;try{h=document.createElement("canvas").getContext("2d")}catch{h=null}h&&(h.font=a.font||`${a.fontSize} ${a.fontFamily}`);const d=u=>h?h.measureText(u).width:u.length*8;return o.map(u=>{let f=0;return u.forEach(g=>{f=Math.max(f,d(g))}),Math.max(Math.ceil(f+c+2),50)})}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.calcAutoColumnWidths();for(let s=0;s<t.length;s++){if(O(this.tableModel.getColumnDef(s)))continue;const o=this.clampToColumnWidthLimits(s,t[s]);this.tableModel.setColumnWidth(s,o)}e&&this.recalcWrappers(),this.stateService.markDirty("columns")}recalcWrappers(){this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}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 Ts(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 Ko=Ge;class Rh extends Kt{constructor(e){super(),this.onCheckboxChangedCallback=e,super.onCheckboxChanged=t=>{this.onCheckboxChangedCallback(t)}}}const Hs=class Hs{};Hs.themes=["light","combat","paper","blackboard"],Hs.vars={light:`html[data-theme="light"] {
|
|
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 xl(n){const{matrix:e,anchorRow:t,shownColumns:s,rowCount:o}=n,i=e.length,r=e.reduce((C,S)=>Math.max(C,S.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}=Ti(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 S=t+C,E=e[C%i];for(let x=0;x<u;x++){const R=s[l+x];if(S<o&&n.isWritable&&!n.isWritable(S,R)){y++;continue}const F=E[x%r]??"";b.push({rowIndex:S,columnIndex:R,value:F})}}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 Ti(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 Sr=n=>n.replace(/\r\n?/g,`
|
|
71
|
+
`).replace(/\n$/,"");class Wo{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?yl(e):t?Sl(t):[];if(!i.length||!i[0].length)return[];const r=this.memory&&e&&Sr(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,P)=>H.map((ue,te)=>{var L;return((L=r.values[P])==null?void 0:L[te])instanceof zt?r.values[P][te]:ue})):i,S=!!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},P=E(H);if(P===!1)return[];Array.isArray(P)&&(C=P,S=!1)}const x=this.options.maxPasteCells,R=Ti(C.length,C.reduce((H,P)=>Math.max(H,P.length),0),g);if(R.rows*R.columns>x)return o.announce(o.getSheetTexts().pasteTooLarge(x)),[];const F=this.options.pasteAddsRows&&!!this.options.createRow&&!y&&this.canAppendRows(),v=((_e=(j=o.tableModel).getColumnDefs)==null?void 0:_e.call(j))??[],D=xl({matrix:C,anchorRow:u,anchorColumn:f,shownColumns:h,rowCount:c,selection:g,canAddRows:F,isWritable:(H,P)=>a.isEditable(H,P)&&!O(v[P])});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 N="paste";if(l){N="cut";const H=new Map(h.map((te,L)=>[te,L])),P=[],ue=new Set;for(const{rowIndex:te,columnIndex:L,value:Y}of D.cells){const Ot=S?Y:this.convertPastedText(Y,te,L);o.checkPastedValue(te,L,Ot,S)||(k.push({rowIndex:te,column:L,value:Ot}),P.push([te-u,H.get(L)-m]),ue.add(`${te}:${L}`))}for(const te of this.cutSourceChanges(l,P,ue))k.push(te)}else for(const{rowIndex:H,columnIndex:P,value:ue}of D.cells)k.push({rowIndex:H,column:P,value:S?ue:this.convertPastedText(ue,H,P)});const V=k.length?o.writePastedCells(k,N,S):[];l&&(this.memory=void 0,this.removeCutFrame()),D.addRows&&o.repaintHard();let $=V.length;if(l){const H=new Set(D.cells.map(P=>`${P.rowIndex}:${P.columnIndex}`));$=V.filter(P=>H.has(`${P.rowIndex}:${P.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&&(xr(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="",xr(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:Sr(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 x=l.getRanges(),R=x[x.length-1];c=x.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 x=t.getActiveBodyCell();a=x?M.singleCell(x[0],x[1]):void 0}if(!a||a.r2<a.r1||a.c2<a.c1)return;const h=[];for(let x=a.c1;x<=a.c2;x++){const R=s.getColumnDef(x);((E=R==null?void 0:R.isVisible)==null?void 0:E.call(R))===!1||s.getColumnWidth(x)<=0||O(R)&&!R.options.exported||h.push(x)}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 x=h.map(R=>t.getColumnAriaLabel(R));g.push(x),p.push(x),m.push(x.map(R=>({text:R})))}for(let x=a.r1;x<=a.r2;x++){const R=[],F=[],v=[];for(const D of h){const k=s.getColumnDef(D);let N,V;if(f&&!l.isSelected(x,D))N="",V="";else if(O(k))N=k.getRowNumberText(x,o),V=N;else{V=t.getCopyValue(x,D);const j=V instanceof zt?V.value:V;N=u||j===null||j===void 0||j instanceof Date?bh(j):o.getTextValueAt(x,D)}R.push(N),F.push(V);const $=V instanceof zt?V.value:V;v.push(typeof $=="number"?{text:N,num:$}:{text:N})}g.push(R),p.push(F),m.push(v)}let b=g,y=!1;if(this.options.processCopy){const x=this.options.processCopy({ranges:[a],matrix:g,cut:e});Array.isArray(x)&&(b=x,y=!0)}const C=wl(b),S=this.options.html?Cl(y?b.map(x=>x.map(R=>({text:R}))):m):void 0;return{text:C,html:S,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&&!O(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}`)||O(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 xr(n){return n.getRootNode().activeElement??null}function bh(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 vl(n){return n?{"meta+z":"UNDO","meta+shift+z":"REDO"}:{"ctrl+z":"UNDO","ctrl+y":"REDO","ctrl+shift+z":"REDO"}}class ho{constructor(){this.maxSteps=100,this.maxCells=1e6,this.onConflict="skip",this.recordApiChanges=!1}static create(e){if(!e)return;const t=new ho;if(typeof e=="object")for(const[s,o]of Object.entries(e))o!==void 0&&(t[s]=o);return t}}class Rl{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 Al(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 wh(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=Al(n);return e?new Set(e):null}class Uo{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=S=>{const E=o.getRowByIndex(S);return U(E)?E.data:E};let a,c;const h=S=>{if(S.row===void 0||S.row===null||typeof S.row!="object")return S.rowIndex>=0&&S.rowIndex<i?S.rowIndex:-1;if(S.rowIndex>=0&&S.rowIndex<i&&l(S.rowIndex)===S.row)return S.rowIndex;if(!a){a=new Map;for(let E=0;E<i;E++)a.set(l(E),E)}return a.get(S.row)??-1},d=S=>(c===void 0&&(c=wh(o)),!!c&&c.has(S)),u=S=>{var E;return!!S&&(Ur(S)?!!o.defaultEditable:!!((E=S.editable)!=null&&E.call(S)))},f=[],g=[];let p=0;const m=t==="undo"?[...this.entries].reverse():this.entries;for(const S of m){const E=t==="undo"?S.newValue:S.oldValue,x=t==="undo"?S.oldValue:S.newValue,R=yh(e,S);if(R<0){p++;continue}const F=h(S);if(F>=0){if(!o.isEditable(F,R)||!r&&!Mt(e.getCellInput(F,R),E)){p++;continue}f.push({rowIndex:F,columnIndex:R,value:x});continue}const v=s.getColumnDef(R),D=d(S.row)?Ch(S.row,v,R,E):void 0;if(!d(S.row)||!u(v)||!r&&!Mt(D,E)||!Bn(S.row,v,R,x)){p++;continue}g.push({row:S.row,rowIndex:-1,columnIndex:R,property:S.property,oldValue:D,newValue:x})}const b=e.writeUndoCells(f,g,t);let y;for(const S of b)S.rowIndex<0||(y?(y.r1=Math.min(y.r1,S.rowIndex),y.r2=Math.max(y.r2,S.rowIndex),y.c1=Math.min(y.c1,S.columnIndex),y.c2=Math.max(y.c2,S.columnIndex)):y=new M(S.rowIndex,S.columnIndex,S.rowIndex,S.columnIndex));return{applied:b.length,skipped:p+f.length+g.length-b.length,range:y}}}function yh(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 Ch(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 El{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&&Mt(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 Ml{constructor(e,t,s,o,i){this.canUndo=e,this.canRedo=t,this.undoLabel=s,this.redoLabel=o,this.size=i}}const vr={edit:"Edit",fill:"Fill",paste:"Paste",cut:"Cut",clear:"Clear",api:"Change"};class Sh{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 Rr([...this.steps].reverse().map(t=>t.undo(e)))}redo(e){return Rr(this.steps.map(t=>t.redo(e)))}}function Rr(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 Tl{constructor(e,t){this.tableScope=e,this.options=t,this.running=!1,this.foldDepth=0,this.stack=new Rl(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 Uo&&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 Uo(vr[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 El(vr[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 Sh(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 Ml(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 Al(this.tableScope.tableModel.getBodyModel())}fire(){var e,t;(t=(e=this.tableScope.getEventListener()).onUndoStackChanged)==null||t.call(e,this.getState())}}function Il(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 xh(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}const Ge=class Ge extends Cn{constructor(e,t,s,o,i,r=new Se,l=new On){var u;if(super(e,t,new xs(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 pn(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=no.create(Ze(this.tableOptions,"editing")),this.subscribers=new Set,this.clipboardOptions=os.create(Ze(this.tableOptions,"clipboard")),this.undoOptions=ho.create(Ze(this.tableOptions,"undo")),this.lastTabKeyTime=0,this.lastContextmenu=Date.now(),this.allExpanded=!0,this.selectionEventsHeld=0,t.setTableScope(this),this.liveAnnouncer=new Ds(e.ownerDocument,this.ariaIds.liveRegion(),s),this.eventListener=xh(i??new Kt,this.subscribers),this.stateService=new Is(this),this.mouseHandler=new Gr(this),this.inputHandler=new An(this),this.resizeHandler=new Fn(this,o.resizeEventDebounceDelay),this.shortcutService=new Dn(this),this.rowDragService=new Nn(this),this.batchEditService=new $n(this),this.fillHandleService=new qn(this),this.editingOptions){this.cellEditorService=new ll(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 Wo(this,this.clipboardOptions,!0)),this.undoOptions&&(this.undoService=new Tl(this,this.undoOptions));const a=Tt.create(Ze(o,"cellFormulas"));if(a&&(o.masterDetail?console.warn("GuiExpert Table – cellFormulas: no cell formulas with master/detail."):this.tableSheet=co.create(t,a)),o!=null&&o.masterDetail&&(this.masterDetailService=new Zn(this,(f,g,p,m)=>new Ge(f,g,new Vo,this.nestedTableOptions(p),m??new Kt)),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 Kt,i=new Vo,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(cl(e)),this.undoOptions&&t.push(vl(e)),!s)return t;const o=al(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 bt("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&&!O(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&&!O(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 pe;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,O(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 O(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 Il((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&&!O(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()||ii(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 vs(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 bt("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 bt("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,S,E,x,R,F;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:v,columnIndex:D,value:k}of e){const N=!!(h!=null&&h.isFormulaInput(D,k));if(!s.skipValidation){const $=N?this.checkFormulaSyntax(k):this.validateCellValue(v,D,s.raw?k:this.pipeCellValue(v,D,k));if($){a++,c=c||$;continue}}const V=this.getCellInput(v,D);(s.raw||N?this.setRawValue(v,D,k):o.setValue(v,D,k))&&l.push({row:this.rowObjectOf(v),rowIndex:v,columnIndex:D,property:this.batchEditService.propertyOf(D),oldValue:V,newValue:this.getCellInput(v,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(v=>v.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 v=Xe.createSingle(u[0].rowIndex,u[0].columnIndex);v.changes=u,v.source=t,(E=(S=this.eventListener).onModelChanged)==null||E.call(S,v)}else(R=(x=this.eventListener).onModelChanged)==null||R.call(x,Xe.createForChanges(u,t))}finally{(F=this.undoService)==null||F.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 pe().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 zt))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 pe;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)||Cs(this.tableModel)}getClipboardService(){return this.clipboardService||(this.clipboardService=new Wo(this,os.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&&!Mt(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 ss.create(Ze(this.tableOptions,"fillHandle"))}fillRange(e,t,s,o="auto",i){const r=this.getFillHandleOptions()??ss.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=Jn({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 S;return{row:this.rowObjectOf(y),property:((S=this.tableModel.getColumnDef(C))==null?void 0:S.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??Ei(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 pe;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;if(this.destroyed)return;try{this.stateService.destroy()}catch(c){console.error(c)}try{(s=this.rowDragService)==null||s.destroy()}catch(c){console.error(c)}(o=this.fillHandleService)==null||o.destroy(),(i=this.cellEditorService)==null||i.destroy(),(r=this.clipboardService)==null||r.destroy(),(l=this.tableSheet)==null||l.destroy(),this.subscribers.clear();try{(a=this.masterDetailService)==null||a.destroy()}catch(c){console.error(c)}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 Qn(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){const t=new js;if(t.originalEvent=e,e){const s=this.getMouseEventTarget(e);if([t.areaIdent,t.sideIdent]=this.getAreaAndSideIdentByAttr(s),t.rowIndex=this.getNumberByAttr(s,"data-row-index"),t.columnIndex=this.getNumberByAttr(s,"data-col-index"),t.action=this.getStringByAttr(s,"data-ge-action"),t.areaIdent){const o=this.tableModel.getAreaModel(t.areaIdent);t.rowTop=t.areaIdent==="body"?this.getBodyRowTop(t.rowIndex):o.getYPosByRowIndex(t.rowIndex)}t.columnLeft=this.tableModel.getXPosByColumnIndex(t.columnIndex)}return t}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){this.selectionService.onMouseDown(),e.columnIndex>-1&&e.action&&["resize-column","drag-column"].includes(e.action)&&!O(this.tableModel.getColumnDef(e.columnIndex))&&(this.mouseStartWidth=this.tableModel.getColumnWidth(e.columnIndex),this.mouseStartAction=e.action,this.mouseStartColumnIndex=e.columnIndex,this.mouseStartAction==="drag-column"&&(this.firstDraggingRendering=!0,this.dragFrom=this.mouseStartColumnIndex))}mouseDraggingOnFrame(e,t){var s,o,i;(o=(s=this.eventListener).onMouseDragging)==null||o.call(s,e),this.mouseEvent=e,this.mouseStartColumnIndex>-1&&this.mouseStartAction==="resize-column"&&this.tableOptions.columnsResizable?this.resizeColumn(e):!this.mouseStartAction&&this.selectionService.onMouseDragging(e,t)?this.repaint():this.mouseStartAction==="drag-column"&&e.columnIndex>-1&&this.tableOptions.columnsDraggable&&((i=this.tableSheet)==null?void 0:i.allowsColumnDrag())!==!1&&(this.draggingTargetColumnIndex=Math.max(e.columnIndex,this.getFirstDataColumnIndex()),this.dragTo=this.draggingTargetColumnIndex,this.dragFrom>-1&&this.dragTo>-1&&this.dragFrom!==this.dragTo&&(this.lastDragFrom===this.dragTo&&this.lastDragTo===this.dragFrom||(this.tableModel.changeColumnOrder(this.dragFrom,this.dragTo),this.lastDragFrom=this.dragFrom,this.lastDragTo=this.dragTo,this.dragFrom=this.dragTo,this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows())),t&&(this.adjustDraggingColumn(e,this.dragFrom,this.firstDraggingRendering),this.firstDraggingRendering=!1),this.repaint())}mouseDraggingEndOnFrame(e){var t,s;(s=(t=this.eventListener).onMouseDraggingEnd)==null||s.call(t,e),this.draggingTargetColumnIndex=-1,this.mouseStartAction==="resize-column"?(this.resizeColumn(e),this.stateService.markDirty("columns")):this.mouseStartAction==="drag-column"&&(this.hideDraggingColumn(),this.repaint(),this.stateService.markDirty("columns"),this.stateService.markDirty("selection")),this.mouseStartWidth=-1,this.mouseStartColumnIndex=-1,this.dragFrom=-1,this.dragTo=-1,this.firstDraggingRendering=!0,this.mouseStartAction=""}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),_o(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(!Cs(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 Ts(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){const s=this.getContentScrollRangeY(),o=this.getScrollerRangeY();if(s>0&&o>0){const i=Math.min(s,Math.max(0,t)),r=i/s*o;this.scrollViewport.scrollTo(Ss(e,this.isRtl()),r),this.pendingContentScroll={scrollTop:this.scrollViewport.scrollTop,contentTop:i},this.adjustAfterScrolling();return}this.scrollViewport.scrollTo(Ss(e,this.isRtl()),t)}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;super.adjustAfterScrolling();const e=this.scrollViewport;(s=(t=this.eventListener).onScroll)==null||s.call(t,new En(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(){const e=this.tableModel.getBodyModel(),t=this.tableModel.getColumnCount();if(!e)return console.warn("Body model is not available."),[];const s=30,o=Array.from({length:t},()=>new Set),i=new Array(t).fill(0),r=u=>{var p,m;const f=this.tableModel.getAreaModel(u),g=(f==null?void 0:f.getRowCount())??0;for(let b=0;b<g;b++)for(let y=0;y<t;y++){const C=((p=f.getTextValueAt)==null?void 0:p.call(f,b,y))||(((m=f.getValueAt(b,y))==null?void 0:m.toString())??""),S=C.length;S>i[y]&&(i[y]=S,o[y].forEach(E=>{E.length<S-2&&o[y].delete(E)})),S>=i[y]-2&&o[y].size<s&&o[y].add(C)}};r("header"),r("body"),r("footer");const l=this.hostElement.querySelector(".ge-table-label"),a=getComputedStyle(l??this.hostElement),c=l?(parseFloat(a.paddingLeft)||0)+(parseFloat(a.paddingRight)||0):20;let h=null;try{h=document.createElement("canvas").getContext("2d")}catch{h=null}h&&(h.font=a.font||`${a.fontSize} ${a.fontFamily}`);const d=u=>h?h.measureText(u).width:u.length*8;return o.map(u=>{let f=0;return u.forEach(g=>{f=Math.max(f,d(g))}),Math.max(Math.ceil(f+c+2),50)})}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.calcAutoColumnWidths();for(let s=0;s<t.length;s++){if(O(this.tableModel.getColumnDef(s)))continue;const o=this.clampToColumnWidthLimits(s,t[s]);this.tableModel.setColumnWidth(s,o)}e&&this.recalcWrappers(),this.stateService.markDirty("columns")}recalcWrappers(){this.tableModel.recalcPadding(),this.resetSizeOfWrapperDiv(),this.adjustContainersAndRows()}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 Ts(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 Ko=Ge;class Rh extends Kt{constructor(e){super(),this.onCheckboxChangedCallback=e,super.onCheckboxChanged=t=>{this.onCheckboxChangedCallback(t)}}}const Hs=class Hs{};Hs.themes=["light","combat","paper","blackboard"],Hs.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);
|
|
@@ -328,7 +328,7 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
|
|
|
328
328
|
--ge-table-spinner-size: 28px;
|
|
329
329
|
--ge-table-row-number-bg: var(--ge-table-header-west-bg);
|
|
330
330
|
--ge-table-row-number-color: #c9c86f;
|
|
331
|
-
}`};let zo=Hs;class ze{constructor(e,t=!0,s,o,i=0,r=!1,l=!1){this.data=e,this.expanded=t,this.children=s,this.parent=o,this.deep=i,this.checked=r,this.keep=l,this.type="TreeRow"}}class pt{static buildTreeRows(e,t="children",s=12,o=!0){const i=typeof t=="string"?{childrenProperty:t,deepMaxLimit:s,expanded:o}:t,r=i.childrenProperty??"children",l=i.deepMaxLimit??12,a=pt.toExpandedFn(i.expanded??!0),c=[];for(const h of e){const d=new ze(h,a(h,0),[],void 0,0);c.push(pt.buildTreeRow(h,r,d,0,l,a))}return c}static buildTreeRow(e,t="children",s=new ze(e,!0,[],void 0,0),o=0,i=12,r=!0){var c;const l=pt.toExpandedFn(r),a=e[t];if(a!=null&&a.length&&o>=i)return console.warn("Max deep limit reached: ",o),s;if(a)for(const h of a){const d=new ze(h,l(h,o+1),[],s,o+1);(c=s.children)==null||c.push(d),pt.buildTreeRow(h,t,d,o+1,i,l)}return s}static toExpandedFn(e){return typeof e=="function"?e:()=>e}}const Ah=new T(500,"px"),Eh=new T(400,"px"),Dl=new T(300,"px"),Mh=new T(290,"px"),Th=new T(280,"px"),Ih=new T(270,"px"),Dh=new T(260,"px"),kh=new T(250,"px"),Fh=new T(240,"px"),Lh=new T(230,"px"),Oh=new T(220,"px"),Ph=new T(210,"px"),Fs=new T(200,"px"),Nh=new T(190,"px"),Vh=new T(180,"px"),_h=new T(170,"px"),Bh=new T(160,"px"),$h=new T(150,"px"),Hh=new T(140,"px"),Gh=new T(130,"px"),Wh=new T(120,"px"),Uh=new T(110,"px"),Kh=new T(100,"px"),zh=new T(90,"px"),jh=new T(80,"px"),Xh=new T(70,"px"),Yh=new T(60,"px"),Jh=new T(50,"px"),qh=new T(40,"px"),Zh=new T(30,"px"),Qh=new T(20,"px"),ed=new T(10,"px"),td=new T(0,"px");class kl{flattenTree(e,t=[]){var s;for(const o of e)this.isVisible(o)&&(t.push(o),o.expanded&&((s=o.children)!=null&&s.length)&&this.flattenVisibleChildren(o.children,t));return t}flattenVisibleChildren(e,t){var s;for(const o of e)t.push(o),o.expanded&&((s=o.children)!=null&&s.length)&&this.flattenVisibleChildren(o.children,t)}isVisible(e){return e.parent?e.parent.expanded?this.isVisible(e.parent):!1:!0}}class rt extends as{constructor(e,t,s,o=[]){super(e,o,s),this.areaIdent=e,this.rows=t,this.defaultRowHeight=s,this.columnDefs=o,this.type="AreaModelTree",this.sorterService=new di,this.service=new kl,this.filteredFlattenRows=[],this.flattenRows=[],this.keepMarked=!1,this.showValuesCache=new Map,this.properties=o.map(i=>i.property),this.refreshDisplayedRows()}changeColumnOrder(e,t){this.arrayMove(this.properties,e,t),super.changeColumnOrder(e,t)}recalcVisibleTreeRows(e=!0){this.refreshDisplayedRows(e)}getDisplayedRootRows(){return this.lastPredictFn?this.rows.filter(e=>e.keep):this.rows}hasDisplayedChildren(e){var t;return(t=e.children)!=null&&t.length?!this.lastPredictFn||e.children.some(s=>s.keep):!1}getDisplayedChildren(e){var t;return(t=e.children)!=null&&t.length?this.lastPredictFn?e.children.filter(s=>s.keep):e.children:[]}getLeafRows(e=!0){const t=!e||!this.lastPredictFn;return this.collectAllRows(this.rows??[],[]).filter(s=>{var o;return!((o=s.children)!=null&&o.length)&&(t||s.keep)})}getFilteredFlattenRows(){return this.filteredFlattenRows}getRowCount(){return this.filteredFlattenRows.length}getUnfilteredRowCount(){return this.flattenRows.length}canMoveRows(e,t){if(this.getRowCount()!==this.getUnfilteredRowCount())return!1;const s=this.getDragRows(e);return s.length>0&&gi(s,this.getRowByIndex(t.rowIndex))}moveRows(e,t){if(!this.canMoveRows(e,t))return!1;const s=this.getRowByIndex(t.rowIndex),o=Yr(this.rows,this.getDragRows(e),s,t.position);return o&&(this.showValuesCache.clear(),this.invalidateColumnValues(),this.refreshDisplayedRows(!0)),o}getDragRows(e){const t=it(e,this.getRowCount()).map(s=>this.getRowByIndex(s)).filter(s=>!!s);return fi(t)}getValueAt(e,t){const s=this.getRowByIndex(e);if(s){const o=this.properties[t];if(o){const i=this.getRawValueOfRow(s,o),r=this.getColumnValues().getShowValuesAs(o);return r?this.applyShowValuesAs(s,o,i,r):i}}return""}getRawValueOfRow(e,t){return this.getColumnValues().getter(t)?this.getColumnValues().get(e.data,t):t.includes(".")?this.getPropertyValue(e.data,t.split(".")):e.data[t]}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={byRow:new Map},this.showValuesCache.set(t,i)),o.mode){case"percentOfColumnTotal":case"percentOfGrandTotal":return i.total===void 0&&(i.total=qs(this.getLeafRows(!0).map(r=>this.getRawValueOfRow(r,t)))),typeof s=="number"&&!Number.isNaN(s)&&i.total!==0?s/i.total:void 0;case"percentOfRowTotal":return s;default:{if(!i.byRow.has(e)){const r=e.parent?this.getDisplayedChildren(e.parent):this.getDisplayedRootRows(),l=hi(r.map(a=>this.getRawValueOfRow(a,t)),o.mode);r.forEach((a,c)=>i.byRow.set(a,l[c]))}return i.byRow.get(e)}}}readPropertyPath(e,t){return t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}getAggregationSourceForValues(){return{signal:this.rows,length:this.rows.length,rows:()=>this.getLeafRows(!0).map(e=>e.data)}}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.getRowHeight===rt.prototype.getRowHeight&&this.defaultRowHeight>0?this.defaultRowHeight:void 0}getCustomClassesAt(e,t){const s=this.filteredFlattenRows[e];return this.addCalculatedClasses(["ge-table-tree-cell","ge-table-tree-deep-"+s.deep],this.properties[t],()=>this.getValueAt(e,t))}getRowByIndex(e){return this.filteredFlattenRows[e]}getValueByT(e,t){if(!e||!t)return;const s=this.getColumnValues();return s.getter(t)?s.get(e,t):t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}externalFilterChanged(e){this.lastPredictFn=e,this.showValuesCache.clear(),this.invalidateColumnValues(),this.refreshDisplayedRows(!0)}doSort(e){if(!e.length)return!1;const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.genericTreeTableSortComparator(this.properties[s],i)});return this.showValuesCache.clear(),this.treeSortWith(this.rows,(s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}),this.refreshDisplayedRows(!1),!0}sort(e){this.showValuesCache.clear(),this.treeSortWith(this.rows,e),this.refreshDisplayedRows(!1)}toggleExpandCollapseAll(e){this.expandAllRecursive(this.rows,e),this.refreshDisplayedRows(!1)}setAllParentsOk(e){return e.parent&&(e.parent.keep=!0,this.setAllParentsOk(e.parent)),!1}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.getRowByIndex(e);if(i){const l=i.data,a=this.columnDefs[t];if(this.areaIdent==="body"&&(a!=null&&a.valueGetter))return this.setCalculatedValue(l,a,s);const c=this.columnDefs[t].property;return c.includes(".")?this.setPropertyValue(l,c.split("."),s):(l[c]=s,!0)}return!1}genericTreeTableSortComparator(e,t){const s=this.columnDefs.find(l=>l.property===e),o=this.getColumnValues().isCalculated(e),i=o?new Map:void 0,r=l=>{if(!i)return this.getValueByT(l,e);if(i.has(l))return i.get(l);const a=this.getValueByT(l,e),c=w(a)?void 0:a;return i.set(l,c),c};return(l,a)=>{const c=r(l.data),h=r(a.data);return o&&(c===void 0||h===void 0)?c===h?0:c===void 0?1:-1:s!=null&&s.sortComparator?t*s.sortComparator(c,h,l.data,a.data,t):this.sorterService.genericSortComparator(c,h,t)}}expandAllRecursive(e,t){for(const s of e)s.expanded=t,s.children&&this.expandAllRecursive(s.children,t)}refreshDisplayedRows(e=!0){if(this.flattenRows=this.service.flattenTree(this.rows??[]),!this.lastPredictFn){this.filteredFlattenRows=[...this.flattenRows];return}(e||!this.keepMarked)&&(this.markKeptRows(this.lastPredictFn),this.keepMarked=!0),this.filteredFlattenRows=this.flattenRows.filter(t=>t.keep)}markKeptRows(e){const t=this.collectAllRows(this.rows??[],[]);t.forEach(s=>s.keep=!1),t.forEach((s,o)=>{if(e(s,o,t)){s.keep=!0;for(let i=s.parent;i&&!i.keep;i=i.parent)i.keep=!0}})}collectAllRows(e,t){var s;for(const o of e)t.push(o),(s=o.children)!=null&&s.length&&this.collectAllRows(o.children,t);return t}getPropertyValue(e,t){const s=t.shift();let o=e[s];return o&&t.length?this.getPropertyValue(o,t):o}treeSortWith(e,t){e.sort(t);for(const s of e)s.children&&this.treeSortWith(s.children,t)}}class jo extends K{constructor(e,t,s,o,i="ge-selected-row",r="ge-focused-row"){super(e,t,o,s,i,r),this.areaIdent=e,this.rows=t,this.columnDefs=s,this.defaultRowHeight=o}}class Ii{constructor(){this.areaIdent="body",this.rowSelectionModel=void 0}changeColumnOrder(e,t){}doSort(e){return!1}sort(e){}externalFilterChanged(e){}getCellRenderer(e,t){}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){return[]}getCustomStyleAt(e,t){}getMaxColspan(){return 0}getMaxRowspan(){return 0}getRowByIndex(e){}getRowCount(){return 0}getRowHeight(e){return 0}getRowspanAt(e,t){return 0}getTooltipAt(e,t){}getValueAt(e,t){}getTextValueAt(e,t){return""}getYPosByRowIndex(e){const t=this.getConstantRowHeight();if(t!==void 0&&t>0)return e*t;let s=0;for(let o=0;o<e;o++)s+=this.getRowHeight(o);return s}getConstantRowHeight(){}init(){}isEditable(e,t){return!1}isFilterable(){return!1}isRowCheckable(e){return!1}isRowChecked(e){}isSelectable(e,t){return!0}setRowChecked(e,t){}setValue(e,t,s){return!1}}const sd={sum:"Sum",count:"Count",avg:"Average",min:"Min",max:"Max",countDistinct:"Distinct",first:"First",last:"Last"},od=new Intl.NumberFormat("en-US");class is extends Ii{constructor(e,t,s){super(),this.columnDefs=t,this.type="AreaModelAggregateFooter",this.textRenderer=new kt,this.areaIdent="footer",this.getBody=typeof e=="function"?e:()=>e,this.options=is.toOptions(s),this.defaultRowHeight=this.options.rowHeight??34,this.footerRows=this.options.rows.map(o=>{const i=Object.keys(o.aggregates).map(r=>ls(r,o.aggregates[r]));return{row:o,specs:i,byKey:new Map(i.map(r=>[r.key,r]))}})}static toOptions(e){if(Array.isArray(e))return{rows:e};const t=e;return Array.isArray(t.rows)?t:{rows:[{aggregates:e}]}}getRowCount(){return this.footerRows.length}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.defaultRowHeight}invalidateDerivedValues(){this.cache=void 0}getResults(e=0){return this.compute().results[e]??{}}getAggregationRowCount(){return this.compute().rowCount}isLabelCell(e,t){return e>=0&&e<this.footerRows.length&&this.getLabelColumnIndex(e)===t}getValueAt(e,t){var i;const s=this.footerRows[e],o=(i=this.columnDefs[t])==null?void 0:i.property;return!s||o===void 0?"":s.byKey.has(o)?this.getResults(e)[o]:this.isLabelCell(e,t)?this.getLabel(e):""}getTextValueAt(e,t){var r;const s=this.footerRows[e],o=(r=this.columnDefs[t])==null?void 0:r.property;if(!s||o===void 0)return"";const i=s.byKey.get(o);if(i){const l=this.getResults(e)[o];return i.format?i.format(l):It(l)}return this.isLabelCell(e,t)?this.getLabel(e):""}getCellRenderer(e,t){var i,r;const s=(i=this.columnDefs[t])==null?void 0:i.property,o=this.footerRows[e];if(!(!o||s===void 0))return o.byKey.has(s)?((r=this.columnDefs[t].rendererMap)==null?void 0:r.footer)??this.textRenderer:this.isLabelCell(e,t)?this.textRenderer:void 0}getCustomClassesAt(e,t){var r,l;const s=(r=this.columnDefs[t])==null?void 0:r.property;if(s!==void 0&&((l=this.footerRows[e])!=null&&l.byKey.has(s)))return["ge-table-footer-aggregate"];if(!this.isLabelCell(e,t))return[];const o=this.columnDefs[t+1];return!o||!this.footerRows[e].byKey.has(o.property)?["ge-table-footer-label","ge-table-footer-label-overflow"]:["ge-table-footer-label"]}getLabelColumnIndex(e){const t=this.footerRows[e].byKey,s=this.options.labelProperty;return s!==void 0?t.has(s)?-1:this.columnDefs.findIndex(o=>o.property===s):this.columnDefs.findIndex(o=>{var i;return!O(o)&&!me(o)&&((i=o.isVisible)==null?void 0:i.call(o))!==!1&&!t.has(o.property)})}getLabel(e){const{row:t,specs:s}=this.footerRows[e],o=this.getAggregationRowCount();if(typeof t.label=="string")return t.label;if(typeof t.label=="function")return t.label(o,this.getResults(e));if(this.footerRows.length>1&&s.length){const i=s[0].aggregator.name,r=sd[i];if(r&&s.every(l=>l.aggregator===Oe[i]))return r}return`${od.format(o)} ${o===1?"row":"rows"}`}getSource(){const e=this.getBody(),t=this.options.getRows;if(t)return{signal:t,getRows:()=>t(e)};const s=this.options.source==="all",o=e;if(typeof o.getFilteredRows=="function"&&typeof o.getAllRows=="function"){const r=s?o.getAllRows():o.getFilteredRows();return{signal:r,length:r.length,getRows:()=>r}}if(Z(e)){const r=e;return{signal:r.rows,getRows:()=>r.getLeafRows(!s).map(l=>l.data)}}const i=e.getRowCount();return{signal:void 0,length:i,getRows:()=>i}}createIndexGetter(e,t){if(!t.getValue)return;if(typeof t.value=="string"){const o=this.columnDefs.findIndex(i=>i.property===t.value);if(o>=0)return i=>e.getValueAt(i,o)}const s=ns(t.value);return o=>s(e.getRowByIndex(o))}withCalculatedValues(e){const t=this.getBody();return typeof t.isCalculatedProperty!="function"||typeof t.getRowValue!="function"?e:e.map(s=>{const o=s.value;return!s.getValue||typeof o!="string"||!t.isCalculatedProperty(o)?s:{...s,getValue:i=>t.getRowValue(i,o)}})}compute(){const e=this.getSource(),t=this.cache;if(t&&t.signal===e.signal&&t.length===e.length)return t;const s=e.getRows(),o=this.withCalculatedValues(this.footerRows.flatMap(c=>c.specs));let i;if(typeof s=="number"){const c=this.getBody();i=va(s,o.map(h=>({aggregator:h.aggregator,getValue:this.createIndexGetter(c,h)})))}else i=Ys(s,o);let r=0;const l=this.footerRows.map(c=>{const h={};for(const d of c.specs)h[d.key]=d.aggregator.result(i[r++]);return h}),a=typeof s=="number"?s:s.length;return this.cache={signal:e.signal,length:e.length,rowCount:a,results:l},this.cache}}class ye{static createTableModel(e){var s,o,i,r,l,a,c,h,d,u,f,g,p,m,b,y;if(e.defaultRowHeights===void 0)if((s=e.tableOptions)!=null&&s.defaultRowHeights)e.defaultRowHeights=e.tableOptions.defaultRowHeights;else{if(e.defaultRowHeights=new Le,e.headerAreaModel&&"defaultRowHeight"in e.headerAreaModel){const C=e.headerAreaModel.defaultRowHeight;C>-1&&(e.defaultRowHeights.header=C)}if(e.bodyAreaModel&&"defaultRowHeight"in e.bodyAreaModel){const C=e.bodyAreaModel.defaultRowHeight;C>-1&&(e.defaultRowHeights.body=C)}if(e.footerAreaModel&&"defaultRowHeight"in e.footerAreaModel){const C=e.footerAreaModel.defaultRowHeight;C>-1&&(e.defaultRowHeights.footer=C)}}if(e.columnDefs===void 0&&((o=e.properties)!=null&&o.length?e.columnDefs=e.properties.map(C=>new be(C,C.toUpperCase(),Fs)):(i=e.rows)!=null&&i.length?e.columnDefs=Object.keys(e.rows[0]).map(C=>new be(C,C.toUpperCase(),Fs)):e.columnDefs=[]),ye.addRowNumberColumn(e),e.rowDrag){const C=(r=e.columnDefs)==null?void 0:r.find(S=>!O(S)&&!me(S));C&&(C.rowDrag=C.rowDrag||!0)}if(e.columnCount===void 0&&((l=e.columnDefs)!=null&&l.length?e.columnCount=e.columnDefs.length:(a=e.headerData)!=null&&a.length?e.columnCount=e.headerData[0].length:(c=e.columnSizes)!=null&&c.length?e.columnCount=(h=e.columnSizes)==null?void 0:h.length:console.warn('Property "columnCount" is missing and cannot be derived from other properties.')),e.headerAreaModel)e.columnLetters&&console.warn("columnLetters: only with the default header (labels or headerData), not with an own headerAreaModel.");else if((d=e.headerData)!=null&&d.length?e.headerAreaModel=new Q("header",e.headerData,e.defaultRowHeights.header,e.columnDefs):(u=e.columnDefs)!=null&&u.length?e.headerAreaModel=new Q("header",[e.columnDefs.map(C=>C.headerLabel)],e.defaultRowHeights.header,e.columnDefs):e.headerAreaModel=new ae("header"),e.columnLetters&&e.headerAreaModel instanceof Q){let C=0;const S=(e.columnDefs??[]).map(E=>O(E)||me(E)?"":Pe(C++));e.headerAreaModel=new vi("header",[S,...e.headerAreaModel.arr],e.defaultRowHeights.header,e.columnDefs)}const t=ye.checkFooterAggregates(e);if(!e.footerAreaModel&&!t&&((f=e.footerData)!=null&&f.length?e.footerAreaModel=new Q("footer",e.footerData,e.defaultRowHeights.footer,e.columnDefs):e.footerAreaModel=new ae("footer")),!e.bodyAreaModel)if(e.rows)if((g=e.rows)!=null&&g.length&&U(e.rows[0])){const C=e.rows;e.bodyAreaModel=new rt("body",C,e.defaultRowHeights.body,e.columnDefs),(((p=e.columnDefs[Zt(e.columnDefs)])==null?void 0:p.property)==="CheckboxColumn"||(m=e.tableOptions)!=null&&m.showCheckboxWihoutExtraColumn)&&(e.bodyAreaModel.rowSelectionModel=new Rt(C))}else e.bodyAreaModel=new jo("body",e.rows,e.columnDefs,e.defaultRowHeights.body);else e.bodyData?e.bodyAreaModel=new Q("body",e.bodyData,e.defaultRowHeights.body):e.bodyAreaModel=new ae("body");if(t){const C=is.toOptions(t);e.footerAreaModel=new is(e.bodyAreaModel,e.columnDefs??[],{...C,rowHeight:C.rowHeight??e.defaultRowHeights.footer})}return e.fixedLeftColumnCount===void 0&&(e.fixedLeftColumnCount=0),e.fixedRightColumnCount===void 0&&(e.fixedRightColumnCount=0),e.rowCheckboxVisible===void 0&&(e.rowCheckboxVisible=!1),e.overridingColumnWidth===void 0&&(e.overridingColumnWidth=-1),!e.getSelectionModel&&((b=e.tableOptions)!=null&&b.getSelectionModel)&&(e.getSelectionModel=(y=e.tableOptions)==null?void 0:y.getSelectionModel),new Ke(e.headerAreaModel,e.bodyAreaModel,e.footerAreaModel??new ae("footer"),e.fixedLeftColumnCount,e.fixedRightColumnCount,e.rowCheckboxVisible,e.defaultRowHeights,e.columnDefs,e.columnSizes,e.overridingColumnWidth,e.columnCount,e.parentSize,e.getSelectionModel)}static checkFooterAggregates(e){var t;if(e.footerAggregates){if(e.footerAreaModel){console.warn("TableFactory.createTableModel: footerAggregates is ignored – an own footerAreaModel is given.");return}return(t=e.footerData)!=null&&t.length&&console.warn("TableFactory.createTableModel: footerData is ignored – footerAggregates builds the footer."),e.footerAggregates}}static addRowNumberColumn(e){var i,r;if(!e.rowNumbersVisible)return;if(e.bodyData||e.headerAreaModel||e.bodyAreaModel||e.footerAreaModel){console.warn("TableFactory.createTableModel: rowNumbersVisible is ignored with bodyData or own area models (their columns would shift) – put a RowNumberColumnDef into the column definitions yourself.");return}const t=e.columnDefs??[];if(O(t[0]))return;const s=e.rowNumbersVisible===!0?{}:e.rowNumbersVisible,o=new ds(s);if(e.columnDefs=[o,...t],e.fixedLeftColumnCount=(e.fixedLeftColumnCount??0)+1,e.columnCount!==void 0&&e.columnCount++,(i=e.headerData)!=null&&i.length){const l=e.headerData.length-1;e.headerData=e.headerData.map((a,c)=>[c===l?o.headerLabel:"",...a])}(r=e.footerData)!=null&&r.length&&(e.footerData=e.footerData.map(l=>["",...l]))}static buildByTypedRowsParam(e){return ye.buildByTypedRows(e.rows??[],e.columnDefs,e.tableOptions??new je,e.fixedLeftColumnCount??0,e.fixedRightColumnCount??0)}static buildByTypedRows(e,t,s=new je,o=0,i=0){var c;const r=s.defaultRowHeights,l=((c=t[Zt(t)])==null?void 0:c.property)==="CheckboxColumn";if(e!=null&&e.length&&U(e[0])){const h=e,d=new rt("body",h,r.body,t);return(l||s.showCheckboxWihoutExtraColumn)&&(d.rowSelectionModel=new Rt(h)),ye.createByAreaModelsParam({headerAreaModel:new Q("header",[t.map(u=>u.headerLabel)],r.header),bodyAreaModel:d,footerAreaModel:new Q("footer",[],r.footer),columnDefs:t,fixedLeftColumnCount:o,fixedRightColumnCount:i,defaultRowHeights:s.defaultRowHeights,rowCheckboxVisible:!1,columnSizes:[],columnCount:t.length,overridingColumnWidth:-1})}return ye.createByObjectArrayParam({rows:e,columnDefs:t,fixedLeftColumnCount:o,fixedRightColumnCount:i,defaultRowHeights:s.defaultRowHeights})}static createByObjectArrayParam(e){const t=e.rowCheckboxVisible!==void 0?e.rowCheckboxVisible:!1;return ye.createByObjectArray(e.rows,e.header??[],e.footer??[],e.fixedLeftColumnCount??0,e.fixedRightColumnCount??0,t,e.defaultRowHeights??new Le,e.columnDefs??[],e.columnSizes??[])}static createByAreaModels(e=new ae,t,s=new ae,o=0,i=0,r=!1,l=new Le,a,c=[],h=-1,d){return new Ke(e,t,s,o,i,r,l,a,c,h,d)}static createByAreaModelsParam(e){return ye.createByAreaModels(e.headerAreaModel??new ae,e.bodyAreaModel,e.footerAreaModel??new ae,e.fixedLeftColumnCount??0,e.fixedRightColumnCount??0,e.rowCheckboxVisible===void 0?!1:e.rowCheckboxVisible,e.defaultRowHeights,e.columnDefs??[],e.columnSizes??[],e.overridingColumnWidth??-1,e.columnCount??0)}static createByObjectArray(e,t=[],s=[],o=0,i=0,r=!1,l=new Le,a,c=[]){let h;t!=null&&t.length?h=new Q("header",t,l.header,a):a!=null&&a.length?h=new Q("header",[a.map(f=>f.headerLabel)],l.header,a):h=new ae;const d=s?new Q("footer",s,l.footer,a):new ae,u=new jo("body",e,a,l.body);return new Ke(h,u,d,o,i,r,l,a,c)}}class Fl{constructor(e,t,s=200,o=300,i=0,r=0){this.items=e,this.cellRenderer=t,this.coverWidth=s,this.coverHeight=o,this.width=i,this.firstRowPaddingTop=r,this.rowSelectionModel=void 0,this.areaIdent="body",this.filteredItems=[],this.sorterService=new di,this.filteredItems=e}setParentWidth(e){this.width=e}getRowCount(){var e;return(e=this.filteredItems)!=null&&e.length?Math.floor(this.filteredItems.length/this.getColumnCount())+1:0}getUnfilteredRowCount(){var e;return(e=this.items)!=null&&e.length?Math.floor(this.items.length/this.getColumnCount())+1:0}getColumnCount(){return this.width?Math.floor(this.width/this.coverWidth):1}getValueAt(e,t){var s;return(s=this.filteredItems)==null?void 0:s[e*this.getColumnCount()+t]}getTextValueAt(e,t){return""}getTooltipAt(e,t){return""}getRowHeight(e){return e===0&&this.firstRowPaddingTop>0?this.firstRowPaddingTop+this.coverHeight:this.coverHeight}getCellRenderer(e,t){return this.cellRenderer}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){return[]}getCustomStyleAt(e,t){}getRowspanAt(e,t){return 0}getRowByIndex(e){}isRowCheckable(e){return!0}isRowChecked(e){}setRowChecked(e,t){}getMaxColspan(){return 31}getMaxRowspan(){return 31}getYPosByRowIndex(e){const t=this.firstRowPaddingTop>0?this.firstRowPaddingTop:0;return this.coverHeight*e+t}init(){}externalFilterChanged(e){this.filteredItems=this.items.filter(e)}isFilterable(){return!0}doSort(e){if(!this.filteredItems)return!1;for(const t of e){const{sortState:s}=t,o=s==="asc"?1:s==="desc"?-1:0;this.filteredItems=this.filteredItems.sort((i,r)=>this.sorterService.genericSortComparator(i,r,o))}return!0}sort(e){this.filteredItems=this.filteredItems.sort(e)}isEditable(e,t){return!1}setValue(e,t,s){return!0}isSelectable(e,t){return!1}changeColumnOrder(e,t){}setPropertyValue(e,t,s){return!1}arrayMove(e,t,s){}}class Ll{constructor(e,t=0){this.bodyModel=e,this.paddingTop=t,this.headerAreaModel=new ae,this.footerAreaModel=new ae}changeColumnOrder(e,t){}isSortable(e){return!1}init(){}setParentWidth(e){this.bodyModel.width=e}getColumnCount(){return this.bodyModel.getColumnCount()}getXPosByColumnIndex(e){return e*this.getColumnWidth(e)}getAreaModel(e){return e==="header"?this.headerAreaModel:e==="footer"?this.footerAreaModel:this.bodyModel}getBodyModel(){return this.bodyModel}getFixedLeftColumnCount(){return 0}getFixedRightColumnCount(){return 0}isHeaderVisibe(){return!1}isFooterVisibe(){return!1}isRowCheckboxVisible(){return!1}getRowHeight(e,t){return this.bodyModel.getRowHeight(t)}getColumnDef(e){}getColumnDefs(){}getColumnProperty(e){return""}getBodyRowByIndex(e){return this.bodyModel.getRowByIndex(e)}getColumnWidth(e){return this.bodyModel.coverWidth}setColumnWidth(e,t){this.bodyModel.coverWidth=t}recalcSize(e){}recalcPadding(){}recalcHeightAndPadding(){}getPadding(){return new Es(0,0,0,0)}getContentHeightInPixel(){return this.paddingTop+this.bodyModel.getRowCount()*this.bodyModel.coverHeight}getContentWidthInPixel(){return this.bodyModel.getColumnCount()*this.bodyModel.coverWidth}externalFilterChanged(e){this.bodyModel.externalFilterChanged(e)}doSort(e){return this.bodyModel.doSort(e)}sort(e){this.bodyModel.sort(e)}getSelectionModel(){}setTableScope(e){this.tableScope=e}getTableScope(){return this.tableScope}}class Ol{constructor(){this.autoRestoreSortingState=!1,this.autoRestoreCollapsedExpandedState=!1,this.autoRestoreScrollPosition=!1,this.autoRestoreCheckedState=!1,this.autoRestoreSelectedState=!1,this.autoRestoreColumnLayout=!1,this.autoRestoreHeaderGroupState=!1,this.autoRestoreCustomState=!1,this.autoRestoreDetailState=!1,this.getStorageKeyFn=void 0,this.isSame=(e,t,s)=>{if(e&&t&&s.getRowId){const o=s.getRowId(e),i=s.getRowId(t);return o===i}return!1},this.getRowId=xc(e=>{if(e){for(const t of["id","uuid"]){const s=e[t];if(s!=null)return s}try{return JSON.stringify(e)}catch(t){console.error(t)}}return console.warn("autoRestoreOptions: getRowId() got no row – set an own getRowId (row, rowIndex) for models without row objects."),-1})}}class id{static createCoverGridModel(e,t,s=200,o=300,i=0,r=0){const l=new Fl(e,t,s,o,i,r);return new Ll(l,r)}static createCoverGrisDefaultOptions(e,t=()=>"CoverGrid"){return{...new je,horizontalBorderVisible:!1,verticalBorderVisible:!1,footerSeparatorBorderVisible:!1,headerSeparatorBorderVisible:!1,fixedEastSeparatorBorderVisible:!1,fixedWestSeparatorBorderVisible:!1,tableTopBorderVisible:!1,tableBottomBorderVisible:!1,hoverColumnVisible:!1,hoverRowVisible:!1,defaultRowHeights:{header:0,body:e,footer:0},autoRestoreOptions:{...new Ol,getStorageKeyFn:t,autoRestoreCollapsedExpandedState:!1,autoRestoreScrollPosition:!0,autoRestoreSortingState:!1,autoRestoreSelectedState:!1}}}}const rd=["COPY_2_CLIPBOARD","START_EDITING","TOGGLE_SELECTION","SELECT_ALL","DESELECT_ALL","NAVIGATE_LEFT","NAVIGATE_RIGHT","NAVIGATE_UP","NAVIGATE_DOWN","NAVIGATE_ROW_START","NAVIGATE_ROW_END","NAVIGATE_FIRST_CELL","NAVIGATE_LAST_CELL","NAVIGATE_PAGE_UP","NAVIGATE_PAGE_DOWN","ACTIVATE_CELL","MOVE_ROW_UP","MOVE_ROW_DOWN","FILL_DOWN","FILL_RIGHT","NAVIGATE_NEXT_CELL","NAVIGATE_PREVIOUS_CELL","EXTEND_SELECTION_UP","EXTEND_SELECTION_DOWN","EXTEND_SELECTION_LEFT","EXTEND_SELECTION_RIGHT","EXTEND_SELECTION_ROW_START","EXTEND_SELECTION_ROW_END","EXTEND_SELECTION_PAGE_UP","EXTEND_SELECTION_PAGE_DOWN","NAVIGATE_DATA_EDGE_UP","NAVIGATE_DATA_EDGE_DOWN","NAVIGATE_DATA_EDGE_LEFT","NAVIGATE_DATA_EDGE_RIGHT","EXTEND_TO_DATA_EDGE_UP","EXTEND_TO_DATA_EDGE_DOWN","EXTEND_TO_DATA_EDGE_LEFT","EXTEND_TO_DATA_EDGE_RIGHT","SELECT_ROW","SELECT_COLUMN","CLEAR_CELLS","CLEAR_AND_EDIT","CUT_2_CLIPBOARD","PASTE_FROM_CLIPBOARD","UNDO","REDO"];class Pl{constructor(e,t){this.tableModel=e,this.tableOptions=t}}class Nl{constructor(e,t,s,o,i,r,l){this.emmitDataKey=e,this.emmitCancelKey=t,this.queryId=s,this.filter=o,this.sorting=i,this.startIndex=r,this.endIndex=l}}class nd extends Nl{constructor(e,t,s,o,i,r,l,a){super(e,t,s,o,i,r,l),this.rows=a}}class Vl{constructor(e,t){this.value=e,this.label=t}}class ld{constructor(e,t){this.index=e,this.px=t}}const ad={body:["ge-table-text-align-left"]},cd={body:["ge-table-text-align-center"]},hd={body:["ge-table-text-align-right"]},dd={header:["ge-table-text-align-left"],body:["ge-table-text-align-left"],footer:["ge-table-text-align-left"]},ud={header:["ge-table-text-align-center"],body:["ge-table-text-align-center"],footer:["ge-table-text-align-center"]},fd={header:["ge-table-text-align-right"],body:["ge-table-text-align-right"],footer:["ge-table-text-align-right"]};class Xo{constructor(){this.type="CheckboxCellRenderer"}render(e,t,s,o,i,r,l){if(i.isRowCheckable(t)){l.addClass(e,"ge-table-row-checkbox-div");const a=i.isRowChecked(t);e.innerText="";const c=l.createElement("input");l.setAttribute(c,"type","checkbox"),l.setAttribute(c,"data-area",`${o}`),l.setAttribute(c,"data-row-index",`${t}`),l.setAttribute(c,"data-col-index",`${s}`),l.setAttribute(c,"data-input-type","checkbox"),l.setAttribute(c,"tabindex","-1"),l.addClass(c,"ge-table-row-checkbox"),a==="full"&&(l.setAttribute(c,"checked",""),c.checked=!0),c.indeterminate=a==="semi",l.appendChild(e,c)}}}class gd{constructor(){this.type="CheckboxColumnDef",this.property="CheckboxColumn",this.headerLabel="",this.width=new T(50,"px"),this.minWidth=new T(50,"px"),this.maxWidth=new T(100,"px"),this.rendererMap=new ee(new Xo,new Xo,void 0),this.classes=new ee([],["ge-table-text-align-left"],[])}}class pd{static body(e){return new ee(void 0,e,void 0)}}class md{constructor(e="down",t){this.status=e,this.originalEvent=t}}class bd{constructor(e,t,s,o,i={}){this.area=e,this.rowIndex=t,this.columnIndex=s,this.value=o,this.cssClasses=i}}class _l{constructor(e,t,s,o=!1,i="normal",r=void 0){this.data=e,this.property=t,this.toggle=s,this.closed=o,this.visibility=i,this.children=r,this.impl="CellGroup"}}class Bl extends _l{constructor(e,t=0,s=0,o){super(e.data,e.property,e.toggle,e.closed,e.visibility,e.children),this.rowIndex=t,this.childIndex=s,this.parent=o,this.impl="CellGroupExt",this.children=void 0,this.leftNeighbour=void 0,this.rightNeighbour=void 0,this.id=e.id}ownColumn(){return!!this.property}toString(){return this.data+""}getColumnIndex(){return this.parent?this.parent.getColumnIndex()+this.childIndex:(this.leftNeighbour,0)}isVisible(){return this.parent?this.visibility==="always"?this.parent.isVisible():this.visibility==="normal"||!this.visibility?this.parent.isVisible()&&!this.parent.closed:this.visibility==="inverted"?this.parent.isVisible()&&this.parent.closed:!0:!0}claimsSpace(){return this.isVisible()&&(this.ownColumn()||this.closed)}getColumnCount(e=this,t=0){var s;if(e!=null&&e.claimsSpace()&&t++,(s=e==null?void 0:e.children)!=null&&s.length)for(const o of e.children)t=this.getColumnCount(o,t);return t}getRowSpan(e=this,t){return e!=null&&e.claimsSpace()?t-this.getParentCount(e,0):1}getParentCount(e=this,t=0){return e.parent&&(t=t+1+this.getParentCount(e.parent,t)),t}log(e=10){const t=" ".substring(0,2*this.rowIndex),s=`${this.getColumnIndex()}`,o=`${this.getColumnCount(this)}`,i=`${this.getRowSpan(this,e)}`,r=`${this.getParentCount(this)}`,l=`${t+this.data}
|
|
331
|
+
}`};let zo=Hs;class ze{constructor(e,t=!0,s,o,i=0,r=!1,l=!1){this.data=e,this.expanded=t,this.children=s,this.parent=o,this.deep=i,this.checked=r,this.keep=l,this.type="TreeRow"}}class pt{static buildTreeRows(e,t="children",s=12,o=!0){const i=typeof t=="string"?{childrenProperty:t,deepMaxLimit:s,expanded:o}:t,r=i.childrenProperty??"children",l=i.deepMaxLimit??12,a=pt.toExpandedFn(i.expanded??!0),c=[];for(const h of e){const d=new ze(h,a(h,0),[],void 0,0);c.push(pt.buildTreeRow(h,r,d,0,l,a))}return c}static buildTreeRow(e,t="children",s=new ze(e,!0,[],void 0,0),o=0,i=12,r=!0){var c;const l=pt.toExpandedFn(r),a=e[t];if(a!=null&&a.length&&o>=i)return console.warn("Max deep limit reached: ",o),s;if(a)for(const h of a){const d=new ze(h,l(h,o+1),[],s,o+1);(c=s.children)==null||c.push(d),pt.buildTreeRow(h,t,d,o+1,i,l)}return s}static toExpandedFn(e){return typeof e=="function"?e:()=>e}}const Ah=new T(500,"px"),Eh=new T(400,"px"),Dl=new T(300,"px"),Mh=new T(290,"px"),Th=new T(280,"px"),Ih=new T(270,"px"),Dh=new T(260,"px"),kh=new T(250,"px"),Lh=new T(240,"px"),Fh=new T(230,"px"),Oh=new T(220,"px"),Ph=new T(210,"px"),Ls=new T(200,"px"),Nh=new T(190,"px"),Vh=new T(180,"px"),_h=new T(170,"px"),Bh=new T(160,"px"),$h=new T(150,"px"),Hh=new T(140,"px"),Gh=new T(130,"px"),Wh=new T(120,"px"),Uh=new T(110,"px"),Kh=new T(100,"px"),zh=new T(90,"px"),jh=new T(80,"px"),Xh=new T(70,"px"),Yh=new T(60,"px"),Jh=new T(50,"px"),qh=new T(40,"px"),Zh=new T(30,"px"),Qh=new T(20,"px"),ed=new T(10,"px"),td=new T(0,"px");class kl{flattenTree(e,t=[]){var s;for(const o of e)this.isVisible(o)&&(t.push(o),o.expanded&&((s=o.children)!=null&&s.length)&&this.flattenVisibleChildren(o.children,t));return t}flattenVisibleChildren(e,t){var s;for(const o of e)t.push(o),o.expanded&&((s=o.children)!=null&&s.length)&&this.flattenVisibleChildren(o.children,t)}isVisible(e){return e.parent?e.parent.expanded?this.isVisible(e.parent):!1:!0}}class rt extends as{constructor(e,t,s,o=[]){super(e,o,s),this.areaIdent=e,this.rows=t,this.defaultRowHeight=s,this.columnDefs=o,this.type="AreaModelTree",this.sorterService=new di,this.service=new kl,this.filteredFlattenRows=[],this.flattenRows=[],this.keepMarked=!1,this.showValuesCache=new Map,this.properties=o.map(i=>i.property),this.refreshDisplayedRows()}changeColumnOrder(e,t){this.arrayMove(this.properties,e,t),super.changeColumnOrder(e,t)}recalcVisibleTreeRows(e=!0){this.refreshDisplayedRows(e)}getDisplayedRootRows(){return this.lastPredictFn?this.rows.filter(e=>e.keep):this.rows}hasDisplayedChildren(e){var t;return(t=e.children)!=null&&t.length?!this.lastPredictFn||e.children.some(s=>s.keep):!1}getDisplayedChildren(e){var t;return(t=e.children)!=null&&t.length?this.lastPredictFn?e.children.filter(s=>s.keep):e.children:[]}getLeafRows(e=!0){const t=!e||!this.lastPredictFn;return this.collectAllRows(this.rows??[],[]).filter(s=>{var o;return!((o=s.children)!=null&&o.length)&&(t||s.keep)})}getFilteredFlattenRows(){return this.filteredFlattenRows}getRowCount(){return this.filteredFlattenRows.length}getUnfilteredRowCount(){return this.flattenRows.length}canMoveRows(e,t){if(this.getRowCount()!==this.getUnfilteredRowCount())return!1;const s=this.getDragRows(e);return s.length>0&&gi(s,this.getRowByIndex(t.rowIndex))}moveRows(e,t){if(!this.canMoveRows(e,t))return!1;const s=this.getRowByIndex(t.rowIndex),o=Yr(this.rows,this.getDragRows(e),s,t.position);return o&&(this.showValuesCache.clear(),this.invalidateColumnValues(),this.refreshDisplayedRows(!0)),o}getDragRows(e){const t=it(e,this.getRowCount()).map(s=>this.getRowByIndex(s)).filter(s=>!!s);return fi(t)}getValueAt(e,t){const s=this.getRowByIndex(e);if(s){const o=this.properties[t];if(o){const i=this.getRawValueOfRow(s,o),r=this.getColumnValues().getShowValuesAs(o);return r?this.applyShowValuesAs(s,o,i,r):i}}return""}getRawValueOfRow(e,t){return this.getColumnValues().getter(t)?this.getColumnValues().get(e.data,t):t.includes(".")?this.getPropertyValue(e.data,t.split(".")):e.data[t]}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={byRow:new Map},this.showValuesCache.set(t,i)),o.mode){case"percentOfColumnTotal":case"percentOfGrandTotal":return i.total===void 0&&(i.total=qs(this.getLeafRows(!0).map(r=>this.getRawValueOfRow(r,t)))),typeof s=="number"&&!Number.isNaN(s)&&i.total!==0?s/i.total:void 0;case"percentOfRowTotal":return s;default:{if(!i.byRow.has(e)){const r=e.parent?this.getDisplayedChildren(e.parent):this.getDisplayedRootRows(),l=hi(r.map(a=>this.getRawValueOfRow(a,t)),o.mode);r.forEach((a,c)=>i.byRow.set(a,l[c]))}return i.byRow.get(e)}}}readPropertyPath(e,t){return t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}getAggregationSourceForValues(){return{signal:this.rows,length:this.rows.length,rows:()=>this.getLeafRows(!0).map(e=>e.data)}}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.getRowHeight===rt.prototype.getRowHeight&&this.defaultRowHeight>0?this.defaultRowHeight:void 0}getCustomClassesAt(e,t){const s=this.filteredFlattenRows[e];return this.addCalculatedClasses(["ge-table-tree-cell","ge-table-tree-deep-"+s.deep],this.properties[t],()=>this.getValueAt(e,t))}getRowByIndex(e){return this.filteredFlattenRows[e]}getValueByT(e,t){if(!e||!t)return;const s=this.getColumnValues();return s.getter(t)?s.get(e,t):t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}externalFilterChanged(e){this.lastPredictFn=e,this.showValuesCache.clear(),this.invalidateColumnValues(),this.refreshDisplayedRows(!0)}doSort(e){if(!e.length)return!1;const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.genericTreeTableSortComparator(this.properties[s],i)});return this.showValuesCache.clear(),this.treeSortWith(this.rows,(s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}),this.refreshDisplayedRows(!1),!0}sort(e){this.showValuesCache.clear(),this.treeSortWith(this.rows,e),this.refreshDisplayedRows(!1)}toggleExpandCollapseAll(e){this.expandAllRecursive(this.rows,e),this.refreshDisplayedRows(!1)}setAllParentsOk(e){return e.parent&&(e.parent.keep=!0,this.setAllParentsOk(e.parent)),!1}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.getRowByIndex(e);if(i){const l=i.data,a=this.columnDefs[t];if(this.areaIdent==="body"&&(a!=null&&a.valueGetter))return this.setCalculatedValue(l,a,s);const c=this.columnDefs[t].property;return c.includes(".")?this.setPropertyValue(l,c.split("."),s):(l[c]=s,!0)}return!1}genericTreeTableSortComparator(e,t){const s=this.columnDefs.find(l=>l.property===e),o=this.getColumnValues().isCalculated(e),i=o?new Map:void 0,r=l=>{if(!i)return this.getValueByT(l,e);if(i.has(l))return i.get(l);const a=this.getValueByT(l,e),c=w(a)?void 0:a;return i.set(l,c),c};return(l,a)=>{const c=r(l.data),h=r(a.data);return o&&(c===void 0||h===void 0)?c===h?0:c===void 0?1:-1:s!=null&&s.sortComparator?t*s.sortComparator(c,h,l.data,a.data,t):this.sorterService.genericSortComparator(c,h,t)}}expandAllRecursive(e,t){for(const s of e)s.expanded=t,s.children&&this.expandAllRecursive(s.children,t)}refreshDisplayedRows(e=!0){if(this.flattenRows=this.service.flattenTree(this.rows??[]),!this.lastPredictFn){this.filteredFlattenRows=[...this.flattenRows];return}(e||!this.keepMarked)&&(this.markKeptRows(this.lastPredictFn),this.keepMarked=!0),this.filteredFlattenRows=this.flattenRows.filter(t=>t.keep)}markKeptRows(e){const t=this.collectAllRows(this.rows??[],[]);t.forEach(s=>s.keep=!1),t.forEach((s,o)=>{if(e(s,o,t)){s.keep=!0;for(let i=s.parent;i&&!i.keep;i=i.parent)i.keep=!0}})}collectAllRows(e,t){var s;for(const o of e)t.push(o),(s=o.children)!=null&&s.length&&this.collectAllRows(o.children,t);return t}getPropertyValue(e,t){const s=t.shift();let o=e[s];return o&&t.length?this.getPropertyValue(o,t):o}treeSortWith(e,t){e.sort(t);for(const s of e)s.children&&this.treeSortWith(s.children,t)}}class jo extends K{constructor(e,t,s,o,i="ge-selected-row",r="ge-focused-row"){super(e,t,o,s,i,r),this.areaIdent=e,this.rows=t,this.columnDefs=s,this.defaultRowHeight=o}}class Ii{constructor(){this.areaIdent="body",this.rowSelectionModel=void 0}changeColumnOrder(e,t){}doSort(e){return!1}sort(e){}externalFilterChanged(e){}getCellRenderer(e,t){}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){return[]}getCustomStyleAt(e,t){}getMaxColspan(){return 0}getMaxRowspan(){return 0}getRowByIndex(e){}getRowCount(){return 0}getRowHeight(e){return 0}getRowspanAt(e,t){return 0}getTooltipAt(e,t){}getValueAt(e,t){}getTextValueAt(e,t){return""}getYPosByRowIndex(e){const t=this.getConstantRowHeight();if(t!==void 0&&t>0)return e*t;let s=0;for(let o=0;o<e;o++)s+=this.getRowHeight(o);return s}getConstantRowHeight(){}init(){}isEditable(e,t){return!1}isFilterable(){return!1}isRowCheckable(e){return!1}isRowChecked(e){}isSelectable(e,t){return!0}setRowChecked(e,t){}setValue(e,t,s){return!1}}const sd={sum:"Sum",count:"Count",avg:"Average",min:"Min",max:"Max",countDistinct:"Distinct",first:"First",last:"Last"},od=new Intl.NumberFormat("en-US");class is extends Ii{constructor(e,t,s){super(),this.columnDefs=t,this.type="AreaModelAggregateFooter",this.textRenderer=new kt,this.areaIdent="footer",this.getBody=typeof e=="function"?e:()=>e,this.options=is.toOptions(s),this.defaultRowHeight=this.options.rowHeight??34,this.footerRows=this.options.rows.map(o=>{const i=Object.keys(o.aggregates).map(r=>ls(r,o.aggregates[r]));return{row:o,specs:i,byKey:new Map(i.map(r=>[r.key,r]))}})}static toOptions(e){if(Array.isArray(e))return{rows:e};const t=e;return Array.isArray(t.rows)?t:{rows:[{aggregates:e}]}}getRowCount(){return this.footerRows.length}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.defaultRowHeight}invalidateDerivedValues(){this.cache=void 0}getResults(e=0){return this.compute().results[e]??{}}getAggregationRowCount(){return this.compute().rowCount}isLabelCell(e,t){return e>=0&&e<this.footerRows.length&&this.getLabelColumnIndex(e)===t}getValueAt(e,t){var i;const s=this.footerRows[e],o=(i=this.columnDefs[t])==null?void 0:i.property;return!s||o===void 0?"":s.byKey.has(o)?this.getResults(e)[o]:this.isLabelCell(e,t)?this.getLabel(e):""}getTextValueAt(e,t){var r;const s=this.footerRows[e],o=(r=this.columnDefs[t])==null?void 0:r.property;if(!s||o===void 0)return"";const i=s.byKey.get(o);if(i){const l=this.getResults(e)[o];return i.format?i.format(l):It(l)}return this.isLabelCell(e,t)?this.getLabel(e):""}getCellRenderer(e,t){var i,r;const s=(i=this.columnDefs[t])==null?void 0:i.property,o=this.footerRows[e];if(!(!o||s===void 0))return o.byKey.has(s)?((r=this.columnDefs[t].rendererMap)==null?void 0:r.footer)??this.textRenderer:this.isLabelCell(e,t)?this.textRenderer:void 0}getCustomClassesAt(e,t){var r,l;const s=(r=this.columnDefs[t])==null?void 0:r.property;if(s!==void 0&&((l=this.footerRows[e])!=null&&l.byKey.has(s)))return["ge-table-footer-aggregate"];if(!this.isLabelCell(e,t))return[];const o=this.columnDefs[t+1];return!o||!this.footerRows[e].byKey.has(o.property)?["ge-table-footer-label","ge-table-footer-label-overflow"]:["ge-table-footer-label"]}getLabelColumnIndex(e){const t=this.footerRows[e].byKey,s=this.options.labelProperty;return s!==void 0?t.has(s)?-1:this.columnDefs.findIndex(o=>o.property===s):this.columnDefs.findIndex(o=>{var i;return!O(o)&&!me(o)&&((i=o.isVisible)==null?void 0:i.call(o))!==!1&&!t.has(o.property)})}getLabel(e){const{row:t,specs:s}=this.footerRows[e],o=this.getAggregationRowCount();if(typeof t.label=="string")return t.label;if(typeof t.label=="function")return t.label(o,this.getResults(e));if(this.footerRows.length>1&&s.length){const i=s[0].aggregator.name,r=sd[i];if(r&&s.every(l=>l.aggregator===Oe[i]))return r}return`${od.format(o)} ${o===1?"row":"rows"}`}getSource(){const e=this.getBody(),t=this.options.getRows;if(t)return{signal:t,getRows:()=>t(e)};const s=this.options.source==="all",o=e;if(typeof o.getFilteredRows=="function"&&typeof o.getAllRows=="function"){const r=s?o.getAllRows():o.getFilteredRows();return{signal:r,length:r.length,getRows:()=>r}}if(Z(e)){const r=e;return{signal:r.rows,getRows:()=>r.getLeafRows(!s).map(l=>l.data)}}const i=e.getRowCount();return{signal:void 0,length:i,getRows:()=>i}}createIndexGetter(e,t){if(!t.getValue)return;if(typeof t.value=="string"){const o=this.columnDefs.findIndex(i=>i.property===t.value);if(o>=0)return i=>e.getValueAt(i,o)}const s=ns(t.value);return o=>s(e.getRowByIndex(o))}withCalculatedValues(e){const t=this.getBody();return typeof t.isCalculatedProperty!="function"||typeof t.getRowValue!="function"?e:e.map(s=>{const o=s.value;return!s.getValue||typeof o!="string"||!t.isCalculatedProperty(o)?s:{...s,getValue:i=>t.getRowValue(i,o)}})}compute(){const e=this.getSource(),t=this.cache;if(t&&t.signal===e.signal&&t.length===e.length)return t;const s=e.getRows(),o=this.withCalculatedValues(this.footerRows.flatMap(c=>c.specs));let i;if(typeof s=="number"){const c=this.getBody();i=va(s,o.map(h=>({aggregator:h.aggregator,getValue:this.createIndexGetter(c,h)})))}else i=Ys(s,o);let r=0;const l=this.footerRows.map(c=>{const h={};for(const d of c.specs)h[d.key]=d.aggregator.result(i[r++]);return h}),a=typeof s=="number"?s:s.length;return this.cache={signal:e.signal,length:e.length,rowCount:a,results:l},this.cache}}class ye{static createTableModel(e){var s,o,i,r,l,a,c,h,d,u,f,g,p,m,b,y;if(e.defaultRowHeights===void 0)if((s=e.tableOptions)!=null&&s.defaultRowHeights)e.defaultRowHeights=e.tableOptions.defaultRowHeights;else{if(e.defaultRowHeights=new Fe,e.headerAreaModel&&"defaultRowHeight"in e.headerAreaModel){const C=e.headerAreaModel.defaultRowHeight;C>-1&&(e.defaultRowHeights.header=C)}if(e.bodyAreaModel&&"defaultRowHeight"in e.bodyAreaModel){const C=e.bodyAreaModel.defaultRowHeight;C>-1&&(e.defaultRowHeights.body=C)}if(e.footerAreaModel&&"defaultRowHeight"in e.footerAreaModel){const C=e.footerAreaModel.defaultRowHeight;C>-1&&(e.defaultRowHeights.footer=C)}}if(e.columnDefs===void 0&&((o=e.properties)!=null&&o.length?e.columnDefs=e.properties.map(C=>new be(C,C.toUpperCase(),Ls)):(i=e.rows)!=null&&i.length?e.columnDefs=Object.keys(e.rows[0]).map(C=>new be(C,C.toUpperCase(),Ls)):e.columnDefs=[]),ye.addRowNumberColumn(e),e.rowDrag){const C=(r=e.columnDefs)==null?void 0:r.find(S=>!O(S)&&!me(S));C&&(C.rowDrag=C.rowDrag||!0)}if(e.columnCount===void 0&&((l=e.columnDefs)!=null&&l.length?e.columnCount=e.columnDefs.length:(a=e.headerData)!=null&&a.length?e.columnCount=e.headerData[0].length:(c=e.columnSizes)!=null&&c.length?e.columnCount=(h=e.columnSizes)==null?void 0:h.length:console.warn('Property "columnCount" is missing and cannot be derived from other properties.')),e.headerAreaModel)e.columnLetters&&console.warn("columnLetters: only with the default header (labels or headerData), not with an own headerAreaModel.");else if((d=e.headerData)!=null&&d.length?e.headerAreaModel=new Q("header",e.headerData,e.defaultRowHeights.header,e.columnDefs):(u=e.columnDefs)!=null&&u.length?e.headerAreaModel=new Q("header",[e.columnDefs.map(C=>C.headerLabel)],e.defaultRowHeights.header,e.columnDefs):e.headerAreaModel=new ae("header"),e.columnLetters&&e.headerAreaModel instanceof Q){let C=0;const S=(e.columnDefs??[]).map(E=>O(E)||me(E)?"":Pe(C++));e.headerAreaModel=new vi("header",[S,...e.headerAreaModel.arr],e.defaultRowHeights.header,e.columnDefs)}const t=ye.checkFooterAggregates(e);if(!e.footerAreaModel&&!t&&((f=e.footerData)!=null&&f.length?e.footerAreaModel=new Q("footer",e.footerData,e.defaultRowHeights.footer,e.columnDefs):e.footerAreaModel=new ae("footer")),!e.bodyAreaModel)if(e.rows)if((g=e.rows)!=null&&g.length&&U(e.rows[0])){const C=e.rows;e.bodyAreaModel=new rt("body",C,e.defaultRowHeights.body,e.columnDefs),(((p=e.columnDefs[Zt(e.columnDefs)])==null?void 0:p.property)==="CheckboxColumn"||(m=e.tableOptions)!=null&&m.showCheckboxWihoutExtraColumn)&&(e.bodyAreaModel.rowSelectionModel=new Rt(C))}else e.bodyAreaModel=new jo("body",e.rows,e.columnDefs,e.defaultRowHeights.body);else e.bodyData?e.bodyAreaModel=new Q("body",e.bodyData,e.defaultRowHeights.body):e.bodyAreaModel=new ae("body");if(t){const C=is.toOptions(t);e.footerAreaModel=new is(e.bodyAreaModel,e.columnDefs??[],{...C,rowHeight:C.rowHeight??e.defaultRowHeights.footer})}return e.fixedLeftColumnCount===void 0&&(e.fixedLeftColumnCount=0),e.fixedRightColumnCount===void 0&&(e.fixedRightColumnCount=0),e.rowCheckboxVisible===void 0&&(e.rowCheckboxVisible=!1),e.overridingColumnWidth===void 0&&(e.overridingColumnWidth=-1),!e.getSelectionModel&&((b=e.tableOptions)!=null&&b.getSelectionModel)&&(e.getSelectionModel=(y=e.tableOptions)==null?void 0:y.getSelectionModel),new Ke(e.headerAreaModel,e.bodyAreaModel,e.footerAreaModel??new ae("footer"),e.fixedLeftColumnCount,e.fixedRightColumnCount,e.rowCheckboxVisible,e.defaultRowHeights,e.columnDefs,e.columnSizes,e.overridingColumnWidth,e.columnCount,e.parentSize,e.getSelectionModel)}static checkFooterAggregates(e){var t;if(e.footerAggregates){if(e.footerAreaModel){console.warn("TableFactory.createTableModel: footerAggregates is ignored – an own footerAreaModel is given.");return}return(t=e.footerData)!=null&&t.length&&console.warn("TableFactory.createTableModel: footerData is ignored – footerAggregates builds the footer."),e.footerAggregates}}static addRowNumberColumn(e){var i,r;if(!e.rowNumbersVisible)return;if(e.bodyData||e.headerAreaModel||e.bodyAreaModel||e.footerAreaModel){console.warn("TableFactory.createTableModel: rowNumbersVisible is ignored with bodyData or own area models (their columns would shift) – put a RowNumberColumnDef into the column definitions yourself.");return}const t=e.columnDefs??[];if(O(t[0]))return;const s=e.rowNumbersVisible===!0?{}:e.rowNumbersVisible,o=new ds(s);if(e.columnDefs=[o,...t],e.fixedLeftColumnCount=(e.fixedLeftColumnCount??0)+1,e.columnCount!==void 0&&e.columnCount++,(i=e.headerData)!=null&&i.length){const l=e.headerData.length-1;e.headerData=e.headerData.map((a,c)=>[c===l?o.headerLabel:"",...a])}(r=e.footerData)!=null&&r.length&&(e.footerData=e.footerData.map(l=>["",...l]))}static buildByTypedRowsParam(e){return ye.buildByTypedRows(e.rows??[],e.columnDefs,e.tableOptions??new je,e.fixedLeftColumnCount??0,e.fixedRightColumnCount??0)}static buildByTypedRows(e,t,s=new je,o=0,i=0){var c;const r=s.defaultRowHeights,l=((c=t[Zt(t)])==null?void 0:c.property)==="CheckboxColumn";if(e!=null&&e.length&&U(e[0])){const h=e,d=new rt("body",h,r.body,t);return(l||s.showCheckboxWihoutExtraColumn)&&(d.rowSelectionModel=new Rt(h)),ye.createByAreaModelsParam({headerAreaModel:new Q("header",[t.map(u=>u.headerLabel)],r.header),bodyAreaModel:d,footerAreaModel:new Q("footer",[],r.footer),columnDefs:t,fixedLeftColumnCount:o,fixedRightColumnCount:i,defaultRowHeights:s.defaultRowHeights,rowCheckboxVisible:!1,columnSizes:[],columnCount:t.length,overridingColumnWidth:-1})}return ye.createByObjectArrayParam({rows:e,columnDefs:t,fixedLeftColumnCount:o,fixedRightColumnCount:i,defaultRowHeights:s.defaultRowHeights})}static createByObjectArrayParam(e){const t=e.rowCheckboxVisible!==void 0?e.rowCheckboxVisible:!1;return ye.createByObjectArray(e.rows,e.header??[],e.footer??[],e.fixedLeftColumnCount??0,e.fixedRightColumnCount??0,t,e.defaultRowHeights??new Fe,e.columnDefs??[],e.columnSizes??[])}static createByAreaModels(e=new ae,t,s=new ae,o=0,i=0,r=!1,l=new Fe,a,c=[],h=-1,d){return new Ke(e,t,s,o,i,r,l,a,c,h,d)}static createByAreaModelsParam(e){return ye.createByAreaModels(e.headerAreaModel??new ae,e.bodyAreaModel,e.footerAreaModel??new ae,e.fixedLeftColumnCount??0,e.fixedRightColumnCount??0,e.rowCheckboxVisible===void 0?!1:e.rowCheckboxVisible,e.defaultRowHeights,e.columnDefs??[],e.columnSizes??[],e.overridingColumnWidth??-1,e.columnCount??0)}static createByObjectArray(e,t=[],s=[],o=0,i=0,r=!1,l=new Fe,a,c=[]){let h;t!=null&&t.length?h=new Q("header",t,l.header,a):a!=null&&a.length?h=new Q("header",[a.map(f=>f.headerLabel)],l.header,a):h=new ae;const d=s?new Q("footer",s,l.footer,a):new ae,u=new jo("body",e,a,l.body);return new Ke(h,u,d,o,i,r,l,a,c)}}class Ll{constructor(e,t,s=200,o=300,i=0,r=0){this.items=e,this.cellRenderer=t,this.coverWidth=s,this.coverHeight=o,this.width=i,this.firstRowPaddingTop=r,this.rowSelectionModel=void 0,this.areaIdent="body",this.filteredItems=[],this.sorterService=new di,this.filteredItems=e}setParentWidth(e){this.width=e}getRowCount(){var e;return(e=this.filteredItems)!=null&&e.length?Math.floor(this.filteredItems.length/this.getColumnCount())+1:0}getUnfilteredRowCount(){var e;return(e=this.items)!=null&&e.length?Math.floor(this.items.length/this.getColumnCount())+1:0}getColumnCount(){return this.width?Math.floor(this.width/this.coverWidth):1}getValueAt(e,t){var s;return(s=this.filteredItems)==null?void 0:s[e*this.getColumnCount()+t]}getTextValueAt(e,t){return""}getTooltipAt(e,t){return""}getRowHeight(e){return e===0&&this.firstRowPaddingTop>0?this.firstRowPaddingTop+this.coverHeight:this.coverHeight}getCellRenderer(e,t){return this.cellRenderer}getColspanAt(e,t){return 0}getCustomClassesAt(e,t){return[]}getCustomStyleAt(e,t){}getRowspanAt(e,t){return 0}getRowByIndex(e){}isRowCheckable(e){return!0}isRowChecked(e){}setRowChecked(e,t){}getMaxColspan(){return 31}getMaxRowspan(){return 31}getYPosByRowIndex(e){const t=this.firstRowPaddingTop>0?this.firstRowPaddingTop:0;return this.coverHeight*e+t}init(){}externalFilterChanged(e){this.filteredItems=this.items.filter(e)}isFilterable(){return!0}doSort(e){if(!this.filteredItems)return!1;for(const t of e){const{sortState:s}=t,o=s==="asc"?1:s==="desc"?-1:0;this.filteredItems=this.filteredItems.sort((i,r)=>this.sorterService.genericSortComparator(i,r,o))}return!0}sort(e){this.filteredItems=this.filteredItems.sort(e)}isEditable(e,t){return!1}setValue(e,t,s){return!0}isSelectable(e,t){return!1}changeColumnOrder(e,t){}setPropertyValue(e,t,s){return!1}arrayMove(e,t,s){}}class Fl{constructor(e,t=0){this.bodyModel=e,this.paddingTop=t,this.headerAreaModel=new ae,this.footerAreaModel=new ae}changeColumnOrder(e,t){}isSortable(e){return!1}init(){}setParentWidth(e){this.bodyModel.width=e}getColumnCount(){return this.bodyModel.getColumnCount()}getXPosByColumnIndex(e){return e*this.getColumnWidth(e)}getAreaModel(e){return e==="header"?this.headerAreaModel:e==="footer"?this.footerAreaModel:this.bodyModel}getBodyModel(){return this.bodyModel}getFixedLeftColumnCount(){return 0}getFixedRightColumnCount(){return 0}isHeaderVisibe(){return!1}isFooterVisibe(){return!1}isRowCheckboxVisible(){return!1}getRowHeight(e,t){return this.bodyModel.getRowHeight(t)}getColumnDef(e){}getColumnDefs(){}getColumnProperty(e){return""}getBodyRowByIndex(e){return this.bodyModel.getRowByIndex(e)}getColumnWidth(e){return this.bodyModel.coverWidth}setColumnWidth(e,t){this.bodyModel.coverWidth=t}recalcSize(e){}recalcPadding(){}recalcHeightAndPadding(){}getPadding(){return new Es(0,0,0,0)}getContentHeightInPixel(){return this.paddingTop+this.bodyModel.getRowCount()*this.bodyModel.coverHeight}getContentWidthInPixel(){return this.bodyModel.getColumnCount()*this.bodyModel.coverWidth}externalFilterChanged(e){this.bodyModel.externalFilterChanged(e)}doSort(e){return this.bodyModel.doSort(e)}sort(e){this.bodyModel.sort(e)}getSelectionModel(){}setTableScope(e){this.tableScope=e}getTableScope(){return this.tableScope}}class Ol{constructor(){this.autoRestoreSortingState=!1,this.autoRestoreCollapsedExpandedState=!1,this.autoRestoreScrollPosition=!1,this.autoRestoreCheckedState=!1,this.autoRestoreSelectedState=!1,this.autoRestoreColumnLayout=!1,this.autoRestoreHeaderGroupState=!1,this.autoRestoreCustomState=!1,this.autoRestoreDetailState=!1,this.getStorageKeyFn=void 0,this.isSame=(e,t,s)=>{if(e&&t&&s.getRowId){const o=s.getRowId(e),i=s.getRowId(t);return o===i}return!1},this.getRowId=xc(e=>{if(e){for(const t of["id","uuid"]){const s=e[t];if(s!=null)return s}try{return JSON.stringify(e)}catch(t){console.error(t)}}return console.warn("autoRestoreOptions: getRowId() got no row – set an own getRowId (row, rowIndex) for models without row objects."),-1})}}class id{static createCoverGridModel(e,t,s=200,o=300,i=0,r=0){const l=new Ll(e,t,s,o,i,r);return new Fl(l,r)}static createCoverGrisDefaultOptions(e,t=()=>"CoverGrid"){return{...new je,horizontalBorderVisible:!1,verticalBorderVisible:!1,footerSeparatorBorderVisible:!1,headerSeparatorBorderVisible:!1,fixedEastSeparatorBorderVisible:!1,fixedWestSeparatorBorderVisible:!1,tableTopBorderVisible:!1,tableBottomBorderVisible:!1,hoverColumnVisible:!1,hoverRowVisible:!1,defaultRowHeights:{header:0,body:e,footer:0},autoRestoreOptions:{...new Ol,getStorageKeyFn:t,autoRestoreCollapsedExpandedState:!1,autoRestoreScrollPosition:!0,autoRestoreSortingState:!1,autoRestoreSelectedState:!1}}}}const rd=["COPY_2_CLIPBOARD","START_EDITING","TOGGLE_SELECTION","SELECT_ALL","DESELECT_ALL","NAVIGATE_LEFT","NAVIGATE_RIGHT","NAVIGATE_UP","NAVIGATE_DOWN","NAVIGATE_ROW_START","NAVIGATE_ROW_END","NAVIGATE_FIRST_CELL","NAVIGATE_LAST_CELL","NAVIGATE_PAGE_UP","NAVIGATE_PAGE_DOWN","ACTIVATE_CELL","MOVE_ROW_UP","MOVE_ROW_DOWN","FILL_DOWN","FILL_RIGHT","NAVIGATE_NEXT_CELL","NAVIGATE_PREVIOUS_CELL","EXTEND_SELECTION_UP","EXTEND_SELECTION_DOWN","EXTEND_SELECTION_LEFT","EXTEND_SELECTION_RIGHT","EXTEND_SELECTION_ROW_START","EXTEND_SELECTION_ROW_END","EXTEND_SELECTION_PAGE_UP","EXTEND_SELECTION_PAGE_DOWN","NAVIGATE_DATA_EDGE_UP","NAVIGATE_DATA_EDGE_DOWN","NAVIGATE_DATA_EDGE_LEFT","NAVIGATE_DATA_EDGE_RIGHT","EXTEND_TO_DATA_EDGE_UP","EXTEND_TO_DATA_EDGE_DOWN","EXTEND_TO_DATA_EDGE_LEFT","EXTEND_TO_DATA_EDGE_RIGHT","SELECT_ROW","SELECT_COLUMN","CLEAR_CELLS","CLEAR_AND_EDIT","CUT_2_CLIPBOARD","PASTE_FROM_CLIPBOARD","UNDO","REDO"];class Pl{constructor(e,t){this.tableModel=e,this.tableOptions=t}}class Nl{constructor(e,t,s,o,i,r,l){this.emmitDataKey=e,this.emmitCancelKey=t,this.queryId=s,this.filter=o,this.sorting=i,this.startIndex=r,this.endIndex=l}}class nd extends Nl{constructor(e,t,s,o,i,r,l,a){super(e,t,s,o,i,r,l),this.rows=a}}class Vl{constructor(e,t){this.value=e,this.label=t}}class ld{constructor(e,t){this.index=e,this.px=t}}const ad={body:["ge-table-text-align-left"]},cd={body:["ge-table-text-align-center"]},hd={body:["ge-table-text-align-right"]},dd={header:["ge-table-text-align-left"],body:["ge-table-text-align-left"],footer:["ge-table-text-align-left"]},ud={header:["ge-table-text-align-center"],body:["ge-table-text-align-center"],footer:["ge-table-text-align-center"]},fd={header:["ge-table-text-align-right"],body:["ge-table-text-align-right"],footer:["ge-table-text-align-right"]};class Xo{constructor(){this.type="CheckboxCellRenderer"}render(e,t,s,o,i,r,l){if(i.isRowCheckable(t)){l.addClass(e,"ge-table-row-checkbox-div");const a=i.isRowChecked(t);e.innerText="";const c=l.createElement("input");l.setAttribute(c,"type","checkbox"),l.setAttribute(c,"data-area",`${o}`),l.setAttribute(c,"data-row-index",`${t}`),l.setAttribute(c,"data-col-index",`${s}`),l.setAttribute(c,"data-input-type","checkbox"),l.setAttribute(c,"tabindex","-1"),l.addClass(c,"ge-table-row-checkbox"),a==="full"&&(l.setAttribute(c,"checked",""),c.checked=!0),c.indeterminate=a==="semi",l.appendChild(e,c)}}}class gd{constructor(){this.type="CheckboxColumnDef",this.property="CheckboxColumn",this.headerLabel="",this.width=new T(50,"px"),this.minWidth=new T(50,"px"),this.maxWidth=new T(100,"px"),this.rendererMap=new ee(new Xo,new Xo,void 0),this.classes=new ee([],["ge-table-text-align-left"],[])}}class pd{static body(e){return new ee(void 0,e,void 0)}}class md{constructor(e="down",t){this.status=e,this.originalEvent=t}}class bd{constructor(e,t,s,o,i={}){this.area=e,this.rowIndex=t,this.columnIndex=s,this.value=o,this.cssClasses=i}}class _l{constructor(e,t,s,o=!1,i="normal",r=void 0){this.data=e,this.property=t,this.toggle=s,this.closed=o,this.visibility=i,this.children=r,this.impl="CellGroup"}}class Bl extends _l{constructor(e,t=0,s=0,o){super(e.data,e.property,e.toggle,e.closed,e.visibility,e.children),this.rowIndex=t,this.childIndex=s,this.parent=o,this.impl="CellGroupExt",this.children=void 0,this.leftNeighbour=void 0,this.rightNeighbour=void 0,this.id=e.id}ownColumn(){return!!this.property}toString(){return this.data+""}getColumnIndex(){return this.parent?this.parent.getColumnIndex()+this.childIndex:(this.leftNeighbour,0)}isVisible(){return this.parent?this.visibility==="always"?this.parent.isVisible():this.visibility==="normal"||!this.visibility?this.parent.isVisible()&&!this.parent.closed:this.visibility==="inverted"?this.parent.isVisible()&&this.parent.closed:!0:!0}claimsSpace(){return this.isVisible()&&(this.ownColumn()||this.closed)}getColumnCount(e=this,t=0){var s;if(e!=null&&e.claimsSpace()&&t++,(s=e==null?void 0:e.children)!=null&&s.length)for(const o of e.children)t=this.getColumnCount(o,t);return t}getRowSpan(e=this,t){return e!=null&&e.claimsSpace()?t-this.getParentCount(e,0):1}getParentCount(e=this,t=0){return e.parent&&(t=t+1+this.getParentCount(e.parent,t)),t}log(e=10){const t=" ".substring(0,2*this.rowIndex),s=`${this.getColumnIndex()}`,o=`${this.getColumnCount(this)}`,i=`${this.getRowSpan(this,e)}`,r=`${this.getParentCount(this)}`,l=`${t+this.data}
|
|
332
332
|
childIndex:${this.childIndex}
|
|
333
333
|
row:${this.rowIndex}
|
|
334
334
|
col:${s}
|
|
@@ -345,7 +345,7 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
|
|
|
345
345
|
data-area="${t}"
|
|
346
346
|
data-row-index="${s}"
|
|
347
347
|
data-col-index="${o}"
|
|
348
|
-
>${X(i)}</span>`}addArrowDiv(e,t,s=!0,o=-1,i=-1,r="header",l){const a=e.createElement("div");e.addClass(a,"ge-table-toggle-icon-div"),e.setStyle(a,"display","inline-block"),e.setStyle(a,"position",""),e.setStyle(a,"width","20px"),e.setStyle(a,"background","transparent"),e.setStyle(a,"cursor","pointer"),e.setAttribute(a,"data-row-index",`${o}`),e.setAttribute(a,"data-col-index",`${i}`),e.setAttribute(a,"data-area",`${r}`),e.setAttribute(a,"data-ge-action",`${l}`);let c;s?c=this.headerGroupOptions.iconExpanded:c=this.headerGroupOptions.iconCollapsed;const h=c.content,d=e.createText(h);e.appendChild(a,d),c.style&&this.applyStyleString(e,a,c.style);for(const u of c.classes)e.addClass(a,u);return e.appendChild(t,a),a}applyStyleString(e,t,s){const o=s.split(";").map(i=>i.trim()).filter(i=>i);for(const i of o){const[r,l]=i.split(":");e.setStyle(t,r.trim(),l.trim())}}};Gs.toggleHeaderGroup="toggleHeaderGroup";let
|
|
348
|
+
>${X(i)}</span>`}addArrowDiv(e,t,s=!0,o=-1,i=-1,r="header",l){const a=e.createElement("div");e.addClass(a,"ge-table-toggle-icon-div"),e.setStyle(a,"display","inline-block"),e.setStyle(a,"position",""),e.setStyle(a,"width","20px"),e.setStyle(a,"background","transparent"),e.setStyle(a,"cursor","pointer"),e.setAttribute(a,"data-row-index",`${o}`),e.setAttribute(a,"data-col-index",`${i}`),e.setAttribute(a,"data-area",`${r}`),e.setAttribute(a,"data-ge-action",`${l}`);let c;s?c=this.headerGroupOptions.iconExpanded:c=this.headerGroupOptions.iconCollapsed;const h=c.content,d=e.createText(h);e.appendChild(a,d),c.style&&this.applyStyleString(e,a,c.style);for(const u of c.classes)e.addClass(a,u);return e.appendChild(t,a),a}applyStyleString(e,t,s){const o=s.split(";").map(i=>i.trim()).filter(i=>i);for(const i of o){const[r,l]=i.split(":");e.setStyle(t,r.trim(),l.trim())}}};Gs.toggleHeaderGroup="toggleHeaderGroup";let Fs=Gs;class $l{constructor(e="header",t,s=[],o,i=new Qs){this.areaIdent=e,this.groups=t,this.columnDefs=s,this.defaultRowHeight=o,this.headerGroupOptions=i,this.gammaCells=!0,this.arr=[],this.groupExts=[],this.cellGroupExtCellRenderer=new Fs(this.headerGroupOptions),this.groupExts=ce.buildGroupExts(t),this.init()}sort(e){}init(){var e;this.arr=this.buildArray(),!((e=this.columnDefs)!=null&&e.length)&&this.areaIdent==="header"&&(this.columnDefs=ce.buildColumnDefs(this.groups),this.columnDefs.forEach(t=>po(t,t.isVisible)))}getAllLeafs(){return ce.flattenGroupExts(this.groupExts).filter(t=>!t.children)}getMaxRowCount(){const e=this.getAllLeafs();return e!=null&&e.length?1+Math.max(...e.map(t=>t.getParentCount(t))):0}buildArray(){const e=ce.flattenGroupExts(this.groupExts),t=1+Math.max(...e.map(r=>r.rowIndex)),s=[];ce.iterateThrowColumns(s,this.groupExts);const o=Array.from(Array(t).keys()).map(r=>[]);return ce.buildArrayOfArrays(e,o)}changeColumnOrder(e,t){}doSort(e){return!1}externalFilterChanged(e){}getCellRenderer(e,t){return this.cellGroupExtCellRenderer}getColspanAt(e,t){const s=this.getValueAt(e,t);return s?s.getColumnCount():0}getCustomClassesAt(e,t){return[]}getCustomStyleAt(e,t){}getMaxColspan(){return 12}getMaxRowspan(){return 12}getRowByIndex(e){}getRowCount(){return this.arr?this.arr.length:0}getRowspanAt(e,t){const s=this.getValueAt(e,t);if(s){const o=this.getRowCount();return s.getRowSpan(s,o)}return 0}getTooltipAt(e,t){return""}getValueAt(e,t){return this.arr[e][t]}getTextValueAt(e,t){return""+this.getValueAt(e,t)}getYPosByRowIndex(e){return 0}getRowHeight(e){return this.defaultRowHeight}isEditable(e,t){return!1}isFilterable(){return!1}isRowCheckable(e){return!1}isRowChecked(e){}isSelectable(e,t){return!1}setRowChecked(e,t){}setValue(e,t,s){return!1}toggleHeaderGroup(e){const t=this.arr[e.rowIdx][e.colIdx];return t!=null&&t.toggle&&t.visibility!=="always"&&(t.closed=!t.closed,this.init()),this.mergeColumnDefs()}getToggleGroupStates(){return Array.from(this.getToggleGroups(),([e,t])=>({id:e,closed:!!t.closed}))}setGroupClosed(e,t){const s=this.getToggleGroups().get(e);if(s)return!!s.closed!==t&&(s.closed=t,this.init()),this.mergeColumnDefs()}setGroups(e,t){return this.groups=e,this.groupExts=ce.buildGroupExts(e),t&&(this.columnDefs=t),this.arr=this.buildArray(),this.mergeColumnDefs()}getToggleGroups(){const e=new Map,t=(s,o)=>{var i;for(const r of s??[]){const l=o?o+"/"+String(r.data):String(r.data);if((i=r.children)!=null&&i.length){if(r.toggle&&r.visibility!=="always"){let a=r.id??l;for(let c=2;e.has(a);c++)a=(r.id??l)+"#"+c;e.set(a,r)}t(r.children,l)}}};return t(this.groupExts,""),e}mergeColumnDefs(){const e=ce.buildColumnDefs(this.groupExts),t=new Map(this.columnDefs.map(o=>[o.property,o])),s=e.map(o=>{const i=t.get(o.property);return i?(po(i,o.isVisible),i):(po(o,o.isVisible),o)});return this.columnDefs=s,s}}class Di{constructor(e){this.getStorageKeyFn=e}autoConvertMapToObject(e){const t={};return e instanceof Map&&e.forEach((o,i)=>{t[i]=o}),t}checkAndPersistItem(e,t){const s=this.getStorageKeyFn;if(s){const o=s();if(o){const i=o+e;if((t+"").includes("Map")){const r=this.autoConvertMapToObject(t);this.persistItem(i,r)}else this.persistItem(i,t)}}}persistItem(e,t){try{t?localStorage.setItem(e,JSON.stringify(t)):localStorage.removeItem(e)}catch{}}loadFromLocalStorage(e){try{const t=localStorage.getItem(e);if(t)return JSON.parse(t)}catch{}return null}}class wd extends Di{constructor(e){super(e),this.SCROLL_STATE="scrollState",this.scrollOffset=[0,0],this.load()}getScrollOffset(){return this.scrollOffset}updateScrollOffset(e){this.scrollOffset=e,this.checkAndPersistItem(this.SCROLL_STATE,this.scrollOffset)}load(){const e=this.getStorageKeyFn;if(e){const t=e();if(t){const s=t+this.SCROLL_STATE;let o=this.loadFromLocalStorage(s);this.scrollOffset=o||[0,0]}}}}class Hl{constructor(e="collapsed",t=[],s=!1,o=!1){this.mode=e,this.rowIds=t,this.allCollapsed=s,this.allExpanded=o}}class yd extends Di{constructor(e){super(e),this.COLLAPSED_EXPANDED_STATE="collapsedExpandedState",this.collapsedExpandedState=new Hl,this.stored=!1,this.load()}hasStoredState(){return this.stored}initModeIfEmpty(e){!this.stored&&!this.collapsedExpandedState.rowIds.length&&(this.collapsedExpandedState.mode=e)}collapsedExpandedStateGet(){return this.collapsedExpandedState}collapsedExpandedStateIncludes(e){return this.collapsedExpandedState.rowIds.includes(e)}collapsedStateIdsPush(e){this.collapsedExpandedState.rowIds.includes(e)||(this.collapsedExpandedState.rowIds.push(e),this.collapsedExpandedState.allCollapsed=!1,this.collapsedExpandedState.allExpanded=!1,this.persist())}collapsedStateIdsRemove(e){const t=this.collapsedExpandedState.rowIds.indexOf(e);t!==-1&&(this.collapsedExpandedState.rowIds.splice(t,1),this.collapsedExpandedState.allCollapsed=!1,this.collapsedExpandedState.allExpanded=!1,this.persist())}collapsedStateAll(e){this.collapsedExpandedState.rowIds=[],this.collapsedExpandedState.mode=e?"collapsed":"expanded",this.collapsedExpandedState.allCollapsed=!e,this.collapsedExpandedState.allExpanded=e,this.persist()}load(){const e=this.getStorageKeyFn;if(e){const t=e();if(t){const s=t+this.COLLAPSED_EXPANDED_STATE,o=this.loadFromLocalStorage(s);o&&(this.collapsedExpandedState=o,this.stored=!0)}}}persist(){this.stored=!0,this.checkAndPersistItem(this.COLLAPSED_EXPANDED_STATE,this.collapsedExpandedState)}}class Cd extends Di{constructor(e){super(e),this.SORTING_STATE="sortingState",this.sortItems=[],this.load()}getSortItems(){return this.sortItems}setSortItems(e){this.sortItems=e,this.checkAndPersistItem(this.SORTING_STATE,this.sortItems)}load(){const e=this.getStorageKeyFn;if(e){const t=e();if(t){const s=t+this.SORTING_STATE,o=this.loadFromLocalStorage(s);this.sortItems=o||[]}}}}class Sd{filterPredict(e,t,s=this.objectToString.bind(this)){if(!e)return!1;if(!t)return!0;t=t.toLowerCase();const o="+",i="-",r=t.toLowerCase().split(" ").filter(d=>d!==o&&d!==i&&d!==""),l=r.filter(d=>!d.startsWith(o)&&!d.startsWith(i)),a=r.filter(d=>d.startsWith(o)).map(d=>d.replace(/\+/g,"")),c=r.filter(d=>d.startsWith(i)).map(d=>d.replace(/-/g,""));let h=!l.length;for(let d=0;d<l.length;d++)(h||s(e).includes(l[d]))&&(h=!0);if(!h)return!1;for(let d=0;d<a.length;d++)if(!s(e).includes(a[d]))return!1;for(let d=0;d<c.length;d++)if(s(e).includes(c[d]))return!1;return!0}filterRows(e,t,s=o=>JSON.stringify(o).toLowerCase()){if(!e)return[];if(!t)return[...e];t=t.toLowerCase();const o="+",i="-",r=t.toLowerCase().split(" ").filter(h=>h!==o&&h!==i&&h!==""),l=r.filter(h=>!h.startsWith(o)&&!h.startsWith(i)),a=r.filter(h=>h.startsWith(o)).map(h=>h.replace(/\+/g,"")),c=r.filter(h=>h.startsWith(i)).map(h=>h.replace(/-/g,""));return e==null?void 0:e.filter(h=>{let d=!l.length;for(let u=0;u<l.length;u++)(d||s(h).includes(l[u]))&&(d=!0);if(!d)return!1;for(let u=0;u<a.length;u++)if(!s(h).includes(a[u]))return!1;for(let u=0;u<c.length;u++)if(s(h).includes(c[u]))return!1;return!0})}objectToString(e){if(!e)return"";const t=[],s=Object.keys(e);for(let o=0;o<s.length;o++){const i=s[o];t.push(e[i])}return t.join(" ").toLowerCase()}}class xd{static bodyRenderer(e){return new ee(void 0,e,void 0)}}class vd{constructor(e,t=!0,s=!1){this.property=e,this.skipCheckableCheck=t,this.readonly=s}render(e,t,s,o,i,r,l){if(this.readonly||this.skipCheckableCheck||i.isRowCheckable(t)){l.addClass(e,"ge-table-row-checkbox-div");const a=i.getRowByIndex(t),h=i.getValueByT(a,this.property)===!0?"checked":"",d=this.readonly?" readonly ":"";if(l.addClass(e,"ge-padding-property-checkbox"),e.innerHTML=`
|
|
349
349
|
<input
|
|
350
350
|
type="checkbox"
|
|
351
351
|
data-area="${o}"
|
|
@@ -383,10 +383,10 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
|
|
|
383
383
|
</div>`}}}class Id{constructor(e={true:"Yes",false:"No"}){this.ariaLabels=e}render(e,t,s,o,i,r,l){r==="true"||r===!0?e.innerHTML=`<span class="ge-true-text-color" role="img" aria-label="${X(this.ariaLabels.true)}">✅</span>`:r==="false"||r===!1?e.innerHTML=`<span class="ge-false-text-color" role="img" aria-label="${X(this.ariaLabels.false)}">❌</span>`:e.innerText=""}}class Dd{render(e,t,s,o,i,r,l){if(r){const a=new Date(r);e.innerText=isNaN(a.getTime())?String(r):a.toISOString().replace(/T/g," ").replace(/\..*/g,"")}}}class kd{constructor(e=Number.MIN_SAFE_INTEGER,t=Number.MAX_SAFE_INTEGER){this.min=e,this.max=t}render(e,t,s,o,i,r,l){(r||r===0)&&(e.innerHTML=`
|
|
384
384
|
<div class="ge-table-label-div">
|
|
385
385
|
<div class="ge-table-label">${X(r)}</div>
|
|
386
|
-
</div>`,(typeof r=="string"||isNaN(r)||r<this.min||r>this.max)&&l.addClass(e,"ge-cell-error"))}}class
|
|
386
|
+
</div>`,(typeof r=="string"||isNaN(r)||r<this.min||r>this.max)&&l.addClass(e,"ge-cell-error"))}}class Ld{constructor(e,t=s=>s===1?"1 star":`${s} stars`){this.property=e,this.ariaLabel=t}render(e,t,s,o,i,r,l){l.addClass(e,"ge-star-rating-div");const a=i.getRowByIndex(t),c=+(""+i.getValueByT(a,this.property));if(!isNaN(c)){const h=[];for(let u=0;u<c;u++)h.push("★");const d=h.join(" ");e.innerHTML=`
|
|
387
387
|
<div class="ge-table-label-div" data-row-index="${t}" data-col-index="${s}" data-area="${o}" style="position: relative; background: transparent; width: 100%; height: 100%;">
|
|
388
388
|
<div class="ge-table-label" data-row-index="${t}" data-col-index="${s}" data-area="${o}" role="img" aria-label="${X(this.ariaLabel(c))}">${d}</div>
|
|
389
|
-
</div>`}}}class
|
|
389
|
+
</div>`}}}class Fd{render(e,t,s,o,i,r,l){if(r!=null&&r.length){const a=l.createElement("div");l.addClass(a,"ge-table-label-div"),l.appendChild(e,a);const c=l.createElement("div");l.addClass(c,"ge-table-label"),l.appendChild(a,c);const h=l.createText(r.join(", "));l.appendChild(c,h)}else e.innerText=""}}class Od{constructor(e,t=100,s=!1,o=i=>`${Math.round(i)} %`){this.property=e,this.maxValue=t,this.labelVisible=s,this.ariaLabel=o}render(e,t,s,o,i,r,l){l.addClass(e,"ge-star-rating-div");const a=i.getRowByIndex(t),c=+(""+i.getValueByT(a,this.property));if(!isNaN(c)){const h=c*100/this.maxValue,d=this.labelVisible?Math.round(h)+"%":"";e.innerHTML=`
|
|
390
390
|
<div class="ge-table-label-div"
|
|
391
391
|
data-row-index="${t}"
|
|
392
392
|
data-col-index="${s}"
|
|
@@ -443,7 +443,7 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
|
|
|
443
443
|
${r}
|
|
444
444
|
class="ge-table-cell-action ge-table-cell-link ${e.elementClass}">
|
|
445
445
|
${e.label}
|
|
446
|
-
</a>`}addClickEventListeners(e,t,s){e.querySelectorAll(".ge-table-cell-action").forEach(i=>{i.addEventListener("click",r=>{const l=r.target;if(l){const a=this.createActionEvent(l,s);a&&this.actionEventListener.onActionEvent(a)}})})}createActionEvent(e,t){const s=e.getAttribute("data-area"),o=e.getAttribute("data-row-index"),i=e.getAttribute("data-col-index"),r=e.getAttribute("data-action")??"unknown",l=e.getAttribute("data-id")??"unknown";if(s&&o&&i){const a=rs(s),c=Number(o),h=Number(i);return new ki(r,a,t,c,h,l)}return null}getCrudActions(e){return Array.isArray(e)&&e.every(t=>t instanceof He)?e:this.crudActions}}class
|
|
446
|
+
</a>`}addClickEventListeners(e,t,s){e.querySelectorAll(".ge-table-cell-action").forEach(i=>{i.addEventListener("click",r=>{const l=r.target;if(l){const a=this.createActionEvent(l,s);a&&this.actionEventListener.onActionEvent(a)}})})}createActionEvent(e,t){const s=e.getAttribute("data-area"),o=e.getAttribute("data-row-index"),i=e.getAttribute("data-col-index"),r=e.getAttribute("data-action")??"unknown",l=e.getAttribute("data-id")??"unknown";if(s&&o&&i){const a=rs(s),c=Number(o),h=Number(i);return new ki(r,a,t,c,h,l)}return null}getCrudActions(e){return Array.isArray(e)&&e.every(t=>t instanceof He)?e:this.crudActions}}class Li{constructor(e){this.options=e}static create(e){return new Li(e.map(t=>new Vl(t,t)))}render(e,t,s,o,i,r,l){if(i.isEditable(t,s)){l.addClass(e,"ge-table-row-select-div");const a=r!==void 0?r:i.getValueAt(t,s),c=l.createElement("select");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-select");for(const h of this.options){const d=l.createElement("option");d.value=String(h.value),d.textContent=String(h.label),h.value===a&&(d.selected=!0,d.defaultSelected=!0),l.appendChild(c,d)}e.textContent="",l.appendChild(e,c)}}}class Nd extends Me{constructor(e){super("row","multi"),this.model=e}getSelectedRowItems(e){if(this.isAllSelected()&&!this.negativeRanges.length)return e;const t=new Set(this.getMergedRowIndices(e.length));return e.filter((s,o)=>t.has(o))}selectRow(e){this.addRange(M.singleRow(e))}unselectRow(e){this.removeSelection(M.singleRow(e))}toggleSelection(){if(this.isAllSelected())this.clear();else if(this.hasNoSelection())this.selectAll();else{const e=this.model.getAllRows();this.silent=!0;for(let t=0;t<e.length;t++)this.toggleRow(t);this.silent=!1,this.fireChangeEvent()}}toggleFilteredRowsSelection(){if(this.isAllSelected())this.clear();else if(this.hasNoSelection()){const e=this.model.getFilteredRows();this.silent=!0;for(let t=0;t<e.length;t++)this.selectRow(t);this.silent=!1,this.fireChangeEvent()}else{const e=this.model.getFilteredRows();this.silent=!0;for(let t=0;t<e.length;t++)this.toggleRow(t);this.silent=!1,this.fireChangeEvent()}}toggleRow(e){this.isSelected(e,0)?this.unselectRow(e):this.reselectPoint(e,0)?this.fireChangeEvent():this.selectRow(e)}}class Vd{constructor(e,t,s){this.r=e,this.g=t,this.b=s}}class Yo{constructor(e,t,s,o){this.minValue=e,this.minColor=t,this.maxValue=s,this.maxColor=o}}class jt{static normalize(e,t,s,o=0,i=1){return(e-t)/(s-t)*(i-o)+o}static getTwoColorGradientRGB(e,t){const s=jt.normalize(e,t.minValue,t.maxValue,0,1),o=t.maxColor.r-t.minColor.r,i=t.maxColor.g-t.minColor.g,r=t.maxColor.b-t.minColor.b,l=o*s+t.minColor.r,a=i*s+t.minColor.g,c=r*s+t.minColor.b;return`rgb(${Math.round(l)}, ${Math.round(a)}, ${Math.round(c)})`}static getThreeColorGradientRGB(e,t){return e<t.middleValue?jt.getTwoColorGradientRGB(e,new Yo(t.minValue,t.minColor,t.middleValue,t.middleColor)):e>t.middleValue?jt.getTwoColorGradientRGB(e,new Yo(t.middleValue,t.middleColor,t.maxValue,t.maxColor)):`rgb(${t.middleColor.r}, ${t.middleColor.g}, ${t.middleColor.b})`}}class _d{constructor(e,t,s,o,i,r){this.minValue=e,this.minColor=t,this.middleValue=s,this.middleColor=o,this.maxValue=i,this.maxColor=r}}class Wl{constructor(e=!0,t=!0,s=(r,l)=>r*10+10,o=50,i=450){this.autoCalc=e,this.takeHeaderLabelsIntoAccount=t,this.charCountToWidth=s,this.minWidth=o,this.maxWidth=i}}class Ul{constructor(e){this.object=e}openDialog(){const e=document.createElement("dialog");e.classList.add("ge-table-crud-object-view"),this.direction&&e.setAttribute("dir",this.direction),e.innerHTML=`
|
|
447
447
|
<div class="ge-table-dialog-header">Item</div>
|
|
448
448
|
<div class="ge-table-dialog-content">
|
|
449
449
|
${this.generateHtmlTable(this.object)}
|
|
@@ -479,4 +479,4 @@ render scope: this.lastFullVisibleRowIndex <- `+this.lastFullVisibleRowIndex),th
|
|
|
479
479
|
<label for="${a}">${X(r)}</label>
|
|
480
480
|
${h}
|
|
481
481
|
</div>
|
|
482
|
-
`)}return s.join("")}readInput(e,t){return e.type==="checkbox"?e.checked:e.type==="number"?e.value===""?null:Number(e.value):t==null&&e.value===""?t:e.value}getNestedValue(e,t){let s=e;for(const o of t){if(s===null||typeof s!="object")return;s=s[o]}return s}setNestedValue(e,t,s){if(t.some(i=>Ar.has(i)))return;let o=e;for(let i=0;i<t.length-1;i++){const r=t[i];(o[r]===null||typeof o[r]!="object")&&(o[r]={}),o=o[r]}o[t[t.length-1]]=s}static deepCopy(e){try{return structuredClone(e)}catch{return JSON.parse(JSON.stringify(e))}}}class Kl{constructor(){this.urls={list:{url:"",method:"GET"}},this.singleRowActions=[new He("VIEW","View","","","link"),new He("EDIT","Edit","","","link"),new He("CLONE","Clone","","","link"),new He("DELETE","Delete","","","link")],this.tableActions=[new He("CREATE","Create","","","button"),new He("DELETE_SELECTED","Delete Selected","","","button")],this.autoAddActionColumn=!0,this.columnWidths=new Wl,this.calcFixedRightColumnCount=e=>e>6?1:0,this.getHeadersInit=()=>({}),this.getIdKey=()=>"id",this.getIdByObject=e=>{const t=this.getIdKey()??"id";return e?e[t]:void 0},this.fetchList=e=>Vt(e,"list","GET",{}),this.fetchItem=(e,t)=>Vt(e,"read","GET",{id:t}),this.updateItem=(e,t,s)=>Vt(e,"update","PATCH",{id:t,item:s}),this.createItem=(e,t)=>Vt(e,"create","POST",{item:t}),this.deleteItem=(e,t)=>Vt(e,"delete","DELETE",{id:t}),this.getEmptyItem=()=>{}}}function Vt(n,e,t,s){var l;const o=(l=n.urls)==null?void 0:l[e];if(!(o!=null&&o.url))return Promise.reject(new Error(`CrudOptions: no URL for "${e}" (set urls.${e}.url)`));const i="id"in s?o.url.split("{id}").join(encodeURIComponent(String(s.id))):o.url,r={headers:n.getHeadersInit?n.getHeadersInit():{},method:o.method??t};if("item"in s){const a=new Headers(r.headers);a.has("Content-Type")||a.set("Content-Type","application/json"),r.headers=a,r.body=JSON.stringify(s.item)}return fetch(i,r).then(a=>Bd(a,r.method,i))}function Bd(n,e,t){return n.ok?n.text().then(s=>s?JSON.parse(s):void 0):Promise.reject(new Error(`CrudOptions: ${e} ${t} failed: ${n.status} ${n.statusText}`.trim()))}class $d{constructor(){this.crudOptions=new Kl,this.listenActionEvent=e=>{},this.pendingRequests=0}createTableModel(e,t,s=i=>{},o=i=>{}){this.crudOptions=e,this.listenActionEvent=o,e.fetchList(e).then(i=>{var r,l,a,c;if(t.rows=i,i!=null&&i.length){const h=(r=t.columnDefs)!=null&&r.length?t.columnDefs.map(y=>y.property):this.extractProperties(i[0]),d=new Me("row","multi"),u=()=>d;this.tableOptions={...new je,...t.tableOptions,hoverColumnVisible:!1,getSelectionModel:u};const f=this.calcAutoColumnWidths(i,h),g=(l=t.columnDefs)!=null&&l.length?t.columnDefs:h.map(((y,C)=>new be(y,y.toUpperCase(),new T(f[C],"px"))));if((a=e==null?void 0:e.columnWidths)!=null&&a.autoCalc)for(let y=0;y<g.length;y++){const C=g[y];C.width=new T(f[y],"px")}if(e.autoAddActionColumn){let y=new be(this.getIdKey(),"Actions",Dl,new ee(["ge-table-text-align-left"],["ge-table-text-align-left ge-table-actions-cell"],void 0));y.rendererMap=new ee(void 0,new Gl(this,e.singleRowActions),void 0),g.push(y)}const p=0,m=e.calcFixedRightColumnCount(g.length);this.tableModel=ye.buildByTypedRowsParam({rows:i,columnDefs:g,tableOptions:this.tableOptions,fixedLeftColumnCount:p,fixedRightColumnCount:m}),this.tableModel.getSelectionModel=u,this.bodyModel=(c=this.tableModel)==null?void 0:c.getBodyModel();const b=new Pl(this.tableModel,this.tableOptions);s(b)}},i=>this.logError("loading the list",i))}openDialogForCreate(){if(this.bodyModel){const e=new ki("CREATE","body",this.bodyModel,-1,-1,null);this.onActionEvent(e)}}withDirection(e){var t,s;return e.direction=(s=(t=this.tableModel)==null?void 0:t.getTableScope())==null?void 0:s.direction,e}onActionEvent(e){this.listenActionEvent&&this.listenActionEvent(e);const t=this.crudOptions,s=this.getIdKey(),o=e.action,i=e.id;o==="VIEW"?this.whileLoading(()=>t.fetchItem(t,i)).then(r=>this.withDirection(new Ul(r)).openDialog()).catch(r=>this.logError(o,r)):o==="EDIT"?this.whileLoading(()=>t.fetchItem(t,i)).then(r=>this.withDirection(new yt(s,r)).openDialog(l=>this.whileLoading(()=>t.updateItem(t,i,l)).then(a=>this.updateRow(i,this.isItemWithId(a)?a:l)).catch(a=>this.logError(o,a)))).catch(r=>this.logError(o,r)):o==="CLONE"?this.whileLoading(()=>t.fetchItem(t,i)).then(r=>this.withDirection(new yt(s,r,"Clone Item")).openDialog(l=>this.createItem(o,l))).catch(r=>this.logError(o,r)):o==="CREATE"?this.withDirection(new yt(s,t.getEmptyItem()??{},"Create Item")).openDialog(r=>this.createItem(o,r)):o==="DELETE"&&this.whileLoading(()=>t.deleteItem(t,i)).then(()=>{var r,l,a,c,h,d,u;(r=this.bodyModel)==null||r.filterRowsByPredict(f=>!this.hasId(f,i)),(a=(l=this.tableModel)==null?void 0:l.getTableScope())==null||a.clearSelection(!0),(h=(c=this.tableModel)==null?void 0:c.getTableScope())==null||h.invalidateAggregates(),(u=(d=this.tableModel)==null?void 0:d.getTableScope())==null||u.repaintHard()}).catch(r=>this.logError(o,r))}createItem(e,t){const s=this.crudOptions,{[this.getIdKey()]:o,...i}=t;this.whileLoading(()=>s.createItem(s,i).then(r=>this.isItemWithId(r)?this.addRow(r):this.reloadRows())).catch(r=>this.logError(e,r))}updateRow(e,t){var o,i,r,l,a;const s=(o=this.bodyModel)==null?void 0:o.getAllRows().find(c=>this.hasId(c,e));s&&(Object.assign(s,t),(r=(i=this.tableModel)==null?void 0:i.getTableScope())==null||r.invalidateAggregates(),(a=(l=this.tableModel)==null?void 0:l.getTableScope())==null||a.repaint())}addRow(e){var s,o,i,r;const t=this.bodyModel;if(t){const l=t.getAllRows(),a=t.getFilteredRows();l.push(e),a!==l&&a.push(e),(o=(s=this.tableModel)==null?void 0:s.getTableScope())==null||o.invalidateAggregates(),(r=(i=this.tableModel)==null?void 0:i.getTableScope())==null||r.repaintHard()}}reloadRows(){const e=this.crudOptions;return e.fetchList(e).then(t=>{var o,i;(o=this.bodyModel)==null||o.setRows(t??[]);const s=(i=this.tableModel)==null?void 0:i.getTableScope();s==null||s.externalFilterChanged(!1),s==null||s.repaintHard()})}whileLoading(e){var o;const t=(o=this.tableModel)==null?void 0:o.getTableScope();this.pendingRequests++,t==null||t.showLoadingOverlay();const s=()=>{this.pendingRequests=Math.max(0,this.pendingRequests-1),this.pendingRequests===0&&(t==null||t.hideOverlay())};return Promise.resolve().then(e).then(i=>(s(),i),i=>{throw s(),i})}getIdKey(){var e,t;return((t=(e=this.crudOptions).getIdKey)==null?void 0:t.call(e))??"id"}hasId(e,t){const s=this.getValueByT(e,this.getIdKey());return s!=null&&String(s)===String(t)}isItemWithId(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=this.getValueByT(e,this.getIdKey());return t!=null}logError(e,t){console.error(`CrudTableModelFactory: ${e} failed`,t)}calcAutoColumnWidths(e,t,s=t){var c;const o=t.length;if(!((c=this.crudOptions.columnWidths)!=null&&c.autoCalc))return new Array(o).fill(200);const i=e.length??0,r=new Array(o).fill(0);for(let h=0;h<i;h++)for(let d=0;d<o;d++){const u=t[d],f=this.getValueByT(e[h],u),g=(f==null?void 0:f.toString().length)||0;g>r[d]&&(r[d]=g)}if(this.crudOptions.columnWidths.takeHeaderLabelsIntoAccount)for(let h=0;h<o;h++){const d=s[h].length||0;d>r[h]&&(r[h]=d)}const l=this.crudOptions.columnWidths.minWidth,a=this.crudOptions.columnWidths.maxWidth;return r.map((h,d)=>Math.min(a,Math.max(this.crudOptions.columnWidths.charCountToWidth(h,d),l)))}getValueByT(e,t){return t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}getPropertyValue(e,t){const s=t.shift(),o=e[s];return o&&t.length?this.getPropertyValue(o,t):o}extractProperties(e,t="",s=[]){for(const o in e)if(e.hasOwnProperty(o)){const i=t?`${t}.${o}`:o;typeof e[o]=="object"&&e[o]!==null&&!Array.isArray(e[o])?this.extractProperties(e[o],i,s):s.push(i)}return s}}class Hd{constructor(e,t){this.method=e,this.url=t}}class zl{constructor(e,t,s,o,i,r,l,a){this.key=e,this.label=t,this.level=s,this.field=o,this.path=i,this.parent=r,this.source=l,this.type="RowGroup",this.children=[],this.count=0,this.results={},this.sourceIndices=[],this.states=[],this.idParts=[...(r==null?void 0:r.idParts)??[],[o,a]]}get id(){return"rowgroup:"+JSON.stringify(this.idParts)}isLeaf(){return this.children.length===0}getRows(e=!0){return this.collectIndices(e,[]).map(t=>this.source[t])}collectIndices(e,t){if(this.isLeaf()){const s=e?this.accept:void 0;for(const o of this.sourceIndices)(!s||s(o))&&t.push(o)}else for(const s of this.children)s.collectIndices(e,t);return t}}function Os(n,e,t){var r;const s=[],o=e.length;if(!o)return s;const i={byKey:new Map};for(let l=0;l<n.length;l++){const a=n[l];let c=i,h;for(let d=0;d<o;d++){const u=e[d];let f=u.getKey(a);Et(f)&&(f=Ec);let g;const p=f instanceof Date?f.getTime():void 0;if(p!==void 0?g=(r=c.byTime)==null?void 0:r.get(p):g=c.byKey.get(f),!g){const m=u.format&&!Et(f)?u.format(f):Ic(f,t),b=new zl(f,`${m??""}`,d,u.name,h?[...h.path,f]:[f],h,n,st(f));g=[b,{byKey:new Map}],p!==void 0?(c.byTime??(c.byTime=new Map)).set(p,g):c.byKey.set(f,g),(h?h.children:s).push(b)}h=g[0],c=g[1]}h.sourceIndices.push(l)}return jl(s,e),s}function jl(n,e){var s;if(!n.length)return;const t=(s=e[n[0].level])==null?void 0:s.compare;t&&n.sort((o,i)=>t(o.key,i.key));for(const o of n)jl(o.children,e)}function Xl(n,e,t){for(const s of n)Jl(s,e,t);return Yl(n,e)}function Yl(n,e){const t=e.map(o=>o.aggregator.init());for(const o of n)e.forEach((i,r)=>t[r]=i.aggregator.merge(t[r],o.states[r]));const s={};return e.forEach((o,i)=>s[o.key]=o.aggregator.result(t[i])),s}function Jl(n,e,t){if(n.isLeaf()){ql(n,e,t);return}for(const s of n.children)Jl(s,e,t);Zl(n,e)}function ql(n,e,t){const s=n.source;let o=n.sourceIndices;if(t){o=[];for(const l of n.sourceIndices)t(l)&&o.push(l)}const i=o.length,r=e.map(l=>{const a=l.aggregator,c=l.getValue;let h=a.init();for(let d=0;d<i;d++){const u=s[o[d]];h=a.add(h,c?c(u):u)}return h});n.accept=t,n.states=r,n.count=i,n.results=Ql(r,e)}function Zl(n,e){const t=e.map(o=>o.aggregator.init());let s=0;for(const o of n.children)s+=o.count,e.forEach((i,r)=>t[r]=i.aggregator.merge(t[r],o.states[r]));n.states=t,n.count=s,n.results=Ql(t,e)}function Ql(n,e){const t={};return e.forEach((s,o)=>t[s.key]=s.aggregator.result(n[o])),t}const Gd="(empty)";function Wd(n,e,t={}){return Os(n,Ve(e),t.emptyLabel??Gd)}function Ud(n,e,t){const s=Object.keys(e??{}).map(o=>ls(o,e[o]));return Xl(n,s,t)}const Ws=class Ws extends be{constructor(e={}){const t={width:new T(220,"px"),showCount:!0,fixed:!0,...e};super(Ws.PROPERTY,t.headerLabel??"Group",t.width,new ee(["ge-table-row-group-column-header"],["ge-table-row-group-column"],[]),new ee,new T(60,"px"),new T(2e3,"px"),Lt),this.type="RowGroupColumnDef",this.options=t,this.autoHeaderLabel=e.headerLabel===void 0}};Ws.PROPERTY="RowGroupColumn";let J=Ws;class qe extends ze{constructor(e,t,s,o){super(e,!1,void 0,t,s),this.sourceIndex=o}}const Kd=new Intl.NumberFormat("en-US");class ea extends rt{constructor(e,t,s,o=34){super("body",[],o,t),this.kind="AreaModelRowGroups",this.hiddenColumnProperties=[],this.fields=[],this.groups=[],this.textRenderer=new kt,this.groupRowById=new Map,this.detailRows=[],this.allDirty=!0,this.dirtyLeaves=new Set,this.totals={},this.batchDepth=0,this.regroupPending=!1,this.builds=0,this.sourceRows=e??[],this.options={...s,groupBy:[...s.groupBy??[]]};const i=s.aggregations??{};this.specs=Object.keys(i).map(r=>this.withCalculatedValue(ls(r,i[r]))),this.specByKey=new Map(this.specs.map(r=>[r.key,r])),this.fields=this.withCalculatedKeys(Ve(this.options.groupBy)),this.build(!1)}getSourceRows(){return this.sourceRows}setRows(e){this.sourceRows=e??[],this.build(!0)}getGroupBy(){return[...this.options.groupBy]}setGroupBy(e){const t=Ve(e??[]);this.options.groupBy=[...e??[]],this.fields=this.withCalculatedKeys(t),this.build(!0)}regroup(){this.build(!0)}getGroups(){return this.ensureAggregates(),this.groups}findGroup(e){this.ensureAggregates();let t=this.groups,s;for(const o of e){const i=st(o);if(s=t.find(r=>st(r.key)===i),!s)return;t=s.children}return s}getRowGroup(e){var s;const t=(s=this.getRowByIndex(e))==null?void 0:s.data;if(le(t))return this.ensureAggregates(),t}getDetailRow(e){const t=this.getRowByIndex(e);return t&&!le(t.data)?t.data:void 0}isGroupRowIndex(e){var t;return le((t=this.getRowByIndex(e))==null?void 0:t.data)}getTotals(){return this.ensureAggregates(),this.totals}getCheckedRows(){const e=[];return this.detailRows.forEach(t=>{t.checked&&e.push(t.data)}),e}expandToLevel(e){this.groupRowById.forEach(t=>t.expanded=t.data.level<e),this.recalcVisibleTreeRows(!1)}getBuildCount(){return this.builds}batch(e){this.batchDepth++;try{e()}finally{this.batchDepth--}return this.batchDepth||!this.regroupPending?!1:(this.regroupPending=!1,this.build(!0),!0)}getRawValueOfRow(e,t){if(le(e.data)){this.ensureAggregates();const s=e.data;return t===J.PROPERTY?this.getGroupLabel(s):this.specByKey.has(t)?s.results[t]:""}return t===J.PROPERTY?"":super.getRawValueOfRow(e,t)}canMoveRows(e,t){return!1}moveRows(e,t){return!1}getTextValueAt(e,t){const s=this.getRowByIndex(e),o=this.properties[t];if(s&&o!==void 0&&o!==J.PROPERTY&&this.getColumnValues().getShowValuesAs(o))return this.getCalculatedText(o,this.getValueAt(e,t))??"";if(s&&le(s.data)&&o!==J.PROPERTY){const r=o!==void 0?this.specByKey.get(o):void 0;if(!r)return"";const l=this.getValueAt(e,t);return r.format?r.format(l):It(l)}const i=this.getValueAt(e,t);return i==null?"":`${i}`}getCellRenderer(e,t){const s=this.getRowByIndex(e),o=this.properties[t];return s&&le(s.data)?o!==void 0&&this.specByKey.has(o)?this.textRenderer:void 0:o===J.PROPERTY?void 0:super.getCellRenderer(e,t)}getCustomClassesAt(e,t){const s=super.getCustomClassesAt(e,t),o=this.getRowByIndex(e);if(!o||!le(o.data))return s;const i=this.properties[t],r=o.data.level,l=[...s,"ge-table-row-group",`ge-table-row-group-level-${r}`];return i===J.PROPERTY?l.push("ge-table-row-group-label"):i!==void 0&&this.specByKey.has(i)&&l.push("ge-table-row-group-aggregate"),l}isGroupLabelCell(e,t){return this.properties[t]===J.PROPERTY&&this.isGroupRowIndex(e)}isEditable(e,t){return this.properties[t]===J.PROPERTY||this.isGroupRowIndex(e)?!1:super.isEditable(e,t)}setValue(e,t,s){const o=this.getRowByIndex(e);if(!(o instanceof qe)||this.properties[t]===J.PROPERTY)return!1;const i=this.keysOf(o.data);if(!super.setValue(e,t,s))return!1;const l=this.keysOf(o.data);return i.some((a,c)=>st(a)!==st(l[c]))?this.batchDepth?this.regroupPending=!0:this.build(!0):this.markRowDirty(o),!0}externalFilterChanged(e){this.userFilter=e;const t=this.sourceRows,s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=e(t[o],o,t)?1:0;this.accepted=s,this.allDirty=!0,super.externalFilterChanged(o=>o instanceof qe&&s[o.sourceIndex]===1)}doSort(e){if(!e.length)return!1;this.lastSort={items:[...e]},this.ensureAggregates();const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.createRowComparator(this.properties[s],i)});return super.sort((s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}),this.syncGroupOrder(),this.allDirty=!0,!0}sort(e){this.lastSort={compareFn:e},super.sort((t,s)=>t instanceof qe&&s instanceof qe?e(t.data,s.data):0),this.syncGroupOrder(),this.allDirty=!0}invalidateDerivedValues(e){if(super.invalidateDerivedValues(e),(e==null?void 0:e.area)==="body"&&Array.isArray(e.rowIndices)){for(const t of e.rowIndices){const s=this.getRowByIndex(t);s instanceof qe?this.markRowDirty(s):this.allDirty=!0}return}this.allDirty=!0}withCalculatedValue(e){const t=e.value,s=e.getValue;return!s||typeof t!="string"?e:{...e,getValue:o=>this.isCalculatedProperty(t)?this.getValueByT(o,t):s(o)}}withCalculatedKeys(e){return e.map(t=>{const s=t.path,o=t.getKey;return s===void 0?t:{...t,getKey:i=>this.isCalculatedProperty(s)?this.getValueByT(i,s):o(i)}})}syncGroupOrder(){const e=t=>(t??[]).filter(s=>le(s.data)).map(s=>{const o=s.data;if(o.isLeaf()){const i=(s.children??[]).map(r=>r.sourceIndex);o.sourceIndices.length=0;for(const r of i)o.sourceIndices.push(r)}else{const i=e(s.children);o.children.length=0,o.children.push(...i)}return o});this.groups=e(this.rows)}getGroupLabel(e){const t=this.options.groupColumn;return t!=null&&t.label?`${t.label(e)??""}`:(t==null?void 0:t.showCount)===!1?e.label:`${e.label} (${Kd.format(e.count)})`}ensureAggregates(){if(!this.allDirty&&!this.dirtyLeaves.size)return;const e=this.accepted?(s=>o=>s[o]===1)(this.accepted):void 0;if(!this.fields.length){if(this.allDirty||this.dirtyLeaves.size){const s=e?this.sourceRows.filter((i,r)=>e(r)):this.sourceRows,o=Ys(s,this.specs);this.totals={},this.specs.forEach((i,r)=>this.totals[i.key]=i.aggregator.result(o[r])),this.allDirty=!1,this.dirtyLeaves.clear()}return}if(this.allDirty){this.totals=Xl(this.groups,this.specs,e),this.allDirty=!1,this.dirtyLeaves.clear();return}if(!this.dirtyLeaves.size)return;const t=new Set;this.dirtyLeaves.forEach(s=>{ql(s,this.specs,e);for(let o=s.parent;o;o=o.parent)t.add(o)}),this.dirtyLeaves.clear(),Array.from(t).sort((s,o)=>o.level-s.level).forEach(s=>Zl(s,this.specs)),this.totals=Yl(this.groups,this.specs)}markRowDirty(e){var s;const t=(s=e.parent)==null?void 0:s.data;le(t)?this.dirtyLeaves.add(t):this.allDirty=!0}keysOf(e){return this.fields.map(t=>t.getKey(e))}createRowComparator(e,t){if(!t||e===void 0)return()=>0;const s=this.genericTreeTableSortComparator(e,t),o=this.specByKey.has(e),i=e===J.PROPERTY;return(r,l)=>{const a=le(r.data),c=le(l.data);if(a&&c){const h=r.data,d=l.data;if(o)return this.sorterService.genericSortComparator(h.results[e],d.results[e],t);const u=this.fields[h.level];if(i||(u==null?void 0:u.path)===e){const f=u==null?void 0:u.compare;return f?t*f(h.key,d.key):0}return 0}return!a&&!c&&!i?s(r,l):0}}build(e){const t=new Map,s=new Set;e&&(this.groupRowById.forEach((l,a)=>t.set(a,l.expanded)),this.detailRows.forEach(l=>l.checked&&s.add(l.data))),this.builds++;const o=this.options.emptyLabel??"(empty)";this.groups=Os(this.sourceRows,this.fields,o),this.groupRowById=new Map,this.detailRows=new Array(this.sourceRows.length);const i=[];if(this.fields.length)for(const l of this.groups)i.push(this.createGroupRow(l,void 0,t));else for(let l=0;l<this.sourceRows.length;l++)i.push(this.detailRows[l]=new qe(this.sourceRows[l],void 0,0,l));this.rows.length=0;for(const l of i)this.rows.push(l);s.size&&(this.detailRows.forEach(l=>l.checked=s.has(l.data)),this.rows.forEach(l=>ta(l))),this.allDirty=!0,this.dirtyLeaves.clear(),this.userFilter?this.externalFilterChanged(this.userFilter):this.recalcVisibleTreeRows(!1);const r=this.lastSort;r&&"items"in r?this.doSort(r.items):r&&this.sort(r.compareFn)}createGroupRow(e,t,s){const o=e.id,i=s.get(o)??this.isExpandedByDefault(e),r=new ze(e,i,[],t,e.level);if(this.groupRowById.set(o,r),e.isLeaf()){const l=e.level+1;for(const a of e.sourceIndices){const c=new qe(this.sourceRows[a],r,l,a);this.detailRows[a]=c,r.children.push(c)}}else for(const l of e.children)r.children.push(this.createGroupRow(l,r,s));return r}isExpandedByDefault(e){const t=this.options.expanded??!0;return typeof t=="function"?!!t(e):typeof t=="number"?e.level<t:t}}function ta(n){var t;if(!((t=n.children)!=null&&t.length))return n.checked;let e=!0;for(const s of n.children)ta(s)||(e=!1);return n.checked=e,e}class Li{static createTableModel(e){var d,u;const t=e.rows??[];let s=e.columnDefs?[...e.columnDefs]:t.length?Object.keys(t[0]).map(f=>new be(f,f.toUpperCase(),Fs)):[];const o=e.defaultRowHeights??((d=e.tableOptions)==null?void 0:d.defaultRowHeights)??new Le;let i=e.fixedLeftColumnCount??0;e.rowNumbersVisible&&!O(s[0])&&(s=[new ds(e.rowNumbersVisible===!0?{}:e.rowNumbersVisible),...s],i++);let r=O(s[0])?1:0;const l=me(s[r]);l&&r++;const a=new J(e.groupColumn??{});a.autoHeaderLabel&&(a.headerLabel=Fn(e.groupBy??[],s)),s.splice(r,0,a),a.options.fixed&&(i=Math.max(i,r)+1);const c=new ea(t,s,{groupBy:e.groupBy??[],aggregations:e.aggregations,expanded:e.expanded,emptyLabel:e.emptyLabel,groupColumn:a.options,hideGroupedColumns:e.hideGroupedColumns},o.body);(l||(u=e.tableOptions)!=null&&u.showCheckboxWihoutExtraColumn)&&(c.rowSelectionModel=new Rt(c.rows));const h=ye.createTableModel({columnDefs:s,bodyAreaModel:c,footerAggregates:Li.footerConfig(e),fixedLeftColumnCount:i,fixedRightColumnCount:e.fixedRightColumnCount??0,rowCheckboxVisible:e.rowCheckboxVisible??l,defaultRowHeights:o,getSelectionModel:e.getSelectionModel,tableOptions:e.tableOptions});return _o(h),h}static updateLayout(e){return _o(e)}static footerConfig(e){const t=e.footerAggregates;if(t!==!1)return t===void 0||t===!0?e.aggregations&&Object.keys(e.aggregations).length?e.aggregations:void 0:t}}class sa extends be{constructor(e,t,s,o=new T(100,"px")){super(e,t,o,new ee(["ge-table-pivot-header",`ge-table-pivot-header-${s.kind}`],[],[]),new ee,new T(40,"px"),new T(2e3,"px"),Lt),this.pivot=s,this.type="PivotColumnDef"}}const zd=1e3,Oi="Total";function jd(n){const e=n??[];if(!e.length)throw new Error('Pivot: at least one value is needed (values: ["amount"]).');const t=new Set;return e.map((s,o)=>{const i=typeof s=="string"||typeof s=="function"?{value:s}:s;if(!i||typeof i.value!="string"&&typeof i.value!="function")throw new Error(`Pivot: value ${o} has no value (a property path or a function).`);const r=Xs(i.aggregator??"sum"),l=typeof i.value=="string"?i.value:`value${o}`;let a=i.name??`${r.name}(${l})`;if(t.has(a)){let c=2;for(;t.has(`${a}#${c}`);)c++;a=`${a}#${c}`}return t.add(a),{name:a,label:i.label??a,aggregator:r,format:i.format,showValuesAs:Dt(i.showValuesAs),getValue:r===Oe.count?void 0:ns(i.value)}})}const Xd="(empty)";class Ps{constructor(e,t,s){this.source=e,this.allColumnLeaves=[],this.shownColumns=new Set,this.columnParentsPostOrder=[],this.rowParentsPostOrder=[],this.rowLeaves=[],this.cells=new Map,this.resolved=jd(t.values),this.values=this.resolved;const o=t.emptyLabel??Xd;this.rowGroups=Os(e,Ve(t.rowFields??[]),o),this.columnGroups=Os(e,Ve(t.columnFields??[]),o);const i=Math.max(0,t.maxColumns??zd),r=this.allColumnLeaves;ys(this.columnGroups,r),this.truncated=r.length>i,this.truncated&&console.warn(`Pivot: ${r.length} column keys, only the first ${i} are shown (maxColumns). Totals and subtotals count all rows.`),this.columnLeaves=this.truncated?r.slice(0,i):r,this.columnLeafOf=new Int32Array(e.length).fill(-1),r.forEach((l,a)=>{for(const c of l.sourceIndices)this.columnLeafOf[c]=a});for(const l of this.columnLeaves)for(let a=l;a&&!this.shownColumns.has(a);a=a.parent)this.shownColumns.add(a);Jo(this.columnGroups,this.columnParentsPostOrder,()=>!0),Jo(this.rowGroups,this.rowParentsPostOrder,()=>!0),ys(this.rowGroups,this.rowLeaves),this.compute(s)}compute(e){this.accept=e;const t=new Map;if(this.rowGroups.length){for(const a of this.rowLeaves)a.accept=e,t.set(a,this.leafCells(a.sourceIndices));for(const a of this.rowParentsPostOrder){const c=new Map;for(const h of a.children)this.mergeMap(c,t.get(h));t.set(a,c)}const l=new Map;for(const a of this.rowGroups)this.mergeMap(l,t.get(a));t.set(null,l)}else{const l=[];for(let a=0;a<this.source.length;a++)l.push(a);t.set(null,this.leafCells(l))}this.cells=t;const s=(l,a)=>{l.count=(a==null?void 0:a.count)??0;const c={};this.values.forEach((h,d)=>c[h.name]=a&&a.count?h.aggregator.result(a.states[d]):void 0),l.results=c},o=l=>l.forEach(a=>{var c;s(a,(c=t.get(a))==null?void 0:c.get(null)),o(a.children)});o(this.rowGroups);const i=t.get(null),r=l=>l.forEach(a=>{a.isLeaf()&&(a.accept=e),s(a,i.get(a)),r(a.children)});r(this.columnGroups)}getValue(e,t,s=0){const o=this.valueIndex(s),i=this.cell(e,t);if(!(!i||!i.count||o<0))return this.values[o].aggregator.result(i.states[o])}getCount(e,t){var s;return((s=this.cell(e,t))==null?void 0:s.count)??0}getSourceRows(e,t){let s;if(e)s=e.collectIndices(!1,[]).sort((l,a)=>l-a);else{s=[];for(let l=0;l<this.source.length;l++)s.push(l)}const o=this.accept;let i;if(t){i=new Set;const l=[];ys([t],l);for(const a of l){const c=this.allColumnLeaves.indexOf(a);c>=0&&i.add(c)}}const r=[];for(const l of s)o&&!o(l)||i&&!i.has(this.columnLeafOf[l])||r.push(this.source[l]);return r}isColumnShown(e){return this.shownColumns.has(e)}valueIndex(e){return typeof e=="number"?e>=0&&e<this.values.length?e:-1:this.values.findIndex(t=>t.name===e)}cell(e,t){var s;return(s=this.cells.get(e??null))==null?void 0:s.get(t??null)}newCell(){return{count:0,states:this.values.map(e=>e.aggregator.init())}}leafCells(e){const t=this.resolved,s=t.length,o=this.accept,i=this.source,r=this.columnLeafOf,l=new Array(this.allColumnLeaves.length),a=this.newCell(),c=new Array(s);for(let d=0;d<e.length;d++){const u=e[d];if(o&&!o(u))continue;const f=i[u],g=r[u],p=g>=0?l[g]??(l[g]=this.newCell()):void 0;a.count++;for(let m=0;m<s;m++){const b=t[m].getValue;c[m]=b?b(f):f,a.states[m]=t[m].aggregator.add(a.states[m],c[m])}if(p){p.count++;for(let m=0;m<s;m++)p.states[m]=t[m].aggregator.add(p.states[m],c[m])}}const h=new Map;for(let d=0;d<l.length;d++){const u=l[d];u&&h.set(this.allColumnLeaves[d],u)}for(const d of this.columnParentsPostOrder){let u;for(const f of d.children){const g=h.get(f);g&&(u??(u=this.newCell()),this.mergeInto(u,g))}u&&h.set(d,u)}return h.set(null,a),h}mergeInto(e,t){e.count+=t.count,this.values.forEach((s,o)=>e.states[o]=s.aggregator.merge(e.states[o],t.states[o]))}mergeMap(e,t){t.forEach((s,o)=>{let i=e.get(o);i||(i=this.newCell(),e.set(o,i)),this.mergeInto(i,s)})}}function Yd(n,e,t){return new Ps(n??[],e,t)}function ys(n,e){for(const t of n)t.isLeaf()?e.push(t):ys(t.children,e)}function Jo(n,e,t){for(const s of n)s.isLeaf()||!t(s)||(Jo(s.children,e,t),e.push(s))}function oa(n,e){return"pivot:"+JSON.stringify([...n.idParts,e.name])}function ia(n,e){return"pivot:subtotal:"+JSON.stringify([...n.idParts,e.name])}function qo(n){return"pivot:total:"+JSON.stringify([n.name])}function Jd(n){const e=n.slice(n.lastIndexOf(".")+1);return e.charAt(0).toUpperCase()+e.slice(1)}function ra(n){return kn(Ve(n),Jd).join(" › ")}function qd(n){var e;return n.columnSubtotals??(((e=n.columnFields)==null?void 0:e.length)??0)>1}function na(n,e,t,s={}){var m;const o=n.values,i=o.length>1,r=e.totalLabel??Oi,l=qd(e),a=(((m=e.columnFields)==null?void 0:m.length)??0)>0,c=s.valueWidth??new T(100,"px"),h=[...t],d=t.map(b=>({data:b.headerLabel,property:b.property})),u=(b,y,C)=>{var S;return h.push(new sa(b,y,C,((S=s.widths)==null?void 0:S.get(b))??c)),{data:y,property:b}},f=(b,y,C,S,E)=>i?{data:b,visibility:E,children:o.map((x,R)=>u(S(x),x.label,{kind:y,column:C,value:x,valueIndex:R}))}:{...u(S(o[0]),b,{kind:y,column:C,value:o[0],valueIndex:0}),visibility:E},g=b=>{var C;if(!n.isColumnShown(b))return;if(b.isLeaf())return f(b.label,"value",b,S=>oa(b,S));const y=b.children.map(g).filter(S=>!!S);return l&&y.push(f(`${b.label} ${r}`,"subtotal",b,S=>ia(b,S),"always")),{id:b.id,data:b.label,toggle:l,closed:l&&!!((C=s.closedIds)!=null&&C.has(b.id)),children:y}};let p=0;if(a){for(const b of n.columnGroups){const y=g(b);y&&d.push(y)}e.totalColumn!==!1&&(d.push(f(r,"total",void 0,b=>qo(b))),(e.totalColumn===void 0||e.totalColumn==="fixed")&&(p=o.length))}else o.forEach((b,y)=>d.push(u(qo(b),b.label,{kind:"total",value:b,valueIndex:y})));return{columnDefs:h,cellGroups:d,fixedRightColumnCount:p}}class la extends Ke{constructor(e,t,s,o,i,r,l,a,c,h){super(e,t,s,l,r,!1,a,i,[],-1,0,400,c),this.leadingColumnDefs=o,this.valueWidth=h,this.kind="PivotTableModel",this.pivotFixedRightColumnCount=r}getFixedRightColumnCount(){return this.pivotFixedRightColumnCount}getPivotBody(){return this.bodyAreaModel}getPivotConfig(){return this.getPivotBody().getConfig()}setPivotConfig(e,t){const s=this.getPivotBody(),o={...s.getConfig(),...e};s.configure(o,t),this.relayout()}relayout(){const e=this.getPivotBody(),t=this.headerAreaModel,s=e.getConfig(),o=this.leadingColumnDefs.find(ot);o!=null&&o.autoHeaderLabel&&(o.headerLabel=ra(s.rowFields??[]));const i=new Set(t.getToggleGroupStates().filter(d=>d.closed).map(d=>d.id)),r=this.columnDefs.filter(zs),l=new Map(r.map(d=>[d.property,d.width])),a=new Set(r.filter(d=>!Fo(d)).map(d=>d.property)),c=na(e.getResult(),s,this.leadingColumnDefs,{valueWidth:this.valueWidth,closedIds:i,widths:l}),h=t.setGroups(c.cellGroups,c.columnDefs);h.filter(d=>a.has(d.property)).forEach(d=>nn(d,!1)),this.columnDefs=h,this.columnCount=h.length,this.columnSizes=[],this.pivotFixedRightColumnCount=c.fixedRightColumnCount,e.setColumnDefs(h)}}const Zd=new Intl.NumberFormat("en-US");class aa extends rt{constructor(e,t,s={},o=34){super("body",[],o,[]),this.kind="AreaModelPivot",this.rowFields=[],this.textRenderer=new kt,this.infoByProperty=new Map,this.dirty=!1,this.builds=0,this.sourceRows=e??[],this.config={...t},this.groupColumnOptions=s,this.build(!1)}getConfig(){return{...this.config}}getResult(){return this.ensureComputed(),this.result}getSourceRows(){return this.sourceRows}getBuildCount(){return this.builds}configure(e,t){const s=new Ps(t??this.sourceRows,e);this.config={...e},t&&(this.sourceRows=t),this.build(!0,s)}setColumnDefs(e){this.columnDefs=e,this.properties.length=0;for(const t of e)this.properties.push(t.property);this.infoByProperty=new Map;for(const t of e)zs(t)&&this.infoByProperty.set(t.property,t.pivot)}getPropertyAt(e){return this.properties[e]}getRowGroup(e){var s;const t=(s=this.getRowByIndex(e))==null?void 0:s.data;return t&&t.type==="RowGroup"?t:void 0}getColumnInfo(e){const t=this.properties[e];return t===void 0?void 0:this.infoByProperty.get(t)}getColumnProperty(e,t=0){const s=this.result,o=s.values[s.valueIndex(t)];if(!o)return;if(!e.length){const a=qo(o);return this.infoByProperty.has(a)?a:void 0}let i=s.columnGroups,r;for(const a of e){const c=st(a);if(r=i.find(h=>st(h.key)===c),!r)return;i=r.children}const l=r.isLeaf()?oa(r,o):ia(r,o);return this.infoByProperty.has(l)?l:void 0}getColumnIndex(e,t=0){const s=this.getColumnProperty(e,t);return s===void 0?-1:this.properties.indexOf(s)}getCellSourceRows(e,t){const s=this.getResult(),o=this.getRowGroup(e);if(!o&&this.rowFields.length)return[];const i=this.getColumnInfo(t);return s.getSourceRows(o,(i==null?void 0:i.kind)==="total"||i==null?void 0:i.column)}getValueAt(e,t){if(!this.getRowByIndex(e))return"";const o=this.properties[t],i=this.getRowGroup(e);if(o===J.PROPERTY)return i?this.getGroupLabel(i):this.config.totalLabel??Oi;const r=o===void 0?void 0:this.infoByProperty.get(o);if(!r)return"";if(!(i&&i.children.length>0&&this.config.subtotals===!1))return this.getShownValue(i,r)}getShownValue(e,t){const s=this.getResult(),o=s.getValue(e,t.column,t.valueIndex),i=t.value.showValuesAs;if(!i||typeof o!="number")return o;let r;switch(i.mode){case"percentOfRowTotal":r=s.getValue(e,void 0,t.valueIndex);break;case"percentOfColumnTotal":r=s.getValue(void 0,t.column,t.valueIndex);break;case"percentOfGrandTotal":r=s.getValue(void 0,void 0,t.valueIndex);break;case"percentOfParentTotal":{const l=e==null?void 0:e.parent;r=s.getValue(e?l??void 0:void 0,t.column,t.valueIndex);break}default:return o}return typeof r=="number"&&r!==0?o/r:void 0}canMoveRows(e,t){return!1}moveRows(e,t){return!1}getTextValueAt(e,t){const s=this.properties[t],o=s===void 0?void 0:this.infoByProperty.get(s),i=this.getValueAt(e,t);return o?i===void 0?this.isSubtotalSuppressed(e)?"":this.config.emptyText??"":o.value.showValuesAs?Js(i,o.value.showValuesAs):o.value.format?o.value.format(i):It(i):i==null?"":`${i}`}getCellRenderer(e,t){const s=this.properties[t];if(s!==void 0&&this.infoByProperty.has(s))return this.textRenderer}getCustomClassesAt(e,t){const s=super.getCustomClassesAt(e,t),o=this.properties[t],i=this.getRowGroup(e),r=[...s,`ge-table-pivot-level-${(i==null?void 0:i.level)??0}`],l=!!i&&i.children.length>0;if(o===J.PROPERTY)return r.push("ge-table-pivot-label"),l&&r.push("ge-table-pivot-subtotal"),r;const a=o===void 0?void 0:this.infoByProperty.get(o);return a&&(r.push("ge-table-pivot-value"),(l||a.kind==="subtotal")&&r.push("ge-table-pivot-subtotal"),a.kind==="total"&&r.push("ge-table-pivot-total"),this.getValueAt(e,t)===void 0&&r.push("ge-table-pivot-empty")),r}isRowHeaderCell(e,t){return this.properties[t]===J.PROPERTY&&!!this.getRowByIndex(e)}isEditable(e,t){return!1}setValue(e,t,s){return!1}externalFilterChanged(e){this.userFilter=e,this.accepted=this.acceptedBy(this.userFilter),this.dirty=!0,this.ensureComputed();const t=this.result;super.externalFilterChanged(s=>{var o;return!((o=s.children)!=null&&o.length)&&(!this.rowFields.length||t.getCount(s.data)>0)})}doSort(e){if(!e.length)return!1;this.ensureComputed();const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.createRowComparator(this.properties[s],i)});return super.sort((s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}),!0}sort(e){super.sort((t,s)=>e(t.data,s.data))}invalidateDerivedValues(){super.invalidateDerivedValues(),this.dirty=!0}isSubtotalSuppressed(e){const t=this.getRowGroup(e);return this.config.subtotals===!1&&!!t&&t.children.length>0}getGroupLabel(e){const t=this.groupColumnOptions;return t.label?`${t.label(e)??""}`:t.showCount?`${e.label} (${Zd.format(e.count)})`:e.label}ensureComputed(){var t;if(!this.dirty)return;this.dirty=!1,this.userFilter&&((t=this.accepted)==null?void 0:t.length)!==this.sourceRows.length&&(this.accepted=this.acceptedBy(this.userFilter));const e=this.accepted;this.result.compute(e?(s=>e[s]===1):void 0)}acceptedBy(e){const t=this.sourceRows,s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=e(t[o],o,t)?1:0;return s}createRowComparator(e,t){if(!t||e===void 0)return()=>0;if(e===J.PROPERTY)return(i,r)=>{var h;const l=i.data,a=r.data,c=(h=this.rowFields[l.level])==null?void 0:h.compare;return c?t*c(l.key,a.key):0};const s=this.infoByProperty.get(e);if(!s)return()=>0;const o=this.columnDefs.find(i=>i.property===e);return(i,r)=>{const l=this.getShownValue(i.data,s),a=this.getShownValue(r.data,s);return l===void 0||a===void 0?l===a?0:l===void 0?1:-1:o!=null&&o.sortComparator?t*o.sortComparator(l,a,i.data,r.data,t):this.sorterService.genericSortComparator(l,a,t)}}build(e,t){const s=new Map;if(e){const i=r=>r.forEach(l=>{var a;((a=l.data)==null?void 0:a.type)==="RowGroup"&&s.set(l.data.id,l.expanded),l.children&&i(l.children)});i(this.rows)}this.builds++,this.rowFields=Ve(this.config.rowFields??[]),this.result=t??new Ps(this.sourceRows,this.config),this.dirty=!1;const o=[];if(this.rowFields.length)for(const i of this.result.rowGroups)o.push(this.createRow(i,void 0,s));else o.push(new ze({type:"PivotTotal"},!0,void 0,void 0,0));this.rows.length=0;for(const i of o)this.rows.push(i);this.userFilter?this.externalFilterChanged(this.userFilter):this.recalcVisibleTreeRows(!1)}createRow(e,t,s){const o=s.get(e.id)??this.isExpandedByDefault(e),i=e.isLeaf()?void 0:[],r=new ze(e,o,i,t,e.level);for(const l of e.children)i.push(this.createRow(l,r,s));return r}isExpandedByDefault(e){const t=this.config.expanded??!0;return typeof t=="function"?!!t(e):typeof t=="number"?e.level<t:t}}class ca extends Ii{constructor(e,t=34){super(),this.body=e,this.defaultRowHeight=t,this.type="AreaModelPivotFooter",this.textRenderer=new kt,this.areaIdent="footer"}getRowCount(){var t;const e=this.body.getConfig();return e.totalRow===!1||!((t=e.rowFields)!=null&&t.length)?0:1}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.defaultRowHeight}getValueAt(e,t){if(e!==0)return"";if(this.isRowHeaderCell(e,t))return this.body.getConfig().totalLabel??Oi;const s=this.body.getColumnInfo(t);return s?this.body.getShownValue(void 0,s):""}getTextValueAt(e,t){const s=this.body.getColumnInfo(t),o=this.getValueAt(e,t);return s?o===void 0?this.body.getConfig().emptyText??"":s.value.showValuesAs?Js(o,s.value.showValuesAs):s.value.format?s.value.format(o):It(o):o==null?"":`${o}`}getCellRenderer(e,t){return this.body.getColumnInfo(t)||this.isLabelColumn(t)?this.textRenderer:void 0}getCustomClassesAt(e,t){if(this.isLabelColumn(t))return["ge-table-pivot-total","ge-table-pivot-label"];if(!this.body.getColumnInfo(t))return[];const o=["ge-table-pivot-value","ge-table-pivot-total"];return this.getValueAt(e,t)===void 0&&o.push("ge-table-pivot-empty"),o}isRowHeaderCell(e,t){return e===0&&this.isLabelColumn(t)}isLabelColumn(e){return this.body.getPropertyAt(e)===J.PROPERTY}}class Qd extends $l{getCustomClassesAt(e,t){const s=this.getValueAt(e,t);return s?s.ownColumn()?["ge-table-pivot-header-column"]:["ge-table-pivot-header-group"]:[]}}class Pi{static createTableModel(e){var f,g,p;const t=e.defaultRowHeights??((f=e.tableOptions)==null?void 0:f.defaultRowHeights)??new Le,s=Pi.toConfig(e),o=[];e.rowNumbersVisible&&o.push(new ds(e.rowNumbersVisible===!0?{}:e.rowNumbersVisible));const i={showCount:!1,...e.groupColumn??{}},r=new J(i);r.autoHeaderLabel&&(r.headerLabel=ra(s.rowFields??[])),o.push(r);const l=r.options.fixed?o.length:o.length-1,a=new aa(e.rows??[],s,r.options,t.body),c=na(a.getResult(),s,o,{valueWidth:e.valueColumnWidth}),h=new Qd("header",c.cellGroups,c.columnDefs,t.header,(g=e.tableOptions)==null?void 0:g.headerGroupOptions);c.columnDefs=h.setGroups(c.cellGroups,c.columnDefs),a.setColumnDefs(c.columnDefs);const d=new ca(a,t.footer),u=e.getSelectionModel??((p=e.tableOptions)==null?void 0:p.getSelectionModel)??(()=>{});return new la(h,a,d,o,c.columnDefs,c.fixedRightColumnCount,l,t,u,e.valueColumnWidth)}static toConfig(e){return{rowFields:e.rowFields??[],columnFields:e.columnFields??[],values:e.values,subtotals:e.subtotals,columnSubtotals:e.columnSubtotals,totalColumn:e.totalColumn,totalRow:e.totalRow,maxColumns:e.maxColumns,expanded:e.expanded,emptyLabel:e.emptyLabel,emptyText:e.emptyText,totalLabel:e.totalLabel}}}class Ni{constructor(e){this.options=e,this.abort=new AbortController}static create(e){return new Ni(e.map(t=>({value:t,label:t})))}open(e,t){var l;const s=t.domService,o=s.createElement("select");this.select=o,s.setAttribute(o,"aria-label",t.ariaLabel),s.addClass(o,"ge-table-cell-editor-field");let i=-1;const r=(l=t.typedText)==null?void 0:l.toLowerCase();this.options.forEach((a,c)=>{const h=s.createElement("option");h.value=String(a.value),h.textContent=String(a.label),s.appendChild(o,h),r!==void 0?i<0&&String(a.label).toLowerCase().startsWith(r)&&(i=c):a.value===t.value&&(i=c)}),o.selectedIndex=i,o.addEventListener("change",()=>t.inputChanged(),{signal:this.abort.signal}),s.appendChild(e,o)}getValue(){var t;const e=this.select;return!e||e.selectedIndex<0?"":(t=this.options[e.selectedIndex])==null?void 0:t.value}getText(){return String(this.getValue()??"")}focus(){this.select&&this.select.ownerDocument.activeElement!==this.select&&this.select.focus({preventScroll:!0})}getFocusElement(){return this.select}wantsKey(e,t){var s,o;return e.altKey&&e.key==="ArrowDown"?((o=(s=this.select)==null?void 0:s.showPicker)==null||o.call(s),!0):e.key==="ArrowUp"||e.key==="ArrowDown"}close(){var e;this.abort.abort(),(e=this.select)==null||e.remove(),this.select=void 0}}class eu{constructor(e,t,s={}){this.api=t,this.abort=new AbortController,this.original="",this.options={addressBox:!0,ariaLabel:"Formula",addressAriaLabel:"Cell address",...s};const o=e.ownerDocument;this.element=o.createElement("div"),this.element.className="ge-table-formula-bar",this.addressInput=o.createElement("input"),this.addressInput.className="ge-table-formula-bar-address",this.addressInput.type="text",this.addressInput.autocomplete="off",this.addressInput.spellcheck=!1,this.addressInput.setAttribute("aria-label",this.options.addressAriaLabel),this.options.addressBox||(this.addressInput.hidden=!0);const i=o.createElement("span");i.className="ge-table-formula-bar-fx",i.setAttribute("aria-hidden","true"),i.textContent="fx",this.input=o.createElement("input"),this.input.className="ge-table-formula-bar-input",this.input.type="text",this.input.autocomplete="off",this.input.spellcheck=!1,this.input.setAttribute("aria-label",this.options.ariaLabel),this.element.append(this.addressInput,i,this.input),e.appendChild(this.element);const r=this.abort.signal;this.input.addEventListener("focus",()=>this.beginInput(),{signal:r}),this.input.addEventListener("keydown",a=>this.onInputKey(a),{signal:r}),this.input.addEventListener("blur",()=>this.endInput(!0),{signal:r}),this.addressInput.addEventListener("keydown",a=>this.onAddressKey(a),{signal:r}),this.addressInput.addEventListener("input",()=>this.addressInput.removeAttribute("aria-invalid"),{signal:r});const l={onFocusChanged:()=>this.show(),onSelectionChanged:()=>this.show(),onModelChanged:()=>this.show(),onEditingChanged:a=>this.onEditing(a)};this.unsubscribe=t.subscribe(l),this.show()}destroy(){this.unsubscribe(),this.abort.abort(),this.element.remove()}show(){const e=this.element.ownerDocument;if(e.activeElement===this.input&&this.cell)return;const t=this.api.getActiveCell(),s=t?this.api.getCellAddress(t[0],t[1]):void 0;e.activeElement!==this.addressInput&&(this.addressInput.value=s??""),this.input.value=t?tu(this.api.getCellInput(t[0],t[1])):"",this.input.disabled=!t}onEditing(e){this.element.ownerDocument.activeElement!==this.input&&(e.type==="start"||e.type==="input"?this.input.value=e.input??this.input.value:this.show())}beginInput(){this.cell=this.api.getActiveCell(),this.original=this.input.value}endInput(e){const t=this.cell;this.cell=void 0,t&&e&&this.input.value!==this.original&&this.api.applyCellChanges([{rowIndex:t[0],column:t[1],value:this.input.value}],"edit")}onInputKey(e){if(e.isComposing)return;const t=this.cell;if(e.key==="Escape"){e.preventDefault(),this.input.value=this.original,this.cell=void 0,this.focusTable();return}if(!(e.key!=="Enter"&&e.key!=="Tab")){if(e.preventDefault(),this.endInput(!0),t){const s=this.api.getTableScope();e.key==="Enter"?s.moveActiveCell(t[0],t[1],e.shiftKey?-1:1,0):s.moveActiveCell(t[0],t[1],0,e.shiftKey?-1:1)}this.focusTable()}}onAddressKey(e){if(e.key==="Escape"){e.preventDefault(),this.addressInput.removeAttribute("aria-invalid"),this.focusTable();return}e.key==="Enter"&&(e.preventDefault(),this.api.goToAddress(this.addressInput.value)?(this.addressInput.removeAttribute("aria-invalid"),this.focusTable()):this.addressInput.setAttribute("aria-invalid","true"))}focusTable(){this.api.getTableScope().hostElement.focus({preventScroll:!0}),this.show()}}function tu(n){if(n==null)return"";if(n instanceof Date){if(Number.isNaN(n.getTime()))return"";const e=t=>String(t).padStart(2,"0");return`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())}`}return String(n)}exports.ALL_TABLE_STATE_PARTS=Be;exports.AbstractAreaModel=as;exports.ActionEvent=ki;exports.ActionsCellRenderer=Gl;exports.AggregateCellRenderer=kt;exports.Aggregators=Oe;exports.AnyPropertyType=si;exports.AreaMapFactory=pd;exports.AreaModel=Ii;exports.AreaModelAggregateFooter=is;exports.AreaModelArrayOfArrays=Q;exports.AreaModelCellGroups=$l;exports.AreaModelHidden=ae;exports.AreaModelObjectArray=K;exports.AreaModelObjectArrayWithColumndefs=jo;exports.AreaModelPivot=aa;exports.AreaModelPivotFooter=ca;exports.AreaModelRowGroups=ea;exports.AreaModelSheet=Ne;exports.AreaModelSheetHeader=vi;exports.AreaModelTree=rt;exports.AreaObjectMap=ee;exports.AriaGridInfo=ts;exports.AriaIds=Qt;exports.AriaTexts=pe;exports.ArrayPropertyType=We;exports.AutoRestoreOptions=Ol;exports.AvoidDoubleExecution=ua;exports.BatchEditOptions=oo;exports.BatchEditService=$n;exports.BooleanPropertyType=Dr;exports.CellChangesUndoable=Uo;exports.CellEditorService=ll;exports.CellFormulaOptions=Tt;exports.CellGroup=_l;exports.CellGroupExt=Bl;exports.CellGroupExtCellRenderer=Ls;exports.CellRange=M;exports.CellgroupFactory=ce;exports.CheckboxBooleanPropertyCellRenderer=vd;exports.CheckboxCellRenderer=Xo;exports.CheckboxColumnDef=gd;exports.CheckboxModel=on;exports.ChunkData=nd;exports.ClipboardOptions=os;exports.ClipboardService=Wo;exports.ColAndRowspanModel=bn;exports.CollapsedExpandedData=Hl;exports.ColorRgb=Vd;exports.ColumnDef=be;exports.ColumnDefGenerator=fa;exports.ColumnWidths=Wl;exports.ConvenienceDomService=xs;exports.CopyService=Se;exports.CoverGridBodyModel=Fl;exports.CoverGridFactory=id;exports.CoverGridTableModel=Ll;exports.CrudAction=He;exports.CrudObjectEdit=yt;exports.CrudObjectView=Ul;exports.CrudOptions=Kl;exports.CrudTableModelFactory=$d;exports.CssVars=zo;exports.DEFAULT_GET_EDIT_RENDERER=Ci;exports.DateCellEditor=tl;exports.DateToIntlDDMMYYYYCellRenderer=Ad;exports.DateToIsoCellRenderer=Rd;exports.DateToLocaleDateCellRenderer=Ed;exports.DateToTecCellRenderer=Dd;exports.DefaultRowHeights=Le;exports.EditingOptions=no;exports.EleScope=es;exports.EventAdapter=Kt;exports.EventCheckboxChangedHandler=Rh;exports.ExcelService=On;exports.FORMULA_FUNCTION_INFO=ol;exports.FORMULA_FUNCTION_NAMES=ec;exports.FalseFn=rn;exports.FillHandleOptions=ss;exports.FillHandleService=qn;exports.FocusModel=Si;exports.FormulaAssist=nl;exports.FormulaBar=eu;exports.FormulaError=I;exports.FormulaRange=tt;exports.GeBatchEditEvent=_n;exports.GeCellIndices=Oo;exports.GeCssColorUtil=jt;exports.GeDetailEvent=Qn;exports.GeEditEvent=bt;exports.GeFilterService=Sd;exports.GeKeyEvent=md;exports.GeModelChangeEvent=Xe;exports.GeMouseEvent=js;exports.GeRowDragEvent=Pn;exports.GeScrollEvent=En;exports.GeStateChangeEvent=vn;exports.GeUndoEvent=Ml;exports.GeoData=Ae;exports.HeaderGroupOptions=Qs;exports.Icon=Ee;exports.IndexAndPx=ld;exports.InputCellRenderer=cn;exports.InputHandler=An;exports.JsonService=Ao;exports.LicenseManager=Qe;exports.LiveAnnouncer=Ds;exports.MaleFemaleToIconCellRenderer=Md;exports.MasterDetailOptions=ro;exports.MasterDetailService=Zn;exports.MouseHandler=Gr;exports.MouseTargetData=vs;exports.MultiRowsSelectionModel=Nd;exports.NullPropertyType=Mr;exports.NumberCellEditor=el;exports.NumberCellProgressBarCellRenderer=Td;exports.NumberCellRenderer=kd;exports.NumberPropertyType=Ir;exports.ObjectPropertyType=Ce;exports.OsxShortcutActionIdMapping=Tn;exports.OverlayOptions=to;exports.PROPERTY_TYPE_KEY_ANY=Zo;exports.PROPERTY_TYPE_KEY_ARRAY=ti;exports.PROPERTY_TYPE_KEY_BOOLEAN=Ks;exports.PROPERTY_TYPE_KEY_NULL=Qo;exports.PROPERTY_TYPE_KEY_NUMBER=Us;exports.PROPERTY_TYPE_KEY_OBJECT=St;exports.PROPERTY_TYPE_KEY_STRING=ei;exports.PROPERTY_TYPE_KEY_UNDEFINED=Ct;exports.Padding=Es;exports.PendingCellChanges=Vn;exports.PendingChangesUndoable=El;exports.PivotColumnDef=sa;exports.PivotFactory=Pi;exports.PivotResult=Ps;exports.PivotTableModel=la;exports.PositiveAndNegativeNumberRenderer=Pd;exports.ProgressBarCellRenderer=Od;exports.PropertyItem=oi;exports.PropertyTypeService=ga;exports.RenderScope=Cn;exports.Renderer=xd;exports.RequestChunk=Nl;exports.ResizeHandler=Ln;exports.RowDragOptions=so;exports.RowDragService=Nn;exports.RowGroup=zl;exports.RowGroupColumnDef=J;exports.RowGroupFactory=Li;exports.RowLayout=yn;exports.RowNumberCellRenderer=an;exports.RowNumberColumnDef=ds;exports.RowNumberOptions=Lo;exports.SHEET_MAX_COLUMNS=q;exports.SHEET_MAX_ROWS=ie;exports.SHOW_VALUES_AS_MODES=jr;exports.SchemeGenerator=pa;exports.SelectCellEditor=Ni;exports.SelectCellRenderer=Fi;exports.SelectionAggregator=Rs;exports.SelectionModel=Me;exports.SelectionService=fe;exports.SheetDate=xt;exports.SheetEngine=ao;exports.ShortcutService=Dn;exports.SimpleArrayCellRenderer=Ld;exports.SimpleDomService=Vo;exports.Size=T;exports.SortItem=Ts;exports.SortedOptions=ni;exports.SpreadsheetFactory=mc;exports.SpreadsheetTableModel=Ri;exports.StarRatingCellRenderer=Fd;exports.StoreStateCollapsedExpandService=yd;exports.StoreStateScrollPosService=wd;exports.StoreStateSortingService=Cd;exports.StringPropertyType=Tr;exports.TableApi=pn;exports.TableCellUpdateEvent=bd;exports.TableFactory=ye;exports.TableModel=Ke;exports.TableModelAndOptions=Pl;exports.TableOptions=je;exports.TableOverlay=mn;exports.TableScope=Ko;exports.TableSheet=co;exports.TableStateService=Is;exports.TextCellEditor=lo;exports.ThreeColorGradientArg=_d;exports.TreeAriaInfo=wn;exports.TreeCheckboxModel=Rt;exports.TreeFactory=pt;exports.TreeOptions=ri;exports.TreeRow=ze;exports.TreeRowService=kl;exports.TrueFalseCellRenderer=Id;exports.TrueFn=Lt;exports.TwoColorGradientArg=Yo;exports.UNIMPORTANT_TYPES=Yt;exports.UndefinedPropertyType=ms;exports.UndoOptions=ho;exports.UndoService=Tl;exports.UndoStack=Rl;exports.UrlInfo=Hd;exports.ValueInfo=kr;exports.ValueLabel=Vl;exports.WindowsShortcutActionIdMapping=Mn;exports.actionIds=rd;exports.adjustFormula=bl;exports.aggregate=Ra;exports.aggregateColumns=Aa;exports.aggregateRowGroups=Ud;exports.allCenter=ud;exports.allLeft=dd;exports.allRight=fd;exports.applySpreadsheetPreset=vh;exports.applyStructureEdit=gt;exports.bodyCenter=cd;exports.bodyLeft=ad;exports.bodyRight=hd;exports.booleanInputPipe=pc;exports.calcMoveToIndex=Io;exports.calcOverlayKind=Po;exports.calculateShowValuesAs=hi;exports.canMoveFlatRows=Zs;exports.canMoveTreeRows=gi;exports.canScrollHorizontally=Br;exports.clipboardShortcutLayer=cl;exports.columnIndexOfLetter=Fe;exports.columnLetter=Pe;exports.compileFormula=bi;exports.computeFillChanges=Jn;exports.computeFillValues=Wn;exports.computePastePlan=xl;exports.createDateInputPipe=uc;exports.createFormulaValueGetter=wi;exports.createHarmonizedShortcutByKeyboardEvent=In;exports.createNumberInputPipe=hc;exports.createValueGetter=ns;exports.dateToSerial=Ft;exports.debounce=Er;exports.editInputPipeForNumber=sl;exports.editingShortcutLayer=al;exports.entitySuffix=Eo;exports.escapeHtml=X;exports.findDataEdge=Il;exports.findRowIndexAtY=Fa;exports.firstLetterUppercase=Or;exports.formatAggregateValue=It;exports.formatFormula=Gt;exports.formatShowValuesAs=Js;exports.getAggregator=Xs;exports.getAreaIdentByString=rs;exports.getEntityName=Fr;exports.getFillRange=Ei;exports.getInsertBeforeIndex=ui;exports.getLeadingRowNumberColumnCount=Zt;exports.getLogicalScrollLeft=Vr;exports.getPasteSize=Ti;exports.getTopmostTreeRows=fi;exports.groupRows=Wd;exports.harmonizeShortcut=Ut;exports.isAreaModelAggregateFooter=Pr;exports.isAreaModelPivot=To;exports.isAreaModelRowGroups=ne;exports.isAreaModelTree=Z;exports.isCheckboxCellRenderer=ii;exports.isCheckboxColumnDef=me;exports.isExcelFormattedValue=ws;exports.isExcelFormulaCell=bs;exports.isFillSeries=Un;exports.isFormulaError=w;exports.isFormulaRange=Ye;exports.isFormulaText=wt;exports.isGroupRow=Mo;exports.isPercentShowValuesAs=ci;exports.isPivotColumnDef=zs;exports.isPivotTableModel=Cs;exports.isRowGroup=le;exports.isRowGroupColumnDef=ot;exports.isRowNumberColumnDef=O;exports.isSameCellValue=Mt;exports.isSheetDate=G;exports.isSpreadsheetTableModel=eo;exports.isTreeRow=U;exports.mirrorArrowKeys=Hr;exports.moveArrayItems=Xr;exports.moveFlatRows=pi;exports.moveTreeRows=Yr;exports.normalizeRowIndices=it;exports.offsetReferences=uh;exports.parseCellAddress=Ue;exports.parseHtmlTable=Sl;exports.parseRangeAddress=qr;exports.parseTsv=yl;exports.pivotRows=Yd;exports.px0=td;exports.px10=ed;exports.px100=Kh;exports.px110=Uh;exports.px120=Wh;exports.px130=Gh;exports.px140=Hh;exports.px150=$h;exports.px160=Bh;exports.px170=_h;exports.px180=Vh;exports.px190=Nh;exports.px20=Qh;exports.px200=Fs;exports.px210=Ph;exports.px220=Oh;exports.px230=Lh;exports.px240=Fh;exports.px250=kh;exports.px260=Dh;exports.px270=Ih;exports.px280=Th;exports.px290=Mh;exports.px30=Zh;exports.px300=Dl;exports.px40=qh;exports.px400=Eh;exports.px50=Jh;exports.px500=Ah;exports.px60=Yh;exports.px70=Xh;exports.px80=jh;exports.px90=zh;exports.readLegacyState=Rn;exports.removeLegacyState=No;exports.resolveShowValuesAs=Dt;exports.resolveTableDirection=Nr;exports.serialToDate=yi;exports.setLogicalScrollLeft=_r;exports.sheetInputPipe=xi;exports.shiftFormula=ml;exports.spreadsheetOption=Ze;exports.sumOfNumbers=qs;exports.throttle=ha;exports.toCellAddress=mt;exports.toHtmlTable=Cl;exports.toLogicalX=$r;exports.toPhysicalScrollLeft=Ss;exports.toTsv=wl;exports.trimArraySuffixes=Lr;exports.undoShortcutLayer=vl;
|
|
482
|
+
`)}return s.join("")}readInput(e,t){return e.type==="checkbox"?e.checked:e.type==="number"?e.value===""?null:Number(e.value):t==null&&e.value===""?t:e.value}getNestedValue(e,t){let s=e;for(const o of t){if(s===null||typeof s!="object")return;s=s[o]}return s}setNestedValue(e,t,s){if(t.some(i=>Ar.has(i)))return;let o=e;for(let i=0;i<t.length-1;i++){const r=t[i];(o[r]===null||typeof o[r]!="object")&&(o[r]={}),o=o[r]}o[t[t.length-1]]=s}static deepCopy(e){try{return structuredClone(e)}catch{return JSON.parse(JSON.stringify(e))}}}class Kl{constructor(){this.urls={list:{url:"",method:"GET"}},this.singleRowActions=[new He("VIEW","View","","","link"),new He("EDIT","Edit","","","link"),new He("CLONE","Clone","","","link"),new He("DELETE","Delete","","","link")],this.tableActions=[new He("CREATE","Create","","","button"),new He("DELETE_SELECTED","Delete Selected","","","button")],this.autoAddActionColumn=!0,this.columnWidths=new Wl,this.calcFixedRightColumnCount=e=>e>6?1:0,this.getHeadersInit=()=>({}),this.getIdKey=()=>"id",this.getIdByObject=e=>{const t=this.getIdKey()??"id";return e?e[t]:void 0},this.fetchList=e=>Vt(e,"list","GET",{}),this.fetchItem=(e,t)=>Vt(e,"read","GET",{id:t}),this.updateItem=(e,t,s)=>Vt(e,"update","PATCH",{id:t,item:s}),this.createItem=(e,t)=>Vt(e,"create","POST",{item:t}),this.deleteItem=(e,t)=>Vt(e,"delete","DELETE",{id:t}),this.getEmptyItem=()=>{}}}function Vt(n,e,t,s){var l;const o=(l=n.urls)==null?void 0:l[e];if(!(o!=null&&o.url))return Promise.reject(new Error(`CrudOptions: no URL for "${e}" (set urls.${e}.url)`));const i="id"in s?o.url.split("{id}").join(encodeURIComponent(String(s.id))):o.url,r={headers:n.getHeadersInit?n.getHeadersInit():{},method:o.method??t};if("item"in s){const a=new Headers(r.headers);a.has("Content-Type")||a.set("Content-Type","application/json"),r.headers=a,r.body=JSON.stringify(s.item)}return fetch(i,r).then(a=>Bd(a,r.method,i))}function Bd(n,e,t){return n.ok?n.text().then(s=>s?JSON.parse(s):void 0):Promise.reject(new Error(`CrudOptions: ${e} ${t} failed: ${n.status} ${n.statusText}`.trim()))}class $d{constructor(){this.crudOptions=new Kl,this.listenActionEvent=e=>{},this.pendingRequests=0}createTableModel(e,t,s=i=>{},o=i=>{}){this.crudOptions=e,this.listenActionEvent=o,e.fetchList(e).then(i=>{var r,l,a,c;if(t.rows=i,i!=null&&i.length){const h=(r=t.columnDefs)!=null&&r.length?t.columnDefs.map(y=>y.property):this.extractProperties(i[0]),d=new Me("row","multi"),u=()=>d;this.tableOptions={...new je,...t.tableOptions,hoverColumnVisible:!1,getSelectionModel:u};const f=this.calcAutoColumnWidths(i,h),g=(l=t.columnDefs)!=null&&l.length?t.columnDefs:h.map(((y,C)=>new be(y,y.toUpperCase(),new T(f[C],"px"))));if((a=e==null?void 0:e.columnWidths)!=null&&a.autoCalc)for(let y=0;y<g.length;y++){const C=g[y];C.width=new T(f[y],"px")}if(e.autoAddActionColumn){let y=new be(this.getIdKey(),"Actions",Dl,new ee(["ge-table-text-align-left"],["ge-table-text-align-left ge-table-actions-cell"],void 0));y.rendererMap=new ee(void 0,new Gl(this,e.singleRowActions),void 0),g.push(y)}const p=0,m=e.calcFixedRightColumnCount(g.length);this.tableModel=ye.buildByTypedRowsParam({rows:i,columnDefs:g,tableOptions:this.tableOptions,fixedLeftColumnCount:p,fixedRightColumnCount:m}),this.tableModel.getSelectionModel=u,this.bodyModel=(c=this.tableModel)==null?void 0:c.getBodyModel();const b=new Pl(this.tableModel,this.tableOptions);s(b)}},i=>this.logError("loading the list",i))}openDialogForCreate(){if(this.bodyModel){const e=new ki("CREATE","body",this.bodyModel,-1,-1,null);this.onActionEvent(e)}}withDirection(e){var t,s;return e.direction=(s=(t=this.tableModel)==null?void 0:t.getTableScope())==null?void 0:s.direction,e}onActionEvent(e){this.listenActionEvent&&this.listenActionEvent(e);const t=this.crudOptions,s=this.getIdKey(),o=e.action,i=e.id;o==="VIEW"?this.whileLoading(()=>t.fetchItem(t,i)).then(r=>this.withDirection(new Ul(r)).openDialog()).catch(r=>this.logError(o,r)):o==="EDIT"?this.whileLoading(()=>t.fetchItem(t,i)).then(r=>this.withDirection(new yt(s,r)).openDialog(l=>this.whileLoading(()=>t.updateItem(t,i,l)).then(a=>this.updateRow(i,this.isItemWithId(a)?a:l)).catch(a=>this.logError(o,a)))).catch(r=>this.logError(o,r)):o==="CLONE"?this.whileLoading(()=>t.fetchItem(t,i)).then(r=>this.withDirection(new yt(s,r,"Clone Item")).openDialog(l=>this.createItem(o,l))).catch(r=>this.logError(o,r)):o==="CREATE"?this.withDirection(new yt(s,t.getEmptyItem()??{},"Create Item")).openDialog(r=>this.createItem(o,r)):o==="DELETE"&&this.whileLoading(()=>t.deleteItem(t,i)).then(()=>{var r,l,a,c,h,d,u;(r=this.bodyModel)==null||r.filterRowsByPredict(f=>!this.hasId(f,i)),(a=(l=this.tableModel)==null?void 0:l.getTableScope())==null||a.clearSelection(!0),(h=(c=this.tableModel)==null?void 0:c.getTableScope())==null||h.invalidateAggregates(),(u=(d=this.tableModel)==null?void 0:d.getTableScope())==null||u.repaintHard()}).catch(r=>this.logError(o,r))}createItem(e,t){const s=this.crudOptions,{[this.getIdKey()]:o,...i}=t;this.whileLoading(()=>s.createItem(s,i).then(r=>this.isItemWithId(r)?this.addRow(r):this.reloadRows())).catch(r=>this.logError(e,r))}updateRow(e,t){var o,i,r,l,a;const s=(o=this.bodyModel)==null?void 0:o.getAllRows().find(c=>this.hasId(c,e));s&&(Object.assign(s,t),(r=(i=this.tableModel)==null?void 0:i.getTableScope())==null||r.invalidateAggregates(),(a=(l=this.tableModel)==null?void 0:l.getTableScope())==null||a.repaint())}addRow(e){var s,o,i,r;const t=this.bodyModel;if(t){const l=t.getAllRows(),a=t.getFilteredRows();l.push(e),a!==l&&a.push(e),(o=(s=this.tableModel)==null?void 0:s.getTableScope())==null||o.invalidateAggregates(),(r=(i=this.tableModel)==null?void 0:i.getTableScope())==null||r.repaintHard()}}reloadRows(){const e=this.crudOptions;return e.fetchList(e).then(t=>{var o,i;(o=this.bodyModel)==null||o.setRows(t??[]);const s=(i=this.tableModel)==null?void 0:i.getTableScope();s==null||s.externalFilterChanged(!1),s==null||s.repaintHard()})}whileLoading(e){var o;const t=(o=this.tableModel)==null?void 0:o.getTableScope();this.pendingRequests++,t==null||t.showLoadingOverlay();const s=()=>{this.pendingRequests=Math.max(0,this.pendingRequests-1),this.pendingRequests===0&&(t==null||t.hideOverlay())};return Promise.resolve().then(e).then(i=>(s(),i),i=>{throw s(),i})}getIdKey(){var e,t;return((t=(e=this.crudOptions).getIdKey)==null?void 0:t.call(e))??"id"}hasId(e,t){const s=this.getValueByT(e,this.getIdKey());return s!=null&&String(s)===String(t)}isItemWithId(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;const t=this.getValueByT(e,this.getIdKey());return t!=null}logError(e,t){console.error(`CrudTableModelFactory: ${e} failed`,t)}calcAutoColumnWidths(e,t,s=t){var c;const o=t.length;if(!((c=this.crudOptions.columnWidths)!=null&&c.autoCalc))return new Array(o).fill(200);const i=e.length??0,r=new Array(o).fill(0);for(let h=0;h<i;h++)for(let d=0;d<o;d++){const u=t[d],f=this.getValueByT(e[h],u),g=(f==null?void 0:f.toString().length)||0;g>r[d]&&(r[d]=g)}if(this.crudOptions.columnWidths.takeHeaderLabelsIntoAccount)for(let h=0;h<o;h++){const d=s[h].length||0;d>r[h]&&(r[h]=d)}const l=this.crudOptions.columnWidths.minWidth,a=this.crudOptions.columnWidths.maxWidth;return r.map((h,d)=>Math.min(a,Math.max(this.crudOptions.columnWidths.charCountToWidth(h,d),l)))}getValueByT(e,t){return t.includes(".")?this.getPropertyValue(e,t.split(".")):e[t]}getPropertyValue(e,t){const s=t.shift(),o=e[s];return o&&t.length?this.getPropertyValue(o,t):o}extractProperties(e,t="",s=[]){for(const o in e)if(e.hasOwnProperty(o)){const i=t?`${t}.${o}`:o;typeof e[o]=="object"&&e[o]!==null&&!Array.isArray(e[o])?this.extractProperties(e[o],i,s):s.push(i)}return s}}class Hd{constructor(e,t){this.method=e,this.url=t}}class zl{constructor(e,t,s,o,i,r,l,a){this.key=e,this.label=t,this.level=s,this.field=o,this.path=i,this.parent=r,this.source=l,this.type="RowGroup",this.children=[],this.count=0,this.results={},this.sourceIndices=[],this.states=[],this.idParts=[...(r==null?void 0:r.idParts)??[],[o,a]]}get id(){return"rowgroup:"+JSON.stringify(this.idParts)}isLeaf(){return this.children.length===0}getRows(e=!0){return this.collectIndices(e,[]).map(t=>this.source[t])}collectIndices(e,t){if(this.isLeaf()){const s=e?this.accept:void 0;for(const o of this.sourceIndices)(!s||s(o))&&t.push(o)}else for(const s of this.children)s.collectIndices(e,t);return t}}function Os(n,e,t){var r;const s=[],o=e.length;if(!o)return s;const i={byKey:new Map};for(let l=0;l<n.length;l++){const a=n[l];let c=i,h;for(let d=0;d<o;d++){const u=e[d];let f=u.getKey(a);Et(f)&&(f=Ec);let g;const p=f instanceof Date?f.getTime():void 0;if(p!==void 0?g=(r=c.byTime)==null?void 0:r.get(p):g=c.byKey.get(f),!g){const m=u.format&&!Et(f)?u.format(f):Ic(f,t),b=new zl(f,`${m??""}`,d,u.name,h?[...h.path,f]:[f],h,n,st(f));g=[b,{byKey:new Map}],p!==void 0?(c.byTime??(c.byTime=new Map)).set(p,g):c.byKey.set(f,g),(h?h.children:s).push(b)}h=g[0],c=g[1]}h.sourceIndices.push(l)}return jl(s,e),s}function jl(n,e){var s;if(!n.length)return;const t=(s=e[n[0].level])==null?void 0:s.compare;t&&n.sort((o,i)=>t(o.key,i.key));for(const o of n)jl(o.children,e)}function Xl(n,e,t){for(const s of n)Jl(s,e,t);return Yl(n,e)}function Yl(n,e){const t=e.map(o=>o.aggregator.init());for(const o of n)e.forEach((i,r)=>t[r]=i.aggregator.merge(t[r],o.states[r]));const s={};return e.forEach((o,i)=>s[o.key]=o.aggregator.result(t[i])),s}function Jl(n,e,t){if(n.isLeaf()){ql(n,e,t);return}for(const s of n.children)Jl(s,e,t);Zl(n,e)}function ql(n,e,t){const s=n.source;let o=n.sourceIndices;if(t){o=[];for(const l of n.sourceIndices)t(l)&&o.push(l)}const i=o.length,r=e.map(l=>{const a=l.aggregator,c=l.getValue;let h=a.init();for(let d=0;d<i;d++){const u=s[o[d]];h=a.add(h,c?c(u):u)}return h});n.accept=t,n.states=r,n.count=i,n.results=Ql(r,e)}function Zl(n,e){const t=e.map(o=>o.aggregator.init());let s=0;for(const o of n.children)s+=o.count,e.forEach((i,r)=>t[r]=i.aggregator.merge(t[r],o.states[r]));n.states=t,n.count=s,n.results=Ql(t,e)}function Ql(n,e){const t={};return e.forEach((s,o)=>t[s.key]=s.aggregator.result(n[o])),t}const Gd="(empty)";function Wd(n,e,t={}){return Os(n,Ve(e),t.emptyLabel??Gd)}function Ud(n,e,t){const s=Object.keys(e??{}).map(o=>ls(o,e[o]));return Xl(n,s,t)}const Ws=class Ws extends be{constructor(e={}){const t={width:new T(220,"px"),showCount:!0,fixed:!0,...e};super(Ws.PROPERTY,t.headerLabel??"Group",t.width,new ee(["ge-table-row-group-column-header"],["ge-table-row-group-column"],[]),new ee,new T(60,"px"),new T(2e3,"px"),Ft),this.type="RowGroupColumnDef",this.options=t,this.autoHeaderLabel=e.headerLabel===void 0}};Ws.PROPERTY="RowGroupColumn";let J=Ws;class qe extends ze{constructor(e,t,s,o){super(e,!1,void 0,t,s),this.sourceIndex=o}}const Kd=new Intl.NumberFormat("en-US");class ea extends rt{constructor(e,t,s,o=34){super("body",[],o,t),this.kind="AreaModelRowGroups",this.hiddenColumnProperties=[],this.fields=[],this.groups=[],this.textRenderer=new kt,this.groupRowById=new Map,this.detailRows=[],this.allDirty=!0,this.dirtyLeaves=new Set,this.totals={},this.batchDepth=0,this.regroupPending=!1,this.builds=0,this.sourceRows=e??[],this.options={...s,groupBy:[...s.groupBy??[]]};const i=s.aggregations??{};this.specs=Object.keys(i).map(r=>this.withCalculatedValue(ls(r,i[r]))),this.specByKey=new Map(this.specs.map(r=>[r.key,r])),this.fields=this.withCalculatedKeys(Ve(this.options.groupBy)),this.build(!1)}getSourceRows(){return this.sourceRows}setRows(e){this.sourceRows=e??[],this.build(!0)}getGroupBy(){return[...this.options.groupBy]}setGroupBy(e){const t=Ve(e??[]);this.options.groupBy=[...e??[]],this.fields=this.withCalculatedKeys(t),this.build(!0)}regroup(){this.build(!0)}getGroups(){return this.ensureAggregates(),this.groups}findGroup(e){this.ensureAggregates();let t=this.groups,s;for(const o of e){const i=st(o);if(s=t.find(r=>st(r.key)===i),!s)return;t=s.children}return s}getRowGroup(e){var s;const t=(s=this.getRowByIndex(e))==null?void 0:s.data;if(le(t))return this.ensureAggregates(),t}getDetailRow(e){const t=this.getRowByIndex(e);return t&&!le(t.data)?t.data:void 0}isGroupRowIndex(e){var t;return le((t=this.getRowByIndex(e))==null?void 0:t.data)}getTotals(){return this.ensureAggregates(),this.totals}getCheckedRows(){const e=[];return this.detailRows.forEach(t=>{t.checked&&e.push(t.data)}),e}expandToLevel(e){this.groupRowById.forEach(t=>t.expanded=t.data.level<e),this.recalcVisibleTreeRows(!1)}getBuildCount(){return this.builds}batch(e){this.batchDepth++;try{e()}finally{this.batchDepth--}return this.batchDepth||!this.regroupPending?!1:(this.regroupPending=!1,this.build(!0),!0)}getRawValueOfRow(e,t){if(le(e.data)){this.ensureAggregates();const s=e.data;return t===J.PROPERTY?this.getGroupLabel(s):this.specByKey.has(t)?s.results[t]:""}return t===J.PROPERTY?"":super.getRawValueOfRow(e,t)}canMoveRows(e,t){return!1}moveRows(e,t){return!1}getTextValueAt(e,t){const s=this.getRowByIndex(e),o=this.properties[t];if(s&&o!==void 0&&o!==J.PROPERTY&&this.getColumnValues().getShowValuesAs(o))return this.getCalculatedText(o,this.getValueAt(e,t))??"";if(s&&le(s.data)&&o!==J.PROPERTY){const r=o!==void 0?this.specByKey.get(o):void 0;if(!r)return"";const l=this.getValueAt(e,t);return r.format?r.format(l):It(l)}const i=this.getValueAt(e,t);return i==null?"":`${i}`}getCellRenderer(e,t){const s=this.getRowByIndex(e),o=this.properties[t];return s&&le(s.data)?o!==void 0&&this.specByKey.has(o)?this.textRenderer:void 0:o===J.PROPERTY?void 0:super.getCellRenderer(e,t)}getCustomClassesAt(e,t){const s=super.getCustomClassesAt(e,t),o=this.getRowByIndex(e);if(!o||!le(o.data))return s;const i=this.properties[t],r=o.data.level,l=[...s,"ge-table-row-group",`ge-table-row-group-level-${r}`];return i===J.PROPERTY?l.push("ge-table-row-group-label"):i!==void 0&&this.specByKey.has(i)&&l.push("ge-table-row-group-aggregate"),l}isGroupLabelCell(e,t){return this.properties[t]===J.PROPERTY&&this.isGroupRowIndex(e)}isEditable(e,t){return this.properties[t]===J.PROPERTY||this.isGroupRowIndex(e)?!1:super.isEditable(e,t)}setValue(e,t,s){const o=this.getRowByIndex(e);if(!(o instanceof qe)||this.properties[t]===J.PROPERTY)return!1;const i=this.keysOf(o.data);if(!super.setValue(e,t,s))return!1;const l=this.keysOf(o.data);return i.some((a,c)=>st(a)!==st(l[c]))?this.batchDepth?this.regroupPending=!0:this.build(!0):this.markRowDirty(o),!0}externalFilterChanged(e){this.userFilter=e;const t=this.sourceRows,s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=e(t[o],o,t)?1:0;this.accepted=s,this.allDirty=!0,super.externalFilterChanged(o=>o instanceof qe&&s[o.sourceIndex]===1)}doSort(e){if(!e.length)return!1;this.lastSort={items:[...e]},this.ensureAggregates();const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.createRowComparator(this.properties[s],i)});return super.sort((s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}),this.syncGroupOrder(),this.allDirty=!0,!0}sort(e){this.lastSort={compareFn:e},super.sort((t,s)=>t instanceof qe&&s instanceof qe?e(t.data,s.data):0),this.syncGroupOrder(),this.allDirty=!0}invalidateDerivedValues(e){if(super.invalidateDerivedValues(e),(e==null?void 0:e.area)==="body"&&Array.isArray(e.rowIndices)){for(const t of e.rowIndices){const s=this.getRowByIndex(t);s instanceof qe?this.markRowDirty(s):this.allDirty=!0}return}this.allDirty=!0}withCalculatedValue(e){const t=e.value,s=e.getValue;return!s||typeof t!="string"?e:{...e,getValue:o=>this.isCalculatedProperty(t)?this.getValueByT(o,t):s(o)}}withCalculatedKeys(e){return e.map(t=>{const s=t.path,o=t.getKey;return s===void 0?t:{...t,getKey:i=>this.isCalculatedProperty(s)?this.getValueByT(i,s):o(i)}})}syncGroupOrder(){const e=t=>(t??[]).filter(s=>le(s.data)).map(s=>{const o=s.data;if(o.isLeaf()){const i=(s.children??[]).map(r=>r.sourceIndex);o.sourceIndices.length=0;for(const r of i)o.sourceIndices.push(r)}else{const i=e(s.children);o.children.length=0,o.children.push(...i)}return o});this.groups=e(this.rows)}getGroupLabel(e){const t=this.options.groupColumn;return t!=null&&t.label?`${t.label(e)??""}`:(t==null?void 0:t.showCount)===!1?e.label:`${e.label} (${Kd.format(e.count)})`}ensureAggregates(){if(!this.allDirty&&!this.dirtyLeaves.size)return;const e=this.accepted?(s=>o=>s[o]===1)(this.accepted):void 0;if(!this.fields.length){if(this.allDirty||this.dirtyLeaves.size){const s=e?this.sourceRows.filter((i,r)=>e(r)):this.sourceRows,o=Ys(s,this.specs);this.totals={},this.specs.forEach((i,r)=>this.totals[i.key]=i.aggregator.result(o[r])),this.allDirty=!1,this.dirtyLeaves.clear()}return}if(this.allDirty){this.totals=Xl(this.groups,this.specs,e),this.allDirty=!1,this.dirtyLeaves.clear();return}if(!this.dirtyLeaves.size)return;const t=new Set;this.dirtyLeaves.forEach(s=>{ql(s,this.specs,e);for(let o=s.parent;o;o=o.parent)t.add(o)}),this.dirtyLeaves.clear(),Array.from(t).sort((s,o)=>o.level-s.level).forEach(s=>Zl(s,this.specs)),this.totals=Yl(this.groups,this.specs)}markRowDirty(e){var s;const t=(s=e.parent)==null?void 0:s.data;le(t)?this.dirtyLeaves.add(t):this.allDirty=!0}keysOf(e){return this.fields.map(t=>t.getKey(e))}createRowComparator(e,t){if(!t||e===void 0)return()=>0;const s=this.genericTreeTableSortComparator(e,t),o=this.specByKey.has(e),i=e===J.PROPERTY;return(r,l)=>{const a=le(r.data),c=le(l.data);if(a&&c){const h=r.data,d=l.data;if(o)return this.sorterService.genericSortComparator(h.results[e],d.results[e],t);const u=this.fields[h.level];if(i||(u==null?void 0:u.path)===e){const f=u==null?void 0:u.compare;return f?t*f(h.key,d.key):0}return 0}return!a&&!c&&!i?s(r,l):0}}build(e){const t=new Map,s=new Set;e&&(this.groupRowById.forEach((l,a)=>t.set(a,l.expanded)),this.detailRows.forEach(l=>l.checked&&s.add(l.data))),this.builds++;const o=this.options.emptyLabel??"(empty)";this.groups=Os(this.sourceRows,this.fields,o),this.groupRowById=new Map,this.detailRows=new Array(this.sourceRows.length);const i=[];if(this.fields.length)for(const l of this.groups)i.push(this.createGroupRow(l,void 0,t));else for(let l=0;l<this.sourceRows.length;l++)i.push(this.detailRows[l]=new qe(this.sourceRows[l],void 0,0,l));this.rows.length=0;for(const l of i)this.rows.push(l);s.size&&(this.detailRows.forEach(l=>l.checked=s.has(l.data)),this.rows.forEach(l=>ta(l))),this.allDirty=!0,this.dirtyLeaves.clear(),this.userFilter?this.externalFilterChanged(this.userFilter):this.recalcVisibleTreeRows(!1);const r=this.lastSort;r&&"items"in r?this.doSort(r.items):r&&this.sort(r.compareFn)}createGroupRow(e,t,s){const o=e.id,i=s.get(o)??this.isExpandedByDefault(e),r=new ze(e,i,[],t,e.level);if(this.groupRowById.set(o,r),e.isLeaf()){const l=e.level+1;for(const a of e.sourceIndices){const c=new qe(this.sourceRows[a],r,l,a);this.detailRows[a]=c,r.children.push(c)}}else for(const l of e.children)r.children.push(this.createGroupRow(l,r,s));return r}isExpandedByDefault(e){const t=this.options.expanded??!0;return typeof t=="function"?!!t(e):typeof t=="number"?e.level<t:t}}function ta(n){var t;if(!((t=n.children)!=null&&t.length))return n.checked;let e=!0;for(const s of n.children)ta(s)||(e=!1);return n.checked=e,e}class Fi{static createTableModel(e){var d,u;const t=e.rows??[];let s=e.columnDefs?[...e.columnDefs]:t.length?Object.keys(t[0]).map(f=>new be(f,f.toUpperCase(),Ls)):[];const o=e.defaultRowHeights??((d=e.tableOptions)==null?void 0:d.defaultRowHeights)??new Fe;let i=e.fixedLeftColumnCount??0;e.rowNumbersVisible&&!O(s[0])&&(s=[new ds(e.rowNumbersVisible===!0?{}:e.rowNumbersVisible),...s],i++);let r=O(s[0])?1:0;const l=me(s[r]);l&&r++;const a=new J(e.groupColumn??{});a.autoHeaderLabel&&(a.headerLabel=Ln(e.groupBy??[],s)),s.splice(r,0,a),a.options.fixed&&(i=Math.max(i,r)+1);const c=new ea(t,s,{groupBy:e.groupBy??[],aggregations:e.aggregations,expanded:e.expanded,emptyLabel:e.emptyLabel,groupColumn:a.options,hideGroupedColumns:e.hideGroupedColumns},o.body);(l||(u=e.tableOptions)!=null&&u.showCheckboxWihoutExtraColumn)&&(c.rowSelectionModel=new Rt(c.rows));const h=ye.createTableModel({columnDefs:s,bodyAreaModel:c,footerAggregates:Fi.footerConfig(e),fixedLeftColumnCount:i,fixedRightColumnCount:e.fixedRightColumnCount??0,rowCheckboxVisible:e.rowCheckboxVisible??l,defaultRowHeights:o,getSelectionModel:e.getSelectionModel,tableOptions:e.tableOptions});return _o(h),h}static updateLayout(e){return _o(e)}static footerConfig(e){const t=e.footerAggregates;if(t!==!1)return t===void 0||t===!0?e.aggregations&&Object.keys(e.aggregations).length?e.aggregations:void 0:t}}class sa extends be{constructor(e,t,s,o=new T(100,"px")){super(e,t,o,new ee(["ge-table-pivot-header",`ge-table-pivot-header-${s.kind}`],[],[]),new ee,new T(40,"px"),new T(2e3,"px"),Ft),this.pivot=s,this.type="PivotColumnDef"}}const zd=1e3,Oi="Total";function jd(n){const e=n??[];if(!e.length)throw new Error('Pivot: at least one value is needed (values: ["amount"]).');const t=new Set;return e.map((s,o)=>{const i=typeof s=="string"||typeof s=="function"?{value:s}:s;if(!i||typeof i.value!="string"&&typeof i.value!="function")throw new Error(`Pivot: value ${o} has no value (a property path or a function).`);const r=Xs(i.aggregator??"sum"),l=typeof i.value=="string"?i.value:`value${o}`;let a=i.name??`${r.name}(${l})`;if(t.has(a)){let c=2;for(;t.has(`${a}#${c}`);)c++;a=`${a}#${c}`}return t.add(a),{name:a,label:i.label??a,aggregator:r,format:i.format,showValuesAs:Dt(i.showValuesAs),getValue:r===Oe.count?void 0:ns(i.value)}})}const Xd="(empty)";class Ps{constructor(e,t,s){this.source=e,this.allColumnLeaves=[],this.shownColumns=new Set,this.columnParentsPostOrder=[],this.rowParentsPostOrder=[],this.rowLeaves=[],this.cells=new Map,this.resolved=jd(t.values),this.values=this.resolved;const o=t.emptyLabel??Xd;this.rowGroups=Os(e,Ve(t.rowFields??[]),o),this.columnGroups=Os(e,Ve(t.columnFields??[]),o);const i=Math.max(0,t.maxColumns??zd),r=this.allColumnLeaves;ys(this.columnGroups,r),this.truncated=r.length>i,this.truncated&&console.warn(`Pivot: ${r.length} column keys, only the first ${i} are shown (maxColumns). Totals and subtotals count all rows.`),this.columnLeaves=this.truncated?r.slice(0,i):r,this.columnLeafOf=new Int32Array(e.length).fill(-1),r.forEach((l,a)=>{for(const c of l.sourceIndices)this.columnLeafOf[c]=a});for(const l of this.columnLeaves)for(let a=l;a&&!this.shownColumns.has(a);a=a.parent)this.shownColumns.add(a);Jo(this.columnGroups,this.columnParentsPostOrder,()=>!0),Jo(this.rowGroups,this.rowParentsPostOrder,()=>!0),ys(this.rowGroups,this.rowLeaves),this.compute(s)}compute(e){this.accept=e;const t=new Map;if(this.rowGroups.length){for(const a of this.rowLeaves)a.accept=e,t.set(a,this.leafCells(a.sourceIndices));for(const a of this.rowParentsPostOrder){const c=new Map;for(const h of a.children)this.mergeMap(c,t.get(h));t.set(a,c)}const l=new Map;for(const a of this.rowGroups)this.mergeMap(l,t.get(a));t.set(null,l)}else{const l=[];for(let a=0;a<this.source.length;a++)l.push(a);t.set(null,this.leafCells(l))}this.cells=t;const s=(l,a)=>{l.count=(a==null?void 0:a.count)??0;const c={};this.values.forEach((h,d)=>c[h.name]=a&&a.count?h.aggregator.result(a.states[d]):void 0),l.results=c},o=l=>l.forEach(a=>{var c;s(a,(c=t.get(a))==null?void 0:c.get(null)),o(a.children)});o(this.rowGroups);const i=t.get(null),r=l=>l.forEach(a=>{a.isLeaf()&&(a.accept=e),s(a,i.get(a)),r(a.children)});r(this.columnGroups)}getValue(e,t,s=0){const o=this.valueIndex(s),i=this.cell(e,t);if(!(!i||!i.count||o<0))return this.values[o].aggregator.result(i.states[o])}getCount(e,t){var s;return((s=this.cell(e,t))==null?void 0:s.count)??0}getSourceRows(e,t){let s;if(e)s=e.collectIndices(!1,[]).sort((l,a)=>l-a);else{s=[];for(let l=0;l<this.source.length;l++)s.push(l)}const o=this.accept;let i;if(t){i=new Set;const l=[];ys([t],l);for(const a of l){const c=this.allColumnLeaves.indexOf(a);c>=0&&i.add(c)}}const r=[];for(const l of s)o&&!o(l)||i&&!i.has(this.columnLeafOf[l])||r.push(this.source[l]);return r}isColumnShown(e){return this.shownColumns.has(e)}valueIndex(e){return typeof e=="number"?e>=0&&e<this.values.length?e:-1:this.values.findIndex(t=>t.name===e)}cell(e,t){var s;return(s=this.cells.get(e??null))==null?void 0:s.get(t??null)}newCell(){return{count:0,states:this.values.map(e=>e.aggregator.init())}}leafCells(e){const t=this.resolved,s=t.length,o=this.accept,i=this.source,r=this.columnLeafOf,l=new Array(this.allColumnLeaves.length),a=this.newCell(),c=new Array(s);for(let d=0;d<e.length;d++){const u=e[d];if(o&&!o(u))continue;const f=i[u],g=r[u],p=g>=0?l[g]??(l[g]=this.newCell()):void 0;a.count++;for(let m=0;m<s;m++){const b=t[m].getValue;c[m]=b?b(f):f,a.states[m]=t[m].aggregator.add(a.states[m],c[m])}if(p){p.count++;for(let m=0;m<s;m++)p.states[m]=t[m].aggregator.add(p.states[m],c[m])}}const h=new Map;for(let d=0;d<l.length;d++){const u=l[d];u&&h.set(this.allColumnLeaves[d],u)}for(const d of this.columnParentsPostOrder){let u;for(const f of d.children){const g=h.get(f);g&&(u??(u=this.newCell()),this.mergeInto(u,g))}u&&h.set(d,u)}return h.set(null,a),h}mergeInto(e,t){e.count+=t.count,this.values.forEach((s,o)=>e.states[o]=s.aggregator.merge(e.states[o],t.states[o]))}mergeMap(e,t){t.forEach((s,o)=>{let i=e.get(o);i||(i=this.newCell(),e.set(o,i)),this.mergeInto(i,s)})}}function Yd(n,e,t){return new Ps(n??[],e,t)}function ys(n,e){for(const t of n)t.isLeaf()?e.push(t):ys(t.children,e)}function Jo(n,e,t){for(const s of n)s.isLeaf()||!t(s)||(Jo(s.children,e,t),e.push(s))}function oa(n,e){return"pivot:"+JSON.stringify([...n.idParts,e.name])}function ia(n,e){return"pivot:subtotal:"+JSON.stringify([...n.idParts,e.name])}function qo(n){return"pivot:total:"+JSON.stringify([n.name])}function Jd(n){const e=n.slice(n.lastIndexOf(".")+1);return e.charAt(0).toUpperCase()+e.slice(1)}function ra(n){return kn(Ve(n),Jd).join(" › ")}function qd(n){var e;return n.columnSubtotals??(((e=n.columnFields)==null?void 0:e.length)??0)>1}function na(n,e,t,s={}){var m;const o=n.values,i=o.length>1,r=e.totalLabel??Oi,l=qd(e),a=(((m=e.columnFields)==null?void 0:m.length)??0)>0,c=s.valueWidth??new T(100,"px"),h=[...t],d=t.map(b=>({data:b.headerLabel,property:b.property})),u=(b,y,C)=>{var S;return h.push(new sa(b,y,C,((S=s.widths)==null?void 0:S.get(b))??c)),{data:y,property:b}},f=(b,y,C,S,E)=>i?{data:b,visibility:E,children:o.map((x,R)=>u(S(x),x.label,{kind:y,column:C,value:x,valueIndex:R}))}:{...u(S(o[0]),b,{kind:y,column:C,value:o[0],valueIndex:0}),visibility:E},g=b=>{var C;if(!n.isColumnShown(b))return;if(b.isLeaf())return f(b.label,"value",b,S=>oa(b,S));const y=b.children.map(g).filter(S=>!!S);return l&&y.push(f(`${b.label} ${r}`,"subtotal",b,S=>ia(b,S),"always")),{id:b.id,data:b.label,toggle:l,closed:l&&!!((C=s.closedIds)!=null&&C.has(b.id)),children:y}};let p=0;if(a){for(const b of n.columnGroups){const y=g(b);y&&d.push(y)}e.totalColumn!==!1&&(d.push(f(r,"total",void 0,b=>qo(b))),(e.totalColumn===void 0||e.totalColumn==="fixed")&&(p=o.length))}else o.forEach((b,y)=>d.push(u(qo(b),b.label,{kind:"total",value:b,valueIndex:y})));return{columnDefs:h,cellGroups:d,fixedRightColumnCount:p}}class la extends Ke{constructor(e,t,s,o,i,r,l,a,c,h){super(e,t,s,l,r,!1,a,i,[],-1,0,400,c),this.leadingColumnDefs=o,this.valueWidth=h,this.kind="PivotTableModel",this.pivotFixedRightColumnCount=r}getFixedRightColumnCount(){return this.pivotFixedRightColumnCount}getPivotBody(){return this.bodyAreaModel}getPivotConfig(){return this.getPivotBody().getConfig()}setPivotConfig(e,t){const s=this.getPivotBody(),o={...s.getConfig(),...e};s.configure(o,t),this.relayout()}relayout(){const e=this.getPivotBody(),t=this.headerAreaModel,s=e.getConfig(),o=this.leadingColumnDefs.find(ot);o!=null&&o.autoHeaderLabel&&(o.headerLabel=ra(s.rowFields??[]));const i=new Set(t.getToggleGroupStates().filter(d=>d.closed).map(d=>d.id)),r=this.columnDefs.filter(zs),l=new Map(r.map(d=>[d.property,d.width])),a=new Set(r.filter(d=>!Lo(d)).map(d=>d.property)),c=na(e.getResult(),s,this.leadingColumnDefs,{valueWidth:this.valueWidth,closedIds:i,widths:l}),h=t.setGroups(c.cellGroups,c.columnDefs);h.filter(d=>a.has(d.property)).forEach(d=>nn(d,!1)),this.columnDefs=h,this.columnCount=h.length,this.columnSizes=[],this.pivotFixedRightColumnCount=c.fixedRightColumnCount,e.setColumnDefs(h)}}const Zd=new Intl.NumberFormat("en-US");class aa extends rt{constructor(e,t,s={},o=34){super("body",[],o,[]),this.kind="AreaModelPivot",this.rowFields=[],this.textRenderer=new kt,this.infoByProperty=new Map,this.dirty=!1,this.builds=0,this.sourceRows=e??[],this.config={...t},this.groupColumnOptions=s,this.build(!1)}getConfig(){return{...this.config}}getResult(){return this.ensureComputed(),this.result}getSourceRows(){return this.sourceRows}getBuildCount(){return this.builds}configure(e,t){const s=new Ps(t??this.sourceRows,e);this.config={...e},t&&(this.sourceRows=t),this.build(!0,s)}setColumnDefs(e){this.columnDefs=e,this.properties.length=0;for(const t of e)this.properties.push(t.property);this.infoByProperty=new Map;for(const t of e)zs(t)&&this.infoByProperty.set(t.property,t.pivot)}getPropertyAt(e){return this.properties[e]}getRowGroup(e){var s;const t=(s=this.getRowByIndex(e))==null?void 0:s.data;return t&&t.type==="RowGroup"?t:void 0}getColumnInfo(e){const t=this.properties[e];return t===void 0?void 0:this.infoByProperty.get(t)}getColumnProperty(e,t=0){const s=this.result,o=s.values[s.valueIndex(t)];if(!o)return;if(!e.length){const a=qo(o);return this.infoByProperty.has(a)?a:void 0}let i=s.columnGroups,r;for(const a of e){const c=st(a);if(r=i.find(h=>st(h.key)===c),!r)return;i=r.children}const l=r.isLeaf()?oa(r,o):ia(r,o);return this.infoByProperty.has(l)?l:void 0}getColumnIndex(e,t=0){const s=this.getColumnProperty(e,t);return s===void 0?-1:this.properties.indexOf(s)}getCellSourceRows(e,t){const s=this.getResult(),o=this.getRowGroup(e);if(!o&&this.rowFields.length)return[];const i=this.getColumnInfo(t);return s.getSourceRows(o,(i==null?void 0:i.kind)==="total"||i==null?void 0:i.column)}getValueAt(e,t){if(!this.getRowByIndex(e))return"";const o=this.properties[t],i=this.getRowGroup(e);if(o===J.PROPERTY)return i?this.getGroupLabel(i):this.config.totalLabel??Oi;const r=o===void 0?void 0:this.infoByProperty.get(o);if(!r)return"";if(!(i&&i.children.length>0&&this.config.subtotals===!1))return this.getShownValue(i,r)}getShownValue(e,t){const s=this.getResult(),o=s.getValue(e,t.column,t.valueIndex),i=t.value.showValuesAs;if(!i||typeof o!="number")return o;let r;switch(i.mode){case"percentOfRowTotal":r=s.getValue(e,void 0,t.valueIndex);break;case"percentOfColumnTotal":r=s.getValue(void 0,t.column,t.valueIndex);break;case"percentOfGrandTotal":r=s.getValue(void 0,void 0,t.valueIndex);break;case"percentOfParentTotal":{const l=e==null?void 0:e.parent;r=s.getValue(e?l??void 0:void 0,t.column,t.valueIndex);break}default:return o}return typeof r=="number"&&r!==0?o/r:void 0}canMoveRows(e,t){return!1}moveRows(e,t){return!1}getTextValueAt(e,t){const s=this.properties[t],o=s===void 0?void 0:this.infoByProperty.get(s),i=this.getValueAt(e,t);return o?i===void 0?this.isSubtotalSuppressed(e)?"":this.config.emptyText??"":o.value.showValuesAs?Js(i,o.value.showValuesAs):o.value.format?o.value.format(i):It(i):i==null?"":`${i}`}getCellRenderer(e,t){const s=this.properties[t];if(s!==void 0&&this.infoByProperty.has(s))return this.textRenderer}getCustomClassesAt(e,t){const s=super.getCustomClassesAt(e,t),o=this.properties[t],i=this.getRowGroup(e),r=[...s,`ge-table-pivot-level-${(i==null?void 0:i.level)??0}`],l=!!i&&i.children.length>0;if(o===J.PROPERTY)return r.push("ge-table-pivot-label"),l&&r.push("ge-table-pivot-subtotal"),r;const a=o===void 0?void 0:this.infoByProperty.get(o);return a&&(r.push("ge-table-pivot-value"),(l||a.kind==="subtotal")&&r.push("ge-table-pivot-subtotal"),a.kind==="total"&&r.push("ge-table-pivot-total"),this.getValueAt(e,t)===void 0&&r.push("ge-table-pivot-empty")),r}isRowHeaderCell(e,t){return this.properties[t]===J.PROPERTY&&!!this.getRowByIndex(e)}isEditable(e,t){return!1}setValue(e,t,s){return!1}externalFilterChanged(e){this.userFilter=e,this.accepted=this.acceptedBy(this.userFilter),this.dirty=!0,this.ensureComputed();const t=this.result;super.externalFilterChanged(s=>{var o;return!((o=s.children)!=null&&o.length)&&(!this.rowFields.length||t.getCount(s.data)>0)})}doSort(e){if(!e.length)return!1;this.ensureComputed();const t=e.map(({columnIndex:s,sortState:o})=>{const i=o==="asc"?1:o==="desc"?-1:0;return this.createRowComparator(this.properties[s],i)});return super.sort((s,o)=>{for(const i of t){const r=i(s,o);if(r)return r}return 0}),!0}sort(e){super.sort((t,s)=>e(t.data,s.data))}invalidateDerivedValues(){super.invalidateDerivedValues(),this.dirty=!0}isSubtotalSuppressed(e){const t=this.getRowGroup(e);return this.config.subtotals===!1&&!!t&&t.children.length>0}getGroupLabel(e){const t=this.groupColumnOptions;return t.label?`${t.label(e)??""}`:t.showCount?`${e.label} (${Zd.format(e.count)})`:e.label}ensureComputed(){var t;if(!this.dirty)return;this.dirty=!1,this.userFilter&&((t=this.accepted)==null?void 0:t.length)!==this.sourceRows.length&&(this.accepted=this.acceptedBy(this.userFilter));const e=this.accepted;this.result.compute(e?(s=>e[s]===1):void 0)}acceptedBy(e){const t=this.sourceRows,s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=e(t[o],o,t)?1:0;return s}createRowComparator(e,t){if(!t||e===void 0)return()=>0;if(e===J.PROPERTY)return(i,r)=>{var h;const l=i.data,a=r.data,c=(h=this.rowFields[l.level])==null?void 0:h.compare;return c?t*c(l.key,a.key):0};const s=this.infoByProperty.get(e);if(!s)return()=>0;const o=this.columnDefs.find(i=>i.property===e);return(i,r)=>{const l=this.getShownValue(i.data,s),a=this.getShownValue(r.data,s);return l===void 0||a===void 0?l===a?0:l===void 0?1:-1:o!=null&&o.sortComparator?t*o.sortComparator(l,a,i.data,r.data,t):this.sorterService.genericSortComparator(l,a,t)}}build(e,t){const s=new Map;if(e){const i=r=>r.forEach(l=>{var a;((a=l.data)==null?void 0:a.type)==="RowGroup"&&s.set(l.data.id,l.expanded),l.children&&i(l.children)});i(this.rows)}this.builds++,this.rowFields=Ve(this.config.rowFields??[]),this.result=t??new Ps(this.sourceRows,this.config),this.dirty=!1;const o=[];if(this.rowFields.length)for(const i of this.result.rowGroups)o.push(this.createRow(i,void 0,s));else o.push(new ze({type:"PivotTotal"},!0,void 0,void 0,0));this.rows.length=0;for(const i of o)this.rows.push(i);this.userFilter?this.externalFilterChanged(this.userFilter):this.recalcVisibleTreeRows(!1)}createRow(e,t,s){const o=s.get(e.id)??this.isExpandedByDefault(e),i=e.isLeaf()?void 0:[],r=new ze(e,o,i,t,e.level);for(const l of e.children)i.push(this.createRow(l,r,s));return r}isExpandedByDefault(e){const t=this.config.expanded??!0;return typeof t=="function"?!!t(e):typeof t=="number"?e.level<t:t}}class ca extends Ii{constructor(e,t=34){super(),this.body=e,this.defaultRowHeight=t,this.type="AreaModelPivotFooter",this.textRenderer=new kt,this.areaIdent="footer"}getRowCount(){var t;const e=this.body.getConfig();return e.totalRow===!1||!((t=e.rowFields)!=null&&t.length)?0:1}getRowHeight(e){return this.defaultRowHeight}getConstantRowHeight(){return this.defaultRowHeight}getValueAt(e,t){if(e!==0)return"";if(this.isRowHeaderCell(e,t))return this.body.getConfig().totalLabel??Oi;const s=this.body.getColumnInfo(t);return s?this.body.getShownValue(void 0,s):""}getTextValueAt(e,t){const s=this.body.getColumnInfo(t),o=this.getValueAt(e,t);return s?o===void 0?this.body.getConfig().emptyText??"":s.value.showValuesAs?Js(o,s.value.showValuesAs):s.value.format?s.value.format(o):It(o):o==null?"":`${o}`}getCellRenderer(e,t){return this.body.getColumnInfo(t)||this.isLabelColumn(t)?this.textRenderer:void 0}getCustomClassesAt(e,t){if(this.isLabelColumn(t))return["ge-table-pivot-total","ge-table-pivot-label"];if(!this.body.getColumnInfo(t))return[];const o=["ge-table-pivot-value","ge-table-pivot-total"];return this.getValueAt(e,t)===void 0&&o.push("ge-table-pivot-empty"),o}isRowHeaderCell(e,t){return e===0&&this.isLabelColumn(t)}isLabelColumn(e){return this.body.getPropertyAt(e)===J.PROPERTY}}class Qd extends $l{getCustomClassesAt(e,t){const s=this.getValueAt(e,t);return s?s.ownColumn()?["ge-table-pivot-header-column"]:["ge-table-pivot-header-group"]:[]}}class Pi{static createTableModel(e){var f,g,p;const t=e.defaultRowHeights??((f=e.tableOptions)==null?void 0:f.defaultRowHeights)??new Fe,s=Pi.toConfig(e),o=[];e.rowNumbersVisible&&o.push(new ds(e.rowNumbersVisible===!0?{}:e.rowNumbersVisible));const i={showCount:!1,...e.groupColumn??{}},r=new J(i);r.autoHeaderLabel&&(r.headerLabel=ra(s.rowFields??[])),o.push(r);const l=r.options.fixed?o.length:o.length-1,a=new aa(e.rows??[],s,r.options,t.body),c=na(a.getResult(),s,o,{valueWidth:e.valueColumnWidth}),h=new Qd("header",c.cellGroups,c.columnDefs,t.header,(g=e.tableOptions)==null?void 0:g.headerGroupOptions);c.columnDefs=h.setGroups(c.cellGroups,c.columnDefs),a.setColumnDefs(c.columnDefs);const d=new ca(a,t.footer),u=e.getSelectionModel??((p=e.tableOptions)==null?void 0:p.getSelectionModel)??(()=>{});return new la(h,a,d,o,c.columnDefs,c.fixedRightColumnCount,l,t,u,e.valueColumnWidth)}static toConfig(e){return{rowFields:e.rowFields??[],columnFields:e.columnFields??[],values:e.values,subtotals:e.subtotals,columnSubtotals:e.columnSubtotals,totalColumn:e.totalColumn,totalRow:e.totalRow,maxColumns:e.maxColumns,expanded:e.expanded,emptyLabel:e.emptyLabel,emptyText:e.emptyText,totalLabel:e.totalLabel}}}class Ni{constructor(e){this.options=e,this.abort=new AbortController}static create(e){return new Ni(e.map(t=>({value:t,label:t})))}open(e,t){var l;const s=t.domService,o=s.createElement("select");this.select=o,s.setAttribute(o,"aria-label",t.ariaLabel),s.addClass(o,"ge-table-cell-editor-field");let i=-1;const r=(l=t.typedText)==null?void 0:l.toLowerCase();this.options.forEach((a,c)=>{const h=s.createElement("option");h.value=String(a.value),h.textContent=String(a.label),s.appendChild(o,h),r!==void 0?i<0&&String(a.label).toLowerCase().startsWith(r)&&(i=c):a.value===t.value&&(i=c)}),o.selectedIndex=i,o.addEventListener("change",()=>t.inputChanged(),{signal:this.abort.signal}),s.appendChild(e,o)}getValue(){var t;const e=this.select;return!e||e.selectedIndex<0?"":(t=this.options[e.selectedIndex])==null?void 0:t.value}getText(){return String(this.getValue()??"")}focus(){this.select&&this.select.ownerDocument.activeElement!==this.select&&this.select.focus({preventScroll:!0})}getFocusElement(){return this.select}wantsKey(e,t){var s,o;return e.altKey&&e.key==="ArrowDown"?((o=(s=this.select)==null?void 0:s.showPicker)==null||o.call(s),!0):e.key==="ArrowUp"||e.key==="ArrowDown"}close(){var e;this.abort.abort(),(e=this.select)==null||e.remove(),this.select=void 0}}class eu{constructor(e,t,s={}){this.api=t,this.abort=new AbortController,this.original="",this.options={addressBox:!0,ariaLabel:"Formula",addressAriaLabel:"Cell address",...s};const o=e.ownerDocument;this.element=o.createElement("div"),this.element.className="ge-table-formula-bar",this.addressInput=o.createElement("input"),this.addressInput.className="ge-table-formula-bar-address",this.addressInput.type="text",this.addressInput.autocomplete="off",this.addressInput.spellcheck=!1,this.addressInput.setAttribute("aria-label",this.options.addressAriaLabel),this.options.addressBox||(this.addressInput.hidden=!0);const i=o.createElement("span");i.className="ge-table-formula-bar-fx",i.setAttribute("aria-hidden","true"),i.textContent="fx",this.input=o.createElement("input"),this.input.className="ge-table-formula-bar-input",this.input.type="text",this.input.autocomplete="off",this.input.spellcheck=!1,this.input.setAttribute("aria-label",this.options.ariaLabel),this.element.append(this.addressInput,i,this.input),e.appendChild(this.element);const r=this.abort.signal;this.input.addEventListener("focus",()=>this.beginInput(),{signal:r}),this.input.addEventListener("keydown",a=>this.onInputKey(a),{signal:r}),this.input.addEventListener("blur",()=>this.endInput(!0),{signal:r}),this.addressInput.addEventListener("keydown",a=>this.onAddressKey(a),{signal:r}),this.addressInput.addEventListener("input",()=>this.addressInput.removeAttribute("aria-invalid"),{signal:r});const l={onFocusChanged:()=>this.show(),onSelectionChanged:()=>this.show(),onModelChanged:()=>this.show(),onEditingChanged:a=>this.onEditing(a)};this.unsubscribe=t.subscribe(l),this.show()}destroy(){this.unsubscribe(),this.abort.abort(),this.element.remove()}show(){const e=this.element.ownerDocument;if(e.activeElement===this.input&&this.cell)return;const t=this.api.getActiveCell(),s=t?this.api.getCellAddress(t[0],t[1]):void 0;e.activeElement!==this.addressInput&&(this.addressInput.value=s??""),this.input.value=t?tu(this.api.getCellInput(t[0],t[1])):"",this.input.disabled=!t}onEditing(e){this.element.ownerDocument.activeElement!==this.input&&(e.type==="start"||e.type==="input"?this.input.value=e.input??this.input.value:this.show())}beginInput(){this.cell=this.api.getActiveCell(),this.original=this.input.value}endInput(e){const t=this.cell;this.cell=void 0,t&&e&&this.input.value!==this.original&&this.api.applyCellChanges([{rowIndex:t[0],column:t[1],value:this.input.value}],"edit")}onInputKey(e){if(e.isComposing)return;const t=this.cell;if(e.key==="Escape"){e.preventDefault(),this.input.value=this.original,this.cell=void 0,this.focusTable();return}if(!(e.key!=="Enter"&&e.key!=="Tab")){if(e.preventDefault(),this.endInput(!0),t){const s=this.api.getTableScope();e.key==="Enter"?s.moveActiveCell(t[0],t[1],e.shiftKey?-1:1,0):s.moveActiveCell(t[0],t[1],0,e.shiftKey?-1:1)}this.focusTable()}}onAddressKey(e){if(e.key==="Escape"){e.preventDefault(),this.addressInput.removeAttribute("aria-invalid"),this.focusTable();return}e.key==="Enter"&&(e.preventDefault(),this.api.goToAddress(this.addressInput.value)?(this.addressInput.removeAttribute("aria-invalid"),this.focusTable()):this.addressInput.setAttribute("aria-invalid","true"))}focusTable(){this.api.getTableScope().hostElement.focus({preventScroll:!0}),this.show()}}function tu(n){if(n==null)return"";if(n instanceof Date){if(Number.isNaN(n.getTime()))return"";const e=t=>String(t).padStart(2,"0");return`${n.getFullYear()}-${e(n.getMonth()+1)}-${e(n.getDate())}`}return String(n)}exports.ALL_TABLE_STATE_PARTS=Be;exports.AbstractAreaModel=as;exports.ActionEvent=ki;exports.ActionsCellRenderer=Gl;exports.AggregateCellRenderer=kt;exports.Aggregators=Oe;exports.AnyPropertyType=si;exports.AreaMapFactory=pd;exports.AreaModel=Ii;exports.AreaModelAggregateFooter=is;exports.AreaModelArrayOfArrays=Q;exports.AreaModelCellGroups=$l;exports.AreaModelHidden=ae;exports.AreaModelObjectArray=K;exports.AreaModelObjectArrayWithColumndefs=jo;exports.AreaModelPivot=aa;exports.AreaModelPivotFooter=ca;exports.AreaModelRowGroups=ea;exports.AreaModelSheet=Ne;exports.AreaModelSheetHeader=vi;exports.AreaModelTree=rt;exports.AreaObjectMap=ee;exports.AriaGridInfo=ts;exports.AriaIds=Qt;exports.AriaTexts=pe;exports.ArrayPropertyType=We;exports.AutoRestoreOptions=Ol;exports.AvoidDoubleExecution=ua;exports.BatchEditOptions=oo;exports.BatchEditService=$n;exports.BooleanPropertyType=Dr;exports.CellChangesUndoable=Uo;exports.CellEditorService=ll;exports.CellFormulaOptions=Tt;exports.CellGroup=_l;exports.CellGroupExt=Bl;exports.CellGroupExtCellRenderer=Fs;exports.CellRange=M;exports.CellgroupFactory=ce;exports.CheckboxBooleanPropertyCellRenderer=vd;exports.CheckboxCellRenderer=Xo;exports.CheckboxColumnDef=gd;exports.CheckboxModel=on;exports.ChunkData=nd;exports.ClipboardOptions=os;exports.ClipboardService=Wo;exports.ColAndRowspanModel=bn;exports.CollapsedExpandedData=Hl;exports.ColorRgb=Vd;exports.ColumnDef=be;exports.ColumnDefGenerator=fa;exports.ColumnWidths=Wl;exports.ConvenienceDomService=xs;exports.CopyService=Se;exports.CoverGridBodyModel=Ll;exports.CoverGridFactory=id;exports.CoverGridTableModel=Fl;exports.CrudAction=He;exports.CrudObjectEdit=yt;exports.CrudObjectView=Ul;exports.CrudOptions=Kl;exports.CrudTableModelFactory=$d;exports.CssVars=zo;exports.DEFAULT_GET_EDIT_RENDERER=Ci;exports.DateCellEditor=tl;exports.DateToIntlDDMMYYYYCellRenderer=Ad;exports.DateToIsoCellRenderer=Rd;exports.DateToLocaleDateCellRenderer=Ed;exports.DateToTecCellRenderer=Dd;exports.DefaultRowHeights=Fe;exports.EditingOptions=no;exports.EleScope=es;exports.EventAdapter=Kt;exports.EventCheckboxChangedHandler=Rh;exports.ExcelService=On;exports.FORMULA_FUNCTION_INFO=ol;exports.FORMULA_FUNCTION_NAMES=ec;exports.FalseFn=rn;exports.FillHandleOptions=ss;exports.FillHandleService=qn;exports.FocusModel=Si;exports.FormulaAssist=nl;exports.FormulaBar=eu;exports.FormulaError=I;exports.FormulaRange=tt;exports.GeBatchEditEvent=_n;exports.GeCellIndices=Oo;exports.GeCssColorUtil=jt;exports.GeDetailEvent=Qn;exports.GeEditEvent=bt;exports.GeFilterService=Sd;exports.GeKeyEvent=md;exports.GeModelChangeEvent=Xe;exports.GeMouseEvent=js;exports.GeRowDragEvent=Pn;exports.GeScrollEvent=En;exports.GeStateChangeEvent=vn;exports.GeUndoEvent=Ml;exports.GeoData=Ae;exports.HeaderGroupOptions=Qs;exports.Icon=Ee;exports.IndexAndPx=ld;exports.InputCellRenderer=cn;exports.InputHandler=An;exports.JsonService=Ao;exports.LicenseManager=Qe;exports.LiveAnnouncer=Ds;exports.MaleFemaleToIconCellRenderer=Md;exports.MasterDetailOptions=ro;exports.MasterDetailService=Zn;exports.MouseHandler=Gr;exports.MouseTargetData=vs;exports.MultiRowsSelectionModel=Nd;exports.NullPropertyType=Mr;exports.NumberCellEditor=el;exports.NumberCellProgressBarCellRenderer=Td;exports.NumberCellRenderer=kd;exports.NumberPropertyType=Ir;exports.ObjectPropertyType=Ce;exports.OsxShortcutActionIdMapping=Tn;exports.OverlayOptions=to;exports.PROPERTY_TYPE_KEY_ANY=Zo;exports.PROPERTY_TYPE_KEY_ARRAY=ti;exports.PROPERTY_TYPE_KEY_BOOLEAN=Ks;exports.PROPERTY_TYPE_KEY_NULL=Qo;exports.PROPERTY_TYPE_KEY_NUMBER=Us;exports.PROPERTY_TYPE_KEY_OBJECT=St;exports.PROPERTY_TYPE_KEY_STRING=ei;exports.PROPERTY_TYPE_KEY_UNDEFINED=Ct;exports.Padding=Es;exports.PendingCellChanges=Vn;exports.PendingChangesUndoable=El;exports.PivotColumnDef=sa;exports.PivotFactory=Pi;exports.PivotResult=Ps;exports.PivotTableModel=la;exports.PositiveAndNegativeNumberRenderer=Pd;exports.ProgressBarCellRenderer=Od;exports.PropertyItem=oi;exports.PropertyTypeService=ga;exports.RenderScope=Cn;exports.Renderer=xd;exports.RequestChunk=Nl;exports.ResizeHandler=Fn;exports.RowDragOptions=so;exports.RowDragService=Nn;exports.RowGroup=zl;exports.RowGroupColumnDef=J;exports.RowGroupFactory=Fi;exports.RowLayout=yn;exports.RowNumberCellRenderer=an;exports.RowNumberColumnDef=ds;exports.RowNumberOptions=Fo;exports.SHEET_MAX_COLUMNS=q;exports.SHEET_MAX_ROWS=ie;exports.SHOW_VALUES_AS_MODES=jr;exports.SchemeGenerator=pa;exports.SelectCellEditor=Ni;exports.SelectCellRenderer=Li;exports.SelectionAggregator=Rs;exports.SelectionModel=Me;exports.SelectionService=fe;exports.SheetDate=xt;exports.SheetEngine=ao;exports.ShortcutService=Dn;exports.SimpleArrayCellRenderer=Fd;exports.SimpleDomService=Vo;exports.Size=T;exports.SortItem=Ts;exports.SortedOptions=ni;exports.SpreadsheetFactory=mc;exports.SpreadsheetTableModel=Ri;exports.StarRatingCellRenderer=Ld;exports.StoreStateCollapsedExpandService=yd;exports.StoreStateScrollPosService=wd;exports.StoreStateSortingService=Cd;exports.StringPropertyType=Tr;exports.TableApi=pn;exports.TableCellUpdateEvent=bd;exports.TableFactory=ye;exports.TableModel=Ke;exports.TableModelAndOptions=Pl;exports.TableOptions=je;exports.TableOverlay=mn;exports.TableScope=Ko;exports.TableSheet=co;exports.TableStateService=Is;exports.TextCellEditor=lo;exports.ThreeColorGradientArg=_d;exports.TreeAriaInfo=wn;exports.TreeCheckboxModel=Rt;exports.TreeFactory=pt;exports.TreeOptions=ri;exports.TreeRow=ze;exports.TreeRowService=kl;exports.TrueFalseCellRenderer=Id;exports.TrueFn=Ft;exports.TwoColorGradientArg=Yo;exports.UNIMPORTANT_TYPES=Yt;exports.UndefinedPropertyType=ms;exports.UndoOptions=ho;exports.UndoService=Tl;exports.UndoStack=Rl;exports.UrlInfo=Hd;exports.ValueInfo=kr;exports.ValueLabel=Vl;exports.WindowsShortcutActionIdMapping=Mn;exports.actionIds=rd;exports.adjustFormula=bl;exports.aggregate=Ra;exports.aggregateColumns=Aa;exports.aggregateRowGroups=Ud;exports.allCenter=ud;exports.allLeft=dd;exports.allRight=fd;exports.applySpreadsheetPreset=vh;exports.applyStructureEdit=gt;exports.bodyCenter=cd;exports.bodyLeft=ad;exports.bodyRight=hd;exports.booleanInputPipe=pc;exports.calcMoveToIndex=Io;exports.calcOverlayKind=Po;exports.calculateShowValuesAs=hi;exports.canMoveFlatRows=Zs;exports.canMoveTreeRows=gi;exports.canScrollHorizontally=Br;exports.clipboardShortcutLayer=cl;exports.columnIndexOfLetter=Le;exports.columnLetter=Pe;exports.compileFormula=bi;exports.computeFillChanges=Jn;exports.computeFillValues=Wn;exports.computePastePlan=xl;exports.createDateInputPipe=uc;exports.createFormulaValueGetter=wi;exports.createHarmonizedShortcutByKeyboardEvent=In;exports.createNumberInputPipe=hc;exports.createValueGetter=ns;exports.dateToSerial=Lt;exports.debounce=Er;exports.editInputPipeForNumber=sl;exports.editingShortcutLayer=al;exports.entitySuffix=Eo;exports.escapeHtml=X;exports.findDataEdge=Il;exports.findRowIndexAtY=La;exports.firstLetterUppercase=Or;exports.formatAggregateValue=It;exports.formatFormula=Gt;exports.formatShowValuesAs=Js;exports.getAggregator=Xs;exports.getAreaIdentByString=rs;exports.getEntityName=Lr;exports.getFillRange=Ei;exports.getInsertBeforeIndex=ui;exports.getLeadingRowNumberColumnCount=Zt;exports.getLogicalScrollLeft=Vr;exports.getPasteSize=Ti;exports.getTopmostTreeRows=fi;exports.groupRows=Wd;exports.harmonizeShortcut=Ut;exports.isAreaModelAggregateFooter=Pr;exports.isAreaModelPivot=To;exports.isAreaModelRowGroups=ne;exports.isAreaModelTree=Z;exports.isCheckboxCellRenderer=ii;exports.isCheckboxColumnDef=me;exports.isExcelFormattedValue=ws;exports.isExcelFormulaCell=bs;exports.isFillSeries=Un;exports.isFormulaError=w;exports.isFormulaRange=Ye;exports.isFormulaText=wt;exports.isGroupRow=Mo;exports.isPercentShowValuesAs=ci;exports.isPivotColumnDef=zs;exports.isPivotTableModel=Cs;exports.isRowGroup=le;exports.isRowGroupColumnDef=ot;exports.isRowNumberColumnDef=O;exports.isSameCellValue=Mt;exports.isSheetDate=G;exports.isSpreadsheetTableModel=eo;exports.isTreeRow=U;exports.mirrorArrowKeys=Hr;exports.moveArrayItems=Xr;exports.moveFlatRows=pi;exports.moveTreeRows=Yr;exports.normalizeRowIndices=it;exports.offsetReferences=uh;exports.parseCellAddress=Ue;exports.parseHtmlTable=Sl;exports.parseRangeAddress=qr;exports.parseTsv=yl;exports.pivotRows=Yd;exports.px0=td;exports.px10=ed;exports.px100=Kh;exports.px110=Uh;exports.px120=Wh;exports.px130=Gh;exports.px140=Hh;exports.px150=$h;exports.px160=Bh;exports.px170=_h;exports.px180=Vh;exports.px190=Nh;exports.px20=Qh;exports.px200=Ls;exports.px210=Ph;exports.px220=Oh;exports.px230=Fh;exports.px240=Lh;exports.px250=kh;exports.px260=Dh;exports.px270=Ih;exports.px280=Th;exports.px290=Mh;exports.px30=Zh;exports.px300=Dl;exports.px40=qh;exports.px400=Eh;exports.px50=Jh;exports.px500=Ah;exports.px60=Yh;exports.px70=Xh;exports.px80=jh;exports.px90=zh;exports.readLegacyState=Rn;exports.removeLegacyState=No;exports.resolveShowValuesAs=Dt;exports.resolveTableDirection=Nr;exports.serialToDate=yi;exports.setLogicalScrollLeft=_r;exports.sheetInputPipe=xi;exports.shiftFormula=ml;exports.spreadsheetOption=Ze;exports.sumOfNumbers=qs;exports.throttle=ha;exports.toCellAddress=mt;exports.toHtmlTable=Cl;exports.toLogicalX=$r;exports.toPhysicalScrollLeft=Ss;exports.toTsv=wl;exports.trimArraySuffixes=Fr;exports.undoShortcutLayer=vl;
|