efficient-office 0.6.0 → 0.7.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 (51) hide show
  1. package/dist/Documents-CVV64UEH.js +1 -0
  2. package/dist/Slides-JMP36AJH.js +1 -0
  3. package/dist/SlidesEditor-MZM7IR46.js +1 -0
  4. package/dist/Spreadsheet-55AVNUEA.js +1 -0
  5. package/dist/chunk-4NKXNXKY.js +1 -0
  6. package/dist/chunk-7K7AY3V3.js +1 -0
  7. package/dist/chunk-A5KQPSPX.js +1 -0
  8. package/dist/chunk-B32ASXHM.js +1 -0
  9. package/dist/chunk-B6JN7D6G.js +1 -0
  10. package/dist/chunk-COXKOQPZ.js +1 -0
  11. package/dist/chunk-GLT7O6TV.js +1 -0
  12. package/dist/{chunk-E4N3DBYM.js → chunk-HU4RI2OM.js} +1 -1
  13. package/dist/chunk-I3AC6PYR.js +1 -0
  14. package/dist/chunk-JCSB2PHB.js +1 -0
  15. package/dist/{chunk-QSM7NWZ2.js → chunk-OB4MLAZC.js} +1 -1
  16. package/dist/chunk-QFPW3KLL.js +1 -0
  17. package/dist/{chunk-USKJW3BA.js → chunk-RLNXQG4T.js} +1 -1
  18. package/dist/chunk-X6F3Z4KZ.js +1 -0
  19. package/dist/chunk-XYVQTQ6N.js +1 -0
  20. package/dist/deckPdf-Y2RE7MFX.js +1 -0
  21. package/dist/documents/documents.css +4 -0
  22. package/dist/documents/index.d.ts +22 -7
  23. package/dist/documents/index.js +1 -1
  24. package/dist/docxPdf-EW5I5JR3.js +1 -0
  25. package/dist/importDocument-274VK7OM.js +1 -0
  26. package/dist/importSpreadsheet-4U3KEJ76.js +1 -0
  27. package/dist/pptxImport-STLMOUNE.js +1 -0
  28. package/dist/slides/index.d.ts +34 -2
  29. package/dist/slides/index.js +1 -1
  30. package/dist/slides/slides.css +23 -0
  31. package/dist/spreadsheet/index.d.ts +62 -44
  32. package/dist/spreadsheet/index.js +1 -1
  33. package/dist/spreadsheet/spreadsheet.css +4 -0
  34. package/dist/words-DK_ajpEa.d.ts +67 -0
  35. package/dist/workbookPdf-C5SSN226.js +1 -0
  36. package/package.json +2 -2
  37. package/dist/Documents-HT324TAY.js +0 -1
  38. package/dist/Slides-EUDBOA5K.js +0 -1
  39. package/dist/SlidesEditor-6KDRHX4H.js +0 -1
  40. package/dist/Spreadsheet-SOF7NDLP.js +0 -1
  41. package/dist/chunk-2PIEDEY5.js +0 -1
  42. package/dist/chunk-3SRMKGQW.js +0 -1
  43. package/dist/chunk-AVUZSUQD.js +0 -1
  44. package/dist/chunk-SB3YS3LH.js +0 -1
  45. package/dist/chunk-XKOHIZO5.js +0 -1
  46. package/dist/chunk-YYHJJIA4.js +0 -1
  47. package/dist/deckPdf-Q4OXQ7HV.js +0 -1
  48. package/dist/docxPdf-NCSEKI4J.js +0 -1
  49. package/dist/options-Djr917yc.d.ts +0 -10
  50. package/dist/pptxImport-QEKBZWT2.js +0 -1
  51. package/dist/workbookPdf-OJDSHKRR.js +0 -1
@@ -0,0 +1 @@
1
+ import{countWords as e,documentText as t,findInNodes as n,pageBlocks as r,pageDocument as o,pageStarts as a,pageStyles as i,replaceSpots as l,sanitizeHtml as s}from"./chunk-4NKXNXKY.js";import{DocumentsConflict as c,useDocumentsHost as d,useDocumentsWords as u}from"./chunk-HU4RI2OM.js";import"./chunk-I3AC6PYR.js";import{FileList as m}from"./chunk-A5KQPSPX.js";import"./chunk-B32ASXHM.js";import{importDocumentFile as f}from"./chunk-JCSB2PHB.js";import{fingerprintOf as p,readDocx as h,readParts as g,stampFingerprints as w}from"./chunk-COXKOQPZ.js";import{BUILTIN_STYLES as b,HIGHLIGHTS as v,MARGIN_PRESETS as y,PAPER_SIZES as x,REL as C,WORD_NS as k,addContentDefault as S,addContentOverride as N,addRel as A,blankDocxParts as $,child as L,escapeXml as T,marginsOf as M,paperOf as E,parseParaProps as z,parseRunProps as R,parseXml as P,partText as j,readRels as D,resolveTarget as O,setPartText as F,withMargins as I,withPaper as H,writeZip as B}from"./chunk-RHW2M2UY.js";import{hasExtension as U,placeCopy as W}from"./chunk-XYVQTQ6N.js";import{useEffect as q,useRef as K,useState as G}from"react";import{WindowTitle as V,useWindowDirty as Q}from"efficient-shell";import{Button as X,EmptyState as Y,Input as J,LoadingSpinner as Z,confirmDestructive as _,toast as ee}from"efficient-shell/ui";import{useCallback as te,useEffect as ne,useId as re,useMemo as oe,useRef as ae,useState as ie}from"react";import{saveIndicator as le,useAutosave as se}from"efficient-easel/autosave";import{useEaselStrings as ce}from"efficient-easel/strings";import{Icon as de}from"efficient-shell/icons";import{Button as ue,ColorPickerPanel as me,ContextMenu as fe,DropdownMenu as pe,IconButton as he,Popover as ge,PopupMenu as we,PopupMenuDivider as be,PopupMenuItem as ve,PopupMenuLabel as ye,prompt as xe,registerModalEscapeInterceptor as Ce,toast as ke,useShellLocale as Se}from"efficient-shell/ui";import{SettingsColour as Ne}from"efficient-easel/panel";import{useEaselStrings as Ae}from"efficient-easel/strings";import{Button as $e,Select as Le}from"efficient-shell/ui";import{jsx as Te,jsxs as Me}from"react/jsx-runtime";function Ee({page:e,onPage:t,onMorePageSetup:n,colour:r,onColour:o,outline:a,onHeading:i}){const l=u(),s=Ae(),c=E(e),d=M(e),m={a4:"A4",a3:"A3",a5:"A5",letter:l.paperLetter,legal:l.paperLegal},f={normal:l.marginsNormal,narrow:l.marginsNarrow,moderate:l.marginsModerate,wide:l.marginsWide},p={value:"custom",label:l.custom};return Me("aside",{className:"docs-panel",children:[Te("h3",{children:l.documentPanel}),Me("div",{className:"docs-panel-section",children:[Te("p",{className:"docs-panel-label",children:l.pagePanel}),Te(Le,{"aria-label":l.paperSize,value:c??"custom",onChange:n=>{"custom"!==n&&t(H(e,n))},options:[...c?[]:[p],...Object.keys(x).map(e=>({value:e,label:m[e]}))]}),Te(Le,{"aria-label":l.margins,value:d??"custom",onChange:n=>{"custom"!==n&&t(I(e,n))},options:[...d?[]:[p],...Object.keys(y).map(e=>({value:e,label:f[e]}))]}),Te($e,{variant:"secondary",block:!0,onClick:n,children:l.morePageSetup})]}),Te("div",{className:"docs-panel-section",children:Te(Ne,{label:l.textColor,value:r,onChange:o,words:s.colourRow})}),Me("div",{className:"docs-panel-section",children:[Te("p",{className:"docs-panel-label",children:l.outline}),0===a.length?Te("p",{className:"docs-panel-empty",children:l.outlineEmpty}):Te("ul",{className:"docs-outline",children:a.map((e,t)=>Te("li",{style:{paddingLeft:10*(e.level-1)+"px"},children:Te("button",{type:"button",onClick:()=>i(t),children:e.text})},t))})]})]})}import{EaselIconButton as ze,EaselTopBar as Re,SaveState as Pe,TopBarCluster as je,TopBarDivider as De}from"efficient-easel/chrome";import"efficient-easel/shell.css";import"efficient-easel/chrome.css";import"efficient-easel/panel.css";import"efficient-easel/fields.css";import{Icon as Oe}from"efficient-shell/icons";import{DropdownMenu as Fe}from"efficient-shell/ui";import{jsx as Ie,jsxs as He}from"react/jsx-runtime";function Be({onClose:e,fileMenu:t,name:n,saveState:r,canUndo:o,canRedo:a,onUndo:i,onRedo:l,exportControl:s}){const c=u();return He(Re,{children:[He(je,{children:[e&&Ie(ze,{label:c.backToFiles,onClick:e,children:Ie(Oe,{name:"chevron-left",size:16})}),t.length>0&&Ie(Fe,{trigger:c.menuFile,items:t,align:"start",triggerClassName:"docs-menu-trigger"}),n,Ie(Pe,{...r}),Ie(De,{}),He("span",{className:"docs-history",onMouseDown:e=>e.preventDefault(),children:[Ie(ze,{label:c.undo,disabled:!o,onClick:i,children:Ie(Oe,{name:"undo",size:16})}),Ie(ze,{label:c.redo,disabled:!a,onClick:l,children:Ie(Oe,{name:"redo",size:16})})]})]}),Ie(je,{kind:"right",children:s})]})}var Ue=["w:rStyle","w:rFonts","w:b","w:bCs","w:i","w:iCs","w:caps","w:smallCaps","w:strike","w:dstrike","w:outline","w:shadow","w:emboss","w:imprint","w:noProof","w:snapToGrid","w:vanish","w:webHidden","w:color","w:spacing","w:w","w:kern","w:position","w:sz","w:szCs","w:highlight","w:u","w:effect","w:bdr","w:shd","w:fitText","w:vertAlign","w:rtl","w:cs","w:em","w:lang","w:eastAsianLayout","w:specVanish","w:oMath","w:rPrChange"],We=["w:pStyle","w:keepNext","w:keepLines","w:pageBreakBefore","w:framePr","w:widowControl","w:numPr","w:suppressLineNumbers","w:pBdr","w:shd","w:tabs","w:suppressAutoHyphens","w:kinsoku","w:wordWrap","w:overflowPunct","w:topLinePunct","w:autoSpaceDE","w:autoSpaceDN","w:bidi","w:adjustRightInd","w:snapToGrid","w:spacing","w:ind","w:contextualSpacing","w:mirrorIndents","w:suppressOverlap","w:jc","w:textDirection","w:textAlignment","w:textboxTightWrap","w:outlineLvl","w:divId","w:cnfStyle","w:rPr","w:sectPr","w:pPrChange"],qe=["w:cnfStyle","w:tcW","w:gridSpan","w:hMerge","w:vMerge","w:tcBorders","w:shd","w:noWrap","w:tcMar","w:textDirection","w:tcFitText","w:vAlign","w:hideMark","w:headers","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"],Ke=["w:headerReference","w:footerReference","w:footnotePr","w:endnotePr","w:type","w:pgSz","w:pgMar","w:paperSrc","w:pgBorders","w:lnNumType","w:pgNumType","w:cols","w:formProt","w:vAlign","w:noEndnote","w:titlePg","w:textDirection","w:bidi","w:rtlGutter","w:docGrid","w:printerSettings","w:sectPrChange"];function Ge(e){if(!e)return[];return P(e).children.map(t=>({name:t.name,xml:e.slice(t.start,t.end)}))}function Ve(e,t){const n=e=>{const n=t.indexOf(e);return n<0?t.length:n};return e.map((e,t)=>({p:e,i:t})).sort((e,t)=>n(e.p.name)-n(t.p.name)||e.i-t.i).map(e=>e.p.xml).join("")}function Qe(e){const t=new Map;for(const n of(e.getAttribute("style")??"").split(";")){const e=n.indexOf(":");e>0&&t.set(n.slice(0,e).trim().toLowerCase(),n.slice(e+1).trim())}return t}var Xe={black:"#000000",white:"#ffffff",red:"#ff0000",blue:"#0000ff",green:"#008000",yellow:"#ffff00"};function Ye(e){if(!e)return;const t=e.trim().toLowerCase();if("transparent"===t||"inherit"===t||"initial"===t||"auto"===t)return;if(Xe[t])return Xe[t];if(/^#[0-9a-f]{6}$/.test(t))return t;if(/^#[0-9a-f]{3}$/.test(t))return`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`;const n=/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+))?\s*\)$/.exec(t);return!n||void 0!==n[4]&&0===Number(n[4])?void 0:`#${[n[1],n[2],n[3]].map(e=>Math.round(Number(e)).toString(16).padStart(2,"0")).join("")}`}function Je(e){if(!e)return;const t=/^(-?[\d.]+)(pt|px|in|cm|mm|em)?$/.exec(e.trim());if(!t)return;const n=Number(t[1]);switch(t[2]){case"pt":return n;case"px":return.75*n;case"in":return 72*n;case"cm":return 72*n/2.54;case"mm":return 72*n/25.4;default:return"0"===t[1]?0:void 0}}var Ze=[10,13,16,18,24,32,48].map(e=>.75*e);var _e=(e,t)=>void 0===e||void 0===t?e===t:Math.abs(e-t)<.02,et=e=>Math.round(20*e);function tt(e,t){const n=D(e.parts,e.doc.docPath).find(e=>e.type===C.styles),r=n?j(e.parts,O(e.doc.docPath,n.target)):void 0;if(r)for(const e of P(r).children)if("w:style"===e.name&&L(e,"w:name")?.attrs["w:val"]?.toLowerCase()===t)return e.attrs["w:styleId"];return Object.entries(b).find(([,e])=>e.name===t)?.[0]??null}var nt=["•","o","▪"],rt=["decimal","lowerLetter","lowerRoman"];function ot(e){const t=D(e.parts,e.doc.docPath).find(e=>e.type===C.numbering);if(t){const n=O(e.doc.docPath,t.target);return{path:n,text:j(e.parts,n)??`<w:numbering ${k}></w:numbering>`}}const n="word/numbering.xml";return A(e.parts,e.doc.docPath,C.numbering,"numbering.xml"),N(e.parts,n,"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml"),{path:n,text:`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:numbering ${k}></w:numbering>`}}function at(e,t){const{path:n,text:r}=ot(e),o=P(r),a=o.children.filter(e=>"w:abstractNum"===e.name).map(e=>Number(e.attrs["w:abstractNumId"])),i=String((a.length?Math.max(...a):-1)+1);let l="";for(let e=0;e<9;e++){l+=`<w:lvl w:ilvl="${e}"><w:start w:val="1"/><w:numFmt w:val="${t?rt[e%3]:"bullet"}"/><w:lvlText w:val="${t?`%${e+1}.`:nt[e%3]}"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="${720*(e+1)}" w:hanging="360"/></w:pPr></w:lvl>`}const s=`<w:abstractNum w:abstractNumId="${i}"><w:multiLevelType w:val="hybridMultilevel"/>${l}</w:abstractNum>`,c=o.children.find(e=>"w:num"===e.name),d=c?c.start:o.innerEnd>o.innerStart||r.includes("</w:numbering>")?r.lastIndexOf("</w:numbering>"):-1,u=d>=0?r.slice(0,d)+s+r.slice(d):r.replace(/\/>\s*$/,`>${s}</w:numbering>`);return F(e.parts,n,u),i}function it(e,t,n){const{path:r,text:o}=ot(e),a=P(o),i=a.children.filter(e=>"w:num"===e.name).map(e=>Number(e.attrs["w:numId"])),l=String((i.length?Math.max(...i):0)+1),s=`<w:num w:numId="${l}"><w:abstractNumId w:val="${t}"/>${n?'<w:lvlOverride w:ilvl="0"><w:startOverride w:val="1"/></w:lvlOverride>':""}</w:num>`,c=[...a.children].reverse().find(e=>"w:num"===e.name),d=c?c.end:o.lastIndexOf("</w:numbering>");return F(e.parts,r,o.slice(0,d)+s+o.slice(d)),l}var lt={"image/png":"png","image/jpeg":"jpeg","image/gif":"gif","image/bmp":"bmp","image/webp":"webp","image/svg+xml":"svg"};function st(e,t){const n=t.getAttribute("data-raw"),r=function(e,t){const n=Qe(t),r=Je(n.get("width")),o=Je(n.get("height")),a=t.naturalWidth?.75*t.naturalWidth:0,i=t.naturalHeight?.75*t.naturalHeight:0,l=a&&i?i/a:o&&r?o/r:.75;let s=r??(a||e.contentWidth);return s>2*e.contentWidth&&(s=e.contentWidth),{width:s,height:o??s*l}}(e,t),o=Math.round(12700*r.width),a=Math.round(12700*r.height),i=n?e.doc.raw.get(n):void 0;if(i)return i.replace(/(<wp:extent\b[^>]*?\bcx=")\d+("[^>]*?\bcy=")\d+/,`$1${o}$2${a}`).replace(/(<a:xfrm\b[^>]*>\s*<a:off\b[^>]*\/>\s*<a:ext\b[^>]*?\bcx=")\d+("[^>]*?\bcy=")\d+/,`$1${o}$2${a}`);const l=t.getAttribute("src")??"";let s=e.mediaBySrc.get(l);if(!s){const t=e.images.get(l)??function(e){const t=/^data:([^;,]+);base64,(.*)$/s.exec(e);if(!t)return null;const n=atob(t[2]),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return{bytes:r,mime:t[1]}}(l);if(!t)return"";const n=lt[t.mime]??"png";S(e.parts,n,t.mime);let r=1;for(;e.parts.has(`word/media/inserted${r}.${n}`);)r++;e.parts.set(`word/media/inserted${r}.${n}`,t.bytes),s=A(e.parts,e.doc.docPath,C.image,`media/inserted${r}.${n}`),e.mediaBySrc.set(l,s)}const c=++e.drawingId;return`<w:r><w:drawing><wp:inline xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${o}" cy="${a}"/><wp:docPr id="${c}" name="Picture ${c}"/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="${c}" name="Picture ${c}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${s}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${o}" cy="${a}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>`}function ct(e,t,n,r={}){let o="",a=null;const i=()=>{a?.body&&(o+=`<w:r>${function(e,t,n){const r=n?e.runs.get(n):void 0,o=r?P(r):void 0,a=R(o,e.theme);let i=Ge(r);const l=(e,t)=>{i=i.filter(t=>!e.includes(t.name)),i.push(...t)},s=(e,t)=>void 0===t?[]:[{name:e,xml:t?`<${e}/>`:`<${e} w:val="0"/>`}];if(t.b!==a.b&&l(["w:b","w:bCs"],[...s("w:b",t.b),...s("w:bCs",t.b)]),t.i!==a.i&&l(["w:i","w:iCs"],[...s("w:i",t.i),...s("w:iCs",t.i)]),!!t.u!=!!a.u&&l(["w:u"],t.u?[{name:"w:u",xml:'<w:u w:val="single"/>'}]:a.u?[{name:"w:u",xml:'<w:u w:val="none"/>'}]:[]),t.strike!==a.strike&&!!t.strike!=!!a.strike&&l(["w:strike"],s("w:strike",t.strike)),t.vert!==a.vert&&l(["w:vertAlign"],t.vert?[{name:"w:vertAlign",xml:`<w:vertAlign w:val="${"sub"===t.vert?"subscript":"superscript"}"/>`}]:[]),t.font!==a.font){const e=T(t.font??"");l(["w:rFonts"],t.font?[{name:"w:rFonts",xml:`<w:rFonts w:ascii="${e}" w:hAnsi="${e}" w:eastAsia="${e}" w:cs="${e}"/>`}]:[])}if(t.size!==a.size){const e=t.size?Math.round(2*t.size):0;l(["w:sz","w:szCs"],e?[{name:"w:sz",xml:`<w:sz w:val="${e}"/>`},{name:"w:szCs",xml:`<w:szCs w:val="${e}"/>`}]:[])}if(t.color!==a.color&&l(["w:color"],t.color?[{name:"w:color",xml:`<w:color w:val="${t.color.slice(1).toUpperCase()}"/>`}]:[]),t.hl!==a.hl){const e=t.hl?Object.entries(v).find(([,e])=>e===t.hl)?.[0]:void 0;l(["w:highlight","w:shd"],t.hl?e?[{name:"w:highlight",xml:`<w:highlight w:val="${e}"/>`}]:[{name:"w:shd",xml:`<w:shd w:val="clear" w:color="auto" w:fill="${t.hl.slice(1).toUpperCase()}"/>`}]:[])}const c=Ve(i,Ue);return c?`<w:rPr>${c}</w:rPr>`:""}(e.doc,a.format,a.runId)}${a.body}</w:r>`),a=null},l=(e,t,n)=>{n&&(a&&a.runId===t&&JSON.stringify(a.format)===JSON.stringify(e)?a.body+=n:(i(),a={format:e,runId:t,body:n}))},s=(t,r,a)=>{if(3===t.nodeType)return void l(r,a,function(e){let t="",n="";const r=()=>{n&&(t+=`<w:t xml:space="preserve">${T(n)}</w:t>`),n=""};for(const o of e)"\t"===o?(r(),t+="<w:tab/>"):"\n"===o?(r(),t+="<w:br/>"):"‑"===o?(r(),t+="<w:noBreakHyphen/>"):"­"===o?(r(),t+="<w:softHyphen/>"):"​"!==o&&"\ufeff"!==o&&(n+=o);return r(),t}(t.nodeValue??""));if(1!==t.nodeType)return;const c=t,d=c.tagName;if("IMG"===d)return i(),void(o+=st(e,c));const u=c.getAttribute("data-raw");if(u){const t=e.doc.raw.get(u);return void(t&&(i(),o+=t))}if(c.hasAttribute("data-page-break"))return void l(r,a,'<w:br w:type="page"/>');if("BR"===d)return void(function(e,t){let n=e;for(;n!==t;){let e=n.nextSibling;for(;e&&3===e.nodeType&&!e.nodeValue;)e=e.nextSibling;if(e)return!1;if(!n.parentNode)return!0;n=n.parentNode}return!0}(c,n)||l(r,a,"<w:br/>"));if("A"===d)return i(),void(o+=function(e,t,n,r){const o=t.getAttribute("data-anchor"),a=t.getAttribute("href")??"";let i=t.getAttribute("data-rel");const l=D(e.parts,e.doc.docPath),s=i?l.find(e=>e.id===i):void 0;a&&!a.startsWith("#")&&s?.target!==a&&(i=l.find(e=>e.external&&e.target===a)?.id??A(e.parts,e.doc.docPath,C.hyperlink,a,!0),t.setAttribute("data-rel",i));const c=t.querySelector("[data-r]")?n:{color:"#0563c1",u:!0,...n},d=ct(e,Array.from(t.childNodes),r,c);return`<w:hyperlink${o?` w:anchor="${T(o)}"`:i?` r:id="${T(i)}"`:a.startsWith("#")?` w:anchor="${T(a.slice(1))}"`:""} w:history="1">${d}</w:hyperlink>`}(e,c,r,n));const m=c.getAttribute("data-comment");m&&e.firstComment.get(m)===c&&(i(),o+=`<w:commentRangeStart w:id="${T(m)}"/>`);const f=c.getAttribute("data-r"),p=function(e,t){const n={...t},r=e.tagName;if("B"!==r&&"STRONG"!==r||(n.b=!0),"I"!==r&&"EM"!==r||(n.i=!0),"U"===r&&(n.u=!0),"S"!==r&&"STRIKE"!==r||(n.strike=!0),"SUB"===r&&(n.vert="sub"),"SUP"===r&&(n.vert="super"),"FONT"===r){const t=Ye(e.getAttribute("color")??void 0);t&&(n.color=t);const r=e.getAttribute("face");r&&(n.font=r.split(",")[0].replace(/["']/g,"").trim());const o=Number(e.getAttribute("size"));o>=1&&o<=7&&(n.size=Ze[o-1])}const o=Qe(e),a=o.get("font-weight");a&&(n.b="bold"===a||"bolder"===a||Number(a)>=600);const i=o.get("font-style");i&&(n.i="italic"===i||"oblique"===i);const l=o.get("text-decoration-line")??o.get("text-decoration");l&&(/none/.test(l)?(n.u=!1,n.strike=!1):(/underline/.test(l)&&(n.u=!0),/line-through/.test(l)&&(n.strike=!0)));const s=o.get("font-family");s&&(n.font=s.split(",")[0].replace(/["']|&quot;/g,"").trim());const c=Je(o.get("font-size"));if(c&&(n.size=Math.round(2*c)/2),o.has("color")){const e=Ye(o.get("color"));e?n.color=e:delete n.color}const d=o.get("background-color")??o.get("background");if(void 0!==d){const e=Ye(d);e?n.hl=e:delete n.hl}return n}(c,r);for(const e of Array.from(c.childNodes))s(e,p,f??a);m&&e.lastComment.get(m)===c&&(i(),o+=`<w:commentRangeEnd w:id="${T(m)}"/><w:r><w:commentReference w:id="${T(m)}"/></w:r>`)};for(const e of t)s(e,r,null);return i(),o}function dt(e,t,n,r,o){const a=n?P(n):void 0,i=z(a),l=function(e){const t=Qe(e),n={},r=t.get("text-align")??e.getAttribute("align")??void 0;"left"===r||"start"===r?n.align="left":"center"!==r&&"right"!==r&&"justify"!==r||(n.align=r);const o=Je(t.get("margin-left"));void 0!==o&&(n.indentLeft=o);const a=Je(t.get("text-indent"));void 0!==a&&(n.firstLine=a);const i=Je(t.get("margin-top"));void 0!==i&&(n.before=i);const l=Je(t.get("margin-bottom"));void 0!==l&&(n.after=l);const s=t.get("line-height");if(s){const e=Je(s);e?n.linePoints=e:Number(s)&&(n.lineMultiple=Number(s))}return n}(t);let s=Ge(n);const c=(e,t)=>{s=s.filter(t=>t.name!==e),t&&s.push({name:e,xml:t})};if(c("w:pStyle",r?`<w:pStyle w:val="${T(r)}"/>`:null),c("w:numPr",o?`<w:numPr><w:ilvl w:val="${o.ilvl}"/><w:numId w:val="${T(o.numId)}"/></w:numPr>`:null),l.align!==i.align&&c("w:jc",l.align?`<w:jc w:val="${"justify"===l.align?"both":l.align}"/>`:null),!(o||_e(l.indentLeft,i.indentLeft)&&_e(l.firstLine,i.firstLine))){const e=[];void 0!==l.indentLeft&&e.push(`w:left="${et(l.indentLeft)}"`),void 0!==l.firstLine&&e.push(l.firstLine<0?`w:hanging="${et(-l.firstLine)}"`:`w:firstLine="${et(l.firstLine)}"`),c("w:ind",e.length?`<w:ind ${e.join(" ")}/>`:null)}if(!(_e(l.before,i.before)&&_e(l.after,i.after)&&_e(l.lineMultiple,i.lineMultiple)&&_e(l.linePoints,i.linePoints))){const e=[];void 0!==l.before&&e.push(`w:before="${et(l.before)}"`),void 0!==l.after&&e.push(`w:after="${et(l.after)}"`),void 0!==l.lineMultiple&&e.push(`w:line="${Math.round(240*l.lineMultiple)}" w:lineRule="auto"`),void 0!==l.linePoints&&e.push(`w:line="${et(l.linePoints)}" w:lineRule="exact"`),c("w:spacing",e.length?`<w:spacing ${e.join(" ")}/>`:null)}const d=Ve(s,We);return d?`<w:pPr>${d}</w:pPr>`:""}function ut(e,t){let n=t.getAttribute("data-pstyle");if(!n){const r=/^H([1-6])$/.exec(t.tagName);r?n=tt(e,`heading ${r[1]}`)??`Heading${r[1]}`:"BLOCKQUOTE"===t.tagName&&(n=tt(e,"quote"))}return n&&function(e,t){const n=D(e.parts,e.doc.docPath).find(e=>e.type===C.styles);if(!n)return;const r=O(e.doc.docPath,n.target),o=j(e.parts,r);if(!o||new RegExp(`w:styleId="${t}"`).test(o))return;const a=b[t];a&&F(e.parts,r,o.replace("</w:styles>",`${a.xml}</w:styles>`))}(e,n),n}function mt(e,t,n,r){const o=t.getAttribute("data-docx"),a=o?e.doc.blocks.get(o):void 0;if(a?.xml&&a.xml.startsWith("<w:p")&&(a.fingerprint===p(t)||t.hasAttribute("data-locked"))&&(t.hasAttribute("data-locked")||(a.numId??null)===(r?.numId??null)&&(a.ilvl??null)===(r?.ilvl??null)))return a.xml;return`<w:p>${dt(0,t,a?.props,ut(e,t),r)}${ct(e,n,t)}</w:p>`}var ft=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","TABLE","LI","HR","SECTION","ARTICLE"]);function pt(e,t,n,r){const o=function(e,t,n){const r=t.getAttribute("data-num-id");if(r)return r;if(n)return t.setAttribute("data-num-id",n),n;let o;return"OL"===t.tagName?(e.orderedAbstract??=at(e,!0),o=it(e,e.orderedAbstract,!0)):(e.bulletNum??=it(e,at(e,!1),!1),o=e.bulletNum),t.setAttribute("data-num-id",o),o}(e,t,n),a=t.getAttribute("data-ilvl"),i=null!==a&&Number(a)>r?Number(a):r+1;let l="";for(const n of Array.from(t.children)){if("UL"===n.tagName||"OL"===n.tagName){l+=pt(e,n,o,i);continue}if("LI"!==n.tagName)continue;const t=Array.from(n.children).filter(e=>"UL"===e.tagName||"OL"===e.tagName);l+=mt(e,n,Array.from(n.childNodes).filter(e=>!t.includes(e)),{numId:o,ilvl:i});for(const n of t)l+=pt(e,n,o,i)}return l}function ht(e){return Array.from(e.children).some(e=>ft.has(e.tagName))}function gt(e,t){let n="",r=[];const o=()=>{r.some(e=>1===e.nodeType||(e.nodeValue??"").trim())&&(n+=`<w:p>${ct(e,r,t)}</w:p>`),r=[]};for(const a of Array.from(t.childNodes)){const t=a;if(1!==a.nodeType||!ft.has(t.tagName)){r.push(a);continue}o();const i=t.getAttribute("data-docx"),l=i?e.doc.blocks.get(i):void 0;"UL"===t.tagName||"OL"===t.tagName?n+=pt(e,t,null,-1):"TABLE"===t.tagName?n+=wt(e,t):t.hasAttribute("data-locked")&&l?.xml?n+=l.xml:"HR"===t.tagName?n+='<w:p><w:pPr><w:pBdr><w:bottom w:val="single" w:sz="6" w:space="1" w:color="auto"/></w:pBdr></w:pPr></w:p>':ht(t)?n+=gt(e,t):n+=mt(e,t,Array.from(t.childNodes),null)}return o(),n}function wt(e,t){const n=t.getAttribute("data-docx"),r=n?e.doc.blocks.get(n):void 0;if(r?.xml&&(t.hasAttribute("data-locked")||r.fingerprint===p(t)))return r.xml;const o=Array.from(t.querySelectorAll(":scope > tbody > tr, :scope > tr, :scope > thead > tr, :scope > tfoot > tr")),a=[];let i=0;const l=o.map(t=>{const n=[];let r=0;const o=()=>{for(;a[r]?.left>0;){const e=a[r];e.left--,n.push({continuation:!0,span:e.span,col:r,props:e.props}),r+=e.span}};for(const i of Array.from(t.children).filter(e=>"TD"===e.tagName||"TH"===e.tagName)){o();const t=Math.max(1,Number(i.getAttribute("colspan")??1)),l=Math.max(1,Number(i.getAttribute("rowspan")??1));n.push({cell:i,span:t,col:r}),l>1&&(a[r]={left:l-1,span:t,props:e.doc.blocks.get(i.getAttribute("data-docx")??"")?.props}),r+=t}return o(),i=Math.max(i,r),n}),s=Array.from(t.querySelectorAll(":scope > colgroup > col")),c=[];for(let t=0;t<i;t++){const n=s[t]?Je(Qe(s[t]).get("width")):void 0;c.push(void 0!==n&&s.length===i?et(n):Math.round(20*e.contentWidth/Math.max(i,1)))}return`<w:tbl>${r?.props??'<w:tblPr><w:tblW w:w="5000" w:type="pct"/><w:tblBorders><w:top w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:left w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:bottom w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:right w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:insideH w:val="single" w:sz="4" w:space="0" w:color="auto"/><w:insideV w:val="single" w:sz="4" w:space="0" w:color="auto"/></w:tblBorders><w:tblLook w:val="04A0"/></w:tblPr>'}${`<w:tblGrid>${c.map(e=>`<w:gridCol w:w="${e}"/>`).join("")}</w:tblGrid>`}${o.map((t,n)=>`<w:tr>${e.doc.blocks.get(t.getAttribute("data-docx")??"")?.props??""}${l[n].map(t=>{const n=t.span,r=c.slice(t.col,t.col+n).reduce((e,t)=>e+t,0);if("continuation"in t)return`<w:tc><w:tcPr>${bt(t.props,r,n,"continue",void 0)}</w:tcPr><w:p/></w:tc>`;const o=e.doc.blocks.get(t.cell.getAttribute("data-docx")??""),a=Number(t.cell.getAttribute("rowspan")??1),i=Ye(Qe(t.cell).get("background-color"));let l=gt(e,t.cell);return l.endsWith("</w:p>")||l.endsWith("<w:p/>")||(l+="<w:p/>"),`<w:tc><w:tcPr>${bt(o?.props,r,n,a>1?"restart":null,i)}</w:tcPr>${l}</w:tc>`}).join("")}</w:tr>`).join("")}</w:tbl>`}function bt(e,t,n,r,o){const a=e?P(e):void 0;let i=Ge(e).filter(e=>!["w:tcW","w:gridSpan","w:vMerge"].includes(e.name));i.push({name:"w:tcW",xml:`<w:tcW w:w="${t}" w:type="dxa"/>`}),n>1&&i.push({name:"w:gridSpan",xml:`<w:gridSpan w:val="${n}"/>`}),r&&i.push({name:"w:vMerge",xml:"restart"===r?'<w:vMerge w:val="restart"/>':"<w:vMerge/>"});const l=L(a,"w:shd")?.attrs["w:fill"]?.toLowerCase();return"continue"!==r&&(o?.slice(1)??void 0)!==(l&&/^[0-9a-f]{6}$/.test(l)?l:void 0)&&(i=i.filter(e=>"w:shd"!==e.name),o&&i.push({name:"w:shd",xml:`<w:shd w:val="clear" w:color="auto" w:fill="${o.slice(1).toUpperCase()}"/>`})),Ve(i,qe)}function vt(e,t,n,r,o){let a=Ge(t);const i=e.doc.page;if(Object.keys(n).some(e=>n[e]!==i[e])||!t){const e=n.width>n.height,r=`<w:pgSz w:w="${n.width}" w:h="${n.height}"${e?' w:orient="landscape"':""}/>`,o=t?P(t):void 0,i=L(o,"w:pgMar")?.attrs["w:gutter"]??"0",l=`<w:pgMar w:top="${n.top}" w:right="${n.right}" w:bottom="${n.bottom}" w:left="${n.left}" w:header="${n.header}" w:footer="${n.footer}" w:gutter="${i}"/>`;a=a.filter(e=>"w:pgSz"!==e.name&&"w:pgMar"!==e.name),a.push({name:"w:pgSz",xml:r},{name:"w:pgMar",xml:l})}const l=n.width-n.left-n.right,s=(t,n,r)=>{if(!t.editable||n===t.text)return;const o=function(e,t,n){const r=t.split(/\s*\|\s*/),o=r.length>1,a=r.map(e=>e.split(/(\{page\}|\{pages\})/).map(e=>"{page}"===e?'<w:fldSimple w:instr=" PAGE "><w:r><w:t>1</w:t></w:r></w:fldSimple>':"{pages}"===e?'<w:fldSimple w:instr=" NUMPAGES "><w:r><w:t>1</w:t></w:r></w:fldSimple>':e?`<w:r><w:t xml:space="preserve">${T(e)}</w:t></w:r>`:"").join("")).join("<w:r><w:tab/></w:r>");return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:${e} ${k}><w:p>${o?`<w:pPr><w:tabs><w:tab w:val="right" w:pos="${n}"/></w:tabs></w:pPr>`:""}${a}</w:p></w:${e}>`}(r,n,l);if(t.part)return void F(e.parts,t.part,o);const i="hdr"===r?"header":"footer";let s=1;for(;e.parts.has(`word/${i}${s}.xml`);)s++;const c=`word/${i}${s}.xml`;F(e.parts,c,o),N(e.parts,c,`application/vnd.openxmlformats-officedocument.wordprocessingml.${i}+xml`);const d=A(e.parts,e.doc.docPath,"hdr"===r?C.header:C.footer,`${i}${s}.xml`);a.push({name:`w:${i}Reference`,xml:`<w:${i}Reference w:type="default" r:id="${d}"/>`}),t.part=c};s(e.doc.header,r,"hdr"),s(e.doc.footer,o,"ftr");return`<w:sectPr${t?/^<w:sectPr\b([^>]*?)\/?>/.exec(t)?.[1]??"":""}>${Ve(a,Ke)}</w:sectPr>`}async function yt(e,t,n){const r=new Map(e.parts),o=j(r,e.docPath);if(!o)throw new Error("Not a Word document");const a=P(o),i=L(a,"w:body"),l=L(i,"w:sectPr"),s={doc:e,parts:r,images:n.images??new Map,firstComment:new Map,lastComment:new Map,drawingId:9e4,mediaBySrc:e.insertedMedia??=new Map,contentWidth:(n.page.width-n.page.left-n.page.right)/20,bulletNum:null,orderedAbstract:null};t.querySelectorAll("[data-comment]").forEach(e=>{const t=e.getAttribute("data-comment");s.firstComment.has(t)||s.firstComment.set(t,e),s.lastComment.set(t,e)});let c=gt(s,t);/<\/w:p>\s*$|<w:p\/>\s*$/.test(c)||(c+="<w:p/>"),c=function(e){const t=new Set,n=e.replace(/<w:commentRangeStart\b[^>]*w:id="([^"]+)"[^>]*\/>/g,(e,n)=>t.has(n)?"":(t.add(n),e)),r=new Set,o=[],a=n.split(/(<w:commentRangeEnd\b[^>]*\/>|<w:r>(?:<w:rPr>(?:(?!<\/w:rPr>).)*<\/w:rPr>)?<w:commentReference\b[^>]*\/><\/w:r>)/s);for(let e=a.length-1;e>=0;e--){const t=a[e],n=/^<w:commentRangeEnd\b[^>]*w:id="([^"]+)"/.exec(t)??/^<w:r>.*<w:commentReference\b[^>]*w:id="([^"]+)"/s.exec(t);if(n&&e%2==1){const e=`${t.includes("commentRangeEnd")?"e":"r"}${n[1]}`;if(r.has(e))continue;r.add(e)}o.push(t)}return o.reverse().join("")}(c);const d=vt(s,l?o.slice(l.start,l.end):void 0,n.page,n.headerText,n.footerText),u=o.slice(a.start,a.innerStart),m=[!/\bxmlns:r=/.test(u)&&/\br:(id|embed)=/.test(c+d)?' xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"':""].join(""),f=(m?o.slice(0,a.innerStart-1)+m+">":o.slice(0,a.innerStart))+o.slice(a.innerStart,i.innerStart)+c+d+o.slice(i.innerEnd);return F(r,e.docPath,f),e.parts=r,e.page={...n.page},e.header={...e.header,text:e.header.editable?n.headerText:e.header.text},e.footer={...e.footer,text:e.footer.editable?n.footerText:e.footer.text},B(r)}function xt(e,t,n){const r=new Blob([e],{type:n}),o=URL.createObjectURL(r),a=document.createElement("a");a.href=o,a.download=t,a.click(),setTimeout(()=>URL.revokeObjectURL(o),1e4)}import{useEffect as Ct,useRef as kt}from"react";import{Icon as St}from"efficient-shell/icons";import{Button as Nt,Checkbox as At,IconButton as $t,Input as Lt}from"efficient-shell/ui";import{jsx as Tt,jsxs as Mt}from"react/jsx-runtime";function Et({query:e,replacement:t,matchCase:n,current:r,total:o,onQuery:a,onReplacement:i,onMatchCase:l,onStep:s,onReplace:c,onReplaceAll:d,onClose:m}){const f=u(),p=kt(null);return Ct(()=>{p.current?.focus(),p.current?.select()},[]),Mt("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-line bg-surface-sunken px-2 py-1",children:[Tt("div",{className:"w-40",children:Tt(Lt,{ref:p,size:"sm","aria-label":f.find,placeholder:f.find,value:e,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),s(!e.shiftKey))}})}),Tt("span",{className:"min-w-14 text-xs text-ink-muted","aria-live":"polite",children:e?o?f.matchCount(r+1,o):f.noMatches:""}),Tt($t,{size:"sm",variant:"ghost","aria-label":f.previousMatch,title:f.previousMatch,onClick:()=>s(!1),children:Tt(St,{name:"chevron-up",size:16})}),Tt($t,{size:"sm",variant:"ghost","aria-label":f.nextMatch,title:f.nextMatch,onClick:()=>s(!0),children:Tt(St,{name:"chevron-down",size:16})}),Tt("div",{className:"ml-1 w-40",children:Tt(Lt,{size:"sm","aria-label":f.replaceWith,placeholder:f.replaceWith,value:t,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),c())}})}),Tt(Nt,{size:"sm",variant:"secondary",onClick:c,children:f.replace}),Tt(Nt,{size:"sm",variant:"secondary",onClick:d,children:f.replaceAll}),Mt("label",{className:"ml-1 flex items-center gap-1 text-xs text-ink-muted",children:[Tt(At,{checked:n,onChange:l,"aria-label":f.matchCase}),f.matchCase]}),Tt($t,{className:"ml-auto",size:"sm",variant:"ghost","aria-label":f.closeFind,title:f.closeFind,onClick:m,children:Tt(St,{name:"close",size:16})})]})}var zt=class{past=[];future=[];get canUndo(){return this.past.length>0}get canRedo(){return this.future.length>0}record(e){if(this.past[this.past.length-1]?.html===e.html)return;this.past.push(e),this.future=[];let t=this.past.reduce((e,t)=>e+t.html.length,0);for(;this.past.length>1&&(this.past.length>200||t>67108864);)t-=this.past.shift().html.length}undo(e){const t=this.past.pop();return t?(this.future.push(e),t):null}redo(e){const t=this.future.pop();return t?(this.past.push(e),t):null}};function Rt(e,t,n){const r=[];let o=t;for(;o&&o!==e;){const e=o.parentNode;if(!e)return null;r.unshift(Array.prototype.indexOf.call(e.childNodes,o)),o=e}return o===e?{path:r,offset:n}:null}function Pt(e,t){let n=e;for(const e of t.path){const t=n.childNodes[e];if(!t)return null;n=t}const r=3===n.nodeType?(n.nodeValue??"").length:n.childNodes.length;return{node:n,offset:Math.min(t.offset,r)}}function jt(e){return Array.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6")).filter(e=>!e.closest("[data-hidden]")&&""!==(e.textContent??"").trim())}var Dt=["#000000","#404040","#7f7f7f","#c00000","#ff0000","#ffc000","#00b050","#0070c0","#002060","#7030a0"],Ot=["#ffff00","#00ff00","#00ffff","#ff00ff","#ff0000","#c0c0c0"],Ft=["#d9e2f3","#e2efd9","#fff2cc","#fbe4d5","#ededed","#bfbfbf"];function It(e){if(/^#[0-9a-f]{6}$/i.test(e))return e.toLowerCase();const t=/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i.exec(e);return t?`#${[t[1],t[2],t[3]].map(e=>Number(e).toString(16).padStart(2,"0")).join("")}`:""}import{useState as Ht}from"react";import{Button as Bt,Dialog as Ut,FormField as Wt,Input as qt,Select as Kt}from"efficient-shell/ui";import{Fragment as Gt,jsx as Vt,jsxs as Qt}from"react/jsx-runtime";function Xt({value:e,headerEditable:t,footerEditable:n,onApply:r,onClose:o}){const a=u(),[i,l]=Ht(e.page),[s,c]=Ht(e.header),[d,m]=Ht(e.footer),f=i.width>i.height,p=E(i),h=M(i),g={a4:"A4",a3:"A3",a5:"A5",letter:a.paperLetter,legal:a.paperLegal},w={normal:a.marginsNormal,narrow:a.marginsNarrow,moderate:a.marginsModerate,wide:a.marginsWide},b={value:"custom",label:a.custom};return Vt(Ut,{open:!0,onClose:o,title:a.pageSetup,size:"sm",footer:Qt(Gt,{children:[Vt(Bt,{variant:"secondary",onClick:o,children:a.cancel}),Vt(Bt,{variant:"primary",onClick:()=>r({page:i,header:s,footer:d}),children:a.ok})]}),children:Qt("div",{className:"space-y-3",children:[Vt(Wt,{label:a.paperSize,children:Vt(Kt,{value:p??"custom",onChange:e=>{"custom"!==e&&l(t=>H(t,e))},options:[...p?[]:[b],...Object.keys(x).map(e=>({value:e,label:g[e]}))]})}),Vt(Wt,{label:a.orientation,children:Vt(Kt,{value:f?"landscape":"portrait",onChange:e=>{"landscape"===e!==f&&l(e=>({...e,width:e.height,height:e.width}))},options:[{value:"portrait",label:a.portrait},{value:"landscape",label:a.landscape}]})}),Vt(Wt,{label:a.margins,children:Vt(Kt,{value:h??"custom",onChange:e=>{"custom"!==e&&l(t=>I(t,e))},options:[...h?[]:[b],...Object.keys(y).map(e=>({value:e,label:w[e]}))]})}),Vt(Wt,{label:a.header,hint:t?a.headerFooterHint:a.headerFooterLocked,children:Vt(qt,{value:s,disabled:!t,onChange:e=>c(e.target.value)})}),Vt(Wt,{label:a.footer,hint:n?void 0:a.headerFooterLocked,children:Vt(qt,{value:d,disabled:!n,onChange:e=>m(e.target.value)})})]})})}var Yt=e=>e.querySelectorAll("ul,ol").forEach(e=>e.removeAttribute("data-ilvl"));function Jt(e){const t=e.previousElementSibling,n=e.parentElement;if(!t||"LI"!==t.tagName||!n)return!1;const r=t.lastElementChild;let o;var a;return a=r,"UL"===a?.tagName||"OL"===a?.tagName?o=r:(o=e.ownerDocument.createElement(n.tagName),t.appendChild(o)),o.appendChild(e),Yt(e),!0}function Zt(e){const t=e.parentElement,n=t?.parentElement;if(!t||"LI"!==n?.tagName)return!1;const r=[];for(let t=e.nextElementSibling;t;t=t.nextElementSibling)r.push(t);if(r.length){const n=e.ownerDocument.createElement(t.tagName),o=t.getAttribute("data-num-id");o&&n.setAttribute("data-num-id",o),r.forEach(e=>n.appendChild(e)),e.appendChild(n)}return n.parentElement.insertBefore(e,n.nextSibling),Yt(e),t.children.length||t.remove(),!0}var _t=e=>Array.from(e.querySelectorAll(":scope > tbody > tr, :scope > tr, :scope > thead > tr, :scope > tfoot > tr")),en=(e,t)=>Math.max(1,Number(e.getAttribute(t)??1));function tn(e){const t=_t(e),n=t.map(()=>[]);return t.forEach((e,r)=>{let o=0;for(const a of(e=>Array.from(e.children).filter(e=>"TD"===e.tagName||"TH"===e.tagName))(e)){for(;n[r][o];)o++;const e=en(a,"colspan"),i=en(a,"rowspan");for(let l=r;l<Math.min(r+i,t.length);l++)for(let t=o;t<o+e;t++)n[l][t]=a;o+=e}}),{table:e,slots:n,cols:Math.max(0,...n.map(e=>e.length))}}function nn(e,t){for(let n=0;n<e.slots.length;n++){const r=e.slots[n].indexOf(t);if(r>=0)return{row:n,col:r}}return null}function rn(e){const t=e.createElement("td");return t.innerHTML="<p><br></p>",t}function on(e,t,n){const r=tn(e),o=nn(r,t);if(!o)return;const a=_t(e),i=en(t,"rowspan"),l=n?o.row+i:o.row,s=e.ownerDocument.createElement("tr"),c=new Set;for(let t=0;t<r.cols;t++){const n=l>0?r.slots[l-1]?.[t]:void 0,o=r.slots[l]?.[t];n&&n===o?c.has(n)||(c.add(n),n.setAttribute("rowspan",String(en(n,"rowspan")+1))):s.appendChild(rn(e.ownerDocument))}const d=a[l];d?d.parentNode.insertBefore(s,d):a[a.length-1].parentNode.appendChild(s)}function an(e,t,n){const r=tn(e),o=nn(r,t);if(!o)return;const a=n?o.col+en(t,"colspan"):o.col,i=new Set;r.slots.forEach((t,n)=>{const r=a>0?t[a-1]:void 0,o=t[a];if(r&&r===o)return void(i.has(r)||(i.add(r),r.setAttribute("colspan",String(en(r,"colspan")+1))));if(o&&o.parentElement!==_t(e)[n])return;const l=_t(e)[n],s=t.slice(a).find(e=>e.parentElement===l);l.insertBefore(rn(e.ownerDocument),s??null)}),ln(e,r.cols+1,a,null)}function ln(e,t,n,r){const o=e.querySelector(":scope > colgroup");if(!o)return;const a=Array.from(o.children);if(null!==r&&a[r]?.remove(),null!==n){const t=e.ownerDocument.createElement("col"),r=a[Math.min(n,a.length-1)];r?.getAttribute("style")&&t.setAttribute("style",r.getAttribute("style")),o.insertBefore(t,a[n]??null)}o.children.length!==t&&o.remove()}import{Fragment as sn,jsx as cn,jsxs as dn}from"react/jsx-runtime";var un=["Calibri","Arial","Cambria","Courier New","Georgia","Tahoma","Times New Roman","Verdana"],mn=[8,9,10,10.5,11,12,14,16,18,20,22,24,28,32,36,48,72],fn=[1,1.15,1.5,2,2.5,3],pn=[50,75,90,100,110,125,150,200],hn="p,h1,h2,h3,h4,h5,h6,li,blockquote,pre",gn=/^(https?:|mailto:|tel:)/i,wn={bold:!1,italic:!1,underline:!1,strike:!1,sub:!1,sup:!1,ul:!1,ol:!1,align:"left",font:"",size:null,styleId:null,color:""};function bn({sessionKey:d,doc:m,filename:f,images:p,fileEntries:h,title:g,startsDirty:w,dirty:b,onDirty:v,onOpenFile:y,onNewImageUrl:x,onClose:C,stored:k,onReload:S}){const N=u(),A=Se(),$=re().replace(/[^a-zA-Z0-9]/g,""),L=ae(null),T=ae(null),M=ae(null),z=ae(new zt),R=ae(null),P=ae(null),j=ae(null),D=ae(!!w),O=ae(0),F=ae(()=>{}),I=ae(null),H=ae(0),B=ae(k?.version??""),U=ae(null),[W,q]=ie({page:m.page,header:m.header.text,footer:m.footer.text}),[K,G]=ie(wn),[V,Q]=ie({undo:!1,redo:!1}),[X,Y]=ie({words:0,pageNow:1}),[J,Z]=ie([0]),[_,ee]=ie([]),[Ne,Ae]=ie(!1),[$e,Le]=ie(100),[Te,Me]=ie(!1),[ze,Re]=ie(!0),[Pe,je]=ie(!1),[De,Oe]=ie({rows:0,cols:0}),[Fe,Ie]=ie(null),[He,Ue]=ie(null),[We,qe]=ie(!1),[Ke,Ge]=ie(""),[Ve,Qe]=ie(""),[Xe,Ye]=ie(!1),[Je,Ze]=ie(0),[_e,et]=ie(0),tt=ae([]),nt=(W.page.width-W.page.left-W.page.right)/20,rt=e=>!!e&&!!T.current?.contains(e),ot=te(()=>{const e=T.current,t=document.getSelection();if(!(e&&t?.anchorNode&&t.focusNode&&rt(t.anchorNode))){const t=R.current;if(!e||!t)return null;const n=Rt(e,t.startContainer,t.startOffset),r=Rt(e,t.endContainer,t.endOffset);return n&&r?{anchor:n,focus:r}:null}const n=Rt(e,t.anchorNode,t.anchorOffset),r=Rt(e,t.focusNode,t.focusOffset);return n&&r?{anchor:n,focus:r}:null},[]),at=te(e=>{const t=T.current,n=document.getSelection();if(!t||!n||!e)return;const r=Pt(t,e.anchor),o=Pt(t,e.focus);r&&o&&n.setBaseAndExtent(r.node,r.offset,o.node,o.offset)},[]),it=te(e=>{const t=T.current;if(!t)return;const n=document.getSelection(),r=!e&&!!n&&rt(n.anchorNode);if(document.activeElement!==t&&t.focus({preventScroll:!0}),r&&n?.rangeCount)return void(R.current=n.getRangeAt(0).cloneRange());const o=e??R.current;n&&o&&(n.removeAllRanges(),n.addRange(o),R.current=o.cloneRange())},[]),lt=te(()=>{const e=T.current,t=R.current;if(!e||!t)return[];const n=Array.from(e.querySelectorAll(hn)).filter(e=>!e.closest("[data-locked]"));var r;return(t.collapsed?[(r=t.startContainer,(1===r.nodeType?r:r.parentElement)?.closest(hn))].filter(Boolean):n.filter(e=>t.intersectsNode(e))).filter(e=>rt(e)&&!e.closest("[data-locked]"))},[]),st=te(()=>{cancelAnimationFrame(O.current),O.current=requestAnimationFrame(()=>{const n=T.current;if(!n)return;const o=n.getBoundingClientRect().height/(n.offsetHeight||1)||1,i=n.getBoundingClientRect().top+W.page.top/20*(4/3)*o,l=(W.page.height-W.page.top-W.page.bottom)/20*(4/3),s=a(r(n,i,o),l);Z(e=>e.length===s.length&&e.every((e,t)=>e===s[t])?e:s);const c=document.getSelection();let d=1;if(c?.rangeCount&&rt(c.anchorNode)){const e=c.getRangeAt(0).getClientRects()[0]??c.anchorNode?.getBoundingClientRect?.();if(e){const t=(e.top-i)/o;for(let e=0;e<s.length;e++)s[e]<=t+1&&(d=e+1)}}Y({words:e(t(n)),pageNow:d});const u=function(e){return jt(e).map(e=>({level:Number(e.tagName[1]),text:(e.textContent??"").trim().replace(/\s+/g," ")}))}(n);ee(e=>{return n=u,(t=e).length===n.length&&t.every((e,t)=>e.level===n[t].level&&e.text===n[t].text)?e:u;var t,n})})},[W.page]),ct=te(()=>{const e=document.getSelection();if(!e?.anchorNode||!rt(e.anchorNode))return;const t=1===e.anchorNode.nodeType?e.anchorNode:e.anchorNode.parentElement;if(!t)return;const n=getComputedStyle(t),r=t.closest(hn),o=e=>{try{return document.queryCommandState(e)}catch{return!1}},a=n.textAlign,i=.75*parseFloat(n.fontSize);G({bold:o("bold"),italic:o("italic"),underline:o("underline"),strike:o("strikeThrough"),sub:o("subscript"),sup:o("superscript"),ul:o("insertUnorderedList"),ol:o("insertOrderedList"),align:"center"===a||"right"===a||"justify"===a?a:"left",font:n.fontFamily.split(",")[0].replace(/["']/g,"").trim(),size:i?Math.round(2*i)/2:null,styleId:r?.getAttribute("data-pstyle")??null,color:It(n.color)})},[]),dt=async()=>{const e=I.current;if(!e)throw new Error("No page");if(!D.current&&W.page===m.page&&m.source)return m.source;const t=H.current,n=await yt(m,e,{page:W.page,headerText:W.header,footerText:W.footer,images:p});return D.current&&H.current===t&&(m.source=n,D.current=!1,q(e=>({...e,page:m.page}))),n},ut=ce(),mt=se({debounceMs:1500,maxWaitMs:4e3,save:async()=>{k&&(B.current=await k.store.save(k.id,await dt(),B.current))},onFailure:(e,t)=>{e instanceof c?(mt.stop(),Ae(!0)):0===t&&ke.error(N.saveFailed)}}),{push:ft,flush:pt}=mt,ht=!!k,gt=mt.state.pending;ne(()=>{ht&&v(gt||Ne)},[Ne,ht,v,gt]),ne(()=>()=>{pt()},[pt]);const wt=te(()=>{D.current=!0,H.current+=1,v(!0),ht&&ft(H.current),st(),Q({undo:z.current.canUndo,redo:z.current.canRedo})},[ht,st,v,ft]),bt=te(()=>({html:T.current?.innerHTML??"",caret:ot()}),[ot]),vt=()=>{P.current&&clearTimeout(P.current),P.current=null},Ct=te(e=>{e&&T.current&&(T.current.innerHTML=e.html,T.current.focus({preventScroll:!0}),at(e.caret),vt(),wt(),ct())},[at,wt,ct]),kt=te(()=>Ct(z.current.undo(bt())),[Ct,bt]),St=te(()=>Ct(z.current.redo(bt())),[Ct,bt]),Nt=te(e=>{it(),vt(),z.current.record(bt()),e(),wt(),ct()},[wt,ct,it,bt]),At=te((e,t)=>Nt(()=>{document.execCommand(e,!1,t)}),[Nt]),$t=e=>Nt(()=>{document.execCommand(e);const t=T.current;if(!t)return;const n=document.getSelection(),r=n?.anchorNode??null,o=n?.anchorOffset??0;let a=!1;t.querySelectorAll("p > ul, p > ol").forEach(e=>{const t=e.parentElement;Array.from(t.childNodes).some(t=>t!==e&&(1===t.nodeType||(t.nodeValue??"").trim()))||(t.replaceWith(e),a=!0)}),a&&r&&n?.collapse(r,o)});ne(()=>{const e=T.current;if(!e)return;I.current=e,e.innerHTML=m.html;try{document.execCommand("defaultParagraphSeparator",!1,"p"),document.execCommand("styleWithCSS",!1,"true")}catch{}e.focus({preventScroll:!0});const t=e.querySelector(hn);t&&document.getSelection()?.collapse(t,0),st();const n=t=>"historyUndo"===t.inputType?(t.preventDefault(),void kt()):"historyRedo"===t.inputType?(t.preventDefault(),void St()):(P.current?clearTimeout(P.current):z.current.record({html:e.innerHTML,caret:ot()}),void(P.current=setTimeout(()=>{P.current=null},600))),r=()=>{(()=>{const t=j.current;e.querySelectorAll('font[size="7"]').forEach(e=>{const n=document.createElement("span");for(n.setAttribute("style",`font-size:${t??11}pt`);e.firstChild;)n.appendChild(e.firstChild);e.replaceWith(n),3===n.lastChild?.nodeType&&document.getSelection()?.collapse(n.lastChild,(n.lastChild.nodeValue??"").length)})})(),wt(),ct()},o=()=>{const e=document.getSelection();e?.rangeCount&&rt(e.anchorNode)&&(R.current=e.getRangeAt(0).cloneRange(),ct(),st())};e.addEventListener("beforeinput",n),e.addEventListener("input",r),document.addEventListener("selectionchange",o);const a=new ResizeObserver(()=>st());return a.observe(e),()=>{e.removeEventListener("beforeinput",n),e.removeEventListener("input",r),document.removeEventListener("selectionchange",o),a.disconnect(),cancelAnimationFrame(O.current),vt(),U.current&&clearTimeout(U.current)}},[]),ne(()=>{st()},[st]),ne(()=>{w&&v(!0)},[]);const Lt=e=>Nt(()=>{const t=ot(),n=e?/^heading ([1-6])$/i.exec(m.styles.find(t=>t.id===e)?.name??"")?.[1]:void 0,r=n?`H${n}`:"P";for(const t of lt()){if("LI"===t.tagName){e?t.setAttribute("data-pstyle",e):t.removeAttribute("data-pstyle");continue}let n=t;if(t.tagName!==r){n=document.createElement(r);for(const e of Array.from(t.attributes))n.setAttribute(e.name,e.value);for(;t.firstChild;)n.appendChild(t.firstChild);t.replaceWith(n)}e?n.setAttribute("data-pstyle",e):n.removeAttribute("data-pstyle")}at(t)}),Tt=e=>Nt(()=>{const t=lt(),n=t.filter(e=>"LI"===e.tagName);if(n.length){const t=document.getSelection(),r=t?.anchorNode??null,o=t?.anchorOffset??0;for(const t of e?n:[...n].reverse())e?Jt(t):Zt(t);return void(r&&t?.collapse(r,o))}for(const n of t){const t=parseFloat(n.style.marginLeft)||0,r=Math.max(0,t+(e?36:-36));n.style.marginLeft=r?`${r}pt`:""}}),Mt=e=>At({left:"justifyLeft",center:"justifyCenter",right:"justifyRight",justify:"justifyFull"}[e]),Ht=async e=>{for(const t of e){if(!t.type.startsWith("image/"))continue;const e=new Uint8Array(await t.arrayBuffer()),n=URL.createObjectURL(new Blob([e],{type:t.type}));x(n),p.set(n,{bytes:e,mime:t.type});const r=new Image;r.src=n,await r.decode().catch(()=>{});const o=.75*r.naturalWidth,a=Math.min(o||nt,nt),i=o?a*(r.naturalHeight/r.naturalWidth):0;At("insertHTML",`<img src="${n}" alt="" style="width:${Math.round(100*a)/100}pt${i?`;height:${Math.round(100*i)/100}pt`:""}">`)}},Bt=async()=>{it();const e=R.current?.cloneRange()??null,t=e?.startContainer?1===e.startContainer.nodeType?e.startContainer:e.startContainer.parentElement:null,n=t?.closest("a")??null,r=await xe({title:N.link,message:N.linkPrompt,placeholder:"https://example.com",defaultValue:n?.getAttribute("href")??"",confirmLabel:N.ok,cancelLabel:N.cancel,allowEmpty:!0});if(await new Promise(e=>setTimeout(e,0)),it(e),null===r)return;const o=r.trim();if(!o)return void(n&&At("unlink"));const a=/^[a-z][a-z0-9+.-]*:/i.test(o)?o:`https://${o}`;if(gn.test(a))if(n)Nt(()=>{n.setAttribute("href",a)});else if(e?.collapsed){const e=document.createElement("a");e.href=a,e.textContent=o,At("insertHTML",e.outerHTML)}else At("createLink",a);else ke.error(N.linkInvalid)},Ut=()=>At("insertHTML",'<span data-page-break="" contenteditable="false"></span>​'),Wt=(e,t)=>{je(!1);const n=function(e,t,n,r){const o=e.createElement("table"),a=e.createElement("colgroup");for(let t=0;t<n;t++){const t=e.createElement("col");t.setAttribute("style",`width:${Math.round(r/n*100)/100}pt`),a.appendChild(t)}o.appendChild(a);const i=e.createElement("tbody");for(let r=0;r<t;r++){const t=e.createElement("tr");for(let r=0;r<n;r++)t.appendChild(rn(e));i.appendChild(t)}return o.appendChild(i),o}(document,e,t,nt);n.setAttribute("data-new",""),At("insertHTML",`${n.outerHTML}<p><br></p>`);const r=T.current?.querySelector("table[data-new]");if(r){r.removeAttribute("data-new");const e=r.querySelector("td p");e&&document.getSelection()?.collapse(e,0)}};F.current=e=>{Ht(e)};const qt=e=>{if(!Fe)return;const t=Fe.el;Nt(()=>{const n=.75*t.naturalWidth,r=null===e?n:nt*e,o=t.naturalWidth?t.naturalHeight/t.naturalWidth:.75;t.removeAttribute("width"),t.removeAttribute("height"),t.style.width=Math.round(100*r)/100+"pt",t.style.height=Math.round(r*o*100)/100+"pt"}),Ie(null)},Kt=te((e,t)=>{const n=tt.current,r=e=>{const t=document.createRange();return t.setStart(e[0].node,e[0].start),t.setEnd(e[e.length-1].node,e[e.length-1].end),t},o=globalThis.CSS?.highlights,a=globalThis.Highlight;o&&a&&(o.set("docs-find",new a(...n.map(r))),o.set("docs-find-current",new a(...n[e]?[r(n[e])]:[]))),t&&n[e]&&n[e][0].node.parentElement?.scrollIntoView({block:"center"})},[]),Gt=()=>{const e=globalThis.CSS?.highlights;e?.delete("docs-find"),e?.delete("docs-find-current")},Vt=te((e,t,r)=>{const o=T.current,a=o?n(o,e,t):[];tt.current=a,et(a.length);const i=a.length?Math.min(r,a.length-1):0;Ze(i),Kt(i,!0)},[Kt]),Qt=te(()=>{const e=tt.current[Je];qe(!1),Gt();const t=T.current;t?.focus({preventScroll:!0}),e&&document.getSelection()?.setBaseAndExtent(e[0].node,e[0].start,e[e.length-1].node,e[e.length-1].end),tt.current=[]},[Je]),Yt=()=>{const e=document.getSelection(),t=e&&rt(e.anchorNode)?e.toString():"";qe(!0);const n=t&&!t.includes("\n")?t:Ke;Ge(n),setTimeout(()=>Vt(n,Xe,0),0)},bn=ae(Qt);bn.current=Qt;const yn=ae(We);yn.current=We,ne(()=>Ce(()=>!(!yn.current||!L.current?.contains(document.activeElement))&&(bn.current(),!0)),[]),ne(()=>()=>Gt(),[]),ne(()=>{const e=e=>{const{key:t,files:n}=e.detail;t===d&&F.current(n)};return window.addEventListener("docs-insert-images",e),()=>window.removeEventListener("docs-insert-images",e)},[d]);const xn=k?f:(e=>e.replace(/\.[^.]+$/,"")||e)(f),Cn=`${xn}.docx`,kn=async()=>{try{const e=H.current;xt(await dt(),Cn,"application/vnd.openxmlformats-officedocument.wordprocessingml.document"),k||H.current!==e||v(!1)}catch{ke.error(N.saveFailed)}},Sn=e=>o({title:xn,html:e,doc:m,scope:$,page:W.page,header:W.header,footer:W.footer}),Nn=()=>{const e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.style.cssText="position:fixed;width:0;height:0;border:0;left:-10px;top:-10px",document.body.appendChild(e);const t=e.contentWindow;if(!t)return void e.remove();t.document.open(),t.document.write(Sn(T.current?.innerHTML??"")),t.document.close();const n=()=>{t.focus(),t.print(),setTimeout(()=>e.remove(),6e4)},r=Array.from(t.document.images).filter(e=>!e.complete);r.length?Promise.all(r.map(e=>e.decode().catch(()=>{}))).then(n):n()},An=h.length?[...h,{type:"divider",key:"d1"},{key:"save",label:cn(vn,{label:N.saveDocx,hint:"⌘S"}),onSelect:()=>{kn()}}]:[],$n=[{key:"docx",label:N.saveAsWord,onSelect:()=>{kn()}},{key:"pdf",label:N.saveAsPdf,onSelect:Nn},{key:"html",label:N.saveAsWeb,onSelect:()=>{(async()=>{const e=document.createElement("div");e.innerHTML=T.current?.innerHTML??"";for(const t of Array.from(e.querySelectorAll("img"))){const e=p.get(t.getAttribute("src")??"");if(!e)continue;let n="";for(let t=0;t<e.bytes.length;t+=32768)n+=String.fromCharCode(...e.bytes.subarray(t,t+32768));t.setAttribute("src",`data:${e.mime};base64,${btoa(n)}`)}e.querySelectorAll("[data-hidden]").forEach(e=>e.remove()),xt(Sn(e.innerHTML),`${xn}.html`,"text/html")})()}},{key:"txt",label:N.saveAsText,onSelect:()=>{xt(t(T.current),`${xn}.txt`,"text/plain")}}],Ln=[{key:"table",label:N.table,onSelect:()=>je(!0)},{key:"image",label:N.image,onSelect:()=>M.current?.click()},{key:"link",label:cn(vn,{label:N.link,hint:"⌘K"}),onSelect:()=>{Bt()}},{key:"break",label:cn(vn,{label:N.pageBreak,hint:"⌘↵"}),onSelect:Ut},{key:"number",label:N.pageNumber,onSelect:()=>Me(!0)},{key:"line",label:N.horizontalLine,onSelect:()=>At("insertHorizontalRule")}],Tn=[{key:"setup",label:N.pageSetup,onSelect:()=>Me(!0)}],Mn={Title:N.styleTitle,"heading 1":N.styleHeading1,"heading 2":N.styleHeading2,"heading 3":N.styleHeading3,Quote:N.styleQuote},En=[{key:"normal",label:N.styleNormal,onSelect:()=>Lt(null)},...m.styles.map(e=>({key:e.id,label:Mn[e.name]??e.name,onSelect:()=>Lt(e.id)}))],zn=oe(()=>Array.from(new Set([...m.defaultFont?[m.defaultFont]:[],...un])),[m.defaultFont]).map(e=>({key:e,label:cn("span",{style:{fontFamily:`"${e}"`},children:e}),onSelect:()=>At("fontName",e)})),Rn=mn.map(e=>({key:String(e),label:String(e),onSelect:()=>(e=>Nt(()=>{j.current=e,document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7"),document.execCommand("styleWithCSS",!1,"true");const t=T.current,n=[];if(t.querySelectorAll('font[size="7"]').forEach(t=>{const r=document.createElement("span");for(r.setAttribute("style",`font-size:${e}pt`);t.firstChild;)r.appendChild(t.firstChild);t.replaceWith(r),n.push(r)}),n.length){const e=document.getSelection();e?.setBaseAndExtent(n[0],0,n[n.length-1],n[n.length-1].childNodes.length)}}))(e)})),Pn=fn.map(e=>({key:String(e),label:e.toFixed(1.15===e?2:1),onSelect:()=>{return t=e,Nt(()=>{for(const e of lt())e.style.lineHeight=String(t)});var t}})),jn=e=>e.preventDefault(),Dn="rounded px-2 py-0.5 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",On="inline-flex h-7 items-center gap-1 rounded px-2 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",Fn=cn("div",{className:"mx-1 h-4 w-px bg-line"}),In=(e,t,n,r={})=>cn(he,{"aria-label":e,title:e,size:"sm",variant:"ghost",onMouseDown:jn,onClick:n,disabled:r.disabled,...void 0!==r.pressed?{"aria-pressed":r.pressed}:{},children:t}),Hn=(e,t,n,r="")=>cn(pe,{"aria-label":e,align:"start",items:n,triggerClassName:On,trigger:dn("span",{title:e,className:`flex items-center justify-between gap-1 ${r}`,children:[cn("span",{className:"truncate",children:t}),cn(de,{name:"chevron-down",size:12})]})}),Bn=(e,t,n,r,o)=>cn(ge,{triggerLabel:e,align:"start",triggerClassName:"inline-flex h-7 w-7 flex-col items-center justify-center rounded text-ink-muted hover:bg-line-subtle hover:text-ink",trigger:dn(sn,{children:[t,cn("span",{className:"h-0.5 w-4 rounded-sm",style:{background:n}})]}),children:({close:t})=>cn(me,{label:e,value:"",presets:r,clearable:!0,dragWrites:"end",onChange:e=>{"hiliteColor"===o?At("hiliteColor",e||"transparent"):At("foreColor",e||Dt[0]),Wn(t=>({...t,[o]:e||("hiliteColor"===o?"var(--line)":"var(--ink)")})),t()}})}),[Un,Wn]=ie({foreColor:"var(--ink)",hiliteColor:"var(--line)"}),qn=E(W.page),Kn=qn?{a4:"A4",a3:"A3",a5:"A5",letter:N.paperLetter,legal:N.paperLegal}[qn]:N.custom,Gn=oe(()=>{if(!m.lang)return"";try{return new Intl.DisplayNames(A?[A]:void 0,{type:"language"}).of(m.lang)??m.lang}catch{return m.lang}},[m.lang,A]),Vn=W.page.width/20,Qn=W.page.top/20,Xn=W.header.split(/\s*\|\s*/),Yn=W.footer.split(/\s*\|\s*/),Jn=(e,t)=>e.replace(/\{page\}/g,String(t)).replace(/\{pages\}/g,String(J.length)),Zn=m.notices,_n=[Zn.comments&&N.noticeComments(Zn.comments),Zn.tracked&&N.noticeTracked(Zn.tracked),Zn.objects&&N.noticeObjects(Zn.objects),Zn.footnotes&&N.noticeFootnotes(Zn.footnotes)].filter(Boolean);return dn("div",{ref:L,className:"es-editor docs-frame",onKeyDown:e=>{const t=e.metaKey||e.ctrlKey,n=e.key.toLowerCase(),r=rt(e.target),o=()=>{e.preventDefault(),e.stopPropagation()};if(t&&!e.altKey){if("s"===n)return o(),void(k?pt():kn());if("o"===n)return o(),void y();if("p"===n)return o(),void Nn();if("f"===n)return o(),void Yt();if("k"===n)return o(),void Bt();if(r){if("z"===n&&!e.shiftKey)return o(),void kt();if("z"===n&&e.shiftKey||"y"===n)return o(),void St();if("b"===n)return o(),void At("bold");if("i"===n)return o(),void At("italic");if("u"===n)return o(),void At("underline");if("Enter"===e.key)return o(),void Ut()}}if(r&&"Tab"===e.key&&!t&&!e.altKey){const t=document.getSelection(),n=t?.anchorNode?1===t.anchorNode.nodeType?t.anchorNode:t.anchorNode.parentElement:null,r=n?.closest("td,th");if(r)return o(),void((e,t)=>{const n=Array.from(e.closest("table").querySelectorAll("td,th")),r=n[n.indexOf(e)+(t?1:-1)];if(r){const e=document.createRange();e.selectNodeContents(r);const t=document.getSelection();t?.removeAllRanges(),t?.addRange(e)}else t&&Nt(()=>on(e.closest("table"),e,!0))})(r,!e.shiftKey);if(n?.closest("li"))return o(),void Tt(!e.shiftKey);if(!e.shiftKey)return o(),void At("insertText","\t")}},children:[cn("style",{children:i(m,$)}),cn("input",{ref:M,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files?.length&&Ht(Array.from(e.target.files)),e.target.value=""}}),cn(Be,{onClose:C,fileMenu:An,name:g,saveState:k?le(mt.state,ut.save):{tone:b?"off-unsaved":"off",label:b?N.noStoreEdited:N.noStoreClean},canUndo:V.undo,canRedo:V.redo,onUndo:kt,onRedo:St,exportControl:cn(pe,{"aria-label":N.export,align:"end",items:$n,triggerClassName:"docs-export-trigger",trigger:dn(sn,{children:[cn(de,{name:"download",size:16}),N.export]})})}),Ne&&dn("div",{className:"docs-conflict",role:"alert",children:[cn("span",{children:N.conflict}),cn(ue,{variant:"secondary",onClick:S,children:N.reload})]}),dn("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1",children:[cn(pe,{trigger:N.menuInsert,items:Ln,align:"start",triggerClassName:Dn}),cn(ge,{open:Pe,onOpenChange:je,align:"start",triggerLabel:N.table,triggerClassName:"h-5 w-0 overflow-hidden",trigger:cn("span",{}),children:dn("div",{className:"p-1",children:[cn("div",{className:"mb-1 text-xs text-ink-muted",children:De.rows?N.tableSize(De.cols,De.rows):N.table}),cn("div",{className:"grid gap-0.5",style:{gridTemplateColumns:"repeat(8, 1fr)"},onMouseLeave:()=>Oe({rows:0,cols:0}),children:Array.from({length:48},(e,t)=>{const n=Math.floor(t/8)+1,r=t%8+1,o=n<=De.rows&&r<=De.cols;return cn("button",{type:"button","aria-label":N.tableSize(r,n),onMouseEnter:()=>Oe({rows:n,cols:r}),onFocus:()=>Oe({rows:n,cols:r}),onClick:()=>Wt(n,r),className:"h-4 w-4 rounded-sm border "+(o?"border-accent-fill bg-accent-tint-strong":"border-line bg-surface")},t)})})]})}),cn(pe,{trigger:N.menuLayout,items:Tn,align:"start",triggerClassName:Dn}),Fn,In(N.print,cn(de,{name:"print",size:16}),Nn),In(N.find,cn(de,{name:"search",size:16}),()=>We?Qt():Yt(),{pressed:We}),Fn,Hn(N.paragraphStyle,(e=>{if(!e)return N.styleNormal;const t=m.styles.find(t=>t.id===e);return t?Mn[t.name]??t.name:e})(K.styleId),En,"w-20"),Hn(N.font,K.font||m.defaultFont||"Calibri",zn,"w-20"),Hn(N.fontSize,K.size??m.defaultSize??11,Rn),Fn,In(N.bold,cn(de,{name:"bold",size:16}),()=>At("bold"),{pressed:K.bold}),In(N.italic,cn(de,{name:"italic",size:16}),()=>At("italic"),{pressed:K.italic}),In(N.underline,cn(de,{name:"underline",size:16}),()=>At("underline"),{pressed:K.underline}),In(N.strikethrough,cn(de,{name:"strike",size:16}),()=>At("strikeThrough"),{pressed:K.strike}),In(N.superscript,cn(de,{name:"superscript",size:16}),()=>At("superscript"),{pressed:K.sup}),In(N.subscript,cn(de,{name:"subscript",size:16}),()=>At("subscript"),{pressed:K.sub}),Bn(N.textColor,cn(de,{name:"text-color",size:14}),Un.foreColor,Dt,"foreColor"),Bn(N.highlight,cn(de,{name:"palette",size:14}),Un.hiliteColor,Ot,"hiliteColor"),In(N.clearFormatting,cn(de,{name:"clear-marks",size:16}),()=>Nt(()=>{document.execCommand("removeFormat");for(const e of lt())e.style.removeProperty("text-align"),e.style.removeProperty("line-height"),e.style.removeProperty("margin-left")})),Fn,In(N.bulletedList,cn(de,{name:"list",size:16}),()=>$t("insertUnorderedList"),{pressed:K.ul}),In(N.numberedList,cn(de,{name:"numbered-list",size:16}),()=>$t("insertOrderedList"),{pressed:K.ol}),In(N.decreaseIndent,cn(de,{name:"chevron-double-left",size:16}),()=>Tt(!1)),In(N.increaseIndent,cn(de,{name:"chevron-double-right",size:16}),()=>Tt(!0)),Fn,In(N.alignLeft,cn(de,{name:"align-left",size:16}),()=>Mt("left"),{pressed:"left"===K.align}),In(N.alignCenter,cn(de,{name:"align-center",size:16}),()=>Mt("center"),{pressed:"center"===K.align}),In(N.alignRight,cn(de,{name:"align-right",size:16}),()=>Mt("right"),{pressed:"right"===K.align}),In(N.justify,cn(de,{name:"align-justify",size:16}),()=>Mt("justify"),{pressed:"justify"===K.align}),cn(pe,{"aria-label":N.lineSpacing,align:"start",items:Pn,triggerClassName:On,trigger:dn("span",{title:N.lineSpacing,className:"flex items-center gap-0.5",children:[cn(de,{name:"line-spacing",size:16}),cn(de,{name:"chevron-down",size:12})]})})]}),ze&&_n.length>0&&dn("div",{role:"status",className:"flex shrink-0 items-center gap-2 border-b border-status-warning-line bg-status-warning-soft px-3 py-1 text-xs text-status-warning-soft-ink",children:[cn(de,{name:"info",size:14}),cn("span",{className:"min-w-0 flex-1",children:N.noticeLead(_n)}),cn(he,{size:"sm",variant:"ghost",ink:"inherit","aria-label":N.dismiss,title:N.dismiss,onClick:()=>Re(!1),children:cn(de,{name:"close",size:14})})]}),We&&cn(Et,{query:Ke,replacement:Ve,matchCase:Xe,current:Je,total:_e,onQuery:e=>{Ge(e),Vt(e,Xe,0)},onReplacement:Qe,onMatchCase:e=>{Ye(e),Vt(Ke,e,0)},onStep:e=>{const t=tt.current.length;if(!t)return;const n=(Je+(e?1:-1)+t)%t;Ze(n),Kt(n,!0)},onReplace:()=>{const e=tt.current[Je];e&&(z.current.record(bt()),l(e,Ve),wt(),Vt(Ke,Xe,Je))},onReplaceAll:()=>{const e=tt.current;if(e.length){z.current.record(bt());for(let t=e.length-1;t>=0;t--)l(e[t],Ve);wt(),ke.success(N.replacedCount(e.length)),Vt(Ke,Xe,0)}},onClose:Qt}),dn("div",{className:"docs-body",children:[dn("div",{className:"docs-centre",children:[cn("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken px-6 py-6",children:dn("div",{className:"docs-sheet relative mx-auto shadow",style:{width:`${Vn}pt`,zoom:$e/100,minHeight:W.page.height/20+"pt"},children:[W.header&&dn("div",{className:"pointer-events-none absolute flex justify-between gap-4 text-xs","aria-hidden":"true",style:{top:W.page.header/20+"pt",left:W.page.left/20+"pt",right:W.page.right/20+"pt"},children:[cn("span",{children:Jn(Xn[0],1)}),void 0!==Xn[1]&&cn("span",{children:Jn(Xn[1],1)})]}),cn("div",{ref:T,contentEditable:!0,suppressContentEditableWarning:!0,spellCheck:!0,lang:m.lang,role:"textbox","aria-multiline":"true","aria-label":f,"data-doc":$,onPaste:e=>{(async e=>{const t=Array.from(e.clipboardData?.items??[]).filter(e=>"file"===e.kind&&e.type.startsWith("image/")).map(e=>e.getAsFile()).filter(e=>!!e),n=e.clipboardData?.getData("text/html");if(n){e.preventDefault();const t=document.createElement("div");t.innerHTML=s(n);for(const e of Array.from(t.querySelectorAll("img"))){const t=e.getAttribute("src")??"";if(t.startsWith("blob:")&&!p.has(t))try{const e=await(await fetch(t)).blob();p.set(t,{bytes:new Uint8Array(await e.arrayBuffer()),mime:e.type})}catch{e.remove()}}return void At("insertHTML",t.innerHTML)}t.length&&(e.preventDefault(),Ht(t))})(e)},onClick:e=>{const t=e.target;if("IMG"===t.tagName&&null===t.closest('[contenteditable="false"]')&&!t.getAttribute("contenteditable"))return e.preventDefault(),void Ie({x:e.clientX,y:e.clientY,el:t});const n=t.closest("a");if(n&&(e.metaKey||e.ctrlKey)){const e=n.getAttribute("href")??"";gn.test(e)&&window.open(e,"_blank","noopener,noreferrer")}},onContextMenu:e=>{const t=e.target.closest?.("td,th");t&&!e.shiftKey&&!t.closest("[data-locked]")&&rt(t)&&(e.preventDefault(),Ue({x:e.clientX,y:e.clientY,cell:t}))},className:"docs-page",style:{paddingTop:`${Qn}pt`,paddingRight:W.page.right/20+"pt",paddingBottom:W.page.bottom/20+"pt",paddingLeft:W.page.left/20+"pt",minHeight:W.page.height/20+"pt",boxSizing:"border-box"}}),J.slice(1).map((e,t)=>cn("div",{className:"docs-sheet-line pointer-events-none absolute left-0 right-0 border-t border-dashed","aria-hidden":"true",style:{top:`calc(${Qn}pt + ${e}px)`},children:cn("span",{className:"docs-sheet absolute right-1 -top-2 px-1 text-2xs",children:N.pageLabel(t+2)})},e)),W.footer&&dn("div",{className:"pointer-events-none absolute flex justify-between gap-4 text-xs","aria-hidden":"true",style:{bottom:W.page.footer/20+"pt",left:W.page.left/20+"pt",right:W.page.right/20+"pt"},children:[cn("span",{children:Jn(Yn[0],J.length)}),void 0!==Yn[1]&&cn("span",{children:Jn(Yn[1],J.length)})]})]})}),dn("div",{className:"flex shrink-0 items-center gap-2 border-t border-line bg-surface-sunken px-3 py-1 text-xs text-ink-muted",children:[cn("span",{children:N.pageOf(Math.min(X.pageNow,J.length),J.length)}),cn("span",{children:N.wordCount(X.words)}),cn("span",{children:Kn}),Gn&&cn("span",{children:Gn}),dn("span",{className:"ml-auto flex items-center gap-1",children:[cn(ue,{size:"sm",variant:"ghost","aria-label":N.zoomOut,onClick:()=>Le(e=>[...pn].reverse().find(t=>t<e)??e),children:"−"}),dn("span",{className:"w-9 text-center tabular-nums",children:[$e,"%"]}),cn(ue,{size:"sm",variant:"ghost","aria-label":N.zoomIn,onClick:()=>Le(e=>pn.find(t=>t>e)??e),children:"+"})]})]})]}),cn(Ee,{page:W.page,onPage:e=>{q(t=>({...t,page:e})),wt()},onMorePageSetup:()=>Me(!0),colour:K.color,onColour:e=>{G(t=>({...t,color:e})),Wn(t=>({...t,foreColor:e})),U.current&&clearTimeout(U.current),U.current=setTimeout(()=>{U.current=null,At("foreColor",e)},150)},outline:_,onHeading:e=>{const t=T.current;t&&jt(t)[e]?.scrollIntoView({block:"start"})}})]}),Te&&cn(Xt,{value:W,headerEditable:m.header.editable,footerEditable:m.footer.editable,onClose:()=>Me(!1),onApply:e=>{q(e),Me(!1),wt()}}),Fe&&dn(we,{minWidth:150,portal:!0,style:{position:"fixed",left:Fe.x,top:Fe.y},onClose:()=>Ie(null),children:[cn(ye,{children:N.imageWidth}),cn(ve,{onClick:()=>qt(.25),children:"25%"}),cn(ve,{onClick:()=>qt(.5),children:"50%"}),cn(ve,{onClick:()=>qt(.75),children:"75%"}),cn(ve,{onClick:()=>qt(1),children:"100%"}),cn(ve,{onClick:()=>qt(null),children:N.imageOriginalSize}),cn(be,{}),cn(ve,{danger:!0,onClick:()=>{if(!Fe)return;const e=Fe.el;Nt(()=>{e.remove()}),Ie(null)},children:N.imageRemove})]}),He&&cn(fe,{at:{x:He.x,y:He.y},owner:He.cell,onClose:()=>Ue(null),items:(e=>{const t=e.closest("table"),n=(e,t,n,r={})=>({key:e,label:t,onSelect:()=>Nt(n),...r}),r=(e=>{const t=R.current;return t?Array.from(e.querySelectorAll("td,th")).filter(n=>n.closest("table")===e&&t.intersectsNode(n)):[]})(t);return[n("above",N.rowAbove,()=>on(t,e,!1)),n("below",N.rowBelow,()=>on(t,e,!0)),n("left",N.columnLeft,()=>an(t,e,!1)),n("right",N.columnRight,()=>an(t,e,!0)),{type:"divider",key:"d1"},n("merge",N.mergeCells,()=>{(function(e,t){if(t.length<2)return!1;const n=tn(e);let r=1/0,o=1/0,a=-1,i=-1;for(const e of t){const t=nn(n,e);if(!t)return!1;r=Math.min(r,t.row),o=Math.min(o,t.col),a=Math.max(a,t.row+en(e,"rowspan")-1),i=Math.max(i,t.col+en(e,"colspan")-1)}const l=new Set;for(let e=r;e<=a;e++)for(let t=o;t<=i;t++){const r=n.slots[e]?.[t];r&&l.add(r)}for(const e of l){const t=nn(n,e);if(t.row<r||t.col<o||t.row+en(e,"rowspan")-1>a||t.col+en(e,"colspan")-1>i)return!1}const s=n.slots[r][o];for(const e of l)if(e!==s){if((e.textContent??"").trim())for(;e.firstChild;)s.appendChild(e.firstChild);e.remove()}return s.setAttribute("colspan",String(i-o+1)),s.setAttribute("rowspan",String(a-r+1)),i===o&&s.removeAttribute("colspan"),a===r&&s.removeAttribute("rowspan"),!0})(t,r)||ke.error(N.mergeFailed)},{disabled:r.length<2}),{type:"submenu",key:"shade",label:N.cellShading,items:[...Ft.map(t=>({key:t,label:dn("span",{className:"flex items-center gap-2",children:[cn("span",{className:"h-3 w-5 rounded-sm border border-line",style:{background:t}}),t.toUpperCase()]}),onSelect:()=>Nt(()=>{for(const n of r.length?r:[e])n.style.backgroundColor=t})})),{key:"none",label:N.noColor,onSelect:()=>Nt(()=>{for(const t of r.length?r:[e])t.style.removeProperty("background-color")})}]},{type:"divider",key:"d2"},n("delRow",N.deleteRow,()=>{!function(e,t){const n=tn(e),r=nn(n,t);if(!r)return!1;const o=_t(e);if(1===o.length)return e.remove(),!1;const a=new Set;for(let e=0;e<n.cols;e++){const t=n.slots[r.row][e];if(!t||a.has(t))continue;a.add(t);const i=en(t,"rowspan");if(1!==i)if(t.parentElement===o[r.row]){const a=o[r.row+1],l=n.slots[r.row+1].slice(e+en(t,"colspan")).find(e=>e.parentElement===a);t.setAttribute("rowspan",String(i-1)),a.insertBefore(t,l??null)}else t.setAttribute("rowspan",String(i-1))}o[r.row].remove()}(t,e)}),n("delCol",N.deleteColumn,()=>{!function(e,t){const n=tn(e),r=nn(n,t);if(!r)return!1;if(1===n.cols)return e.remove(),!1;const o=new Set;for(const e of n.slots){const t=e[r.col];if(!t||o.has(t))continue;o.add(t);const n=en(t,"colspan");n>1?t.setAttribute("colspan",String(n-1)):t.remove()}ln(e,n.cols-1,null,r.col)}(t,e)}),n("delTable",N.deleteTable,()=>{t.remove()},{danger:!0})]})(He.cell)})]})}function vn({label:e,hint:t}){return dn("span",{className:"flex w-full items-center justify-between gap-4",children:[cn("span",{children:e}),cn("span",{className:"text-2xs text-ink-faint",children:t})]})}import{useEffect as yn,useRef as xn,useState as Cn}from"react";import{Icon as kn}from"efficient-shell/icons";import{Button as Sn,IconButton as Nn,registerModalEscapeInterceptor as An,toast as $n}from"efficient-shell/ui";var Ln={LF:"\n",CRLF:"\r\n",CR:"\r"};function Tn(e,t){let n=1,r=-1;for(let o=e.indexOf("\n");o>=0&&o<t;o=e.indexOf("\n",o+1))n++,r=o;return{line:n,col:t-r}}function Mn(e){let t=1;for(let n=e.indexOf("\n");n>=0;n=e.indexOf("\n",n+1))t++;return t}import{jsx as En,jsxs as zn}from"react/jsx-runtime";function Rn({filename:e,decoded:t,bytes:n,fileEntries:r,title:o,dirty:a,onDirty:i,onOpenFile:l,onClose:s}){const c=u(),d=xn(null),m=xn(null),f=xn(t.text),p=xn(!1),[h,g]=Cn(!0),[w,b]=Cn(!1),[v,y]=Cn({line:1,col:1,lines:Mn(t.text)}),[x,C]=Cn(!1),[k,S]=Cn(""),[N,A]=Cn(""),[$,L]=Cn(!1),[T,M]=Cn(0),[E,z]=Cn([]),R=()=>m.current?.value??"",P=xn(null),[j,D]=Cn(0),O=()=>{P.current&&m.current&&(P.current.scrollTop=m.current.scrollTop,P.current.scrollLeft=m.current.scrollLeft)};yn(()=>{const e=P.current?.querySelector("[data-current]"),t=m.current;if(!e||!t)return;const n=e.offsetTop-t.clientHeight/3;(e.offsetTop<t.scrollTop||e.offsetTop>t.scrollTop+t.clientHeight-42)&&(t.scrollTop=Math.max(0,n)),h||(t.scrollLeft=Math.max(0,e.offsetLeft-t.clientWidth/2)),O()},[j,T,E,h]);const F=()=>{const e=m.current;e&&y({...Tn(e.value,e.selectionStart),lines:Mn(e.value)})},I=(e=k,t=$)=>{const n=function(e,t,n){if(!t)return[];const r=n?e:e.toLowerCase(),o=n?t:t.toLowerCase(),a=r.length===e.length?r:e,i=[];for(let e=a.indexOf(o);e>=0;e=a.indexOf(o,e+Math.max(o.length,1)))i.push(e);return i}(R(),e,t);return z(n),n},H=(e,t,n=k)=>{const r=m.current;if(!r||!e.length)return;const o=(t%e.length+e.length)%e.length;M(o),r.setSelectionRange(e[o],e[o]+n.length),D(e=>e+1)},B=()=>{xt(p.current?function(e,t,n){const r=e.replace(/\n/g,Ln[n]);if("utf-16le"===t||"utf-16be"===t){const e=new Uint8Array(2+2*r.length),n=new DataView(e.buffer),o="utf-16le"===t;n.setUint16(0,65279,o);for(let e=0;e<r.length;e++)n.setUint16(2+2*e,r.charCodeAt(e),o);return e}const o=(new TextEncoder).encode(r);if("utf-8-bom"!==t)return o;const a=new Uint8Array(o.length+3);return a.set([239,187,191]),a.set(o,3),a}(R(),t.encoding,t.eol):n,e,"text/plain"),p.current&&"windows-1252"===t.encoding&&$n.info(c.savedAsUtf8),f.current=R(),i(!1)},U=()=>{p.current=!0,b(!0),i(R()!==f.current),F(),x&&I()},W=e=>{document.execCommand("insertText",!1,e)||m.current?.setRangeText(e,m.current.selectionStart,m.current.selectionEnd,"end"),U()},q=e=>{m.current?.focus(),document.execCommand(e)},K=()=>{C(!1),m.current?.focus()};yn(()=>{m.current?.focus(),m.current?.setSelectionRange(0,0)},[]);const G=xn(x);G.current=x,yn(()=>An(()=>!(!G.current||!d.current?.contains(document.activeElement))&&(K(),!0)),[]);const V=[...r,{type:"divider",key:"d1"},{key:"save",label:c.saveKeepType,onSelect:B}],Q=a?c.noStoreEdited:c.noStoreClean;return zn("div",{ref:d,className:"es-editor docs-frame",onKeyDown:e=>{const t=e.metaKey||e.ctrlKey,n=e.key.toLowerCase();if(t&&"s"===n)e.preventDefault(),B();else if(t&&"o"===n)e.preventDefault(),l();else if(t&&"f"===n){e.preventDefault(),C(!0);const t=m.current,n=t?t.value.slice(t.selectionStart,t.selectionEnd):"";n&&!n.includes("\n")&&(S(n),I(n))}else"Tab"!==e.key||t||e.shiftKey||e.target!==m.current||(e.preventDefault(),W("\t"))},children:[En(Be,{onClose:s,fileMenu:V,name:o,saveState:{tone:a?"off-unsaved":"off",label:Q},canUndo:w,canRedo:w,onUndo:()=>q("undo"),onRedo:()=>q("redo"),exportControl:En(Sn,{variant:"secondary",leftIcon:En(kn,{name:"download",size:16}),onClick:B,children:c.export})}),zn("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1",children:[En(Nn,{size:"sm",variant:"ghost","aria-label":c.find,title:c.find,"aria-pressed":x,onClick:()=>C(e=>!e),children:En(kn,{name:"search",size:16})}),En(Nn,{size:"sm",variant:"ghost","aria-label":c.wrapLines,title:c.wrapLines,"aria-pressed":h,onClick:()=>g(e=>!e),children:En(kn,{name:"wrap",size:16})})]}),x&&En(Et,{query:k,replacement:N,matchCase:$,current:T,total:E.length,onQuery:e=>{S(e);const t=I(e);M(0),H(t,0,e)},onReplacement:A,onMatchCase:e=>{L(e);const t=I(k,e);M(0),H(t,0)},onStep:e=>H(E,T+(e?1:-1)),onReplace:()=>{const e=m.current;if(!e||!E.length)return;e.focus(),e.setSelectionRange(E[T],E[T]+k.length),W(N);const t=I();H(t,T)},onReplaceAll:()=>{const e=m.current;if(!e||!E.length)return;const t=E.length;e.focus();for(let t=E.length-1;t>=0;t--)e.setSelectionRange(E[t],E[t]+k.length),W(N);I(),M(0),$n.success(c.replacedCount(t))},onClose:K}),zn("div",{className:"relative min-h-0 flex-1 bg-surface",children:[x&&k&&E.length>0&&E.length<=2e3&&En("div",{ref:P,"aria-hidden":"true",style:{lineHeight:"21px",scrollbarGutter:"stable"},className:"pointer-events-none absolute inset-0 overflow-hidden p-4 font-mono text-sm text-transparent "+(h?"whitespace-pre-wrap break-words":"whitespace-pre"),children:(()=>{const e=R(),t=[];let n=0;return E.forEach((r,o)=>{t.push(e.slice(n,r)),n=r+k.length,t.push(En("mark",{...o===T?{"data-current":""}:{},className:"rounded-sm text-transparent "+(o===T?"bg-status-warning-line":"bg-status-warning-soft"),children:e.slice(r,n)},r))}),t.push(e.slice(n)),t})()}),En("textarea",{ref:m,defaultValue:t.text,"aria-label":e,spellCheck:!1,wrap:h?"soft":"off",onInput:U,onSelect:F,onKeyUp:F,onClick:F,onScroll:O,style:{lineHeight:"21px",scrollbarGutter:"stable"},className:"absolute inset-0 h-full w-full resize-none bg-transparent p-4 font-mono text-sm text-ink outline-none "+(h?"whitespace-pre-wrap break-words":"overflow-x-auto whitespace-pre")})]}),zn("div",{className:"flex shrink-0 items-center gap-2 border-t border-line bg-surface-sunken px-3 py-1 text-xs text-ink-muted",children:[En("span",{children:e}),En("span",{children:c.lineColumn(v.line,v.col)}),En("span",{children:c.lineCount(v.lines)}),En("span",{children:t.eol})]})]})}import{jsx as Pn,jsxs as jn}from"react/jsx-runtime";var Dn=new Set(["txt","md","markdown","csv","tsv","log","json","xml","html","htm","css","js","jsx","ts","tsx","py","rb","go","rs","java","c","h","cpp","hpp","sh","bash","yml","yaml","toml","ini","conf","env","sql"]),On=["docx"],Fn=`${Array.from(Dn,e=>`.${e}`).join(",")},.docx,text/*`,In=/^<!doctype html><meta charset="utf-8"><title>[^<]*<\/title>(?!<body style="font-family:ui-monospace)/,Hn=()=>"undefined"!=typeof navigator&&navigator.language||"en-AU";function Bn({value:e,onRename:t}){const n=u(),[r,o]=G(e);return q(()=>o(e),[e]),Pn("div",{className:"docs-title",children:Pn(J,{"aria-label":n.documentName,value:r,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&e.currentTarget.blur()},onBlur:()=>{const n=r.trim();o(n||e),n&&n!==e&&t(n)}})})}function Un({documentId:e,onClose:t}){const n=u(),{store:r,canCreate:o=!0,canDelete:a=!0,chooseFile:i}=d(),[l,s]=G(null),[c,p]=G(null);if(!r||e)return Pn(Wn,{documentId:e,onClose:t});if(l)return Pn(Wn,{documentId:l.id,initialFile:l.file,onClose:()=>s(null)},l.key);return Pn(m,{words:{windowTitle:n.filesHeading,heading:n.filesHeading,newFile:n.newFile,emptyTitle:n.filesEmptyTitle,emptyBody:n.filesEmptyBody,deleteConfirm:n.deleteConfirm,createFailed:n.createFailed,deleteFailed:n.deleteFailed},files:n.files,list:r.list,create:()=>r.create(n.untitled),rename:r.rename,remove:r.remove,canCreate:o,canDelete:a,accept:Fn,choose:i&&{run:i,request:{title:n.files.choosing(n.fileKind,n.filesHeading),extensions:On}},onOpen:e=>s({key:Date.now(),id:e}),onOpenFile:(e,t)=>{U(e.name,On)?c||(p(n.files.opening(e.name)),f(r,e).then(async r=>{const o=await W(t,r.id);ee.success(n.files.savedCopy(r.title,e.name,o?t?.location:void 0)),s({key:Date.now(),id:r.id})}).catch(()=>ee.error(n.files.openFailed(e.name))).finally(()=>p(null))):s({key:Date.now(),file:e})},busy:c})}function Wn({documentId:e,onClose:t,initialFile:n}){const r=u(),{store:o}=d(),a=o&&e?e:null,i=K([]),l=K(0),c=K(null),m={textBox:r.objectTextBox,chart:r.objectChart,diagram:r.objectDiagram,equation:r.objectEquation,picture:r.objectPicture,object:r.objectOther,contents:r.objectField},f=e=>({labels:m,imageUrl:(t,n)=>{const r=URL.createObjectURL(new Blob([t],{type:n}));return i.current.push(r),e.set(r,{bytes:t,mime:n}),r}}),p=e=>{const t=new Map;return{key:++l.current,kind:"rich",filename:e,images:t,doc:g($(Hn()),null,f(t))}},[b,v]=G(()=>a?null:p(r.untitled)),[y,x]=G(!1),[C,k]=G(0),[S,N]=G(!1),[A,L]=G(!1),[T,M]=G(!1);Q(T),q(()=>()=>{i.current.forEach(e=>URL.revokeObjectURL(e))},[]),q(()=>{if(!o||!a)return;let e=!0;return x(!1),(async()=>{const t=await o.get(a),n=new Map,r=t.bytes?.length?await h(t.bytes,f(n)):g($(Hn()),null,f(n));e&&E({key:++l.current,kind:"rich",doc:r,images:n,filename:t.title,stored:{id:t.id,version:t.version}})})().catch(()=>{e&&x(!0)}),()=>{e=!1}},[o,a,C]);const E=e=>{const t=i.current;if(i.current=[],"rich"===e.kind)for(const t of e.images.keys())i.current.push(t);v(e),M(!1),setTimeout(()=>t.filter(e=>!i.current.includes(e)).forEach(e=>URL.revokeObjectURL(e)),0)},z=async()=>!T||_({title:r.discardTitle(b?.filename??""),message:r.discardMessage,confirmLabel:r.discard,cancelLabel:r.keepEditing}),R=async e=>{if(!await z())return;const t=(e.name.split(".").pop()||"").toLowerCase();N(!0);try{if("docx"===t){const t=new Map,n=new Uint8Array(await e.arrayBuffer());try{const r=await h(n,f(t));E({key:++l.current,kind:"rich",doc:r,filename:e.name,images:t})}catch{ee.error(r.cannotRead(e.name))}}else if("doc"===t)ee.error(r.legacyDoc);else if(Dn.has(t)||e.type.startsWith("text/")){const n=new Uint8Array(await e.arrayBuffer()),o=function(e){let t,n="utf-8";if(239===e[0]&&187===e[1]&&191===e[2])n="utf-8-bom",t=new TextDecoder("utf-8").decode(e.subarray(3));else if(255===e[0]&&254===e[1])n="utf-16le",t=new TextDecoder("utf-16le").decode(e.subarray(2));else if(254===e[0]&&255===e[1])n="utf-16be",t=new TextDecoder("utf-16be").decode(e.subarray(2));else try{t=new TextDecoder("utf-8",{fatal:!0}).decode(e)}catch{n="windows-1252",t=new TextDecoder("windows-1252").decode(e)}const r=t.match(/\r\n/g)?.length??0,o=(t.match(/\n/g)?.length??0)-r,a=(t.match(/\r/g)?.length??0)-r,i=r>o&&r>=a?"CRLF":a>o?"CR":"LF";return{text:t.replace(/\r\n?/g,"\n"),encoding:n,eol:i}}(n);if("html"!==t&&"htm"!==t||!In.test(o.text))E({key:++l.current,kind:"text",decoded:o,bytes:n,filename:e.name});else{const t=new Map,n=g($(Hn()),null,f(t));n.html=s(o.text)||n.html,w(n),E({key:++l.current,kind:"rich",doc:n,images:t,filename:e.name.replace(/\.[^.]+$/,".docx"),imported:!0}),ee.info(r.openedOldSave)}}else ee.error(r.unsupported(t))}finally{N(!1)}};q(()=>{n&&R(n)},[]);const P=async()=>{await z()&&(M(!1),c.current?.click())},j="rich"===b?.kind&&!!b.stored,D=()=>ee.info(r.openFromFiles),O=[{key:"new",label:r.newDocument,onSelect:()=>{(async()=>{await z()&&E(p(r.untitled))})()}},{key:"open",label:jn("span",{className:"flex w-full items-center justify-between gap-4",children:[Pn("span",{children:r.open}),Pn("span",{className:"text-2xs text-ink-faint",children:"⌘O"})]}),onSelect:()=>{P()}}],F=b&&Pn(Bn,{value:b.filename,onRename:e=>{const t=b?.filename??e;v(t=>t?{...t,filename:e}:t),o&&"rich"===b?.kind&&b.stored&&o.rename(b.stored.id,e).catch(()=>{ee.error(r.renameFailed),v(e=>e?{...e,filename:t}:e)})}});return jn("div",{className:"relative flex h-full flex-col bg-surface text-ink",onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),A||L(!0))},onDragLeave:e=>{e.currentTarget===e.target&&L(!1)},onDrop:e=>{if(!e.dataTransfer.types.includes("Files"))return;e.preventDefault(),L(!1);const t=Array.from(e.dataTransfer.files??[]);"rich"===b?.kind&&t.length&&t.every(e=>e.type.startsWith("image/"))?window.dispatchEvent(new CustomEvent("docs-insert-images",{detail:{key:b.key,files:t}})):t[0]&&j?D():t[0]&&R(t[0])},children:[b&&Pn(V,{title:`${I=b.filename,I.length>24?`${I.slice(0,23)}…`:I}${T?" •":""} - Documents`}),Pn("input",{ref:c,type:"file",accept:Fn,className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&R(t),e.target.value=""}}),y?Pn("div",{className:"docs-open-failed",children:Pn(Y,{title:r.openFailed,children:t&&Pn(X,{onClick:t,children:r.backToFiles})})}):S||!b?Pn(Z,{size:"sm",padding:"",className:"h-full",label:r.loading}):"rich"===b.kind?Pn(bn,{sessionKey:b.key,doc:b.doc,filename:b.filename,images:b.images,fileEntries:j?[]:O,title:F,startsDirty:b.imported,dirty:T,onDirty:M,onOpenFile:()=>{j?D():P()},onNewImageUrl:e=>{i.current.push(e)},onClose:t,stored:o&&b.stored?{store:o,...b.stored}:void 0,onReload:()=>{M(!1),v(null),k(e=>e+1)}},b.key):Pn(Rn,{filename:b.filename,decoded:b.decoded,bytes:b.bytes,fileEntries:O,title:F,dirty:T,onDirty:M,onOpenFile:()=>{P()},onClose:t},b.key),A&&Pn("div",{className:"pointer-events-none absolute inset-0 z-20 flex items-center justify-center border-4 border-dashed border-accent-fill bg-accent-tint",children:Pn("div",{className:"rounded-md bg-accent-fill px-4 py-2 text-sm font-medium text-on-accent",children:r.dropHint})})]});var I}function qn({id:e,onClose:t}){return Pn(Un,{documentId:e,onClose:t})}export{qn as OpenDocument,Un as default};
@@ -0,0 +1 @@
1
+ import{FileList as e}from"./chunk-A5KQPSPX.js";import{importDeckFile as n}from"./chunk-QFPW3KLL.js";import{PptxPasswordError as i,PptxUnreadableError as t}from"./chunk-RLNXQG4T.js";import{useSlidesHost as o,useSlidesWords as s}from"./chunk-OB4MLAZC.js";import"./chunk-X6F3Z4KZ.js";import"./chunk-B32ASXHM.js";import{placeCopy as l}from"./chunk-XYVQTQ6N.js";import{lazy as r,Suspense as a,useCallback as c,useEffect as d,useState as m}from"react";import{Button as p,EmptyState as f,IconButton as u,toast as h}from"efficient-shell/ui";import{Icon as k}from"efficient-shell/icons";import{jsx as y,jsxs as C}from"react/jsx-runtime";var F=r(()=>import("./SlidesEditor-MZM7IR46.js")),v=["pptx"];function j({id:e,onClose:n,note:i}){const t=s(),{store:l}=o(),[r,h]=m(null),[v,j]=m(!1),[w,g]=m(i??null),P=c(()=>{l.get(e).then(e=>h(n=>({deck:e,nonce:(n?.nonce??0)+1})),()=>j(!0))},[e,l]);if(d(P,[P]),v)return y("div",{className:"slides-list-empty",children:y(f,{title:t.openFailed,children:y(p,{onClick:n,children:t.backToDecks})})});if(!r)return null;const x=y(a,{fallback:null,children:y(F,{deck:r.deck,onClose:n,onReload:P},r.nonce)});return w?C("div",{className:"slides-with-note",children:[C("div",{className:"slides-import-note",role:"status",children:[y(k,{name:"info",size:16}),y("span",{children:w}),y(u,{"aria-label":t.dismiss,onClick:()=>g(null),children:y(k,{name:"close",size:14})})]}),y("div",{className:"slides-with-note-body",children:x})]}):x}function w(){const r=s(),{store:a,canCreate:d=!0,canDelete:p=!0,chooseFile:f,storeImage:u}=o(),[k,C]=m(null),[F,w]=m(null),g=c(()=>a.list(),[a]);if(k)return y(j,{id:k.id,note:k.note,onClose:()=>C(null)});return y(e,{words:{windowTitle:r.slidesPanel,heading:r.decks,newFile:r.newDeck,emptyTitle:r.emptyTitle,emptyBody:r.emptyBody,deleteConfirm:r.deleteConfirm,createFailed:r.createFailed,deleteFailed:r.deleteFailed},files:r.files,list:g,create:()=>a.create(r.untitledDeck),rename:a.rename,remove:a.remove,canCreate:d,canDelete:p,accept:".pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation",choose:f&&{run:f,request:{title:r.files.choosing(r.fileKind,r.slidesPanel),extensions:v}},onOpen:e=>C({id:e}),onOpenFile:(e,o)=>{if(F)return;const s=r.files.opening(e.name);w(s),n(a,e,{storeImage:u,onProgress:e=>w(`${s} ${Math.round(100*e)}%`)}).then(async n=>{const i=await l(o,n.id);h.success(r.files.savedCopy(n.title,e.name,i?o?.location:void 0)),C({id:n.id,note:r.importNotes({skipped:n.notes.skipped,animations:n.notes.animationsDropped,fonts:n.notes.fontsReplaced})})}).catch(n=>{h.error(n instanceof i?r.pptxPasswordProtected:n instanceof t?n.message:r.files.openFailed(e.name))}).finally(()=>w(null))},busy:F})}export{j as OpenDeck,w as default};
@@ -0,0 +1 @@
1
+ import{SlidesConflict as e,useSlidesHost as t,useSlidesWords as n}from"./chunk-OB4MLAZC.js";import{SlideView as l}from"./chunk-2AKHYM66.js";import{HANDLES as i,NO_FILL as a,SLIDE_H as s,SLIDE_W as r,alignElements as o,angleTo as d,asDocument as c,boundsOf as h,boxesTouch as u,bringForward as m,chartToText as p,copySlide as f,duplicateElements as v,historyReducer as b,insertSlideAfter as g,moveSlide as y,newElement as w,newSlide as x,removeElements as k,removeSlide as C,resizeBox as S,snapBox as N,tableToText as D,textToChart as z,textToTable as M,updateElements as I,updateSlide as T}from"./chunk-2TZUCKZ7.js";import"./chunk-X6F3Z4KZ.js";import"./chunk-B32ASXHM.js";import{useCallback as A,useEffect as P,useReducer as j,useRef as K,useState as E}from"react";import{saveIndicator as L,useAutosave as F}from"efficient-easel/autosave";import{EaselIconButton as R,EaselTopBar as B,SaveState as W,TopBarCluster as H,TopBarDivider as O}from"efficient-easel/chrome";import{useEaselStrings as U}from"efficient-easel/strings";import"efficient-easel/shell.css";import"efficient-easel/chrome.css";import"efficient-easel/panel.css";import"efficient-easel/fields.css";import{Button as $}from"efficient-shell/ui";import{IconButton as q}from"efficient-shell/ui";import{Input as _}from"efficient-shell/ui";import{Textarea as Z}from"efficient-shell/ui";import{Icon as X}from"efficient-shell/icons";import{toast as Y}from"efficient-shell";import{useEffect as V,useRef as G,useState as J}from"react";import{Button as Q}from"efficient-shell/ui";import{Icon as ee}from"efficient-shell/icons";import{useLayoutEffect as te,useState as ne}from"react";import{createPortal as le}from"react-dom";import{jsx as ie}from"react/jsx-runtime";function ae(e){const[t,n]=ne(0);return te(()=>{const t=e.current;if(!t)return;const l=t.ownerDocument.defaultView,i=()=>n(Math.min(t.clientWidth,t.clientHeight*r/s));i();const a=new(l?.ResizeObserver??ResizeObserver)(i);return a.observe(t),()=>a.disconnect()},[e]),t}function se({slide:e,popup:t}){const[n]=ne(()=>{const e=t.document.createElement("div");return e.style.cssText="position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background:#000;cursor:pointer",t.document.body.appendChild(e),{current:e}}),i=ae(n);return le(ie("div",{onClick:()=>{t.document.documentElement.requestFullscreen?.()},children:ie(l,{slide:e,width:i})}),n.current)}import{jsx as re,jsxs as oe}from"react/jsx-runtime";var de=e=>String(e).padStart(2,"0");function ce({slides:e,startIndex:t,popup:i,onEnd:a}){const[s,r]=J(t),o=function(){const[e,t]=J(0);return V(()=>{const e=Date.now(),n=setInterval(()=>t(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(n)},[]),`${de(Math.floor(e/60))}:${de(e%60)}`}(),d=n(),c=e.length-1,h=G(null),u=ae(h),m=e=>r(Math.max(0,Math.min(e,c)));V(()=>{const e=e=>{["ArrowRight","ArrowDown","PageDown"," "].includes(e.key)?(e.preventDefault(),r(e=>Math.min(e+1,c))):["ArrowLeft","ArrowUp","PageUp"].includes(e.key)?(e.preventDefault(),r(e=>Math.max(e-1,0))):"Escape"===e.key&&a()};return window.addEventListener("keydown",e),i?.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e),i?.removeEventListener("keydown",e)}},[c,a,i]),V(()=>{if(i)return()=>i.close()},[i]);const p=e[s],f=e[s+1];return oe("div",{className:"slides-presenter",children:[oe("div",{className:"slides-presenter-head",children:[re("span",{className:"slides-presenter-clock",children:o}),re("span",{children:d.slideOf(s+1,e.length)}),re(Q,{variant:"secondary",onClick:a,leftIcon:re(ee,{name:"close",size:16}),children:d.endShow})]}),!i&&re("p",{className:"slides-presenter-blocked",children:d.popupBlocked}),oe("div",{className:"slides-presenter-body",children:[oe("div",{className:"slides-presenter-main",children:[re("div",{ref:h,className:"slides-presenter-current",children:re(l,{slide:p,width:u})}),oe("div",{className:"slides-presenter-steps",children:[re(Q,{variant:"secondary",onClick:()=>m(s-1),leftIcon:re(ee,{name:"arrow-left",size:16}),children:d.back}),re(Q,{variant:"secondary",onClick:()=>m(s+1),rightIcon:re(ee,{name:"arrow-right",size:16}),children:d.next})]})]}),oe("div",{className:"slides-presenter-side",children:[re("p",{className:"slides-presenter-label",children:d.nextSlide}),f?re(l,{slide:f,width:280}):re("p",{children:d.endOfDeck}),re("p",{className:"slides-presenter-label",children:d.notes}),re("p",{className:"slides-presenter-notes",children:p.notes||d.noNotes})]})]}),i&&re(se,{slide:p,popup:i})]})}import{useState as he}from"react";import{SettingsColour as ue}from"efficient-easel/panel";import{Button as me}from"efficient-shell/ui";import{IconButton as pe}from"efficient-shell/ui";import{Input as fe}from"efficient-shell/ui";import{Select as ve}from"efficient-shell/ui";import{Textarea as be}from"efficient-shell/ui";import{Icon as ge}from"efficient-shell/icons";import{jsx as ye,jsxs as we}from"react/jsx-runtime";var xe=e=>e===a?"#ffffff":e;function ke({label:e,value:t,onChange:n}){return we("label",{className:"slides-number",children:[ye("span",{children:e}),ye(fe,{type:"number",value:Math.round(t),onChange:e=>{const t=Number(e.target.value);""!==e.target.value&&Number.isFinite(t)&&n(t)}})]})}function Ce({label:e,hint:t,value:n,onChange:l}){const[i,a]=he(null);return we("label",{className:"slides-field",children:[ye("span",{children:e}),ye(be,{rows:5,value:i??n,onFocus:()=>a(n),onBlur:()=>a(null),onChange:e=>{a(e.target.value),l(e.target.value)}}),ye("small",{children:t})]})}function Se({slide:e,selected:l,onChangeSlide:i,onChangeSelected:a,onAlign:s,onForward:r,onDelete:o}){const d=n(),{pickImage:c}=t();if(0===l.length)return we("aside",{className:"slides-inspector",children:[ye("h3",{children:d.slide}),ye("div",{className:"slides-section",children:ye(ue,{label:d.background,value:e.background,onChange:e=>i({background:e})})})]});const h=1===l.length?l[0]:null,u={text:d.elementText,shape:d.elementShape,image:d.elementImage,chart:d.elementChart,table:d.elementTable},m=e=>a(t=>({...t,...e}));return we("aside",{className:"slides-inspector",children:[ye("h3",{children:h?u[h.type]:d.objects(l.length)}),h&&we("div",{className:"slides-section",children:[ye("p",{className:"slides-label",children:d.positionAndSize}),we("div",{className:"slides-numbers",children:[ye(ke,{label:"X",value:h.x,onChange:e=>m({x:e})}),ye(ke,{label:"Y",value:h.y,onChange:e=>m({y:e})}),ye(ke,{label:d.width,value:h.w,onChange:e=>m({w:Math.max(20,e)})}),ye(ke,{label:d.height,value:h.h,onChange:e=>m({h:Math.max(20,e)})}),ye(ke,{label:d.angle,value:h.rotation,onChange:e=>m({rotation:e})})]})]}),we("div",{className:"slides-section",children:[ye("p",{className:"slides-label",children:d.align}),we("div",{className:"slides-actions",children:[ye(pe,{"aria-label":d.alignLeft,onClick:()=>s("left"),children:ye(ge,{name:"align-left",size:16})}),ye(pe,{"aria-label":d.alignCentre,onClick:()=>s("center"),children:ye(ge,{name:"align-center",size:16})}),ye(pe,{"aria-label":d.alignRight,onClick:()=>s("right"),children:ye(ge,{name:"align-right",size:16})}),ye(pe,{"aria-label":d.bringForward,onClick:r,children:ye(ge,{name:"layers",size:16})}),ye(pe,{"aria-label":d.delete,onClick:o,children:ye(ge,{name:"trash",size:16})})]})]}),"text"===h?.type&&we("div",{className:"slides-section",children:[ye("div",{className:"slides-numbers",children:ye(ke,{label:d.size,value:h.fontSize,onChange:e=>m({fontSize:Math.max(8,e)})})}),ye(ve,{"aria-label":d.weight,value:h.bold?"bold":"regular",onChange:e=>m({bold:"bold"===e}),options:[{value:"regular",label:d.regular},{value:"bold",label:d.bold}]}),ye(ve,{"aria-label":d.textAlignment,value:h.align,onChange:e=>m({align:e}),options:[{value:"left",label:d.left},{value:"center",label:d.centre},{value:"right",label:d.right}]}),ye(ue,{label:d.colour,value:h.color,onChange:e=>m({color:e})})]}),"shape"===h?.type&&we("div",{className:"slides-section",children:[ye(ve,{"aria-label":d.elementShape,value:h.shape,onChange:e=>m({shape:e}),options:[{value:"rect",label:d.rectangle},{value:"roundRect",label:d.roundedRectangle},{value:"ellipse",label:d.ellipse},{value:"diamond",label:d.diamond},{value:"line",label:d.lineShape}]}),"line"!==h.shape&&ye(ue,{label:d.colour,value:xe(h.fill),onChange:e=>m({fill:e})}),(h.stroke||"line"===h.shape)&&ye(ue,{label:d.outlineColour,value:xe(h.stroke??h.fill),onChange:e=>m({stroke:e})})]}),"image"===h?.type&&we("div",{className:"slides-section",children:[c?ye(me,{variant:"secondary",block:!0,onClick:()=>{const{id:e}=h;c().then(t=>{t&&a(n=>n.id===e?{...n,src:t}:n)})},children:d.chooseImage}):we("label",{className:"slides-field",children:[ye("span",{children:d.imageAddress}),ye(fe,{value:h.src,onChange:e=>m({src:e.target.value})})]}),we("label",{className:"slides-field",children:[ye("span",{children:d.description}),ye(fe,{value:h.alt,onChange:e=>m({alt:e.target.value})})]})]}),"chart"===h?.type&&we("div",{className:"slides-section",children:[ye("p",{className:"slides-label",children:d.data}),ye(ve,{"aria-label":d.chartType,value:h.kind,onChange:e=>m({kind:e}),options:[{value:"bar",label:d.bar},{value:"line",label:d.line}]}),ye(Ce,{label:d.values,hint:d.valuesHint,value:p(h.points),onChange:e=>m({points:z(e)})}),ye(ue,{label:d.colour,value:h.color,onChange:e=>m({color:e})})]}),"table"===h?.type&&we("div",{className:"slides-section",children:[ye(Ce,{label:d.rows,hint:d.rowsHint,value:D(h.rows),onChange:e=>m({rows:M(e)})}),ye(ue,{label:d.headingColour,value:xe(h.headerFill),onChange:e=>m({headerFill:e})})]})]})}import{useState as Ne}from"react";import{Button as De}from"efficient-shell/ui";import{IconButton as ze}from"efficient-shell/ui";import{Icon as Me}from"efficient-shell/icons";import{jsx as Ie,jsxs as Te}from"react/jsx-runtime";function Ae({slides:e,currentId:t,onShow:i,onAdd:a,onMove:s,onDuplicate:r,onDelete:o}){const[d,c]=Ne(null),h=n();return Te("nav",{className:"slides-rail","aria-label":h.slidesPanel,children:[e.map((e,n)=>Te("div",{className:"slides-thumb","data-current":e.id===t||void 0,draggable:!0,onDragStart:()=>c(e.id),onDragEnd:()=>c(null),onDragOver:e=>e.preventDefault(),onDrop:()=>{d&&d!==e.id&&s(d,n),c(null)},children:[Ie("span",{className:"slides-thumb-number",children:n+1}),Ie("div",{role:"button",tabIndex:0,"aria-label":h.slideNumber(n+1),"aria-current":e.id===t,className:"slides-thumb-image",onClick:()=>i(e.id),onKeyDown:t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),t.stopPropagation(),i(e.id))},children:Ie(l,{slide:e,width:132})}),e.id===t&&Te("div",{className:"slides-thumb-actions",children:[Ie(ze,{"aria-label":h.duplicateSlide,size:"sm",onClick:()=>r(e.id),children:Ie(Me,{name:"copy",size:14})}),Ie(ze,{"aria-label":h.deleteSlide,size:"sm",onClick:()=>o(e.id),children:Ie(Me,{name:"trash",size:14})})]})]},e.id)),Ie(De,{variant:"secondary",block:!0,onClick:a,children:h.addSlide})]})}import{useLayoutEffect as Pe,useRef as je,useState as Ke}from"react";import{Fragment as Ee,jsx as Le,jsxs as Fe}from"react/jsx-runtime";var Re={x:[],y:[]};function Be({element:e,onDone:t}){const l=je(null),i=n();return Pe(()=>{const t=l.current;t&&(t.innerText=e.text,t.focus(),document.getSelection()?.selectAllChildren(t))},[e.text]),Le("div",{ref:l,contentEditable:"plaintext-only",role:"textbox","aria-label":i.slideText,suppressContentEditableWarning:!0,className:"slides-text-edit",onPointerDown:e=>e.stopPropagation(),onBlur:e=>t(e.currentTarget.innerText),onKeyDown:e=>{e.stopPropagation(),"Escape"===e.key&&e.currentTarget.blur()},style:{fontSize:e.fontSize,fontWeight:e.bold?600:400,color:e.color,textAlign:e.align}})}function We({slide:e,selected:t,onSelect:n,onLive:a,onSettle:o,onCommit:c}){const m=je(null),[p,f]=Ke(0),[v,b]=Ke(Re),[g,y]=Ke(null),[w,x]=Ke(null),k=je(null);Pe(()=>{const e=m.current;if(!e)return;const t=()=>{f(Math.max(0,Math.min(e.clientWidth-48,(e.clientHeight-48)*r/s)))};t();const n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);const C=p/r,D=je(null),z=e=>{const t=D.current?.getBoundingClientRect();return{x:(e.clientX-(t?.left??0))/C,y:(e.clientY-(t?.top??0))/C}},M=(t,n)=>{for(let l=e.elements.length-1;l>=0;l-=1){const i=e.elements[l],a=-i.rotation*Math.PI/180,s=t-(i.x+i.w/2),r=n-(i.y+i.h/2),o=s*Math.cos(a)-r*Math.sin(a),d=s*Math.sin(a)+r*Math.cos(a);if(Math.abs(o)<=i.w/2&&Math.abs(d)<=i.h/2)return i}return null},T=(e,t)=>{e.stopPropagation(),e.currentTarget.setPointerCapture(e.pointerId),k.current=t},A=l=>{const i=k.current;if(!i)return;const{x:s,y:r}=z(l);if("marquee"===i.kind){const t={x:Math.min(i.px,s),y:Math.min(i.py,r),w:Math.abs(s-i.px),h:Math.abs(r-i.py)};y(t),n(new Set(e.elements.filter(e=>u(t,e)).map(e=>e.id)))}else if("move"===i.kind){const e=i.start.elements.filter(e=>t.has(e.id)),n=i.start.elements.filter(e=>!t.has(e.id)),o=h(e),d={...o,x:o.x+s-i.px,y:o.y+r-i.py},c=l.altKey?{box:d,guides:Re}:N(d,n);b(c.guides);const u=c.box.x-o.x,m=c.box.y-o.y;a(I(i.start,t,e=>({...e,x:e.x+u,y:e.y+m})))}else"resize"===i.kind?a(I(i.start,new Set([i.id]),e=>{const t=-e.rotation*Math.PI/180,n=s-i.px,a=r-i.py,o=n*Math.cos(t)-a*Math.sin(t),d=n*Math.sin(t)+a*Math.cos(t);return{...e,...S(e,i.handle,o,d,l.shiftKey)}})):a(I(i.start,new Set([i.id]),e=>({...e,rotation:d(e,s,r,l.shiftKey)})))},P=()=>{const e=k.current;k.current=null,b(Re),y(null),e&&"marquee"!==e.kind&&o()},j=1===t.size?e.elements.find(e=>t.has(e.id)):void 0,K=e.elements.filter(e=>t.has(e.id)),E=e.elements.find(e=>e.id===w&&"text"===e.type);return Le("div",{ref:m,className:"slides-pane",children:Fe("div",{ref:D,className:"slides-stage",style:{width:p,height:p*s/r},onPointerDown:l=>{if(0!==l.button)return;const{x:i,y:a}=z(l),s=M(i,a);if(!s)return l.shiftKey||n(new Set),void T(l,{kind:"marquee",px:i,py:a});let r=t;if(l.shiftKey){const e=new Set(t);e.has(s.id)?e.delete(s.id):e.add(s.id),r=e,n(e)}else t.has(s.id)||(r=new Set([s.id]),n(r));r.has(s.id)&&T(l,{kind:"move",start:e,px:i,py:a})},onPointerMove:A,onPointerUp:P,onPointerCancel:P,onDoubleClick:e=>{const{x:t,y:n}=z(e),l=M(t,n);"text"===l?.type&&x(l.id)},children:[Le(l,{slide:e,width:p,editingId:E?.id,editor:E&&Le(Be,{element:E,onDone:t=>{x(null),t!==E.text&&c(I(e,new Set([E.id]),e=>({...e,text:t})))}})}),!E&&K.map(t=>Le("div",{className:"slides-selection",style:{left:t.x*C,top:t.y*C,width:t.w*C,height:t.h*C,transform:t.rotation?`rotate(${t.rotation}deg)`:void 0},children:j?.id===t.id&&Fe(Ee,{children:[i.map(n=>Le("div",{className:`slides-handle slides-handle-${n}`,onPointerDown:l=>T(l,{kind:"resize",start:e,id:t.id,handle:n,...He(z(l))}),onPointerMove:A,onPointerUp:P,onPointerCancel:P},n)),Le("div",{className:"slides-rotate-stem"}),Le("div",{className:"slides-rotate",onPointerDown:n=>T(n,{kind:"rotate",start:e,id:t.id}),onPointerMove:A,onPointerUp:P,onPointerCancel:P})]})},t.id)),v.x.map(e=>Le("div",{className:"slides-guide slides-guide-x",style:{left:e*C}},`x${e}`)),v.y.map(e=>Le("div",{className:"slides-guide slides-guide-y",style:{top:e*C}},`y${e}`)),g&&Le("div",{className:"slides-marquee",style:{left:g.x*C,top:g.y*C,width:g.w*C,height:g.h*C}})]})})}var He=({x:e,y:t})=>({px:e,py:t}),Oe=13.333,Ue=e=>e/r*Oe,$e=e=>e.replace("#","").toUpperCase(),qe=e=>Math.round(72*Ue(e));function _e(e){return`${e.replace(/[^\p{L}\p{N} _-]+/gu," ").replace(/ +/g," ").trim()||"Deck"}.pptx`}var Ze=e=>e===a?{type:"none"}:{color:$e(e)},Xe=e=>e.stroke?{color:$e(e.stroke),width:qe(e.strokeWidth??1)}:void 0;function Ye(e,t,n){const{columnWidths:l,rowHeights:i,fontSize:a}=t;e.addTable(t.rows.map((e,n)=>e.map((e,l)=>function(e,t,n,l){const i=e.cellFills?.[n]?.[l]??(0===n?e.headerFill:null),a=e.cellColors?.[n]?.[l]??(0===n?e.headerColor:void 0);return{text:t,options:{...0===n?{bold:!0}:{},...i?{fill:Ze(i)}:{},...a?{color:$e(a)}:{}}}}(t,e,n,l))),{...n,border:{type:"solid",color:"B4B2A9",pt:1},...a?{fontSize:qe(a)}:{},...l?{colW:l.map(e=>e*n.w)}:{},...i?{rowH:i.map(Ue)}:{}})}function Ve(e,t,n){const l={x:Ue(n.x),y:Ue(n.y),w:Ue(n.w),h:Ue(n.h),rotate:n.rotation};switch(n.type){case"text":t.addText(n.text,{...l,fontSize:qe(n.fontSize),bold:n.bold,color:$e(n.color),align:n.align,valign:"top",margin:0});break;case"shape":!function(e,t,n,l){if("line"===n.shape)return void t.addShape(e.ShapeType.line,{...l,y:l.y+l.h/2,h:0,line:{color:$e(n.stroke??n.fill),width:qe(n.strokeWidth??1),beginArrowType:n.arrowStart?"triangle":"none",endArrowType:n.arrowEnd?"triangle":"none"}});const i={rect:e.ShapeType.rect,ellipse:e.ShapeType.ellipse,roundRect:e.ShapeType.roundRect,diamond:e.ShapeType.diamond};t.addShape(i[n.shape],{...l,fill:Ze(n.fill),line:Xe(n),rectRadius:"roundRect"===n.shape&&void 0!==n.radius?Ue(n.radius):void 0})}(e,t,n,l);break;case"image":n.src&&t.addImage({...l,path:n.src,altText:n.alt});break;case"chart":t.addChart("line"===n.kind?e.ChartType.line:e.ChartType.bar,[{name:"Series",labels:n.points.map(e=>e.label),values:n.points.map(e=>e.value)}],{...l,chartColors:[$e(n.color)],showValue:!0,showLegend:!1});break;case"table":Ye(t,n,l)}}async function Ge(e,t){const n=await async function(e,t){const{default:n}=await(import("pptxgenjs")),l=new n;l.defineLayout({name:"SLIDE_16_9",width:Oe,height:7.5}),l.layout="SLIDE_16_9",l.title=e;for(const e of t.slides){const t=l.addSlide();t.background={color:$e(e.background)},e.notes&&t.addNotes(e.notes);for(const n of e.elements)Ve(l,t,n)}return l}(e,t);await n.writeFile({fileName:_e(e)})}import{jsx as Je,jsxs as Qe}from"react/jsx-runtime";var et=[{type:"text",labelKey:"addText",icon:"type"},{type:"shape",labelKey:"addShape",icon:"square"},{type:"image",labelKey:"addImage",icon:"image"},{type:"chart",labelKey:"addChart",icon:"chart-bar"},{type:"table",labelKey:"addTable",icon:"table"}];function tt({deck:l,onClose:i,onReload:a}){const s=n(),{store:r}=t(),[d,h]=E(l.title),[u,p]=j(b,void 0,()=>({past:[],present:c(l.document),future:[]})),S=u.present,[N,D]=E(S.slides[0].id),[z,M]=E(new Set),[V,G]=E(!0),[J,Q]=E(null),ee=S.slides.find(e=>e.id===N)??S.slides[0],te=S.slides.indexOf(ee),ne=K(l.version),[le,ie]=E(!1),ae=U(),se=F({save:async e=>{ne.current=await r.save(l.id,e,ne.current)},onFailure:(t,n)=>{t instanceof e?(se.stop(),ie(!0)):0===n&&Y.error(s.saveFailed)}}),re=K(S),{push:oe,flush:de}=se;P(()=>{S!==re.current&&(re.current=S,oe(S))},[S,oe]),P(()=>()=>{de()},[de]);const he=A(e=>p({type:"commit",doc:e}),[]),ue=e=>he(T(S,ee.id,()=>e)),me=K(null),pe=e=>{D(e),M(new Set)},fe=()=>{ue(k(ee,z)),M(new Set)};return Qe("div",{className:"es-editor slides-editor",onKeyDown:e=>{if(J)return;if(e.target.closest('input, textarea, select, [contenteditable], [role="listbox"]'))return;const t=e.metaKey||e.ctrlKey;if(t&&"z"===e.key.toLowerCase())e.preventDefault(),p({type:e.shiftKey?"redo":"undo"});else if(t&&"y"===e.key.toLowerCase())e.preventDefault(),p({type:"redo"});else if(t&&"a"===e.key.toLowerCase())e.preventDefault(),M(new Set(ee.elements.map(e=>e.id)));else if(t&&"d"===e.key.toLowerCase()&&z.size>0){e.preventDefault();const t=v(ee,z);ue(t.slide),M(new Set(t.ids))}else if(("Delete"===e.key||"Backspace"===e.key)&&z.size>0)e.preventDefault(),fe();else if("Escape"===e.key)M(new Set);else if(e.key.startsWith("Arrow")&&z.size>0){e.preventDefault();const t=e.shiftKey?1:10,n="ArrowLeft"===e.key?-t:"ArrowRight"===e.key?t:0,l="ArrowUp"===e.key?-t:"ArrowDown"===e.key?t:0;ue(I(ee,z,e=>({...e,x:e.x+n,y:e.y+l})))}},tabIndex:-1,children:[Qe(B,{children:[Qe(H,{children:[Je(R,{label:s.backToDecks,onClick:i,children:Je(X,{name:"chevron-left",size:16})}),Je(R,{label:s.slidesPanel,state:V?"active":"inactive",onClick:()=>G(e=>!e),children:Je(X,{name:"bars-3-bottom-left",size:16})}),Je("div",{className:"slides-title",children:Je(_,{"aria-label":s.deckName,value:d,onChange:e=>h(e.target.value),onBlur:()=>{const e=d.trim();e&&e!==l.title?r.rename(l.id,e).catch(()=>Y.error(s.renameFailed)):h(e||l.title)}})}),Je(W,{...L(se.state,ae.save)}),Je(O,{}),Je(R,{label:s.undo,disabled:0===u.past.length,onClick:()=>p({type:"undo"}),children:Je(X,{name:"undo",size:16})}),Je(R,{label:s.redo,disabled:0===u.future.length,onClick:()=>p({type:"redo"}),children:Je(X,{name:"redo",size:16})})]}),Qe(H,{kind:"right",children:[Je($,{variant:"secondary",leftIcon:Je(X,{name:"download",size:16}),onClick:()=>Ge(d,S).catch(()=>Y.error(s.exportFailed)),children:s.export}),Je($,{leftIcon:Je(X,{name:"play",size:16}),onClick:()=>{const e=window.open("about:blank","_blank","popup,width=1280,height=720");e&&(e.document.title=d),Q({popup:e})},children:s.present})]})]}),le&&Qe("div",{className:"slides-conflict",role:"alert",children:[Je("span",{children:s.conflict}),Je($,{variant:"secondary",onClick:a,children:s.reload})]}),Qe("div",{className:"slides-body",children:[V&&Je(Ae,{slides:S.slides,currentId:ee.id,onShow:pe,onAdd:()=>{const e=x();he(g(S,ee.id,e)),pe(e.id)},onMove:(e,t)=>he(y(S,e,t)),onDuplicate:e=>{const t=S.slides.find(t=>t.id===e);if(!t)return;const n=f(t);he(g(S,e,n)),pe(n.id)},onDelete:e=>{const t=C(S,e);he(t),e===ee.id&&pe(t.slides[Math.min(te,t.slides.length-1)].id)}}),Qe("div",{className:"slides-centre",children:[Je("div",{className:"slides-toolbar",children:et.map(({type:e,labelKey:t,icon:n})=>Je(q,{"aria-label":s[t],onClick:()=>(e=>{const t=w(e);ue({...ee,elements:[...ee.elements,t]}),M(new Set([t.id]))})(e),children:Je(X,{name:n,size:16})},e))}),Je(We,{slide:ee,selected:z,onSelect:M,onLive:e=>{me.current??=S,p({type:"live",doc:T(me.current,ee.id,()=>e)})},onSettle:()=>{me.current&&p({type:"settle",from:me.current}),me.current=null},onCommit:ue},ee.id),Qe("label",{className:"slides-notes",children:[Je("span",{children:s.speakerNotes}),Je(Z,{rows:2,value:ee.notes,onChange:e=>ue({...ee,notes:e.target.value})})]})]}),Je(Se,{slide:ee,selected:ee.elements.filter(e=>z.has(e.id)),onChangeSlide:e=>ue({...ee,...e}),onChangeSelected:e=>ue(I(ee,z,e)),onAlign:e=>ue(o(ee,z,e)),onForward:()=>ue(m(ee,z)),onDelete:fe})]}),J&&Je(ce,{slides:S.slides,startIndex:te,popup:J.popup,onEnd:()=>Q(null)})]})}export{tt as default};
@@ -0,0 +1 @@
1
+ import{importSpreadsheetFile as e,readWithSheetJs as t}from"./chunk-B6JN7D6G.js";import{readXlsx as r,writeXlsx as n}from"./chunk-N26CBJZA.js";import{SPREADSHEET_ACCEPT as o,SPREADSHEET_EXTENSIONS as l,SpreadsheetsConflict as a,sheetsOf as i,useSpreadsheetWords as c,useSpreadsheetsHost as s}from"./chunk-GLT7O6TV.js";import"./chunk-7K7AY3V3.js";import{DEFAULT_COL_WIDTH as u,DEFAULT_FONT_SIZE as d,DEFAULT_ROW_HEIGHT as f,FUNCTION_NAMES as h,MAX_COLS as m,MAX_ROWS as g,NUMBER_FORMATS as p,adjustDecimals as v,applyBorders as w,cellDisplay as b,cellLabel as x,changeStructure as y,clearValues as C,colLabel as k,columnValues as N,commitEntry as D,copyClip as S,cycleRefAbsolute as R,dataRegion as M,deleteSheet as T,duplicateSheet as E,editText as A,expandForMerges as z,fillRange as F,filteredRows as I,findCells as O,formatKey as L,formatNumber as P,isFormula as $,makeEvaluator as B,mergeRange as U,mergedAt as K,moveCells as H,newSheet as W,nextSheetName as X,normalizeRange as V,parseCsv as Y,parseRangeLabel as G,pasteClip as j,printRef as _,rangeContains as Z,rangeLabel as Q,rawAt as J,readEntry as q,renameSheet as ee,replaceInCell as te,selectionStats as re,serializeCsv as ne,sheetFromRows as oe,shiftFormula as le,sortRange as ae,tokenize as ie,unmergeRange as ce,updateFormats as se,usedBounds as ue,withFormat as de,writeCells as fe}from"./chunk-VKCG3LPQ.js";import{FileList as he}from"./chunk-A5KQPSPX.js";import"./chunk-B32ASXHM.js";import{placeCopy as me}from"./chunk-XYVQTQ6N.js";import{useCallback as ge,useEffect as pe,useMemo as ve,useRef as we,useState as be}from"react";import{saveIndicator as xe,useAutosave as ye}from"efficient-easel/autosave";import{SaveState as Ce}from"efficient-easel/chrome";import"efficient-easel/chrome.css";import{useEaselStrings as ke}from"efficient-easel/strings";import{WindowTitle as Ne,useBrowserLayoutEffect as De,useWindowDirty as Se}from"efficient-shell";import{Icon as Re}from"efficient-shell/icons";import{Button as Me,Checkbox as Te,ColorPickerPanel as Ee,ContextMenu as Ae,DropdownMenu as ze,EmptyState as Fe,IconButton as Ie,Input as Oe,LoadingSpinner as Le,Popover as Pe,PopupMenu as $e,PopupMenuDivider as Be,PopupMenuItem as Ue,confirmDestructive as Ke,registerModalEscapeInterceptor as He,toDateKey as We,toast as Xe,useContextMenu as Ve}from"efficient-shell/ui";import{SPREADSHEET_PREVIEW_UPDATE_EVENT as Ye,peekSpreadsheetPreviewStage as Ge,claimSpreadsheetPreviewStage as je}from"efficient-shell/apps";import{forwardRef as _e,useCallback as Ze,useEffect as Qe,useImperativeHandle as Je,useMemo as qe,useRef as et,useState as tt}from"react";import{Icon as rt}from"efficient-shell/icons";import{jsx as nt,jsxs as ot}from"react/jsx-runtime";var lt,at=46,it=24,ct=4/3;function st(e,t){const r=new Float64Array(e+1);for(let n=0;n<e;n++)r[n+1]=r[n]+t(n);return r}function ut(e,t){let r=0,n=e.length-2;for(;r<n;){const o=r+n+1>>1;e[o]<=t?r=o:n=o-1}return r}function dt(e,t){if(void 0===lt)try{lt=document.createElement("canvas").getContext("2d")}catch{lt=null}const r=(t?.fontSize??d)*ct;return lt?(lt.font=`${t?.italic?"italic ":""}${t?.bold?"bold ":""}${r}px system-ui, sans-serif`,lt.measureText(e).width):e.length*r*.55}var ft=_e(function({sheet:e,sheetIndex:t,evaluator:r,filterHidden:n,selection:o,showGridlines:l,showFormulas:a,clipRange:i,highlights:s,pointing:h,onSelect:m,onPoint:g,onEdit:p,onFill:v,onResizeCol:w,onResizeRow:x,onAutoFitCol:y,onAutoFitRow:C,onHeaderMenu:N,onFilterButton:D,renderEditor:S,onKeyDown:R,onCopy:M,onCut:T,onPaste:E},A){const F=c(),I=et(null),[O,P]=tt({x:0,y:0}),[$,B]=tt({width:1e3,height:600}),[U,H]=tt(null),[W,X]=tt(null),[Y,G]=tt(null);Qe(()=>{const e=I.current;if(!e)return;const t=()=>{e.clientWidth&&e.clientHeight&&B({width:e.clientWidth,height:e.clientHeight})};if(t(),"undefined"==typeof ResizeObserver)return;const r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);const j=qe(()=>{const n=new Map;for(const[o,l]of Object.entries(e.formats)){if(!l.fontSize&&!l.wrap)continue;const[a,i]=o.split(":").map(Number);if(void 0!==e.rowHeights[a])continue;const c=(l.fontSize??d)*ct*1.4;let s=1;if(l.wrap&&""!==J(e,a,i)){const n=(e.colWidths[i]??u)-8;s=b(e,t,r,a,i).text.split("\n").reduce((e,t)=>e+Math.max(1,Math.ceil(dt(t,l)/Math.max(n,1))),0)}const h=Math.ceil(c*s+6);h>(n.get(a)??f)&&n.set(a,h)}return n},[e,t,r]),_=qe(()=>new Set(e.hiddenRows),[e.hiddenRows]),Z=qe(()=>new Set(e.hiddenCols),[e.hiddenCols]),Q=qe(()=>st(e.rowCount,t=>_.has(t)||n.has(t)?0:W?.row===t?W.height:e.rowHeights[t]??j.get(t)??f),[e.rowCount,e.rowHeights,_,n,j,W]),q=qe(()=>st(e.colCount,t=>Z.has(t)?0:U?.col===t?U.width:e.colWidths[t]??u),[e.colCount,e.colWidths,Z,U]),ee=Math.min(e.frozenRows,e.rowCount),te=Math.min(e.frozenCols,e.colCount),re=Q[ee],ne=q[te],oe=q[e.colCount],le=Q[e.rowCount],ae=Ze(e=>at+q[e]-(e>=te?O.x:0),[q,te,O.x]),ie=Ze(e=>it+Q[e]-(e>=ee?O.y:0),[Q,ee,O.y]),ce=Ze(e=>{const t=I.current;if(!t)return;const r=t.clientWidth-at-ne,n=t.clientHeight-it-re;let{scrollLeft:o,scrollTop:l}=t;if(e.col>=te){const t=q[e.col]-ne,n=q[e.col+1]-ne;t<o?o=t:n>o+r&&(o=n-r)}if(e.row>=ee){const t=Q[e.row]-re,r=Q[e.row+1]-re;t<l?l=t:r>l+n&&(l=r-n)}t.scrollTo(o,l)},[q,Q,ne,re,te,ee]);Je(A,()=>({focus:()=>I.current?.focus({preventScroll:!0}),scrollTo:ce,measureColumn:n=>{let o=0;for(let l=0;l<e.cells.length;l++){if(""===J(e,l,n))continue;const a=e.formats[L(l,n)];o=Math.max(o,dt(b(e,t,r,l,n).text,a))}return Math.ceil(o+8+4)}}),[ce,e,t,r]);const se=Ze((e,t)=>{const r=I.current.getBoundingClientRect(),n=e-r.left-at,o=t-r.top-it,l=n<ne?n:n+I.current.scrollLeft,a=o<re?o:o+I.current.scrollTop;return{row:ut(Q,Math.max(0,Math.min(a,le-1))),col:ut(q,Math.max(0,Math.min(l,oe-1)))}},[q,Q,ne,re,oe,le]),ue=Ze((e,t)=>{const r=I.current,n=t=>{const n=r.getBoundingClientRect();t.clientY>n.bottom-4?r.scrollBy(0,24):t.clientY<n.top+it&&r.scrollBy(0,-24),t.clientX>n.right-4?r.scrollBy(24,0):t.clientX<n.left+at&&r.scrollBy(-24,0),e(t)},o=e=>{window.removeEventListener("pointermove",n),window.removeEventListener("pointerup",o),window.removeEventListener("pointercancel",o),t(e)};window.addEventListener("pointermove",n),window.addEventListener("pointerup",o),window.addEventListener("pointercancel",o)},[]),de=Ze((t,r)=>{const n=z(e,V(t,r));m({active:t,range:n})},[e,m]),fe=Math.max(0,$.width-at-ne),he=Math.max(0,$.height-it-re),me=ut(Q,re+O.y),ge=ut(q,ne+O.x),pe=Math.min(e.rowCount-1,ut(Q,re+O.y+he)),ve=Math.min(e.colCount-1,ut(q,ne+O.x+fe)),we=(n,o,i,c)=>{const s=[],u=[],f=new Set,h=(n,o,i)=>{const c=L(n,o);if(f.has(c))return;f.add(c);const h=i?i.r2:n,m=i?i.c2:o,g=q[o],p=Q[n],v=q[m+1]-g,w=Q[h+1]-p;if(v<=0||w<=0)return;const x=e.formats[c],y=J(e,n,o),C=a&&"="===y[0]?{text:y,color:null,align:"left",error:!1}:b(e,t,r,n,o),k=x?.border,N="1px solid var(--ink)",D=!!x?.fill||!!k||!!i,S=l?"1px solid var(--line-subtle)":"1px solid transparent",R={position:"absolute",left:g,top:p,width:v,height:w,boxSizing:"border-box",borderRight:k?.right?N:S,borderBottom:k?.bottom?N:S,borderTop:k?.top?N:void 0,borderLeft:k?.left?N:void 0,background:x?.fill??(i?"var(--surface)":void 0)};if((D||l)&&s.push(nt("div",{style:R},`b${c}`)),!C.text)return;const M=x?.align??C.align;let T=C.text;"string"==typeof T&&!C.error&&"right"===C.align&&!x?.wrap&&dt(T,x)>v-4&&(T="#".repeat(Math.max(1,Math.floor(v/8))));let E=v,A=0;if(!i&&!x?.wrap&&"left"===C.align&&dt(T,x)>v-8){if("left"===M||"center"===M)for(let t=o+1;t<=Math.min(o+40,e.colCount-1)&&(""===J(e,n,t)&&!K(e,n,t));t++)E+=q[t+1]-q[t];if("right"===M||"center"===M)for(let t=o-1;t>=Math.max(o-40,0)&&(""===J(e,n,t)&&!K(e,n,t));t--)A+=q[t+1]-q[t]}const z=x?.vAlign??"bottom",F=C.error?"var(--danger-text)":C.color??x?.color;u.push(nt("div",{"data-cell":c,className:"pointer-events-none",style:{position:"absolute",left:g-A,top:p,width:E+A,height:w,boxSizing:"border-box",padding:"0 4px",overflow:"hidden",display:"flex",alignItems:"top"===z?"flex-start":"middle"===z?"center":"flex-end",justifyContent:x?.wrap?void 0:"right"===M?"flex-end":"center"===M?"center":"flex-start",textAlign:M,whiteSpace:x?.wrap?"pre-wrap":"pre",wordBreak:x?.wrap?"break-word":void 0,fontSize:(x?.fontSize??d)*ct,lineHeight:1.3,paddingBottom:"bottom"===z?2:void 0,fontWeight:x?.bold?700:void 0,fontStyle:x?.italic?"italic":void 0,textDecoration:[x?.underline?"underline":"",x?.strike?"line-through":""].join(" ").trim()||void 0,color:F},children:nt("span",{style:x?.wrap?{width:"100%"}:void 0,children:T})},`t${c}`))};for(let t=n;t<=o;t++)for(let r=i;r<=c;r++){const n=K(e,t,r);(!n||n.r1===t&&n.c1===r)&&h(t,r,n)}for(const t of e.merges)(t.r1<n||t.c1<i)&&t.r2>=n&&t.r1<=o&&t.c2>=i&&t.c1<=c&&h(t.r1,t.c1,t);return[...s,...u]},be=(t,r,n,l)=>{const a=[],c=(e,o,i,c)=>{e.r2<t||e.r1>r||e.c2<n||e.c1>l||a.push(nt("div",{style:{position:"absolute",boxSizing:"border-box",pointerEvents:"none",left:q[e.c1],top:Q[e.r1],width:q[e.c2+1]-q[e.c1],height:Q[e.r2+1]-Q[e.r1],...i},children:c},o))},u=o.range,d=u.r1!==u.r2||u.c1!==u.c2,f=K(e,o.active.row,o.active.col),h=!!f&&f.r1===u.r1&&f.r2===u.r2&&f.c1===u.c1&&f.c2===u.c2;return c(u,"sel",{background:d&&!h?"color-mix(in srgb, var(--accent-fill) 12%, transparent)":void 0,border:"2px solid var(--accent-fill)"}),Y&&c(Y,"fill",{border:"1px dashed var(--ink-muted)"}),i&&c(i,"clip",{border:"2px dashed var(--accent-fill)"}),s.forEach((e,t)=>c(e.range,`ref${t}`,{border:`2px solid ${e.color}`,background:`color-mix(in srgb, ${e.color} 10%, transparent)`})),a},xe=[];ee&&te&&xe.push({key:"corner",left:at,top:it,width:ne,height:re,offsetX:0,offsetY:0,r1:0,r2:ee-1,c1:0,c2:te-1}),ee&&xe.push({key:"top",left:at+ne,top:it,width:fe,height:re,offsetX:O.x,offsetY:0,r1:0,r2:ee-1,c1:ge,c2:ve}),te&&xe.push({key:"left",left:at,top:it+re,width:ne,height:he,offsetX:0,offsetY:O.y,r1:me,r2:pe,c1:0,c2:te-1}),xe.push({key:"main",left:at+ne,top:it+re,width:fe,height:he,offsetX:O.x,offsetY:O.y,r1:me,r2:pe,c1:ge,c2:ve});const ye=o.range,Ce=[];for(let e=0;e<te;e++)Ce.push(e);for(let e=ge;e<=ve;e++)Ce.push(e);const ke=[];for(let e=0;e<ee;e++)ke.push(e);for(let e=me;e<=pe;e++)ke.push(e);const Ne=0===ye.r1&&ye.r2===e.rowCount-1,De=0===ye.c1&&ye.c2===e.colCount-1,Se="absolute flex items-center justify-center select-none text-xs border-r border-b border-line",Re="bg-accent-tint text-accent-text",Me="bg-surface-sunken text-ink-muted",Te=ye.r2<ee||ye.r2>=me,Ee=ae(ye.c2+1),Ae=ie(ye.r2+1),ze=Te&&!h&&Ee>=at&&Ae>=it&&Ee<=$.width&&Ae<=$.height,Fe=K(e,o.active.row,o.active.col)??{r1:o.active.row,c1:o.active.col,r2:o.active.row,c2:o.active.col},Ie={x:ae(Fe.c1),y:ie(Fe.r1),width:q[Fe.c2+1]-q[Fe.c1],height:Q[Fe.r2+1]-Q[Fe.r1],viewportWidth:$.width,viewportHeight:$.height},{filter:Oe}=e,Le=Oe?.range.r1??-1,Pe=[];if(Oe&&(Le<ee||Le>=me&&Le<=pe))for(let e=Oe.range.c1;e<=Oe.range.c2;e++)q[e+1]>q[e]&&(e<te||e>=ge&&e<=ve)&&Pe.push(e);return nt("div",{ref:I,tabIndex:0,role:"grid","aria-label":e.name,"aria-rowcount":e.rowCount,"aria-colcount":e.colCount,className:"relative h-full w-full overflow-auto outline-none bg-surface text-ink",onScroll:e=>P({x:e.currentTarget.scrollLeft,y:e.currentTarget.scrollTop}),onKeyDown:R,onCopy:M,onCut:T,onPaste:E,children:nt("div",{style:{width:at+oe,height:it+le},children:ot("div",{className:"sticky top-0 left-0 overflow-hidden",style:{width:$.width,height:$.height},children:[ot("div",{className:"absolute inset-0",onPointerDown:t=>{if(0!==t.button)return;const r=se(t.clientX,t.clientY);if(h)return t.preventDefault(),g(V(r,r),!1),void ue(e=>g(V(r,se(e.clientX,e.clientY)),!1),e=>g(V(r,se(e.clientX,e.clientY)),!0));if(I.current?.focus({preventScroll:!0}),t.detail>=2)return t.preventDefault(),void p(r);const n=t.shiftKey?o.active:K(e,r.row,r.col)?{row:K(e,r.row,r.col).r1,col:K(e,r.row,r.col).c1}:r;de(n,r),ue(e=>de(n,se(e.clientX,e.clientY)),()=>{})},onContextMenu:e=>N(e,"cell",se(e.clientX,e.clientY)),children:[xe.map(e=>nt("div",{className:"absolute overflow-hidden",style:{left:e.left,top:e.top,width:e.width,height:e.height},children:ot("div",{className:"absolute",style:{left:-e.offsetX,top:-e.offsetY,width:oe,height:le},children:[we(e.r1,e.r2,e.c1,e.c2),be(e.r1,e.r2,e.c1,e.c2)]})},e.key)),re>0&&nt("div",{className:"absolute bg-line-strong pointer-events-none",style:{left:0,right:0,top:it+re-1,height:2}}),ne>0&&nt("div",{className:"absolute bg-line-strong pointer-events-none",style:{top:0,bottom:0,left:at+ne-1,width:2}})]}),Pe.map(e=>{const t=ae(e+1),r=ie(Le),n=Q[Le+1]-Q[Le],o=(Oe?.excluded[e]?.length??0)>0;return nt("button",{type:"button","aria-label":F.filterColumn(k(e)),onClick:t=>{t.stopPropagation(),D(e,t.currentTarget.getBoundingClientRect())},onPointerDown:e=>e.stopPropagation(),className:`absolute flex items-center justify-center rounded border ${o?"":"border-line"} ${o?"border-accent-fill bg-accent-tint":"bg-surface hover:bg-surface-sunken"}`,style:{left:t-19,top:r+Math.max(0,(n-17)/2),width:17,height:17},children:nt(rt,{name:"filter",size:11})},e)}),ze&&nt("div",{"aria-label":F.fillHandle,className:"absolute bg-accent-fill border border-surface cursor-crosshair",style:{left:Ee-5,top:Ae-5,width:8,height:8},onPointerDown:e=>{e.preventDefault(),e.stopPropagation();const t=o.range;let r=null;ue(e=>{r=(e=>{const r=se(e.clientX,e.clientY);return(r.row>t.r2?r.row-t.r2:r.row<t.r1?t.r1-r.row:0)>=(r.col>t.c2?r.col-t.c2:r.col<t.c1?t.c1-r.col:0)?{...t,r1:Math.min(t.r1,r.row),r2:Math.max(t.r2,r.row)}:{...t,c1:Math.min(t.c1,r.col),c2:Math.max(t.c2,r.col)}})(e),G(r)},()=>{G(null),!r||r.r1===t.r1&&r.r2===t.r2&&r.c1===t.c1&&r.c2===t.c2||v(r)})}}),nt("div",{className:"absolute top-0 overflow-hidden bg-surface-sunken",style:{left:at,right:0,height:it},children:Ce.map(t=>{const r=q[t+1]-q[t];if(r<=0)return null;const n=q[t]-(t>=te?O.x:0),l=t>=ye.c1&&t<=ye.c2;return ot("div",{className:`${Se} ${l?Re:Me} ${l&&Ne?"font-semibold":""}`,style:{left:n,top:0,width:r,height:it},onPointerDown:r=>((t,r)=>{if(0!==t.button)return;I.current?.focus({preventScroll:!0});const n=t.shiftKey?o.active.col:r,l=t=>{const r={r1:0,c1:Math.min(n,t),r2:e.rowCount-1,c2:Math.max(n,t)};m({active:{row:0,col:n},range:r})};l(r),ue(e=>l(se(e.clientX,e.clientY).col),()=>{})})(r,t),onContextMenu:e=>N(e,"col",{row:0,col:t}),children:[k(t),nt("div",{className:"absolute top-0 bottom-0 cursor-col-resize",style:{right:-3,width:7},onPointerDown:e=>((e,t)=>{e.preventDefault(),e.stopPropagation();const r=e.clientX,n=q[t+1]-q[t],o=e=>Math.max(16,Math.round(n+e.clientX-r));ue(e=>H({col:t,width:o(e)}),e=>{H(null),o(e)!==n&&w(t,o(e))})})(e,t),onDoubleClick:e=>{e.stopPropagation(),y(t)}})]},t)})}),nt("div",{className:"absolute left-0 overflow-hidden bg-surface-sunken",style:{top:it,bottom:0,width:at},children:ke.map(t=>{const r=Q[t+1]-Q[t];if(r<=0)return null;const n=Q[t]-(t>=ee?O.y:0),l=t>=ye.r1&&t<=ye.r2;return ot("div",{className:`${Se} ${l?Re:Me} ${l&&De?"font-semibold":""}`,style:{left:0,top:n,width:at,height:r},onPointerDown:r=>((t,r)=>{if(0!==t.button)return;I.current?.focus({preventScroll:!0});const n=t.shiftKey?o.active.row:r,l=t=>{const r={r1:Math.min(n,t),c1:0,r2:Math.max(n,t),c2:e.colCount-1};m({active:{row:n,col:0},range:r})};l(r),ue(e=>l(se(e.clientX,e.clientY).row),()=>{})})(r,t),onContextMenu:e=>N(e,"row",{row:t,col:0}),children:[t+1,nt("div",{className:"absolute left-0 right-0 cursor-row-resize",style:{bottom:-3,height:7},onPointerDown:e=>((e,t)=>{e.preventDefault(),e.stopPropagation();const r=e.clientY,n=Q[t+1]-Q[t],o=e=>Math.max(12,Math.round(n+e.clientY-r));ue(e=>X({row:t,height:o(e)}),e=>{X(null),o(e)!==n&&x(t,o(e))})})(e,t),onDoubleClick:e=>{e.stopPropagation(),C(t)}})]},t)})}),nt("div",{role:"button","aria-label":F.selectAll,className:`${Se} top-0 left-0 cursor-pointer bg-surface-sunken hover:bg-line`,style:{width:at,height:it},onPointerDown:t=>{t.preventDefault(),I.current?.focus({preventScroll:!0}),m({active:{row:0,col:0},range:{r1:0,c1:0,r2:e.rowCount-1,c2:e.colCount-1}})},onContextMenu:e=>N(e,"corner",{row:0,col:0})}),S?.(Ie)]})})})}),ht=["#000000","#434343","#666666","#999999","#cccccc","#efefef","#ffffff","#c00000","#ff0000","#ffc000","#ffff00","#92d050","#00b050","#00b0f0","#0070c0","#002060","#7030a0","#f4cccc","#fce5cd","#fff2cc","#d9ead3","#d0e0e3","#c9daf8","#d9d2e9","#ead1dc"],mt=["#1a73e8","#d93025","#7b1fa2","#188038","#e37400","#c5221f"];function gt(e,t){let r=!1;for(let n=0;n<t;n++)'"'===e[n]&&(r=!r);return r}function pt(e,t){if("="!==e[0]||gt(e,t))return null;const r=/[A-Za-z][A-Za-z0-9.]*$/.exec(e.slice(0,t));if(!r)return null;if("!"===e[r.index-1]||"("===e[t])return null;const n=r[0].toUpperCase(),o=h.filter(e=>e.startsWith(n));return o.length?{start:r.index,prefix:n,matches:o.slice(0,8)}:null}var vt={ABS:"value",AND:"condition1, [condition2, ...]",AVERAGE:"value1, [value2, ...]",AVERAGEIF:"range, criterion, [average_range]",AVERAGEIFS:"average_range, range1, criterion1, ...",CEILING:"value, [factor]","CEILING.MATH":"value, [factor]",CHOOSE:"index, choice1, [choice2, ...]",COLUMN:"[cell]",COLUMNS:"range",CONCAT:"value1, [value2, ...]",CONCATENATE:"value1, [value2, ...]",COS:"angle",COUNT:"value1, [value2, ...]",COUNTA:"value1, [value2, ...]",COUNTBLANK:"range",COUNTIF:"range, criterion",COUNTIFS:"range1, criterion1, ...",DATE:"year, month, day",DATEDIF:"start, end, unit",DAY:"date",DAYS:"end, start",EDATE:"start, months",EOMONTH:"start, months",EXACT:"text1, text2",EXP:"value",FIND:"find, within, [start]",FLOOR:"value, [factor]","FLOOR.MATH":"value, [factor]",FV:"rate, periods, payment, [present], [type]",HLOOKUP:"key, range, row, [approximate]",HOUR:"time",IF:"condition, if_true, [if_false]",IFERROR:"value, [if_error]",IFNA:"value, [if_na]",IFS:"condition1, value1, ...",INDEX:"range, row, [column]",INT:"value",ISBLANK:"value",ISERROR:"value",ISLOGICAL:"value",ISNA:"value",ISNUMBER:"value",ISTEXT:"value",LARGE:"range, k",LEFT:"text, [count]",LEN:"text",LN:"value",LOG:"value, [base]",LOG10:"value",LOWER:"text",MATCH:"key, range, [type]",MAX:"value1, [value2, ...]",MEDIAN:"value1, [value2, ...]",MID:"text, start, count",MIN:"value1, [value2, ...]",MINUTE:"time",MOD:"value, divisor",MODE:"value1, [value2, ...]","MODE.SNGL":"value1, [value2, ...]",MONTH:"date",N:"value",NA:"",NETWORKDAYS:"start, end, [holidays]",NOT:"condition",NOW:"",NPV:"rate, value1, [value2, ...]",OR:"condition1, [condition2, ...]",PI:"",PMT:"rate, periods, present, [future], [type]",POWER:"value, exponent",PRODUCT:"value1, [value2, ...]",PROPER:"text",PV:"rate, periods, payment, [future], [type]",RAND:"",RANDBETWEEN:"low, high",RANK:"value, range, [ascending]","RANK.EQ":"value, range, [ascending]",REPLACE:"text, start, count, new",REPT:"text, count",RIGHT:"text, [count]",ROUND:"value, [places]",ROUNDDOWN:"value, [places]",ROUNDUP:"value, [places]",ROW:"[cell]",ROWS:"range",SEARCH:"find, within, [start]",SECOND:"time",SIGN:"value",SIN:"angle",SMALL:"range, k",SQRT:"value",STDEV:"value1, [value2, ...]","STDEV.P":"value1, [value2, ...]","STDEV.S":"value1, [value2, ...]",STDEVP:"value1, [value2, ...]",SUBSTITUTE:"text, find, new, [occurrence]",SUM:"value1, [value2, ...]",SUMIF:"range, criterion, [sum_range]",SUMIFS:"sum_range, range1, criterion1, ...",SUMPRODUCT:"range1, [range2, ...]",SWITCH:"value, case1, result1, ..., [default]",TAN:"angle",TEXT:"value, format",TEXTJOIN:"delimiter, skip_blank, value1, ...",TIME:"hour, minute, second",TODAY:"",TRIM:"text",TRUNC:"value, [places]",UPPER:"text",VALUE:"text",VAR:"value1, [value2, ...]","VAR.P":"value1, [value2, ...]","VAR.S":"value1, [value2, ...]",VARP:"value1, [value2, ...]",VLOOKUP:"key, range, column, [approximate]",WEEKDAY:"date, [type]",XLOOKUP:"key, lookup_range, result_range, [if_not_found], [match_mode]",XOR:"condition1, [condition2, ...]",YEAR:"date"};import{Fragment as wt,jsx as bt,jsxs as xt}from"react/jsx-runtime";var yt=[8,9,10,11,12,14,16,18,20,24,28,36],Ct="undefined"!=typeof navigator&&/Mac|iPhone|iPad/.test(navigator.platform),kt=Ct?"⌘":"Ctrl+";function Nt(e,t,r){const n=URL.createObjectURL(new Blob([e],{type:t})),o=document.createElement("a");o.href=n,o.download=r,o.click(),URL.revokeObjectURL(n)}var Dt=o;function St({spreadsheetId:t,onClose:r}){const n=c(),{store:o,canCreate:a=!0,canDelete:i=!0,chooseFile:u}=s(),[d]=be(()=>null!=Ge()),[f,h]=be(null),[m,g]=be(null);if(!o||d)return bt(Et,{onClose:r});if(t)return bt(Mt,{store:o,id:t,onClose:r});if(f?.id)return bt(Mt,{store:o,id:f.id,onClose:()=>h(null)},f.key);if(f?.file)return bt(Et,{initialFile:f.file,hasStore:!0,onClose:()=>h(null)},f.key);return bt(he,{words:{windowTitle:n.filesHeading,heading:n.filesHeading,newFile:n.newFile,emptyTitle:n.filesEmptyTitle,emptyBody:n.filesEmptyBody,deleteConfirm:n.deleteConfirm,createFailed:n.createFailed,deleteFailed:n.deleteFailed},files:n.files,list:o.list,create:()=>o.create(n.untitled),rename:o.rename,remove:o.remove,canCreate:a,canDelete:i,accept:Dt,choose:u&&{run:u,request:{title:n.files.choosing(n.fileKind,n.filesHeading),extensions:l}},onOpen:e=>h({key:Date.now(),id:e}),onOpenFile:(t,r)=>{m||(g(n.files.opening(t.name)),e(o,t).then(async e=>{const o=await me(r,e.id);Xe.success(n.files.savedCopy(e.title,t.name,o?r?.location:void 0)),h({key:Date.now(),id:e.id})}).catch(()=>Xe.error(n.files.openFailed(t.name))).finally(()=>g(null)))},busy:m})}function Rt({id:e,onClose:t}){return bt(St,{spreadsheetId:e,onClose:t})}function Mt({store:e,id:t,onClose:r,pane:n}){const o=c(),[l,a]=be(null),[i,s]=be(!1),u=ge(()=>{s(!1),e.get(t).then(e=>a(t=>({kept:e,nonce:(t?.nonce??0)+1})),()=>s(!0))},[t,e]);return pe(u,[u]),i?bt("div",{className:"office-open-failed",children:bt(Fe,{title:o.storedOpenFailed,children:r&&bt(Me,{onClick:r,children:o.backToFiles})})}):l?bt(Et,{stored:{store:e,...l.kept},onClose:r,onReload:u,pane:n},l.nonce):bt(Le,{size:"sm",padding:"",className:"h-full",label:o.loading})}function Tt({initial:e,spreadsheetId:t,bridge:r,onSaveToFiles:n}){const{store:o}=s(),l=ve(()=>({bridge:r,onSaveToFiles:n}),[r,n]);return o&&t?bt(Mt,{store:o,id:t,pane:l}):bt(Et,{initial:e??{rows:[],filename:""},pane:l})}function Et({stored:e,initialFile:o,hasStore:l,onClose:s,onReload:u,initial:f,pane:h}){const b=c(),k=we(void 0);void 0===k.current&&(k.current=e?null:f?{token:-1,data:f}:Ge());const he=we(k.current?.data??null),[me]=be(()=>{const e=k.current;if(!e)return null;const t=At(e.data,b.sheetName(1));return t?{sheet:t,title:e.data.filename.replace(/\.(csv|tsv|txt)$/i,"")}:-1===e.token&&e.data.filename?{sheet:W(b.sheetName(1)),title:e.data.filename}:null}),[Fe,Le]=be(()=>e?i(e.workbook,b.sheetName(1)):me?[me.sheet]:[W(b.sheetName(1))]),[_e,Ze]=be(0),[Qe,Je]=be(e?.title??me?.title??b.untitled),[qe,et]=be(()=>k.current?.data.onEmail),tt=we(Fe),rt=we([]),nt=we([]),[,ot]=be(0),lt=ge(e=>{const t=tt.current,r=e(t);r!==t&&(rt.current.push(t),rt.current.length>100&&rt.current.shift(),nt.current=[],tt.current=r,Le(r),ot(e=>e+1))},[]),at=ge(e=>{rt.current=[],nt.current=[],tt.current=e,Le(e),Ze(0),ot(e=>e+1)},[]),it=ge(()=>{const e=rt.current.pop();e&&(nt.current.push(tt.current),tt.current=e,Le(e),Ze(t=>Math.min(t,e.length-1)),ot(e=>e+1))},[]),ct=ge(()=>{const e=nt.current.pop();e&&(rt.current.push(tt.current),tt.current=e,Le(e),Ze(t=>Math.min(t,e.length-1)),ot(e=>e+1))},[]),st=we(Fe),ut=we(e?.version??""),dt=we(e?.title??""),[St,Rt]=be(!1),Mt=ke(),Tt=ye({save:async t=>{e&&(ut.current=await e.store.save(e.id,{sheets:t},ut.current))},onFailure:(e,t)=>{e instanceof a?(Tt.stop(),Rt(!0)):0===t&&Xe.error(b.saveFailed)}}),{push:Et,flush:zt}=Tt,Ft=we(Fe);pe(()=>{e&&Fe!==Ft.current&&(Ft.current=Fe,Et(Fe))},[Et,Fe,e]),pe(()=>()=>{zt()},[zt]),Se(e?Tt.state.pending||St:Fe!==st.current);const It=ge(e=>{const t=At(e,b.sheetName(1));t&&(at([t]),st.current=tt.current,Je(e.filename.replace(/\.(csv|tsv|txt)$/i,"")),et(()=>e.onEmail))},[at,b]);pe(()=>{const e=k.current;null!=e&&(je(e),e.data!==he.current&&It(e.data))},[]),pe(()=>{const e=k.current?.token;if(null==e)return;const t=t=>{const r=t.detail;r&&r.token===e&&It(r.data)};return window.addEventListener(Ye,t),()=>window.removeEventListener(Ye,t)},[]);const Ot=Math.min(_e,Fe.length-1),Lt=Fe[Ot],Pt=ve(()=>B(Fe),[Fe]),$t=ve(()=>I(Lt,Ot,Pt),[Lt,Ot,Pt]),Bt=we(null),Ut=we(null),[Kt,Ht]=be({}),Wt=Kt[Lt.id]??{active:{row:0,col:0},range:{r1:0,c1:0,r2:0,c2:0}},Xt=we(_e);Xt.current=_e;const Vt=ge(e=>{Ht(t=>({...t,[tt.current[Math.min(Xt.current,tt.current.length-1)].id]:e}))},[]),Yt=Wt.active,Gt=Lt.formats[L(Yt.row,Yt.col)]??{},jt=J(Lt,Yt.row,Yt.col),[_t,Zt]=be(null),Qt=we(_t);Qt.current=_t;const[Jt,qt]=be(null),[er,tr]=be(!0),[rr,nr]=be(!1),[or,lr]=be(null),[ar,ir]=be(null),[cr,sr]=be(!1),[ur,dr]=be(null),[fr,hr]=be(null),[mr,gr]=be(!1),[pr,vr]=be(""),[wr,br]=be(""),[xr,yr]=be({matchCase:!1,wholeCell:!1,inFormulas:!1}),Cr=we(null),kr=we(null),Nr=we(null),Dr=Ve(),Sr=Ve(),Rr=ge(()=>{Bt.current?.focus(),setTimeout(()=>{const e=document.activeElement;e&&e!==document.body&&!e.closest("[aria-haspopup]")||Bt.current?.focus()},0)},[]),Mr=ge(e=>{lt(t=>{const r=Math.min(Xt.current,t.length-1),n=e(t[r]);return n===t[r]?t:t.map((e,t)=>t===r?n:e)})},[lt]),Tr=we(null),Er=we(()=>!1);pe(()=>He(()=>!!Tr.current?.contains(document.activeElement)&&Er.current()),[]);const Ar=ge(e=>Lt.hiddenRows.includes(e)||$t.has(e),[Lt.hiddenRows,$t]),zr=ge(e=>Lt.hiddenCols.includes(e),[Lt.hiddenCols]),Fr=ge(e=>{const t=K(Lt,e.row,e.col),r=t??{r1:e.row,c1:e.col,r2:e.row,c2:e.col};Vt({active:t?{row:t.r1,col:t.c1}:e,range:r}),Bt.current?.scrollTo(e)},[Lt,Vt]),Ir=ge((e,t,r)=>{let{row:n,col:o}=e;const l=K(Lt,n,o);l&&(t>0&&(n=l.r2),t<0&&(n=l.r1),r>0&&(o=l.c2),r<0&&(o=l.c1));do{n+=t,o+=r}while(n>=0&&n<Lt.rowCount&&o>=0&&o<Lt.colCount&&(Ar(n)||zr(o)));return n<0||n>=Lt.rowCount||o<0||o>=Lt.colCount?e:{row:n,col:o}},[Lt,Ar,zr]),Or=ge((e,t,r)=>{const n=e=>""!==J(Lt,e.row,e.col);let o=e,l=Ir(o,t,r);if(l===o)return o;if(n(o)&&n(l)){for(;n(l);)if(o=l,l=Ir(o,t,r),l===o)return o;return o}for(;!n(l);)if(o=l,l=Ir(o,t,r),l===o)return o;return l},[Lt,Ir]),Lr=ge(e=>{const t=z(Lt,V(Wt.active,e));Vt({active:Wt.active,range:t}),Bt.current?.scrollTo(e)},[Lt,Wt.active,Vt]),Pr=ge(()=>{const{range:e,active:t}=Wt;return{row:t.row===e.r1?e.r2:e.r1,col:t.col===e.c1?e.c2:e.c1}},[Wt]),$r=we(null),Br=ge((e,t={})=>{const r=J(Lt,e.row,e.col),n=t.text??A(r,Lt.formats[L(e.row,e.col)]);qt(e=>e?.cut?null:e),t.inBar||null!==$r.current||($r.current=n.length),Zt({sheetId:Lt.id,row:e.row,col:e.col,text:n,mode:t.mode??(void 0!==t.text?"enter":"edit"),inBar:!!t.inBar,caret:n.length,pick:null,suggestion:0})},[Lt]),Ur=ge(e=>{const t=Qt.current;if(!t)return!1;Qt.current=null,Zt(null),lt(r=>{const n=r.findIndex(e=>e.id===t.sheetId);if(n<0)return r;const o=r[n];if(t.text===A(J(o,t.row,t.col),o.formats[L(t.row,t.col)])&&!e)return r;let l=o;if(e)for(let r=e.r1;r<=e.r2;r++)for(let n=e.c1;n<=e.c2;n++){const e=$(t.text)?le(q(t.text).raw,r-t.row,n-t.col):t.text;l=D(l,r,n,e)}else l=D(l,t.row,t.col,t.text);return r.map((e,t)=>t===n?l:e)});const r=tt.current.findIndex(e=>e.id===t.sheetId);return r>=0&&r!==Xt.current&&Ze(r),!0},[lt]),Kr=ge(()=>{const e=Qt.current;if(Qt.current=null,Zt(null),e){const t=tt.current.findIndex(t=>t.id===e.sheetId);t>=0&&t!==Xt.current&&Ze(t)}Rr()},[Rr]),Hr=ge((e,t)=>{Fr(Ir(Wt.active,e,t)),Rr()},[Rr,Fr,Wt.active,Ir]);De(()=>{if(!_t)return;const e=_t.inBar?Cr.current:kr.current;e&&(document.activeElement!==e&&e.focus({preventScroll:!0}),null!==$r.current&&(e.setSelectionRange($r.current,$r.current),$r.current=null))},[_t]);const Wr=ge((e,t)=>{Zt(r=>r?{...r,text:e,caret:t,pick:null,suggestion:0}:r)},[]),Xr=_t?.sheetId===Lt.id,Vr=_t?pt(_t.text,_t.caret):null,Yr=_t?function(e,t){if("="!==e[0])return null;const r=[];let n=!1;for(let o=1;o<t;o++){const t=e[o];if('"'===t&&(n=!n),!n)if("("===t){const t=/([A-Za-z][A-Za-z0-9.]*)$/.exec(e.slice(1,o));r.push({name:t?t[1].toUpperCase():"",argIndex:0})}else")"===t?r.pop():","!==t&&";"!==t||!r.length||r[r.length-1].argIndex++}for(let e=r.length-1;e>=0;e--)if(r[e].name)return r[e];return null}(_t.text,_t.caret):null,Gr=!!_t&&(null!==_t.pick||function(e,t){if("="!==e[0]||gt(e,t))return!1;const r=e.slice(0,t).trimEnd(),n=e.slice(t).trimStart()[0];return!(void 0!==n&&!/[,;)+\-*/^&=<>%]/.test(n))&&/[=(,;+\-*/^&<>]$/.test(r)}(_t.text,_t.caret)),jr=ve(()=>_t?function(e,t,r,n,o){if("="!==e[0])return[];const l=[];let a=0;for(const i of ie(e.slice(1)).tokens){if("ref"!==i.type)continue;const e=mt[a++%mt.length];if(!(null===i.ref.sheet?r:i.ref.sheet.toLowerCase()===t.toLowerCase()))continue;const c=i.ref.b??i.ref.a,s=V({row:i.ref.a.row??0,col:i.ref.a.col??0},{row:c.row??n-1,col:c.col??o-1});l.push({range:s,color:e})}return l}(_t.text,Lt.name,Xr,Lt.rowCount,Lt.colCount):[],[_t,Lt.name,Lt.rowCount,Lt.colCount,Xr]),_r=ge((e,t)=>{const r=Qt.current;if(!r)return;const n=_({sheet:r.sheetId===tt.current[Xt.current].id?null:tt.current[Xt.current].name,a:{row:e.r1,col:e.c1,rowAbs:!1,colAbs:!1},b:e.r1===e.r2&&e.c1===e.c2?null:{row:e.r2,col:e.c2,rowAbs:!1,colAbs:!1}}),o=r.pick?.start??r.caret,l=r.pick?.end??r.caret,a=r.text.slice(0,o)+n+r.text.slice(l),i=o+n.length;$r.current=i,Zt({...r,text:a,caret:i,pick:t?null:{start:o,end:i}})},[]),Zr=ge(e=>{const t=Qt.current,r=t?pt(t.text,t.caret):null;if(!t||!r)return;const n=function(e,t,r,n){const o=`${n}(`;return{text:e.slice(0,r)+o+e.slice(t),caret:r+o.length}}(t.text,t.caret,r.start,e);$r.current=n.caret,Zt({...t,text:n.text,caret:n.caret,suggestion:0,pick:null})},[]),Qr=e=>{if(_t){if(e.stopPropagation(),Vr){if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();const t=Vr.matches.length;return void Zt({..._t,suggestion:(_t.suggestion+("ArrowDown"===e.key?1:t-1))%t})}if("Tab"===e.key||"Enter"===e.key&&_t.suggestion>0)return e.preventDefault(),void Zr(Vr.matches[_t.suggestion])}if("Enter"===e.key){if(e.altKey){e.preventDefault();const{selectionStart:t,selectionEnd:r,value:n}=e.currentTarget,o=`${n.slice(0,t)}\n${n.slice(r)}`;return $r.current=t+1,void Wr(o,t+1)}return e.preventDefault(),e.ctrlKey||e.metaKey?(Ur(Wt.range),void Rr()):(Ur(),void Hr(e.shiftKey?-1:1,0))}if("Tab"===e.key)return e.preventDefault(),Ur(),void Hr(0,e.shiftKey?-1:1);if("F4"===e.key){e.preventDefault();const t=function(e,t){if("="!==e[0])return null;const r=t-1;for(const t of ie(e.slice(1)).tokens){if("ref"!==t.type||r<t.start||r>t.end)continue;const n={...t.ref,a:R(t.ref.a),b:t.ref.b?R(t.ref.b):null},o=_(n);return{text:`=${e.slice(1,t.start+1)}${o}${e.slice(t.end+1)}`,caret:t.start+1+o.length}}return null}(_t.text,e.currentTarget.selectionStart);return void(t&&($r.current=t.caret,Wr(t.text,t.caret)))}"enter"!==_t.mode||_t.inBar||$(_t.text)||!e.key.startsWith("Arrow")||(e.preventDefault(),Ur(),Hr("ArrowDown"===e.key?1:"ArrowUp"===e.key?-1:0,"ArrowRight"===e.key?1:"ArrowLeft"===e.key?-1:0))}},Jr=e=>{const t=e.currentTarget.selectionStart;Zt(e=>e&&e.caret!==t?{...e,caret:t,pick:null}:e)},qr=ge(e=>{Ur(),e(),Rr()},[Ur,Rr]),en=we(Wt);en.current=Wt;const tn=h?.bridge,rn=we(Qe);rn.current=Qe;const nn=Kt[Lt.id]?Wt:null,on=we(nn);on.current=nn,pe(()=>{if(tn)return tn.attach({sheets:()=>tt.current,activeSheet:()=>Math.min(Xt.current,tt.current.length-1),title:()=>rn.current||b.untitled,selection:()=>on.current?{sheet:Math.min(Xt.current,tt.current.length-1),range:on.current.range}:null,commit:e=>lt(()=>e),undoLast:it})},[tn,lt,b,it]),pe(()=>{tn?.changed()},[tn,nn,Ot,Fe,Qe]);const ln=ge(e=>{qr(()=>Mr(t=>se(t,en.current.range,e)))},[qr,Mr]),an=ge(e=>{const t=!Gt[e];ln(r=>de(r,e,t||void 0))},[Gt,ln]),cn=ge(e=>{ln(t=>de(t,"numFmt","General"===e?void 0:e))},[ln]),sn=ge(e=>{const t=Pt.value(Ot,Yt.row,Yt.col),r=v(Gt.numFmt??"General",e,"number"==typeof t?t:null);cn(r)},[Yt,Gt.numFmt,Pt,Ot,cn]),un=ge((e,t)=>{const{range:r}=Wt,[n,o]="row"===e?[r.r1,r.r2]:[r.c1,r.c2],l="row"===e?Lt.rowCount:Lt.colCount,a=o-n+1>=l?1:o-n+1;l+a>("row"===e?g:m)||qr(()=>lt(r=>y(r,Ot,e,t?o+1:n,a)))},[Lt.colCount,Lt.rowCount,lt,Ot,qr,Wt]),dn=ge(e=>{const{range:t}=Wt,[r,n]="row"===e?[t.r1,t.r2]:[t.c1,t.c2],o="row"===e?Lt.rowCount:Lt.colCount,l=Math.min(n-r+1,o-1);l<1||qr(()=>{lt(t=>y(t,Ot,e,r,-l)),Fr({row:"row"===e?Math.min(r,o-l-1):Wt.active.row,col:"col"===e?Math.min(r,o-l-1):Wt.active.col})})},[Lt.colCount,Lt.rowCount,lt,Ot,qr,Fr,Wt]),fn=ge(e=>{const{range:t}=Wt;qr(()=>Mr(r=>{if("row"===e){const e=new Set(r.hiddenRows);for(let r=t.r1;r<=t.r2;r++)e.add(r);return{...r,hiddenRows:[...e]}}const n=new Set(r.hiddenCols);for(let e=t.c1;e<=t.c2;e++)n.add(e);return{...r,hiddenCols:[...n]}}))},[qr,Wt,Mr]),hn=ge(e=>{qr(()=>Mr(t=>"row"===e?{...t,hiddenRows:[]}:{...t,hiddenCols:[]}))},[qr,Mr]),mn=ge(e=>{qr(()=>Mr(t=>{const r=Wt.range.r1===Wt.range.r2&&Wt.range.c1===Wt.range.c2,n=0===Wt.range.r1&&Wt.range.r2===t.rowCount-1;let o=r?M(t,Wt.range):Wt.range;return n&&(o={...o,r2:Math.max(o.r1,ue(t)?.row??0)}),t.filter&&Z(t.filter.range,Wt.active.row,Wt.active.col)&&(o={...t.filter.range,r1:t.filter.range.r1+1}),ae(t,Ot,Pt,o,Wt.active.col,e)}))},[Pt,Ot,qr,Wt,Mr]),gn=ge(()=>{ir(null),qr(()=>Mr(e=>{if(e.filter)return{...e,filter:null};const t=M(e,Wt.range);return t.r1===t.r2?e:{...e,filter:{range:t,excluded:{}}}}))},[qr,Wt.range,Mr]),pn=ge(()=>{qr(()=>Mr(e=>e.merges.some(e=>Z(Wt.range,e.r1,e.c1))?ce(e,Wt.range):U(e,Wt.range)))},[qr,Wt.range,Mr]),vn=ge((e,t)=>{qr(()=>Mr(r=>({...r,frozenRows:e??r.frozenRows,frozenCols:t??r.frozenCols})))},[qr,Mr]),wn=ge(e=>{const{range:t,active:r}=Wt,n=t.r1===t.r2&&t.c1===t.c2;let o="";if(n){const e=(e,t)=>"number"==typeof Pt.value(Ot,e,t);let t=r.row;for(;t>0&&e(t-1,r.col);)t--;let n=r.col;for(;n>0&&e(r.row,n-1);)n--;t<r.row?o=Q({r1:t,c1:r.col,r2:r.row-1,c2:r.col}):n<r.col&&(o=Q({r1:r.row,c1:n,r2:r.row,c2:r.col-1}))}else o=Q(t);const l=n?r:{row:t.r2+1,col:t.c1};Ur(),n||Fr(l);const a=`=${e}(${o})`;$r.current=a.length-1,Br(l,{text:a})},[Ur,Pt,Ot,Fr,Wt,Br]),bn=ge((e,t)=>{const r=Wt.range,n={...r,r2:Math.min(r.r2,Math.max(r.r1,Lt.cells.length-1))},o=S(Lt,Ot,Pt,n,e);qt(o),t?(t.preventDefault(),t.clipboardData.setData("text/plain",o.text)):navigator.clipboard?.writeText(o.text).catch(()=>{})},[Lt,Pt,Ot,Wt.range]),xn=ge((e,t)=>{const{range:r}=Wt;if(Jt&&Jt.text===e){if(Jt.cut){const e=tt.current.findIndex(e=>e.id===Jt.sheetId);if(e<0)return;let t=null;return lt(n=>{const o=H(n,e,Jt,Ot,r);return t=o.range,o.sheets}),t&&Vt({active:{row:t.r1,col:t.c1},range:t}),void qt(null)}return void Mr(e=>{const n=j(e,Jt,r,t);return Vt({active:Wt.active,range:n.range}),n.sheet})}if(!e)return;const n=function(e){const t=e.replace(/\r\n?/g,"\n").replace(/\n$/,"");if(!t.includes("\t")&&!t.includes("\n"))return[[t]];if(!t.includes('"'))return t.split("\n").map(e=>e.split("\t"));const r=Y(t.includes("\t")?t:`${t}\t`);return r.length?r:[[t]]}(e);Mr(e=>{let t=e;n.forEach((e,n)=>e.forEach((e,o)=>{t=D(t,r.r1+n,r.c1+o,e)}));const o=n.reduce((e,t)=>Math.max(e,t.length),1);return Vt({active:Wt.active,range:{r1:r.r1,c1:r.c1,r2:r.r1+n.length-1,c2:r.c1+o-1}}),t})},[Jt,lt,Ot,Wt,Vt,Mr]),yn=ge(e=>{qr(()=>{const t=navigator.clipboard?.readText?.();t?t.then(t=>xn(t,e)).catch(()=>{Jt&&xn(Jt.text,e)}):Jt&&xn(Jt.text,e)})},[Jt,xn,qr]);Er.current=()=>Qt.current?(Kr(),!0):ar?(ir(null),Rr(),!0):ur?(dr(null),Rr(),!0):cr?(sr(!1),Rr(),!0):null!==fr?(hr(null),Rr(),!0):mr?(gr(!1),Rr(),!0):!(!Jt&&!or)&&(qt(null),lr(null),!0);const Cn=Qe||b.spreadsheetFile,kn=ge(async()=>{Ur();try{const e=tt.current;Nt(await n(e,B(e)),"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",`${Cn}.xlsx`),st.current=e,ot(e=>e+1)}catch{Xe.error(b.saveFailed)}},[Ur,Cn,b]),Nn=()=>{const e=tt.current,t=Math.min(Xt.current,e.length-1);return ne(e[t],t,B(e))},Dn=async n=>{const o=n.name.replace(/\.(csv|tsv|txt|xlsx|xls|ods)$/i,"");try{if(Ur(),/\.(xlsx|xls|ods)$/i.test(n.name)){const e=new Uint8Array(await n.arrayBuffer()),o=/\.xlsx$/i.test(n.name)&&"undefined"!=typeof DecompressionStream?await r(e):await t(e);lt(()=>o),Ze(0)}else{const e=Y(await n.text());if(!e.length)return;Mr(t=>({...oe(t.name,e),id:t.id}))}e||Je(o)}catch{Xe.error(b.openFailed)}};pe(()=>{o&&Dn(o)},[]);const Sn=ve(()=>mr?O(Lt,Ot,Pt,pr,xr):[],[Lt,Pt,mr,xr,pr,Ot]),Rn=Sn.findIndex(e=>e.row===Wt.active.row&&e.col===Wt.active.col),Mn=e=>{if(!Sn.length)return;const t=Rn<0?e>0?0:Sn.length-1:(Rn+e+Sn.length)%Sn.length;Fr(Sn[t])},Tn=()=>{Ur();const e=Ot+1;lt(t=>{const r=X(t,b.sheetBase);return[...t.slice(0,e),W(r),...t.slice(e)]}),Ze(e),Rr()},En=()=>{if(!ur)return;const{index:e,name:t}=ur;dr(null);const r=t.trim();r&&r!==Fe[e]?.name&&(Fe.some((t,n)=>n!==e&&t.name.toLowerCase()===r.toLowerCase())?Xe.error(b.sheetNameTaken):lt(t=>ee(t,e,r)))},An=(e,t)=>{const r=e+t;r<0||r>=Fe.length||(lt(t=>{const n=[...t],[o]=n.splice(e,1);return n.splice(r,0,o),n}),e===Ot?Ze(r):r===Ot&&Ze(e))},zn=ge(e=>{Qt.current&&Ur(),Vt(e),or&&(Mr(t=>se(t,e.range,()=>or)),lr(null))},[Ur,or,Vt,Mr]),Fn=ge((e,t,r)=>{"cell"!==t||Z(Wt.range,r.row,r.col)?"col"!==t||0===Wt.range.r1&&Wt.range.r2===Lt.rowCount-1&&r.col>=Wt.range.c1&&r.col<=Wt.range.c2?"row"!==t||0===Wt.range.c1&&Wt.range.c2===Lt.colCount-1&&r.row>=Wt.range.r1&&r.row<=Wt.range.r2||Vt({active:{row:r.row,col:0},range:{r1:r.row,c1:0,r2:r.row,c2:Lt.colCount-1}}):Vt({active:{row:0,col:r.col},range:{r1:0,c1:r.col,r2:Lt.rowCount-1,c2:r.col}}):Fr(r),Dr.open(e,{kind:t,pos:r})},[Lt.colCount,Lt.rowCount,Dr,Fr,Wt.range,Vt]),In=ge((e,t)=>{if(!Lt.filter)return;const r=N(Lt,Ot,Pt,Lt.filter.range,e);ir({col:e,x:t.left,y:t.bottom+2,values:r,unticked:new Set(Lt.filter.excluded[e]??[]),search:""})},[Lt,Pt,Ot]),On=(e,t)=>{ir(null),qr(()=>Mr(r=>{if(!r.filter)return r;const{range:n}=r.filter;return ae(r,Ot,Pt,{...n,r1:n.r1+1},e,t)}))},Ln=ve(()=>{const{range:e}=Wt;return e.r1===e.r2&&e.c1===e.c2?null:re(Lt,Ot,Pt,e,$t)},[Lt,Pt,$t,Ot,Wt]),Pn=e=>P(Number(e.toPrecision(12)),Ln?.firstFormat??"#,##0.##").text,$n=(e,t)=>xt("span",{className:"flex w-full items-center justify-between gap-6",children:[bt("span",{children:e}),bt("span",{className:"text-xs text-ink-faint",children:t})]}),Bn=(e,t,r,n={})=>({key:e,label:t,onSelect:r,...n}),Un=e=>({type:"divider",key:e}),Kn=[{key:"general",label:b.formatGeneral,code:p.general},{key:"number",label:b.formatNumber,code:p.number},{key:"percent",label:b.formatPercent,code:p.percent},{key:"scientific",label:b.formatScientific,code:p.scientific},{key:"currency",label:b.formatCurrency,code:p.currency},{key:"date",label:b.formatDate,code:p.date},{key:"time",label:b.formatTime,code:p.time},{key:"dateTime",label:b.formatDateTime,code:p.dateTime},{key:"text",label:b.formatText,code:p.text}].map(e=>({type:"radio",key:e.key,label:e.label,checked:(Gt.numFmt??"General")===e.code,onSelect:()=>cn(e.code)})),Hn=[["all",b.bordersAll],["outer",b.bordersOuter],["top",b.bordersTop],["bottom",b.bordersBottom],["left",b.bordersLeft],["right",b.bordersRight],["none",b.bordersNone]].map(([e,t])=>Bn(e,t,()=>qr(()=>Mr(t=>w(t,Wt.range,e))))),Wn=[...["left","center","right"].map(e=>({type:"radio",key:e,label:"left"===e?b.alignLeft:"center"===e?b.alignCenter:b.alignRight,checked:Gt.align===e,onSelect:()=>ln(t=>de(t,"align",e))})),Un("v"),...["top","middle","bottom"].map(e=>({type:"radio",key:e,label:"top"===e?b.alignTop:"middle"===e?b.alignMiddle:b.alignBottom,checked:(Gt.vAlign??"bottom")===e,onSelect:()=>ln(t=>de(t,"vAlign",e))}))],Xn=yt.map(e=>({type:"radio",key:String(e),label:String(e),checked:(Gt.fontSize??d)===e,onSelect:()=>ln(t=>de(t,"fontSize",e===d?void 0:e))})),Vn=["SUM","AVERAGE","COUNT","MAX","MIN"].map(e=>Bn(e,e,()=>wn(e))),Yn=[...[0,1,2].map(e=>({type:"radio",key:`r${e}`,label:b.freezeRows(e),checked:Lt.frozenRows===e,onSelect:()=>vn(e,null)})),{type:"radio",key:"rUp",label:b.freezeUpToRow(Yt.row+1),checked:Lt.frozenRows===Yt.row+1&&Yt.row>1,onSelect:()=>vn(Yt.row+1,null)},Un("c"),...[0,1,2].map(e=>({type:"radio",key:`c${e}`,label:b.freezeColumns(e),checked:Lt.frozenCols===e,onSelect:()=>vn(null,e)})),{type:"radio",key:"cUp",label:b.freezeUpToColumn(x(0,Yt.col).replace(/\d+$/,"")),checked:Lt.frozenCols===Yt.col+1&&Yt.col>1,onSelect:()=>vn(null,Yt.col+1)}],Gn=[...e?[]:[Bn("new",b.menuNew,()=>qr(()=>{lt(()=>[W(b.sheetName(1))]),Ze(0),Je(b.untitled)}))],Bn("open",b.menuOpen,()=>Ut.current?.click()),Un("a"),Bn("xlsx",$n(b.saveExcel,`${kt}S`),()=>{kn()}),Bn("csv",b.saveCsv,()=>qr(()=>Nt(Nn(),"text/csv",`${Cn}.csv`))),...qe?[Un("b"),Bn("email",b.email,()=>qr(()=>qe(Nn(),`${Cn}.csv`)))]:[],...!e&&h?.onSaveToFiles?[Un("c"),Bn("keep",b.saveToFiles,()=>qr(()=>h.onSaveToFiles?.(Qe.trim()||b.untitled,tt.current)))]:[]],jn=[Bn("undo",$n(b.undo,`${kt}Z`),()=>qr(it),{disabled:0===rt.current.length}),Bn("redo",$n(b.redo,Ct?"⇧⌘Z":"Ctrl+Y"),()=>qr(ct),{disabled:0===nt.current.length}),Un("a"),Bn("cut",$n(b.cut,`${kt}X`),()=>qr(()=>bn(!0))),Bn("copy",$n(b.copy,`${kt}C`),()=>qr(()=>bn(!1))),Bn("paste",$n(b.paste,`${kt}V`),()=>yn("all")),Bn("pasteValues",b.pasteValues,()=>yn("values")),Bn("pasteFormats",b.pasteFormats,()=>yn("formats")),Un("b"),Bn("find",$n(b.findReplace,`${kt}F`),()=>{gr(!0),setTimeout(()=>Nr.current?.focus(),0)}),Bn("clear",$n(b.clearValues,"Delete"),()=>qr(()=>Mr(e=>C(e,Wt.range))))],_n=[{type:"submenu",key:"freeze",label:b.freeze,items:Yn},{type:"checkbox",key:"gridlines",label:b.gridlines,checked:er,onSelect:()=>tr(e=>!e)},{type:"checkbox",key:"formulas",label:$n(b.showFormulas,`${kt}\``),checked:rr,onSelect:()=>nr(e=>!e)}],Zn=[Bn("rowAbove",b.rowsAbove,()=>un("row",!1)),Bn("rowBelow",b.rowsBelow,()=>un("row",!0)),Bn("colLeft",b.columnsLeft,()=>un("col",!1)),Bn("colRight",b.columnsRight,()=>un("col",!0)),Un("a"),Bn("sheet",b.sheet,Tn),{type:"submenu",key:"fn",label:b.function,items:Vn}],Qn=[{type:"submenu",key:"number",label:b.number,items:Kn},Un("a"),Bn("bold",$n(b.bold,`${kt}B`),()=>an("bold")),Bn("italic",$n(b.italic,`${kt}I`),()=>an("italic")),Bn("underline",$n(b.underline,`${kt}U`),()=>an("underline")),Bn("strike",b.strikethrough,()=>an("strike")),{type:"submenu",key:"size",label:b.fontSize,items:Xn},Un("b"),{type:"submenu",key:"align",label:b.alignment,items:Wn},{type:"submenu",key:"borders",label:b.borders,items:Hn},Bn("wrap",b.wrapText,()=>an("wrap")),Bn("merge",b.mergeCells,pn),Un("c"),Bn("clearFormat",b.clearFormatting,()=>qr(()=>Mr(e=>se(e,Wt.range,()=>({})))))],Jn=[Bn("asc",b.sortAscending,()=>mn(!0)),Bn("desc",b.sortDescending,()=>mn(!1)),Un("a"),{type:"checkbox",key:"filter",label:b.filter,checked:!!Lt.filter,onSelect:gn},Un("b"),Bn("hideRows",b.hideRows,()=>fn("row")),Bn("hideCols",b.hideColumns,()=>fn("col")),Bn("unhideRows",b.unhideRows,()=>hn("row"),{disabled:!Lt.hiddenRows.length}),Bn("unhideCols",b.unhideColumns,()=>hn("col"),{disabled:!Lt.hiddenCols.length})],qn="rounded px-2 py-0.5 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",eo="inline-flex h-7 items-center gap-1 rounded px-2 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",to=bt("div",{className:"mx-1 h-4 w-px bg-line"}),ro=e=>e.preventDefault(),no=(e,t,r,n={})=>bt(Ie,{"aria-label":e,title:e,size:"sm",variant:"ghost",onMouseDown:ro,onClick:r,disabled:n.disabled,...void 0!==n.pressed?{"aria-pressed":n.pressed}:{},children:t}),oo=(e,t,r)=>bt(Pe,{triggerLabel:e,align:"start",triggerClassName:"inline-flex h-7 w-7 flex-col items-center justify-center rounded text-ink-muted hover:bg-line-subtle hover:text-ink",trigger:xt(wt,{children:[t,bt("span",{className:"h-0.5 w-4 rounded-sm",style:{background:Gt[r]??("color"===r?"var(--ink)":"var(--line)")}})]}),children:({close:t})=>bt(Ee,{label:e,value:Gt[r]??"",presets:ht,clearable:!0,dragWrites:"end",onChange:e=>{ln(t=>de(t,r,e||void 0)),t()}})}),lo=e=>{if(!_t||!Xr||_t.inBar)return null;const t=Lt.formats[L(_t.row,_t.col)],r=(t?.fontSize??d)*(4/3),n=Math.min(Math.max(e.width,_t.text.length*r*.62+16),e.viewportWidth-e.x-4);return bt("textarea",{ref:kr,"aria-label":b.cellEditor,value:_t.text,spellCheck:!1,rows:1,onChange:e=>Wr(e.target.value,e.target.selectionStart),onSelect:Jr,onKeyDown:Qr,onPointerDown:e=>e.stopPropagation(),className:"absolute resize-none overflow-hidden border-2 border-accent-fill bg-surface text-ink outline-none",style:{left:e.x,top:e.y,width:n,minHeight:e.height,height:Math.max(e.height,_t.text.split("\n").length*r*1.35+6),padding:"0 2px",fontSize:r,lineHeight:1.3,fontWeight:t?.bold?700:void 0,fontStyle:t?.italic?"italic":void 0,background:t?.fill??void 0,color:t?.color??void 0}})},ao=e=>{if(!_t||!Xr)return null;const t=e.y+e.height+2,r=Math.max(0,Math.min(e.x,e.viewportWidth-320));if(Vr)return xt("div",{role:"listbox","aria-label":b.functions,className:"absolute w-80 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",style:{left:r,top:t},onPointerDown:e=>e.preventDefault(),children:[Vr.matches.map((e,t)=>xt("div",{role:"option","aria-selected":t===_t.suggestion,onPointerDown:t=>{t.preventDefault(),t.stopPropagation(),Zr(e)},className:"flex cursor-pointer items-center justify-between gap-3 px-2 py-1 text-xs "+(t===_t.suggestion?"bg-accent-tint text-accent-text":"text-ink hover:bg-surface-sunken"),children:[bt("span",{className:"font-medium",children:e}),bt("span",{className:"truncate "+(t===_t.suggestion?"text-accent-text":"text-ink-muted"),children:b.functionHelp(e)})]},e)),xt("div",{className:"border-t border-line px-2 py-1 font-mono text-xs text-ink-muted",children:[Vr.matches[_t.suggestion],"(",vt[Vr.matches[_t.suggestion]]??"",")"]})]});if(Yr&&void 0!==vt[Yr.name]){const e=vt[Yr.name].split(", ");return xt("div",{className:"absolute max-w-md rounded-lg border border-line bg-surface px-2 py-1 text-xs text-ink-muted shadow-lg",style:{left:r,top:t},children:[xt("div",{className:"font-mono",children:[Yr.name,"(",e.map((t,r)=>xt("span",{children:[r>0?", ":"",bt("span",{className:r===Math.min(Yr.argIndex,e.length-1)?"font-semibold text-ink":"",children:t})]},t+r)),")"]}),bt("div",{className:"mt-0.5",children:b.functionHelp(Yr.name)})]})}return null},io=ar?ar.values.filter(e=>e.toLowerCase().includes(ar.search.toLowerCase())):[];return xt("div",{ref:Tr,className:"flex h-full flex-col bg-surface text-ink",children:[!h&&bt(Ne,{title:`${uo=Qe||b.untitled,uo.length>24?`${uo.slice(0,23)}…`:uo} - Spreadsheets`}),bt("input",{ref:Ut,type:"file",accept:Dt,onChange:e=>{const t=e.target.files?.[0];Ut.current&&(Ut.current.value=""),t&&Dn(t)},className:"hidden"}),xt("div",{className:"flex shrink-0 items-center gap-1 border-b border-line bg-surface-sunken px-2 py-1",children:[s&&bt(Ie,{"aria-label":b.backToFiles,title:b.backToFiles,size:"sm",variant:"ghost",onClick:()=>{zt(),s()},children:bt(Re,{name:"arrow-left",size:16})}),cr?bt("input",{type:"text",value:Qe,autoFocus:!0,"aria-label":b.rename,onChange:e=>Je(e.target.value),onBlur:()=>{sr(!1);const t=Qe.trim()||b.untitled;if(t!==Qe&&Je(t),e&&t!==dt.current){const r=dt.current;dt.current=t,e.store.rename(e.id,t).catch(()=>{Xe.error(b.renameFailed),dt.current=r,Je(r)})}},onKeyDown:e=>{"Enter"===e.key&&(e.currentTarget.blur(),Rr())},className:"w-40 rounded border border-line bg-surface px-2 py-0.5 text-sm font-medium text-ink"}):bt("button",{type:"button",onClick:()=>sr(!0),title:b.rename,className:"max-w-[200px] truncate rounded px-2 py-0.5 text-sm font-medium text-ink hover:bg-line-subtle",children:Qe||b.untitled}),bt(ze,{trigger:b.menuFile,items:Gn,align:"start",triggerClassName:qn}),bt(ze,{trigger:b.menuEdit,items:jn,align:"start",triggerClassName:qn}),bt(ze,{trigger:b.menuView,items:_n,align:"start",triggerClassName:qn}),bt(ze,{trigger:b.menuInsert,items:Zn,align:"start",triggerClassName:qn}),bt(ze,{trigger:b.menuFormat,items:Qn,align:"start",triggerClassName:qn}),bt(ze,{trigger:b.menuData,items:Jn,align:"start",triggerClassName:qn}),(e||l)&&bt("span",{className:"office-save-state",children:bt(Ce,{...e?xe(Tt.state,Mt.save):{tone:Fe!==st.current?"off-unsaved":"off",label:Fe!==st.current?b.noStoreEdited:b.noStoreClean}})})]}),St&&xt("div",{className:"office-conflict",role:"alert",children:[bt("span",{children:b.conflict}),bt(Me,{variant:"secondary",onClick:u,children:b.reload})]}),xt("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1",children:[no(b.undo,bt(Re,{name:"undo",size:16}),()=>qr(it),{disabled:0===rt.current.length}),no(b.redo,bt(Re,{name:"redo",size:16}),()=>qr(ct),{disabled:0===nt.current.length}),no(b.formatPainter,bt(Re,{name:"copy-style",size:16}),()=>lr(e=>e?null:Gt),{pressed:!!or}),to,no(b.formatCurrency,bt(Re,{name:"dollar",size:16}),()=>cn(Gt.numFmt===p.currency?"General":p.currency),{pressed:Gt.numFmt===p.currency}),no(b.formatPercent,bt(Re,{name:"percent",size:16}),()=>cn(/%/.test(Gt.numFmt??"")?"General":"0%"),{pressed:/%/.test(Gt.numFmt??"")}),no(b.fewerDecimals,bt("span",{className:"text-xs",children:".0"}),()=>sn(-1)),no(b.moreDecimals,bt("span",{className:"text-xs",children:".00"}),()=>sn(1)),bt(ze,{trigger:xt("span",{title:b.number,className:"flex items-center gap-0.5",children:["123",bt(Re,{name:"chevron-down",size:12})]}),"aria-label":b.number,items:Kn,align:"start",triggerClassName:eo}),to,bt(ze,{trigger:xt("span",{title:b.fontSize,className:"flex items-center gap-0.5",children:[Gt.fontSize??d,bt(Re,{name:"chevron-down",size:12})]}),"aria-label":b.fontSize,items:Xn,align:"start",triggerClassName:eo}),no(b.bold,bt(Re,{name:"bold",size:16}),()=>an("bold"),{pressed:!!Gt.bold}),no(b.italic,bt(Re,{name:"italic",size:16}),()=>an("italic"),{pressed:!!Gt.italic}),no(b.underline,bt(Re,{name:"underline",size:16}),()=>an("underline"),{pressed:!!Gt.underline}),no(b.strikethrough,bt(Re,{name:"strike",size:16}),()=>an("strike"),{pressed:!!Gt.strike}),oo(b.textColor,bt(Re,{name:"text-color",size:14}),"color"),oo(b.fillColor,bt(Re,{name:"palette",size:14}),"fill"),to,bt(ze,{trigger:xt("span",{title:b.borders,className:"flex items-center gap-0.5",children:[bt(Re,{name:"border-all",size:16}),bt(Re,{name:"chevron-down",size:12})]}),"aria-label":b.borders,items:Hn,align:"start",triggerClassName:eo}),no(b.mergeCells,bt(Re,{name:"grid",size:16}),pn,{pressed:Lt.merges.some(e=>Z(e,Yt.row,Yt.col))}),bt(ze,{trigger:xt("span",{title:b.alignment,className:"flex items-center gap-0.5",children:["center"===Gt.align?bt(Re,{name:"align-center",size:16}):"right"===Gt.align?bt(Re,{name:"align-right",size:16}):bt(Re,{name:"align-left",size:16}),bt(Re,{name:"chevron-down",size:12})]}),"aria-label":b.alignment,items:Wn,align:"start",triggerClassName:eo}),no(b.wrapText,bt(Re,{name:"wrap",size:16}),()=>an("wrap"),{pressed:!!Gt.wrap}),to,no(b.filter,bt(Re,{name:"filter",size:16}),gn,{pressed:!!Lt.filter}),no(b.sortAscending,bt(Re,{name:"sort",size:16}),()=>mn(!0)),bt(ze,{trigger:xt("span",{title:b.functions,className:"flex items-center gap-0.5 text-sm",children:["Σ",bt(Re,{name:"chevron-down",size:12})]}),"aria-label":b.functions,items:Vn,align:"end",triggerClassName:eo})]}),xt("div",{className:"flex shrink-0 items-start gap-1 border-b border-line bg-surface px-2 py-1",children:[bt("input",{type:"text","aria-label":b.nameBox,spellCheck:!1,value:fr??(_t&&Xr?x(_t.row,_t.col):Q(Wt.range)),onFocus:e=>{hr(e.target.value),e.target.select()},onChange:e=>hr(e.target.value),onBlur:()=>hr(null),onKeyDown:e=>{if("Enter"===e.key){const e=G(fr??"");e&&e.r2<Lt.rowCount&&e.c2<Lt.colCount&&(Vt({active:{row:e.r1,col:e.c1},range:z(Lt,e)}),Bt.current?.scrollTo({row:e.r1,col:e.c1})),hr(null),Rr()}},className:"w-20 shrink-0 rounded border border-line bg-surface px-2 py-0.5 text-center text-xs text-ink"}),bt("span",{className:"select-none pt-0.5 font-serif text-sm italic text-ink-faint","aria-hidden":"true",children:"fx"}),bt("textarea",{ref:Cr,"aria-label":b.formulaBar,spellCheck:!1,rows:1,value:_t?_t.text:A(jt,Gt),onFocus:()=>{_t?_t.inBar||Zt({..._t,inBar:!0}):Br(Yt,{inBar:!0,mode:"edit"})},onChange:e=>{_t&&Wr(e.target.value,e.target.selectionStart)},onSelect:Jr,onKeyDown:Qr,className:"max-h-24 min-h-[22px] flex-1 resize-y rounded border border-line bg-surface px-2 py-0.5 font-mono text-xs text-ink outline-none focus:border-accent-fill"})]}),mr&&xt("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-line bg-surface-sunken px-2 py-1 text-xs",children:[bt("div",{className:"w-44",children:bt(Oe,{ref:Nr,size:"sm","aria-label":b.find,placeholder:b.find,value:pr,onChange:e=>vr(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),Mn(e.shiftKey?-1:1))}})}),bt("span",{className:"w-16 text-center text-ink-muted",children:pr?b.hitCount(Rn<0?0:Rn+1,Sn.length):""}),no(b.previous,bt(Re,{name:"arrow-up",size:14}),()=>Mn(-1)),no(b.next,bt(Re,{name:"arrow-down",size:14}),()=>Mn(1)),bt("div",{className:"w-44",children:bt(Oe,{size:"sm","aria-label":b.replaceWith,placeholder:b.replaceWith,value:wr,onChange:e=>br(e.target.value)})}),bt(Me,{size:"sm",variant:"secondary",disabled:!Sn.length,onClick:()=>{if(Rn<0)return void Mn(1);const{row:e,col:t}=Sn[Rn];Mr(r=>{const n=te(J(r,e,t),pr,wr,xr);return n===J(r,e,t)?r:fe(r,[{row:e,col:t,raw:n}])}),Mn(1)},children:b.replace}),bt(Me,{size:"sm",variant:"secondary",disabled:!Sn.length,onClick:()=>{let e=0;Mr(t=>{const r=[];for(const{row:e,col:n}of Sn){const o=te(J(t,e,n),pr,wr,xr);o!==J(t,e,n)&&r.push({row:e,col:n,raw:o})}return e=r.length,fe(t,r)}),Xe.success(b.replacedCount(e))},children:b.replaceAll}),bt(Te,{label:b.matchCase,checked:xr.matchCase,onChange:e=>yr(t=>({...t,matchCase:e}))}),bt(Te,{label:b.wholeCell,checked:xr.wholeCell,onChange:e=>yr(t=>({...t,wholeCell:e}))}),bt(Te,{label:b.inFormulas,checked:xr.inFormulas,onChange:e=>yr(t=>({...t,inFormulas:e}))}),bt("div",{className:"ml-auto",children:no(b.close,bt(Re,{name:"close",size:14}),()=>{gr(!1),Rr()})})]}),bt("div",{className:"min-h-0 flex-1",children:bt(ft,{ref:Bt,sheet:Lt,sheetIndex:Ot,evaluator:Pt,filterHidden:$t,selection:Wt,showGridlines:er,showFormulas:rr,clipRange:Jt&&Jt.sheetId===Lt.id?Jt.range:null,highlights:jr,pointing:Gr,onSelect:zn,onPoint:_r,onEdit:e=>{Ur(),Fr(e),Br(K(Lt,e.row,e.col)?{row:K(Lt,e.row,e.col).r1,col:K(Lt,e.row,e.col).c1}:e)},onFill:e=>{const t=Wt.range;Mr(r=>F(r,t,e)),Vt({active:Wt.active,range:e})},onResizeCol:(e,t)=>Mr(r=>{const{range:n}=Wt,o=0===n.r1&&n.r2===r.rowCount-1&&e>=n.c1&&e<=n.c2,l={...r.colWidths};if(o)for(let e=n.c1;e<=n.c2;e++)l[e]=t;else l[e]=t;return{...r,colWidths:l}}),onResizeRow:(e,t)=>Mr(r=>({...r,rowHeights:{...r.rowHeights,[e]:t}})),onAutoFitCol:e=>{const t=Math.max(40,Bt.current?.measureColumn(e)??0);Mr(r=>({...r,colWidths:{...r.colWidths,[e]:t}}))},onAutoFitRow:e=>Mr(t=>{const r={...t.rowHeights};return delete r[e],{...t,rowHeights:r}}),onHeaderMenu:Fn,onFilterButton:In,renderEditor:e=>xt(wt,{children:[lo(e),ao(e)]}),onKeyDown:t=>{if(_t)return;const r=t.ctrlKey||t.metaKey,n=t.key,o=n.toLowerCase(),l="ArrowUp"===n?[-1,0]:"ArrowDown"===n?[1,0]:"ArrowLeft"===n?[0,-1]:"ArrowRight"===n?[0,1]:null;if(l){t.preventDefault();const e=t.shiftKey?Pr():Wt.active,n=r?Or(e,l[0],l[1]):Ir(e,l[0],l[1]);return void(t.shiftKey?Lr(n):Fr(n))}if("Tab"===n||"Enter"===n){if(t.preventDefault(),"Enter"===n&&r)return;const e=Wt.range.r1!==Wt.range.r2||Wt.range.c1!==Wt.range.c2,o="Enter"===n?t.shiftKey?-1:1:0,l="Tab"===n?t.shiftKey?-1:1:0;if(e){const{range:e}=Wt;let{row:t,col:r}=Wt.active;return t+=o,r+=l,r>e.c2&&(r=e.c1,t=t+1>e.r2?e.r1:t+1),r<e.c1&&(r=e.c2,t=t-1<e.r1?e.r2:t-1),t>e.r2&&(t=e.r1,r=r+1>e.c2?e.c1:r+1),t<e.r1&&(t=e.r2,r=r-1<e.c1?e.c2:r-1),Vt({active:{row:t,col:r},range:e}),void Bt.current?.scrollTo({row:t,col:r})}return void Fr(Ir(Wt.active,o,l))}if("Home"===n)return t.preventDefault(),void Fr(r?{row:Lt.frozenRows,col:Lt.frozenCols}:{row:Wt.active.row,col:0});if("End"===n){t.preventDefault();const e=ue(Lt);return void Fr(r?{row:e?.row??0,col:e?.col??0}:{row:Wt.active.row,col:Math.max(0,(Lt.cells[Wt.active.row]?.length??1)-1)})}if("PageDown"===n||"PageUp"===n){t.preventDefault();const e="PageDown"===n?25:-25;return void Fr({row:Math.max(0,Math.min(Lt.rowCount-1,Wt.active.row+e)),col:Wt.active.col})}if("Delete"===n||"Backspace"===n)return t.preventDefault(),void Mr(e=>C(e,Wt.range));if("F2"===n)return t.preventDefault(),void Br(Wt.active);if(" "===n&&(r||t.shiftKey))return t.preventDefault(),void Vt(r?{active:Wt.active,range:{r1:0,c1:Wt.range.c1,r2:Lt.rowCount-1,c2:Wt.range.c2}}:{active:Wt.active,range:{r1:Wt.range.r1,c1:0,r2:Wt.range.r2,c2:Lt.colCount-1}});if(!r)return!t.altKey||"="!==n&&"≠"!==n?1!==n.length||t.altKey?void("Process"!==n&&229!==t.keyCode||Br(Wt.active,{text:""})):(t.preventDefault(),void Br(Wt.active,{text:n})):(t.preventDefault(),void wn("SUM"));switch(o){case"z":return t.preventDefault(),void(t.shiftKey?ct():it());case"y":return t.preventDefault(),void ct();case"a":return t.preventDefault(),void Vt({active:Wt.active,range:{r1:0,c1:0,r2:Lt.rowCount-1,c2:Lt.colCount-1}});case"b":return t.preventDefault(),void an("bold");case"i":return t.preventDefault(),void an("italic");case"u":return t.preventDefault(),void an("underline");case"f":case"h":return t.preventDefault(),gr(!0),void setTimeout(()=>Nr.current?.focus(),0);case"s":return t.preventDefault(),void(e?zt():kn());case"d":{t.preventDefault();const{range:e}=Wt;return void(e.r2>e.r1?Mr(t=>F(t,{...e,r2:e.r1},e)):e.r1>0&&Mr(t=>F(t,{...e,r1:e.r1-1,r2:e.r1-1},{...e,r1:e.r1-1})))}case"r":{t.preventDefault();const{range:e}=Wt;return void(e.c2>e.c1?Mr(t=>F(t,{...e,c2:e.c1},e)):e.c1>0&&Mr(t=>F(t,{...e,c1:e.c1-1,c2:e.c1-1},{...e,c1:e.c1-1})))}case";":return t.preventDefault(),void Mr(e=>D(e,Wt.active.row,Wt.active.col,We(new Date)));case"`":return t.preventDefault(),void nr(e=>!e)}if(t.shiftKey){if("$"===n||"4"===n)return t.preventDefault(),void cn(p.currency);if("%"===n||"5"===n)return t.preventDefault(),void cn("0%")}},onCopy:e=>{_t||bn(!1,e)},onCut:e=>{_t||bn(!0,e)},onPaste:e=>{_t||(e.preventDefault(),xn(e.clipboardData.getData("text/plain"),"all"))}})}),xt("div",{className:"flex shrink-0 items-center border-t border-line bg-surface-sunken",children:[xt("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto px-1 py-1",children:[bt(Ie,{"aria-label":b.addSheet,title:b.addSheet,size:"sm",variant:"ghost",onClick:Tn,children:bt(Re,{name:"add",size:14})}),Fe.map((e,t)=>bt("button",{type:"button",onClick:()=>(e=>{_t&&!Gr&&Ur(),Ze(e),ir(null)})(t),onDoubleClick:()=>dr({index:t,name:e.name}),onContextMenu:e=>Sr.open(e,t),style:e.tabColor?{boxShadow:`inset 0 -3px 0 ${e.tabColor}`}:void 0,className:"whitespace-nowrap rounded px-3 py-1 text-xs font-medium "+(t===Ot?"bg-accent-tint text-accent-text":"text-ink-muted hover:bg-line-subtle hover:text-ink"),children:ur?.index===t?bt("input",{type:"text",value:ur.name,autoFocus:!0,"aria-label":b.rename,onChange:e=>dr({index:t,name:e.target.value}),onBlur:En,onKeyDown:e=>{e.stopPropagation(),"Enter"===e.key&&En()},onClick:e=>e.stopPropagation(),className:"w-24 rounded border border-accent-fill bg-surface px-1 text-xs text-ink outline-none"}):e.name},e.id))]}),Ln&&Ln.count>0&&xt("div",{className:"flex shrink-0 items-center gap-3 border-l border-line px-3 py-1 text-xs text-ink-muted",children:[Ln.numbers>0&&xt("span",{children:[b.statSum,": ",Pn(Ln.sum)]}),null!==Ln.average&&xt("span",{children:[b.statAverage,": ",Pn(Ln.average)]}),xt("span",{children:[b.statCount,": ",Ln.count]}),Ln.numbers>0&&xt("span",{children:[b.statMin,": ",Pn(Ln.min)]}),Ln.numbers>0&&xt("span",{children:[b.statMax,": ",Pn(Ln.max)]})]})]}),Dr.state&&bt(Ae,{...Dr.props,items:(so=Dr.state.data.kind,[Bn("cut",b.cut,()=>qr(()=>bn(!0))),Bn("copy",b.copy,()=>qr(()=>bn(!1))),Bn("paste",b.paste,()=>yn("all")),Bn("pasteValues",b.pasteValues,()=>yn("values")),Un("a"),..."col"!==so?[Bn("rowAbove",b.rowsAbove,()=>un("row",!1)),Bn("rowBelow",b.rowsBelow,()=>un("row",!0))]:[],..."row"!==so?[Bn("colLeft",b.columnsLeft,()=>un("col",!1)),Bn("colRight",b.columnsRight,()=>un("col",!0))]:[],Un("b"),..."col"!==so?[Bn("delRows",b.deleteRows,()=>dn("row"),{danger:!0})]:[],..."row"!==so?[Bn("delCols",b.deleteColumns,()=>dn("col"),{danger:!0})]:[],Bn("clear",b.clearValues,()=>qr(()=>Mr(e=>C(e,Wt.range)))),Un("c"),..."col"!==so?[Bn("hideRows",b.hideRows,()=>fn("row"))]:[],..."row"!==so?[Bn("hideCols",b.hideColumns,()=>fn("col"))]:[],..."col"!==so&&Lt.hiddenRows.length?[Bn("unhideRows",b.unhideRows,()=>hn("row"))]:[],..."row"!==so&&Lt.hiddenCols.length?[Bn("unhideCols",b.unhideColumns,()=>hn("col"))]:[]])}),Sr.state&&bt(Ae,{...Sr.props,items:(co=Sr.state.data,[Bn("rename",b.rename,()=>dr({index:co,name:Fe[co].name})),Bn("duplicate",b.duplicate,()=>{lt(e=>E(e,co,X(e,Fe[co].name))),Ze(co+1)}),Bn("left",b.moveLeft,()=>An(co,-1),{disabled:0===co}),Bn("right",b.moveRight,()=>An(co,1),{disabled:co===Fe.length-1}),{type:"submenu",key:"colour",label:b.tabColor,items:[Bn("none",b.noColor,()=>lt(e=>e.map((e,t)=>t===co?{...e,tabColor:void 0}:e))),...ht.slice(7,17).map(e=>Bn(e,xt("span",{className:"flex items-center gap-2",children:[bt("span",{className:"inline-block h-3 w-3 rounded-sm",style:{background:e}}),e]}),()=>lt(t=>t.map((t,r)=>r===co?{...t,tabColor:e}:t))))]},Un("a"),Bn("delete",b.deleteSheet,()=>{(async e=>{Fe.length<=1||(null===ue(Fe[e])||await Ke({title:b.deleteSheetTitle,message:b.deleteSheetMessage(Fe[e].name),confirmLabel:b.deleteSheet}))&&(lt(t=>T(t,e)),Ze(t=>t>e||t>=Fe.length-1?Math.max(0,t-1):t))})(co)},{danger:!0,disabled:Fe.length<=1})])}),ar&&xt($e,{portal:!0,minWidth:230,onClose:()=>ir(null),style:{position:"fixed",left:ar.x,top:ar.y},children:[bt(Ue,{onClick:()=>On(ar.col,!0),children:b.sortAscending}),bt(Ue,{onClick:()=>On(ar.col,!1),children:b.sortDescending}),bt(Be,{}),bt("div",{className:"px-2 py-1",children:bt(Oe,{size:"sm","aria-label":b.find,placeholder:b.find,value:ar.search,onChange:e=>ir({...ar,search:e.target.value})})}),bt("div",{className:"max-h-52 overflow-y-auto px-2 py-1",children:io.map(e=>bt("div",{className:"py-0.5",children:bt(Te,{label:e||b.blank,checked:!ar.unticked.has(e),onChange:t=>{const r=new Set(ar.unticked);t?r.delete(e):r.add(e),ir({...ar,unticked:r})}})},e))}),xt("div",{className:"flex items-center justify-between gap-2 border-t border-line px-2 py-1",children:[bt(Me,{size:"sm",variant:"ghost",onClick:()=>ir({...ar,unticked:new Set}),children:b.clear}),bt(Me,{size:"sm",variant:"primary",onClick:()=>{if(!ar)return;const{col:e,unticked:t}=ar;ir(null),qr(()=>Mr(r=>{if(!r.filter)return r;const n={...r.filter.excluded};return t.size?n[e]=[...t]:delete n[e],{...r,filter:{...r.filter,excluded:n}}}))},children:b.apply})]})]})]});var co,so,uo}function At(e,t){const r=e.rows?e.rows.map(e=>e.map(e=>String(e??""))):Y(e.csv??"");return 0===r.length?null:oe(t,r)}export{Mt as OpenSpreadsheet,Rt as SpreadsheetById,Tt as SpreadsheetPane,St as default};
@@ -0,0 +1 @@
1
+ var e=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","LI","TR","TABLE","UL","OL","TBODY"]);function t(t){let o="";const n=t=>{for(const a of Array.from(t.childNodes)){if(3===a.nodeType){o+=(a.nodeValue??"").replace(/​/g,"");continue}if(1!==a.nodeType)continue;const t=a;if("BR"===t.tagName){o+="\n";continue}if("DEL"===t.tagName||t.hasAttribute("data-hidden"))continue;if("object"===t.getAttribute("data-kind")||"mark"===t.getAttribute("data-kind"))continue;if("TD"===t.tagName||"TH"===t.tagName){n(t),o=`${o.replace(/\n+$/,"")}\t`;continue}const r=e.has(t.tagName);n(t),r&&!o.endsWith("\n")&&(o+="\n")}};return n(t),o.replace(/\t\n/g,"\n").replace(/\n+$/,"\n")}function o(e){return(e.match(/[぀-ヿ㐀-鿿豈-﫿]/g)?.length??0)+(e.replace(/[぀-ヿ㐀-鿿豈-﫿]/g," ").match(/\S+/g)?.length??0)}function n(t,o,n){if(!o)return[];const a=function(e){const t=[],o=e=>{for(const n of Array.from(e.childNodes))if(3===n.nodeType)t.push(n);else if(1===n.nodeType){const e=n;if("false"===e.getAttribute("contenteditable")||e.hasAttribute("data-raw"))continue;o(e)}};return o(e),t}(t),r=o=>{let n=o.parentNode;for(;n&&n!==t&&!e.has(n.tagName)&&"TD"!==n.tagName;)n=n.parentNode;return n},i=[];let c=0;for(;c<a.length;){const e=r(a[c]);let t=c;const d=[];for(;t<a.length&&r(a[t])===e;)d.push(a[t++]);const s=d.map(e=>e.nodeValue??"").join(""),l=n?s:s.toLowerCase(),p=n?o:o.toLowerCase(),g=l.length===s.length?l:s;for(let e=g.indexOf(p);e>=0;e=g.indexOf(p,e+p.length)){const t=[];let o=0;for(const n of d){const a=(n.nodeValue??"").length,r=Math.max(e,o),i=Math.min(e+p.length,o+a);r<i&&t.push({node:n,start:r-o,end:i-o}),o+=a}i.push(t)}c=t}return i}function a(e,t){e.forEach((e,o)=>{const n=e.node.nodeValue??"";e.node.nodeValue=n.slice(0,e.start)+(0===o?t:"")+n.slice(e.end)})}function r(e,t){const o=[0];if(t<=0)return o;let n=0;for(const a of e)if(a.breakBefore&&a.top>n&&(n=a.top,o.push(n)),!(a.top+a.height-n<=t))if(a.height<=t)a.top>n&&(n=a.top,o.push(n));else for(;a.top+a.height-n>t;)n+=t,o.push(n);return o}function i(e,t,o=1){const n=[],a=e=>{const a=e.getBoundingClientRect();n.push({top:(a.top-t)/o,height:a.height/o,breakBefore:e.hasAttribute("data-break-before")})};for(const r of Array.from(e.children))"TABLE"===r.tagName?r.querySelectorAll("tr").forEach(a):"UL"===r.tagName||"OL"===r.tagName?r.querySelectorAll("li").forEach(a):a(r),r.querySelectorAll("[data-page-break]").forEach(e=>{const a=e.getBoundingClientRect();n.push({top:(a.bottom-t)/o,height:0,breakBefore:!0})});return n}var c=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","UL","OL","LI","TABLE","THEAD","TBODY","TFOOT","TR","TD","TH","COLGROUP","COL","B","STRONG","I","EM","U","S","STRIKE","SUB","SUP","SPAN","FONT","A","BR","IMG","PRE","HR"]),d=new Set(["SCRIPT","STYLE","TITLE","META","LINK","OBJECT","EMBED","IFRAME","NOSCRIPT","TEMPLATE","SVG","MATH","FORM","INPUT","BUTTON","SELECT","TEXTAREA","VIDEO","AUDIO","CANVAS"]),s=new Set(["color","background-color","font-weight","font-style","text-decoration-line","text-decoration","font-family","font-size","text-align","margin-left","line-height","width","height","list-style-type"]),l=/^(https?:|mailto:|tel:|#)/i,p=/^(data:image\/(png|jpe?g|gif|webp|bmp);base64,|blob:)/i;function g(e){const t=document.implementation.createHTMLDocument("");t.body.innerHTML=e;const o=(e,t,n)=>{for(const a of Array.from(e.childNodes)){if(3===a.nodeType){t.appendChild(n.createTextNode(a.nodeValue??""));continue}if(1!==a.nodeType)continue;const e=a,r=e.tagName.toUpperCase();if(d.has(r))continue;if(!c.has(r)){o(e,t,n);continue}if("IMG"===r&&!p.test(e.getAttribute("src")??""))continue;const i=n.createElement(r),g=(e.getAttribute("style")??"").split(";").map(e=>{const t=e.indexOf(":");if(t<0)return"";const o=e.slice(0,t).trim().toLowerCase(),n=e.slice(t+1).trim();return s.has(o)&&!/url\(|expression|mso-/i.test(n)?`${o}:${n}`:""}).filter(Boolean).join(";");g&&i.setAttribute("style",g),"A"===r&&l.test(e.getAttribute("href")??"")&&i.setAttribute("href",e.getAttribute("href")),"IMG"===r&&i.setAttribute("src",e.getAttribute("src"));for(const t of["colspan","rowspan","start","color","face","size"]){const o=e.getAttribute(t);null!==o&&i.setAttribute(t,o)}o(e,i,n),t.appendChild(i)}},n=document.createElement("div");return o(t.body,n,document),n.innerHTML}import{escapeHtml as f}from"efficient-shell/ui";var u="\nhtml,body{margin:0;background:#fff}\n.docs-page [data-comment]{background:none;border:0}\n.docs-page [data-locked]{background:none;box-shadow:none}\n.docs-page [data-page-break]{break-after:page;border:0;margin:0}\n.docs-page [data-break-before]{break-before:page}\n.docs-page tr,.docs-page img{break-inside:avoid}\n";function h(e,t){return`\n.docs-sheet{background:#fff;color:#777}\n.docs-sheet-line{border-color:#aaa}\n\n${`\n.docs-page{color:#000;background:#fff;white-space:pre-wrap;overflow-wrap:break-word;outline:none;line-height:1.08;tab-size:36pt;font-family:Calibri,Carlito,Arial,sans-serif;font-size:11pt}\n.docs-page p,.docs-page h1,.docs-page h2,.docs-page h3,.docs-page h4,.docs-page h5,.docs-page h6{margin:0;font:inherit;font-weight:400}\n.docs-page ul,.docs-page ol{margin:0;padding-left:24pt}\n.docs-page ul{list-style-type:disc}.docs-page ol{list-style-type:decimal}\n.docs-page ul ul{list-style-type:circle}.docs-page ul ul ul{list-style-type:square}\n.docs-page a{color:#0563c1;text-decoration:underline}\n.docs-page sub,.docs-page sup{font-size:.66em}\n.docs-page img{max-width:100%}\n.docs-page table{border-collapse:collapse;table-layout:fixed;width:100%}\n.docs-page td,.docs-page th{border:.5pt solid #000;padding:0 5.4pt;vertical-align:top}\n.docs-page table[data-no-borders] td,.docs-page table[data-no-borders] th{border:.5pt dotted #bbb}\n.docs-page td p{margin-bottom:0}\n.docs-page blockquote{margin:0 0 8pt 24pt;font-style:italic}\n.docs-page hr{border:0;border-top:.75pt solid #000;margin:6pt 0}\n.docs-page [data-hidden]{display:none}\n.docs-page [data-page-break]{display:block;height:0;border-top:1pt dashed #999;margin:6pt 0;user-select:none}\n.docs-page [data-comment]{background:#fff2cc;border-bottom:1.5pt solid #e0b000}\n.docs-page [data-locked]{background:#f4f4f4;box-shadow:-5pt 0 0 #bbb;cursor:not-allowed}\n.docs-page ins{color:#c00000;text-decoration:underline}\n.docs-page del{color:#c00000;text-decoration:line-through}\n.docs-page [data-kind="object"]{display:inline-block;background:#f4f4f4;border:.75pt dashed #999;color:#555;padding:1pt 5pt;cursor:not-allowed;white-space:normal}\n.docs-page [data-kind="field"]{background:#ededed}\n.docs-page [data-kind="note"]{vertical-align:super;font-size:.66em}\n.docs-page ::highlight(docs-find){background:#ffe680}\n.docs-page ::highlight(docs-find-current){background:#ff9f1a}\n\n${e.css}`.replaceAll(".docs-page",`.docs-page[data-doc="${t}"]`)}`}var b=e=>u.replaceAll(".docs-page",`.docs-page[data-doc="${e}"]`);function m(e,t,o){const n=e=>(e??"").replaceAll("{page}",String(t)).replaceAll("{pages}",String(o)),[a,r]=e.split(/\s*\|\s*/);return[n(a),n(r)]}function T(e,t){const[o,n]=function(e){return e.split(/\s*\|\s*/).map(e=>e.split(/(\{page\}|\{pages\})/).map(e=>"{page}"===e?"counter(page)":"{pages}"===e?"counter(pages)":e?`"${e.replace(/["\\\n\r]/g,"")}"`:"").filter(Boolean).join(" "))}(t),a="font:9pt Calibri,Carlito,Arial,sans-serif;color:#555";return`${o?`@${e}-left{content:${o};${a}}`:""}${n?`@${e}-right{content:${n};${a}}`:""}`}function A({title:e,html:t,doc:o,scope:n,page:a,header:r,footer:i}){const c=e=>Math.round(e)/20+"pt",d=`@page{size:${c(a.width)} ${c(a.height)};margin:${c(a.top)} ${c(a.right)} ${c(a.bottom)} ${c(a.left)};${T("top",r)}${T("bottom",i)}}`;return`<!doctype html><html><head><meta charset="utf-8"><meta name="generator" content="efficient-shell Documents"><title>${f(e)}</title><style>${h(o,n)}\n${b(n)}\n${d}</style></head><body><div class="docs-page" data-doc="${n}">${t}</div></body></html>`}export{t as documentText,o as countWords,n as findInNodes,a as replaceSpots,r as pageStarts,i as pageBlocks,g as sanitizeHtml,h as pageStyles,b as printStyles,m as marginText,A as pageDocument};
@@ -0,0 +1 @@
1
+ import{ENGLISH_FILE_WORDS as e,ZH_HANS_FILE_WORDS as t}from"./chunk-B32ASXHM.js";var o={ABS:"Absolute value",AND:"True if all are true",AVERAGE:"Average of numbers",AVERAGEIF:"Average where a test passes",AVERAGEIFS:"Average on many tests",CEILING:"Rounds up to a multiple","CEILING.MATH":"Rounds up to a multiple",CHOOSE:"Picks by position",COLUMN:"Column number",COLUMNS:"Number of columns",CONCAT:"Joins text",CONCATENATE:"Joins text",COS:"Cosine",COUNT:"Counts numbers",COUNTA:"Counts non-blank cells",COUNTBLANK:"Counts blank cells",COUNTIF:"Counts where a test passes",COUNTIFS:"Counts on many tests",DATE:"Builds a date",DATEDIF:"Time between dates",DAY:"Day of the month",DAYS:"Days between dates",EDATE:"Date some months away",EOMONTH:"Last day of a month",EXACT:"Same text, case included",EXP:"e to a power",FIND:"Position of text, case exact",FLOOR:"Rounds down to a multiple","FLOOR.MATH":"Rounds down to a multiple",FV:"Future value",HLOOKUP:"Looks along the top row",HOUR:"Hour of a time",IF:"One value or another",IFERROR:"A fallback for an error",IFNA:"A fallback for #N/A",IFS:"First test that passes",INDEX:"The cell at a position",INT:"Rounds down to a whole number",ISBLANK:"True if blank",ISERROR:"True if an error",ISLOGICAL:"True if TRUE or FALSE",ISNA:"True if #N/A",ISNUMBER:"True if a number",ISTEXT:"True if text",LARGE:"The kth largest",LEFT:"Text from the start",LEN:"Length of text",LN:"Natural logarithm",LOG:"Logarithm",LOG10:"Base-10 logarithm",LOWER:"Lower case",MATCH:"Position of a value",MAX:"Largest number",MEDIAN:"Middle number",MID:"Text from the middle",MIN:"Smallest number",MINUTE:"Minute of a time",MOD:"Remainder",MODE:"Most common number","MODE.SNGL":"Most common number",MONTH:"Month of a date",N:"A value as a number",NA:"The #N/A error",NETWORKDAYS:"Working days between dates",NOT:"The opposite",NOW:"Date and time now",NPV:"Net present value",OR:"True if any is true",PI:"The number pi",PMT:"Loan payment",POWER:"A number to a power",PRODUCT:"Multiplies numbers",PROPER:"Capitals on each word",PV:"Present value",RAND:"Random from 0 to 1",RANDBETWEEN:"Random whole number",RANK:"Rank in a list","RANK.EQ":"Rank in a list",REPLACE:"Replaces by position",REPT:"Repeats text",RIGHT:"Text from the end",ROUND:"Rounds a number",ROUNDDOWN:"Rounds toward zero",ROUNDUP:"Rounds away from zero",ROW:"Row number",ROWS:"Number of rows",SEARCH:"Position of text, any case",SECOND:"Second of a time",SIGN:"Sign of a number",SIN:"Sine",SMALL:"The kth smallest",SQRT:"Square root",STDEV:"Standard deviation of a sample","STDEV.P":"Standard deviation of everything","STDEV.S":"Standard deviation of a sample",STDEVP:"Standard deviation of everything",SUBSTITUTE:"Replaces text",SUM:"Adds numbers",SUMIF:"Adds where a test passes",SUMIFS:"Adds on many tests",SUMPRODUCT:"Multiplies, then adds",SWITCH:"Picks a result by value",TAN:"Tangent",TEXT:"A number as formatted text",TEXTJOIN:"Joins with a separator",TIME:"Builds a time",TODAY:"Today's date",TRIM:"Removes extra spaces",TRUNC:"Cuts off decimals",UPPER:"Upper case",VALUE:"Text as a number",VAR:"Variance of a sample","VAR.P":"Variance of everything","VAR.S":"Variance of a sample",VARP:"Variance of everything",VLOOKUP:"Looks down the first column",WEEKDAY:"Day of the week",XLOOKUP:"Looks up in any column",XOR:"True if an odd number are true",YEAR:"Year of a date"},a={ABS:"绝对值",AND:"全部为真时返回真",AVERAGE:"数字的平均值",AVERAGEIF:"满足条件的平均值",AVERAGEIFS:"满足多个条件的平均值",CEILING:"向上舍入到倍数","CEILING.MATH":"向上舍入到倍数",CHOOSE:"按位置选择",COLUMN:"列号",COLUMNS:"列数",CONCAT:"连接文本",CONCATENATE:"连接文本",COS:"余弦",COUNT:"统计数字个数",COUNTA:"统计非空单元格",COUNTBLANK:"统计空单元格",COUNTIF:"统计满足条件的个数",COUNTIFS:"统计满足多个条件的个数",DATE:"生成日期",DATEDIF:"两个日期的间隔",DAY:"月份中的第几天",DAYS:"两个日期相差的天数",EDATE:"相隔若干个月的日期",EOMONTH:"月份的最后一天",EXACT:"文本完全相同",EXP:"e 的幂",FIND:"文本位置(区分大小写)",FLOOR:"向下舍入到倍数","FLOOR.MATH":"向下舍入到倍数",FV:"未来值",HLOOKUP:"在首行中查找",HOUR:"时间中的小时",IF:"二选一返回值",IFERROR:"出错时的备用值",IFNA:"#N/A 时的备用值",IFS:"第一个满足的条件",INDEX:"指定位置的单元格",INT:"向下取整",ISBLANK:"为空时返回真",ISERROR:"为错误时返回真",ISLOGICAL:"为逻辑值时返回真",ISNA:"为 #N/A 时返回真",ISNUMBER:"为数字时返回真",ISTEXT:"为文本时返回真",LARGE:"第 k 大的值",LEFT:"从开头截取文本",LEN:"文本长度",LN:"自然对数",LOG:"对数",LOG10:"以 10 为底的对数",LOWER:"转为小写",MATCH:"值的位置",MAX:"最大值",MEDIAN:"中位数",MID:"从中间截取文本",MIN:"最小值",MINUTE:"时间中的分钟",MOD:"余数",MODE:"出现最多的数字","MODE.SNGL":"出现最多的数字",MONTH:"日期中的月份",N:"转为数字",NA:"#N/A 错误",NETWORKDAYS:"两个日期之间的工作日",NOT:"取反",NOW:"当前日期和时间",NPV:"净现值",OR:"任一为真时返回真",PI:"圆周率",PMT:"贷款每期还款额",POWER:"幂运算",PRODUCT:"数字相乘",PROPER:"每个单词首字母大写",PV:"现值",RAND:"0 到 1 之间的随机数",RANDBETWEEN:"随机整数",RANK:"在列表中的排名","RANK.EQ":"在列表中的排名",REPLACE:"按位置替换",REPT:"重复文本",RIGHT:"从末尾截取文本",ROUND:"四舍五入",ROUNDDOWN:"向零舍入",ROUNDUP:"远离零舍入",ROW:"行号",ROWS:"行数",SEARCH:"文本位置(不区分大小写)",SECOND:"时间中的秒",SIGN:"数字的符号",SIN:"正弦",SMALL:"第 k 小的值",SQRT:"平方根",STDEV:"样本标准差","STDEV.P":"总体标准差","STDEV.S":"样本标准差",STDEVP:"总体标准差",SUBSTITUTE:"替换文本",SUM:"数字求和",SUMIF:"对满足条件的值求和",SUMIFS:"对满足多个条件的值求和",SUMPRODUCT:"相乘后求和",SWITCH:"按值选择结果",TAN:"正切",TEXT:"数字转为带格式的文本",TEXTJOIN:"用分隔符连接",TIME:"生成时间",TODAY:"今天的日期",TRIM:"删除多余空格",TRUNC:"截去小数",UPPER:"转为大写",VALUE:"文本转为数字",VAR:"样本方差","VAR.P":"总体方差","VAR.S":"样本方差",VARP:"总体方差",VLOOKUP:"在首列中查找",WEEKDAY:"星期几",XLOOKUP:"在任意列中查找",XOR:"奇数个为真时返回真",YEAR:"日期中的年份"},l={pdfPageFailed:e=>`Page ${e} couldn't be drawn for the PDF.`,files:e,fileKind:"Excel",untitled:"Untitled",backToFiles:"Back to files",filesHeading:"Spreadsheets",newFile:"New spreadsheet",openFile:"Open a file",filesEmptyTitle:"Make your first spreadsheet",filesEmptyBody:"Every change saves by itself.",deleteFile:"Delete",createFailed:"The spreadsheet could not be made.",deleteFailed:"The spreadsheet could not be deleted.",storedOpenFailed:"This spreadsheet could not be opened.",loading:"Loading",renameFailed:"The spreadsheet could not be renamed.",conflict:"Somebody else saved this spreadsheet, so your latest changes are not saved. Reload to see theirs.",reload:"Reload",noStoreEdited:"Not saved. Save as Excel to keep your changes",saveToFiles:"Save to Files",noStoreClean:"No autosave here. Save as Excel to keep a copy",deleteConfirm:e=>`Delete "${e}"? Nobody can open it again.`,spreadsheetFile:"spreadsheet",sheetBase:"Sheet",menuFile:"File",menuEdit:"Edit",menuView:"View",menuInsert:"Insert",menuFormat:"Format",menuData:"Data",menuNew:"New",menuOpen:"Open",saveExcel:"Save as Excel (.xlsx)",saveCsv:"Download this sheet as CSV",email:"Email",undo:"Undo",redo:"Redo",cut:"Cut",copy:"Copy",paste:"Paste",pasteValues:"Paste values only",pasteFormats:"Paste formatting only",findReplace:"Find and replace",clearValues:"Clear contents",freeze:"Freeze",gridlines:"Gridlines",showFormulas:"Show formulas",rowsAbove:"Rows above",rowsBelow:"Rows below",columnsLeft:"Columns left",columnsRight:"Columns right",sheet:"Sheet",function:"Function",functions:"Functions",number:"Number format",bold:"Bold",italic:"Italic",underline:"Underline",strikethrough:"Strikethrough",fontSize:"Font size",alignment:"Alignment",borders:"Borders",wrapText:"Wrap text",mergeCells:"Merge cells",clearFormatting:"Clear formatting",sortAscending:"Sort A to Z",sortDescending:"Sort Z to A",filter:"Filter",hideRows:"Hide rows",hideColumns:"Hide columns",unhideRows:"Show hidden rows",unhideColumns:"Show hidden columns",deleteRows:"Delete rows",deleteColumns:"Delete columns",formatGeneral:"Automatic",formatNumber:"Number",formatPercent:"Percent",formatScientific:"Scientific",formatCurrency:"Currency",formatDate:"Date",formatTime:"Time",formatDateTime:"Date and time",formatText:"Plain text",bordersAll:"All borders",bordersOuter:"Outer borders",bordersTop:"Top border",bordersBottom:"Bottom border",bordersLeft:"Left border",bordersRight:"Right border",bordersNone:"No borders",alignLeft:"Left",alignCenter:"Center",alignRight:"Right",alignTop:"Top",alignMiddle:"Middle",alignBottom:"Bottom",formatPainter:"Paint format",fewerDecimals:"Fewer decimal places",moreDecimals:"More decimal places",textColor:"Text color",fillColor:"Fill color",nameBox:"Selected cells",formulaBar:"Formula bar",cellEditor:"Cell contents",selectAll:"Select all",fillHandle:"Fill",find:"Find",replaceWith:"Replace with",replace:"Replace",replaceAll:"Replace all",previous:"Previous",next:"Next",close:"Close",matchCase:"Match case",wholeCell:"Whole cell",inFormulas:"In formulas",addSheet:"Add sheet",rename:"Rename",duplicate:"Duplicate",moveLeft:"Move left",moveRight:"Move right",tabColor:"Tab color",noColor:"No color",deleteSheet:"Delete sheet",deleteSheetTitle:"Delete this sheet?",sheetNameTaken:"Another sheet already has that name.",saveFailed:"Could not save the workbook. Try again.",openFailed:"Could not open that file. It may be damaged or an unsupported type.",statSum:"Sum",statAverage:"Average",statCount:"Count",statMin:"Min",statMax:"Max",blank:"(Blank)",clear:"Clear",apply:"Apply",sheetName:e=>`Sheet ${e}`,filterColumn:e=>`Filter column ${e}`,freezeRows:e=>0===e?"No frozen rows":1===e?"1 row":`${e} rows`,freezeColumns:e=>0===e?"No frozen columns":1===e?"1 column":`${e} columns`,freezeUpToRow:e=>`Up to row ${e}`,freezeUpToColumn:e=>`Up to column ${e}`,hitCount:(e,t)=>`${e} of ${t}`,replacedCount:e=>1===e?"Replaced in 1 cell":`Replaced in ${e} cells`,deleteSheetMessage:e=>`"${e}" and everything on it will be deleted. Formulas that use it will show #REF!.`,functionHelp:e=>o[e]??String(e)},r={pdfPageFailed:e=>`第 ${e} 页无法绘制到 PDF。`,files:t,fileKind:"Excel",untitled:"未命名",backToFiles:"返回文件",filesHeading:"电子表格",newFile:"新建电子表格",openFile:"打开文件",filesEmptyTitle:"创建您的第一个电子表格",filesEmptyBody:"每次更改都会自动保存。",deleteFile:"删除",createFailed:"无法创建电子表格。",deleteFailed:"无法删除电子表格。",storedOpenFailed:"无法打开此电子表格。",loading:"正在加载",renameFailed:"无法重命名电子表格。",conflict:"其他人已保存此电子表格,您最近的更改尚未保存。请重新加载以查看他们的版本。",reload:"重新加载",noStoreEdited:"未保存。请另存为 Excel 以保留更改",saveToFiles:"保存到文件",noStoreClean:"此处不会自动保存。请另存为 Excel 以保留副本",deleteConfirm:e=>`删除“${e}”?之后任何人都无法再打开它。`,spreadsheetFile:"电子表格",sheetBase:"工作表",menuFile:"文件",menuEdit:"编辑",menuView:"视图",menuInsert:"插入",menuFormat:"格式",menuData:"数据",menuNew:"新建",menuOpen:"打开",saveExcel:"另存为 Excel(.xlsx)",saveCsv:"将此工作表下载为 CSV",email:"发送邮件",undo:"撤销",redo:"重做",cut:"剪切",copy:"复制",paste:"粘贴",pasteValues:"仅粘贴数值",pasteFormats:"仅粘贴格式",findReplace:"查找和替换",clearValues:"清除内容",freeze:"冻结",gridlines:"网格线",showFormulas:"显示公式",rowsAbove:"在上方插入行",rowsBelow:"在下方插入行",columnsLeft:"在左侧插入列",columnsRight:"在右侧插入列",sheet:"工作表",function:"函数",functions:"函数",number:"数字格式",bold:"粗体",italic:"斜体",underline:"下划线",strikethrough:"删除线",fontSize:"字号",alignment:"对齐",borders:"边框",wrapText:"自动换行",mergeCells:"合并单元格",clearFormatting:"清除格式",sortAscending:"升序排序",sortDescending:"降序排序",filter:"筛选",hideRows:"隐藏行",hideColumns:"隐藏列",unhideRows:"显示隐藏的行",unhideColumns:"显示隐藏的列",deleteRows:"删除行",deleteColumns:"删除列",formatGeneral:"自动",formatNumber:"数字",formatPercent:"百分比",formatScientific:"科学计数",formatCurrency:"货币",formatDate:"日期",formatTime:"时间",formatDateTime:"日期和时间",formatText:"纯文本",bordersAll:"所有边框",bordersOuter:"外边框",bordersTop:"上边框",bordersBottom:"下边框",bordersLeft:"左边框",bordersRight:"右边框",bordersNone:"无边框",alignLeft:"左对齐",alignCenter:"居中",alignRight:"右对齐",alignTop:"顶端对齐",alignMiddle:"垂直居中",alignBottom:"底端对齐",formatPainter:"格式刷",fewerDecimals:"减少小数位",moreDecimals:"增加小数位",textColor:"文字颜色",fillColor:"填充颜色",nameBox:"所选单元格",formulaBar:"编辑栏",cellEditor:"单元格内容",selectAll:"全选",fillHandle:"填充",find:"查找",replaceWith:"替换为",replace:"替换",replaceAll:"全部替换",previous:"上一个",next:"下一个",close:"关闭",matchCase:"区分大小写",wholeCell:"整个单元格",inFormulas:"在公式中",addSheet:"添加工作表",rename:"重命名",duplicate:"复制工作表",moveLeft:"左移",moveRight:"右移",tabColor:"标签颜色",noColor:"无颜色",deleteSheet:"删除工作表",deleteSheetTitle:"删除此工作表?",sheetNameTaken:"已有工作表使用该名称。",saveFailed:"无法保存工作簿,请重试。",openFailed:"无法打开该文件,文件可能已损坏或类型不受支持。",statSum:"求和",statAverage:"平均值",statCount:"计数",statMin:"最小值",statMax:"最大值",blank:"(空白)",clear:"清除",apply:"应用",sheetName:e=>`工作表 ${e}`,filterColumn:e=>`筛选 ${e} 列`,freezeRows:e=>0===e?"不冻结行":`${e} 行`,freezeColumns:e=>0===e?"不冻结列":`${e} 列`,freezeUpToRow:e=>`冻结至第 ${e} 行`,freezeUpToColumn:e=>`冻结至 ${e} 列`,hitCount:(e,t)=>`${e} / ${t}`,replacedCount:e=>`已替换 ${e} 个单元格`,deleteSheetMessage:e=>`将删除“${e}”及其全部内容。引用它的公式将显示 #REF!。`,functionHelp:e=>a[e]??String(e)};export{l as ENGLISH_WORDS,r as ZH_HANS_WORDS};
@@ -0,0 +1 @@
1
+ import{useCallback as e,useEffect as t,useRef as i,useState as n}from"react";import{WindowTitle as l,activateWindowById as r}from"efficient-shell";import{Icon as a}from"efficient-shell/icons";import{Button as o,ContextMenu as c,buttonClasses as s,DropdownMenu as d,EmptyState as f,Input as m,confirmDestructive as u,registerModalEscapeInterceptor as p,toast as h,useContextMenu as g}from"efficient-shell/ui";import{jsx as v,jsxs as y}from"react/jsx-runtime";function w({words:m,files:p,list:w,create:b,rename:C,remove:N,canCreate:D,canDelete:F,canRename:S=!0,accept:z,choose:x,onOpen:A,onOpenFile:I,busy:T}){const[q,B]=n(null),[E,O]=n(null),P=i(null),j=i(null),K=g(),L=e(()=>{w().then(B,()=>B([]))},[w]);t(L,[L]);const M=()=>P.current?.click(),R=async e=>{await u({message:m.deleteConfirm(e.title),confirmWord:p.delete})&&N(e.id).then(L,()=>h.error(m.deleteFailed))},W=D&&v(o,{onClick:()=>{b().then(({id:e})=>A(e),()=>h.error(m.createFailed))},children:m.newFile}),G=v(a,{name:"folder-open",size:16}),H=x?v(d,{align:"end",triggerClassName:s({variant:"ghost"}),trigger:y("span",{className:"office-filelist-open",children:[G,p.open,v(a,{name:"chevron-down",size:14})]}),items:[{key:"computer",label:p.fromComputer,icon:v(a,{name:"desktop",size:16}),onSelect:M},{key:"drive",label:p.fromDrive,icon:v(a,{name:"cloud",size:16}),onSelect:()=>{(async()=>{x&&(await new Promise(e=>requestAnimationFrame(()=>setTimeout(e,0))),x.run(x.request).then(e=>{if(!e)return;const t=j.current?.closest("[data-modal-panel]"),i=t?.getAttribute("data-window-key")??t?.getAttribute("data-window-owner");i&&r(i),j.current?.focus({preventScroll:!0}),I(e.file,e)},()=>h.error(p.openFailed(p.fromDrive))))})()}}]}):v(o,{variant:"ghost",leftIcon:G,onClick:M,children:p.open});return y("div",{className:"office-filelist",ref:j,tabIndex:-1,children:[v(l,{title:m.windowTitle}),v("input",{ref:P,type:"file",accept:z,className:"office-filelist-input",onChange:e=>{const t=e.target.files?.[0];e.target.value="",t&&I(t)}}),y("div",{className:"office-filelist-head",children:[v("h2",{children:m.heading}),H,q&&q.length>0&&W]}),T&&v("div",{className:"office-filelist-busy",role:"status",children:T}),0===q?.length?v("div",{className:"office-filelist-empty",children:v(f,{title:m.emptyTitle,description:m.emptyBody,children:W})}):v("ul",{className:"office-filelist-rows",children:q?.map(e=>y("li",{className:"office-filelist-row",onContextMenu:t=>K.open(t,e),children:[E===e.id?v(k,{title:e.title,label:p.name,onDone:t=>((e,t)=>{O(null);const i=t?.trim();i&&i!==e.title&&(B(t=>t?.map(t=>t.id===e.id?{...t,title:i}:t)??t),C(e.id,i).then(L,()=>{h.error(p.renameFailed),L()}))})(e,t)}):v(o,{variant:"link",onClick:()=>A(e.id),children:e.title}),v("span",{className:"office-filelist-date",children:new Date(e.updatedAt).toLocaleDateString()}),F&&v(o,{variant:"ghost",leftIcon:v(a,{name:"trash",size:16}),onClick:()=>{R(e)},children:p.delete})]},e.id))}),K.state&&v(c,{...K.props,items:(J=K.state.data,[{key:"open",label:p.open,onSelect:()=>A(J.id)},...S?[{key:"rename",label:p.rename,onSelect:()=>O(J.id)}]:[],...F?[{key:"divider",type:"divider"},{key:"delete",label:p.delete,danger:!0,onSelect:()=>{R(J)}}]:[]])})]});var J}function k({title:e,label:l,onDone:r}){const[a,o]=n(e),c=i(null),s=i(!1),d=e=>{s.current||(s.current=!0,r(e))},f=i(d);return f.current=d,t(()=>{c.current?.focus(),c.current?.select()},[]),t(()=>p(()=>(f.current(null),!0)),[]),v("div",{className:"office-filelist-rename",children:v(m,{ref:c,"aria-label":l,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key?d(a):"Escape"===e.key&&(e.stopPropagation(),d(null))},onBlur:()=>d(a)})})}export{w as FileList};
@@ -0,0 +1 @@
1
+ var e={open:"Open",fromComputer:"From this computer",fromDrive:"From Efficient Drive",rename:"Rename",delete:"Delete",name:"Name",renameFailed:"Couldn't rename this file.",choosing:(e,o)=>`Choosing a ${e} file for ${o}`,opening:e=>`Opening ${e}…`,openFailed:e=>`Couldn't open ${e}. Check that it isn't damaged or password-protected.`,savedCopy:(e,o,n)=>`${n?`Saved to ${n} as ${e}`:`Saved as ${e}`}. Your ${o} is unchanged.`},o={open:"打开",fromComputer:"从此电脑",fromDrive:"从 Efficient 云盘",rename:"重命名",delete:"删除",name:"名称",renameFailed:"无法重命名此文件。",choosing:(e,o)=>`正在为${o}选择 ${e} 文件`,opening:e=>`正在打开 ${e}…`,openFailed:e=>`无法打开 ${e}。请确认文件未损坏且没有密码保护。`,savedCopy:(e,o,n)=>`${n?`已保存到 ${n},名为 ${e}`:`已保存为 ${e}`}。原文件 ${o} 未作更改。`};export{e as ENGLISH_FILE_WORDS,o as ZH_HANS_FILE_WORDS};
@@ -0,0 +1 @@
1
+ import{readXlsx as t}from"./chunk-N26CBJZA.js";import{formatKey as e,newSheet as r,parseCsv as s,sheetFromRows as n,writeCells as c}from"./chunk-VKCG3LPQ.js";import{titleOf as a}from"./chunk-XYVQTQ6N.js";async function o(t){const s=await(import("xlsx")),n=s.read(t,{type:"array",cellFormula:!0,cellNF:!0});return n.SheetNames.map(t=>{const a=n.Sheets[t],o=r(t),i=[],f={};if(a["!ref"]){const t=s.utils.decode_range(a["!ref"]);for(let r=t.s.r;r<=t.e.r;r++)for(let n=t.s.c;n<=t.e.c;n++){const t=a[s.utils.encode_cell({r:r,c:n})];if(!t||void 0===t.v&&!t.f)continue;const c=t.f?`=${t.f}`:"b"===t.t?t.v?"TRUE":"FALSE":String(t.v);i.push({row:r,col:n,raw:"s"===t.t&&/^(?:=|-?\d|'|true$|false$)/i.test(c)?`'${c}`:c}),t.z&&"General"!==t.z&&(f[e(r,n)]={numFmt:t.z})}}const l={};(a["!cols"]??[]).forEach((t,e)=>{t?.wpx&&(l[e]=t.wpx)});const m=(a["!merges"]??[]).map(t=>({r1:t.s.r,c1:t.s.c,r2:t.e.r,c2:t.e.c}));return{...c(o,i),formats:f,colWidths:l,merges:m}})}async function i(e,r,c="Sheet1"){const i=await async function(e,r){if(/\.(xlsx|xls|ods)$/i.test(e.name)){const r=new Uint8Array(await e.arrayBuffer());return/\.xlsx$/i.test(e.name)&&"undefined"!=typeof DecompressionStream?t(r):o(r)}const c=s(await e.text());return[n(r,c.length?c:[[""]])]}(r,c),f=a(r.name),l=await e.create(f);try{await e.save(l.id,{sheets:i},l.version)}catch(t){throw await e.remove(l.id).catch(()=>{}),t}return{id:l.id,title:f}}export{o as readWithSheetJs,i as importSpreadsheetFile};