@betteroffice/xlsx-react 0.0.8 → 0.1.0

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +10 -3
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect}from'react';import {isPngExportAvailable,isProposalsAvailable,initWasm,openWorkbook,selectionAt,paintDisplayList,normalizeRange,buildA11yGrid,cellAtPoint,moveFocus,toTsv,fromTsv,StaleProposalError,selectionKeyReducer,extendTo,hyperlinkAtCell,safeExternalHyperlink,parseHyperlinkLocation,rangeRect,cellRect}from'@betteroffice/xlsx';import {en,deepMerge,createT}from'@betteroffice/xlsx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {normalizeAwarenessColor,resolveAwarenessCursor,AWARENESS_LABEL_DURATION_MS}from'@betteroffice/xlsx/collaboration';var ao=createContext(en),io=createContext("en");function at({i18n:t,children:o}){let a=typeof t?._lang=="string"?t._lang:"en",c=useMemo(()=>deepMerge(en,t),[t]);return jsx(io.Provider,{value:a,children:jsx(ao.Provider,{value:c,children:o})})}function Se(){let t=useContext(ao),o=useContext(io);return {t:useMemo(()=>createT(t,o),[t,o])}}var Fe=createContext(null);function ir(){let t=useContext(Fe);if(!t)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return t}function L({name:t,size:o=20,style:a}){return jsxs("svg",{width:o,height:o,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...a},children:[t==="search"&&jsxs(Fragment,{children:[jsx("circle",{cx:"10.5",cy:"10.5",r:"6"}),jsx("path",{d:"m15 15 4.5 4.5"})]}),t==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),t==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),t==="print"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 9V4h10v5M7 18H5a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),jsx("path",{d:"M7 14h10v6H7z"}),jsx("path",{d:"M17.5 12h.01"})]}),t==="formatPaint"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 4h11v5H5zM8 9v3h5V9"}),jsx("path",{d:"M10.5 12v8"})]}),t==="decimalDecrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1M14 7h1M18 7h1"}),jsx("path",{d:"M5 16h1M9 16h1"}),jsx("path",{d:"m15 12-4 4 4 4M11 16h8"})]}),t==="decimalIncrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1"}),jsx("path",{d:"M5 16h1M9 16h1M14 16h1M18 16h1"}),jsx("path",{d:"m15 3 4 4-4 4M19 7h-8"})]}),t==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),t==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),t==="strikethrough"&&jsx(Fragment,{children:jsx("path",{d:"M5 12h14M8 7.5A4.5 4.5 0 0 1 12.5 4c2.2 0 3.7 1 4.5 2.5M8 16.5c.8 2.1 2.4 3.5 5 3.5 2.8 0 4.5-1.4 4.5-3.5 0-2.3-2-3.3-5.5-4.5"})}),t==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),t==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-6 6-7-7zM5 12h12"}),jsx("path",{d:"M18 17c0-1 1-2 1-2s1 1 1 2a1 1 0 0 1-2 0Z"})]}),t==="borders"&&jsx(Fragment,{children:jsx("path",{d:"M4 4h16v16H4zM12 4v16M4 12h16"})}),t==="merge"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 5h16v14H4z"}),jsx("path",{d:"m8 9 3 3-3 3M16 9l-3 3 3 3"})]}),t==="alignLeft"&&jsx("path",{d:"M4 6h16M4 10h11M4 14h16M4 18h11"}),t==="verticalAlignCenter"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 4h16M4 20h16M8 12h8"}),jsx("path",{d:"m10 9 2 3 2-3M10 15l2-3 2 3"})]}),t==="wrap"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 6h16M4 11h12a3 3 0 0 1 0 6h-3"}),jsx("path",{d:"m15 14-3 3 3 3M4 17h5"})]}),t==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),t==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),t==="remove"&&jsx("path",{d:"M5 12h14"}),t==="add"&&jsx("path",{d:"M12 5v14M5 12h14"}),t==="check"&&jsx("path",{d:"m5 12 4 4L19 6"}),t==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),t==="image"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),jsx("circle",{cx:"8.5",cy:"9.5",r:"1.25"}),jsx("path",{d:"m6 17 4.5-4.5 3.25 3.25L16 13.5l2 2"})]}),t==="proposals"&&jsxs(Fragment,{children:[jsx("path",{d:"m12 3 1.25 3.75L17 8l-3.75 1.25L12 13l-1.25-3.75L7 8l3.75-1.25L12 3Z"}),jsx("path",{d:"m18 14 .75 2.25L21 17l-2.25.75L18 20l-.75-2.25L15 17l2.25-.75L18 14Z"})]})]})}var I={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},cr={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:I.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function uo(t,o,a,c){return {...cr,background:o?I.active:a&&!t?I.hover:"transparent",color:t?I.disabled:I.text,cursor:t?"default":"pointer",opacity:t?.48:1,...c}}function U({active:t=false,disabled:o=false,title:a,onClick:c,children:u,style:p,testId:s,ariaExpanded:w}){let[M,S]=useState(false);return jsx("button",{type:"button","data-testid":s,disabled:o,"aria-label":a,"aria-pressed":t||void 0,"aria-expanded":w,title:a,onMouseDown:z=>z.preventDefault(),onMouseEnter:()=>S(true),onMouseLeave:()=>S(false),onClick:o?void 0:c,style:uo(o,t,M,p),children:u})}function Y({label:t,children:o,style:a}){return jsx("div",{role:"group","aria-label":t,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...a},children:o})}function Ge(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:I.border,flex:"0 0 auto"}})}function fe({title:t,trigger:o,children:a,disabled:c=false,active:u=false,menuWidth:p=220,style:s,testId:w}){let[M,S]=useState(false),[z,F]=useState(false),[K,_]=useState({top:0,left:0}),$=useRef(null),v=useRef(null),H=useCallback(()=>S(false),[]);return useEffect(()=>{if(!M||!$.current)return;let A=$.current.getBoundingClientRect(),Q=Math.min(A.left,Math.max(8,window.innerWidth-p-8));_({top:A.bottom+4,left:Q});},[M,p]),useEffect(()=>{if(!M)return;let A=Z=>{let oe=Z.target;!$.current?.contains(oe)&&!v.current?.contains(oe)&&H();},Q=Z=>{Z.key==="Escape"&&H();},C=()=>H();return document.addEventListener("mousedown",A),document.addEventListener("keydown",Q),window.addEventListener("scroll",C,true),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",Q),window.removeEventListener("scroll",C,true);}},[M,H]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:$,type:"button","data-testid":w,disabled:c,"aria-label":t,"aria-haspopup":"menu","aria-expanded":M,title:t,onMouseDown:A=>A.preventDefault(),onMouseEnter:()=>F(true),onMouseLeave:()=>F(false),onClick:()=>!c&&S(A=>!A),style:uo(c,u||M,z,s),children:o}),M&&jsx("div",{ref:v,role:"menu","aria-label":t,onMouseDown:A=>A.preventDefault(),style:{position:"fixed",top:K.top,left:K.left,zIndex:1e4,width:p,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${I.border}`,borderRadius:8,background:I.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:a(H)})]})}function le({label:t,icon:o,selected:a=false,disabled:c=false,onClick:u,close:p}){let[s,w]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:c,"aria-label":t,onMouseEnter:()=>w(true),onMouseLeave:()=>w(false),onClick:()=>{c||(u?.(),p?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:s&&!c?I.hover:"transparent",color:c?I.disabled:I.text,cursor:c?"default":"pointer",opacity:c?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:o}),jsx("span",{style:{flex:1},children:t}),a&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function _e(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:I.border}})}function Tt({mode:t,value:o,label:a,onChange:c,disabled:u=false}){let[p,s]=useState(false);return jsxs("label",{title:a,"aria-label":a,style:{position:"relative",display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:p&&!u?I.hover:"transparent",color:u?I.disabled:I.text,cursor:u?"default":"pointer",opacity:u?.48:1,boxSizing:"border-box"},onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),children:[jsx(L,{name:t==="text"?"textColor":"fillColor",size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:o}}),jsx("input",{type:"color",value:o,disabled:u,"aria-label":a,onChange:w=>c?.(w.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})}function Pt({value:t,options:o,label:a,onCommit:c,disabled:u=false,width:p=72,inputStyle:s,testId:w}){let[M,S]=useState(t),[z,F]=useState(false),[K,_]=useState({top:0,left:0,width:p}),$=useRef(null),v=useRef(null),H=useRef(null);useEffect(()=>S(t),[t]);let A=useCallback(()=>F(false),[]);useEffect(()=>{if(!z||!$.current)return;let C=$.current.getBoundingClientRect();_({top:C.bottom+4,left:C.left,width:Math.max(C.width,p)});},[z,p]),useEffect(()=>{if(!z)return;let C=oe=>{let de=oe.target;!$.current?.contains(de)&&!v.current?.contains(de)&&A();},Z=oe=>{oe.key==="Escape"&&(S(t),A());};return document.addEventListener("mousedown",C),document.addEventListener("keydown",Z),()=>{document.removeEventListener("mousedown",C),document.removeEventListener("keydown",Z);}},[z,A,t]);let Q=useCallback(()=>{!u&&c&&M.trim()&&c(M.trim()),S(t);},[u,c,M,t]);return jsxs("div",{ref:$,style:{display:"inline-flex",alignItems:"center",width:p,height:28,border:`1px solid ${I.border}`,borderRadius:4,background:u?"rgba(255,255,255,0.5)":I.surface,opacity:u?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:H,"data-testid":w,role:"combobox","aria-label":a,"aria-autocomplete":"list","aria-expanded":z,disabled:u,value:M,onFocus:C=>{u||(F(true),C.currentTarget.select());},onChange:C=>S(C.target.value),onKeyDown:C=>{C.key==="Enter"?(Q(),A(),C.currentTarget.blur()):C.key==="ArrowDown"&&(F(true),C.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{v.current?.contains(document.activeElement)||Q();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:I.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...s}}),jsx("button",{type:"button",disabled:u,tabIndex:-1,"aria-label":a,title:a,onMouseDown:C=>C.preventDefault(),onClick:()=>{u||(F(C=>!C),H.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:I.muted,cursor:u?"default":"pointer"},children:jsx(L,{name:"chevronDown",size:14})}),z&&!u&&jsx("div",{ref:v,role:"listbox","aria-label":a,style:{position:"fixed",top:K.top,left:K.left,zIndex:1e4,width:K.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${I.border}`,borderRadius:6,background:I.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:o.map(C=>jsx("button",{type:"button",role:"option","aria-selected":C.value===t,onMouseDown:Z=>Z.preventDefault(),onClick:()=>{S(C.label),c?.(C.value),A();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:C.value===t?I.active:"transparent",color:I.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:C.label},C.value))})]})}var gr=[.5,.75,.9,1,1.25,1.5,2],yr=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],xr=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],vr=["automatic","plainText","number","percent","scientific","currency","date","time","custom"],wr=["all","inner","horizontal","vertical","outer","left","top","right","bottom","none"],Sr=["solid","dashed","dotted","double"],Cr=["left","center","right"],kr=["top","middle","bottom"],Tr=["overflow","wrap","clip"];function Mr(t){let o={};for(let a of Object.keys(t))t[a]!==void 0&&(o[a]=t[a]);return o}function Rr(t){let o=useContext(Fe);return o?{...o,...Mr(t)}:t}function mo({preset:t}){let o=a=>t===a||t==="all"||t==="outer"?2:.6;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[t!=="none"&&jsxs(Fragment,{children:[jsx("path",{d:"M3 3h14",strokeWidth:o("top")}),jsx("path",{d:"M17 3v14",strokeWidth:o("right")}),jsx("path",{d:"M3 17h14",strokeWidth:o("bottom")}),jsx("path",{d:"M3 3v14",strokeWidth:o("left")}),(t==="all"||t==="inner"||t==="horizontal")&&jsx("path",{d:"M3 10h14",strokeWidth:"1.5"}),(t==="all"||t==="inner"||t==="vertical")&&jsx("path",{d:"M10 3v14",strokeWidth:"1.5"})]}),t==="none"&&jsx("path",{d:"M4 4h12v12H4zM3 17 17 3",strokeWidth:"1.5"})]})}function ho({value:t}){let o=t==="left"?3:t==="center"?5:7,a=t==="left"?15:t==="center"?17:19;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 4h14M3 10h14M3 16h14"}),jsx("path",{d:`M${o} 7h${a-o}M${o} 13h${a-o}`})]})}function go({value:t}){return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 3h14M3 17h14"}),jsx("path",{d:`M6 ${t==="top"?5:t==="middle"?10:15}h8`}),jsx("path",{d:t==="top"?"m8 8 2-3 2 3":t==="bottom"?"m8 12 2 3 2-3":"m8 7 2 3 2-3m-4 6 2-3 2 3"})]})}function Er({value:t}){return jsx("svg",{width:"44",height:"12",viewBox:"0 0 44 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:t==="double"?jsx(Fragment,{children:jsx("path",{d:"M2 4h40M2 8h40"})}):jsx("path",{d:"M2 6h40",strokeWidth:"2",strokeDasharray:t==="dashed"?"7 4":t==="dotted"?"1 4":void 0})})}function yo(t,o,a){return a>0?o.find(c=>c>t)??t+1:[...o].reverse().find(c=>c<t)??Math.max(1,t-1)}function it(t){let{t:o}=Se(),{currentFormatting:a={},selectionShape:c,onFormat:u,onMerge:p,onSearchMenus:s,onUndo:w,onRedo:M,canUndo:S=false,canRedo:z=false,onPrint:F,zoom:K=1,onZoomChange:_,fontFamilies:$=yr,fontSizes:v=xr,disabled:H=false,className:A,style:Q,children:C}=Rr(t),Z=useRef(null),[oe,de]=useState(Number.POSITIVE_INFINITY),E=!H&&!!u,y=!H&&!!p,re=a.fontSize??10,Ee=(c?.rows??1)>1,B=(c?.columns??1)>1,xe=Ee||B;useEffect(()=>{let h=Z.current;if(!h)return;let m=()=>de(h.clientWidth);m();let ne=new ResizeObserver(m);return ne.observe(h),()=>ne.disconnect()},[]);let pt=useMemo(()=>gr.map(h=>({value:`${h*100}%`,label:`${h*100}%`})),[]),b=useMemo(()=>v.map(h=>({value:String(h),label:String(h)})),[v]),k=h=>{E&&u?.(h);},O=h=>jsx(Fragment,{children:vr.map(m=>jsx(le,{label:o(`toolbar.numberFormats.${m}`),selected:a.numberFormat===m,disabled:!E,onClick:()=>k({type:"numberFormat",value:m}),close:h},m))}),me=h=>jsxs(Fragment,{children:[wr.map(m=>jsx(le,{icon:jsx(mo,{preset:m}),label:o(`toolbar.borderPresets.${m}`),selected:a.borderPreset===m,disabled:!E,onClick:()=>k({type:"borderPreset",value:m}),close:h},m)),jsx(_e,{}),Sr.map(m=>jsx(le,{icon:jsx(Er,{value:m}),label:o(`toolbar.borderStyles.${m}`),selected:a.borderStyle===m,disabled:!E,onClick:()=>k({type:"borderStyle",value:m}),close:h},m)),jsx(_e,{}),jsxs("label",{style:{position:"relative",display:"flex",alignItems:"center",gap:10,minHeight:32,padding:"5px 9px",color:I.text,font:"400 13px ui-sans-serif, system-ui, sans-serif",cursor:E?"pointer":"default"},children:[jsx("span",{style:{width:20,height:5,borderRadius:2,background:a.borderColor??"#000000"}}),jsx("span",{children:o("toolbar.borderColor")}),jsx("input",{type:"color",value:a.borderColor??"#000000",disabled:!E,"aria-label":o("toolbar.borderColor"),onChange:m=>k({type:"borderColor",value:m.target.value}),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})]}),Ye=h=>jsxs(Fragment,{children:[jsx(le,{label:o("toolbar.merge.all"),disabled:!y||!xe,onClick:()=>p?.("all"),close:h}),jsx(le,{label:o("toolbar.merge.horizontal"),disabled:!y||!B,onClick:()=>p?.("horizontal"),close:h}),jsx(le,{label:o("toolbar.merge.vertical"),disabled:!y||!Ee,onClick:()=>p?.("vertical"),close:h}),jsx(_e,{}),jsx(le,{label:o("toolbar.merge.unmerge"),disabled:!y||!c?.canUnmerge,onClick:()=>p?.("unmerge"),close:h})]}),He=h=>jsx(Fragment,{children:Cr.map(m=>jsx(le,{icon:jsx(ho,{value:m}),label:o(`toolbar.horizontalAlign.${m}`),selected:a.horizontalAlignment===m,disabled:!E,onClick:()=>k({type:"horizontalAlignment",value:m}),close:h},m))}),Pe=h=>jsx(Fragment,{children:kr.map(m=>jsx(le,{icon:jsx(go,{value:m}),label:o(`toolbar.verticalAlign.${m}`),selected:a.verticalAlignment===m,disabled:!E,onClick:()=>k({type:"verticalAlignment",value:m}),close:h},m))}),ve=h=>jsx(Fragment,{children:Tr.map(m=>jsx(le,{label:o(`toolbar.wrapping.${m}`),selected:a.textWrapping===m,disabled:!E,onClick:()=>k({type:"textWrapping",value:m}),close:h},m))}),he=[{key:"search",width:29,node:jsx(Y,{label:o("toolbar.groups.search"),children:jsx(U,{title:o("toolbar.searchMenus"),onClick:s,testId:"xlsx-search-menus",children:jsx(L,{name:"search"})})})},{key:"history",width:58,node:jsxs(Y,{label:o("toolbar.groups.history"),children:[jsx(U,{title:o("toolbar.undo"),disabled:H||!S||!w,onClick:w,testId:"xlsx-undo",children:jsx(L,{name:"undo"})}),jsx(U,{title:o("toolbar.redo"),disabled:H||!z||!M,onClick:M,testId:"xlsx-redo",children:jsx(L,{name:"redo"})})]})},{key:"print",width:29,node:jsx(Y,{label:o("toolbar.groups.print"),children:jsx(U,{title:o("toolbar.print"),disabled:H||!F,onClick:F,children:jsx(L,{name:"print"})})})},{key:"paint",width:29,node:jsx(Y,{label:o("toolbar.groups.paintFormat"),children:jsx(U,{title:o("toolbar.paintFormat"),active:a.paintFormat,disabled:!E,onClick:()=>k("paintFormat"),children:jsx(L,{name:"formatPaint"})})})},{key:"zoom",width:82,node:jsx(Y,{label:o("toolbar.groups.zoom"),children:jsx(Pt,{value:`${Math.round(K*100)}%`,options:pt,label:o("toolbar.zoomValue",{value:`${Math.round(K*100)}%`}),disabled:H||!_,onCommit:h=>{let m=Number.parseFloat(h.replace("%",""));Number.isFinite(m)&&m>=25&&m<=400&&_?.(m/100);},width:76,testId:"xlsx-zoom"})})},{key:"number",width:202,node:jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Y,{label:o("toolbar.groups.number"),children:[jsx(U,{title:o("toolbar.currency"),disabled:!E,onClick:()=>k("currency"),children:jsx("span",{style:{fontSize:16},children:o("toolbar.currencySymbol")})}),jsx(U,{title:o("toolbar.percent"),disabled:!E,onClick:()=>k("percent"),children:jsx("span",{style:{fontSize:15},children:"%"})}),jsx(U,{title:o("toolbar.decreaseDecimal"),disabled:!E,onClick:()=>k("decreaseDecimal"),children:jsx(L,{name:"decimalDecrease"})}),jsx(U,{title:o("toolbar.increaseDecimal"),disabled:!E,onClick:()=>k("increaseDecimal"),children:jsx(L,{name:"decimalIncrease"})}),jsx(fe,{title:o("toolbar.moreNumberFormats"),disabled:!E,trigger:jsxs(Fragment,{children:[jsx("span",{children:"123"}),jsx(L,{name:"chevronDown",size:13})]}),children:O})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(Ge,{}),jsx(Y,{label:o("toolbar.groups.font"),children:jsx(fe,{title:o("toolbar.fontFamily"),disabled:!E,menuWidth:210,style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:a.fontFamily??"Calibri"}),jsx(L,{name:"chevronDown",size:13})]}),children:h=>jsx(Fragment,{children:$.map(m=>jsx(le,{label:m,selected:a.fontFamily===m,disabled:!E,onClick:()=>k({type:"fontFamily",value:m}),close:h},m))})})})]})},{key:"font-size",width:116,node:jsxs(Y,{label:o("toolbar.groups.font"),children:[jsx(U,{title:o("toolbar.decreaseFontSize"),disabled:!E,onClick:()=>k({type:"fontSize",value:yo(re,v,-1)}),children:jsx(L,{name:"remove"})}),jsx(Pt,{value:String(re),options:b,label:o("toolbar.fontSize"),disabled:!E,onCommit:h=>{let m=Number.parseFloat(h);Number.isFinite(m)&&m>=1&&m<=400&&k({type:"fontSize",value:m});},width:50,inputStyle:{textAlign:"center"}}),jsx(U,{title:o("toolbar.increaseFontSize"),disabled:!E,onClick:()=>k({type:"fontSize",value:yo(re,v,1)}),children:jsx(L,{name:"add"})})]})},{key:"text",width:98,node:jsxs(Fragment,{children:[jsx(Ge,{}),jsxs(Y,{label:o("toolbar.groups.text"),children:[jsx(U,{title:o("toolbar.bold"),active:a.bold,disabled:!E,onClick:()=>k("bold"),children:jsx(L,{name:"bold"})}),jsx(U,{title:o("toolbar.italic"),active:a.italic,disabled:!E,onClick:()=>k("italic"),children:jsx(L,{name:"italic"})}),jsx(U,{title:o("toolbar.strikethrough"),active:a.strikethrough,disabled:!E,onClick:()=>k("strikethrough"),children:jsx(L,{name:"strikethrough"})})]})]})},{key:"colors",width:58,node:jsxs(Y,{label:o("toolbar.groups.colors"),children:[jsx(Tt,{mode:"text",value:a.textColor??"#000000",label:o("toolbar.textColor"),disabled:!E,onChange:h=>k({type:"textColor",value:h})}),jsx(Tt,{mode:"fill",value:a.fillColor??"#ffffff",label:o("toolbar.fillColor"),disabled:!E,onChange:h=>k({type:"fillColor",value:h})})]})},{key:"borders",width:36,node:jsx(Y,{label:o("toolbar.groups.borders"),children:jsx(fe,{title:o("toolbar.borders"),disabled:!E,menuWidth:240,trigger:jsxs(Fragment,{children:[jsx(mo,{preset:a.borderPreset??"all"}),jsx(L,{name:"chevronDown",size:12})]}),children:me})})},{key:"merge",width:58,node:jsxs(Y,{label:o("toolbar.groups.merge"),children:[jsx(U,{title:o("toolbar.merge.all"),disabled:!y||!xe,onClick:()=>p?.("all"),style:{borderRadius:"4px 0 0 4px"},testId:"xlsx-merge-all",children:jsx(L,{name:"merge"})}),jsx(fe,{title:o("toolbar.mergeCells"),disabled:!y||!xe&&!c?.canUnmerge,menuWidth:220,style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(L,{name:"chevronDown",size:13}),children:Ye})]})},{key:"alignment",width:118,node:jsxs(Y,{label:o("toolbar.groups.alignment"),children:[jsx(fe,{title:o("toolbar.horizontalAlignment"),disabled:!E,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(ho,{value:a.horizontalAlignment??"left"}),jsx(L,{name:"chevronDown",size:12})]}),children:He}),jsx(fe,{title:o("toolbar.verticalAlignment"),disabled:!E,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(go,{value:a.verticalAlignment??"middle"}),jsx(L,{name:"chevronDown",size:12})]}),children:Pe}),jsx(fe,{title:o("toolbar.textWrapping"),disabled:!E,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(L,{name:"wrap"}),jsx(L,{name:"chevronDown",size:12})]}),children:ve})]})}];C&&he.push({key:"custom",width:40,node:C});let ft=Math.max(0,oe-48),R=0,Be=he.length;for(let h=0;h<he.length;h++)if(R+=he[h].width,R>ft){Be=h;break}let Le=he.slice(0,Be),Ae=he.slice(Be);return jsxs("div",{ref:Z,className:A,role:"toolbar","aria-label":o("toolbar.actionsLabel"),"data-testid":"xlsx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:I.rail,color:I.text,overflow:"hidden",boxSizing:"border-box",...Q},children:[Le.map(h=>jsx("span",{style:{display:"contents"},children:h.node},h.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(fe,{title:o("toolbar.more"),disabled:Ae.length===0,menuWidth:390,testId:"xlsx-toolbar-more",trigger:jsx(L,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:Ae.map(h=>jsx("span",{style:{display:"contents"},children:h.node},h.key))})})})]})}function Pr({children:t,className:o,style:a,...c}){return jsx(Fe.Provider,{value:c,children:jsx("div",{className:o,"data-testid":"xlsx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...a},children:t})})}var Ke=Pr;Ke.Toolbar=it;var Fr=8,Hr=32;function Br(t){let o=t.trim().split(/\s+/).filter(Boolean);return o.length===0?"?":o.slice(0,2).map(a=>a[0]).join("").toUpperCase()}function Nr(t){let o=Number.parseInt(t.slice(1,3),16),a=Number.parseInt(t.slice(3,5),16),c=Number.parseInt(t.slice(5,7),16);return `rgba(${o}, ${a}, ${c}, 0.1)`}function Wr(t,o){return t.left<=o.right&&t.right>=o.left&&t.top<=o.bottom&&t.bottom>=o.top}function ct(t,o){let a={...t},c=true;for(;c;){c=false;for(let u of o){let p={top:Math.min(u.start.row,u.end.row),left:Math.min(u.start.col,u.end.col),bottom:Math.max(u.start.row,u.end.row),right:Math.max(u.start.col,u.end.col)};if(!Wr(a,p))continue;let s=Math.min(a.top,p.top),w=Math.min(a.left,p.left),M=Math.max(a.bottom,p.bottom),S=Math.max(a.right,p.right);s===a.top&&w===a.left&&M===a.bottom&&S===a.right||(Object.assign(a,{top:s,left:w,bottom:M,right:S}),c=true);}}return a}function $r(t){let[o,a]=useState(()=>Date.now());return useEffect(()=>{let c=Date.now();a(c);let u=t.map(w=>w.cursorMovedAt+AWARENESS_LABEL_DURATION_MS).filter(w=>w>c);if(u.length===0)return;let p=setTimeout(()=>a(Date.now()),Math.min(...u)-c+1);return p.unref?.(),()=>clearTimeout(p)},[t]),o}function So({peers:t,sheetIds:o,sheetNames:a,activeSheet:c}){if(t.length===0)return null;let u=t.slice(0,Fr),p=t.length-u.length;return jsxs("div",{"data-testid":"xlsx-presence-strip","aria-label":"Collaborators",style:{display:"flex",alignItems:"center",gap:4,padding:"0 6px",flex:"0 0 auto"},children:[u.map(s=>{let w=s.cursor?o.indexOf(s.cursor.sheet):c,M=s.cursor!==null&&w!==c,S=normalizeAwarenessColor(s.user.color,s.clientId),z=w>=0?a[w]:s.cursor?"Unavailable sheet":void 0,F=M||w<0?`${s.user.name} \u2014 ${z}`:s.user.name;return jsx("span",{"data-testid":`xlsx-presence-chip-${s.clientId}`,title:F,"aria-label":F,style:{display:"inline-grid",placeItems:"center",width:24,height:24,borderRadius:"50%",backgroundColor:S,color:"#ffffff",boxShadow:"0 0 0 2px #ffffff",fontSize:9,fontWeight:700,lineHeight:1,letterSpacing:"-0.02em",opacity:M||w<0?.42:1,transition:"opacity 120ms ease"},children:Br(s.user.name)},s.clientId)}),p>0&&jsxs("span",{"data-testid":"xlsx-presence-overflow",title:`${p} more collaborators`,"aria-label":`${p} more collaborators`,style:{display:"inline-grid",placeItems:"center",minWidth:24,height:24,padding:"0 4px",borderRadius:12,backgroundColor:"#5f6368",color:"#ffffff",fontSize:9,fontWeight:700,lineHeight:1},children:["+",p]})]})}function Co({peers:t,grid:o,sheetIds:a,activeSheet:c,zoom:u,mergedRanges:p}){let s=useMemo(()=>t.slice(0,Hr),[t]),w=t.length-s.length,M=$r(s);return o?jsxs(Fragment,{children:[s.map(S=>{if(!S.cursor)return null;let z=resolveAwarenessCursor(S.cursor,a);if(!z||z.sheetIndex!==c)return null;let F=ct(z.range,p),K=rangeRect(o,F);if(!K)return null;let _=normalizeAwarenessColor(S.user.color,S.clientId),$={x:K.x*u,y:K.y*u,w:K.w*u,h:K.h*u},v=z.range.top!==z.range.bottom||z.range.left!==z.range.right,H=F.left<o.startCol,A=F.top<o.startRow||$.y<18,Q=S.cursorMovedAt>0&&M-S.cursorMovedAt<AWARENESS_LABEL_DURATION_MS;return jsx("div",{"data-testid":`xlsx-remote-selection-${S.clientId}`,style:{position:"absolute",left:$.x,top:$.y,width:$.w,height:$.h,boxSizing:"border-box",borderWidth:2,borderStyle:"solid",borderColor:_,backgroundColor:v?Nr(_):"transparent"},children:Q&&jsx("span",{"data-testid":`xlsx-remote-label-${S.clientId}`,style:{position:"absolute",top:A?0:-18,...H?{right:-2}:{left:-2},maxWidth:180,height:18,padding:"2px 6px",borderRadius:A?"0 0 3px 3px":"3px 3px 0 0",boxSizing:"border-box",overflow:"hidden",backgroundColor:_,color:"#ffffff",fontSize:10,fontWeight:600,lineHeight:"14px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:S.user.name})},S.clientId)}),w>0&&jsxs("span",{"data-testid":"xlsx-remote-selection-overflow","aria-hidden":"true",style:{position:"absolute",left:4,top:4,padding:"2px 5px",borderWidth:1,borderStyle:"solid",borderColor:"#c7cacf",borderRadius:8,backgroundColor:"#ffffff",color:"#3c4043",fontSize:9,lineHeight:1},children:["+",w]})]}):null}var ko=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function Ur(t){let o=2166136261;for(let a=0;a<t.length;a++)o^=t.charCodeAt(a),o=Math.imul(o,16777619);return (o>>>0)%ko.length}function To(t){return ko[Ur(t)]}function Mo({proposals:t,staleFor:o,onAccept:a,onReject:c,style:u}){let{t:p}=Se();return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":p("proposals.panelLabel"),style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:10,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left",...u},children:t.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:p("proposals.empty")}):t.map(s=>{let w=To(s.agentId),M=o[s.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":s.id,style:{borderLeft:`3px solid ${w}`,padding:"8px 10px",marginBottom:8,background:"#fafafa",borderRadius:4},children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[jsx("strong",{style:{color:w},children:s.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:p("proposals.cellCount",{count:s.cells.length})})]}),s.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:s.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:s.cells.map(S=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:S.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:S.oldText||"\u2205"})," ",p("proposals.changeArrow")," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:w},children:S.newText})]},S.a1))}),M&&M.length>0&&jsx("div",{"data-testid":"xlsx-proposal-stale",role:"alert",style:{color:"#b45309",background:"#fef3c7",borderRadius:4,padding:"4px 6px",margin:"4px 0",fontSize:12},children:p("proposals.staleWarning",{cells:M.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>a(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:p("proposals.accept")}),M&&M.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>a(s.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:p("proposals.forceApply")}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>c(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:p("proposals.reject")})]})]},s.id)})})}var Ce=96,ke=24,ut="#217346",Io=87,rn=1024,nn="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";function ln(t,o,a){let c=[{op:"fillRect",x:0,y:0,w:t,h:o,color:"#ffffff"}],u=Math.ceil(t/Ce),p=Math.ceil(o/ke);for(let s=0;s<=u;s++)c.push({op:"line",x1:s*Ce,y1:0,x2:s*Ce,y2:o,width:1,color:"#e0e0e0"});for(let s=0;s<=p;s++)c.push({op:"line",x1:0,y1:s*ke,x2:t,y2:s*ke,width:1,color:"#e0e0e0"});return c.push({op:"fillRect",x:0,y:0,w:t,h:ke,color:"#f3f3f3"}),c.push({op:"fillRect",x:0,y:0,w:Ce,h:o,color:"#f3f3f3"}),c.push({op:"text",x:Ce+8,y:ke+18,text:a,fontSize:14,color:"#202020",clip:{x:Ce,y:ke,w:Ce*3,h:ke},align:"left"}),{width:t,height:o,commands:c}}function Lo(t,o){if(!t||t.length<2)return o;let a=[];for(let u=1;u<t.length;u++)a.push(t[u]-t[u-1]);a.sort((u,p)=>u-p);let c=a[a.length>>1];return c>0?c:o}function an(t,o,a){let c=Lo(t?.grid?.rowOffsets,ke),u=Lo(t?.grid?.colOffsets,Ce),p=Math.max(1,Math.round(o.contentHeight/c))+1,s=Math.max(1,Math.round(o.contentWidth/u))+1,w=Math.max(1,Math.floor(a/c));return {rows:p,cols:s,rowsPerPage:w}}function Ao(t,o,a){let c=new Blob([new Uint8Array(t)],{type:a}),u=URL.createObjectURL(c),p=document.createElement("a");p.href=u,p.download=o,document.body.appendChild(p),p.click(),p.remove(),URL.revokeObjectURL(u);}function sn(t){return `${(t??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}function Dt(t,o){return {x:t.x*o,y:t.y*o,w:t.w*o,h:t.h*o}}var cn={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},ye={shell:{flex:"0 0 auto",minHeight:Io,padding:"4px 0 5px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",color:"#0f172a",boxSizing:"border-box"},rail:{display:"flex",alignItems:"center",minHeight:32,margin:"0 8px",padding:"2px 8px",borderRadius:4,background:"#ffffff",boxSizing:"border-box",overflowX:"auto",overflowY:"hidden"},group:{display:"inline-flex",alignItems:"center",gap:1,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)",flex:"0 0 auto"},formulaGroup:{display:"flex",alignItems:"center",gap:4,flex:"1 1 320px",minWidth:240,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)"},nameBox:{appearance:"none",width:64,height:28,flex:"0 0 auto",boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",color:"#0f172a",font:"600 12px ui-monospace, SFMono-Regular, Menlo, monospace",textAlign:"center",outlineColor:"#2563eb"},formulaMark:{display:"grid",placeItems:"center",width:20,height:28,flex:"0 0 auto",color:"#64748b",font:"italic 700 12px Georgia, serif",userSelect:"none"},formulaInput:{appearance:"none",flex:"1 1 260px",minWidth:140,height:28,boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,padding:"0 8px",background:"#ffffff",color:"#0f172a",font:"13px ui-sans-serif, system-ui, sans-serif",outlineColor:"#2563eb"},proposals:{marginLeft:"auto",paddingLeft:6,flex:"0 0 auto"},count:{display:"inline-grid",placeItems:"center",minWidth:15,height:15,marginLeft:-3,padding:"0 4px",borderRadius:8,background:"#0f172a",color:"#ffffff",fontSize:10,fontWeight:700,lineHeight:1,boxSizing:"border-box"}};function dn({i18n:t,...o}){return jsx(at,{i18n:t,children:jsx(un,{...o})})}function un({file:t,fileName:o,onSave:a,collaboration:c,onReady:u,className:p}){let{t:s}=Se(),w=c!==void 0,M=c?.clientId,S=c?.initialUpdate,z=c?.onReplica,F=c?.provider,K=useRef(null),_=useRef(null),$=useRef(null),v=useRef(null),H=useRef(null),A=useRef(null),Q=useRef(null),C=useRef(false),Z=useRef(null),oe=useRef(false),de=useRef(false),E=useRef(u);E.current=u;let[y,re]=useState(null),[Ee,B]=useState(null),[xe,pt]=useState(null),[b,k]=useState(null),[O,me]=useState(null),[Ye,He]=useState(null),[Pe,ve]=useState(null),[he,ft]=useState(Io),[R,Be]=useState(1),[Le,Ae]=useState(0),[h,m]=useState(false),[ne,Ze]=useState({}),[zt,je]=useState({canUndo:false,canRedo:false}),[bt,qe]=useState([]),[mt,Ft]=useState([]),[ht,Ht]=useState(),[gt,Bt]=useState(),[Ie,De]=useState(null),Te=useRef(null),[Je,Qe]=useState([]),[yt,Nt]=useState(false),[xt,Wt]=useState(null),[$t,Ot]=useState([]),[Do,Ne]=useState({}),d=y?.activeSheet??0,zo=useMemo(()=>isPngExportAvailable(),[]),Ut=useMemo(()=>isProposalsAvailable(),[]);useEffect(()=>{let e=K.current;if(!e)return;let r=()=>ft(e.offsetHeight);r();let n=new ResizeObserver(r);return n.observe(e),()=>n.disconnect()},[]);let ue=useCallback(()=>{let e=v.current;if(!e){Qe([]);return}try{Qe(e.listProposals());}catch{Qe([]);}Ae(r=>r+1);},[]);useEffect(()=>{if(me(null),ve(null),Qe([]),Ne({}),Nt(false),Wt(null),Ze({}),je({canUndo:false,canRedo:false}),qe([]),Ft([]),Ht(void 0),Bt(void 0),De(null),Te.current=null,de.current=false,!t){v.current=null,re(null),k(null),B(null);return}v.current=null,re(null),k(null);let e=null,r=()=>{},n=()=>{},i=false,f=()=>{let T=n;n=()=>{};try{T();}catch{}};return initWasm().then(()=>{if(!i)try{e=openWorkbook(t,{collaborative:w,clientId:M}),S&&e.applyUpdate(S.slice()),v.current=e,r=e.onUpdate(()=>{if(!(i||!e))try{re(e.sheetInfo()),Ae(g=>g+1),Ne({}),ue(),B(null);}catch(g){B(g instanceof Error?g.message:String(g));}}),de.current=!0,re(e.sheetInfo()),k(selectionAt({row:0,col:0})),Wt(e),B(null),ue();let T=E.current?.({handle:e,refreshProposals:ue});typeof T=="function"&&(n=T);}catch(T){f(),r(),r=()=>{},e?.dispose(),e=null,v.current=null,re(null),k(null),B(T instanceof Error?T.message:String(T));}},T=>{i||(v.current=null,re(null),k(null),B(T instanceof Error?T.message:String(T)));}),()=>{i=true,f(),r(),e?.dispose(),v.current=null;}},[t,w,M,S,ue]),useEffect(()=>{if(!y||!de.current)return;let e=_.current;e&&(de.current=false,e.scrollLeft=y.initialScrollX*R,e.scrollTop=y.initialScrollY*R);},[y,R]),useEffect(()=>{if(!(!z||!xt))return z(xt),()=>z(null)},[z,xt]),useEffect(()=>{if(Ot([]),!!F)return F.onAwareness(e=>Ot([...e]))},[F]),useEffect(()=>()=>F?.setCursor(null),[F]),useEffect(()=>{if(!F)return;let e=y?.sheetIds[d];if(!b||!e){F.setCursor(null);return}F.setCursor({sheet:e,anchor:{...b.anchor},head:{...b.focus}});},[F,b,y,d,Le]);let vt=useCallback(()=>{let e=_.current,r=$.current;if(!e||!r)return;let n=r.getContext("2d");if(!n)return;let i=window.devicePixelRatio||1,f=e.clientWidth,T=e.clientHeight;if(f===0||T===0)return;r.width=Math.round(f*i),r.height=Math.round(T*i),r.style.width=`${f}px`,r.style.height=`${T}px`;let g=f/R,q=T/R,X=v.current,ee;if(X)try{ee=X.displayList({x:e.scrollLeft/R,y:e.scrollTop/R,width:g,height:q});}catch{return}else ee=ln(g,q,s("editor.demoCellText"));let Jt=[],Re=ee.grid,Qt=(Re?.rowOffsets.length??0)-1,eo=(Re?.colOffsets.length??0)-1;if(X&&Re&&Qt>0&&eo>0)try{let tr=X.cell(d,Re.startRow,Re.startCol).a1,or=X.cell(d,Re.startRow+Qt-1,Re.startCol+eo-1).a1;Jt=X.mergedRanges(d,`${tr}:${or}`).slice(0,rn);}catch{}paintDisplayList(n,ee,i*R),H.current=ee,Ft(Jt),pt(ee);},[d,s,R]);useEffect(()=>{let e=_.current;if(!e)return;let r=()=>{A.current==null&&(A.current=requestAnimationFrame(()=>{A.current=null,vt();}));};vt(),e.addEventListener("scroll",r,{passive:true});let n=new ResizeObserver(r);return n.observe(e),()=>{e.removeEventListener("scroll",r),n.disconnect(),A.current!=null&&(cancelAnimationFrame(A.current),A.current=null);}},[vt,y,Ee,Le]),useEffect(()=>{let e=v.current;if(!e||!b||!y){He(null);return}try{He(e.cell(d,b.focus.row,b.focus.col));}catch{He(null);}},[b,y,d,Le]),useEffect(()=>{let e=()=>{C.current=false,m(false);};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]),useEffect(()=>{let e=v.current;if(!e||!b||!y){Ze({}),je({canUndo:false,canRedo:false}),qe([]);return}let r=normalizeRange(b);try{let n=e.cell(d,r.top,r.left).a1,i=e.cell(d,r.bottom,r.right).a1,f=`${n}:${i}`;Ze(e.selectionFormatting(d,f)),je(e.historyState()),qe(e.mergedRanges(d,f));}catch{Ze({}),je({canUndo:false,canRedo:false}),qe([]);}},[b,y,d,Le]);let et=useMemo(()=>!xe||!y?null:buildA11yGrid(xe,b,y.sheetNames[d]??"",{gridLabel:s("a11y.gridLabel"),rowHeaderLabel:s("a11y.rowHeaderLabel"),columnHeaderLabel:s("a11y.columnHeaderLabel"),cellLabel:s("a11y.cellLabel"),cellLabelSelected:s("a11y.cellLabelSelected"),emptyCellLabel:s("a11y.emptyCellLabel"),emptyCellLabelSelected:s("a11y.emptyCellLabelSelected")}),[xe,b,y,d,s]),j=useCallback(()=>{_.current?.focus({preventScroll:true});},[]);useEffect(()=>{O&&Q.current?.focus({preventScroll:true});},[O]);let G=useCallback(e=>{re(e.sheetInfo),Ae(r=>r+1),ue();},[ue]),tt=useCallback(e=>{let r=v.current;if(!r)return null;let n=normalizeRange(e),i=r.cell(d,n.top,n.left).a1,f=r.cell(d,n.bottom,n.right).a1;return `${i}:${f}`},[d]),pe=useCallback(()=>an(H.current,y,(_.current?.clientHeight??0)/R),[y,R]),we=useCallback((e,r)=>{let n=$.current,i=H.current?.grid;if(!n||!i)return null;let f=n.getBoundingClientRect();return cellAtPoint(i,(e-f.left)/R,(r-f.top)/R)},[R]),ot=useCallback(e=>{let r=v.current;if(!r||!b)return;let{row:n,col:i}=b.focus,f=e??"";if(e===void 0)try{f=r.cell(d,n,i).input;}catch{f="";}me({row:n,col:i,value:f});},[b,d]),wt=useCallback(e=>{let r=v.current;if(!r||!O)return;oe.current=true;let{row:n,col:i,value:f}=O;try{G(r.editCell(d,n,i,f));}catch(g){B(g instanceof Error?g.message:String(g));}me(null);let T=selectionAt({row:n,col:i});k(e?moveFocus(T,e,{limits:pe()}):T),j();},[O,d,G,pe,j]),Fo=useCallback(()=>{oe.current=true,me(null),j();},[j]),rt=useCallback(()=>{let e=v.current;if(!e||!b)return;let r=normalizeRange(b),n=[];for(let i=r.top;i<=r.bottom;i++)for(let f=r.left;f<=r.right;f++)n.push({row:i,col:f,input:""});try{G(e.editCells(d,n));}catch(i){B(i instanceof Error?i.message:String(i));}},[b,d,G]),nt=useCallback(async()=>{let e=v.current;if(!e||!b)return;let r=normalizeRange(b);try{let n=e.cell(d,r.top,r.left).a1,i=e.cell(d,r.bottom,r.right).a1,f=e.rangeCells(d,`${n}:${i}`),T=toTsv(f.map(g=>g.map(q=>({input:q.input,isFormula:q.isFormula}))));await navigator.clipboard.writeText(T);}catch{}},[b,d]),Gt=useCallback(async()=>{await nt(),rt();},[nt,rt]),_t=useCallback(async()=>{let e=v.current;if(!e||!b)return;let r;try{r=await navigator.clipboard.readText();}catch{return}let n=fromTsv(r);if(n.length===0)return;let i=normalizeRange(b),f=[],T=1;n.forEach((g,q)=>{T=Math.max(T,g.length),g.forEach((X,ee)=>f.push({row:i.top+q,col:i.left+ee,input:X}));});try{G(e.editCells(d,f));}catch(g){B(g instanceof Error?g.message:String(g));return}k({anchor:{row:i.top,col:i.left},focus:{row:i.top+n.length-1,col:i.left+T-1}});},[b,d,G]),Ho=useCallback(e=>{let r=v.current;if(!r||!b)return;let n=tt(b);if(n){if(e==="paintFormat"){if(Ie){De(null),Te.current=null;return}try{De(r.captureFormat(d,n));let i=normalizeRange(b);Te.current=`${d}:${i.top}:${i.left}:${i.bottom}:${i.right}`;}catch(i){B(i instanceof Error?i.message:String(i));}return}try{let i;e==="currency"?i=r.setNumberFormat(d,n,"currency"):e==="percent"?i=r.setNumberFormat(d,n,"percent"):e==="increaseDecimal"?i=r.setNumberFormat(d,n,"increaseDecimal"):e==="decreaseDecimal"?i=r.setNumberFormat(d,n,"decreaseDecimal"):e==="bold"?i=r.patchRangeStyle(d,n,{bold:!ne.bold}):e==="italic"?i=r.patchRangeStyle(d,n,{italic:!ne.italic}):e==="strikethrough"?i=r.patchRangeStyle(d,n,{strikethrough:!ne.strikethrough}):e.type==="numberFormat"?i=e.value==="custom"?r.setNumberFormat(d,n,{type:"custom",pattern:ne.numberFormatPattern??"0.00"}):r.setNumberFormat(d,n,e.value):e.type==="fontFamily"?i=r.patchRangeStyle(d,n,{fontFamily:e.value}):e.type==="fontSize"?i=r.patchRangeStyle(d,n,{fontSize:e.value}):e.type==="textColor"?i=r.patchRangeStyle(d,n,{textColor:e.value}):e.type==="fillColor"?i=r.patchRangeStyle(d,n,{fillColor:e.value}):e.type==="borderPreset"?i=r.patchRangeStyle(d,n,{border:{preset:e.value,style:ht??ne.borderStyle??"solid",color:gt??ne.borderColor??"#000000"}}):e.type==="borderStyle"?(Ht(e.value),i=r.patchRangeStyle(d,n,{border:{style:e.value}})):e.type==="borderColor"?(Bt(e.value),i=r.patchRangeStyle(d,n,{border:{color:e.value}})):e.type==="horizontalAlignment"?i=r.patchRangeStyle(d,n,{horizontalAlignment:e.value}):e.type==="verticalAlignment"?i=r.patchRangeStyle(d,n,{verticalAlignment:e.value}):i=r.patchRangeStyle(d,n,{textWrapping:e.value}),G(i),j();}catch(i){B(i instanceof Error?i.message:String(i));}}},[b,tt,Ie,d,ne,ht,gt,G,j]);useEffect(()=>{let e=v.current;if(!e||!b||!Ie||h)return;let r=normalizeRange(b);if(`${d}:${r.top}:${r.left}:${r.bottom}:${r.right}`===Te.current)return;let i=tt(b);if(i)try{G(e.applyFormat(d,i,Ie)),De(null),Te.current=null,j();}catch(f){B(f instanceof Error?f.message:String(f));}},[b,Ie,h,d,tt,G,j]);let St=useCallback(()=>{let e=v.current;if(e)try{G(e.undo());}catch(r){B(r instanceof Error?r.message:String(r));}},[G]),lt=useCallback(()=>{let e=v.current;if(e)try{G(e.redo());}catch(r){B(r instanceof Error?r.message:String(r));}},[G]),Bo=useCallback(()=>window.print(),[]),No=useCallback(()=>{},[]),Wo=useCallback(e=>{let r=v.current;if(!r||!b)return;let n=normalizeRange(b),i=(g,q)=>({row:g,col:q}),f=(g,q,X,ee)=>({start:i(g,q),end:i(X,ee)}),T=[];if(e==="all")T.push({type:"mergeCells",sheet:d,range:f(n.top,n.left,n.bottom,n.right)});else if(e==="horizontal")for(let g=n.top;g<=n.bottom;g++)T.push({type:"mergeCells",sheet:d,range:f(g,n.left,g,n.right)});else if(e==="vertical")for(let g=n.left;g<=n.right;g++)T.push({type:"mergeCells",sheet:d,range:f(n.top,g,n.bottom,g)});else for(let g of bt)T.push({type:"unmergeCells",sheet:d,range:f(g.start.row,g.start.col,g.end.row,g.end.col)});if(T.length!==0)try{G(r.applyOps(T)),j();}catch(g){B(g instanceof Error?g.message:String(g));}},[b,d,bt,G,j]),$o=useCallback((e,r)=>{let n=v.current;if(n)try{G(n.acceptProposal(e,{force:r})),Ne(({[e]:i,...f})=>f),ue(),j();}catch(i){i instanceof StaleProposalError?Ne(f=>({...f,[e]:i.cells})):B(i instanceof Error?i.message:String(i));}},[G,ue,j]),Oo=useCallback(e=>{let r=v.current;if(r)try{r.rejectProposal(e),Ne(({[e]:n,...i})=>i),ue();}catch(n){B(n instanceof Error?n.message:String(n));}},[ue]),Ct=useCallback(()=>{let e=v.current;if(e)try{let r=e.save();a?a(r):Ao(r,o??"workbook.xlsx",nn);}catch(r){B(r instanceof Error?r.message:String(r));}},[a,o]),Uo=useCallback(()=>{let e=v.current,r=_.current;if(!(!e||!r))try{let n=e.renderPng({x:r.scrollLeft/R,y:r.scrollTop/R,width:r.clientWidth/R,height:r.clientHeight/R});Ao(n,sn(o),"image/png");}catch(n){B(n instanceof Error?n.message:String(n));}},[o,R]),Xt=useCallback(e=>{let r=v.current;if(!r||!b||Pe==null)return;let{row:n,col:i}=b.focus;try{G(r.editCell(d,n,i,Pe));}catch(f){B(f instanceof Error?f.message:String(f));}ve(null),e&&k(f=>f&&moveFocus(f,e,{limits:pe()}));},[b,Pe,d,G,pe]),Go=useCallback(e=>{if(!v.current||!b||!y||O)return;let n=e.metaKey||e.ctrlKey,i=e.key.toLowerCase();if(n){if(i==="c"){nt(),e.preventDefault();return}if(i==="v"){_t(),e.preventDefault();return}if(i==="x"){Gt(),e.preventDefault();return}if(i==="z"){e.shiftKey?lt():St(),e.preventDefault();return}if(i==="y"){lt(),e.preventDefault();return}if(i==="s"){Ct(),e.preventDefault();return}}let f=selectionKeyReducer(b,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},pe());switch(f.type){case "move":k(f.selection),e.preventDefault();break;case "startEdit":ot(f.initialInput),e.preventDefault();break;case "clear":rt(),e.preventDefault();break;}},[b,y,O,pe,nt,_t,Gt,St,lt,Ct,ot,rt]),_o=useCallback(e=>{if(!b||O)return;let r=we(e.clientX,e.clientY);r&&(e.shiftKey?k(n=>n&&extendTo(n,r,pe())):k(selectionAt(r)),Z.current=r,C.current=true,m(true),j());},[O,b,we,pe,j]),Xo=useCallback(e=>{let r=we(e.clientX,e.clientY);if(!r){C.current||(e.currentTarget.style.cursor="default",e.currentTarget.title="");return}if(!C.current){let n=H.current?hyperlinkAtCell(H.current,r.row,r.col):null;e.currentTarget.style.cursor=n?"pointer":"default",e.currentTarget.title=n?.tooltip??"";return}k(n=>n&&extendTo(n,r,pe()));},[we,pe]),Kt=useCallback(e=>{let r=v.current,n=H.current;if(!r||!n||!y)return false;let i=hyperlinkAtCell(n,e.row,e.col);if(!i)return false;let f=safeExternalHyperlink(i);if(f)return window.open(f,"_blank","noopener,noreferrer"),true;if(!i.location)return true;let T=y.sheetNames[d]??"",g=parseHyperlinkLocation(i.location,T);if(!g)return true;let q=y.sheetNames.findIndex(X=>X.toLowerCase()===g.sheetName.toLowerCase());if(q<0)return true;try{r.setActiveSheet(q);let X=r.cellPosition(q,g.row,g.col);re(r.sheetInfo()),requestAnimationFrame(()=>{let ee=_.current;ee&&(ee.scrollLeft=X.x*R,ee.scrollTop=X.y*R);}),k(selectionAt({row:g.row,col:g.col})),me(null),ve(null),De(null),Te.current=null,B(null);}catch(X){B(X instanceof Error?X.message:String(X));}return true},[d,y,R]),Ko=useCallback(e=>{if(O){Z.current=null;return}let r=we(e.clientX,e.clientY),n=Z.current;Z.current=null,!(!r||!n||r.row!==n.row||r.col!==n.col)&&Kt(r);},[Kt,O,we]),Vo=useCallback(e=>{if(O)return;let r=we(e.clientX,e.clientY);r&&H.current&&hyperlinkAtCell(H.current,r.row,r.col)||b&&ot();},[O,ot,we,b]),Yo=useCallback(e=>{e.currentTarget.style.cursor="default",e.currentTarget.title="";},[]),Me=xe?.grid,Vt=b?ct(normalizeRange(b),mt):null,Yt=b?ct({top:b.focus.row,left:b.focus.col,bottom:b.focus.row,right:b.focus.col},mt):null,Zt=Me&&Vt?rangeRect(Me,Vt):null,jt=Me&&Yt?rangeRect(Me,Yt):null,qt=Me&&O?cellRect(Me,O.row,O.col):null,We=Zt?Dt(Zt,R):null,$e=jt?Dt(jt,R):null,Oe=qt?Dt(qt,R):null,Zo=y?y.contentWidth*R:void 0,jo=y?y.contentHeight*R:void 0,qo=Pe??Ye?.input??"",ze=b?normalizeRange(b):null,Jo=ze?ze.bottom-ze.top+1:1,Qo=ze?ze.right-ze.left+1:1,er=e=>{let r=v.current;if(r)try{r.setActiveSheet(e),de.current=!0,k(selectionAt({row:0,col:0})),me(null),ve(null),De(null),Te.current=null,re(r.sheetInfo());}catch(n){B(n instanceof Error?n.message:String(n));}};return jsxs("div",{className:p,role:"application","aria-label":s("editor.appLabel"),style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%",minWidth:0,color:"#202124",background:"#ffffff",fontFamily:"ui-sans-serif, system-ui, sans-serif"},children:[jsx("div",{ref:K,"data-testid":"xlsx-toolbar",style:ye.shell,children:jsxs(Ke,{currentFormatting:{...ne,borderStyle:ht??ne.borderStyle,borderColor:gt??ne.borderColor,paintFormat:Ie!==null},selectionShape:{rows:Jo,columns:Qo,canUnmerge:bt.length>0},onSearchMenus:No,onUndo:St,onRedo:lt,canUndo:zt.canUndo,canRedo:zt.canRedo,onPrint:Bo,zoom:R,onZoomChange:Be,onFormat:Ho,onMerge:Wo,children:[jsx(Ke.Toolbar,{}),jsxs("div",{style:ye.rail,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsxs(Y,{style:{...ye.group,paddingLeft:0},label:s("toolbar.fileActionsLabel"),children:[jsx(U,{testId:"xlsx-save",onClick:Ct,disabled:!y,title:s("toolbar.save"),children:jsx(L,{name:"save",size:18})}),jsx(U,{testId:"xlsx-export-png",onClick:Uo,disabled:!y||!zo,title:s("toolbar.exportPng"),children:jsx(L,{name:"image",size:18})})]}),jsxs("div",{style:ye.formulaGroup,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:Ye?.a1??"",placeholder:s("toolbar.nameBoxPlaceholder"),"aria-label":s("toolbar.nameBoxPlaceholder"),style:ye.nameBox}),jsx("span",{style:ye.formulaMark,"aria-hidden":"true",children:"fx"}),jsx("input",{"data-testid":"xlsx-formula-input",value:qo,placeholder:s("toolbar.formulaPlaceholder"),"aria-label":s("toolbar.formulaPlaceholder"),disabled:!y,onChange:e=>ve(e.target.value),onKeyDown:e=>{e.key==="Enter"?(Xt(e.shiftKey?"up":"down"),j(),e.preventDefault()):e.key==="Escape"&&(ve(null),j(),e.preventDefault());},onBlur:()=>Xt(),style:ye.formulaInput})]}),jsx(So,{peers:$t,sheetIds:y?.sheetIds??[],sheetNames:y?.sheetNames??[],activeSheet:d}),Ut&&jsx("div",{style:ye.proposals,children:jsxs(U,{testId:"xlsx-proposals-button",onClick:()=>Nt(e=>!e),disabled:!y,active:yt,ariaExpanded:yt,title:s("proposals.panelLabel"),style:{width:Je.length>0?42:28},children:[jsx(L,{name:"proposals",size:18}),Je.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:ye.count,children:Je.length})]})})]})]})}),Ut&&yt&&jsx(Mo,{proposals:Je,staleFor:Do,onAccept:$o,onReject:Oo,style:{top:he+4,right:8,width:"min(320px, calc(100% - 16px))",maxHeight:`min(420px, calc(100% - ${he+12}px))`}}),jsxs("div",{ref:_,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:Go,onMouseDown:_o,onMouseMove:Xo,onMouseLeave:Yo,onClick:Ko,onDoubleClick:Vo,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:Zo??"100%",height:jo??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:$,style:{display:"block",position:"absolute",top:0,left:0}}),jsxs("div",{"data-testid":"xlsx-overlay-host",style:{position:"absolute",top:0,left:0,width:0,height:0,pointerEvents:"none"},children:[We&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:We.x,top:We.y,width:We.w,height:We.h,boxSizing:"border-box",border:`1px solid ${ut}`,background:"rgba(33, 115, 70, 0.12)"}}),$e&&!O&&jsx("div",{style:{position:"absolute",left:$e.x,top:$e.y,width:$e.w,height:$e.h,boxSizing:"border-box",border:`2px solid ${ut}`}}),jsx(Co,{peers:$t,grid:Me,sheetIds:y?.sheetIds??[],activeSheet:d,zoom:R,mergedRanges:mt}),O&&Oe&&jsx("input",{ref:Q,"data-testid":"xlsx-cell-editor",value:O.value,onChange:e=>me(r=>r&&{...r,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(wt(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(wt(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(Fo(),e.preventDefault());},onBlur:()=>{if(oe.current){oe.current=false;return}wt();},style:{position:"absolute",left:Oe.x,top:Oe.y,width:Oe.w,height:Oe.h,boxSizing:"border-box",border:`2px solid ${ut}`,padding:"0 3px",font:`${13*R}px system-ui, sans-serif`,background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),et&&jsxs("div",{style:cn,role:"grid","aria-label":et.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),et.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),et.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(r=>jsx("span",{role:"gridcell","aria-selected":r.selected,children:r.label},r.col))]},e.row))]}),Ee&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[s("editor.openError"),": ",Ee]}),y&&y.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":s("editor.sheetTabsLabel"),style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:y.sheetNames.map((e,r)=>{let n=r===y.activeSheet;return jsx("button",{role:"tab","aria-selected":n,onClick:()=>er(r),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:n?`2px solid ${ut}`:"2px solid transparent",fontWeight:n?600:400,background:n?"#ffffff":"transparent"},children:e},r)})})]})}export{Ke as EditorToolbar,Fe as EditorToolbarContext,at as LocaleProvider,it as Toolbar,U as ToolbarButton,fe as ToolbarDropdown,Y as ToolbarGroup,le as ToolbarMenuItem,_e as ToolbarMenuSeparator,Ge as ToolbarSeparator,dn as XlsxEditor,it as XlsxToolbar,ir as useEditorToolbar,Se as useTranslation};
1
+ import {createContext,useMemo,useContext,useState,useRef,useCallback,useEffect}from'react';import {isPngExportAvailable,isProposalsAvailable,initWasm,openWorkbook,selectionAt,paintDisplayList,normalizeRange,buildA11yGrid,cellAtPoint,chartRegionAtPoint,moveFocus,toTsv,fromTsv,StaleProposalError,selectionKeyReducer,extendTo,hyperlinkAtCell,safeExternalHyperlink,parseHyperlinkLocation,rangeRect,cellRect}from'@betteroffice/xlsx';import {en,deepMerge,createT}from'@betteroffice/xlsx-i18n';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {normalizeAwarenessColor,resolveAwarenessCursor,AWARENESS_LABEL_DURATION_MS}from'@betteroffice/xlsx/collaboration';var Eo=createContext(en),Po=createContext("en");function St({i18n:t,children:r}){let i=typeof t?._lang=="string"?t._lang:"en",d=useMemo(()=>deepMerge(en,t),[t]);return jsx(Po.Provider,{value:i,children:jsx(Eo.Provider,{value:d,children:r})})}function Me(){let t=useContext(Eo),r=useContext(Po);return {t:useMemo(()=>createT(t,r),[t,r])}}var _e=createContext(null);function Pr(){let t=useContext(_e);if(!t)throw new Error("useEditorToolbar must be used within an <EditorToolbar> component");return t}function L({name:t,size:r=20,style:i}){return jsxs("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",style:{display:"inline-flex",flexShrink:0,...i},children:[t==="search"&&jsxs(Fragment,{children:[jsx("circle",{cx:"10.5",cy:"10.5",r:"6"}),jsx("path",{d:"m15 15 4.5 4.5"})]}),t==="undo"&&jsx("path",{d:"m9 7-5 5 5 5M5 12h9a6 6 0 0 1 6 6"}),t==="redo"&&jsx("path",{d:"m15 7 5 5-5 5m4-5h-9a6 6 0 0 0-6 6"}),t==="print"&&jsxs(Fragment,{children:[jsx("path",{d:"M7 9V4h10v5M7 18H5a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"}),jsx("path",{d:"M7 14h10v6H7z"}),jsx("path",{d:"M17.5 12h.01"})]}),t==="formatPaint"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 4h11v5H5zM8 9v3h5V9"}),jsx("path",{d:"M10.5 12v8"})]}),t==="decimalDecrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1M14 7h1M18 7h1"}),jsx("path",{d:"M5 16h1M9 16h1"}),jsx("path",{d:"m15 12-4 4 4 4M11 16h8"})]}),t==="decimalIncrease"&&jsxs(Fragment,{children:[jsx("path",{d:"M5 7h1M9 7h1"}),jsx("path",{d:"M5 16h1M9 16h1M14 16h1M18 16h1"}),jsx("path",{d:"m15 3 4 4-4 4M19 7h-8"})]}),t==="bold"&&jsx("path",{d:"M7 4h6a4 4 0 0 1 0 8H7zm0 8h7a4 4 0 0 1 0 8H7z"}),t==="italic"&&jsx("path",{d:"M10 4h8M6 20h8M14 4 10 20"}),t==="strikethrough"&&jsx(Fragment,{children:jsx("path",{d:"M5 12h14M8 7.5A4.5 4.5 0 0 1 12.5 4c2.2 0 3.7 1 4.5 2.5M8 16.5c.8 2.1 2.4 3.5 5 3.5 2.8 0 4.5-1.4 4.5-3.5 0-2.3-2-3.3-5.5-4.5"})}),t==="textColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 16 5-12 5 12M9 11h6"}),jsx("path",{d:"M5 20h14",strokeWidth:"3"})]}),t==="fillColor"&&jsxs(Fragment,{children:[jsx("path",{d:"m7 4 10 10-6 6-7-7zM5 12h12"}),jsx("path",{d:"M18 17c0-1 1-2 1-2s1 1 1 2a1 1 0 0 1-2 0Z"})]}),t==="borders"&&jsx(Fragment,{children:jsx("path",{d:"M4 4h16v16H4zM12 4v16M4 12h16"})}),t==="merge"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 5h16v14H4z"}),jsx("path",{d:"m8 9 3 3-3 3M16 9l-3 3 3 3"})]}),t==="alignLeft"&&jsx("path",{d:"M4 6h16M4 10h11M4 14h16M4 18h11"}),t==="verticalAlignCenter"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 4h16M4 20h16M8 12h8"}),jsx("path",{d:"m10 9 2 3 2-3M10 15l2-3 2 3"})]}),t==="wrap"&&jsxs(Fragment,{children:[jsx("path",{d:"M4 6h16M4 11h12a3 3 0 0 1 0 6h-3"}),jsx("path",{d:"m15 14-3 3 3 3M4 17h5"})]}),t==="more"&&jsxs(Fragment,{children:[jsx("circle",{cx:"5",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"12",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),jsx("circle",{cx:"19",cy:"12",r:"1",fill:"currentColor",stroke:"none"})]}),t==="chevronDown"&&jsx("path",{d:"m7 10 5 5 5-5"}),t==="remove"&&jsx("path",{d:"M5 12h14"}),t==="add"&&jsx("path",{d:"M12 5v14M5 12h14"}),t==="check"&&jsx("path",{d:"m5 12 4 4L19 6"}),t==="save"&&jsx("path",{d:"M12 3v11m0 0 4-4m-4 4-4-4M5 19h14"}),t==="image"&&jsxs(Fragment,{children:[jsx("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),jsx("circle",{cx:"8.5",cy:"9.5",r:"1.25"}),jsx("path",{d:"m6 17 4.5-4.5 3.25 3.25L16 13.5l2 2"})]}),t==="proposals"&&jsxs(Fragment,{children:[jsx("path",{d:"m12 3 1.25 3.75L17 8l-3.75 1.25L12 13l-1.25-3.75L7 8l3.75-1.25L12 3Z"}),jsx("path",{d:"m18 14 .75 2.25L21 17l-2.25.75L18 20l-.75-2.25L15 17l2.25-.75L18 14Z"})]})]})}var D={text:"#3c4043",muted:"#5f6368",disabled:"#9aa0a6",hover:"#e2e7ef",active:"#d3e3fd",border:"#c7cacf",surface:"#ffffff",rail:"#edf2fa"},Ar={appearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",gap:2,minWidth:28,height:28,padding:"0 5px",border:0,borderRadius:4,color:D.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",lineHeight:1,whiteSpace:"nowrap",boxSizing:"border-box"};function Do(t,r,i,d){return {...Ar,background:r?D.active:i&&!t?D.hover:"transparent",color:t?D.disabled:D.text,cursor:t?"default":"pointer",opacity:t?.48:1,...d}}function _({active:t=false,disabled:r=false,title:i,onClick:d,children:p,style:b,testId:s,ariaExpanded:R}){let[P,k]=useState(false);return jsx("button",{type:"button","data-testid":s,disabled:r,"aria-label":i,"aria-pressed":t||void 0,"aria-expanded":R,title:i,onMouseDown:I=>I.preventDefault(),onMouseEnter:()=>k(true),onMouseLeave:()=>k(false),onClick:r?void 0:d,style:Do(r,t,P,b),children:p})}function j({label:t,children:r,style:i}){return jsx("div",{role:"group","aria-label":t,style:{display:"inline-flex",alignItems:"center",gap:1,flex:"0 0 auto",...i},children:r})}function rt(){return jsx("div",{role:"separator",style:{width:1,height:24,margin:"0 5px",background:D.border,flex:"0 0 auto"}})}function he({title:t,trigger:r,children:i,disabled:d=false,active:p=false,menuWidth:b=220,style:s,testId:R}){let[P,k]=useState(false),[I,z]=useState(false),[K,X]=useState({top:0,left:0}),O=useRef(null),v=useRef(null),F=useCallback(()=>k(false),[]);return useEffect(()=>{if(!P||!O.current)return;let N=O.current.getBoundingClientRect(),Y=Math.min(N.left,Math.max(8,window.innerWidth-b-8));X({top:N.bottom+4,left:Y});},[P,b]),useEffect(()=>{if(!P)return;let N=q=>{let oe=q.target;!O.current?.contains(oe)&&!v.current?.contains(oe)&&F();},Y=q=>{q.key==="Escape"&&F();},M=()=>F();return document.addEventListener("mousedown",N),document.addEventListener("keydown",Y),window.addEventListener("scroll",M,true),()=>{document.removeEventListener("mousedown",N),document.removeEventListener("keydown",Y),window.removeEventListener("scroll",M,true);}},[P,F]),jsxs("div",{style:{position:"relative",display:"inline-flex",flex:"0 0 auto"},children:[jsx("button",{ref:O,type:"button","data-testid":R,disabled:d,"aria-label":t,"aria-haspopup":"menu","aria-expanded":P,title:t,onMouseDown:N=>N.preventDefault(),onMouseEnter:()=>z(true),onMouseLeave:()=>z(false),onClick:()=>!d&&k(N=>!N),style:Do(d,p||P,I,s),children:r}),P&&jsx("div",{ref:v,role:"menu","aria-label":t,onMouseDown:N=>N.preventDefault(),style:{position:"fixed",top:K.top,left:K.left,zIndex:1e4,width:b,maxHeight:"min(440px, calc(100vh - 16px))",overflowY:"auto",padding:6,border:`1px solid ${D.border}`,borderRadius:8,background:D.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:i(F)})]})}function ce({label:t,icon:r,selected:i=false,disabled:d=false,onClick:p,close:b}){let[s,R]=useState(false);return jsxs("button",{type:"button",role:"menuitem",disabled:d,"aria-label":t,onMouseEnter:()=>R(true),onMouseLeave:()=>R(false),onClick:()=>{d||(p?.(),b?.());},style:{appearance:"none",display:"flex",alignItems:"center",gap:10,width:"100%",minHeight:32,padding:"5px 9px",border:0,borderRadius:4,background:s&&!d?D.hover:"transparent",color:d?D.disabled:D.text,cursor:d?"default":"pointer",opacity:d?.48:1,font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left",boxSizing:"border-box"},children:[jsx("span",{style:{display:"inline-grid",placeItems:"center",width:20,flex:"0 0 auto"},children:r}),jsx("span",{style:{flex:1},children:t}),i&&jsx("span",{"aria-hidden":"true",children:"\u2713"})]})}function nt(){return jsx("div",{role:"separator",style:{height:1,margin:"5px 2px",background:D.border}})}function Ot({mode:t,value:r,label:i,onChange:d,disabled:p=false}){let[b,s]=useState(false);return jsxs("label",{title:i,"aria-label":i,style:{position:"relative",display:"inline-grid",placeItems:"center",width:28,height:28,borderRadius:4,background:b&&!p?D.hover:"transparent",color:p?D.disabled:D.text,cursor:p?"default":"pointer",opacity:p?.48:1,boxSizing:"border-box"},onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),children:[jsx(L,{name:t==="text"?"textColor":"fillColor",size:20}),jsx("span",{"aria-hidden":"true",style:{position:"absolute",left:5,right:5,bottom:2,height:3,borderRadius:2,background:r}}),jsx("input",{type:"color",value:r,disabled:p,"aria-label":i,onChange:R=>d?.(R.target.value),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})}function Gt({value:t,options:r,label:i,onCommit:d,disabled:p=false,width:b=72,inputStyle:s,testId:R}){let[P,k]=useState(t),[I,z]=useState(false),[K,X]=useState({top:0,left:0,width:b}),O=useRef(null),v=useRef(null),F=useRef(null);useEffect(()=>k(t),[t]);let N=useCallback(()=>z(false),[]);useEffect(()=>{if(!I||!O.current)return;let M=O.current.getBoundingClientRect();X({top:M.bottom+4,left:M.left,width:Math.max(M.width,b)});},[I,b]),useEffect(()=>{if(!I)return;let M=oe=>{let re=oe.target;!O.current?.contains(re)&&!v.current?.contains(re)&&N();},q=oe=>{oe.key==="Escape"&&(k(t),N());};return document.addEventListener("mousedown",M),document.addEventListener("keydown",q),()=>{document.removeEventListener("mousedown",M),document.removeEventListener("keydown",q);}},[I,N,t]);let Y=useCallback(()=>{!p&&d&&P.trim()&&d(P.trim()),k(t);},[p,d,P,t]);return jsxs("div",{ref:O,style:{display:"inline-flex",alignItems:"center",width:b,height:28,border:`1px solid ${D.border}`,borderRadius:4,background:p?"rgba(255,255,255,0.5)":D.surface,opacity:p?.48:1,boxSizing:"border-box",flex:"0 0 auto"},children:[jsx("input",{ref:F,"data-testid":R,role:"combobox","aria-label":i,"aria-autocomplete":"list","aria-expanded":I,disabled:p,value:P,onFocus:M=>{p||(z(true),M.currentTarget.select());},onChange:M=>k(M.target.value),onKeyDown:M=>{M.key==="Enter"?(Y(),N(),M.currentTarget.blur()):M.key==="ArrowDown"&&(z(true),M.preventDefault());},onBlur:()=>{requestAnimationFrame(()=>{v.current?.contains(document.activeElement)||Y();});},style:{appearance:"none",width:"calc(100% - 22px)",height:26,padding:"0 2px 0 7px",border:0,outline:0,background:"transparent",color:D.text,font:"500 13px ui-sans-serif, system-ui, sans-serif",boxSizing:"border-box",...s}}),jsx("button",{type:"button",disabled:p,tabIndex:-1,"aria-label":i,title:i,onMouseDown:M=>M.preventDefault(),onClick:()=>{p||(z(M=>!M),F.current?.focus());},style:{appearance:"none",display:"grid",placeItems:"center",width:21,height:26,padding:0,border:0,background:"transparent",color:D.muted,cursor:p?"default":"pointer"},children:jsx(L,{name:"chevronDown",size:14})}),I&&!p&&jsx("div",{ref:v,role:"listbox","aria-label":i,style:{position:"fixed",top:K.top,left:K.left,zIndex:1e4,width:K.width,maxHeight:260,overflowY:"auto",padding:4,border:`1px solid ${D.border}`,borderRadius:6,background:D.surface,boxShadow:"0 4px 16px rgba(60, 64, 67, 0.24)",boxSizing:"border-box"},children:r.map(M=>jsx("button",{type:"button",role:"option","aria-selected":M.value===t,onMouseDown:q=>q.preventDefault(),onClick:()=>{k(M.label),d?.(M.value),N();},style:{appearance:"none",display:"block",width:"100%",minHeight:28,padding:"4px 7px",border:0,borderRadius:3,background:M.value===t?D.active:"transparent",color:D.text,cursor:"pointer",font:"400 13px ui-sans-serif, system-ui, sans-serif",textAlign:"left"},children:M.label},M.value))})]})}var Wr=[.5,.75,.9,1,1.25,1.5,2],$r=["Arial","Calibri","Cambria","Georgia","Roboto","Times New Roman","Verdana"],Or=[8,9,10,11,12,14,16,18,20,24,28,36,48,72],Ur=["automatic","plainText","number","percent","scientific","currency","date","time","custom"],_r=["all","inner","horizontal","vertical","outer","left","top","right","bottom","none"],Xr=["solid","dashed","dotted","double"],Gr=["left","center","right"],Kr=["top","middle","bottom"],Yr=["overflow","wrap","clip"];function Vr(t){let r={};for(let i of Object.keys(t))t[i]!==void 0&&(r[i]=t[i]);return r}function Zr(t){let r=useContext(_e);return r?{...r,...Vr(t)}:t}function Ho({preset:t}){let r=i=>t===i||t==="all"||t==="outer"?2:.6;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","aria-hidden":"true",children:[t!=="none"&&jsxs(Fragment,{children:[jsx("path",{d:"M3 3h14",strokeWidth:r("top")}),jsx("path",{d:"M17 3v14",strokeWidth:r("right")}),jsx("path",{d:"M3 17h14",strokeWidth:r("bottom")}),jsx("path",{d:"M3 3v14",strokeWidth:r("left")}),(t==="all"||t==="inner"||t==="horizontal")&&jsx("path",{d:"M3 10h14",strokeWidth:"1.5"}),(t==="all"||t==="inner"||t==="vertical")&&jsx("path",{d:"M10 3v14",strokeWidth:"1.5"})]}),t==="none"&&jsx("path",{d:"M4 4h12v12H4zM3 17 17 3",strokeWidth:"1.5"})]})}function No({value:t}){let r=t==="left"?3:t==="center"?5:7,i=t==="left"?15:t==="center"?17:19;return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 4h14M3 10h14M3 16h14"}),jsx("path",{d:`M${r} 7h${i-r}M${r} 13h${i-r}`})]})}function Bo({value:t}){return jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",stroke:"currentColor",strokeWidth:"1.6","aria-hidden":"true",children:[jsx("path",{d:"M3 3h14M3 17h14"}),jsx("path",{d:`M6 ${t==="top"?5:t==="middle"?10:15}h8`}),jsx("path",{d:t==="top"?"m8 8 2-3 2 3":t==="bottom"?"m8 12 2 3 2-3":"m8 7 2 3 2-3m-4 6 2-3 2 3"})]})}function jr({value:t}){return jsx("svg",{width:"44",height:"12",viewBox:"0 0 44 12",fill:"none",stroke:"currentColor","aria-hidden":"true",children:t==="double"?jsx(Fragment,{children:jsx("path",{d:"M2 4h40M2 8h40"})}):jsx("path",{d:"M2 6h40",strokeWidth:"2",strokeDasharray:t==="dashed"?"7 4":t==="dotted"?"1 4":void 0})})}function Wo(t,r,i){return i>0?r.find(d=>d>t)??t+1:[...r].reverse().find(d=>d<t)??Math.max(1,t-1)}function Ct(t){let{t:r}=Me(),{currentFormatting:i={},selectionShape:d,onFormat:p,onMerge:b,onSearchMenus:s,onUndo:R,onRedo:P,canUndo:k=false,canRedo:I=false,onPrint:z,zoom:K=1,onZoomChange:X,fontFamilies:O=$r,fontSizes:v=Or,disabled:F=false,className:N,style:Y,children:M}=Zr(t),q=useRef(null),[oe,re]=useState(Number.POSITIVE_INFINITY),C=!F&&!!p,$=!F&&!!b,Ce=i.fontSize??10,Te=(d?.rows??1)>1,Xe=(d?.columns??1)>1,S=Te||Xe;useEffect(()=>{let g=q.current;if(!g)return;let h=()=>re(g.clientWidth);h();let T=new ResizeObserver(h);return T.observe(g),()=>T.disconnect()},[]);let ue=useMemo(()=>Wr.map(g=>({value:`${g*100}%`,label:`${g*100}%`})),[]),Ge=useMemo(()=>v.map(g=>({value:String(g),label:String(g)})),[v]),y=g=>{C&&p?.(g);},ct=g=>jsx(Fragment,{children:Ur.map(h=>jsx(ce,{label:r(`toolbar.numberFormats.${h}`),selected:i.numberFormat===h,disabled:!C,onClick:()=>y({type:"numberFormat",value:h}),close:g},h))}),Ke=g=>jsxs(Fragment,{children:[_r.map(h=>jsx(ce,{icon:jsx(Ho,{preset:h}),label:r(`toolbar.borderPresets.${h}`),selected:i.borderPreset===h,disabled:!C,onClick:()=>y({type:"borderPreset",value:h}),close:g},h)),jsx(nt,{}),Xr.map(h=>jsx(ce,{icon:jsx(jr,{value:h}),label:r(`toolbar.borderStyles.${h}`),selected:i.borderStyle===h,disabled:!C,onClick:()=>y({type:"borderStyle",value:h}),close:g},h)),jsx(nt,{}),jsxs("label",{style:{position:"relative",display:"flex",alignItems:"center",gap:10,minHeight:32,padding:"5px 9px",color:D.text,font:"400 13px ui-sans-serif, system-ui, sans-serif",cursor:C?"pointer":"default"},children:[jsx("span",{style:{width:20,height:5,borderRadius:2,background:i.borderColor??"#000000"}}),jsx("span",{children:r("toolbar.borderColor")}),jsx("input",{type:"color",value:i.borderColor??"#000000",disabled:!C,"aria-label":r("toolbar.borderColor"),onChange:h=>y({type:"borderColor",value:h.target.value}),style:{position:"absolute",inset:0,width:"100%",height:"100%",opacity:0}})]})]}),pe=g=>jsxs(Fragment,{children:[jsx(ce,{label:r("toolbar.merge.all"),disabled:!$||!S,onClick:()=>b?.("all"),close:g}),jsx(ce,{label:r("toolbar.merge.horizontal"),disabled:!$||!Xe,onClick:()=>b?.("horizontal"),close:g}),jsx(ce,{label:r("toolbar.merge.vertical"),disabled:!$||!Te,onClick:()=>b?.("vertical"),close:g}),jsx(nt,{}),jsx(ce,{label:r("toolbar.merge.unmerge"),disabled:!$||!d?.canUnmerge,onClick:()=>b?.("unmerge"),close:g})]}),dt=g=>jsx(Fragment,{children:Gr.map(h=>jsx(ce,{icon:jsx(No,{value:h}),label:r(`toolbar.horizontalAlign.${h}`),selected:i.horizontalAlignment===h,disabled:!C,onClick:()=>y({type:"horizontalAlignment",value:h}),close:g},h))}),m=g=>jsx(Fragment,{children:Kr.map(h=>jsx(ce,{icon:jsx(Bo,{value:h}),label:r(`toolbar.verticalAlign.${h}`),selected:i.verticalAlignment===h,disabled:!C,onClick:()=>y({type:"verticalAlignment",value:h}),close:g},h))}),J=g=>jsx(Fragment,{children:Yr.map(h=>jsx(ce,{label:r(`toolbar.wrapping.${h}`),selected:i.textWrapping===h,disabled:!C,onClick:()=>y({type:"textWrapping",value:h}),close:g},h))}),B=[{key:"search",width:29,node:jsx(j,{label:r("toolbar.groups.search"),children:jsx(_,{title:r("toolbar.searchMenus"),onClick:s,testId:"xlsx-search-menus",children:jsx(L,{name:"search"})})})},{key:"history",width:58,node:jsxs(j,{label:r("toolbar.groups.history"),children:[jsx(_,{title:r("toolbar.undo"),disabled:F||!k||!R,onClick:R,testId:"xlsx-undo",children:jsx(L,{name:"undo"})}),jsx(_,{title:r("toolbar.redo"),disabled:F||!I||!P,onClick:P,testId:"xlsx-redo",children:jsx(L,{name:"redo"})})]})},{key:"print",width:29,node:jsx(j,{label:r("toolbar.groups.print"),children:jsx(_,{title:r("toolbar.print"),disabled:F||!z,onClick:z,children:jsx(L,{name:"print"})})})},{key:"paint",width:29,node:jsx(j,{label:r("toolbar.groups.paintFormat"),children:jsx(_,{title:r("toolbar.paintFormat"),active:i.paintFormat,disabled:!C,onClick:()=>y("paintFormat"),children:jsx(L,{name:"formatPaint"})})})},{key:"zoom",width:82,node:jsx(j,{label:r("toolbar.groups.zoom"),children:jsx(Gt,{value:`${Math.round(K*100)}%`,options:ue,label:r("toolbar.zoomValue",{value:`${Math.round(K*100)}%`}),disabled:F||!X,onCommit:g=>{let h=Number.parseFloat(g.replace("%",""));Number.isFinite(h)&&h>=25&&h<=400&&X?.(h/100);},width:76,testId:"xlsx-zoom"})})},{key:"number",width:202,node:jsxs(Fragment,{children:[jsx(rt,{}),jsxs(j,{label:r("toolbar.groups.number"),children:[jsx(_,{title:r("toolbar.currency"),disabled:!C,onClick:()=>y("currency"),children:jsx("span",{style:{fontSize:16},children:r("toolbar.currencySymbol")})}),jsx(_,{title:r("toolbar.percent"),disabled:!C,onClick:()=>y("percent"),children:jsx("span",{style:{fontSize:15},children:"%"})}),jsx(_,{title:r("toolbar.decreaseDecimal"),disabled:!C,onClick:()=>y("decreaseDecimal"),children:jsx(L,{name:"decimalDecrease"})}),jsx(_,{title:r("toolbar.increaseDecimal"),disabled:!C,onClick:()=>y("increaseDecimal"),children:jsx(L,{name:"decimalIncrease"})}),jsx(he,{title:r("toolbar.moreNumberFormats"),disabled:!C,trigger:jsxs(Fragment,{children:[jsx("span",{children:"123"}),jsx(L,{name:"chevronDown",size:13})]}),children:ct})]})]})},{key:"font-family",width:137,node:jsxs(Fragment,{children:[jsx(rt,{}),jsx(j,{label:r("toolbar.groups.font"),children:jsx(he,{title:r("toolbar.fontFamily"),disabled:!C,menuWidth:210,style:{width:120,justifyContent:"space-between"},trigger:jsxs(Fragment,{children:[jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis"},children:i.fontFamily??"Calibri"}),jsx(L,{name:"chevronDown",size:13})]}),children:g=>jsx(Fragment,{children:O.map(h=>jsx(ce,{label:h,selected:i.fontFamily===h,disabled:!C,onClick:()=>y({type:"fontFamily",value:h}),close:g},h))})})})]})},{key:"font-size",width:116,node:jsxs(j,{label:r("toolbar.groups.font"),children:[jsx(_,{title:r("toolbar.decreaseFontSize"),disabled:!C,onClick:()=>y({type:"fontSize",value:Wo(Ce,v,-1)}),children:jsx(L,{name:"remove"})}),jsx(Gt,{value:String(Ce),options:Ge,label:r("toolbar.fontSize"),disabled:!C,onCommit:g=>{let h=Number.parseFloat(g);Number.isFinite(h)&&h>=1&&h<=400&&y({type:"fontSize",value:h});},width:50,inputStyle:{textAlign:"center"}}),jsx(_,{title:r("toolbar.increaseFontSize"),disabled:!C,onClick:()=>y({type:"fontSize",value:Wo(Ce,v,1)}),children:jsx(L,{name:"add"})})]})},{key:"text",width:98,node:jsxs(Fragment,{children:[jsx(rt,{}),jsxs(j,{label:r("toolbar.groups.text"),children:[jsx(_,{title:r("toolbar.bold"),active:i.bold,disabled:!C,onClick:()=>y("bold"),children:jsx(L,{name:"bold"})}),jsx(_,{title:r("toolbar.italic"),active:i.italic,disabled:!C,onClick:()=>y("italic"),children:jsx(L,{name:"italic"})}),jsx(_,{title:r("toolbar.strikethrough"),active:i.strikethrough,disabled:!C,onClick:()=>y("strikethrough"),children:jsx(L,{name:"strikethrough"})})]})]})},{key:"colors",width:58,node:jsxs(j,{label:r("toolbar.groups.colors"),children:[jsx(Ot,{mode:"text",value:i.textColor??"#000000",label:r("toolbar.textColor"),disabled:!C,onChange:g=>y({type:"textColor",value:g})}),jsx(Ot,{mode:"fill",value:i.fillColor??"#ffffff",label:r("toolbar.fillColor"),disabled:!C,onChange:g=>y({type:"fillColor",value:g})})]})},{key:"borders",width:36,node:jsx(j,{label:r("toolbar.groups.borders"),children:jsx(he,{title:r("toolbar.borders"),disabled:!C,menuWidth:240,trigger:jsxs(Fragment,{children:[jsx(Ho,{preset:i.borderPreset??"all"}),jsx(L,{name:"chevronDown",size:12})]}),children:Ke})})},{key:"merge",width:58,node:jsxs(j,{label:r("toolbar.groups.merge"),children:[jsx(_,{title:r("toolbar.merge.all"),disabled:!$||!S,onClick:()=>b?.("all"),style:{borderRadius:"4px 0 0 4px"},testId:"xlsx-merge-all",children:jsx(L,{name:"merge"})}),jsx(he,{title:r("toolbar.mergeCells"),disabled:!$||!S&&!d?.canUnmerge,menuWidth:220,style:{minWidth:20,width:20,padding:0,borderRadius:"0 4px 4px 0"},trigger:jsx(L,{name:"chevronDown",size:13}),children:pe})]})},{key:"alignment",width:118,node:jsxs(j,{label:r("toolbar.groups.alignment"),children:[jsx(he,{title:r("toolbar.horizontalAlignment"),disabled:!C,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(No,{value:i.horizontalAlignment??"left"}),jsx(L,{name:"chevronDown",size:12})]}),children:dt}),jsx(he,{title:r("toolbar.verticalAlignment"),disabled:!C,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(Bo,{value:i.verticalAlignment??"middle"}),jsx(L,{name:"chevronDown",size:12})]}),children:m}),jsx(he,{title:r("toolbar.textWrapping"),disabled:!C,menuWidth:180,trigger:jsxs(Fragment,{children:[jsx(L,{name:"wrap"}),jsx(L,{name:"chevronDown",size:12})]}),children:J})]})}];M&&B.push({key:"custom",width:40,node:M});let ye=Math.max(0,oe-48),Ye=0,Le=B.length;for(let g=0;g<B.length;g++)if(Ye+=B[g].width,Ye>ye){Le=g;break}let Fe=B.slice(0,Le),xe=B.slice(Le);return jsxs("div",{ref:q,className:N,role:"toolbar","aria-label":r("toolbar.actionsLabel"),"data-testid":"xlsx-formatting-toolbar",style:{display:"flex",alignItems:"center",minWidth:0,minHeight:36,margin:"0 8px 5px",padding:"4px 7px",borderRadius:18,background:D.rail,color:D.text,overflow:"hidden",boxSizing:"border-box",...Y},children:[Fe.map(g=>jsx("span",{style:{display:"contents"},children:g.node},g.key)),jsx("span",{style:{marginLeft:"auto",flex:"0 0 auto"},children:jsx(he,{title:r("toolbar.more"),disabled:xe.length===0,menuWidth:390,testId:"xlsx-toolbar-more",trigger:jsx(L,{name:"more"}),children:()=>jsx("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:2},children:xe.map(g=>jsx("span",{style:{display:"contents"},children:g.node},g.key))})})})]})}function qr({children:t,className:r,style:i,...d}){return jsx(_e.Provider,{value:d,children:jsx("div",{className:r,"data-testid":"xlsx-editor-toolbar",style:{display:"flex",flexDirection:"column",flex:"0 0 auto",...i},children:t})})}var at=qr;at.Toolbar=Ct;var rn=8,nn=32;function ln(t){let r=t.trim().split(/\s+/).filter(Boolean);return r.length===0?"?":r.slice(0,2).map(i=>i[0]).join("").toUpperCase()}function an(t){let r=Number.parseInt(t.slice(1,3),16),i=Number.parseInt(t.slice(3,5),16),d=Number.parseInt(t.slice(5,7),16);return `rgba(${r}, ${i}, ${d}, 0.1)`}function sn(t,r){return t.left<=r.right&&t.right>=r.left&&t.top<=r.bottom&&t.bottom>=r.top}function Rt(t,r){let i={...t},d=true;for(;d;){d=false;for(let p of r){let b={top:Math.min(p.start.row,p.end.row),left:Math.min(p.start.col,p.end.col),bottom:Math.max(p.start.row,p.end.row),right:Math.max(p.start.col,p.end.col)};if(!sn(i,b))continue;let s=Math.min(i.top,b.top),R=Math.min(i.left,b.left),P=Math.max(i.bottom,b.bottom),k=Math.max(i.right,b.right);s===i.top&&R===i.left&&P===i.bottom&&k===i.right||(Object.assign(i,{top:s,left:R,bottom:P,right:k}),d=true);}}return i}function cn(t){let[r,i]=useState(()=>Date.now());return useEffect(()=>{let d=Date.now();i(d);let p=t.map(R=>R.cursorMovedAt+AWARENESS_LABEL_DURATION_MS).filter(R=>R>d);if(p.length===0)return;let b=setTimeout(()=>i(Date.now()),Math.min(...p)-d+1);return b.unref?.(),()=>clearTimeout(b)},[t]),r}function _o({peers:t,sheetIds:r,sheetNames:i,activeSheet:d}){if(t.length===0)return null;let p=t.slice(0,rn),b=t.length-p.length;return jsxs("div",{"data-testid":"xlsx-presence-strip","aria-label":"Collaborators",style:{display:"flex",alignItems:"center",gap:4,padding:"0 6px",flex:"0 0 auto"},children:[p.map(s=>{let R=s.cursor?r.indexOf(s.cursor.sheet):d,P=s.cursor!==null&&R!==d,k=normalizeAwarenessColor(s.user.color,s.clientId),I=R>=0?i[R]:s.cursor?"Unavailable sheet":void 0,z=P||R<0?`${s.user.name} \u2014 ${I}`:s.user.name;return jsx("span",{"data-testid":`xlsx-presence-chip-${s.clientId}`,title:z,"aria-label":z,style:{display:"inline-grid",placeItems:"center",width:24,height:24,borderRadius:"50%",backgroundColor:k,color:"#ffffff",boxShadow:"0 0 0 2px #ffffff",fontSize:9,fontWeight:700,lineHeight:1,letterSpacing:"-0.02em",opacity:P||R<0?.42:1,transition:"opacity 120ms ease"},children:ln(s.user.name)},s.clientId)}),b>0&&jsxs("span",{"data-testid":"xlsx-presence-overflow",title:`${b} more collaborators`,"aria-label":`${b} more collaborators`,style:{display:"inline-grid",placeItems:"center",minWidth:24,height:24,padding:"0 4px",borderRadius:12,backgroundColor:"#5f6368",color:"#ffffff",fontSize:9,fontWeight:700,lineHeight:1},children:["+",b]})]})}function Xo({peers:t,grid:r,sheetIds:i,activeSheet:d,zoom:p,mergedRanges:b}){let s=useMemo(()=>t.slice(0,nn),[t]),R=t.length-s.length,P=cn(s);return r?jsxs(Fragment,{children:[s.map(k=>{if(!k.cursor)return null;let I=resolveAwarenessCursor(k.cursor,i);if(!I||I.sheetIndex!==d)return null;let z=Rt(I.range,b),K=rangeRect(r,z);if(!K)return null;let X=normalizeAwarenessColor(k.user.color,k.clientId),O={x:K.x*p,y:K.y*p,w:K.w*p,h:K.h*p},v=I.range.top!==I.range.bottom||I.range.left!==I.range.right,F=z.left<r.startCol,N=z.top<r.startRow||O.y<18,Y=k.cursorMovedAt>0&&P-k.cursorMovedAt<AWARENESS_LABEL_DURATION_MS;return jsx("div",{"data-testid":`xlsx-remote-selection-${k.clientId}`,style:{position:"absolute",left:O.x,top:O.y,width:O.w,height:O.h,boxSizing:"border-box",borderWidth:2,borderStyle:"solid",borderColor:X,backgroundColor:v?an(X):"transparent"},children:Y&&jsx("span",{"data-testid":`xlsx-remote-label-${k.clientId}`,style:{position:"absolute",top:N?0:-18,...F?{right:-2}:{left:-2},maxWidth:180,height:18,padding:"2px 6px",borderRadius:N?"0 0 3px 3px":"3px 3px 0 0",boxSizing:"border-box",overflow:"hidden",backgroundColor:X,color:"#ffffff",fontSize:10,fontWeight:600,lineHeight:"14px",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:k.user.name})},k.clientId)}),R>0&&jsxs("span",{"data-testid":"xlsx-remote-selection-overflow","aria-hidden":"true",style:{position:"absolute",left:4,top:4,padding:"2px 5px",borderWidth:1,borderStyle:"solid",borderColor:"#c7cacf",borderRadius:8,backgroundColor:"#ffffff",color:"#3c4043",fontSize:9,lineHeight:1},children:["+",R]})]}):null}var Go=["#7c3aed","#0891b2","#c2410c","#4d7c0f","#be185d","#1d4ed8"];function un(t){let r=2166136261;for(let i=0;i<t.length;i++)r^=t.charCodeAt(i),r=Math.imul(r,16777619);return (r>>>0)%Go.length}function Ko(t){return Go[un(t)]}function Yo({proposals:t,staleFor:r,onAccept:i,onReject:d,style:p}){let{t:b}=Me();return jsx("div",{"data-testid":"xlsx-proposals-panel",role:"region","aria-label":b("proposals.panelLabel"),style:{position:"absolute",top:"100%",right:0,marginTop:4,width:320,maxHeight:420,overflowY:"auto",background:"#ffffff",border:"1px solid #d0d0d0",borderRadius:10,boxShadow:"0 6px 24px rgba(0, 0, 0, 0.16)",padding:8,zIndex:10,font:"13px system-ui, sans-serif",textAlign:"left",...p},children:t.length===0?jsx("div",{style:{padding:12,color:"#707070",textAlign:"center"},children:b("proposals.empty")}):t.map(s=>{let R=Ko(s.agentId),P=r[s.id];return jsxs("div",{"data-testid":"xlsx-proposal","data-proposal-id":s.id,style:{borderLeft:`3px solid ${R}`,padding:"8px 10px",marginBottom:8,background:"#fafafa",borderRadius:4},children:[jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline"},children:[jsx("strong",{style:{color:R},children:s.agentId}),jsx("span",{style:{color:"#707070",fontSize:12},children:b("proposals.cellCount",{count:s.cells.length})})]}),s.note&&jsx("div",{style:{color:"#404040",margin:"4px 0"},children:s.note}),jsx("ul",{style:{listStyle:"none",margin:"6px 0",padding:0},children:s.cells.map(k=>jsxs("li",{"data-testid":"xlsx-proposal-cell",style:{fontVariantNumeric:"tabular-nums",lineHeight:1.5},children:[jsx("strong",{"data-testid":"xlsx-proposal-cell-a1",children:k.a1}),":"," ",jsx("span",{style:{color:"#909090"},children:k.oldText||"\u2205"})," ",b("proposals.changeArrow")," ",jsx("span",{"data-testid":"xlsx-proposal-cell-new",style:{color:R},children:k.newText})]},k.a1))}),P&&P.length>0&&jsx("div",{"data-testid":"xlsx-proposal-stale",role:"alert",style:{color:"#b45309",background:"#fef3c7",borderRadius:4,padding:"4px 6px",margin:"4px 0",fontSize:12},children:b("proposals.staleWarning",{cells:P.join(", ")})}),jsxs("div",{style:{display:"flex",gap:6,marginTop:4},children:[jsx("button",{"data-testid":"xlsx-proposal-accept",onClick:()=>i(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:b("proposals.accept")}),P&&P.length>0&&jsx("button",{"data-testid":"xlsx-proposal-force",onClick:()=>i(s.id,true),style:{padding:"3px 10px",cursor:"pointer",color:"#b45309"},children:b("proposals.forceApply")}),jsx("button",{"data-testid":"xlsx-proposal-reject",onClick:()=>d(s.id),style:{padding:"3px 10px",cursor:"pointer"},children:b("proposals.reject")})]})]},s.id)})})}var Ee=96,Pe=24,st="#217346",er=87,Mn=1024,En="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",Pn=1,Ln=10,An=250,Dn={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},In=new Set(["z","y","s"]);function zn(t,r,i){let d=[{op:"fillRect",x:0,y:0,w:t,h:r,color:"#ffffff"}],p=Math.ceil(t/Ee),b=Math.ceil(r/Pe);for(let s=0;s<=p;s++)d.push({op:"line",x1:s*Ee,y1:0,x2:s*Ee,y2:r,width:1,color:"#e0e0e0"});for(let s=0;s<=b;s++)d.push({op:"line",x1:0,y1:s*Pe,x2:t,y2:s*Pe,width:1,color:"#e0e0e0"});return d.push({op:"fillRect",x:0,y:0,w:t,h:Pe,color:"#f3f3f3"}),d.push({op:"fillRect",x:0,y:0,w:Ee,h:r,color:"#f3f3f3"}),d.push({op:"text",x:Ee+8,y:Pe+18,text:i,fontSize:14,color:"#202020",clip:{x:Ee,y:Pe,w:Ee*3,h:Pe},align:"left"}),{width:t,height:r,commands:d}}function qo(t,r){if(!t||t.length<2)return r;let i=[];for(let p=1;p<t.length;p++)i.push(t[p]-t[p-1]);i.sort((p,b)=>p-b);let d=i[i.length>>1];return d>0?d:r}function Fn(t,r,i){let d=qo(t?.grid?.rowOffsets,Pe),p=qo(t?.grid?.colOffsets,Ee),b=Math.max(1,Math.round(r.contentHeight/d))+1,s=Math.max(1,Math.round(r.contentWidth/p))+1,R=Math.max(1,Math.floor(i/d));return {rows:b,cols:s,rowsPerPage:R}}function Jo(t,r,i){let d=new Blob([new Uint8Array(t)],{type:i}),p=URL.createObjectURL(d),b=document.createElement("a");b.href=p,b.download=r,document.body.appendChild(b),b.click(),b.remove(),URL.revokeObjectURL(p);}function Hn(t){return `${(t??"workbook.xlsx").replace(/\.xlsx$/i,"")}.png`}function Et(t,r){return {x:t.x*r,y:t.y*r,w:t.w*r,h:t.h*r}}var Qo={position:"absolute",width:1,height:1,margin:-1,padding:0,border:0,overflow:"hidden",clip:"rect(0 0 0 0)",whiteSpace:"nowrap"},Se={shell:{flex:"0 0 auto",minHeight:er,padding:"4px 0 5px",borderBottom:"1px solid #e2e8f0",background:"#ffffff",color:"#0f172a",boxSizing:"border-box"},rail:{display:"flex",alignItems:"center",minHeight:32,margin:"0 8px",padding:"2px 8px",borderRadius:4,background:"#ffffff",boxSizing:"border-box",overflowX:"auto",overflowY:"hidden"},group:{display:"inline-flex",alignItems:"center",gap:1,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)",flex:"0 0 auto"},formulaGroup:{display:"flex",alignItems:"center",gap:4,flex:"1 1 320px",minWidth:240,padding:"0 6px",borderRight:"1px solid rgba(226, 232, 240, 0.9)"},nameBox:{appearance:"none",width:64,height:28,flex:"0 0 auto",boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,background:"#f8fafc",color:"#0f172a",font:"600 12px ui-monospace, SFMono-Regular, Menlo, monospace",textAlign:"center",outlineColor:"#2563eb"},formulaMark:{display:"grid",placeItems:"center",width:20,height:28,flex:"0 0 auto",color:"#64748b",font:"italic 700 12px Georgia, serif",userSelect:"none"},formulaInput:{appearance:"none",flex:"1 1 260px",minWidth:140,height:28,boxSizing:"border-box",border:"1px solid #e2e8f0",borderRadius:6,padding:"0 8px",background:"#ffffff",color:"#0f172a",font:"13px ui-sans-serif, system-ui, sans-serif",outlineColor:"#2563eb"},proposals:{marginLeft:"auto",paddingLeft:6,flex:"0 0 auto"},count:{display:"inline-grid",placeItems:"center",minWidth:15,height:15,marginLeft:-3,padding:"0 4px",borderRadius:8,background:"#0f172a",color:"#ffffff",fontSize:10,fontWeight:700,lineHeight:1,boxSizing:"border-box"}};function Nn({i18n:t,...r}){return jsx(St,{i18n:t,children:jsx(Bn,{...r})})}function Bn({file:t,fileName:r,onSave:i,collaboration:d,onReady:p,className:b}){let{t:s}=Me(),R=d!==void 0,P=d?.clientId,k=d?.initialUpdate,I=d?.onReplica,z=d?.provider,K=useRef(null),X=useRef(null),O=useRef(null),v=useRef(null),F=useRef(null),N=useRef(null),Y=useRef(null),M=useRef(null),q=useRef(false),oe=useRef(null),re=useRef(null),C=useRef(null),$=useRef(null),Ce=useRef(false),Te=useRef(false),Xe=useRef(p);Xe.current=p;let[S,ue]=useState(null),[Ge,y]=useState(null),[ct,Ke]=useState(null),[pe,dt]=useState(null),[m,J]=useState(null),[B,ye]=useState(null),[Ye,Le]=useState(null),[Fe,xe]=useState(null),[g,h]=useState(er),[T,tr]=useState(1),[ut,Pt]=useState(0),[Vt,Zt]=useState(false),[se,He]=useState(null),[Lt,Re]=useState(null),[jt,Ve]=useState(null),[fe,pt]=useState({}),[qt,ft]=useState({canUndo:false,canRedo:false}),[At,bt]=useState([]),[Dt,Jt]=useState([]),[It,Qt]=useState(),[zt,eo]=useState(),[Ne,Be]=useState(null),Ae=useRef(null),[mt,ht]=useState([]),[Ft,to]=useState(false),[Ht,oo]=useState(null),[ro,no]=useState([]),[or,Ze]=useState({}),u=S?.activeSheet??0,rr=useMemo(()=>isPngExportAvailable(),[]),lo=useMemo(()=>isProposalsAvailable(),[]);useEffect(()=>{let e=K.current;if(!e)return;let o=()=>h(e.offsetHeight);o();let n=new ResizeObserver(o);return n.observe(e),()=>n.disconnect()},[]);let be=useCallback(()=>{let e=v.current;if(!e){ht([]);return}try{ht(e.listProposals());}catch{ht([]);}Pt(o=>o+1);},[]);useEffect(()=>{if(ye(null),xe(null),He(null),C.current=null,Ve(null),$.current!=null&&(clearTimeout($.current),$.current=null),ht([]),Ze({}),to(false),oo(null),pt({}),ft({canUndo:false,canRedo:false}),bt([]),Jt([]),Qt(void 0),eo(void 0),Be(null),Ke(null),Ae.current=null,Te.current=false,!t){v.current=null,ue(null),J(null),y(null);return}v.current=null,ue(null),J(null);let e=null,o=()=>{},n=()=>{},l=false,c=()=>{let w=n;n=()=>{};try{w();}catch{}};return initWasm().then(()=>{if(!l)try{e=openWorkbook(t,{collaborative:R,clientId:P}),k&&e.applyUpdate(k.slice()),v.current=e,o=e.onUpdate(()=>{if(!(l||!e))try{ue(e.sheetInfo()),Pt(f=>f+1),Ze({}),be(),y(null);}catch(f){y(f instanceof Error?f.message:String(f));}}),Te.current=!0,ue(e.sheetInfo()),J(selectionAt({row:0,col:0})),oo(e),y(null),be();let w=Xe.current?.({handle:e,refreshProposals:be});typeof w=="function"&&(n=w);}catch(w){c(),o(),o=()=>{},e?.dispose(),e=null,v.current=null,ue(null),J(null),y(w instanceof Error?w.message:String(w));}},w=>{l||(v.current=null,ue(null),J(null),y(w instanceof Error?w.message:String(w)));}),()=>{l=true,c(),o(),e?.dispose(),v.current=null;}},[t,R,P,k,be]),useEffect(()=>{if(!S||!Te.current)return;let e=X.current;e&&(Te.current=false,e.scrollLeft=S.initialScrollX*T,e.scrollTop=S.initialScrollY*T);},[S,T]),useEffect(()=>{if(!(!I||!Ht))return I(Ht),()=>I(null)},[I,Ht]),useEffect(()=>{if(no([]),!!z)return z.onAwareness(e=>no([...e]))},[z]),useEffect(()=>()=>z?.setCursor(null),[z]),useEffect(()=>{if(!z)return;let e=S?.sheetIds[u];if(!m||!e){z.setCursor(null);return}z.setCursor({sheet:e,anchor:{...m.anchor},head:{...m.focus}});},[z,m,S,u,ut]);let Nt=useCallback(()=>{let e=X.current,o=O.current;if(!e||!o)return;let n=o.getContext("2d");if(!n)return;let l=window.devicePixelRatio||1,c=e.clientWidth,w=e.clientHeight;if(c===0||w===0)return;o.width=Math.round(c*l),o.height=Math.round(w*l),o.style.width=`${c}px`,o.style.height=`${w}px`;let f=c/T,ee=w/T,ne={x:e.scrollLeft/T,y:e.scrollTop/T,width:f,height:ee},le=v.current,Ie;if(le)try{Ie=le.displayList(ne);}catch(tt){F.current=null,N.current=null,dt(null),Ke(tt instanceof Error?tt.message:String(tt));return}else Ie=zn(f,ee,s("editor.demoCellText"));let vo=[],ze=Ie.grid,wo=(ze?.rowOffsets.length??0)-1,So=(ze?.colOffsets.length??0)-1;if(le&&ze&&wo>0&&So>0)try{let tt=le.cell(u,ze.startRow,ze.startCol).a1,Tr=le.cell(u,ze.startRow+wo-1,ze.startCol+So-1).a1;vo=le.mergedRanges(u,`${tt}:${Tr}`).slice(0,Mn);}catch{}paintDisplayList(n,Ie,l*T),F.current=Ie,N.current={frame:Ie,zoom:T},Ke(null),Jt(vo),dt(Ie);},[u,s,T]);useEffect(()=>{let e=X.current;if(!e)return;let o=()=>{Y.current==null&&(Y.current=requestAnimationFrame(()=>{Y.current=null,Nt();}));};Nt(),e.addEventListener("scroll",o,{passive:true});let n=new ResizeObserver(o);return n.observe(e),()=>{e.removeEventListener("scroll",o),n.disconnect(),Y.current!=null&&(cancelAnimationFrame(Y.current),Y.current=null);}},[Nt,S,Ge,ut]),useEffect(()=>{let e=v.current;if(!e||!m||!S){Le(null);return}try{Le(e.cell(u,m.focus.row,m.focus.col));}catch{Le(null);}},[m,S,u,ut]),useEffect(()=>{let e=()=>{q.current=false,Zt(false);};return window.addEventListener("mouseup",e),()=>window.removeEventListener("mouseup",e)},[]),useEffect(()=>{let e=v.current;if(!e||!m||!S){pt({}),ft({canUndo:false,canRedo:false}),bt([]);return}let o=normalizeRange(m);try{let n=e.cell(u,o.top,o.left).a1,l=e.cell(u,o.bottom,o.right).a1,c=`${n}:${l}`;pt(e.selectionFormatting(u,c)),ft(e.historyState()),bt(e.mergedRanges(u,c));}catch{pt({}),ft({canUndo:false,canRedo:false}),bt([]);}},[m,S,u,ut]);let je=useMemo(()=>!pe||!S?null:buildA11yGrid(pe,m,S.sheetNames[u]??"",{gridLabel:s("a11y.gridLabel"),rowHeaderLabel:s("a11y.rowHeaderLabel"),columnHeaderLabel:s("a11y.columnHeaderLabel"),cellLabel:s("a11y.cellLabel"),cellLabelSelected:s("a11y.cellLabelSelected"),emptyCellLabel:s("a11y.emptyCellLabel"),emptyCellLabelSelected:s("a11y.emptyCellLabelSelected")}),[pe,m,S,u,s]),Z=useCallback(()=>{X.current?.focus({preventScroll:true});},[]);useEffect(()=>{B&&M.current?.focus({preventScroll:true});},[B]);let U=useCallback(e=>{ue(e.sheetInfo),Pt(o=>o+1),be();},[be]),gt=useCallback(e=>{let o=v.current;if(!o)return null;let n=normalizeRange(e),l=o.cell(u,n.top,n.left).a1,c=o.cell(u,n.bottom,n.right).a1;return `${l}:${c}`},[u]),me=useCallback(()=>Fn(F.current,S,(X.current?.clientHeight??0)/T),[S,T]),ke=useCallback((e,o)=>{let n=O.current,l=F.current?.grid;if(!n||!l)return null;let c=n.getBoundingClientRect();return cellAtPoint(l,(e-c.left)/T,(o-c.top)/T)},[T]),We=useCallback((e,o)=>{let n=O.current,l=N.current;if(!n||!l)return null;let c=n.getBoundingClientRect();return chartRegionAtPoint(l.frame.charts,(e-c.left)/l.zoom,(o-c.top)/l.zoom)},[]),ao=useMemo(()=>se?pe?.charts?.find(e=>e.id===se.id)??null:null,[pe,se]);useEffect(()=>{!se||!pe||pe.charts?.some(e=>e.id===se.id)||(ve.current(),re.current=null,Re(null),He(null));},[pe,se]);let $e=useCallback((e,o,n)=>{let l=v.current;if(!(!l||o===0&&n===0))try{U(l.moveChart(u,e,o,n));}catch(c){y(c instanceof Error?c.message:String(c));}},[u,U]),io=useCallback(()=>{$.current!=null&&(clearTimeout($.current),$.current=null);let e=C.current;C.current=null,Ve(null),e&&$e(e.id,e.dx,e.dy);},[$e]),ve=useRef(io);ve.current=io;let so=useCallback((e,o,n)=>{let l=C.current;l&&l.id!==e&&ve.current();let c=C.current??{dx:0,dy:0},w={id:e,dx:c.dx+o,dy:c.dy+n};C.current=w,Ve({x:w.dx,y:w.dy}),$.current!=null&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null;let f=C.current;C.current=null,Ve(null),f&&(f.dx!==0||f.dy!==0)&&co.current(f.id,f.dx,f.dy);},An);},[]),co=useRef($e);co.current=$e,useEffect(()=>{let e=n=>{let l=re.current;re.current=null,Re(null),!(!l||n.button!==0)&&$e(l.id,(n.clientX-l.clientX)/T,(n.clientY-l.clientY)/T);},o=()=>{re.current=null,Re(null),ve.current();};return window.addEventListener("mouseup",e),window.addEventListener("blur",o),()=>{window.removeEventListener("mouseup",e),window.removeEventListener("blur",o);}},[$e,T]),useEffect(()=>()=>{$.current!=null&&clearTimeout($.current),$.current=null,C.current=null;},[]);let yt=useCallback(e=>{let o=v.current;if(!o||!m)return;let{row:n,col:l}=m.focus,c=e??"";if(e===void 0)try{c=o.cell(u,n,l).input;}catch{c="";}ye({row:n,col:l,value:c});},[m,u]),Oe=useCallback(e=>{let o=v.current;if(!o||!B)return;Ce.current=true;let{row:n,col:l,value:c}=B;try{U(o.editCell(u,n,l,c));}catch(f){y(f instanceof Error?f.message:String(f));}ye(null);let w=selectionAt({row:n,col:l});J(e?moveFocus(w,e,{limits:me()}):w),Z();},[B,u,U,me,Z]),nr=useCallback(()=>{Ce.current=true,ye(null),Z();},[Z]),xt=useCallback(()=>{let e=v.current;if(!e||!m)return;let o=normalizeRange(m),n=[];for(let l=o.top;l<=o.bottom;l++)for(let c=o.left;c<=o.right;c++)n.push({row:l,col:c,input:""});try{U(e.editCells(u,n));}catch(l){y(l instanceof Error?l.message:String(l));}},[m,u,U]),vt=useCallback(async()=>{let e=v.current;if(!e||!m)return;let o=normalizeRange(m);try{let n=e.cell(u,o.top,o.left).a1,l=e.cell(u,o.bottom,o.right).a1,c=e.rangeCells(u,`${n}:${l}`),w=toTsv(c.map(f=>f.map(ee=>({input:ee.input,isFormula:ee.isFormula}))));await navigator.clipboard.writeText(w);}catch{}},[m,u]),uo=useCallback(async()=>{await vt(),xt();},[vt,xt]),po=useCallback(async()=>{let e=v.current;if(!e||!m)return;let o;try{o=await navigator.clipboard.readText();}catch{return}let n=fromTsv(o);if(n.length===0)return;let l=normalizeRange(m),c=[],w=1;n.forEach((f,ee)=>{w=Math.max(w,f.length),f.forEach((ne,le)=>c.push({row:l.top+ee,col:l.left+le,input:ne}));});try{U(e.editCells(u,c));}catch(f){y(f instanceof Error?f.message:String(f));return}J({anchor:{row:l.top,col:l.left},focus:{row:l.top+n.length-1,col:l.left+w-1}});},[m,u,U]),lr=useCallback(e=>{let o=v.current;if(!o||!m)return;let n=gt(m);if(n){if(e==="paintFormat"){if(Ne){Be(null),Ae.current=null;return}try{Be(o.captureFormat(u,n));let l=normalizeRange(m);Ae.current=`${u}:${l.top}:${l.left}:${l.bottom}:${l.right}`;}catch(l){y(l instanceof Error?l.message:String(l));}return}try{let l;e==="currency"?l=o.setNumberFormat(u,n,"currency"):e==="percent"?l=o.setNumberFormat(u,n,"percent"):e==="increaseDecimal"?l=o.setNumberFormat(u,n,"increaseDecimal"):e==="decreaseDecimal"?l=o.setNumberFormat(u,n,"decreaseDecimal"):e==="bold"?l=o.patchRangeStyle(u,n,{bold:!fe.bold}):e==="italic"?l=o.patchRangeStyle(u,n,{italic:!fe.italic}):e==="strikethrough"?l=o.patchRangeStyle(u,n,{strikethrough:!fe.strikethrough}):e.type==="numberFormat"?l=e.value==="custom"?o.setNumberFormat(u,n,{type:"custom",pattern:fe.numberFormatPattern??"0.00"}):o.setNumberFormat(u,n,e.value):e.type==="fontFamily"?l=o.patchRangeStyle(u,n,{fontFamily:e.value}):e.type==="fontSize"?l=o.patchRangeStyle(u,n,{fontSize:e.value}):e.type==="textColor"?l=o.patchRangeStyle(u,n,{textColor:e.value}):e.type==="fillColor"?l=o.patchRangeStyle(u,n,{fillColor:e.value}):e.type==="borderPreset"?l=o.patchRangeStyle(u,n,{border:{preset:e.value,style:It??fe.borderStyle??"solid",color:zt??fe.borderColor??"#000000"}}):e.type==="borderStyle"?(Qt(e.value),l=o.patchRangeStyle(u,n,{border:{style:e.value}})):e.type==="borderColor"?(eo(e.value),l=o.patchRangeStyle(u,n,{border:{color:e.value}})):e.type==="horizontalAlignment"?l=o.patchRangeStyle(u,n,{horizontalAlignment:e.value}):e.type==="verticalAlignment"?l=o.patchRangeStyle(u,n,{verticalAlignment:e.value}):l=o.patchRangeStyle(u,n,{textWrapping:e.value}),U(l),Z();}catch(l){y(l instanceof Error?l.message:String(l));}}},[m,gt,Ne,u,fe,It,zt,U,Z]);useEffect(()=>{let e=v.current;if(!e||!m||!Ne||Vt)return;let o=normalizeRange(m);if(`${u}:${o.top}:${o.left}:${o.bottom}:${o.right}`===Ae.current)return;let l=gt(m);if(l)try{U(e.applyFormat(u,l,Ne)),Be(null),Ae.current=null,Z();}catch(c){y(c instanceof Error?c.message:String(c));}},[m,Ne,Vt,u,gt,U,Z]);let Bt=useCallback(()=>{let e=v.current;if(e){ve.current();try{U(e.undo());}catch(o){y(o instanceof Error?o.message:String(o));}}},[U]),wt=useCallback(()=>{let e=v.current;if(e){ve.current();try{U(e.redo());}catch(o){y(o instanceof Error?o.message:String(o));}}},[U]),ar=useCallback(()=>window.print(),[]),ir=useCallback(()=>{},[]),sr=useCallback(e=>{let o=v.current;if(!o||!m)return;let n=normalizeRange(m),l=(f,ee)=>({row:f,col:ee}),c=(f,ee,ne,le)=>({start:l(f,ee),end:l(ne,le)}),w=[];if(e==="all")w.push({type:"mergeCells",sheet:u,range:c(n.top,n.left,n.bottom,n.right)});else if(e==="horizontal")for(let f=n.top;f<=n.bottom;f++)w.push({type:"mergeCells",sheet:u,range:c(f,n.left,f,n.right)});else if(e==="vertical")for(let f=n.left;f<=n.right;f++)w.push({type:"mergeCells",sheet:u,range:c(n.top,f,n.bottom,f)});else for(let f of At)w.push({type:"unmergeCells",sheet:u,range:c(f.start.row,f.start.col,f.end.row,f.end.col)});if(w.length!==0)try{U(o.applyOps(w)),Z();}catch(f){y(f instanceof Error?f.message:String(f));}},[m,u,At,U,Z]),cr=useCallback((e,o)=>{let n=v.current;if(n)try{U(n.acceptProposal(e,{force:o})),Ze(({[e]:l,...c})=>c),be(),Z();}catch(l){l instanceof StaleProposalError?Ze(c=>({...c,[e]:l.cells})):y(l instanceof Error?l.message:String(l));}},[U,be,Z]),dr=useCallback(e=>{let o=v.current;if(o)try{o.rejectProposal(e),Ze(({[e]:n,...l})=>l),be();}catch(n){y(n instanceof Error?n.message:String(n));}},[be]),Wt=useCallback(()=>{let e=v.current;if(e){ve.current();try{let o=e.save();i?i(o):Jo(o,r??"workbook.xlsx",En);}catch(o){y(o instanceof Error?o.message:String(o));}}},[i,r]),ur=useCallback(()=>{let e=v.current,o=X.current;if(!(!e||!o))try{let n=e.renderPng({x:o.scrollLeft/T,y:o.scrollTop/T,width:o.clientWidth/T,height:o.clientHeight/T});Jo(n,Hn(r),"image/png");}catch(n){y(n instanceof Error?n.message:String(n));}},[r,T]),fo=useCallback(e=>{let o=v.current;if(!o||!m||Fe==null)return;let{row:n,col:l}=m.focus;try{U(o.editCell(u,n,l,Fe));}catch(c){y(c instanceof Error?c.message:String(c));}xe(null),e&&J(c=>c&&moveFocus(c,e,{limits:me()}));},[m,Fe,u,U,me]),pr=useCallback(e=>{if(!v.current||!m||!S||B)return;let n=e.metaKey||e.ctrlKey,l=e.key.toLowerCase();if(se&&!(n&&In.has(l))){if(e.key==="Escape"){re.current=null,Re(null),C.current=null,Ve(null),$.current!=null&&(clearTimeout($.current),$.current=null),He(null),e.preventDefault();return}let w=n?void 0:Dn[e.key];if(w){let f=Pn*(e.shiftKey?Ln:1);se.movable&&so(se.id,w[0]*f,w[1]*f),e.preventDefault();}return}if(n){if(l==="c"){vt(),e.preventDefault();return}if(l==="v"){po(),e.preventDefault();return}if(l==="x"){uo(),e.preventDefault();return}if(l==="z"){e.shiftKey?wt():Bt(),e.preventDefault();return}if(l==="y"){wt(),e.preventDefault();return}if(l==="s"){Wt(),e.preventDefault();return}}let c=selectionKeyReducer(m,{key:e.key,shiftKey:e.shiftKey,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey},me());switch(c.type){case "move":J(c.selection),e.preventDefault();break;case "startEdit":yt(c.initialInput),e.preventDefault();break;case "clear":xt(),e.preventDefault();break;}},[m,S,B,me,vt,po,uo,Bt,wt,Wt,yt,xt,se,so]),fr=useCallback(e=>{let o=B!=null;if(o&&M.current?.contains(e.target))return;re.current=null,ve.current();let n=We(e.clientX,e.clientY);if(n){o&&Oe(),He({id:n.id,movable:n.movable}),n.movable&&e.button===0&&(re.current={id:n.id,clientX:e.clientX,clientY:e.clientY}),Re(null),oe.current=null,Z(),e.preventDefault();return}if(He(null),Re(null),!m)return;let l=ke(e.clientX,e.clientY);l&&(o&&Oe(),e.shiftKey?J(c=>c&&extendTo(c,l,me())):J(selectionAt(l)),oe.current=o?null:l,q.current=true,Zt(true),Z());},[B,m,ke,We,me,Z,Oe]),br=useCallback(e=>{let o=re.current;if(o){if(e.buttons===0){re.current=null,Re(null);return}e.currentTarget.style.cursor="move",e.currentTarget.title="",Re({x:e.clientX-o.clientX,y:e.clientY-o.clientY});return}let n=ke(e.clientX,e.clientY);if(!n){q.current||(e.currentTarget.style.cursor="default",e.currentTarget.title="");return}if(!q.current){let l=We(e.clientX,e.clientY);if(l){e.currentTarget.style.cursor=l.movable?"move":"pointer",e.currentTarget.title="";return}let c=F.current?hyperlinkAtCell(F.current,n.row,n.col):null;e.currentTarget.style.cursor=c?"pointer":"default",e.currentTarget.title=c?.tooltip??"";return}J(l=>l&&extendTo(l,n,me()));},[ke,We,me]),bo=useCallback(e=>{let o=v.current,n=F.current;if(!o||!n||!S)return false;let l=hyperlinkAtCell(n,e.row,e.col);if(!l)return false;let c=safeExternalHyperlink(l);if(c)return window.open(c,"_blank","noopener,noreferrer"),true;if(!l.location)return true;let w=S.sheetNames[u]??"",f=parseHyperlinkLocation(l.location,w);if(!f)return true;let ee=S.sheetNames.findIndex(ne=>ne.toLowerCase()===f.sheetName.toLowerCase());if(ee<0)return true;try{o.setActiveSheet(ee);let ne=o.cellPosition(ee,f.row,f.col);ue(o.sheetInfo()),requestAnimationFrame(()=>{let le=X.current;le&&(le.scrollLeft=ne.x*T,le.scrollTop=ne.y*T);}),J(selectionAt({row:f.row,col:f.col})),ye(null),xe(null),Be(null),Ae.current=null,y(null);}catch(ne){y(ne instanceof Error?ne.message:String(ne));}return true},[u,S,T]),mr=useCallback(e=>{if(B){oe.current=null;return}let o=ke(e.clientX,e.clientY),n=oe.current;oe.current=null,!(!o||!n||o.row!==n.row||o.col!==n.col)&&bo(o);},[bo,B,ke]),hr=useCallback(e=>{if(B||We(e.clientX,e.clientY))return;let o=ke(e.clientX,e.clientY);o&&F.current&&hyperlinkAtCell(F.current,o.row,o.col)||m&&yt();},[B,yt,ke,We,m]),gr=useCallback(e=>{e.currentTarget.style.cursor="default",e.currentTarget.title="";},[]),De=pe?.grid,mo=m?Rt(normalizeRange(m),Dt):null,ho=m?Rt({top:m.focus.row,left:m.focus.col,bottom:m.focus.row,right:m.focus.col},Dt):null,go=De&&mo?rangeRect(De,mo):null,yo=De&&ho?rangeRect(De,ho):null,xo=De&&B?cellRect(De,B.row,B.col):null,qe=go?Et(go,T):null,Je=yo?Et(yo,T):null,Qe=xo?Et(xo,T):null,et=ao?Et(ao.rect,T):null,yr=S?S.contentWidth*T:void 0,xr=S?S.contentHeight*T:void 0,vr=Fe??Ye?.input??"",Ue=m?normalizeRange(m):null,wr=Ue?Ue.bottom-Ue.top+1:1,Sr=Ue?Ue.right-Ue.left+1:1,Cr=e=>{let o=v.current;if(o){ve.current();try{o.setActiveSheet(e),Te.current=!0,J(selectionAt({row:0,col:0})),He(null),ye(null),xe(null),Be(null),Ae.current=null,ue(o.sheetInfo());}catch(n){y(n instanceof Error?n.message:String(n));}}};return jsxs("div",{className:b,role:"application","aria-label":s("editor.appLabel"),style:{position:"relative",display:"flex",flexDirection:"column",width:"100%",height:"100%",minWidth:0,color:"#202124",background:"#ffffff",fontFamily:"ui-sans-serif, system-ui, sans-serif"},children:[jsx("div",{ref:K,"data-testid":"xlsx-toolbar",style:Se.shell,children:jsxs(at,{currentFormatting:{...fe,borderStyle:It??fe.borderStyle,borderColor:zt??fe.borderColor,paintFormat:Ne!==null},selectionShape:{rows:wr,columns:Sr,canUnmerge:At.length>0},onSearchMenus:ir,onUndo:Bt,onRedo:wt,canUndo:qt.canUndo,canRedo:qt.canRedo,onPrint:ar,zoom:T,onZoomChange:tr,onFormat:lr,onMerge:sr,children:[jsx(at.Toolbar,{}),jsxs("div",{style:Se.rail,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsxs(j,{style:{...Se.group,paddingLeft:0},label:s("toolbar.fileActionsLabel"),children:[jsx(_,{testId:"xlsx-save",onClick:Wt,disabled:!S,title:s("toolbar.save"),children:jsx(L,{name:"save",size:18})}),jsx(_,{testId:"xlsx-export-png",onClick:ur,disabled:!S||!rr,title:s("toolbar.exportPng"),children:jsx(L,{name:"image",size:18})})]}),jsxs("div",{style:Se.formulaGroup,role:"group","aria-label":s("toolbar.formulaBarLabel"),children:[jsx("input",{"data-testid":"xlsx-name-box",readOnly:true,value:Ye?.a1??"",placeholder:s("toolbar.nameBoxPlaceholder"),"aria-label":s("toolbar.nameBoxPlaceholder"),style:Se.nameBox}),jsx("span",{style:Se.formulaMark,"aria-hidden":"true",children:"fx"}),jsx("input",{"data-testid":"xlsx-formula-input",value:vr,placeholder:s("toolbar.formulaPlaceholder"),"aria-label":s("toolbar.formulaPlaceholder"),disabled:!S,onChange:e=>xe(e.target.value),onKeyDown:e=>{e.key==="Enter"?(fo(e.shiftKey?"up":"down"),Z(),e.preventDefault()):e.key==="Escape"&&(xe(null),Z(),e.preventDefault());},onBlur:()=>fo(),style:Se.formulaInput})]}),jsx(_o,{peers:ro,sheetIds:S?.sheetIds??[],sheetNames:S?.sheetNames??[],activeSheet:u}),lo&&jsx("div",{style:Se.proposals,children:jsxs(_,{testId:"xlsx-proposals-button",onClick:()=>to(e=>!e),disabled:!S,active:Ft,ariaExpanded:Ft,title:s("proposals.panelLabel"),style:{width:mt.length>0?42:28},children:[jsx(L,{name:"proposals",size:18}),mt.length>0&&jsx("span",{"data-testid":"xlsx-proposals-count",style:Se.count,children:mt.length})]})})]})]})}),lo&&Ft&&jsx(Yo,{proposals:mt,staleFor:or,onAccept:cr,onReject:dr,style:{top:g+4,right:8,width:"min(320px, calc(100% - 16px))",maxHeight:`min(420px, calc(100% - ${g+12}px))`}}),jsxs("div",{ref:X,"data-testid":"xlsx-scroll",tabIndex:0,onKeyDown:pr,onMouseDown:fr,onMouseMove:br,onMouseLeave:gr,onClick:mr,onDoubleClick:hr,style:{position:"relative",flex:1,overflow:"auto",minHeight:0,outline:"none"},children:[jsx("div",{style:{position:"absolute",top:0,left:0,width:yr??"100%",height:xr??"100%"}}),jsxs("div",{style:{position:"sticky",top:0,left:0,width:0,height:0},children:[jsx("canvas",{ref:O,style:{display:"block",position:"absolute",top:0,left:0}}),jsxs("div",{"data-testid":"xlsx-overlay-host",style:{position:"absolute",top:0,left:0,width:0,height:0,pointerEvents:"none"},children:[qe&&!se&&jsx("div",{"data-testid":"xlsx-selection",style:{position:"absolute",left:qe.x,top:qe.y,width:qe.w,height:qe.h,boxSizing:"border-box",border:`1px solid ${st}`,background:"rgba(33, 115, 70, 0.12)"}}),et&&jsx("div",{"data-testid":"xlsx-chart-selection","data-chart-id":se?.id,"aria-hidden":true,style:{position:"absolute",left:et.x+(Lt?.x??0)+(jt?.x??0)*T,top:et.y+(Lt?.y??0)+(jt?.y??0)*T,width:et.w,height:et.h,boxSizing:"border-box",border:`2px solid ${st}`,boxShadow:"0 1px 6px rgba(0, 0, 0, 0.25)",background:Lt?"rgba(33, 115, 70, 0.08)":"transparent"}}),Je&&!se&&!B&&jsx("div",{style:{position:"absolute",left:Je.x,top:Je.y,width:Je.w,height:Je.h,boxSizing:"border-box",border:`2px solid ${st}`}}),jsx(Xo,{peers:ro,grid:De,sheetIds:S?.sheetIds??[],activeSheet:u,zoom:T,mergedRanges:Dt}),B&&Qe&&jsx("input",{ref:M,"data-testid":"xlsx-cell-editor",value:B.value,onChange:e=>ye(o=>o&&{...o,value:e.target.value}),onKeyDown:e=>{e.stopPropagation(),e.key==="Enter"?(Oe(e.shiftKey?"up":"down"),e.preventDefault()):e.key==="Tab"?(Oe(e.shiftKey?"left":"right"),e.preventDefault()):e.key==="Escape"&&(nr(),e.preventDefault());},onBlur:()=>{if(Ce.current){Ce.current=false;return}Oe();},style:{position:"absolute",left:Qe.x,top:Qe.y,width:Qe.w,height:Qe.h,boxSizing:"border-box",border:`2px solid ${st}`,padding:"0 3px",font:`${13*T}px system-ui, sans-serif`,background:"#ffffff",pointerEvents:"auto",outline:"none"}})]})]})]}),je&&jsxs(Fragment,{children:[jsxs("div",{style:Qo,role:"grid","aria-label":je.label,children:[jsxs("div",{role:"row",children:[jsx("span",{role:"columnheader"}),je.columnHeaders.map(e=>jsx("span",{role:"columnheader",children:e.label},e.col))]}),je.rows.map(e=>jsxs("div",{role:"row",children:[jsx("span",{role:"rowheader",children:e.header}),e.cells.map(o=>jsx("span",{role:"gridcell","aria-selected":o.selected,children:o.label},o.col))]},e.row))]}),je.charts.map((e,o)=>jsx("div",{style:Qo,role:"img","aria-label":e.label},`${o}:${e.label}`))]}),ct&&jsx("div",{"data-testid":"xlsx-render-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020",background:"#ffffff"},children:ct}),Ge&&jsxs("div",{"data-testid":"xlsx-error",role:"alert",style:{position:"absolute",inset:0,display:"grid",placeItems:"center",padding:16,textAlign:"center",color:"#b00020"},children:[s("editor.openError"),": ",Ge]}),S&&S.sheetNames.length>0&&jsx("div",{"data-testid":"xlsx-sheet-tabs",role:"tablist","aria-label":s("editor.sheetTabsLabel"),style:{display:"flex",gap:2,padding:"4px 6px",borderTop:"1px solid #e0e0e0",background:"#fafafa",overflowX:"auto"},children:S.sheetNames.map((e,o)=>{let n=o===S.activeSheet;return jsx("button",{role:"tab","aria-selected":n,onClick:()=>Cr(o),style:{border:"none",padding:"4px 12px",cursor:"pointer",borderBottom:n?`2px solid ${st}`:"2px solid transparent",fontWeight:n?600:400,background:n?"#ffffff":"transparent"},children:e},o)})})]})}export{at as EditorToolbar,_e as EditorToolbarContext,St as LocaleProvider,Ct as Toolbar,_ as ToolbarButton,he as ToolbarDropdown,j as ToolbarGroup,ce as ToolbarMenuItem,nt as ToolbarMenuSeparator,rt as ToolbarSeparator,Nn as XlsxEditor,Ct as XlsxToolbar,Pr as useEditorToolbar,Me as useTranslation};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betteroffice/xlsx-react",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "Excel-faithful React XLSX spreadsheet editor and viewer — full OOXML fidelity, real-time human + AI agent collaboration.",
5
5
  "keywords": [
6
6
  "xlsx",
@@ -10,8 +10,15 @@
10
10
  "editor",
11
11
  "viewer",
12
12
  "react",
13
+ "react-spreadsheet",
14
+ "spreadsheet-component",
15
+ "xlsx-editor",
16
+ "xlsx-viewer",
17
+ "data-grid",
13
18
  "collaborative",
14
19
  "real-time",
20
+ "crdt",
21
+ "yjs",
15
22
  "ai-agent"
16
23
  ],
17
24
  "type": "module",
@@ -33,8 +40,8 @@
33
40
  "typecheck": "tsc --noEmit -p ."
34
41
  },
35
42
  "dependencies": {
36
- "@betteroffice/xlsx": "0.0.8",
37
- "@betteroffice/xlsx-i18n": "0.0.8"
43
+ "@betteroffice/xlsx": "0.1.0",
44
+ "@betteroffice/xlsx-i18n": "0.1.0"
38
45
  },
39
46
  "peerDependencies": {
40
47
  "react": "^18.0.0 || ^19.0.0",