var w=Object.defineProperty;var m=(n,e,t)=>e in n?w(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var o=(n,e,t)=>(m(n,typeof e!="symbol"?e+"":e,t),t);(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))s(l);new MutationObserver(l=>{for(const i of l)if(i.type==="childList")for(const r of i.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&s(r)}).observe(document,{childList:!0,subtree:!0});function t(l){const i={};return l.integrity&&(i.integrity=l.integrity),l.referrerPolicy&&(i.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?i.credentials="include":l.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(l){if(l.ep)return;l.ep=!0;const i=t(l);fetch(l.href,i)}})();class a{constructor(e,t){o(this,"x");o(this,"y");o(this,"width");o(this,"height");this.x=this.getXCoord(t.column,e),this.y=this.getYCoord(t.row,e),this.width=e.columns[t.column].width,this.height=e.rows[t.row].height}getXCoord(e,t){let s=0;for(let l=0;l{const{key:t}=e;switch(t){case"Escape":{this.hide();break}case"Enter":this.root.changeCellValues(this.root.selection.selectedCell,{value:this.element.value,displayValue:this.element.value}),this.hide()}});o(this,"handleClickOutside",e=>{const t=e.target;this.element.contains(t)||this.hide()});this.root=e;const t=document.createElement("input");t.classList.add("editor"),this.element=t,this.hide()}hide(){this.element.style.display="none",this.element.classList.add("hide"),this.element.blur(),window.removeEventListener("click",this.handleClickOutside),this.element.removeEventListener("keydown",this.handleKeydown),this.root.focusTable()}show(e){const{height:t,width:s,x:l,y:i}=new a(this.root.config,e),r=this.root.getCell(e);this.element.classList.remove("hide"),this.element.style.top=i-this.root.viewport.top+"px",this.element.style.left=l-this.root.viewport.left+"px",this.element.style.width=s+"px",this.element.style.height=t+"px",this.element.style.display="block",window.addEventListener("click",this.handleClickOutside),this.element.addEventListener("keydown",this.handleKeydown),this.element.value=r.value,this.element.focus(),this.element.select()}}class g{constructor(e){o(this,"element");o(this,"root");this.root=e;const t=document.createElement("header");t.classList.add(),this.element=t}}class C{constructor(e){o(this,"element");o(this,"verticalScroller");o(this,"horizontalScroller");o(this,"root");o(this,"isSelecting",!1);o(this,"handleMouseMove",e=>{if(!this.isSelecting)return;const{offsetX:t,offsetY:s}=e,l=this.root.getCellByCoords(t,s);this.root.selection.selectedRange&&(this.root.selection.selectedRange.to=l),this.root.renderSheet()});o(this,"handleMouseUp",()=>{this.isSelecting=!1,this.root.selection.selectedRange&&this.root.selection.selectedRange.from.row===this.root.selection.selectedRange.to.row&&this.root.selection.selectedRange.from.column===this.root.selection.selectedRange.to.column&&(this.root.selection.selectedRange=null),this.root.renderSheet()});o(this,"handleDoubleClick",e=>{e.preventDefault();const t=this.root.getCellByCoords(e.offsetX,e.offsetY);this.root.showEditor(t)});o(this,"handleKeydown",e=>{if(console.log(e),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(e.key))switch(e.preventDefault(),this.root.selection.selectedRange=null,e.key){case"ArrowLeft":{this.root.selection.selectedCell&&this.root.selection.selectedCell.column>0&&(console.log("tick"),this.root.selection.selectedCell.column-=1,this.root.renderSheet());break}case"ArrowRight":{this.root.selection.selectedCell&&this.root.selection.selectedCell.column0&&(this.root.selection.selectedCell.row-=1,this.root.renderSheet());break}case"ArrowDown":{this.root.selection.selectedCell&&this.root.selection.selectedCell.row{if(e.button!==0)return;const{offsetX:t,offsetY:s}=e,l=this.root.getCellByCoords(t,s);this.isSelecting=!0,this.root.selection.selectedRange={from:l,to:l},this.root.selection.selectedCell=l,this.root.renderSheet()});o(this,"handleScroll",()=>{const e=this.getViewportBoundlingRect();this.root.viewport.updateValues(e),this.root.renderSheet()});this.root=e;const{horizontalScroller:t,scroller:s,verticalScroller:l}=this.buildComponent();this.element=s,this.verticalScroller=l,this.horizontalScroller=t,this.element.style.height=this.root.config.view.height+"px",this.element.style.width=this.root.config.view.width+"px",this.element.tabIndex=-1,this.updateScrollerSize(),this.element.addEventListener("scroll",this.handleScroll),this.element.addEventListener("mousedown",this.handleClick),this.element.addEventListener("mousemove",this.handleMouseMove),this.element.addEventListener("mouseup",this.handleMouseUp),this.element.addEventListener("dblclick",this.handleDoubleClick),this.element.addEventListener("keydown",this.handleKeydown)}getViewportBoundlingRect(){const{scrollTop:e,scrollLeft:t}=this.element,{height:s,width:l}=this.element.getBoundingClientRect(),i=e+s,r=t+l;return{top:e,left:t,bottom:i,right:r}}buildComponent(){const e=document.createElement("div"),t=document.createElement("div"),s=document.createElement("div"),l=document.createElement("div"),i=document.createElement("div");return t.style.width="0px",t.style.pointerEvents="none",s.style.pointerEvents="none",l.style.display="flex",i.appendChild(t),i.appendChild(s),l.appendChild(i),this.verticalScroller=t,this.horizontalScroller=s,e.appendChild(l),e.classList.add("scroller"),{scroller:e,verticalScroller:t,horizontalScroller:s}}getActualHeight(){return this.root.config.rows.reduce((e,t)=>(e+=t.height,e),0)}getActualWidth(){return this.root.config.columns.reduce((e,t)=>(e+=t.width,e),0)}updateScrollerSize(){const e=this.getActualHeight(),t=this.getActualWidth();this.setScrollerHeight(e),this.setScrollerWidth(t)}setScrollerHeight(e){this.verticalScroller.style.height=e+"px"}setScrollerWidth(e){this.horizontalScroller.style.width=e+"px"}}class p{constructor(e){o(this,"fontSize",16);o(this,"fontColor","black");o(this,"background","white");o(this,"borderColor","black");o(this,"selectedBackground","#4287f5");o(this,"selectedFontColor","#ffffff");e&&Object.assign(this,e)}}class y{constructor(e,t){o(this,"row");o(this,"column");this.row=e,this.column=t}}class v{constructor(e){o(this,"value");o(this,"displayValue");o(this,"resultValue");o(this,"position");o(this,"style",new p);this.value=e.value,this.displayValue=e.displayValue,this.resultValue=e.resultValue,this.position=e.position}changeValues(e){Object.assign(this,e)}isCellInRange(e){const{column:t,row:s}=this.position,{selectedRange:l}=e.selection;if(!l)return!1;const i=s>=Math.min(l.from.row,l.to.row)&&s<=Math.max(l.to.row,l.from.row);return t>=Math.min(l.from.column,l.to.column)&&t<=Math.max(l.to.column,l.from.column)&&i}render(e){var d;let{height:t,width:s,x:l,y:i}=new a(e.config,this.position);const{ctx:r}=e,h=((d=e.selection.selectedCell)==null?void 0:d.row)===this.position.row&&e.selection.selectedCell.column===this.position.column,c=this.isCellInRange(e);i-=e.viewport.top,l-=e.viewport.left,r.clearRect(l,i,s,t),r.fillStyle=h||c?this.style.selectedBackground:this.style.background,r.strokeStyle="black",r.fillRect(l,i,s-1,t-1),r.strokeRect(l,i,s,t),r.fillStyle=h||c?this.style.selectedFontColor:this.style.fontColor,r.textAlign="left",r.font=`${this.style.fontSize}px Arial`,r.textBaseline="middle",r.fillText(this.displayValue,l+2,i+t/2,s)}}class x{constructor(e){o(this,"element");o(this,"ctx");o(this,"root");this.root=e;const t=document.createElement("canvas");t.classList.add("sheet"),t.height=this.root.config.view.height,t.width=this.root.config.view.width,t.style.width=this.root.config.view.width+"px",t.style.height=this.root.config.view.height+"px",this.element=t;const s=this.element.getContext("2d");if(!s)throw new Error("Enable hardware acceleration");this.ctx=s}getCellByCoords(e,t){let s=0,l=0;for(;l<=t&&(l+=this.root.config.rows[s].height,!(l>=t));)s++;let i=0,r=0;for(;r<=e&&(r+=this.root.config.columns[i].width,!(r>=e));)i++;return new y(s,i)}renderCell(e){const{column:t,row:s}=e;this.root.data[s][t].render(this.root)}renderSheet(){const e=this.root.viewport.firstRow,t=this.root.viewport.lastCol+3,s=this.root.viewport.lastRow+3,l=this.root.viewport.firstCol;for(let i=e;i<=s;i++)for(let r=l;r<=t&&!(!this.root.config.columns[r]||!this.root.config.rows[i]);r++)this.renderCell({column:r,row:i})}}class S{constructor(e){o(this,"element");o(this,"root");this.root=e;const t=document.createElement("div");t.classList.add("spreadsheet_container"),this.element=t,this.changeElementSizes(this.root.viewProps)}changeElementSizes(e){const{height:t,width:s}=e;this.element.style.width=s+"px",this.element.style.height=t+"px"}}class b{constructor(e){o(this,"element");o(this,"root");this.root=e;const t=document.createElement("div");t.classList.add("toolbar"),this.element=t}}class u{constructor(e){o(this,"rows");o(this,"columns");o(this,"view",{width:800,height:600});this.columns=e.columns,this.rows=e.rows,this.view=e.view}}class R{constructor(){o(this,"selectedCell",null);o(this,"selectedRange",null)}}class E{}class k{constructor(e,t){o(this,"root");o(this,"top");o(this,"left");o(this,"right");o(this,"bottom");o(this,"firstRow");o(this,"lastRow");o(this,"firstCol");o(this,"lastCol");this.root=e,this.top=t.top,this.left=t.left,this.right=t.right,this.bottom=t.bottom,this.firstRow=this.getFirstRow(),this.lastCol=this.getFirstRow();//!Temp this.firstCol=this.getFirstRow();//!Temp this.lastRow=this.getLastRow(),this.updateValues({top:0,left:0,right:this.root.viewProps.width,bottom:this.root.viewProps.height})}updateValues(e){this.top=e.top,this.left=e.left,this.right=e.right,this.bottom=e.bottom,this.firstRow=this.getFirstRow(),this.lastRow=this.getLastRow(),this.firstCol=this.getFirstCol(),this.lastCol=this.getLastCol()}getFirstRow(){return this.root.cache.getRowByYCoord(this.top)}getLastRow(){return this.root.cache.getRowByYCoord(this.bottom)}getFirstCol(){return this.root.cache.getColumnByXCoord(this.left)}getLastCol(){return this.root.cache.getColumnByXCoord(this.right)}}class I{constructor(e){o(this,"width");o(this,"title");this.width=e.width,this.title=e.title}}class L{constructor(e){o(this,"height");o(this,"title");this.height=e.height,this.title=e.title}}function V(n,e){const t=[];for(let s=0;s<=n;s++){const l=[];for(let i=0;i<=e;i++){const r=`${s}:${i}`,h=new v({displayValue:r,resultValue:r,value:r,position:{column:i,row:s}});l.push(h)}t.push(l)}return t}function A(n,e){const t=[];for(let i=0;i<=n;i++){const r=new L({height:40,title:String(i)});t.push(r)}const s=[];for(let i=0;i<=e;i++){const r=new I({title:String(i),width:150});s.push(r)}return new u({columns:s,rows:t,view:{height:600,width:800}})}class B{constructor(e){o(this,"xPos");o(this,"colIdx");this.xPos=e.xPos,this.colIdx=e.colIdx}}class M{constructor(e){o(this,"yPos");o(this,"rowIdx");this.yPos=e.yPos,this.rowIdx=e.rowIdx}}class P{constructor(e){o(this,"columns");o(this,"rows");this.columns=e.columns,this.rows=e.rows}getRowByYCoord(e){let t=0;for(let s=0;s{this.changeCellValues(e.position,{displayValue:"",resultValue:"",value:""})});else{if(!this.selection.selectedCell)return;this.changeCellValues(this.selection.selectedCell,{displayValue:"",resultValue:"",value:""})}}showEditor(e){this.editor.show(e)}renderSheet(){this.sheet.renderSheet()}renderCell(e,t){this.data[e][t].render(this)}}const z=new T("#spreadsheet",{view:{height:768,width:1366}});console.log(z);