@ninebone/table 0.0.755 → 0.0.757

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.
@@ -123,7 +123,7 @@
123
123
  <button class='ng-scroll-top' disabled><div class='ng-scroll-icon'></div></button>
124
124
  <div class='ng-scroll-track'><div class='ng-scroll-thumb'></div></div>
125
125
  <button class='ng-scroll-bottom' disabled><div class='ng-scroll-icon'></div></button>
126
- `;const e=h(()=>{const s=t(this,it).querySelector(".ng-container-body .ng-part-body");if(!s){setTimeout(e,10);return}p(this,L,{container:s,track:this.querySelector(".ng-scroll-track"),thumb:this.querySelector(".ng-scroll-thumb"),top:this.querySelector(".ng-scroll-top"),bottom:this.querySelector(".ng-scroll-bottom")}),t(this,Zt).call(this),this.refresh()},"initWhenReady");e()}};ot=new WeakMap,it=new WeakMap,yt=new WeakMap,L=new WeakMap,Tt=new WeakMap,Ct=new WeakMap,Zt=new WeakMap,h(We,"NineTableVScrollBar");let qt=We;customElements.get("nine-table-vscrollbar")||customElements.define("nine-table-vscrollbar",qt);const je=class je{constructor(n){d(this,j);d(this,E);d(this,at);d(this,F,new Map);d(this,O,null);d(this,Z,null);d(this,lt,0);d(this,kt,40);d(this,Be,!1);d(this,Pe,!1);d(this,Jt,3);C(this,"refresh",h(()=>{var e;y.log("rowManager.refresh");const n=t(this,E).querySelector(".ng-container-body .ng-part-body");n&&(t(this,Lt).call(this),t(this,It).call(this),t(this,mt).call(this,n.scrollTop),(e=t(this,E).querySelector("nine-table-vscrollbar"))==null||e.refresh())},"refresh"));C(this,"initialize",h(()=>{y.log("rowManager.initialize"),p(this,at,{scrollTables:t(this,E).querySelectorAll(".ng-part-body table"),firstTr:t(this,E).querySelector(".ng-container-body .ng-part-body tbody.bindable-tbody tr:not(.nodata)")}),p(this,O,null),t(this,F).clear(),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(i=>{const a=t(this,E).querySelector(i);if(!a)return;const c=a.querySelector(".ng-part-body table");if(!c)return;const l=c.querySelector("tbody.bindable-tbody");if(!l)return;const u=Array.from(l.querySelectorAll("tr")).map(b=>b.cloneNode(!0));t(this,F).set(i,u)});const n=t(this,E).querySelector(".ng-container-body .ng-part-body"),e=t(this,E).querySelector(".ng-container-left .ng-part-body"),s=t(this,E).querySelector(".ng-container-right .ng-part-body"),r=t(this,E).querySelector(".ng-container-body .ng-part-header"),o=t(this,E).querySelector(".ng-container-body .ng-part-footer");if(n){t(this,Lt).call(this),t(this,Mt).call(this),t(this,It).call(this),t(this,mt).call(this,n.scrollTop);let i=!1;const a=h(c=>{var u;if(i)return;i=!0;const l=c.scrollTop,f=c.scrollLeft;n&&n.scrollTop!==l&&(n.scrollTop=l),e&&e.scrollTop!==l&&(e.scrollTop=l),s&&s.scrollTop!==l&&(s.scrollTop=l),r&&r.scrollLeft!==f&&(r.scrollLeft=f),o&&o.scrollLeft!==f&&(o.scrollLeft=f),t(this,mt).call(this,l),(u=t(this,E).querySelector("nine-table-vscrollbar"))==null||u.refresh(),i=!1},"handleContainerScroll");[n,e,s].forEach(c=>{c==null||c.addEventListener("scroll",l=>{y.log(l),y.log("rowManager.scroll event"),a(c)})})}},"initialize"));d(this,Qt,h((n,e)=>{y.log("rowManager.#renderRows");const s=t(this,F).get(e);if(!s||s.length===0)return;const r=n.querySelector(".ng-part-body tbody.bindable-tbody");if(!r)return;r.querySelectorAll("tr:not(.nodata)").forEach(a=>a.remove());const o=r.querySelector("tr.nodata"),i=document.createDocumentFragment();for(let a=0;a<t(this,kt);a++)s.forEach(c=>{i.appendChild(c.cloneNode(!0))});o?o.before(i):r.appendChild(i),e===".ng-container-body"&&(t(this,at).firstTr=r.querySelector("tr:not(.nodata)"))},"#renderRows"));d(this,Lt,h(()=>{if(t(this,O)!==null&&t(this,O)>0)return t(this,O);const n=t(this,E).querySelector(".ng-container-body .ng-part-body");y.log("rowManager.#measureAndCacheHeight");const e=t(this,F).get(".ng-container-body");if(!e||e.length===0)throw new Error("invalid dom");const s=n.querySelector("tbody.bindable-tbody");if(y.log(s),!s)throw new Error("invalid dom");s.querySelectorAll("tr:not(.nodata)").forEach(b=>b.remove());const r=s.querySelector("tr.nodata"),o=document.createDocumentFragment();e.forEach(b=>{o.appendChild(b.cloneNode(!0))}),r?r.before(o):s.appendChild(o);const i=t(this,E),a=i.style.display,c=i.style.visibility,l=i.style.position;(a==="none"||window.getComputedStyle(i).display==="none")&&(i.style.display="block",i.style.visibility="hidden",i.style.position="absolute");let f=0;const u=s.querySelectorAll("tr");return u.forEach(b=>{let g=b.offsetHeight||b.getBoundingClientRect().height;if(g===0){const m=window.getComputedStyle(b);g=parseFloat(m.height)||parseFloat(m.minHeight)||0}f+=g}),u.forEach(b=>b.remove()),i.style.display=a,i.style.visibility=c,i.style.position=l,f<=0?-1:(p(this,O,f),t(this,Ht).call(this),t(this,O))},"#measureAndCacheHeight"));d(this,It,h(()=>{y.log("rowManager.#updateVirtualScrollHeight");const e=(t(this,j).data.get()||[]).length,s=t(this,O),r=e*s;y.log("🔍 [VirtualHeight]",{totalCount:e,rowHeight:s,totalVirtualHeight:r}),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(o=>{const i=t(this,E).querySelector(o);if(!i)return;const a=i.querySelector(".ng-part-body .ng-virtual-spacer");a&&(a.style.height=`${r}px`)})},"#updateVirtualScrollHeight"));d(this,Ht,h(()=>{if(t(this,lt)>0&&t(this,O)>0){const n=Math.ceil(t(this,lt)/t(this,O));p(this,kt,n+t(this,Jt))}},"#updateRowCount"));d(this,te,h(()=>{var a,c,l,f,u,b;const n=t(this,E).querySelector(".ng-container-left .ng-part-body table"),e=t(this,E).querySelector(".ng-container-body .ng-part-body table"),s=t(this,E).querySelector(".ng-container-right .ng-part-body table");if(e){const g=n?Array.from(n.querySelectorAll("tbody tr")):[],m=Array.from(e.querySelectorAll("tbody tr")),v=s?Array.from(s.querySelectorAll("tbody tr")):[],S=Math.max(g.length,m.length,v.length);for(let x=0;x<S;x++){const k=[((a=g[x])==null?void 0:a.getBoundingClientRect().height)||0,((c=m[x])==null?void 0:c.getBoundingClientRect().height)||0,((l=v[x])==null?void 0:l.getBoundingClientRect().height)||0],q=Math.max(...k);q>0&&(g[x]&&(g[x].style.height=`${q}px`),m[x]&&(m[x].style.height=`${q}px`),v[x]&&(v[x].style.height=`${q}px`))}}const r=t(this,E).querySelector(".ng-container-left .ng-part-footer table"),o=t(this,E).querySelector(".ng-container-body .ng-part-footer table"),i=t(this,E).querySelector(".ng-container-right .ng-part-footer table");if(o){const g=r?Array.from(r.querySelectorAll("tfoot tr")):[],m=Array.from(o.querySelectorAll("tfoot tr")),v=i?Array.from(i.querySelectorAll("tfoot tr")):[],S=Math.max(g.length,m.length,v.length);for(let x=0;x<S;x++){const k=[((f=g[x])==null?void 0:f.getBoundingClientRect().height)||0,((u=m[x])==null?void 0:u.getBoundingClientRect().height)||0,((b=v[x])==null?void 0:b.getBoundingClientRect().height)||0],q=Math.max(...k);q>0&&(g[x]&&(g[x].style.height=`${q}px`),m[x]&&(m[x].style.height=`${q}px`),v[x]&&(v[x].style.height=`${q}px`))}}},"#syncRowHeights"));d(this,ee,h(()=>{!t(this,E)||!(t(this,E)instanceof HTMLElement)||(p(this,Z,new ResizeObserver(n=>{for(const e of n){const s=e.target;if(!s.classList.contains("active"))continue;const r=e.contentRect.height;if(r>0){let o=0;const i=s.querySelector(".ng-part-header"),a=s.querySelector(".ng-part-footer");i&&(o+=i.offsetHeight),a&&(o+=a.offsetHeight);const c=Math.max(r-o,100);t(this,lt)!==c&&(p(this,lt,c),t(this,Ht).call(this),t(this,O)!==null&&(t(this,Mt).call(this),this.refresh()))}}})),t(this,Z).observe(t(this,E)))},"#initResizeObserver"));d(this,Mt,h(()=>{y.log("rowManager.#renderAllContainers"),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(n=>{const e=t(this,E).querySelector(n);e&&e.querySelector(".ng-part-body tbody.bindable-tbody")&&t(this,Qt).call(this,e,n)}),t(this,se).call(this),t(this,te).call(this)},"#renderAllContainers"));d(this,Fe,h(n=>{[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(e=>{var l;const s=t(this,E).querySelector(e);if(!s)return;const r=s.querySelector(".ng-part-body tbody.bindable-tbody");if(!r)return;const o=Array.from(r.querySelectorAll("tr:not(.nodata)")),i=((l=t(this,F).get(e))==null?void 0:l.length)||1,c=(t(this,j).data.get()||[]).length;o.forEach((f,u)=>{const b=n+Math.floor(u/i);if(b>=c){f.style.visibility="hidden";return}const g=t(this,j).data.get(b);f.style.display="",t(this,$t).call(this,f,g,b)})})},"#adjustBufferRows"));d(this,mt,h(n=>{var u,b;const e=t(this,O);if(!e||e<=0)return;const s=t(this,j).data.length;if(s===0)return;const r=((u=t(this,F).get(".ng-container-body"))==null?void 0:u.length)||1,o=t(this,E).querySelector(".ng-container-body .ng-part-body");y.log("bodyContainer.clientHeight",o.clientHeight);const i=Math.max(0,s-Math.floor(o.clientHeight/e)),a=Math.min(i,Math.max(0,Math.floor(n/e)));let c=Math.floor(a*e);y.log(`📜 [Scroll Calc] maxStartIndex: ${i}, startIndex: ${a}, offsetY: ${c}`),a===i&&y.log(`📜 [Scroll Inspect] scrollTop: ${n}, rowHeight: ${e}, maxStartIndex: ${i}, startIndex: ${a}, offsetY: ${c}`);const l=t(this,at).firstTr,f=l&&l.dataset.row!==void 0?parseInt(l.dataset.row,10):-1;(b=t(this,at))==null||b.scrollTables.forEach(g=>{g.style.transform=`translate3d(0, ${c}px, 0)`}),f!==a&&(y.log(`🔄 [Row Bind Trigger] currentStartIndex(${f}) !== startIndex(${a})`),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(g=>{const m=t(this,E).querySelector(g);if(!m)return;const v=m.querySelector(".ng-part-body tbody.bindable-tbody");if(!v)return;Array.from(v.querySelectorAll("tr:not(.nodata)")).forEach((x,k)=>{const q=a+Math.floor(k/r);if(q>=s){x.style.display="none";return}const N=t(this,j).data.get(q);x.style.display="",t(this,$t).call(this,x,N,q)})}))},"#handleScroll"));d(this,$t,h((n,e,s)=>{n.dataset.row=s,n.data=e,Array.from(n.cells).forEach((r,o)=>{r.dataset.row=s;const i=Array.from(r.children).find(a=>a.tagName.toLowerCase().startsWith("cell-")||typeof a.refresh=="function");i&&typeof i.refresh=="function"&&i.refresh()})},"#bindRowData"));d(this,se,h(()=>{var c,l,f;y.log("rowManager.#syncHeaderHeights");const n=t(this,E).querySelector(".ng-container-left .ng-part-header table"),e=t(this,E).querySelector(".ng-container-body .ng-part-header table"),s=t(this,E).querySelector(".ng-container-right .ng-part-header table");if(!e)return;const r=n?Array.from(n.querySelectorAll("tr")):[],o=Array.from(e.querySelectorAll("tr")),i=s?Array.from(s.querySelectorAll("tr")):[],a=Math.max(r.length,o.length,i.length);for(let u=0;u<a;u++){const b=[((c=r[u])==null?void 0:c.getBoundingClientRect().height)||0,((l=o[u])==null?void 0:l.getBoundingClientRect().height)||0,((f=i[u])==null?void 0:f.getBoundingClientRect().height)||0],g=Math.max(...b);g>0&&(r[u]&&(r[u].style.height=`${g}px`),o[u]&&(o[u].style.height=`${g}px`),i[u]&&(i[u].style.height=`${g}px`))}},"#syncHeaderHeights"));C(this,"destroy",h(()=>{t(this,Z)&&(t(this,Z).disconnect(),p(this,Z,null))},"destroy"));p(this,j,n.getRootNode().host),p(this,E,n),t(this,ee).call(this)}getRowHeight(){return t(this,O)}templateLength(n=".ng-container-body"){var e;return((e=t(this,F).get(n))==null?void 0:e.length)||1}};j=new WeakMap,E=new WeakMap,at=new WeakMap,F=new WeakMap,O=new WeakMap,Z=new WeakMap,lt=new WeakMap,kt=new WeakMap,Be=new WeakMap,Pe=new WeakMap,Jt=new WeakMap,Qt=new WeakMap,Lt=new WeakMap,It=new WeakMap,Ht=new WeakMap,te=new WeakMap,ee=new WeakMap,Mt=new WeakMap,Fe=new WeakMap,mt=new WeakMap,$t=new WeakMap,se=new WeakMap,h(je,"RowManager");let Re=je;const ne=class ne{static compileAll(n){return Array.isArray(n)?n.map(e=>ne.compile(e)):[]}static compile(n){if(!n)return null;const e=h(a=>{a.querySelectorAll("tbody td, tbody th, tfoot td, tfoot th").forEach(l=>{const f=l.getAttribute("cell-type")||"renderer";if(l.children.length>0&&l.firstElementChild.tagName.includes("-"))return;let u=`cell-${f}`;const b=l.getAttribute("data-bind"),g=l.getAttribute("data-expr"),m=l.getAttribute("maxbyte"),v=l.getAttribute("type");let S=[];b&&S.push(`data-bind="${b}"`),g&&S.push(`data-expr="${g}"`),m&&S.push(`maxbyte="${m}"`),v&&S.push(`type="${v}"`),l.innerHTML=`<${u} ${S.join(" ")}></${u}>`}),a.querySelectorAll("tbody td, tfoot td").forEach(l=>{l.setAttribute("tabindex","0")})},"processCellTypes"),s=h(a=>{if(!a.querySelector("colgroup")){const c=a.querySelector("tbody tr")||a.querySelector("tr"),l=c?c.querySelectorAll("th, td").length:1,f=document.createElement("colgroup"),u=Math.max(Math.floor(a.clientWidth/l),100);for(let b=0;b<l;b++){const g=document.createElement("col");g.setAttribute("width",u),f.appendChild(g)}a.prepend(f)}if(!a.querySelector("thead")){const c=document.createElement("thead"),l=a.querySelector("colgroup");l?l.after(c):a.prepend(c)}a.classList.add("nine-table-element")},"ensureTableStructure"),r=h((a,c)=>{const l=Array.from(a.querySelectorAll(c+" tr")),f=Array.from(a.querySelectorAll(c+" th,"+c+" td")),u=l.length;if(u===0||f.length===0)return;let b=0;f.forEach(m=>{b+=m.colSpan||1});const g=Array.from(Array(u),()=>Array(b).fill(null));l.forEach(m=>{const v=m.sectionRowIndex;let S=0;Array.from(m.querySelectorAll("th,td")).forEach(x=>{for(let N=0;N<g[v].length;N++)if(g[v][N]===null){S=N;break}const k=x.rowSpan||1,q=x.colSpan||1;for(let N=0;N<k;N++)for(let X=0;X<q;X++)v+N<u&&S+X<b&&(g[v+N][S+X]=N===0&&X===0?"1":"0")})}),l.forEach(m=>{const v=m.sectionRowIndex;Array.from(m.querySelectorAll("th,td")).forEach(S=>{for(let x=0;x<g[v].length;x++)if(g[v][x]==="1"){S.dataset.col=x,g[v][x]="0";break}})})},"resetColIndex"),o=n.cloneNode(!0);return s(o),e(o),r(o,"thead"),r(o,"tbody"),r(o,"tfoot"),Array.from(o.querySelectorAll("colgroup col")).forEach((a,c)=>{const l=a.getAttribute("fixed");l&&o.querySelectorAll(`thead [data-col="${c}"], tbody [data-col="${c}"], tfoot [data-col="${c}"]`).forEach(f=>{f.setAttribute("fixed",l)})}),o}};h(ne,"TableCompiler");let Ae=ne;const Ye=class Ye{constructor(n){d(this,U);d(this,_);d(this,Y,{startRow:-1,startCol:-1,endRow:-1,endCol:-1});C(this,"render",h(()=>{const{startRow:n,startCol:e,endRow:s,endCol:r}=t(this,Y);y.log("🎨 [CellSelection.render] Rendering range ->",t(this,Y));const o=t(this,_).querySelectorAll(".ng-container-left .ng-part-body, .ng-container-body .ng-part-body, .ng-container-right .ng-part-body");if(o.forEach(a=>{a.querySelectorAll(".selected, .selected-top, .selected-bottom, .selected-left, .selected-right").forEach(c=>{c.classList.remove("selected","selected-top","selected-bottom","selected-left","selected-right")})}),n<0||e<0){y.log("⚠️ [CellSelection.render] Range is invalid (< 0), skipping render.");return}let i=0;o.forEach(a=>{a.querySelectorAll("tbody tr").forEach(c=>{const{matrixRow:l}=pt(this,U,Vt).call(this,c);l<0||c.querySelectorAll("td, th").forEach(f=>{const u=parseInt(f.dataset.col,10);if(isNaN(u))return;const b=parseInt(f.rowSpan||1,10),g=parseInt(f.colSpan||1,10),m=l+b-1,v=u+g-1;m>=n&&l<=s&&v>=e&&u<=r&&(i++,f.classList.add("selected"),y.log(f,n,e,s,r),l<=n&&f.classList.add("selected-top"),m>=s&&f.classList.add("selected-bottom"),u<=e&&f.classList.add("selected-left"),v>=r&&f.classList.add("selected-right"))})})}),y.log(`✨ [CellSelection.render] Total rendered cells marked: ${i}`)},"render"));p(this,_,n),pt(this,U,bs).call(this),t(this,_).querySelectorAll(".ng-container-left .ng-part-body, .ng-container-body .ng-part-body, .ng-container-right .ng-part-body").forEach(s=>{s.addEventListener("scroll",()=>{t(this,Y).startRow>=0&&t(this,Y).startCol>=0&&this.render()})}),y.log("🎯 [CellSelection] Initialized")}setRange(n,e,s,r){y.log(`🔍 [CellSelection.setRange] Input -> startRow: ${n}, startCol: ${e}, endRow: ${s}, endCol: ${r}`);let o=Math.min(n,s),i=Math.max(n,s),a=Math.min(e,r),c=Math.max(e,r);const l=t(this,_).querySelectorAll(".ng-container-left .ng-part-body, .ng-container-body .ng-part-body, .ng-container-right .ng-part-body");let f=!0,u=0;for(;f&&u<5;)f=!1,u++,l.forEach(b=>{b.querySelectorAll("tbody tr").forEach(g=>{if(g.classList.contains("nodata"))return;const{matrixRow:m}=pt(this,U,Vt).call(this,g);m<0||g.querySelectorAll("td, th").forEach(v=>{const S=parseInt(v.dataset.col,10);if(isNaN(S))return;const x=parseInt(v.rowSpan||1,10),k=parseInt(v.colSpan||1,10),q=m+x-1,N=S+k-1;if(q>=o&&m<=i&&N>=a&&S<=c){const tt=Math.min(o,m),cs=Math.max(i,q),hs=Math.min(a,S),ds=Math.max(c,N);(tt!==o||cs!==i||hs!==a||ds!==c)&&(o=tt,i=cs,a=hs,c=ds,f=!0)}})})});p(this,Y,{startRow:o,startCol:a,endRow:i,endCol:c}),y.log("📦 [CellSelection.setRange] Final Range ->",t(this,Y)),this.render()}};_=new WeakMap,Y=new WeakMap,U=new WeakSet,Vt=h(function(n){if(!n||n.classList.contains("nodata"))return{dataRow:-1,subRowIndex:-1,matrixRow:-1};const e=parseInt(n.dataset.row,10);if(isNaN(e))return{dataRow:-1,subRowIndex:-1,matrixRow:-1};const s=n.closest("tbody"),o=Array.from(s.querySelectorAll("tr:not(.nodata)")).filter(l=>parseInt(l.dataset.row,10)===e),i=o.indexOf(n),a=o.length>0?o.length:1,c=e*a+(i>=0?i:n.sectionRowIndex%a);return{dataRow:e,subRowIndex:i,matrixRow:c}},"#getMatrixRow"),bs=h(function(){const n=t(this,_).querySelector(".ng-container-top");if(!n){y.log("❌ [CellSelection] .ng-container-top not found!");return}n.addEventListener("mousedown",e=>{if(e.button!==0)return;const s=e.target.closest("td, th");if(!s||s.dataset.row===void 0||s.dataset.col===void 0||s.closest("tr").classList.contains("nodata"))return;t(this,_).style.userSelect="none",t(this,_).style.webkitUserSelect="none";const r=s.closest("tr"),{matrixRow:o}=pt(this,U,Vt).call(this,r),i=parseInt(s.dataset.col,10);if(o<0){t(this,_).style.userSelect="",t(this,_).style.webkitUserSelect="";return}y.log(`🖱️ [MouseDown Success] startRow: ${o}, startCol: ${i}`),this.setRange(o,i,o,i);let a=o,c=i;const l=h(u=>{const b=document.elementFromPoint(u.clientX,u.clientY);let g=b==null?void 0:b.closest("td, th");if(!g||!t(this,_).contains(g)){const x=t(this,_).querySelectorAll(".ng-part-body tbody tr:not(.nodata) td, .ng-part-body tbody tr:not(.nodata) th");for(const k of x){const q=k.getBoundingClientRect();if(u.clientX>=q.left&&u.clientX<=q.right&&u.clientY>=q.top&&u.clientY<=q.bottom){g=k;break}}}if(!g||g.dataset.row===void 0||g.dataset.col===void 0||g.closest("tr").classList.contains("nodata"))return;const m=g.closest("tr"),{matrixRow:v}=pt(this,U,Vt).call(this,m),S=parseInt(g.dataset.col,10);v<0||a===v&&c===S||(a=v,c=S,this.setRange(o,i,v,S))},"onMouseMove"),f=h(()=>{y.log("🖱️ [MouseUp] Drag ended."),t(this,_).style.userSelect="",t(this,_).style.webkitUserSelect="",document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",f)},"onMouseUp");document.addEventListener("mousemove",l),document.addEventListener("mouseup",f)})},"#initEvents"),h(Ye,"CellSelection");let Ee=Ye;const Ue=class Ue{constructor(n){d(this,ie);d(this,V);d(this,ct,null);d(this,re,-1);d(this,oe,-1);d(this,Nt,!1);p(this,V,n),pt(this,ie,ps).call(this),y.log("🎯 [CellNavigation] Initialized")}get currentCell(){return t(this,ct)}set currentCell(n){if(!n)return;p(this,ct,n),n.focus({preventScroll:!0});const e=parseInt(n.dataset.row,10),s=parseInt(n.dataset.col,10);if(!isNaN(e)&&!isNaN(s)){p(this,re,e),p(this,oe,s);const r=n.closest("tr"),o=r==null?void 0:r.closest("tbody");if(o){const a=Array.from(o.querySelectorAll("tr:not(.nodata)")).filter(u=>parseInt(u.dataset.row,10)===e),c=a.length>0?a.length:1,l=a.indexOf(r),f=e*c+(l>=0?l:0);p(this,Nt,!0),y.log("====================",f,s,f,s),t(this,V).selection.setRange(f,s,f,s),setTimeout(()=>{p(this,Nt,!1)},0)}}}moveCell(n){var k,q,N,X;if(!t(this,ct))return;const e=t(this,ct),s=e.closest("tr"),r=parseInt(e.dataset.row,10),o=parseInt(e.dataset.col,10),i=s==null?void 0:s.closest("tbody"),c=Array.from(i.querySelectorAll("tr:not(.nodata)")).filter(tt=>parseInt(tt.dataset.row,10)===r),l=c.length>0?c.length:1,f=c.indexOf(s);let u=r,b=f,g=o;switch(n.code){case"Tab":n.preventDefault(),g=n.shiftKey?o-1:o+1;break;case"ArrowRight":g=o+1;break;case"ArrowLeft":g=o-1;break;case"ArrowDown":n.preventDefault(),f<l-1?b=f+1:(u=r+1,b=0);break;case"ArrowUp":n.preventDefault(),f>0?b=f-1:(u=r-1,b=l-1);break}let m=null;const x=Array.from(i.querySelectorAll("tr:not(.nodata)")).filter(tt=>parseInt(tt.dataset.row,10)===u)[b];if(x&&(m=x.querySelector(`[data-col="${g}"]`)),m)this.currentCell=m;else if(u!==r&&u>=0){const tt=((q=(k=t(this,V)).getRowHeight)==null?void 0:q.call(k))||40;(X=(N=t(this,V)).scrollToY)==null||X.call(N,u*tt)}}};V=new WeakMap,ct=new WeakMap,re=new WeakMap,oe=new WeakMap,Nt=new WeakMap,ie=new WeakSet,ps=h(function(){t(this,V).addEventListener("mousedown",n=>{const e=n.target.closest("td, th");!e||e.dataset.row===void 0||e.dataset.col===void 0||(this.currentCell=e)}),t(this,V).addEventListener("keydown",n=>{["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(n.code)&&this.moveCell(n)})},"#initEvents"),h(Ue,"CellNavigation");let qe=Ue;const Ot=class Ot extends HTMLElement{constructor(){super();d(this,ae);d(this,ht,null);d(this,dt);d(this,_t);d(this,Dt);C(this,"invalidate",h(()=>{y.log("sheet.invalidate()"),t(this,dt).refresh()},"invalidate"));C(this,"generate",h(e=>{if(y.log("sheet.generate()"),!e)return;p(this,ht,Ae.compile(e)),t(this,le).call(this),t(this,ce).call(this);const s=this.querySelector(".ng-container-body .ng-part-header"),r=this.querySelector(".ng-container-body .ng-part-footer"),o=this.querySelector(".ng-nodata-overlay");s&&o&&(o.style.top=`${s.offsetHeight}px`),r&&o&&(o.style.bottom=`${r.offsetHeight}px`),t(this,dt).initialize(),setTimeout(()=>{var i;(i=this.querySelector("nine-table-hscrollbar"))==null||i.refresh()},0)},"generate"));d(this,le,h(()=>{[{selector:".ng-container-body",type:null},{selector:".ng-container-left",type:"left"},{selector:".ng-container-right",type:"right"}].forEach(({selector:s,type:r})=>{var o,i,a;(o=this.querySelector(`${s} .ng-part-header`))==null||o.appendChild(t(this,xt).call(this,t(this,ht),r,"header")),(i=this.querySelector(`${s} .ng-virtual-spacer`))==null||i.before(t(this,xt).call(this,t(this,ht),r,"body")),(a=this.querySelector(`${s} .ng-part-footer`))==null||a.appendChild(t(this,xt).call(this,t(this,ht),r,"footer"))})},"#renderSplitContainers"));d(this,ce,h(()=>{["left","right","body"].forEach(e=>{const s=this.querySelector(`.ng-container-${e}`),r=s==null?void 0:s.querySelectorAll("table");if(!s||!r||r.length===0)return;let o=0;r[0].querySelectorAll("col").forEach(i=>{const a=parseInt(i.getAttribute("width"),10);isNaN(o)||(o+=a)}),e==="body"?s.style.flex="1":(s.style.flex=`0 0 ${o}px`,s.style.width=`${o}px`)})},"#updateContainerWidths"));d(this,xt,h((e,s,r)=>{const o=e.cloneNode(!0),i=o.querySelector("thead"),a=o.querySelector("tbody"),c=o.querySelector("tfoot");if(r==="header"){if(a&&a.remove(),c&&c.remove(),e.querySelector("tbody")){const f=document.createElement("tbody");f.className="fixed-tbody",o.appendChild(f)}}else r==="body"?(i&&i.remove(),c&&c.remove(),a&&(a.className="bindable-tbody")):r==="footer"&&(i&&i.remove(),a&&a.remove());return s==="left"?o.querySelectorAll("col, th, td, tfoot td, tfoot th").forEach(l=>{l.getAttribute("fixed")!=="left"&&l.remove()}):s==="right"?o.querySelectorAll("col, th, td, tfoot td, tfoot th").forEach(l=>{l.getAttribute("fixed")!=="right"&&l.remove()}):o.querySelectorAll("[fixed=left], [fixed=right]").forEach(l=>{l.remove()}),o},"#createSplitTable"));C(this,"getRowHeight",h(()=>t(this,dt).getRowHeight(),"getRowHeight"));C(this,"scrollToX",h(e=>{const s=this.querySelector(".ng-container-body .ng-part-body");s&&(s.scrollLeft=e)},"scrollToX"));C(this,"scrollToY",h(e=>{const s=this.querySelector(".ng-container-body .ng-part-body");s&&(s.scrollTop=e)},"scrollToY"));d(this,he,h(()=>{t(this,de).call(this),p(this,_t,new Ee(this)),p(this,Dt,new qe(this))},"#init"));d(this,de,h(()=>{const e=Ot.SCROLLBAR_SIZE;this.innerHTML=`
126
+ `;const e=h(()=>{const s=t(this,it).querySelector(".ng-container-body .ng-part-body");if(!s){setTimeout(e,10);return}p(this,L,{container:s,track:this.querySelector(".ng-scroll-track"),thumb:this.querySelector(".ng-scroll-thumb"),top:this.querySelector(".ng-scroll-top"),bottom:this.querySelector(".ng-scroll-bottom")}),t(this,Zt).call(this),this.refresh()},"initWhenReady");e()}};ot=new WeakMap,it=new WeakMap,yt=new WeakMap,L=new WeakMap,Tt=new WeakMap,Ct=new WeakMap,Zt=new WeakMap,h(We,"NineTableVScrollBar");let qt=We;customElements.get("nine-table-vscrollbar")||customElements.define("nine-table-vscrollbar",qt);const je=class je{constructor(n){d(this,j);d(this,E);d(this,at);d(this,F,new Map);d(this,O,null);d(this,Z,null);d(this,lt,0);d(this,kt,40);d(this,Be,!1);d(this,Pe,!1);d(this,Jt,3);C(this,"refresh",h(()=>{var e;y.log("rowManager.refresh");const n=t(this,E).querySelector(".ng-container-body .ng-part-body");n&&(t(this,Lt).call(this),t(this,It).call(this),t(this,mt).call(this,n.scrollTop),(e=t(this,E).querySelector("nine-table-vscrollbar"))==null||e.refresh())},"refresh"));C(this,"initialize",h(()=>{y.log("rowManager.initialize"),p(this,at,{scrollTables:t(this,E).querySelectorAll(".ng-part-body table"),firstTr:t(this,E).querySelector(".ng-container-body .ng-part-body tbody.bindable-tbody tr:not(.nodata)")}),p(this,O,null),t(this,F).clear(),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(i=>{const a=t(this,E).querySelector(i);if(!a)return;const c=a.querySelector(".ng-part-body table");if(!c)return;const l=c.querySelector("tbody.bindable-tbody");if(!l)return;const u=Array.from(l.querySelectorAll("tr")).map(b=>b.cloneNode(!0));t(this,F).set(i,u)});const n=t(this,E).querySelector(".ng-container-body .ng-part-body"),e=t(this,E).querySelector(".ng-container-left .ng-part-body"),s=t(this,E).querySelector(".ng-container-right .ng-part-body"),r=t(this,E).querySelector(".ng-container-body .ng-part-header"),o=t(this,E).querySelector(".ng-container-body .ng-part-footer");if(n){t(this,Lt).call(this),t(this,Mt).call(this),t(this,It).call(this),t(this,mt).call(this,n.scrollTop);let i=!1;const a=h(c=>{var u;if(i)return;i=!0;const l=c.scrollTop,f=c.scrollLeft;n&&n.scrollTop!==l&&(n.scrollTop=l),e&&e.scrollTop!==l&&(e.scrollTop=l),s&&s.scrollTop!==l&&(s.scrollTop=l),r&&r.scrollLeft!==f&&(r.scrollLeft=f),o&&o.scrollLeft!==f&&(o.scrollLeft=f),t(this,mt).call(this,l),(u=t(this,E).querySelector("nine-table-vscrollbar"))==null||u.refresh(),i=!1},"handleContainerScroll");[n,e,s].forEach(c=>{c==null||c.addEventListener("scroll",l=>{y.log(l),y.log("rowManager.scroll event"),a(c)})})}},"initialize"));d(this,Qt,h((n,e)=>{y.log("rowManager.#renderRows");const s=t(this,F).get(e);if(!s||s.length===0)return;const r=n.querySelector(".ng-part-body tbody.bindable-tbody");if(!r)return;r.querySelectorAll("tr:not(.nodata)").forEach(a=>a.remove());const o=r.querySelector("tr.nodata"),i=document.createDocumentFragment();for(let a=0;a<t(this,kt);a++)s.forEach(c=>{i.appendChild(c.cloneNode(!0))});o?o.before(i):r.appendChild(i),e===".ng-container-body"&&(t(this,at).firstTr=r.querySelector("tr:not(.nodata)"))},"#renderRows"));d(this,Lt,h(()=>{if(t(this,O)!==null&&t(this,O)>0)return t(this,O);const n=t(this,E).querySelector(".ng-container-body .ng-part-body");y.log("rowManager.#measureAndCacheHeight");const e=t(this,F).get(".ng-container-body");if(!e||e.length===0)throw new Error("invalid dom");const s=n.querySelector("tbody.bindable-tbody");if(y.log(s),!s)throw new Error("invalid dom");s.querySelectorAll("tr:not(.nodata)").forEach(b=>b.remove());const r=s.querySelector("tr.nodata"),o=document.createDocumentFragment();e.forEach(b=>{o.appendChild(b.cloneNode(!0))}),r?r.before(o):s.appendChild(o);const i=t(this,E),a=i.style.display,c=i.style.visibility,l=i.style.position;(a==="none"||window.getComputedStyle(i).display==="none")&&(i.style.display="block",i.style.visibility="hidden",i.style.position="absolute");let f=0;const u=s.querySelectorAll("tr");return u.forEach(b=>{let g=b.offsetHeight||b.getBoundingClientRect().height;if(g===0){const m=window.getComputedStyle(b);g=parseFloat(m.height)||parseFloat(m.minHeight)||0}f+=g}),u.forEach(b=>b.remove()),i.style.display=a,i.style.visibility=c,i.style.position=l,f<=0?-1:(p(this,O,f),t(this,Ht).call(this),t(this,O))},"#measureAndCacheHeight"));d(this,It,h(()=>{y.log("rowManager.#updateVirtualScrollHeight");const e=(t(this,j).data.get()||[]).length,s=t(this,O),r=e*s;y.log("🔍 [VirtualHeight]",{totalCount:e,rowHeight:s,totalVirtualHeight:r}),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(o=>{const i=t(this,E).querySelector(o);if(!i)return;const a=i.querySelector(".ng-part-body .ng-virtual-spacer");a&&(a.style.height=`${r}px`)})},"#updateVirtualScrollHeight"));d(this,Ht,h(()=>{if(t(this,lt)>0&&t(this,O)>0){const n=Math.ceil(t(this,lt)/t(this,O));p(this,kt,n+t(this,Jt))}},"#updateRowCount"));d(this,te,h(()=>{var a,c,l,f,u,b;const n=t(this,E).querySelector(".ng-container-left .ng-part-body table"),e=t(this,E).querySelector(".ng-container-body .ng-part-body table"),s=t(this,E).querySelector(".ng-container-right .ng-part-body table");if(e){const g=n?Array.from(n.querySelectorAll("tbody tr")):[],m=Array.from(e.querySelectorAll("tbody tr")),v=s?Array.from(s.querySelectorAll("tbody tr")):[],S=Math.max(g.length,m.length,v.length);for(let x=0;x<S;x++){const k=[((a=g[x])==null?void 0:a.getBoundingClientRect().height)||0,((c=m[x])==null?void 0:c.getBoundingClientRect().height)||0,((l=v[x])==null?void 0:l.getBoundingClientRect().height)||0],q=Math.max(...k);q>0&&(g[x]&&(g[x].style.height=`${q}px`),m[x]&&(m[x].style.height=`${q}px`),v[x]&&(v[x].style.height=`${q}px`))}}const r=t(this,E).querySelector(".ng-container-left .ng-part-footer table"),o=t(this,E).querySelector(".ng-container-body .ng-part-footer table"),i=t(this,E).querySelector(".ng-container-right .ng-part-footer table");if(o){const g=r?Array.from(r.querySelectorAll("tfoot tr")):[],m=Array.from(o.querySelectorAll("tfoot tr")),v=i?Array.from(i.querySelectorAll("tfoot tr")):[],S=Math.max(g.length,m.length,v.length);for(let x=0;x<S;x++){const k=[((f=g[x])==null?void 0:f.getBoundingClientRect().height)||0,((u=m[x])==null?void 0:u.getBoundingClientRect().height)||0,((b=v[x])==null?void 0:b.getBoundingClientRect().height)||0],q=Math.max(...k);q>0&&(g[x]&&(g[x].style.height=`${q}px`),m[x]&&(m[x].style.height=`${q}px`),v[x]&&(v[x].style.height=`${q}px`))}}},"#syncRowHeights"));d(this,ee,h(()=>{!t(this,E)||!(t(this,E)instanceof HTMLElement)||(p(this,Z,new ResizeObserver(n=>{for(const e of n){const s=e.target;if(!s.classList.contains("active"))continue;const r=e.contentRect.height;if(r>0){let o=0;const i=s.querySelector(".ng-part-header"),a=s.querySelector(".ng-part-footer");i&&(o+=i.offsetHeight),a&&(o+=a.offsetHeight);const c=Math.max(r-o,100);t(this,lt)!==c&&(p(this,lt,c),t(this,Ht).call(this),t(this,O)!==null&&(t(this,Mt).call(this),this.refresh()))}}})),t(this,Z).observe(t(this,E)))},"#initResizeObserver"));d(this,Mt,h(()=>{y.log("rowManager.#renderAllContainers"),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(n=>{const e=t(this,E).querySelector(n);e&&e.querySelector(".ng-part-body tbody.bindable-tbody")&&t(this,Qt).call(this,e,n)}),t(this,se).call(this),t(this,te).call(this)},"#renderAllContainers"));d(this,Fe,h(n=>{[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(e=>{var l;const s=t(this,E).querySelector(e);if(!s)return;const r=s.querySelector(".ng-part-body tbody.bindable-tbody");if(!r)return;const o=Array.from(r.querySelectorAll("tr:not(.nodata)")),i=((l=t(this,F).get(e))==null?void 0:l.length)||1,c=(t(this,j).data.get()||[]).length;o.forEach((f,u)=>{const b=n+Math.floor(u/i);if(b>=c){f.style.visibility="hidden";return}const g=t(this,j).data.get(b);f.style.display="",t(this,$t).call(this,f,g,b)})})},"#adjustBufferRows"));d(this,mt,h(n=>{var u,b;const e=t(this,O);if(!e||e<=0)return;const s=t(this,j).data.length;if(s===0)return;const r=((u=t(this,F).get(".ng-container-body"))==null?void 0:u.length)||1,o=t(this,E).querySelector(".ng-container-body .ng-part-body");y.log("bodyContainer.clientHeight",o.clientHeight);const i=Math.max(0,s-Math.floor(o.clientHeight/e)),a=Math.min(i,Math.max(0,Math.floor(n/e)));let c=Math.floor(a*e);y.log(`📜 [Scroll Calc] maxStartIndex: ${i}, startIndex: ${a}, offsetY: ${c}`),a===i&&y.log(`📜 [Scroll Inspect] scrollTop: ${n}, rowHeight: ${e}, maxStartIndex: ${i}, startIndex: ${a}, offsetY: ${c}`);const l=t(this,at).firstTr,f=l&&l.dataset.row!==void 0?parseInt(l.dataset.row,10):-1;(b=t(this,at))==null||b.scrollTables.forEach(g=>{g.style.transform=`translate3d(0, ${c}px, 0)`}),f!==a&&(y.log(`🔄 [Row Bind Trigger] currentStartIndex(${f}) !== startIndex(${a})`),[".ng-container-body",".ng-container-left",".ng-container-right"].forEach(g=>{const m=t(this,E).querySelector(g);if(!m)return;const v=m.querySelector(".ng-part-body tbody.bindable-tbody");if(!v)return;Array.from(v.querySelectorAll("tr:not(.nodata)")).forEach((x,k)=>{const q=a+Math.floor(k/r);if(q>=s){x.style.display="none";return}const N=t(this,j).data.get(q);x.style.display="",t(this,$t).call(this,x,N,q)})}))},"#handleScroll"));d(this,$t,h((n,e,s)=>{n.dataset.row=s,n.data=e,Array.from(n.cells).forEach((r,o)=>{r.dataset.row=s;const i=Array.from(r.children).find(a=>a.tagName.toLowerCase().startsWith("cell-")||typeof a.refresh=="function");i&&typeof i.refresh=="function"&&i.refresh()})},"#bindRowData"));d(this,se,h(()=>{var c,l,f;y.log("rowManager.#syncHeaderHeights");const n=t(this,E).querySelector(".ng-container-left .ng-part-header table"),e=t(this,E).querySelector(".ng-container-body .ng-part-header table"),s=t(this,E).querySelector(".ng-container-right .ng-part-header table");if(!e)return;const r=n?Array.from(n.querySelectorAll("tr")):[],o=Array.from(e.querySelectorAll("tr")),i=s?Array.from(s.querySelectorAll("tr")):[],a=Math.max(r.length,o.length,i.length);for(let u=0;u<a;u++){const b=[((c=r[u])==null?void 0:c.getBoundingClientRect().height)||0,((l=o[u])==null?void 0:l.getBoundingClientRect().height)||0,((f=i[u])==null?void 0:f.getBoundingClientRect().height)||0],g=Math.max(...b);g>0&&(r[u]&&(r[u].style.height=`${g}px`),o[u]&&(o[u].style.height=`${g}px`),i[u]&&(i[u].style.height=`${g}px`))}},"#syncHeaderHeights"));C(this,"destroy",h(()=>{t(this,Z)&&(t(this,Z).disconnect(),p(this,Z,null))},"destroy"));p(this,j,n.getRootNode().host),p(this,E,n),t(this,ee).call(this)}getRowHeight(){return t(this,O)}templateLength(n=".ng-container-body"){var e;return((e=t(this,F).get(n))==null?void 0:e.length)||1}};j=new WeakMap,E=new WeakMap,at=new WeakMap,F=new WeakMap,O=new WeakMap,Z=new WeakMap,lt=new WeakMap,kt=new WeakMap,Be=new WeakMap,Pe=new WeakMap,Jt=new WeakMap,Qt=new WeakMap,Lt=new WeakMap,It=new WeakMap,Ht=new WeakMap,te=new WeakMap,ee=new WeakMap,Mt=new WeakMap,Fe=new WeakMap,mt=new WeakMap,$t=new WeakMap,se=new WeakMap,h(je,"RowManager");let Re=je;const ne=class ne{static compileAll(n){return Array.isArray(n)?n.map(e=>ne.compile(e)):[]}static compile(n){if(!n)return null;const e=h(a=>{a.querySelectorAll("tbody td, tbody th, tfoot td, tfoot th").forEach(l=>{const f=l.getAttribute("cell-type")||"renderer";if(l.children.length>0&&l.firstElementChild.tagName.includes("-"))return;let u=`cell-${f}`;const b=l.getAttribute("data-bind"),g=l.getAttribute("data-expr"),m=l.getAttribute("maxbyte"),v=l.getAttribute("type");let S=[];b&&S.push(`data-bind="${b}"`),g&&S.push(`data-expr="${g}"`),m&&S.push(`maxbyte="${m}"`),v&&S.push(`type="${v}"`),l.innerHTML=`<${u} ${S.join(" ")}></${u}>`}),a.querySelectorAll("tbody td, tfoot td").forEach(l=>{l.setAttribute("tabindex","0")})},"processCellTypes"),s=h(a=>{if(!a.querySelector("colgroup")){const c=a.querySelector("tbody tr")||a.querySelector("tr"),l=c?c.querySelectorAll("th, td").length:1,f=document.createElement("colgroup"),u=Math.max(Math.floor(a.clientWidth/l),100);for(let b=0;b<l;b++){const g=document.createElement("col");g.setAttribute("width",u),f.appendChild(g)}a.prepend(f)}if(!a.querySelector("thead")){const c=document.createElement("thead"),l=a.querySelector("colgroup");l?l.after(c):a.prepend(c)}a.classList.add("nine-table-element")},"ensureTableStructure"),r=h((a,c)=>{const l=Array.from(a.querySelectorAll(c+" tr")),f=Array.from(a.querySelectorAll(c+" th,"+c+" td")),u=l.length;if(u===0||f.length===0)return;let b=0;f.forEach(m=>{b+=m.colSpan||1});const g=Array.from(Array(u),()=>Array(b).fill(null));l.forEach(m=>{const v=m.sectionRowIndex;let S=0;Array.from(m.querySelectorAll("th,td")).forEach(x=>{for(let N=0;N<g[v].length;N++)if(g[v][N]===null){S=N;break}const k=x.rowSpan||1,q=x.colSpan||1;for(let N=0;N<k;N++)for(let X=0;X<q;X++)v+N<u&&S+X<b&&(g[v+N][S+X]=N===0&&X===0?"1":"0")})}),l.forEach(m=>{const v=m.sectionRowIndex;Array.from(m.querySelectorAll("th,td")).forEach(S=>{for(let x=0;x<g[v].length;x++)if(g[v][x]==="1"){S.dataset.col=x,g[v][x]="0";break}})})},"resetColIndex"),o=n.cloneNode(!0);return s(o),e(o),r(o,"thead"),r(o,"tbody"),r(o,"tfoot"),Array.from(o.querySelectorAll("colgroup col")).forEach((a,c)=>{const l=a.getAttribute("fixed");l&&o.querySelectorAll(`thead [data-col="${c}"], tbody [data-col="${c}"], tfoot [data-col="${c}"]`).forEach(f=>{f.setAttribute("fixed",l)})}),o}};h(ne,"TableCompiler");let Ae=ne;const Ye=class Ye{constructor(n){d(this,U);d(this,_);d(this,Y,{startRow:-1,startCol:-1,endRow:-1,endCol:-1});C(this,"render",h(()=>{const{startRow:n,startCol:e,endRow:s,endCol:r}=t(this,Y);y.log("🎨 [CellSelection.render] Rendering range ->",t(this,Y));const o=t(this,_).querySelectorAll(".ng-container-left .ng-part-body, .ng-container-body .ng-part-body, .ng-container-right .ng-part-body");if(o.forEach(a=>{a.querySelectorAll(".selected, .selected-top, .selected-bottom, .selected-left, .selected-right").forEach(c=>{c.classList.remove("selected","selected-top","selected-bottom","selected-left","selected-right")})}),n<0||e<0){y.log("⚠️ [CellSelection.render] Range is invalid (< 0), skipping render.");return}let i=0;o.forEach(a=>{a.querySelectorAll("tbody tr").forEach(c=>{const{matrixRow:l}=pt(this,U,Vt).call(this,c);l<0||c.querySelectorAll("td, th").forEach(f=>{const u=parseInt(f.dataset.col,10);if(isNaN(u))return;const b=parseInt(f.rowSpan||1,10),g=parseInt(f.colSpan||1,10),m=l+b-1,v=u+g-1;m>=n&&l<=s&&v>=e&&u<=r&&(i++,f.classList.add("selected"),y.log(f,n,e,s,r),l<=n&&f.classList.add("selected-top"),m>=s&&f.classList.add("selected-bottom"),u<=e&&f.classList.add("selected-left"),v>=r&&f.classList.add("selected-right"))})})}),y.log(`✨ [CellSelection.render] Total rendered cells marked: ${i}`)},"render"));p(this,_,n),pt(this,U,bs).call(this),t(this,_).querySelectorAll(".ng-container-left .ng-part-body, .ng-container-body .ng-part-body, .ng-container-right .ng-part-body").forEach(s=>{s.addEventListener("scroll",()=>{t(this,Y).startRow>=0&&t(this,Y).startCol>=0&&this.render()})}),y.log("🎯 [CellSelection] Initialized")}setRange(n,e,s,r){y.log(`🔍 [CellSelection.setRange] Input -> startRow: ${n}, startCol: ${e}, endRow: ${s}, endCol: ${r}`);let o=Math.min(n,s),i=Math.max(n,s),a=Math.min(e,r),c=Math.max(e,r);const l=t(this,_).querySelectorAll(".ng-container-left .ng-part-body, .ng-container-body .ng-part-body, .ng-container-right .ng-part-body");let f=!0,u=0;for(;f&&u<5;)f=!1,u++,l.forEach(b=>{b.querySelectorAll("tbody tr").forEach(g=>{if(g.classList.contains("nodata"))return;const{matrixRow:m}=pt(this,U,Vt).call(this,g);m<0||g.querySelectorAll("td, th").forEach(v=>{const S=parseInt(v.dataset.col,10);if(isNaN(S))return;const x=parseInt(v.rowSpan||1,10),k=parseInt(v.colSpan||1,10),q=m+x-1,N=S+k-1;if(q>=o&&m<=i&&N>=a&&S<=c){const tt=Math.min(o,m),cs=Math.max(i,q),hs=Math.min(a,S),ds=Math.max(c,N);(tt!==o||cs!==i||hs!==a||ds!==c)&&(o=tt,i=cs,a=hs,c=ds,f=!0)}})})});p(this,Y,{startRow:o,startCol:a,endRow:i,endCol:c}),y.log("📦 [CellSelection.setRange] Final Range ->",t(this,Y)),this.render()}};_=new WeakMap,Y=new WeakMap,U=new WeakSet,Vt=h(function(n){if(!n||n.classList.contains("nodata"))return{dataRow:-1,subRowIndex:-1,matrixRow:-1};const e=parseInt(n.dataset.row,10);if(isNaN(e))return{dataRow:-1,subRowIndex:-1,matrixRow:-1};const s=n.closest("tbody"),o=Array.from(s.querySelectorAll("tr:not(.nodata)")).filter(l=>parseInt(l.dataset.row,10)===e),i=o.indexOf(n),a=o.length>0?o.length:1,c=e*a+(i>=0?i:n.sectionRowIndex%a);return{dataRow:e,subRowIndex:i,matrixRow:c}},"#getMatrixRow"),bs=h(function(){const n=t(this,_).querySelector(".ng-container-top");if(!n){y.log("❌ [CellSelection] .ng-container-top not found!");return}n.addEventListener("mousedown",e=>{if(e.button!==0)return;const s=e.target.closest("td, th");if(!s||s.dataset.row===void 0||s.dataset.col===void 0||s.closest("tr").classList.contains("nodata"))return;t(this,_).style.userSelect="none",t(this,_).style.webkitUserSelect="none";const r=s.closest("tr"),{matrixRow:o}=pt(this,U,Vt).call(this,r),i=parseInt(s.dataset.col,10);if(o<0){t(this,_).style.userSelect="",t(this,_).style.webkitUserSelect="";return}y.log(`🖱️ [MouseDown Success] startRow: ${o}, startCol: ${i}`),this.setRange(o,i,o,i);let a=o,c=i;const l=h(u=>{const b=document.elementFromPoint(u.clientX,u.clientY);let g=b==null?void 0:b.closest("td, th");if(!g||!t(this,_).contains(g)){const x=t(this,_).querySelectorAll(".ng-part-body tbody tr:not(.nodata) td, .ng-part-body tbody tr:not(.nodata) th");for(const k of x){const q=k.getBoundingClientRect();if(u.clientX>=q.left&&u.clientX<=q.right&&u.clientY>=q.top&&u.clientY<=q.bottom){g=k;break}}}if(!g||g.dataset.row===void 0||g.dataset.col===void 0||g.closest("tr").classList.contains("nodata"))return;const m=g.closest("tr"),{matrixRow:v}=pt(this,U,Vt).call(this,m),S=parseInt(g.dataset.col,10);v<0||a===v&&c===S||(a=v,c=S,this.setRange(o,i,v,S))},"onMouseMove"),f=h(()=>{y.log("🖱️ [MouseUp] Drag ended."),t(this,_).style.userSelect="",t(this,_).style.webkitUserSelect="",document.removeEventListener("mousemove",l),document.removeEventListener("mouseup",f)},"onMouseUp");document.addEventListener("mousemove",l),document.addEventListener("mouseup",f)})},"#initEvents"),h(Ye,"CellSelection");let Ee=Ye;const Ue=class Ue{constructor(n){d(this,ie);d(this,V);d(this,ct,null);d(this,re,-1);d(this,oe,-1);d(this,Nt,!1);p(this,V,n),pt(this,ie,ps).call(this),y.log("🎯 [CellNavigation] Initialized")}get currentCell(){return t(this,ct)}set currentCell(n){if(!n)return;p(this,ct,n),n.focus({preventScroll:!0});const e=parseInt(n.dataset.row,10),s=parseInt(n.dataset.col,10);if(!isNaN(e)&&!isNaN(s)){p(this,re,e),p(this,oe,s);const r=n.closest("tr"),o=r==null?void 0:r.closest("tbody");if(o){const a=Array.from(o.querySelectorAll("tr:not(.nodata)")).filter(u=>parseInt(u.dataset.row,10)===e),c=a.length>0?a.length:1,l=a.indexOf(r),f=e*c+(l>=0?l:0);p(this,Nt,!0),y.log("====================",f,s,f,s),t(this,V).selection.setRange(f,s,f,s),setTimeout(()=>{p(this,Nt,!1)},0)}}}moveCell(n){var k,q,N,X;if(!t(this,ct))return;const e=t(this,ct),s=e.closest("tr"),r=parseInt(e.dataset.row,10),o=parseInt(e.dataset.col,10),i=s==null?void 0:s.closest("tbody"),c=Array.from(i.querySelectorAll("tr:not(.nodata)")).filter(tt=>parseInt(tt.dataset.row,10)===r),l=c.length>0?c.length:1,f=c.indexOf(s);let u=r,b=f,g=o;switch(n.code){case"Tab":n.preventDefault(),g=n.shiftKey?o-1:o+1;break;case"ArrowRight":g=o+1;break;case"ArrowLeft":g=o-1;break;case"ArrowDown":n.preventDefault(),f<l-1?b=f+1:(u=r+1,b=0);break;case"ArrowUp":n.preventDefault(),f>0?b=f-1:(u=r-1,b=l-1);break}let m=null;const x=Array.from(i.querySelectorAll("tr:not(.nodata)")).filter(tt=>parseInt(tt.dataset.row,10)===u)[b];if(x&&(m=x.querySelector(`[data-col="${g}"]`)),m)this.currentCell=m;else if(u!==r&&u>=0){const tt=((q=(k=t(this,V)).getRowHeight)==null?void 0:q.call(k))||40;(X=(N=t(this,V)).scrollToY)==null||X.call(N,u*tt)}}};V=new WeakMap,ct=new WeakMap,re=new WeakMap,oe=new WeakMap,Nt=new WeakMap,ie=new WeakSet,ps=h(function(){t(this,V).addEventListener("mousedown",n=>{const e=n.target.closest("td, th");!e||e.dataset.row===void 0||e.dataset.col===void 0||(this.currentCell=e)}),t(this,V).addEventListener("keydown",n=>{["Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(n.code)&&this.moveCell(n)})},"#initEvents"),h(Ue,"CellNavigation");let qe=Ue;const Ot=class Ot extends HTMLElement{constructor(){super();d(this,ae);d(this,ht,null);d(this,dt);d(this,_t);d(this,Dt);C(this,"invalidate",h(()=>{y.log("sheet.invalidate()"),t(this,dt).refresh()},"invalidate"));C(this,"generate",h(e=>{if(y.log("sheet.generate()"),!e)return;p(this,ht,Ae.compile(e)),t(this,le).call(this),t(this,ce).call(this);const s=this.querySelector(".ng-container-body .ng-part-header"),r=this.querySelector(".ng-container-body .ng-part-footer"),o=this.querySelector(".ng-nodata-overlay");s&&o&&(o.style.top=`${s.offsetHeight}px`),r&&o&&(o.style.bottom=`${r.offsetHeight}px`),t(this,dt).initialize(),setTimeout(()=>{var i;(i=this.querySelector("nine-table-hscrollbar"))==null||i.refresh()},0)},"generate"));d(this,le,h(()=>{[{selector:".ng-container-body",type:null},{selector:".ng-container-left",type:"left"},{selector:".ng-container-right",type:"right"}].forEach(({selector:s,type:r})=>{var o,i,a;(o=this.querySelector(`${s} .ng-part-header`))==null||o.appendChild(t(this,xt).call(this,t(this,ht),r,"header")),(i=this.querySelector(`${s} .ng-virtual-spacer`))==null||i.before(t(this,xt).call(this,t(this,ht),r,"body")),(a=this.querySelector(`${s} .ng-part-footer`))==null||a.appendChild(t(this,xt).call(this,t(this,ht),r,"footer"))})},"#renderSplitContainers"));d(this,ce,h(()=>{["left","right","body"].forEach(e=>{const s=this.querySelector(`.ng-container-${e}`),r=s==null?void 0:s.querySelectorAll("table");if(!s||!r||r.length===0)return;let o=0;r[0].querySelectorAll("col").forEach(i=>{const a=parseInt(i.getAttribute("width"),10);isNaN(a)||(o+=a)}),e==="body"?(s.style.flex="1",s.querySelectorAll("table").forEach(i=>{i.style.width="100%"})):(s.style.flex=`0 0 ${o}px`,s.style.width=`${o}px`,s.querySelectorAll("table").forEach(i=>{i.style.width=`${o}px`}))})},"#updateContainerWidths"));d(this,xt,h((e,s,r)=>{const o=e.cloneNode(!0),i=o.querySelector("thead"),a=o.querySelector("tbody"),c=o.querySelector("tfoot");if(r==="header"){if(a&&a.remove(),c&&c.remove(),e.querySelector("tbody")){const f=document.createElement("tbody");f.className="fixed-tbody",o.appendChild(f)}}else r==="body"?(i&&i.remove(),c&&c.remove(),a&&(a.className="bindable-tbody")):r==="footer"&&(i&&i.remove(),a&&a.remove());return s==="left"?o.querySelectorAll("col, th, td, tfoot td, tfoot th").forEach(l=>{l.getAttribute("fixed")!=="left"&&l.remove()}):s==="right"?o.querySelectorAll("col, th, td, tfoot td, tfoot th").forEach(l=>{l.getAttribute("fixed")!=="right"&&l.remove()}):o.querySelectorAll("[fixed=left], [fixed=right]").forEach(l=>{l.remove()}),o},"#createSplitTable"));C(this,"getRowHeight",h(()=>t(this,dt).getRowHeight(),"getRowHeight"));C(this,"scrollToX",h(e=>{const s=this.querySelector(".ng-container-body .ng-part-body");s&&(s.scrollLeft=e)},"scrollToX"));C(this,"scrollToY",h(e=>{const s=this.querySelector(".ng-container-body .ng-part-body");s&&(s.scrollTop=e)},"scrollToY"));d(this,he,h(()=>{t(this,de).call(this),p(this,_t,new Ee(this)),p(this,Dt,new qe(this))},"#init"));d(this,de,h(()=>{const e=Ot.SCROLLBAR_SIZE;this.innerHTML=`
127
127
  <style>
128
128
  nine-table-sheet {
129
129
  display: none;