@nuptechs/nup-xlsx-preview 1.1.2-debug → 1.1.3

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.
@@ -1,10 +1,10 @@
1
- import {forwardRef,useRef,useState,useMemo,useLayoutEffect,useEffect,useCallback,useImperativeHandle}from'react';import {jsx,jsxs}from'react/jsx-runtime';var j=class{rowPositions;colPositions;rowHeightCache;colWidthCache;totalHeight;totalWidth;overscan;rowCount;colCount;frozenRows;frozenCols;frozenRowsHeight;frozenColsWidth;constructor(e){let{rows:t,cols:r,rowHeights:l,colWidths:s,defaultRowHeight:i=24,defaultColWidth:d=100,overscan:u=5,frozenRows:h=0,frozenCols:p=0}=e;this.frozenRows=h,this.frozenCols=p,this.rowCount=t,this.colCount=r,this.overscan=u,this.rowPositions=new Array(t+1),this.rowHeightCache=new Array(t),this.rowPositions[0]=0;for(let m=0;m<t;m++){let w=l[m]??i;this.rowHeightCache[m]=w,this.rowPositions[m+1]=this.rowPositions[m]+w;}this.totalHeight=this.rowPositions[t],this.frozenRowsHeight=h>0?this.rowPositions[h]??0:0,this.colPositions=new Array(r+1),this.colWidthCache=new Array(r),this.colPositions[0]=0;for(let m=0;m<r;m++){let w=s[m]??d;this.colWidthCache[m]=w,this.colPositions[m+1]=this.colPositions[m]+w;}this.totalWidth=this.colPositions[r],this.frozenColsWidth=p>0?this.colPositions[p]??0:0;}getFrozenInfo(){return {rows:this.frozenRows,cols:this.frozenCols,frozenRowsHeight:this.frozenRowsHeight,frozenColsWidth:this.frozenColsWidth}}binarySearch(e,t){let r=0,l=e.length-2;for(;r<=l;){let s=r+l>>>1,i=e[s],d=e[s+1];if(t>=i&&t<d)return s;t<i?l=s-1:r=s+1;}return Math.max(0,Math.min(r,e.length-2))}getVisibleRange(e,t,r,l){let s=e+this.frozenRowsHeight,i=t+this.frozenColsWidth,d=this.binarySearch(this.rowPositions,s),u=this.binarySearch(this.rowPositions,s+Math.max(0,r)),h=this.binarySearch(this.colPositions,i),p=this.binarySearch(this.colPositions,i+Math.max(0,l)),m=Math.max(this.frozenRows,d-this.overscan),w=Math.min(this.rowCount-1,u+this.overscan),L=Math.max(this.frozenCols,h-this.overscan),K=Math.min(this.colCount-1,p+this.overscan);return {startRow:m,endRow:w,startCol:L,endCol:K}}getFrozenRowsRange(){return this.frozenRows===0?null:{startRow:0,endRow:this.frozenRows-1}}getFrozenColsRange(){return this.frozenCols===0?null:{startCol:0,endCol:this.frozenCols-1}}getCellRect(e,t){return {top:this.rowPositions[e]??0,left:this.colPositions[t]??0,width:this.colWidthCache[t]??100,height:this.rowHeightCache[e]??24}}getRowHeight(e){return this.rowHeightCache[e]??24}getColWidth(e){return this.colWidthCache[e]??100}setColWidth(e,t){if(e<0||e>=this.colCount)return;let r=this.colWidthCache[e],l=t-r;this.colWidthCache[e]=t;for(let s=e+1;s<=this.colCount;s++)this.colPositions[s]+=l;this.totalWidth+=l;}getIndexAtPosition(e,t){return {row:this.binarySearch(this.rowPositions,e),col:this.binarySearch(this.colPositions,t)}}getScrollToPosition(e,t,r,l){let s=this.rowPositions[e]??0,i=this.colPositions[t]??0;return {scrollTop:Math.max(0,s-r/2),scrollLeft:Math.max(0,i-l/2)}}};function re(b){let e="",t=b;for(;t>=0;)e=String.fromCharCode(t%26+65)+e,t=Math.floor(t/26)-1;return e}function _e(b){let e=0,t=b.toUpperCase();for(let r=0;r<t.length;r++)e=e*26+(t.charCodeAt(r)-64);return e-1}function M(b,e){return `${re(e)}${b+1}`}function k(b){let e=b.match(/^([A-Z]+)(\d+)$/i);if(!e)return null;let t=_e(e[1]),r=parseInt(e[2],10)-1;return r<0||t<0?null:{row:r,col:t}}var O=class{state;sheet;onChange;constructor(e,t){this.sheet=e,this.onChange=t??null,this.state={anchor:null,focus:null,ranges:[]};}handleClick(e,t,r){let{shiftKey:l,ctrlKey:s,metaKey:i}=r;l&&this.state.anchor?(this.state.focus={row:e,col:t},this.updateRanges()):s||i?(this.state.anchor={row:e,col:t},this.state.focus={row:e,col:t},this.state.ranges.push(this.createRange(this.state.anchor,this.state.focus))):(this.state.anchor={row:e,col:t},this.state.focus={row:e,col:t},this.state.ranges=[this.createRange(this.state.anchor,this.state.focus)]),this.notifyChange();}handleDrag(e,t){this.state.anchor&&(this.state.focus={row:e,col:t},this.updateRanges(),this.notifyChange());}selectCell(e){let t=k(e);t&&(this.state.anchor=t,this.state.focus=t,this.state.ranges=[this.createRange(t,t)],this.notifyChange());}selectRange(e,t){let r=k(e),l=k(t);!r||!l||(this.state.anchor=r,this.state.focus=l,this.state.ranges=[this.createRange(r,l)],this.notifyChange());}selectAll(){this.state.anchor={row:0,col:0},this.state.focus={row:this.sheet.rowCount-1,col:this.sheet.colCount-1},this.state.ranges=[this.createRange(this.state.anchor,this.state.focus)],this.notifyChange();}clear(){this.state.anchor=null,this.state.focus=null,this.state.ranges=[],this.notifyChange();}getSelection(){return this.state.ranges.length===0?null:this.state.ranges[0]}getAllSelections(){return [...this.state.ranges]}isCellSelected(e,t){return this.state.ranges.some(r=>e>=r.start.row&&e<=r.end.row&&t>=r.start.col&&t<=r.end.col)}isAnchor(e,t){return this.state.anchor?.row===e&&this.state.anchor?.col===t}setSheet(e){this.sheet=e,this.clear();}updateRanges(){if(!this.state.anchor||!this.state.focus)return;let e=this.createRange(this.state.anchor,this.state.focus);this.state.ranges.length>0?this.state.ranges[this.state.ranges.length-1]=e:this.state.ranges.push(e);}createRange(e,t){let r=Math.min(e.row,t.row),l=Math.max(e.row,t.row),s=Math.min(e.col,t.col),i=Math.max(e.col,t.col),d=[],u=[];for(let h=r;h<=l;h++){let p=[];for(let m=s;m<=i;m++){let w=M(h,m);u.push(w),p.push(this.sheet.cells[w]??null);}d.push(p);}return {start:{row:r,col:s},end:{row:l,col:i},cells:d,cellRefs:u}}notifyChange(){this.onChange&&this.onChange(this.getSelection());}};var X=class{selection;virtualScroll;config;onScroll;onCopy;constructor(e,t,r,l){this.selection=e,this.virtualScroll=t,this.config=r,this.onScroll=l?.onScroll??null,this.onCopy=l?.onCopy??null;}handleKeyDown(e){if(!this.config.enabled)return false;let t=this.getAction(e);return t?(e.preventDefault(),this.executeAction(t),true):false}getAction(e){let{key:t,shiftKey:r,ctrlKey:l,metaKey:s}=e,i=l||s;if(i&&t==="c")return "copy";if(i&&t==="a")return "select-all";if(r)switch(t){case "ArrowUp":return "extend-up";case "ArrowDown":return "extend-down";case "ArrowLeft":return "extend-left";case "ArrowRight":return "extend-right"}if(i)switch(t){case "Home":return "move-ctrl-home";case "End":return "move-ctrl-end"}switch(t){case "ArrowUp":return "move-up";case "ArrowDown":return "move-down";case "ArrowLeft":return "move-left";case "ArrowRight":return "move-right";case "PageUp":return "move-page-up";case "PageDown":return "move-page-down";case "Home":return "move-home";case "End":return "move-end";case "Tab":return r?"move-left":"move-right";case "Enter":return r?"move-up":"move-down"}return null}executeAction(e){let t=this.selection.getSelection();if(!t&&!["select-all","move-ctrl-home"].includes(e)){this.selection.selectCell("A1"),this.scrollToSelection();return}let{row:r,col:l}=t?.start??{row:0,col:0},s=r,i=l;switch(e){case "move-up":s=Math.max(0,r-1);break;case "move-down":s=Math.min(this.virtualScroll.rowCount-1,r+1);break;case "move-left":i=Math.max(0,l-1);break;case "move-right":i=Math.min(this.virtualScroll.colCount-1,l+1);break;case "move-page-up":s=Math.max(0,r-20);break;case "move-page-down":s=Math.min(this.virtualScroll.rowCount-1,r+20);break;case "move-home":i=0;break;case "move-end":i=this.virtualScroll.colCount-1;break;case "move-ctrl-home":s=0,i=0;break;case "move-ctrl-end":s=this.virtualScroll.rowCount-1,i=this.virtualScroll.colCount-1;break;case "select-all":this.selection.selectAll();return;case "copy":this.onCopy?.();return;case "extend-up":case "extend-down":case "extend-left":case "extend-right":this.extendSelection(e);return}this.selection.handleClick(s,i,{shiftKey:false,ctrlKey:false,metaKey:false}),this.scrollToSelection();}extendSelection(e){let t=this.selection.getSelection();if(!t)return;let{row:r,col:l}=t.end;switch(e){case "extend-up":r=Math.max(0,r-1);break;case "extend-down":r=Math.min(this.virtualScroll.rowCount-1,r+1);break;case "extend-left":l=Math.max(0,l-1);break;case "extend-right":l=Math.min(this.virtualScroll.colCount-1,l+1);break}this.selection.handleDrag(r,l),this.scrollToSelection();}scrollToSelection(){let e=this.selection.getSelection();!e||!this.onScroll||this.onScroll(e.start.row,e.start.col);}setVirtualScroll(e){this.virtualScroll=e;}setSelection(e){this.selection=e;}};var G=class{merges;mergeMap;constructor(e=[]){this.merges=[],this.mergeMap=new Map,this.parseMerges(e);}parseMerges(e){for(let t of e){let[r,l]=t.split(":");if(!r||!l)continue;let s=k(r),i=k(l);if(!s||!i)continue;let d={startRow:Math.min(s.row,i.row),startCol:Math.min(s.col,i.col),endRow:Math.max(s.row,i.row),endCol:Math.max(s.col,i.col),cellRef:r};this.merges.push(d);for(let u=d.startRow;u<=d.endRow;u++)for(let h=d.startCol;h<=d.endCol;h++){let p=`${u},${h}`;this.mergeMap.set(p,d);}}}getMergeAt(e,t){return this.mergeMap.get(`${e},${t}`)??null}isMergeMaster(e,t){let r=this.getMergeAt(e,t);return r?r.startRow===e&&r.startCol===t:false}isMergeHidden(e,t){let r=this.getMergeAt(e,t);return r?!(r.startRow===e&&r.startCol===t):false}getMergeMaster(e,t){let r=this.getMergeAt(e,t);return r?{row:r.startRow,col:r.startCol}:null}getMergeRect(e,t,r){let l=this.getMergeAt(e,t);if(!l||!this.isMergeMaster(e,t))return null;let s=r(l.startRow,l.startCol),i=r(l.endRow,l.endCol);return {top:s.top,left:s.left,width:i.left+i.width-s.left,height:i.top+i.height-s.top}}getAllMerges(){return [...this.merges]}getVisibleMerges(e,t,r,l){return this.merges.filter(s=>s.endRow>=e&&s.startRow<=t&&s.endCol>=r&&s.startCol<=l)}update(e){this.merges=[],this.mergeMap.clear(),this.parseMerges(e);}};var Q=class{async copyToClipboard(e){let t=this.formatSelection(e);try{if(navigator.clipboard&&typeof ClipboardItem<"u"){let r=new Blob([t.html],{type:"text/html"}),l=new Blob([t.text],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/html":r,"text/plain":l})]);}else await this.copyWithExecCommand(t.text);}catch{await this.copyWithExecCommand(t.text);}return t}formatSelection(e){let{cells:t}=e,r=[];for(let d of t){let u=d.map(h=>this.getCellValue(h));r.push(u.join(" "));}let l=r.join(`
2
- `),s=[];for(let d of t){let u=d.map(h=>{let p=this.escapeHtml(this.getCellValue(h));return `<td style="${this.getCellStyle(h)}">${p}</td>`});s.push(`<tr>${u.join("")}</tr>`);}let i=`
1
+ import {forwardRef,useRef,useState,useMemo,useLayoutEffect,useEffect,useCallback,useImperativeHandle}from'react';import {jsx,jsxs}from'react/jsx-runtime';var j=class{rowPositions;colPositions;rowHeightCache;colWidthCache;totalHeight;totalWidth;overscan;rowCount;colCount;frozenRows;frozenCols;frozenRowsHeight;frozenColsWidth;constructor(e){let{rows:t,cols:r,rowHeights:i,colWidths:s,defaultRowHeight:l=24,defaultColWidth:u=100,overscan:h=5,frozenRows:f=0,frozenCols:m=0}=e;this.frozenRows=f,this.frozenCols=m,this.rowCount=t,this.colCount=r,this.overscan=h,this.rowPositions=new Array(t+1),this.rowHeightCache=new Array(t),this.rowPositions[0]=0;for(let p=0;p<t;p++){let w=i[p]??l;this.rowHeightCache[p]=w,this.rowPositions[p+1]=this.rowPositions[p]+w;}this.totalHeight=this.rowPositions[t],this.frozenRowsHeight=f>0?this.rowPositions[f]??0:0,this.colPositions=new Array(r+1),this.colWidthCache=new Array(r),this.colPositions[0]=0;for(let p=0;p<r;p++){let w=s[p]??u;this.colWidthCache[p]=w,this.colPositions[p+1]=this.colPositions[p]+w;}this.totalWidth=this.colPositions[r],this.frozenColsWidth=m>0?this.colPositions[m]??0:0;}getFrozenInfo(){return {rows:this.frozenRows,cols:this.frozenCols,frozenRowsHeight:this.frozenRowsHeight,frozenColsWidth:this.frozenColsWidth}}binarySearch(e,t){let r=0,i=e.length-2;for(;r<=i;){let s=r+i>>>1,l=e[s],u=e[s+1];if(t>=l&&t<u)return s;t<l?i=s-1:r=s+1;}return Math.max(0,Math.min(r,e.length-2))}getVisibleRange(e,t,r,i){let s=e+this.frozenRowsHeight,l=t+this.frozenColsWidth,u=this.binarySearch(this.rowPositions,s),h=this.binarySearch(this.rowPositions,s+Math.max(0,r)),f=this.binarySearch(this.colPositions,l),m=this.binarySearch(this.colPositions,l+Math.max(0,i)),p=Math.max(this.frozenRows,u-this.overscan),w=Math.min(this.rowCount-1,h+this.overscan),L=Math.max(this.frozenCols,f-this.overscan),$=Math.min(this.colCount-1,m+this.overscan);return {startRow:p,endRow:w,startCol:L,endCol:$}}getFrozenRowsRange(){return this.frozenRows===0?null:{startRow:0,endRow:this.frozenRows-1}}getFrozenColsRange(){return this.frozenCols===0?null:{startCol:0,endCol:this.frozenCols-1}}getCellRect(e,t){return {top:this.rowPositions[e]??0,left:this.colPositions[t]??0,width:this.colWidthCache[t]??100,height:this.rowHeightCache[e]??24}}getRowHeight(e){return this.rowHeightCache[e]??24}getColWidth(e){return this.colWidthCache[e]??100}setColWidth(e,t){if(e<0||e>=this.colCount)return;let r=this.colWidthCache[e],i=t-r;this.colWidthCache[e]=t;for(let s=e+1;s<=this.colCount;s++)this.colPositions[s]+=i;this.totalWidth+=i;}getIndexAtPosition(e,t){return {row:this.binarySearch(this.rowPositions,e),col:this.binarySearch(this.colPositions,t)}}getScrollToPosition(e,t,r,i){let s=this.rowPositions[e]??0,l=this.colPositions[t]??0;return {scrollTop:Math.max(0,s-r/2),scrollLeft:Math.max(0,l-i/2)}}};function se(a){let e="",t=a;for(;t>=0;)e=String.fromCharCode(t%26+65)+e,t=Math.floor(t/26)-1;return e}function it(a){let e=0,t=a.toUpperCase();for(let r=0;r<t.length;r++)e=e*26+(t.charCodeAt(r)-64);return e-1}function M(a,e){return `${se(e)}${a+1}`}function k(a){let e=a.match(/^([A-Z]+)(\d+)$/i);if(!e)return null;let t=it(e[1]),r=parseInt(e[2],10)-1;return r<0||t<0?null:{row:r,col:t}}var O=class{state;sheet;onChange;constructor(e,t){this.sheet=e,this.onChange=t??null,this.state={anchor:null,focus:null,ranges:[]};}handleClick(e,t,r){let{shiftKey:i,ctrlKey:s,metaKey:l}=r;i&&this.state.anchor?(this.state.focus={row:e,col:t},this.updateRanges()):s||l?(this.state.anchor={row:e,col:t},this.state.focus={row:e,col:t},this.state.ranges.push(this.createRange(this.state.anchor,this.state.focus))):(this.state.anchor={row:e,col:t},this.state.focus={row:e,col:t},this.state.ranges=[this.createRange(this.state.anchor,this.state.focus)]),this.notifyChange();}handleDrag(e,t){this.state.anchor&&(this.state.focus={row:e,col:t},this.updateRanges(),this.notifyChange());}selectCell(e){let t=k(e);t&&(this.state.anchor=t,this.state.focus=t,this.state.ranges=[this.createRange(t,t)],this.notifyChange());}selectRange(e,t){let r=k(e),i=k(t);!r||!i||(this.state.anchor=r,this.state.focus=i,this.state.ranges=[this.createRange(r,i)],this.notifyChange());}selectAll(){this.state.anchor={row:0,col:0},this.state.focus={row:this.sheet.rowCount-1,col:this.sheet.colCount-1},this.state.ranges=[this.createRange(this.state.anchor,this.state.focus)],this.notifyChange();}clear(){this.state.anchor=null,this.state.focus=null,this.state.ranges=[],this.notifyChange();}getSelection(){return this.state.ranges.length===0?null:this.state.ranges[0]}getAllSelections(){return [...this.state.ranges]}isCellSelected(e,t){return this.state.ranges.some(r=>e>=r.start.row&&e<=r.end.row&&t>=r.start.col&&t<=r.end.col)}isAnchor(e,t){return this.state.anchor?.row===e&&this.state.anchor?.col===t}setSheet(e){this.sheet=e,this.clear();}updateRanges(){if(!this.state.anchor||!this.state.focus)return;let e=this.createRange(this.state.anchor,this.state.focus);this.state.ranges.length>0?this.state.ranges[this.state.ranges.length-1]=e:this.state.ranges.push(e);}createRange(e,t){let r=Math.min(e.row,t.row),i=Math.max(e.row,t.row),s=Math.min(e.col,t.col),l=Math.max(e.col,t.col),u=[],h=[];for(let f=r;f<=i;f++){let m=[];for(let p=s;p<=l;p++){let w=M(f,p);h.push(w),m.push(this.sheet.cells[w]??null);}u.push(m);}return {start:{row:r,col:s},end:{row:i,col:l},cells:u,cellRefs:h}}notifyChange(){this.onChange&&this.onChange(this.getSelection());}};var X=class{selection;virtualScroll;config;onScroll;onCopy;constructor(e,t,r,i){this.selection=e,this.virtualScroll=t,this.config=r,this.onScroll=i?.onScroll??null,this.onCopy=i?.onCopy??null;}handleKeyDown(e){if(!this.config.enabled)return false;let t=this.getAction(e);return t?(e.preventDefault(),this.executeAction(t),true):false}getAction(e){let{key:t,shiftKey:r,ctrlKey:i,metaKey:s}=e,l=i||s;if(l&&t==="c")return "copy";if(l&&t==="a")return "select-all";if(r)switch(t){case "ArrowUp":return "extend-up";case "ArrowDown":return "extend-down";case "ArrowLeft":return "extend-left";case "ArrowRight":return "extend-right"}if(l)switch(t){case "Home":return "move-ctrl-home";case "End":return "move-ctrl-end"}switch(t){case "ArrowUp":return "move-up";case "ArrowDown":return "move-down";case "ArrowLeft":return "move-left";case "ArrowRight":return "move-right";case "PageUp":return "move-page-up";case "PageDown":return "move-page-down";case "Home":return "move-home";case "End":return "move-end";case "Tab":return r?"move-left":"move-right";case "Enter":return r?"move-up":"move-down"}return null}executeAction(e){let t=this.selection.getSelection();if(!t&&!["select-all","move-ctrl-home"].includes(e)){this.selection.selectCell("A1"),this.scrollToSelection();return}let{row:r,col:i}=t?.start??{row:0,col:0},s=r,l=i;switch(e){case "move-up":s=Math.max(0,r-1);break;case "move-down":s=Math.min(this.virtualScroll.rowCount-1,r+1);break;case "move-left":l=Math.max(0,i-1);break;case "move-right":l=Math.min(this.virtualScroll.colCount-1,i+1);break;case "move-page-up":s=Math.max(0,r-20);break;case "move-page-down":s=Math.min(this.virtualScroll.rowCount-1,r+20);break;case "move-home":l=0;break;case "move-end":l=this.virtualScroll.colCount-1;break;case "move-ctrl-home":s=0,l=0;break;case "move-ctrl-end":s=this.virtualScroll.rowCount-1,l=this.virtualScroll.colCount-1;break;case "select-all":this.selection.selectAll();return;case "copy":this.onCopy?.();return;case "extend-up":case "extend-down":case "extend-left":case "extend-right":this.extendSelection(e);return}this.selection.handleClick(s,l,{shiftKey:false,ctrlKey:false,metaKey:false}),this.scrollToSelection();}extendSelection(e){let t=this.selection.getSelection();if(!t)return;let{row:r,col:i}=t.end;switch(e){case "extend-up":r=Math.max(0,r-1);break;case "extend-down":r=Math.min(this.virtualScroll.rowCount-1,r+1);break;case "extend-left":i=Math.max(0,i-1);break;case "extend-right":i=Math.min(this.virtualScroll.colCount-1,i+1);break}this.selection.handleDrag(r,i),this.scrollToSelection();}scrollToSelection(){let e=this.selection.getSelection();!e||!this.onScroll||this.onScroll(e.start.row,e.start.col);}setVirtualScroll(e){this.virtualScroll=e;}setSelection(e){this.selection=e;}};var G=class{merges;mergeMap;constructor(e=[]){this.merges=[],this.mergeMap=new Map,this.parseMerges(e);}parseMerges(e){for(let t of e){let[r,i]=t.split(":");if(!r||!i)continue;let s=k(r),l=k(i);if(!s||!l)continue;let u={startRow:Math.min(s.row,l.row),startCol:Math.min(s.col,l.col),endRow:Math.max(s.row,l.row),endCol:Math.max(s.col,l.col),cellRef:r};this.merges.push(u);for(let h=u.startRow;h<=u.endRow;h++)for(let f=u.startCol;f<=u.endCol;f++){let m=`${h},${f}`;this.mergeMap.set(m,u);}}}getMergeAt(e,t){return this.mergeMap.get(`${e},${t}`)??null}isMergeMaster(e,t){let r=this.getMergeAt(e,t);return r?r.startRow===e&&r.startCol===t:false}isMergeHidden(e,t){let r=this.getMergeAt(e,t);return r?!(r.startRow===e&&r.startCol===t):false}getMergeMaster(e,t){let r=this.getMergeAt(e,t);return r?{row:r.startRow,col:r.startCol}:null}getMergeRect(e,t,r){let i=this.getMergeAt(e,t);if(!i||!this.isMergeMaster(e,t))return null;let s=r(i.startRow,i.startCol),l=r(i.endRow,i.endCol);return {top:s.top,left:s.left,width:l.left+l.width-s.left,height:l.top+l.height-s.top}}getAllMerges(){return [...this.merges]}getVisibleMerges(e,t,r,i){return this.merges.filter(s=>s.endRow>=e&&s.startRow<=t&&s.endCol>=r&&s.startCol<=i)}update(e){this.merges=[],this.mergeMap.clear(),this.parseMerges(e);}};var Z=class{async copyToClipboard(e){let t=this.formatSelection(e);try{if(navigator.clipboard&&typeof ClipboardItem<"u"){let r=new Blob([t.html],{type:"text/html"}),i=new Blob([t.text],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/html":r,"text/plain":i})]);}else await this.copyWithExecCommand(t.text);}catch{await this.copyWithExecCommand(t.text);}return t}formatSelection(e){let{cells:t}=e,r=[];for(let u of t){let h=u.map(f=>this.getCellValue(f));r.push(h.join(" "));}let i=r.join(`
2
+ `),s=[];for(let u of t){let h=u.map(f=>{let m=this.escapeHtml(this.getCellValue(f));return `<td style="${this.getCellStyle(f)}">${m}</td>`});s.push(`<tr>${h.join("")}</tr>`);}let l=`
3
3
  <table style="border-collapse: collapse; font-family: Arial, sans-serif; font-size: 12px;">
4
4
  <tbody>
5
5
  ${s.join(`
6
6
  `)}
7
7
  </tbody>
8
8
  </table>
9
- `.trim();return {text:l,html:i,cells:t}}getCellValue(e){return !e||e.v===void 0||e.v===null?"":String(e.v)}getCellStyle(e){let t=["border: 1px solid #ccc","padding: 4px 8px"];return e?.t==="n"&&t.push("text-align: right"),t.join("; ")}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}async copyWithExecCommand(e){let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();try{document.execCommand("copy");}finally{document.body.removeChild(t);}}};var Z=class{sheet;results;currentIndex;constructor(e){this.sheet=e,this.results=[],this.currentIndex=-1;}search(e,t={}){if(!e)return this.results=[],this.currentIndex=-1,[];let{caseSensitive:r=false,regex:l=false,matchWholeCell:s=false}=t,i;try{if(l)i=new RegExp(e,r?"g":"gi");else {let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),h=s?`^${u}$`:u;i=new RegExp(h,r?"g":"gi");}}catch{let u=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");i=new RegExp(u,r?"g":"gi");}let d=[];for(let[u,h]of Object.entries(this.sheet.cells)){if(h.v===void 0||h.v===null)continue;let p=String(h.v);i.lastIndex=0;let m=i.exec(p);if(m){let w=this.parseCellRef(u);w&&d.push({row:w.row,col:w.col,cellRef:u,value:p,matchStart:m.index,matchEnd:m.index+m[0].length});}}return d.sort((u,h)=>u.row!==h.row?u.row-h.row:u.col-h.col),this.results=d,this.currentIndex=d.length>0?0:-1,d}next(){return this.results.length===0?null:(this.currentIndex=(this.currentIndex+1)%this.results.length,this.results[this.currentIndex])}previous(){return this.results.length===0?null:(this.currentIndex=(this.currentIndex-1+this.results.length)%this.results.length,this.results[this.currentIndex])}current(){return this.currentIndex<0||this.currentIndex>=this.results.length?null:this.results[this.currentIndex]}getResults(){return [...this.results]}getCount(){return this.results.length}getCurrentIndex(){return this.currentIndex+1}isResult(e,t){return this.results.some(r=>r.row===e&&r.col===t)}isCurrent(e,t){let r=this.current();return r?.row===e&&r?.col===t}clear(){this.results=[],this.currentIndex=-1;}setSheet(e){this.sheet=e,this.clear();}parseCellRef(e){let t=e.match(/^([A-Z]+)(\d+)$/i);if(!t)return null;let r=t[1].toUpperCase(),l=parseInt(t[2],10)-1,s=0;for(let i=0;i<r.length;i++)s=s*26+(r.charCodeAt(i)-64);return s-=1,{row:l,col:s}}};var Y=class{state=null;virtualScroll;onChange;minWidth;maxWidth;constructor(e,t,r=30,l=500){this.virtualScroll=e,this.onChange=t??null,this.minWidth=r,this.maxWidth=l;}startResize(e,t){let r=this.virtualScroll.getColWidth(e);this.state={isResizing:true,colIndex:e,startX:t,startWidth:r},document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),document.body.style.cursor="col-resize",document.body.style.userSelect="none";}handleMouseMove=e=>{if(!this.state)return;let t=e.clientX-this.state.startX,r=Math.min(this.maxWidth,Math.max(this.minWidth,this.state.startWidth+t));this.virtualScroll.setColWidth(this.state.colIndex,r),this.onChange?.(this.state.colIndex,r);};handleMouseUp=()=>{this.cleanup();};isResizing(){return this.state?.isResizing??false}getResizeColumn(){return this.state?.colIndex??null}cancel(){this.state&&(this.virtualScroll.setColWidth(this.state.colIndex,this.state.startWidth),this.onChange?.(this.state.colIndex,this.state.startWidth)),this.cleanup();}cleanup(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.body.style.cursor="",document.body.style.userSelect="",this.state=null;}setVirtualScroll(e){this.virtualScroll=e;}destroy(){this.cleanup();}};var ne={default:{name:"default",colors:{background:"#ffffff",foreground:"#202124",grid:"#e0e0e0",headerBackground:"#f8f9fa",headerForeground:"#5f6368",selectionBorder:"#1a73e8",selectionBackground:"rgba(26, 115, 232, 0.08)",frozenBorder:"#dadce0"},fonts:{family:"'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},excel:{name:"excel",colors:{background:"#ffffff",foreground:"#000000",grid:"#d4d4d4",headerBackground:"#f0f0f0",headerForeground:"#000000",selectionBorder:"#217346",selectionBackground:"rgba(33, 115, 70, 0.1)",frozenBorder:"#9bc2e6"},fonts:{family:"'Calibri', 'Segoe UI', sans-serif",size:"11px",headerSize:"11px"}},modern:{name:"modern",colors:{background:"#fafafa",foreground:"#18181b",grid:"#e4e4e7",headerBackground:"#f4f4f5",headerForeground:"#71717a",selectionBorder:"#3b82f6",selectionBackground:"rgba(59, 130, 246, 0.08)",frozenBorder:"#a1a1aa"},fonts:{family:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",size:"13px",headerSize:"11px"}},minimal:{name:"minimal",colors:{background:"#ffffff",foreground:"#27272a",grid:"#f4f4f5",headerBackground:"#ffffff",headerForeground:"#a1a1aa",selectionBorder:"#18181b",selectionBackground:"rgba(24, 24, 27, 0.04)",frozenBorder:"#e4e4e7"},fonts:{family:"'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif",size:"13px",headerSize:"11px"}},dark:{name:"dark",colors:{background:"#1e1e1e",foreground:"#d4d4d4",grid:"#3c3c3c",headerBackground:"#252526",headerForeground:"#858585",selectionBorder:"#0078d4",selectionBackground:"rgba(0, 120, 212, 0.2)",frozenBorder:"#4a4a4a"},fonts:{family:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},midnight:{name:"midnight",colors:{background:"#0d1117",foreground:"#c9d1d9",grid:"#21262d",headerBackground:"#161b22",headerForeground:"#8b949e",selectionBorder:"#58a6ff",selectionBackground:"rgba(88, 166, 255, 0.15)",frozenBorder:"#30363d"},fonts:{family:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},accessible:{name:"accessible",colors:{background:"#ffffff",foreground:"#000000",grid:"#000000",headerBackground:"#e6e6e6",headerForeground:"#000000",selectionBorder:"#0000ff",selectionBackground:"rgba(0, 0, 255, 0.15)",frozenBorder:"#000000"},fonts:{family:"Arial, Helvetica, sans-serif",size:"14px",headerSize:"12px"}}};function Ie(b,e){let t=b.style;t.setProperty("--nup-background",e.colors.background),t.setProperty("--nup-foreground",e.colors.foreground),t.setProperty("--nup-grid",e.colors.grid),t.setProperty("--nup-header-bg",e.colors.headerBackground),t.setProperty("--nup-header-fg",e.colors.headerForeground),t.setProperty("--nup-selection-border",e.colors.selectionBorder),t.setProperty("--nup-selection-bg",e.colors.selectionBackground),t.setProperty("--nup-frozen-border",e.colors.frozenBorder),t.setProperty("--nup-font-family",e.fonts.family),t.setProperty("--nup-font-size",e.fonts.size);}function He(b){return `nup-theme-${b}`}var ot=forwardRef(function(e,t){let{workbook:r,activeSheet:l=0,theme:s="default",width:i="100%",height:d="400px",className:u="",style:h={},showHeaders:p=true,showGridLines:m=true,showSheetTabs:w=true,selectable:L=true,resizable:K=true,searchable:Ee=false,copyable:se=true,keyboardNavigation:le=true,frozenRows:ie=0,frozenCols:ae=0,overscan:ce=5,defaultRowHeight:he=24,defaultColWidth:ue=100,ariaLabel:Ke="Spreadsheet",onCellClick:de,onCellDoubleClick:me,onCellRightClick:fe,onSelectionChange:pe,onSheetChange:ge,onColumnResize:be,onScroll:we,onSearch:ve,onCopy:D}=e,J=useRef(null),H=useRef(null),[F,Ce]=useState(l),[W,$e]=useState({top:0,left:0}),[v,ye]=useState({width:0,height:0}),[S,Re]=useState(null),[_,q]=useState([]),[Le,Se]=useState(""),[De,ee]=useState(0),g=r.sheets[F]??r.sheets[0],xe=useMemo(()=>typeof s=="string"?ne[s]??ne.default:s,[s]),f=useMemo(()=>{let o={},n={};return Object.entries(g.rows).forEach(([a,c])=>{c.h&&(o[parseInt(a)]=c.h);}),Object.entries(g.cols).forEach(([a,c])=>{c.w&&(n[parseInt(a)]=c.w);}),new j({rows:g.rowCount,cols:g.colCount,rowHeights:o,colWidths:n,defaultRowHeight:he,defaultColWidth:ue,overscan:ce,frozenRows:ie,frozenCols:ae})},[g,he,ue,ce,ie,ae,De]),C=useMemo(()=>new O(g,o=>{Re(o),pe?.(o);}),[g,pe]),Me=useMemo(()=>new G(g.merges??[]),[g.merges]),T=useMemo(()=>new Z(g),[g]),V=useMemo(()=>new Q,[]),U=useMemo(()=>new Y(f,(o,n)=>{ee(a=>a+1),be?.(o,n);}),[f,be]),ke=useMemo(()=>new X(C,f,{enabled:le},{onScroll:(o,n)=>{let a=f.getScrollToPosition(o,n,v.height,v.width);H.current?.scrollTo({top:a.scrollTop,left:a.scrollLeft,behavior:"smooth"});},onCopy:async()=>{let o=C.getSelection();if(o&&se){let n=await V.copyToClipboard(o);D?.(n);}}}),[C,f,le,se,v,V,D]);useLayoutEffect(()=>{let o=H.current;if(!o)return;let n=new ResizeObserver(a=>{let c=a[0];c&&ye({width:c.contentRect.width,height:c.contentRect.height});});return n.observe(o),ye({width:o.clientWidth,height:o.clientHeight}),()=>n.disconnect()},[]),useEffect(()=>{J.current&&Ie(J.current,xe);},[xe]),useEffect(()=>{Ce(l);},[l]);let Fe=useCallback(o=>{let{scrollTop:n,scrollLeft:a}=o.currentTarget;$e({top:n,left:a});let c=f.getVisibleRange(n,a,v.height,v.width);we?.({scrollTop:n,scrollLeft:a,visibleRows:{start:c.startRow,end:c.endRow},visibleCols:{start:c.startCol,end:c.endCol}});},[f,v,we]),Ve=useCallback((o,n,a)=>{if(!L)return;let c=M(o,n),y=g.cells[c]??null;C.handleClick(o,n,{shiftKey:a.shiftKey,ctrlKey:a.ctrlKey,metaKey:a.metaKey}),de?.({cell:y,row:o,col:n,cellRef:c,originalEvent:a.nativeEvent});},[L,g,C,de]),Ue=useCallback((o,n,a)=>{let c=M(o,n),y=g.cells[c]??null;me?.({cell:y,row:o,col:n,cellRef:c,originalEvent:a.nativeEvent});},[g,me]),je=useCallback((o,n,a)=>{a.preventDefault();let c=M(o,n),y=g.cells[c]??null;fe?.({cell:y,row:o,col:n,cellRef:c,originalEvent:a.nativeEvent});},[g,fe]),Oe=useCallback(o=>{ke.handleKeyDown(o.nativeEvent);},[ke]),te=useCallback(o=>{Ce(o),C.clear(),ge?.(o);},[C,ge]),oe=useCallback(o=>{Se(o);let n=T.search(o);q(n),ve?.(n);},[T,ve]),Xe=useCallback((o,n)=>{K&&(n.preventDefault(),n.stopPropagation(),U.startResize(o,n.clientX));},[K,U]);useImperativeHandle(t,()=>({scrollTo:(o,n)=>{let a=f.getScrollToPosition(o,n,v.height,v.width);H.current?.scrollTo({top:a.scrollTop,left:a.scrollLeft,behavior:"smooth"});},scrollToCell:o=>{let n=k(o);if(n){let a=f.getScrollToPosition(n.row,n.col,v.height,v.width);H.current?.scrollTo({top:a.scrollTop,left:a.scrollLeft,behavior:"smooth"});}},select:o=>{Re(o);},selectCell:o=>{C.selectCell(o);},selectAll:()=>{C.selectAll();},clearSelection:()=>{C.clear();},getSelection:()=>S,setActiveSheet:te,getActiveSheet:()=>F,search:o=>(oe(o),T.getResults()),highlightResults:o=>{q(o);},clearHighlights:()=>{q([]),Se("");},getWorkbook:()=>r,getVisibleCells:()=>{let o=f.getVisibleRange(W.top,W.left,v.height,v.width),n=[];for(let a=o.startRow;a<=o.endRow;a++){let c=[];for(let y=o.startCol;y<=o.endCol;y++)c.push(g.cells[M(a,y)]??null);n.push(c);}return n},getCellAt:(o,n)=>g.cells[M(o,n)]??null,copySelection:async()=>{let o=C.getSelection();if(o){let n=await V.copyToClipboard(o);D?.(n);}},setColumnWidth:(o,n)=>{f.setColWidth(o,n),ee(a=>a+1);},autoFitColumn:()=>{},autoFitAllColumns:()=>{},refresh:()=>ee(o=>o+1),destroy:()=>{U.destroy();}}),[f,v,C,T,V,te,oe,F,S,r,g,W,U,D]);let A=p?24:0,B=p?40:0,z=f.getVisibleRange(W.top,W.left,v.height,v.width),ze=[];for(let o=z.startRow;o<=z.endRow;o++)for(let n=z.startCol;n<=z.endCol;n++){if(Me.isMergeHidden(o,n))continue;let a=Me.getMergeRect(o,n,(x,Je)=>f.getCellRect(x,Je))??f.getCellRect(o,n),c=M(o,n),y=g.cells[c],Qe=C.isCellSelected(o,n),Te=C.isAnchor(o,n),Ze=_.some(x=>x.row===o&&x.col===n),Ye=T.isCurrent(o,n),E="nup-cell";y?.t==="n"&&(E+=" nup-cell-number"),Qe&&(E+=" nup-cell-selected"),Te&&(E+=" nup-cell-anchor"),Ze&&(E+=" nup-cell-search-result"),Ye&&(E+=" nup-cell-search-current"),ze.push(jsx("div",{className:E,style:{top:a.top,left:a.left,width:a.width,height:a.height},onClick:x=>Ve(o,n,x),onDoubleClick:x=>Ue(o,n,x),onContextMenu:x=>je(o,n,x),"data-row":o,"data-col":n,"data-cell-ref":c,role:"gridcell","aria-rowindex":o+1,"aria-colindex":n+1,tabIndex:Te?0:-1,children:y?.v!==void 0&&y?.v!==null?String(y.v):""},`${o}-${n}`));}let Ne=[];if(p)for(let o=z.startCol;o<=z.endCol;o++){let n=f.getCellRect(0,o),a=S&&o>=S.start.col&&o<=S.end.col;Ne.push(jsxs("div",{className:`nup-header nup-header-col${a?" nup-header-selected":""}`,style:{left:n.left,width:n.width,height:A},children:[re(o),K&&jsx("div",{className:"nup-resize-handle",onMouseDown:c=>Xe(o,c)})]},`ch-${o}`));}let Pe=[];if(p)for(let o=z.startRow;o<=z.endRow;o++){let n=f.getCellRect(o,0),a=S&&o>=S.start.row&&o<=S.end.row;Pe.push(jsx("div",{className:`nup-header nup-header-row${a?" nup-header-selected":""}`,style:{top:n.top,width:B,height:n.height},children:o+1},`rh-${o}`));}let We=null;if(S){let o=f.getCellRect(S.start.row,S.start.col),n=f.getCellRect(S.end.row,S.end.col);We=jsx("div",{className:"nup-selection-border",style:{top:o.top,left:o.left,width:n.left+n.width-o.left,height:n.top+n.height-o.top}});}let Ge=typeof s=="string"?He(s):"";return jsxs("div",{ref:J,className:`nup-spreadsheet ${Ge} ${u} ${m?"":"nup-no-gridlines"}`,style:{width:i,height:d,...h},tabIndex:0,onKeyDown:Oe,role:"grid","aria-label":Ke,"aria-rowcount":g.rowCount,"aria-colcount":g.colCount,children:[Ee&&jsxs("div",{className:"nup-search-bar",children:[jsx("input",{type:"search",className:"nup-search-input",placeholder:"Search...",value:Le,onChange:o=>oe(o.target.value),"aria-label":"Search in spreadsheet"}),_.length>0&&jsxs("span",{className:"nup-search-count",children:[T.getCurrentIndex()," of ",_.length]}),jsx("button",{className:"nup-search-btn",onClick:()=>{let o=T.next();if(o){let n=f.getScrollToPosition(o.row,o.col,v.height,v.width);H.current?.scrollTo({top:n.scrollTop,left:n.scrollLeft,behavior:"smooth"});}},"aria-label":"Next result",children:"Next"})]}),p&&jsx("div",{className:"nup-corner",style:{width:B,height:A}}),p&&jsx("div",{className:"nup-header-row-container",style:{position:"absolute",top:0,left:B,right:0,height:A,overflow:"hidden"},children:jsx("div",{style:{position:"relative",width:f.totalWidth,height:A,transform:`translateX(${-W.left}px)`},children:Ne})}),p&&jsx("div",{className:"nup-header-col-container",style:{position:"absolute",top:A,left:0,bottom:w?32:0,width:B,overflow:"hidden"},children:jsx("div",{style:{position:"relative",width:B,height:f.totalHeight,transform:`translateY(${-W.top}px)`},children:Pe})}),jsx("div",{ref:H,className:"nup-scroll-container",style:{top:A,left:B,right:0,bottom:w?32:0},onScroll:Fe,children:jsxs("div",{className:"nup-content",style:{width:f.totalWidth,height:f.totalHeight},children:[ze,We]})}),w&&r.sheets.length>1&&jsx("div",{className:"nup-sheet-tabs",children:r.sheets.map((o,n)=>jsx("button",{className:`nup-sheet-tab${n===F?" nup-sheet-tab-active":""}`,onClick:()=>te(n),children:o.name},o.id))})]})}),xt=ot;export{ot as NupSpreadsheetPreview,xt as default};//# sourceMappingURL=react.js.map
9
+ `.trim();return {text:i,html:l,cells:t}}getCellValue(e){return !e||e.v===void 0||e.v===null?"":String(e.v)}getCellStyle(e){let t=["border: 1px solid #ccc","padding: 4px 8px"];return e?.t==="n"&&t.push("text-align: right"),t.join("; ")}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}async copyWithExecCommand(e){let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();try{document.execCommand("copy");}finally{document.body.removeChild(t);}}};var Q=class{sheet;results;currentIndex;constructor(e){this.sheet=e,this.results=[],this.currentIndex=-1;}search(e,t={}){if(!e)return this.results=[],this.currentIndex=-1,[];let{caseSensitive:r=false,regex:i=false,matchWholeCell:s=false}=t,l;try{if(i)l=new RegExp(e,r?"g":"gi");else {let h=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=s?`^${h}$`:h;l=new RegExp(f,r?"g":"gi");}}catch{let h=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");l=new RegExp(h,r?"g":"gi");}let u=[];for(let[h,f]of Object.entries(this.sheet.cells)){if(f.v===void 0||f.v===null)continue;let m=String(f.v);l.lastIndex=0;let p=l.exec(m);if(p){let w=this.parseCellRef(h);w&&u.push({row:w.row,col:w.col,cellRef:h,value:m,matchStart:p.index,matchEnd:p.index+p[0].length});}}return u.sort((h,f)=>h.row!==f.row?h.row-f.row:h.col-f.col),this.results=u,this.currentIndex=u.length>0?0:-1,u}next(){return this.results.length===0?null:(this.currentIndex=(this.currentIndex+1)%this.results.length,this.results[this.currentIndex])}previous(){return this.results.length===0?null:(this.currentIndex=(this.currentIndex-1+this.results.length)%this.results.length,this.results[this.currentIndex])}current(){return this.currentIndex<0||this.currentIndex>=this.results.length?null:this.results[this.currentIndex]}getResults(){return [...this.results]}getCount(){return this.results.length}getCurrentIndex(){return this.currentIndex+1}isResult(e,t){return this.results.some(r=>r.row===e&&r.col===t)}isCurrent(e,t){let r=this.current();return r?.row===e&&r?.col===t}clear(){this.results=[],this.currentIndex=-1;}setSheet(e){this.sheet=e,this.clear();}parseCellRef(e){let t=e.match(/^([A-Z]+)(\d+)$/i);if(!t)return null;let r=t[1].toUpperCase(),i=parseInt(t[2],10)-1,s=0;for(let l=0;l<r.length;l++)s=s*26+(r.charCodeAt(l)-64);return s-=1,{row:i,col:s}}};var Y=class{state=null;virtualScroll;onChange;minWidth;maxWidth;constructor(e,t,r=30,i=500){this.virtualScroll=e,this.onChange=t??null,this.minWidth=r,this.maxWidth=i;}startResize(e,t){let r=this.virtualScroll.getColWidth(e);this.state={isResizing:true,colIndex:e,startX:t,startWidth:r},document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("mouseup",this.handleMouseUp),document.body.style.cursor="col-resize",document.body.style.userSelect="none";}handleMouseMove=e=>{if(!this.state)return;let t=e.clientX-this.state.startX,r=Math.min(this.maxWidth,Math.max(this.minWidth,this.state.startWidth+t));this.virtualScroll.setColWidth(this.state.colIndex,r),this.onChange?.(this.state.colIndex,r);};handleMouseUp=()=>{this.cleanup();};isResizing(){return this.state?.isResizing??false}getResizeColumn(){return this.state?.colIndex??null}cancel(){this.state&&(this.virtualScroll.setColWidth(this.state.colIndex,this.state.startWidth),this.onChange?.(this.state.colIndex,this.state.startWidth)),this.cleanup();}cleanup(){document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("mouseup",this.handleMouseUp),document.body.style.cursor="",document.body.style.userSelect="",this.state=null;}setVirtualScroll(e){this.virtualScroll=e;}destroy(){this.cleanup();}};var ie={default:{name:"default",colors:{background:"#ffffff",foreground:"#202124",grid:"#e0e0e0",headerBackground:"#f8f9fa",headerForeground:"#5f6368",selectionBorder:"#1a73e8",selectionBackground:"rgba(26, 115, 232, 0.08)",frozenBorder:"#dadce0"},fonts:{family:"'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},excel:{name:"excel",colors:{background:"#ffffff",foreground:"#000000",grid:"#d4d4d4",headerBackground:"#f0f0f0",headerForeground:"#000000",selectionBorder:"#217346",selectionBackground:"rgba(33, 115, 70, 0.1)",frozenBorder:"#9bc2e6"},fonts:{family:"'Calibri', 'Segoe UI', sans-serif",size:"11px",headerSize:"11px"}},modern:{name:"modern",colors:{background:"#fafafa",foreground:"#18181b",grid:"#e4e4e7",headerBackground:"#f4f4f5",headerForeground:"#71717a",selectionBorder:"#3b82f6",selectionBackground:"rgba(59, 130, 246, 0.08)",frozenBorder:"#a1a1aa"},fonts:{family:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",size:"13px",headerSize:"11px"}},minimal:{name:"minimal",colors:{background:"#ffffff",foreground:"#27272a",grid:"#f4f4f5",headerBackground:"#ffffff",headerForeground:"#a1a1aa",selectionBorder:"#18181b",selectionBackground:"rgba(24, 24, 27, 0.04)",frozenBorder:"#e4e4e7"},fonts:{family:"'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif",size:"13px",headerSize:"11px"}},dark:{name:"dark",colors:{background:"#1e1e1e",foreground:"#d4d4d4",grid:"#3c3c3c",headerBackground:"#252526",headerForeground:"#858585",selectionBorder:"#0078d4",selectionBackground:"rgba(0, 120, 212, 0.2)",frozenBorder:"#4a4a4a"},fonts:{family:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},midnight:{name:"midnight",colors:{background:"#0d1117",foreground:"#c9d1d9",grid:"#21262d",headerBackground:"#161b22",headerForeground:"#8b949e",selectionBorder:"#58a6ff",selectionBackground:"rgba(88, 166, 255, 0.15)",frozenBorder:"#30363d"},fonts:{family:"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",size:"13px",headerSize:"11px"}},accessible:{name:"accessible",colors:{background:"#ffffff",foreground:"#000000",grid:"#000000",headerBackground:"#e6e6e6",headerForeground:"#000000",selectionBorder:"#0000ff",selectionBackground:"rgba(0, 0, 255, 0.15)",frozenBorder:"#000000"},fonts:{family:"Arial, Helvetica, sans-serif",size:"14px",headerSize:"12px"}}};function Ae(a,e){let t=a.style;t.setProperty("--nup-background",e.colors.background),t.setProperty("--nup-foreground",e.colors.foreground),t.setProperty("--nup-grid",e.colors.grid),t.setProperty("--nup-header-bg",e.colors.headerBackground),t.setProperty("--nup-header-fg",e.colors.headerForeground),t.setProperty("--nup-selection-border",e.colors.selectionBorder),t.setProperty("--nup-selection-bg",e.colors.selectionBackground),t.setProperty("--nup-frozen-border",e.colors.frozenBorder),t.setProperty("--nup-font-family",e.fonts.family),t.setProperty("--nup-font-size",e.fonts.size);}function He(a){return `nup-theme-${a}`}var lt={thin:"1px solid",medium:"2px solid",thick:"3px solid",dashed:"1px dashed",dotted:"1px dotted",double:"3px double"};function _(a){if(!a||!a.style)return;let e=lt[a.style]||"1px solid",t=a.color||"#000000";return `${e} ${t}`}function at(a,e){let t=a.replace("#",""),r=parseInt(t.substring(0,2),16),i=parseInt(t.substring(2,4),16),s=parseInt(t.substring(4,6),16),l,u,h;return e<0?(l=Math.round(r*(1+e)),u=Math.round(i*(1+e)),h=Math.round(s*(1+e))):(l=Math.round(r+(255-r)*e),u=Math.round(i+(255-i)*e),h=Math.round(s+(255-s)*e)),`#${l.toString(16).padStart(2,"0")}${u.toString(16).padStart(2,"0")}${h.toString(16).padStart(2,"0")}`}function Ee(a){if(!a)return {};let e={};if(a.font){let t=a.font;t.name&&(e.fontFamily=t.name),t.size&&(e.fontSize=`${t.size}pt`),t.bold&&(e.fontWeight="bold"),t.italic&&(e.fontStyle="italic"),t.color&&(e.color=t.color);let r=[];t.underline&&r.push("underline"),t.strike&&r.push("line-through"),r.length>0&&(e.textDecoration=r.join(" "));}if(a.fill){let t=a.fill;if(t.color){let r=t.color;t.tint!==void 0&&t.tint!==0&&(r=at(r,t.tint)),e.backgroundColor=r;}}if(a.alignment){let t=a.alignment;t.horizontal&&(e.textAlign=t.horizontal),t.vertical&&(e.verticalAlign=t.vertical==="middle"?"middle":t.vertical),t.wrapText&&(e.whiteSpace="pre-wrap"),t.indent&&(e.paddingLeft=`${t.indent*8}px`),t.rotation&&(e.transform=`rotate(${t.rotation}deg)`);}if(a.border){let t=a.border;(t.top||t.right||t.bottom||t.left)&&(e.borderTop=_(t.top)||"none",e.borderRight=_(t.right)||"none",e.borderBottom=_(t.bottom)||"none",e.borderLeft=_(t.left)||"none");}return e}function ct(a,e){if(a!==void 0&&e.styles)return e.styles[a]??e.styles[String(a)]}function $e(a){let e=t=>t&&t!=="none";return !!(e(a.borderTop)||e(a.borderRight)||e(a.borderBottom)||e(a.borderLeft))}function Ke(a,e,t){let r=t?ct(e,t):void 0;if(!(!a&&!r))return a?r?{...r,...a,font:{...r.font,...a.font},fill:{...r.fill,...a.fill},border:{...r.border,...a.border},alignment:{...r.alignment,...a.alignment}}:a:r}var ft=forwardRef(function(e,t){let{workbook:r,activeSheet:i=0,theme:s="default",width:l="100%",height:u="400px",className:h="",style:f={},showHeaders:m=true,showGridLines:p=true,showSheetTabs:w=true,selectable:L=true,resizable:$=true,searchable:Ve=false,copyable:le=true,keyboardNavigation:ae=true,frozenRows:ce=0,frozenCols:he=0,overscan:ue=5,defaultRowHeight:de=24,defaultColWidth:fe=100,ariaLabel:Fe="Spreadsheet",onCellClick:pe,onCellDoubleClick:ge,onCellRightClick:me,onSelectionChange:be,onSheetChange:we,onColumnResize:Ce,onScroll:ve,onSearch:Se,onCopy:D}=e,J=useRef(null),A=useRef(null),[V,ye]=useState(i),[W,Ue]=useState({top:0,left:0}),[C,Re]=useState({width:0,height:0}),[R,xe]=useState(null),[q,ee]=useState([]),[je,Me]=useState(""),[Oe,te]=useState(0),b=r.sheets[V]??r.sheets[0],ke=useMemo(()=>typeof s=="string"?ie[s]??ie.default:s,[s]),g=useMemo(()=>{let o={},n={};return Object.entries(b.rows).forEach(([c,d])=>{d.h&&(o[parseInt(c)]=d.h);}),Object.entries(b.cols).forEach(([c,d])=>{d.w&&(n[parseInt(c)]=d.w);}),new j({rows:b.rowCount,cols:b.colCount,rowHeights:o,colWidths:n,defaultRowHeight:de,defaultColWidth:fe,overscan:ue,frozenRows:ce,frozenCols:he})},[b,de,fe,ue,ce,he,Oe]),S=useMemo(()=>new O(b,o=>{xe(o),be?.(o);}),[b,be]),re=useMemo(()=>new G(b.merges??[]),[b.merges]),I=useMemo(()=>new Q(b),[b]),F=useMemo(()=>new Z,[]),U=useMemo(()=>new Y(g,(o,n)=>{te(c=>c+1),Ce?.(o,n);}),[g,Ce]),ze=useMemo(()=>new X(S,g,{enabled:ae},{onScroll:(o,n)=>{let c=g.getScrollToPosition(o,n,C.height,C.width);A.current?.scrollTo({top:c.scrollTop,left:c.scrollLeft,behavior:"smooth"});},onCopy:async()=>{let o=S.getSelection();if(o&&le){let n=await F.copyToClipboard(o);D?.(n);}}}),[S,g,ae,le,C,F,D]);useLayoutEffect(()=>{let o=A.current;if(!o)return;let n=new ResizeObserver(c=>{let d=c[0];d&&Re({width:d.contentRect.width,height:d.contentRect.height});});return n.observe(o),Re({width:o.clientWidth,height:o.clientHeight}),()=>n.disconnect()},[]),useEffect(()=>{J.current&&Ae(J.current,ke);},[ke]),useEffect(()=>{ye(i);},[i]);let Xe=useCallback(o=>{let{scrollTop:n,scrollLeft:c}=o.currentTarget;Ue({top:n,left:c});let d=g.getVisibleRange(n,c,C.height,C.width);ve?.({scrollTop:n,scrollLeft:c,visibleRows:{start:d.startRow,end:d.endRow},visibleCols:{start:d.startCol,end:d.endCol}});},[g,C,ve]),Ge=useCallback((o,n,c)=>{if(!L)return;let d=M(o,n),v=b.cells[d]??null;S.handleClick(o,n,{shiftKey:c.shiftKey,ctrlKey:c.ctrlKey,metaKey:c.metaKey}),pe?.({cell:v,row:o,col:n,cellRef:d,originalEvent:c.nativeEvent});},[L,b,S,pe]),Ze=useCallback((o,n,c)=>{let d=M(o,n),v=b.cells[d]??null;ge?.({cell:v,row:o,col:n,cellRef:d,originalEvent:c.nativeEvent});},[b,ge]),Qe=useCallback((o,n,c)=>{c.preventDefault();let d=M(o,n),v=b.cells[d]??null;me?.({cell:v,row:o,col:n,cellRef:d,originalEvent:c.nativeEvent});},[b,me]),Ye=useCallback(o=>{ze.handleKeyDown(o.nativeEvent);},[ze]),oe=useCallback(o=>{ye(o),S.clear(),we?.(o);},[S,we]),ne=useCallback(o=>{Me(o);let n=I.search(o);ee(n),Se?.(n);},[I,Se]),_e=useCallback((o,n)=>{$&&(n.preventDefault(),n.stopPropagation(),U.startResize(o,n.clientX));},[$,U]);useImperativeHandle(t,()=>({scrollTo:(o,n)=>{let c=g.getScrollToPosition(o,n,C.height,C.width);A.current?.scrollTo({top:c.scrollTop,left:c.scrollLeft,behavior:"smooth"});},scrollToCell:o=>{let n=k(o);if(n){let c=g.getScrollToPosition(n.row,n.col,C.height,C.width);A.current?.scrollTo({top:c.scrollTop,left:c.scrollLeft,behavior:"smooth"});}},select:o=>{xe(o);},selectCell:o=>{S.selectCell(o);},selectAll:()=>{S.selectAll();},clearSelection:()=>{S.clear();},getSelection:()=>R,setActiveSheet:oe,getActiveSheet:()=>V,search:o=>(ne(o),I.getResults()),highlightResults:o=>{ee(o);},clearHighlights:()=>{ee([]),Me("");},getWorkbook:()=>r,getVisibleCells:()=>{let o=g.getVisibleRange(W.top,W.left,C.height,C.width),n=[];for(let c=o.startRow;c<=o.endRow;c++){let d=[];for(let v=o.startCol;v<=o.endCol;v++)d.push(b.cells[M(c,v)]??null);n.push(d);}return n},getCellAt:(o,n)=>b.cells[M(o,n)]??null,copySelection:async()=>{let o=S.getSelection();if(o){let n=await F.copyToClipboard(o);D?.(n);}},setColumnWidth:(o,n)=>{g.setColWidth(o,n),te(c=>c+1);},autoFitColumn:()=>{},autoFitAllColumns:()=>{},refresh:()=>te(o=>o+1),destroy:()=>{U.destroy();}}),[g,C,S,I,F,oe,ne,V,R,r,b,W,U,D]);let H=m?24:0,E=m?40:0,z=g.getVisibleRange(W.top,W.left,C.height,C.width),Ne=[];for(let o=z.startRow;o<=z.endRow;o++)for(let n=z.startCol;n<=z.endCol;n++){if(re.isMergeHidden(o,n))continue;let c=re.getMergeRect(o,n,(x,st)=>g.getCellRect(x,st))??g.getCellRect(o,n),d=M(o,n),v=b.cells[d],qe=S.isCellSelected(o,n),Ie=S.isAnchor(o,n),et=q.some(x=>x.row===o&&x.col===n),tt=I.isCurrent(o,n),rt=Ke(v?.style,v?.s,r),Be=Ee(rt),ot=$e(Be),nt=re.isMergeMaster(o,n),N="nup-cell";v?.t==="n"&&(N+=" nup-cell-number"),qe&&(N+=" nup-cell-selected"),Ie&&(N+=" nup-cell-anchor"),et&&(N+=" nup-cell-search-result"),tt&&(N+=" nup-cell-search-current"),ot&&(N+=" nup-has-border"),nt&&(N+=" nup-cell-merge-master"),Ne.push(jsx("div",{className:N,style:{top:c.top,left:c.left,width:c.width,height:c.height,...Be},onClick:x=>Ge(o,n,x),onDoubleClick:x=>Ze(o,n,x),onContextMenu:x=>Qe(o,n,x),"data-row":o,"data-col":n,"data-cell-ref":d,role:"gridcell","aria-rowindex":o+1,"aria-colindex":n+1,tabIndex:Ie?0:-1,children:v?.v!==void 0&&v?.v!==null?String(v.v):""},`${o}-${n}`));}let Pe=[];if(m)for(let o=z.startCol;o<=z.endCol;o++){let n=g.getCellRect(0,o),c=R&&o>=R.start.col&&o<=R.end.col;Pe.push(jsxs("div",{className:`nup-header nup-header-col${c?" nup-header-selected":""}`,style:{left:n.left,width:n.width,height:H},children:[se(o),$&&jsx("div",{className:"nup-resize-handle",onMouseDown:d=>_e(o,d)})]},`ch-${o}`));}let Te=[];if(m)for(let o=z.startRow;o<=z.endRow;o++){let n=g.getCellRect(o,0),c=R&&o>=R.start.row&&o<=R.end.row;Te.push(jsx("div",{className:`nup-header nup-header-row${c?" nup-header-selected":""}`,style:{top:n.top,width:E,height:n.height},children:o+1},`rh-${o}`));}let We=null;if(R){let o=g.getCellRect(R.start.row,R.start.col),n=g.getCellRect(R.end.row,R.end.col);We=jsx("div",{className:"nup-selection-border",style:{top:o.top,left:o.left,width:n.left+n.width-o.left,height:n.top+n.height-o.top}});}let Je=typeof s=="string"?He(s):"";return jsxs("div",{ref:J,className:`nup-spreadsheet ${Je} ${h} ${p?"":"nup-no-gridlines"}`,style:{width:l,height:u,...f},tabIndex:0,onKeyDown:Ye,role:"grid","aria-label":Fe,"aria-rowcount":b.rowCount,"aria-colcount":b.colCount,children:[Ve&&jsxs("div",{className:"nup-search-bar",children:[jsx("input",{type:"search",className:"nup-search-input",placeholder:"Search...",value:je,onChange:o=>ne(o.target.value),"aria-label":"Search in spreadsheet"}),q.length>0&&jsxs("span",{className:"nup-search-count",children:[I.getCurrentIndex()," of ",q.length]}),jsx("button",{className:"nup-search-btn",onClick:()=>{let o=I.next();if(o){let n=g.getScrollToPosition(o.row,o.col,C.height,C.width);A.current?.scrollTo({top:n.scrollTop,left:n.scrollLeft,behavior:"smooth"});}},"aria-label":"Next result",children:"Next"})]}),m&&jsx("div",{className:"nup-corner",style:{width:E,height:H}}),m&&jsx("div",{className:"nup-header-row-container",style:{position:"absolute",top:0,left:E,right:0,height:H,overflow:"hidden"},children:jsx("div",{style:{position:"relative",width:g.totalWidth,height:H,transform:`translateX(${-W.left}px)`},children:Pe})}),m&&jsx("div",{className:"nup-header-col-container",style:{position:"absolute",top:H,left:0,bottom:w?32:0,width:E,overflow:"hidden"},children:jsx("div",{style:{position:"relative",width:E,height:g.totalHeight,transform:`translateY(${-W.top}px)`},children:Te})}),jsx("div",{ref:A,className:"nup-scroll-container",style:{top:H,left:E,right:0,bottom:w?32:0},onScroll:Xe,children:jsxs("div",{className:"nup-content",style:{width:g.totalWidth,height:g.totalHeight},children:[Ne,We]})}),w&&r.sheets.length>1&&jsx("div",{className:"nup-sheet-tabs",children:r.sheets.map((o,n)=>jsx("button",{className:`nup-sheet-tab${n===V?" nup-sheet-tab-active":""}`,onClick:()=>oe(n),children:o.name},o.id))})]})}),$t=ft;export{ft as NupSpreadsheetPreview,$t as default};//# sourceMappingURL=react.js.map
10
10
  //# sourceMappingURL=react.js.map