efficient-office 0.10.0 → 0.12.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.
- package/dist/Documents-2ZU5D3ZI.js +1 -0
- package/dist/{Slides-LJW5C24V.js → Slides-YZQXZJX4.js} +1 -1
- package/dist/Spreadsheet-VWRRB6FE.js +1 -0
- package/dist/{chunk-6ZFEBY6H.js → chunk-ADXHTZ3Q.js} +1 -1
- package/dist/chunk-D3JKD7KW.js +1 -0
- package/dist/{chunk-3KJZFUBH.js → chunk-DG4VDXLL.js} +1 -1
- package/dist/chunk-EC6D54MM.js +1 -0
- package/dist/{chunk-HU4RI2OM.js → chunk-HNNYUGDU.js} +1 -1
- package/dist/{chunk-4M3QRYCH.js → chunk-MR7ZWQHF.js} +1 -1
- package/dist/{chunk-4MGZXE3N.js → chunk-NRGUS5QY.js} +1 -1
- package/dist/{chunk-JCSB2PHB.js → chunk-O35VT6BD.js} +1 -1
- package/dist/chunk-POH6OTTR.js +1 -0
- package/dist/chunk-UKGIT2RS.js +1 -0
- package/dist/chunk-YKQ5UKYZ.js +1 -0
- package/dist/chunk-ZS45QEF4.js +1 -0
- package/dist/documents/documents.css +39 -0
- package/dist/documents/index.d.ts +63 -2
- package/dist/documents/index.js +1 -1
- package/dist/docxPdf-QSMEFCUF.js +1 -0
- package/dist/importDocument-34WALCTG.js +1 -0
- package/dist/importSpreadsheet-IRN32JON.js +1 -0
- package/dist/{pptxImport-Y7TB6PYP.js → pptxImport-OACGHWQ6.js} +1 -1
- package/dist/slides/index.js +1 -1
- package/dist/spreadsheet/index.d.ts +3 -1
- package/dist/spreadsheet/index.js +1 -1
- package/dist/{workbookPdf-63WIOPEC.js → workbookPdf-CQTTURQ5.js} +1 -1
- package/dist/xlsxFile-SX767BIH.js +1 -0
- package/package.json +1 -1
- package/dist/Documents-ISV66NLW.js +0 -1
- package/dist/Spreadsheet-I5XA7TU7.js +0 -1
- package/dist/chunk-4NKXNXKY.js +0 -1
- package/dist/chunk-COXKOQPZ.js +0 -1
- package/dist/chunk-I3AC6PYR.js +0 -1
- package/dist/chunk-MZJSGEU3.js +0 -1
- package/dist/chunk-RHW2M2UY.js +0 -1
- package/dist/chunk-UDEPDAZI.js +0 -1
- package/dist/docxPdf-EW5I5JR3.js +0 -1
- package/dist/importDocument-274VK7OM.js +0 -1
- package/dist/importSpreadsheet-ZXS3RSKE.js +0 -1
- package/dist/xlsxFile-GYMIRUWG.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-EC6D54MM.js";import{DocumentsConflict as c,useDocumentsHost as d,useDocumentsWords as u}from"./chunk-HNNYUGDU.js";import"./chunk-POH6OTTR.js";import{FileList as m}from"./chunk-PMGQ5GUH.js";import"./chunk-B32ASXHM.js";import{importDocumentFile as f}from"./chunk-O35VT6BD.js";import{fingerprintOf as p,headerKindFor as h,marginTextOfHtml as g,readDocx as w,readParts as b,stampFingerprints as y,tocEntryHtml as v}from"./chunk-YKQ5UKYZ.js";import{BUILTIN_STYLES as x,CHECK_BULLETS as k,HIGHLIGHTS as C,MARGIN_PRESETS as S,PAPER_SIZES as N,REL as $,WEB_FONTS as A,WORD_NS as L,addContentDefault as P,addContentOverride as T,addRel as M,blankDocxParts as R,child as E,escapeXml as z,marginsOf as F,paperOf as O,paraCss as j,parseParaProps as H,parseRunProps as D,parseTabsAttr as I,parseXml as B,partText as U,readRels as W,resolveTarget as q,runCss as K,setPartText as G,tabCss as V,tabsAttr as X,webFontSheetUrl as Q,withMargins as _,withPaper as J,writeZip as Y}from"./chunk-D3JKD7KW.js";import{hasExtension as Z,placeCopy as ee}from"./chunk-XYVQTQ6N.js";import{useEffect as te,useRef as ne,useState as re}from"react";import{WindowTitle as oe,useWindowDirty as ae}from"efficient-shell";import{Button as ie,EmptyState as le,Input as se,LoadingSpinner as ce,confirmDestructive as de,toast as ue}from"efficient-shell/ui";import{useCallback as me,useEffect as fe,useId as pe,useMemo as he,useRef as ge,useState as we}from"react";import{saveIndicator as be,useAutosave as ye}from"efficient-easel/autosave";import{useEaselStrings as ve}from"efficient-easel/strings";import{Icon as xe}from"efficient-shell/icons";import{Button as ke,ColorPickerPanel as Ce,ContextMenu as Se,DropdownMenu as Ne,IconButton as $e,Popover as Ae,PopupMenu as Le,PopupMenuDivider as Pe,PopupMenuItem as Te,PopupMenuLabel as Me,prompt as Re,registerModalEscapeInterceptor as Ee,toast as ze,useShellLocale as Fe}from"efficient-shell/ui";import{SettingsColour as Oe}from"efficient-easel/panel";import{useEaselStrings as je}from"efficient-easel/strings";import{Button as He,Select as De}from"efficient-shell/ui";import{jsx as Ie,jsxs as Be}from"react/jsx-runtime";function Ue({page:e,onPage:t,onMorePageSetup:n,colour:r,onColour:o,outline:a,onHeading:i}){const l=u(),s=je(),c=O(e),d=F(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 Be("aside",{className:"docs-panel",children:[Ie("h3",{children:l.documentPanel}),Be("div",{className:"docs-panel-section",children:[Ie("p",{className:"docs-panel-label",children:l.pagePanel}),Ie(De,{"aria-label":l.paperSize,value:c??"custom",onChange:n=>{"custom"!==n&&t(J(e,n))},options:[...c?[]:[p],...Object.keys(N).map(e=>({value:e,label:m[e]}))]}),Ie(De,{"aria-label":l.margins,value:d??"custom",onChange:n=>{"custom"!==n&&t(_(e,n))},options:[...d?[]:[p],...Object.keys(S).map(e=>({value:e,label:f[e]}))]}),Ie(He,{variant:"secondary",block:!0,onClick:n,children:l.morePageSetup})]}),Ie("div",{className:"docs-panel-section",children:Ie(Oe,{label:l.textColor,value:r,onChange:o,words:s.colourRow})}),Be("div",{className:"docs-panel-section",children:[Ie("p",{className:"docs-panel-label",children:l.outline}),0===a.length?Ie("p",{className:"docs-panel-empty",children:l.outlineEmpty}):Ie("ul",{className:"docs-outline",children:a.map((e,t)=>Ie("li",{style:{paddingLeft:10*(e.level-1)+"px"},children:Ie("button",{type:"button",onClick:()=>i(t),children:e.text})},t))})]})]})}import{EaselIconButton as We,EaselTopBar as qe,SaveState as Ke,TopBarCluster as Ge,TopBarDivider as Ve}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 Xe}from"efficient-shell/icons";import{DropdownMenu as Qe}from"efficient-shell/ui";import{jsx as _e,jsxs as Je}from"react/jsx-runtime";function Ye({onClose:e,fileMenu:t,name:n,saveState:r,canUndo:o,canRedo:a,onUndo:i,onRedo:l,exportControl:s}){const c=u();return Je(qe,{children:[Je(Ge,{children:[e&&_e(We,{label:c.backToFiles,onClick:e,children:_e(Xe,{name:"chevron-left",size:16})}),t.length>0&&_e(Qe,{trigger:c.menuFile,items:t,align:"start",triggerClassName:"docs-menu-trigger"}),n,_e(Ke,{...r}),_e(Ve,{}),Je("span",{className:"docs-history",onMouseDown:e=>e.preventDefault(),children:[_e(We,{label:c.undo,disabled:!o,onClick:i,children:_e(Xe,{name:"undo",size:16})}),_e(We,{label:c.redo,disabled:!a,onClick:l,children:_e(Xe,{name:"redo",size:16})})]})]}),_e(Ge,{kind:"right",children:s})]})}var Ze=["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"],et=["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"],tt=["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"],nt=["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 rt(e){if(!e)return[];return B(e).children.map(t=>({name:t.name,xml:e.slice(t.start,t.end)}))}function ot(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 at(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 it={black:"#000000",white:"#ffffff",red:"#ff0000",blue:"#0000ff",green:"#008000",yellow:"#ffff00"};function lt(e){if(!e)return;const t=e.trim().toLowerCase();if("transparent"===t||"inherit"===t||"initial"===t||"auto"===t)return;if(it[t])return it[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 st(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 ct=[10,13,16,18,24,32,48].map(e=>.75*e);var dt=(e,t)=>void 0===e||void 0===t?e===t:Math.abs(e-t)<.02,ut=e=>Math.round(20*e);function mt(e,t,n){return ft(n?e.runs.get(n):void 0,t,e)}function ft(e,t,n){const r=e?B(e):void 0,o=D(r,n.theme);let a=rt(e);const i=(e,t)=>{a=a.filter(t=>!e.includes(t.name)),a.push(...t)},l=(e,t)=>void 0===t?[]:[{name:e,xml:t?`<${e}/>`:`<${e} w:val="0"/>`}];if(t.b!==o.b&&i(["w:b","w:bCs"],[...l("w:b",t.b),...l("w:bCs",t.b)]),t.i!==o.i&&i(["w:i","w:iCs"],[...l("w:i",t.i),...l("w:iCs",t.i)]),!!t.u!=!!o.u&&i(["w:u"],t.u?[{name:"w:u",xml:'<w:u w:val="single"/>'}]:o.u?[{name:"w:u",xml:'<w:u w:val="none"/>'}]:[]),t.strike!==o.strike&&!!t.strike!=!!o.strike&&i(["w:strike"],l("w:strike",t.strike)),t.vert!==o.vert&&i(["w:vertAlign"],t.vert?[{name:"w:vertAlign",xml:`<w:vertAlign w:val="${"sub"===t.vert?"subscript":"superscript"}"/>`}]:[]),t.font!==o.font){const e=z(t.font??"");i(["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!==o.size){const e=t.size?Math.round(2*t.size):0;i(["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!==o.color&&i(["w:color"],t.color?[{name:"w:color",xml:`<w:color w:val="${t.color.slice(1).toUpperCase()}"/>`}]:[]),t.hl!==o.hl){const e=t.hl?Object.entries(C).find(([,e])=>e===t.hl)?.[0]:void 0;i(["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 s=ot(a,Ze);return s?`<w:rPr>${s}</w:rPr>`:""}var pt={FootnoteText:'<w:style w:type="paragraph" w:styleId="FootnoteText"><w:name w:val="footnote text"/><w:basedOn w:val="Normal"/><w:uiPriority w:val="99"/><w:unhideWhenUsed/><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:rPr><w:sz w:val="20"/><w:szCs w:val="20"/></w:rPr></w:style>',FootnoteReference:'<w:style w:type="character" w:styleId="FootnoteReference"><w:name w:val="footnote reference"/><w:uiPriority w:val="99"/><w:unhideWhenUsed/><w:rPr><w:vertAlign w:val="superscript"/></w:rPr></w:style>',TOCHeading:'<w:style w:type="paragraph" w:styleId="TOCHeading"><w:name w:val="TOC Heading"/><w:basedOn w:val="Heading1"/><w:next w:val="Normal"/><w:uiPriority w:val="39"/><w:unhideWhenUsed/></w:style>',...Object.fromEntries([1,2,3,4,5,6].map(e=>[`TOC${e}`,`<w:style w:type="paragraph" w:styleId="TOC${e}"><w:name w:val="toc ${e}"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:uiPriority w:val="39"/><w:unhideWhenUsed/><w:pPr><w:spacing w:after="100"/><w:ind w:left="${220*(e-1)}"/></w:pPr></w:style>`]))};function ht(e){const t=W(e.parts,e.doc.docPath).find(e=>e.type===$.styles);return t?q(e.doc.docPath,t.target):void 0}function gt(e,t){const n=ht(e);if(!n)return;const r=U(e.parts,n);if(!r||new RegExp(`w:styleId="${t}"`).test(r))return;const o=x[t]?.xml??pt[t];o&&G(e.parts,n,r.replace("</w:styles>",`${o}</w:styles>`))}var wt=["w:name","w:aliases","w:basedOn","w:next","w:link","w:autoRedefine","w:hidden","w:uiPriority","w:semiHidden","w:unhideWhenUsed","w:qFormat","w:locked","w:personal","w:personalCompose","w:personalReply","w:rsid","w:pPr","w:rPr","w:tblPr","w:trPr","w:tcPr","w:tblStylePr"];function bt(e,t){let n=rt(e);const r=(e,t)=>{n=n.filter(t=>t.name!==e),t&&n.push({name:e,xml:t})};t.align&&r("w:jc",`<w:jc w:val="${"justify"===t.align?"both":t.align}"/>`);const o=[];void 0!==t.indentLeft&&o.push(`w:left="${ut(t.indentLeft)}"`),void 0!==t.indentRight&&o.push(`w:right="${ut(t.indentRight)}"`),void 0!==t.firstLine&&o.push(t.firstLine<0?`w:hanging="${ut(-t.firstLine)}"`:`w:firstLine="${ut(t.firstLine)}"`),o.length&&r("w:ind",`<w:ind ${o.join(" ")}/>`);const a=[];void 0!==t.before&&a.push(`w:before="${ut(t.before)}"`),void 0!==t.after&&a.push(`w:after="${ut(t.after)}"`),void 0!==t.lineMultiple&&a.push(`w:line="${Math.round(240*t.lineMultiple)}" w:lineRule="auto"`),void 0!==t.linePoints&&a.push(`w:line="${ut(t.linePoints)}" w:lineRule="exact"`),a.length&&r("w:spacing",`<w:spacing ${a.join(" ")}/>`);const i=ot(n,et);return i?`<w:pPr>${i}</w:pPr>`:""}function yt(e,t){const n=W(e.parts,e.doc.docPath).find(e=>e.type===$.styles),r=n?U(e.parts,q(e.doc.docPath,n.target)):void 0;if(r)for(const e of B(r).children)if("w:style"===e.name&&E(e,"w:name")?.attrs["w:val"]?.toLowerCase()===t)return e.attrs["w:styleId"];return Object.entries(x).find(([,e])=>e.name===t)?.[0]??null}var vt=["•","o","▪"],xt=["decimal","lowerLetter","lowerRoman"];function kt(e){const t=W(e.parts,e.doc.docPath).find(e=>e.type===$.numbering);if(t){const n=q(e.doc.docPath,t.target);return{path:n,text:U(e.parts,n)??`<w:numbering ${L}></w:numbering>`}}const n="word/numbering.xml";return M(e.parts,e.doc.docPath,$.numbering,"numbering.xml"),T(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 ${L}></w:numbering>`}}function Ct(e,t,n){const{path:r,text:o}=kt(e),a=B(o),i=a.children.filter(e=>"w:abstractNum"===e.name).map(e=>Number(e.attrs["w:abstractNumId"])),l=String((i.length?Math.max(...i):-1)+1);let s="";for(let e=0;e<9;e++){s+=`<w:lvl w:ilvl="${e}"><w:start w:val="1"/><w:numFmt w:val="${t?xt[e%3]:"bullet"}"/><w:lvlText w:val="${t?`%${e+1}.`:n??vt[e%3]}"/><w:lvlJc w:val="left"/><w:pPr><w:ind w:left="${720*(e+1)}" w:hanging="360"/></w:pPr></w:lvl>`}const c=`<w:abstractNum w:abstractNumId="${l}"><w:multiLevelType w:val="hybridMultilevel"/>${s}</w:abstractNum>`,d=a.children.find(e=>"w:num"===e.name),u=d?d.start:a.innerEnd>a.innerStart||o.includes("</w:numbering>")?o.lastIndexOf("</w:numbering>"):-1,m=u>=0?o.slice(0,u)+c+o.slice(u):o.replace(/\/>\s*$/,`>${c}</w:numbering>`);return G(e.parts,r,m),l}function St(e,t,n){const{path:r,text:o}=kt(e),a=B(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 G(e.parts,r,o.slice(0,d)+s+o.slice(d)),l}var Nt={"image/png":"png","image/jpeg":"jpeg","image/gif":"gif","image/bmp":"bmp","image/webp":"webp","image/svg+xml":"svg"};function $t(e,t){const n=t.getAttribute("data-raw"),r=function(e,t){const n=at(t),r=st(n.get("width")),o=st(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")??"",s=`${e.part}\n${l}`;let c=e.mediaBySrc.get(s);if(!c){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=Nt[t.mime]??"png";P(e.parts,n,t.mime);let r=1;const o=[...e.parts.keys()].find(r=>r.startsWith("word/media/inserted")&&r.endsWith(`.${n}`)&&function(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}(e.parts.get(r),t.bytes));if(o)r=Number(/inserted(\d+)\./.exec(o)[1]);else{for(;e.parts.has(`word/media/inserted${r}.${n}`);)r++;e.parts.set(`word/media/inserted${r}.${n}`,t.bytes)}c=M(e.parts,e.part,$.image,function(e,t){const n=e.split("/").slice(0,-1),r=t.split("/");let o=0;for(;o<n.length&&o<r.length-1&&n[o]===r[o];)o++;return[...n.slice(o).map(()=>".."),...r.slice(o)].join("/")}(e.part,`word/media/inserted${r}.${n}`)),e.mediaBySrc.set(s,c)}const d=++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="${d}" name="Picture ${d}"/><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="${d}" name="Picture ${d}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${c}"/><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 At(e,t,n,r={}){let o="",a=null;const i=()=>{a?.body&&(o+=`<w:r>${mt(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">${z(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+=$t(e,c));const u=c.getAttribute("data-raw");if(u){const t=e.doc.raw.get(u);if(t){i(),o+=t;const n=c.getAttribute("data-note");null!==n&&e.notesUsed.add(n)}return}if(c.hasAttribute("data-page-break"))return void l(r,a,'<w:br w:type="page"/>');const m=c.getAttribute("data-note");if(null!==m)return i(),e.notesUsed.add(m),gt(e,"FootnoteReference"),void(o+=`<w:r><w:rPr><w:rStyle w:val="FootnoteReference"/></w:rPr><w:footnoteReference w:id="${z(m)}"/></w:r>`);const f=c.getAttribute("data-bookmark");if(null!==f){i();const t=++e.bookmarkId;return void(o+=`<w:bookmarkStart w:id="${t}" w:name="${z(f)}"/><w:bookmarkEnd w:id="${t}"/>`)}const p=c.getAttribute("data-field");if("page"===p||"pages"===p)return i(),void(o+=`<w:fldSimple w:instr=" ${"page"===p?"PAGE":"NUMPAGES"} "><w:r>${mt(e.doc,r,a)}<w:t>1</w:t></w:r></w:fldSimple>`);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=W(e.parts,e.part),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??M(e.parts,e.part,$.hyperlink,a,!0),t.setAttribute("data-rel",i));const c=t.querySelector("[data-r]")?n:{color:"#0563c1",u:!0,...n},d=At(e,Array.from(t.childNodes),r,c);return`<w:hyperlink${o?` w:anchor="${z(o)}"`:i?` r:id="${z(i)}"`:a.startsWith("#")?` w:anchor="${z(a.slice(1))}"`:""} w:history="1">${d}</w:hyperlink>`}(e,c,r,n));const h=c.getAttribute("data-comment");h&&e.firstComment.get(h)===c&&(i(),o+=`<w:commentRangeStart w:id="${z(h)}"/>`);const g=c.getAttribute("data-r"),w=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=lt(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=ct[o-1])}const o=at(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(/["']|"/g,"").trim());const c=st(o.get("font-size"));if(c&&(n.size=Math.round(2*c)/2),o.has("color")){const e=lt(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=lt(d);e?n.hl=e:delete n.hl}return n}(c,r);for(const e of Array.from(c.childNodes))s(e,w,g??a);h&&e.lastComment.get(h)===c&&(i(),o+=`<w:commentRangeEnd w:id="${z(h)}"/><w:r><w:commentReference w:id="${z(h)}"/></w:r>`)};for(const e of t)s(e,r,null);return i(),o}function Lt(e,t,n,r,o){const a=n?B(n):void 0,i=H(a),l=function(e){const t=at(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=st(t.get("margin-left"));void 0!==o&&(n.indentLeft=o);const a=st(t.get("margin-right"));void 0!==a&&(n.indentRight=a),e.hasAttribute("data-tabs")&&(n.tabs=I(e.getAttribute("data-tabs")));const i=st(t.get("text-indent"));void 0!==i&&(n.firstLine=i);const l=st(t.get("margin-top"));void 0!==l&&(n.before=l);const s=st(t.get("margin-bottom"));void 0!==s&&(n.after=s);const c=t.get("line-height");if(c){const e=st(c);e?n.linePoints=e:Number(c)&&(n.lineMultiple=Number(c))}return n}(t);let s=rt(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="${z(r)}"/>`:null),c("w:numPr",o?`<w:numPr><w:ilvl w:val="${o.ilvl}"/><w:numId w:val="${z(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||dt(l.indentLeft,i.indentLeft)&&dt(l.firstLine,i.firstLine)&&dt(l.indentRight,i.indentRight))){const e=[];void 0!==l.indentLeft&&e.push(`w:left="${ut(l.indentLeft)}"`),void 0!==l.indentRight&&e.push(`w:right="${ut(l.indentRight)}"`),void 0!==l.firstLine&&e.push(l.firstLine<0?`w:hanging="${ut(-l.firstLine)}"`:`w:firstLine="${ut(l.firstLine)}"`),c("w:ind",e.length?`<w:ind ${e.join(" ")}/>`:null)}if(!(dt(l.before,i.before)&&dt(l.after,i.after)&&dt(l.lineMultiple,i.lineMultiple)&&dt(l.linePoints,i.linePoints))){const e=[];void 0!==l.before&&e.push(`w:before="${ut(l.before)}"`),void 0!==l.after&&e.push(`w:after="${ut(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="${ut(l.linePoints)}" w:lineRule="exact"`),c("w:spacing",e.length?`<w:spacing ${e.join(" ")}/>`:null)}if(t.hasAttribute("data-tabs")&&!Pt(l.tabs??[],i.tabs??[])){const e=(l.tabs??[]).map(e=>`<w:tab w:val="${e.align}" w:pos="${ut(e.pos)}"/>`),t=(i.tabs??[]).filter(e=>!(l.tabs??[]).some(t=>dt(t.pos,e.pos))).map(e=>`<w:tab w:val="clear" w:pos="${ut(e.pos)}"/>`);c("w:tabs",e.length||t.length?`<w:tabs>${[...e,...t].join("")}</w:tabs>`:null)}c("w:sectPr",e.sections.get(t)??null);const d=ot(s,et);return d?`<w:pPr>${d}</w:pPr>`:""}var Pt=(e,t)=>e.length===t.length&&e.every((e,n)=>dt(e.pos,t[n].pos)&&e.align===t[n].align);function Tt(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"))&&!e.sections.has(t)&&(t.hasAttribute("data-locked")||(a.numId??null)===(r?.numId??null)&&(a.ilvl??null)===(r?.ilvl??null))){for(const t of a.xml.matchAll(/<w:footnoteReference\b[^>]*w:id="([^"]+)"/g))e.notesUsed.add(t[1]);return a.xml}const i=Lt(e,t,a?.props,function(e,t){let n=t.getAttribute("data-pstyle");if(!n){const r=/^H([1-6])$/.exec(t.tagName);r?n=yt(e,`heading ${r[1]}`)??`Heading${r[1]}`:"BLOCKQUOTE"===t.tagName&&(n=yt(e,"quote"))}return n&>(e,n),n}(e,t),r);let l=At(e,n,t);const s=t.getAttribute("data-bm");if(s&&/^[A-Za-z0-9_]+$/.test(s)&&!l.includes(`w:name="${s}"`)){const t=++e.bookmarkId;l=`<w:bookmarkStart w:id="${t}" w:name="${s}"/>${l}<w:bookmarkEnd w:id="${t}"/>`}return`<w:p>${i}${l}</w:p>`}var Mt=new Set(["P","DIV","H1","H2","H3","H4","H5","H6","BLOCKQUOTE","PRE","UL","OL","TABLE","LI","HR","SECTION","ARTICLE"]);function Rt(e,t,n,r){if(t.hasAttribute("data-checklist")){const n=function(e){if(e.checkNums)return e.checkNums;const{path:t,text:n}=kt(e),r=B(n),o={},a=new Map;for(const e of r.children.filter(e=>"w:abstractNum"===e.name)){const t=e.children.find(e=>"w:lvl"===e.name&&"0"===e.attrs["w:ilvl"]),n=E(t,"w:lvlText")?.attrs["w:val"];n===k.open&&a.set(e.attrs["w:abstractNumId"],"open"),n===k.done&&a.set(e.attrs["w:abstractNumId"],"done")}for(const e of r.children.filter(e=>"w:num"===e.name)){const t=a.get(E(e,"w:abstractNumId")?.attrs["w:val"]??"");t&&!o[t]&&(o[t]=e.attrs["w:numId"])}const i=t=>{const n=Ct(e,!1,t);return St(e,n,!1)};return e.checkNums={open:o.open??i(k.open),done:o.done??i(k.done)},e.checkNums}(e),o=t.getAttribute("data-ilvl"),a=null!==o&&Number(o)>r?Number(o):r+1;let i="";for(const r of Array.from(t.children)){if("UL"===r.tagName||"OL"===r.tagName){i+=Rt(e,r,null,a);continue}if("LI"!==r.tagName)continue;const t=Array.from(r.children).filter(e=>"UL"===e.tagName||"OL"===e.tagName);i+=Tt(e,r,Array.from(r.childNodes).filter(e=>!t.includes(e)),{numId:r.hasAttribute("data-checked")?n.done:n.open,ilvl:a});for(const n of t)i+=Rt(e,n,null,a)}return i}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??=Ct(e,!0),o=St(e,e.orderedAbstract,!0)):(e.bulletNum??=St(e,Ct(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+=Rt(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+=Tt(e,n,Array.from(n.childNodes).filter(e=>!t.includes(e)),{numId:o,ilvl:i});for(const n of t)l+=Rt(e,n,o,i)}return l}function Et(e){return Array.from(e.children).some(e=>Mt.has(e.tagName))}function zt(e,t){let n="",r=[];const o=()=>{r.some(e=>1===e.nodeType||(e.nodeValue??"").trim())&&(n+=`<w:p>${At(e,r,t)}</w:p>`),r=[]};for(const a of Array.from(t.childNodes)){const t=a;if(1!==a.nodeType||!Mt.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+=Rt(e,t,null,-1):"TABLE"===t.tagName?n+=Ft(e,t):t.hasAttribute("data-toc")?n+=jt(e,t,l?.fingerprint===p(t)?l.xml:void 0):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>':Et(t)?n+=zt(e,t):n+=Tt(e,t,Array.from(t.childNodes),null)}return o(),n}function Ft(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]?st(at(s[t]).get("width")):void 0;c.push(void 0!==n&&s.length===i?ut(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>${Ot(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=lt(at(t.cell).get("background-color"));let l=zt(e,t.cell);return l.endsWith("</w:p>")||l.endsWith("<w:p/>")||(l+="<w:p/>"),`<w:tc><w:tcPr>${Ot(o?.props,r,n,a>1?"restart":null,i)}</w:tcPr>${l}</w:tc>`}).join("")}</w:tr>`).join("")}</w:tbl>`}function Ot(e,t,n,r,o){const a=e?B(e):void 0;let i=rt(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=E(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()}"/>`})),ot(i,tt)}function jt(e,t,n){if(n)return n;const r=Math.round(20*e.contentWidth),o='<w:r><w:fldChar w:fldCharType="begin"/></w:r><w:r><w:instrText xml:space="preserve"> TOC \\o "1-3" \\h \\z \\u </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r>',a=Array.from(t.querySelectorAll("[data-toc-level]")).map((t,n)=>{const a=Math.min(Math.max(Number(t.getAttribute("data-toc-level"))||1,1),6);gt(e,`TOC${a}`);const i=t.querySelector("a"),l=i?.getAttribute("data-anchor")??"",s=t.querySelector("[data-toc-page]")?.textContent??"",c=(i??t).cloneNode(!0);c.querySelectorAll("[data-toc-page]").forEach(e=>e.remove());const d=`<w:r><w:t xml:space="preserve">${z(c.textContent??"")}</w:t></w:r><w:r><w:tab/></w:r><w:r><w:t>${z(s)}</w:t></w:r>`,u=/^[A-Za-z0-9_]+$/.test(l)?`<w:hyperlink w:anchor="${l}" w:history="1">${d}</w:hyperlink>`:d;return`<w:p><w:pPr><w:pStyle w:val="TOC${a}"/><w:tabs><w:tab w:val="right" w:leader="dot" w:pos="${r}"/></w:tabs></w:pPr>${0===n?o:""}${u}</w:p>`});return a.length||a.push(`<w:p>${o}</w:p>`),`<w:sdt><w:sdtPr><w:docPartObj><w:docPartGallery w:val="Table of Contents"/><w:docPartUnique/></w:docPartObj></w:sdtPr><w:sdtContent>${a.join("")}<w:p><w:r><w:fldChar w:fldCharType="end"/></w:r></w:p></w:sdtContent></w:sdt>`}function Ht(e,t){return`<w:footnote w:id="${z(e)}"><w:p><w:pPr><w:pStyle w:val="FootnoteText"/></w:pPr><w:r><w:rPr><w:rStyle w:val="FootnoteReference"/></w:rPr><w:footnoteRef/></w:r><w:r><w:t xml:space="preserve"> ${z(t)}</w:t></w:r></w:p></w:footnote>`}var Dt=["w:writeProtection","w:view","w:zoom","w:removePersonalInformation","w:removeDateAndTime","w:doNotDisplayPageBoundaries","w:displayBackgroundShape","w:printPostScriptOverText","w:printFractionalCharacterWidth","w:printFormsData","w:embedTrueTypeFonts","w:embedSystemFonts","w:saveSubsetFonts","w:saveFormsData","w:mirrorMargins","w:alignBordersAndEdges","w:bordersDoNotSurroundHeader","w:bordersDoNotSurroundFooter","w:gutterAtTop","w:hideSpellingErrors","w:hideGrammaticalErrors","w:activeWritingStyle","w:proofState","w:formsDesign","w:attachedTemplate","w:linkStyles","w:stylePaneFormatFilter","w:stylePaneSortMethod","w:documentType","w:mailMerge","w:revisionView","w:trackRevisions","w:doNotTrackMoves","w:doNotTrackFormatting","w:documentProtection","w:autoFormatOverride","w:styleLockTheme","w:styleLockQFSet","w:defaultTabStop","w:autoHyphenation","w:consecutiveHyphenLimit","w:hyphenationZone","w:doNotHyphenateCaps","w:showEnvelope","w:summaryLength","w:clickAndTypeStyle","w:defaultTableStyle","w:evenAndOddHeaders","w:bookFoldRevPrinting","w:bookFoldPrinting","w:bookFoldPrintingSheets","w:drawingGridHorizontalSpacing","w:drawingGridVerticalSpacing","w:displayHorizontalDrawingGridEvery","w:displayVerticalDrawingGridEvery","w:doNotUseMarginsForDrawingGridOrigin","w:drawingGridHorizontalOrigin","w:drawingGridVerticalOrigin","w:doNotShadeFormData","w:noPunctuationKerning","w:characterSpacingControl","w:printTwoOnOne","w:strictFirstAndLastChars","w:noLineBreaksAfter","w:noLineBreaksBefore","w:savePreviewPicture","w:doNotValidateAgainstSchema","w:saveInvalidXml","w:ignoreMixedContent","w:alwaysShowPlaceholderText","w:doNotDemarcateInvalidXml","w:saveXmlDataOnly","w:useXSLTWhenSaving","w:saveThroughXslt","w:showXMLTags","w:alwaysMergeEmptyNamespace","w:updateFields","w:hdrShapeDefaults","w:footnotePr","w:endnotePr","w:compat","w:docVars","w:rsids","m:mathPr","w:attachedSchema","w:themeFontLang","w:clrSchemeMapping","w:doNotIncludeSubdocsInStats","w:doNotAutoCompressPictures","w:forceUpgrade","w:captions","w:readModeInkLockDown","w:smartTagType","sl:schemaLibrary","w:shapeDefaults","w:doNotEmbedSmartTags","w:decimalSymbol","w:listSeparator"];function It(e,t,n){const{path:r,text:o}=function(e){const t=W(e.parts,e.doc.docPath).find(e=>e.type===$.settings);if(t){const n=q(e.doc.docPath,t.target);return{path:n,text:U(e.parts,n)??`<w:settings ${L}></w:settings>`}}const n="word/settings.xml";return M(e.parts,e.doc.docPath,$.settings,"settings.xml"),T(e.parts,n,"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml"),{path:n,text:`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:settings ${L}></w:settings>`}}(e),a=B(o),i=a.children.find(e=>e.name===t);let l=o;if(i)l=o.slice(0,i.start)+(n??"")+o.slice(i.end);else if(n){const e=Dt.indexOf(t),r=a.children.find(t=>Dt.indexOf(t.name)>e);l=r?o.slice(0,r.start)+n+o.slice(r.start):/<\/w:settings>\s*$/.test(o)?o.replace(/<\/w:settings>\s*$/,`${n}</w:settings>`):o.replace(/\/>\s*$/,`>${n}</w:settings>`)}l!==o&&G(e.parts,r,l)}function Bt(e,t,n){const r=/^<w:sectPr\b([^>]*?)\/?>/.exec(e)?.[1]??"";let o=rt(`<x>${/^<w:sectPr\b[^>]*\/>$/.test(e)?"":e.replace(/^<w:sectPr\b[^>]*>/,"").replace(/<\/w:sectPr>$/,"")}</x>`).filter(e=>e.name!==t);return n&&(o=[...o,{name:t,xml:n}]),`<w:sectPr${r}>${ot(o,nt)}</w:sectPr>`}var Ut=e=>e>1?`<w:cols w:num="${e}" w:space="720"/>`:null;var Wt=`${L} xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"`;function qt(e,t,n,r){const o=document.createElement("div");o.innerHTML=n;const a=e.part;let i;e.part=r;try{i=zt(e,o)}finally{e.part=a}/<\/w:p>\s*$|<w:p\/>\s*$/.test(i)||(i+="<w:p/>");const l=U(e.parts,r);return`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n${(l?new RegExp(`<w:${t}\\b[^>]*>`).exec(l)?.[0]:void 0)??`<w:${t} ${Wt}>`}${i}</w:${t}>`}async function Kt(e,t,n){const r=new Map(e.parts),o=U(r,e.docPath);if(!o)throw new Error("Not a Word document");const a=B(o),i=E(a,"w:body"),l=E(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,part:e.docPath,checkNums:null,bookmarkId:8e4,sections:new Map,notesUsed:new Set};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)});const c=l?o.slice(l.start,l.end):void 0,d=function(e,t,n){const r=Array.from(t.children).filter(e=>e.hasAttribute("data-section")),o=(n??"<w:sectPr/>").replace(/<w:(header|footer)Reference\b[^>]*\/>/g,"").replace(/<w:titlePg\b[^>]*\/>/g,"").replace(/<w:type\b[^>]*\/>/g,"");r.forEach((t,n)=>{const a=e.doc.blocks.get(t.getAttribute("data-docx")??""),i=a?.props?/<w:sectPr\b[\s\S]*?(?:<\/w:sectPr>|\/>)/.exec(a.props)?.[0]:void 0;let l=i??o;const s=0===n?null:r[n-1].getAttribute("data-section");l=0===n&&i?l:Bt(l,"w:type",s&&"nextPage"!==s?`<w:type w:val="${z(s)}"/>`:null),l=Bt(l,"w:cols",Ut(Number(t.getAttribute("data-cols")??1))),e.sections.set(t,l)});const a=r[r.length-1]?.getAttribute("data-section");return r.length?a??"nextPage":null}(s,t,c);let u=zt(s,t);/<\/w:p>\s*$|<w:p\/>\s*$/.test(u)||(u+="<w:p/>"),u=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("")}(u);const m=function(e,t,n,r){let o=t??"<w:sectPr/>";const a=n.page,i=e.doc.page;if(Object.keys(a).some(e=>a[e]!==i[e])||!t){const e=a.width>a.height,n=t?B(t):void 0,r=E(n,"w:pgMar")?.attrs["w:gutter"]??"0";o=Bt(o,"w:pgSz",`<w:pgSz w:w="${a.width}" w:h="${a.height}"${e?' w:orient="landscape"':""}/>`),o=Bt(o,"w:pgMar",`<w:pgMar w:top="${a.top}" w:right="${a.right}" w:bottom="${a.bottom}" w:left="${a.left}" w:header="${a.header}" w:footer="${a.footer}" w:gutter="${r}"/>`)}const l=n.columns??e.doc.columns;l!==e.doc.columns&&(o=Bt(o,"w:cols",Ut(l))),null!==r&&(o=Bt(o,"w:type","nextPage"!==r?`<w:type w:val="${z(r)}"/>`:null));const s=n.titlePage??e.doc.titlePage;s!==e.doc.titlePage&&(o=Bt(o,"w:titlePg",s?"<w:titlePg/>":null));const c=n.evenOdd??e.doc.evenOdd;c!==e.doc.evenOdd&&It(e,"w:evenAndOddHeaders",c?"<w:evenAndOddHeaders/>":null);const d=[],u=(t,n)=>{const r="headers"===t?"header":"footer";for(const o of["default","first","even"]){const a=e.doc[t][o],i=n?.[o];if(void 0===i||!a.editable||i===a.html)continue;if(!a.part&&!i.replace(/<br>|<p>|<\/p>|\s/g,""))continue;let l=a.part;if(!l){let n=1;for(;e.parts.has(`word/${r}${n}.xml`);)n++;l=`word/${r}${n}.xml`,G(e.parts,l,""),T(e.parts,l,`application/vnd.openxmlformats-officedocument.wordprocessingml.${r}+xml`);const i=M(e.parts,e.doc.docPath,"headers"===t?$.header:$.footer,`${r}${n}.xml`);d.push(`<w:${r}Reference w:type="${o}" r:id="${i}"/>`),a.part=l}G(e.parts,l,qt(e,"headers"===t?"hdr":"ftr",i,l))}};if(u("headers",n.headers),u("footers",n.footers),d.length){const e=/^<w:sectPr\b([^>]*?)\/?>/.exec(o)?.[1]??"",t=/^<w:sectPr\b[^>]*\/>$/.test(o)?"":o.replace(/^<w:sectPr\b[^>]*>/,"").replace(/<\/w:sectPr>$/,"");o=`<w:sectPr${e}>${ot([...rt(`<x>${t}</x>`),...d.map(e=>({name:/^<(w:\w+)/.exec(e)[1],xml:e}))],nt)}</w:sectPr>`}return o}(s,c,n,d);!function(e){const t=[...e.notesUsed].filter(t=>{const n=e.doc.footnotes.get(t);return n&&n.editable&&(!n.xml||n.text!==e.doc.footnotesRead?.get(t))});if(!t.length)return;gt(e,"FootnoteText"),gt(e,"FootnoteReference");const n=W(e.parts,e.doc.docPath).find(e=>e.type===$.footnotes);let r,o;n?(r=q(e.doc.docPath,n.target),o=U(e.parts,r)??""):(r="word/footnotes.xml",M(e.parts,e.doc.docPath,$.footnotes,"footnotes.xml"),T(e.parts,r,"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"),o=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:footnotes ${L}><w:footnote w:type="separator" w:id="-1"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:separator/></w:r></w:p></w:footnote><w:footnote w:type="continuationSeparator" w:id="0"><w:p><w:pPr><w:spacing w:after="0" w:line="240" w:lineRule="auto"/></w:pPr><w:r><w:continuationSeparator/></w:r></w:p></w:footnote></w:footnotes>`,It(e,"w:footnotePr",'<w:footnotePr><w:footnote w:id="-1"/><w:footnote w:id="0"/></w:footnotePr>'));const a=B(o),i=new Map(a.children.filter(e=>"w:footnote"===e.name).map(e=>[e.attrs["w:id"],e]));let l=o;const s=[],c=[];for(const n of t){const t=Ht(n,e.doc.footnotes.get(n).text),r=i.get(n);r?c.push({start:r.start,end:r.end,xml:t}):s.push(t)}for(const e of c.sort((e,t)=>t.start-e.start))l=l.slice(0,e.start)+e.xml+l.slice(e.end);s.length&&(l=l.replace(/<\/w:footnotes>\s*$/,`${s.join("")}</w:footnotes>`)),G(e.parts,r,l)}(s),n.styleEdits?.size&&function(e,t){for(const n of t.keys())gt(e,n);const n=ht(e),r=n?U(e.parts,n):void 0;if(!n||!r)return;let o=r;const a=B(r).children.filter(e=>"w:style"===e.name&&t.has(e.attrs["w:styleId"])).reverse();for(const n of a){const a=t.get(n.attrs["w:styleId"]),i=r.slice(n.start,n.end),l=B(i),s=E(l,"w:rPr"),c=E(l,"w:pPr"),d=s?i.slice(s.start,s.end):void 0,u=c?i.slice(c.start,c.end):void 0,m=ft(d,{...D(s,e.doc.theme),...a.run},e.doc),f=bt(u,a.para);let p=l.children.filter(e=>"w:rPr"!==e.name&&"w:pPr"!==e.name).map(e=>({name:e.name,xml:i.slice(e.start,e.end)}));f&&p.push({name:"w:pPr",xml:f}),m&&p.push({name:"w:rPr",xml:m}),p=p.filter(Boolean);const h=`${/^<w:style\b[^>]*?(?=\/?>)/.exec(i)[0]}>${ot(p,wt)}</w:style>`;o=o.slice(0,n.start)+h+o.slice(n.end)}G(e.parts,n,o)}(s,n.styleEdits);const f=o.slice(a.start,a.innerStart),p=[!/\bxmlns:r=/.test(f)&&/\br:(id|embed)=/.test(u+m)?' xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"':""].join(""),h=(p?o.slice(0,a.innerStart-1)+p+">":o.slice(0,a.innerStart))+o.slice(a.innerStart,i.innerStart)+u+m+o.slice(i.innerEnd);G(r,e.docPath,h),e.parts=r,e.page={...n.page};for(const t of["headers","footers"]){const r=n[t];for(const n of["default","first","even"]){const o=r?.[n];void 0!==o&&e[t][n].editable&&(e[t][n]={...e[t][n],html:o})}}return e.titlePage=n.titlePage??e.titlePage,e.evenOdd=n.evenOdd??e.evenOdd,e.columns=n.columns??e.columns,e.footnotesRead=new Map([...e.footnotes].map(([e,t])=>[e,t.text])),Y(r)}import{useRef as Gt,useState as Vt}from"react";import{Icon as Xt}from"efficient-shell/icons";import{Button as Qt,Checkbox as _t,Dialog as Jt,IconButton as Yt}from"efficient-shell/ui";import{Fragment as Zt,jsx as en,jsxs as tn}from"react/jsx-runtime";function nn({label:e,html:t,locked:n,scope:r,onRef:o}){const a=u(),i=Gt(null),l=(e,t)=>{document.activeElement!==i.current&&i.current?.focus(),document.execCommand(e,!1,t)},s=e=>{const t=i.current,n=document.getSelection();if(!t||!n)return;if(!n.rangeCount||!t.contains(n.anchorNode)){t.focus();const e=document.createRange();e.selectNodeContents(t.lastElementChild??t),e.collapse(!1),n.removeAllRanges(),n.addRange(e)}const r=n.getRangeAt(0);r.deleteContents();const o=document.createElement("div");o.innerHTML=(e=>`<span data-kind="field" data-field="${e}" contenteditable="false">1</span>`)(e);const a=o.firstChild;r.insertNode(a);const l=a.nextSibling;l&&"BR"===l.nodeName&&!l.nextSibling&&l.remove();const s=document.createTextNode("");a.after(s),n.collapse(s,1)};return tn("div",{className:"docs-hf-region",children:[tn("div",{className:"docs-hf-tools",onMouseDown:e=>e.preventDefault(),children:[en("span",{className:"docs-hf-label",children:e}),!n&&tn(Zt,{children:[en(Yt,{size:"sm",variant:"ghost","aria-label":a.bold,title:a.bold,onClick:()=>l("bold"),children:en(Xt,{name:"bold",size:14})}),en(Yt,{size:"sm",variant:"ghost","aria-label":a.italic,title:a.italic,onClick:()=>l("italic"),children:en(Xt,{name:"italic",size:14})}),en(Yt,{size:"sm",variant:"ghost","aria-label":a.underline,title:a.underline,onClick:()=>l("underline"),children:en(Xt,{name:"underline",size:14})}),en(Yt,{size:"sm",variant:"ghost","aria-label":a.alignLeft,title:a.alignLeft,onClick:()=>l("justifyLeft"),children:en(Xt,{name:"align-left",size:14})}),en(Yt,{size:"sm",variant:"ghost","aria-label":a.alignCenter,title:a.alignCenter,onClick:()=>l("justifyCenter"),children:en(Xt,{name:"align-center",size:14})}),en(Yt,{size:"sm",variant:"ghost","aria-label":a.alignRight,title:a.alignRight,onClick:()=>l("justifyRight"),children:en(Xt,{name:"align-right",size:14})}),en(Qt,{size:"sm",variant:"ghost",onClick:()=>s("page"),children:a.pageNumber}),en(Qt,{size:"sm",variant:"ghost",onClick:()=>s("pages"),children:a.pageCount})]})]}),en("div",{ref:e=>{i.current=e,o(e),e&&!e.dataset.ready&&(e.innerHTML=t||"<p><br></p>",e.dataset.ready="1")},className:"docs-page docs-hf-edit","data-doc":r,role:"textbox","aria-label":e,"aria-multiline":"true",contentEditable:!n,suppressContentEditableWarning:!0}),n&&en("p",{className:"docs-hf-note",children:a.headerFooterLocked})]})}function rn({value:e,locked:t,scope:n,onApply:r,onClose:o}){const a=u(),[i,l]=Vt(e.titlePage),[s,c]=Vt(e.evenOdd),d=Gt({}),m=[...i?["first"]:[],"default",...s?["even"]:[]],f={first:a.headerFirst,default:s?a.headerOdd:a.headerDefault,even:a.headerEven};return en(Jt,{open:!0,onClose:o,title:a.headersFooters,size:"lg",footer:tn(Zt,{children:[en(Qt,{variant:"secondary",onClick:o,children:a.cancel}),en(Qt,{variant:"primary",onClick:()=>{const t=(t,n)=>{const r=d.current[`${t}:${n}`];if(!r)return e[t][n];const o=r.innerHTML;return"<p><br></p>"!==o||e[t][n]?o:""},n=e=>({default:t(e,"default"),first:t(e,"first"),even:t(e,"even")});r({headers:n("headers"),footers:n("footers"),titlePage:i,evenOdd:s})},children:a.ok})]}),children:tn("div",{className:"docs-hf",children:[tn("div",{className:"docs-hf-options",children:[en(_t,{checked:i,onChange:l,label:a.differentFirst}),en(_t,{checked:s,onChange:c,label:a.differentOddEven})]}),m.map(r=>tn("section",{className:"docs-hf-kind",children:[en("h4",{children:f[r]}),en(nn,{label:`${a.header} · ${f[r]}`,html:e.headers[r],locked:t.headers[r],scope:n,onRef:e=>{d.current[`headers:${r}`]=e}}),en(nn,{label:`${a.footer} · ${f[r]}`,html:e.footers[r],locked:t.footers[r],scope:n,onRef:e=>{d.current[`footers:${r}`]=e}})]},r))]})})}import{useState as on}from"react";import{Button as an,Dialog as ln,FormField as sn,Input as cn,Select as dn}from"efficient-shell/ui";import{Fragment as un,jsx as mn,jsxs as fn}from"react/jsx-runtime";var pn=e=>{const t=Number(e.replace(",","."));return""!==e.trim()&&Number.isFinite(t)?t:void 0},hn=e=>void 0===e?"":String(Math.round(100*e)/100);function gn({value:e,onApply:t,onClose:n}){const r=u(),[o,a]=on(hn(e.lineMultiple??1.15)),[i,l]=on(hn(e.before??0)),[s,c]=on(hn(e.after??0)),[d,m]=on(hn(e.indentLeft??0)),[f,p]=on(hn(e.indentRight??0)),[h,g]=on(void 0===e.firstLine||0===e.firstLine?"none":e.firstLine>0?"first":"hanging"),[w,b]=on(hn(void 0===e.firstLine?36:Math.abs(e.firstLine)||36)),[y,v]=on(""),x=e=>t=>{e(t.target.value),v("")};return fn(ln,{open:!0,onClose:n,title:r.customSpacing,size:"sm",footer:fn(un,{children:[mn(an,{variant:"secondary",onClick:n,children:r.cancel}),mn(an,{variant:"primary",onClick:()=>{if([o,i,s,d,f,..."none"===h?[]:[w]].some(e=>void 0===pn(e)||pn(e)<0)||pn(o)<=0||pn(o)>10)return void v(r.spacingInvalid);const e=pn(w);t({lineMultiple:pn(o),before:pn(i),after:pn(s),indentLeft:pn(d),indentRight:pn(f),firstLine:"none"===h?0:"first"===h?e:-e})},children:r.ok})]}),children:[fn("div",{className:"docs-para-grid",children:[mn(sn,{label:r.lineSpacingCustom,children:mn(cn,{inputMode:"decimal",value:o,onChange:x(a)})}),mn(sn,{label:r.spacingBefore,children:mn(cn,{inputMode:"decimal",value:i,onChange:x(l)})}),mn(sn,{label:r.spacingAfter,children:mn(cn,{inputMode:"decimal",value:s,onChange:x(c)})}),mn(sn,{label:r.indentLeft,children:mn(cn,{inputMode:"decimal",value:d,onChange:x(m)})}),mn(sn,{label:r.indentRight,children:mn(cn,{inputMode:"decimal",value:f,onChange:x(p)})}),mn(sn,{label:r.indentSpecial,children:mn(dn,{value:h,onChange:e=>{g(String(e)),v("")},options:[{value:"none",label:r.indentNone},{value:"first",label:r.indentFirstLine},{value:"hanging",label:r.indentHanging}]})}),"none"!==h&&mn(sn,{label:r.indentBy,children:mn(cn,{inputMode:"decimal",value:w,onChange:x(b)})})]}),y&&mn("p",{className:"docs-para-error",role:"alert",children:y})]})}import{useRef as wn}from"react";import{Fragment as bn,jsx as yn,jsxs as vn}from"react/jsx-runtime";var xn=4/3,kn={left:"center",center:"right",right:"left"};function Cn({pageWidth:e,marginLeft:t,marginRight:n,zoom:r,value:o,onChange:a}){const i=u(),l=wn(null),s=r/100*xn,c=e-t-n,d=e=>(t+e)*s+"px",m=e=>{const n=l.current.getBoundingClientRect();return r=(e-n.left)/s-t,4.5*Math.round(r/4.5);var r},f=(e,t,n)=>{e.preventDefault(),e.stopPropagation();const r=e.currentTarget;r.setPointerCapture(e.pointerId);const o=l.current.getBoundingClientRect().bottom,i=e=>{const n=t(m(e.clientX),e.clientY>o+12);n&&a(n)},s=e=>{r.removeEventListener("pointermove",i),r.removeEventListener("pointerup",s);const t=n?.(m(e.clientX),e.clientY>o+12);t&&a(t)};r.addEventListener("pointermove",i),r.addEventListener("pointerup",s)},p=(e,t,n)=>Math.min(Math.max(e,t),n),h=o;return vn("div",{className:"docs-ruler",style:{width:e*s+"px"},"aria-label":i.ruler,title:h?i.tabStopHint:void 0,ref:l,onPointerDown:e=>{if(!h||0!==e.button)return;const t=m(e.clientX);t<=0||t>=c||a({...h,tabs:[...h.tabs.filter(e=>Math.abs(e.pos-t)>1),{pos:t,align:"left"}].sort((e,t)=>e.pos-t.pos)})},children:[yn("div",{className:"docs-ruler-margin",style:{left:0,width:d(0)}}),yn("div",{className:"docs-ruler-margin",style:{right:0,width:n*s+"px"}}),Array.from({length:Math.floor(c/36)+1},(e,t)=>yn("span",{className:"docs-ruler-tick",style:{left:d(36*t)},children:t?t/2:""},t)),h&&vn(bn,{children:[yn("button",{type:"button",className:"docs-ruler-first","aria-label":i.indentFirstLine,style:{left:d(h.indentLeft+h.firstLine)},onPointerDown:e=>f(e,e=>({...h,firstLine:p(e,0,c-18)-h.indentLeft}))}),yn("button",{type:"button",className:"docs-ruler-left","aria-label":i.indentLeft,style:{left:d(h.indentLeft)},onPointerDown:e=>f(e,e=>{const t=p(e,0,c-h.indentRight-18);return{...h,indentLeft:t}})}),yn("button",{type:"button",className:"docs-ruler-right","aria-label":i.indentRight,style:{left:d(c-h.indentRight)},onPointerDown:e=>f(e,e=>({...h,indentRight:p(c-e,0,c-h.indentLeft-18)}))}),h.tabs.map((e,t)=>yn("button",{type:"button",className:`docs-ruler-tab docs-ruler-tab-${e.align}`,"aria-label":`${i.tabStop} ${Math.round(e.pos)}pt`,style:{left:d(e.pos)},onDoubleClick:e=>{e.stopPropagation(),a({...h,tabs:h.tabs.map((e,n)=>n===t?{...e,align:kn[e.align]}:e)})},onPointerDown:e=>f(e,e=>({...h,tabs:h.tabs.map((n,r)=>r===t?{...n,pos:p(e,0,c)}:n)}),(e,n)=>({...h,tabs:n?h.tabs.filter((e,n)=>n!==t):h.tabs.map((n,r)=>r===t?{...n,pos:p(e,0,c)}:n).sort((e,t)=>e.pos-t.pos)}))},`${e.pos}-${t}`))]})]})}function Sn(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 Nn,useRef as $n}from"react";import{Icon as An}from"efficient-shell/icons";import{Button as Ln,Checkbox as Pn,IconButton as Tn,Input as Mn}from"efficient-shell/ui";import{jsx as Rn,jsxs as En}from"react/jsx-runtime";function zn({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=$n(null);return Nn(()=>{p.current?.focus(),p.current?.select()},[]),En("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-line bg-surface-sunken px-2 py-1",children:[Rn("div",{className:"w-40",children:Rn(Mn,{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))}})}),Rn("span",{className:"min-w-14 text-xs text-ink-muted","aria-live":"polite",children:e?o?f.matchCount(r+1,o):f.noMatches:""}),Rn(Tn,{size:"sm",variant:"ghost","aria-label":f.previousMatch,title:f.previousMatch,onClick:()=>s(!1),children:Rn(An,{name:"chevron-up",size:16})}),Rn(Tn,{size:"sm",variant:"ghost","aria-label":f.nextMatch,title:f.nextMatch,onClick:()=>s(!0),children:Rn(An,{name:"chevron-down",size:16})}),Rn("div",{className:"ml-1 w-40",children:Rn(Mn,{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())}})}),Rn(Ln,{size:"sm",variant:"secondary",onClick:c,children:f.replace}),Rn(Ln,{size:"sm",variant:"secondary",onClick:d,children:f.replaceAll}),En("label",{className:"ml-1 flex items-center gap-1 text-xs text-ink-muted",children:[Rn(Pn,{checked:n,onChange:l,"aria-label":f.matchCase}),f.matchCase]}),Rn(Tn,{className:"ml-auto",size:"sm",variant:"ghost","aria-label":f.closeFind,title:f.closeFind,onClick:m,children:Rn(An,{name:"close",size:16})})]})}var Fn=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 On(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 jn(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 Hn(e){return Array.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6")).filter(e=>!e.closest("[data-hidden]")&&""!==(e.textContent??"").trim())}var Dn=["#000000","#404040","#7f7f7f","#c00000","#ff0000","#ffc000","#00b050","#0070c0","#002060","#7030a0"],In=["#ffff00","#00ff00","#00ffff","#ff00ff","#ff0000","#c0c0c0"],Bn=["#d9e2f3","#e2efd9","#fff2cc","#fbe4d5","#ededed","#bfbfbf"];function Un(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 Wn}from"react";import{Button as qn,Dialog as Kn,FormField as Gn,Select as Vn}from"efficient-shell/ui";import{Fragment as Xn,jsx as Qn,jsxs as _n}from"react/jsx-runtime";function Jn({value:e,onApply:t,onClose:n}){const r=u(),[o,a]=Wn(e.page),i=o.width>o.height,l=O(o),s=F(o),c={a4:"A4",a3:"A3",a5:"A5",letter:r.paperLetter,legal:r.paperLegal},d={normal:r.marginsNormal,narrow:r.marginsNarrow,moderate:r.marginsModerate,wide:r.marginsWide},m={value:"custom",label:r.custom};return Qn(Kn,{open:!0,onClose:n,title:r.pageSetup,size:"sm",footer:_n(Xn,{children:[Qn(qn,{variant:"secondary",onClick:n,children:r.cancel}),Qn(qn,{variant:"primary",onClick:()=>t({page:o}),children:r.ok})]}),children:_n("div",{className:"space-y-3",children:[Qn(Gn,{label:r.paperSize,children:Qn(Vn,{value:l??"custom",onChange:e=>{"custom"!==e&&a(t=>J(t,e))},options:[...l?[]:[m],...Object.keys(N).map(e=>({value:e,label:c[e]}))]})}),Qn(Gn,{label:r.orientation,children:Qn(Vn,{value:i?"landscape":"portrait",onChange:e=>{"landscape"===e!==i&&a(e=>({...e,width:e.height,height:e.width}))},options:[{value:"portrait",label:r.portrait},{value:"landscape",label:r.landscape}]})}),Qn(Gn,{label:r.margins,children:Qn(Vn,{value:s??"custom",onChange:e=>{"custom"!==e&&a(t=>_(t,e))},options:[...s?[]:[m],...Object.keys(S).map(e=>({value:e,label:d[e]}))]})})]})})}var Yn=e=>e.querySelectorAll("ul,ol").forEach(e=>e.removeAttribute("data-ilvl"));function Zn(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),Yn(e),!0}function er(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),Yn(e),t.children.length||t.remove(),!0}var tr=e=>Array.from(e.querySelectorAll(":scope > tbody > tr, :scope > tr, :scope > thead > tr, :scope > tfoot > tr")),nr=(e,t)=>Math.max(1,Number(e.getAttribute(t)??1));function rr(e){const t=tr(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=nr(a,"colspan"),i=nr(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 or(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 ar(e){const t=e.createElement("td");return t.innerHTML="<p><br></p>",t}function ir(e,t,n){const r=rr(e),o=or(r,t);if(!o)return;const a=tr(e),i=nr(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(nr(n,"rowspan")+1))):s.appendChild(ar(e.ownerDocument))}const d=a[l];d?d.parentNode.insertBefore(s,d):a[a.length-1].parentNode.appendChild(s)}function lr(e,t,n){const r=rr(e),o=or(r,t);if(!o)return;const a=n?o.col+nr(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(nr(r,"colspan")+1))));if(o&&o.parentElement!==tr(e)[n])return;const l=tr(e)[n],s=t.slice(a).find(e=>e.parentElement===l);l.insertBefore(ar(e.ownerDocument),s??null)}),sr(e,r.cols+1,a,null)}function sr(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 cr,jsx as dr,jsxs as ur}from"react/jsx-runtime";var mr=["Calibri","Arial","Cambria","Courier New","Georgia","Tahoma","Times New Roman","Verdana"],fr=[8,9,10,10.5,11,12,14,16,18,20,22,24,28,32,36,48,72],pr=[1,1.15,1.5,2,2.5,3],hr=/^[A-Za-z][A-Za-z0-9_]{0,39}$/,gr="data-docs-fonts",wr=["default","first","even"];function br(e){const t=[...new Set(e)].filter(e=>A.includes(e));if(!t.length||"undefined"==typeof document)return;const n=document.head.querySelector(`link[${gr}]`),r=n?.getAttribute(gr)?.split("|").filter(Boolean)??[],o=[...new Set([...r,...t])].sort();if(n&&o.length===r.length)return;const a=document.createElement("link");a.rel="stylesheet",a.href=Q(o),a.setAttribute(gr,o.join("|")),document.head.appendChild(a),n?.remove()}function yr(e,t,n){if(!e)return"";const r=document.createElement("div");return r.innerHTML=e,r.querySelectorAll('[data-field="page"]').forEach(e=>{e.textContent=String(t)}),r.querySelectorAll('[data-field="pages"]').forEach(e=>{e.textContent=String(n)}),r.innerHTML}var vr=e=>Math.round(.75*(parseFloat(e)||0)*100)/100,xr=[50,75,90,100,110,125,150,200],kr="p,h1,h2,h3,h4,h5,h6,li,blockquote,pre",Cr=/^(https?:|mailto:|tel:)/i,Sr={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 Nr({sessionKey:d,doc:m,filename:f,images:p,fileEntries:w,title:b,startsDirty:y,dirty:x,onDirty:k,onOpenFile:C,onNewImageUrl:S,onClose:N,stored:$,onReload:L}){const P=u(),T=Fe(),M=pe().replace(/[^a-zA-Z0-9]/g,""),R=ge(null),E=ge(null),z=ge(null),F=ge(new Fn),H=ge(null),D=ge(null),B=ge(null),U=ge(!!y),W=ge(0),q=ge(()=>{}),G=ge(null),Q=ge(0),_=ge($?.version??""),J=ge(null),[Y,Z]=we({page:m.page}),[ee,te]=we(()=>({headers:{default:m.headers.default.html,first:m.headers.first.html,even:m.headers.even.html},footers:{default:m.footers.default.html,first:m.footers.first.html,even:m.footers.even.html},titlePage:m.titlePage,evenOdd:m.evenOdd})),[ne,re]=we(!1),[oe,ae]=we(m.columns),[ie,le]=we(!1),se=ge(new Map),[ce,de]=we(""),[ue,Oe]=we(null),[je,He]=we(null),De=ge(null),Ie=ge(null),[Be,We]=we(!1),[qe,Ke]=we([]),[,Ge]=we(0),Ve=ge(null),[Xe,Qe]=we(null),[_e,Je]=we(Sr),[Ze,et]=we({undo:!1,redo:!1}),[tt,nt]=we({words:0,pageNow:1}),[rt,ot]=we([0]),[at,it]=we([]),[lt,st]=we(!1),[ct,dt]=we(100),[ut,mt]=we(!1),[ft,pt]=we(!0),[ht,gt]=we(!1),[wt,bt]=we({rows:0,cols:0}),[yt,vt]=we(null),[xt,kt]=we(null),[Ct,St]=we(!1),[Nt,$t]=we(""),[At,Lt]=we(""),[Pt,Tt]=we(!1),[Mt,Rt]=we(0),[Et,zt]=we(0),Ft=ge([]),Ot=(Y.page.width-Y.page.left-Y.page.right)/20,jt=e=>!!e&&!!E.current?.contains(e),Ht=me(()=>{const e=E.current,t=document.getSelection();if(!(e&&t?.anchorNode&&t.focusNode&&jt(t.anchorNode))){const t=H.current;if(!e||!t)return null;const n=On(e,t.startContainer,t.startOffset),r=On(e,t.endContainer,t.endOffset);return n&&r?{anchor:n,focus:r}:null}const n=On(e,t.anchorNode,t.anchorOffset),r=On(e,t.focusNode,t.focusOffset);return n&&r?{anchor:n,focus:r}:null},[]),Dt=me(e=>{const t=E.current,n=document.getSelection();if(!t||!n||!e)return;const r=jn(t,e.anchor),o=jn(t,e.focus);r&&o&&n.setBaseAndExtent(r.node,r.offset,o.node,o.offset)},[]),It=me(e=>{const t=E.current;if(!t)return;const n=document.getSelection(),r=!e&&!!n&&jt(n.anchorNode);if(document.activeElement!==t&&t.focus({preventScroll:!0}),r&&n?.rangeCount)return void(H.current=n.getRangeAt(0).cloneRange());const o=e??H.current;n&&o&&(n.removeAllRanges(),n.addRange(o),H.current=o.cloneRange())},[]),Bt=me(()=>{const e=E.current,t=H.current;if(!e||!t)return[];const n=Array.from(e.querySelectorAll(kr)).filter(e=>!e.closest("[data-locked]"));var r;return(t.collapsed?[(r=t.startContainer,(1===r.nodeType?r:r.parentElement)?.closest(kr))].filter(Boolean):n.filter(e=>t.intersectsNode(e))).filter(e=>jt(e)&&!e.closest("[data-locked]"))},[]),Ut=me(()=>{cancelAnimationFrame(W.current),W.current=requestAnimationFrame(()=>{const n=E.current;if(!n)return;const o=n.getBoundingClientRect().height/(n.offsetHeight||1)||1,i=n.getBoundingClientRect().top+Y.page.top/20*(4/3)*o,l=(Y.page.height-Y.page.top-Y.page.bottom)/20*(4/3),s=a(r(n,i,o),l);ot(e=>e.length===s.length&&e.every((e,t)=>e===s[t])?e:s);const c=document.getSelection();let d=1;if(c?.rangeCount&&jt(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)}}nt({words:e(t(n)),pageNow:d});const u=[...new Set(Array.from(n.querySelectorAll("[data-note]")).map(e=>e.getAttribute("data-note")))];Ke(e=>e.length===u.length&&e.every((e,t)=>e===u[t])?e:u),le(!!n.querySelector(":scope > [data-section]"));const m=function(e){return Hn(e).map(e=>({level:Number(e.tagName[1]),text:(e.textContent??"").trim().replace(/\s+/g," ")}))}(n);it(e=>{return n=m,(t=e).length===n.length&&t.every((e,t)=>e.level===n[t].level&&e.text===n[t].text)?e:m;var t,n})})},[Y.page]),Wt=me(()=>{const e=document.getSelection();if(!e?.anchorNode||!jt(e.anchorNode))return;const t=1===e.anchorNode.nodeType?e.anchorNode:e.anchorNode.parentElement;if(!t)return;const n=getComputedStyle(t),r=t.closest(kr),o=e=>{try{return document.queryCommandState(e)}catch{return!1}},a=n.textAlign,i=.75*parseFloat(n.fontSize);if(Je({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:Un(n.color)}),r&&!r.closest("[data-locked]")){const e=getComputedStyle(r),t="LI"===r.tagName;He({indentLeft:t?0:vr(e.marginLeft),indentRight:vr(e.marginRight),firstLine:t?0:vr(e.textIndent),tabs:I(r.getAttribute("data-tabs"))})}else He(null)},[]),qt=async()=>{const e=G.current;if(!e)throw new Error("No page");if(!U.current&&Y.page===m.page&&m.source)return m.source;const t=Q.current,n=await Kt(m,e,{page:Y.page,headers:ee.headers,footers:ee.footers,titlePage:ee.titlePage,evenOdd:ee.evenOdd,columns:oe,styleEdits:se.current,images:p});return U.current&&Q.current===t&&(m.source=n,U.current=!1,Z(e=>({...e,page:m.page}))),n},Gt=ve(),Vt=ye({debounceMs:1500,maxWaitMs:4e3,save:async()=>{$&&(_.current=await $.store.save($.id,await qt(),_.current))},onFailure:(e,t)=>{e instanceof c?(Vt.stop(),st(!0)):0===t&&ze.error(P.saveFailed)}}),{push:Xt,flush:Qt}=Vt,_t=!!$,Jt=Vt.state.pending;fe(()=>{_t&&k(Jt||lt)},[lt,_t,k,Jt]),fe(()=>()=>{Qt()},[Qt]);const Yt=me(()=>{U.current=!0,Q.current+=1,k(!0),_t&&Xt(Q.current),Ut(),et({undo:F.current.canUndo,redo:F.current.canRedo})},[_t,Ut,k,Xt]),Zt=me(()=>({html:E.current?.innerHTML??"",caret:Ht()}),[Ht]),en=()=>{D.current&&clearTimeout(D.current),D.current=null},tn=me(e=>{e&&E.current&&(E.current.innerHTML=e.html,E.current.focus({preventScroll:!0}),Dt(e.caret),en(),Yt(),Wt())},[Dt,Yt,Wt]),nn=me(()=>tn(F.current.undo(Zt())),[tn,Zt]),on=me(()=>tn(F.current.redo(Zt())),[tn,Zt]),an=me(e=>{It(),en(),F.current.record(Zt()),e(),Yt(),Wt()},[Yt,Wt,It,Zt]),ln=me((e,t)=>an(()=>{document.execCommand(e,!1,t)}),[an]),sn=e=>an(()=>{document.execCommand(e);const t=E.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)});fe(()=>{const e=E.current;if(!e)return;G.current=e,e.innerHTML=m.html,br(A.filter(e=>m.html.includes(e)||m.css.includes(e)||m.defaultFont===e));try{document.execCommand("defaultParagraphSeparator",!1,"p"),document.execCommand("styleWithCSS",!1,"true")}catch{}e.focus({preventScroll:!0});const t=e.querySelector(kr);t&&document.getSelection()?.collapse(t,0),Ut();const n=t=>"historyUndo"===t.inputType?(t.preventDefault(),void nn()):"historyRedo"===t.inputType?(t.preventDefault(),void on()):(D.current?clearTimeout(D.current):F.current.record({html:e.innerHTML,caret:Ht()}),void(D.current=setTimeout(()=>{D.current=null},600))),r=()=>{(()=>{const t=B.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)})})(),Yt(),Wt()},o=()=>{const e=document.getSelection();e?.rangeCount&&jt(e.anchorNode)&&(H.current=e.getRangeAt(0).cloneRange(),Wt(),Ut())};e.addEventListener("beforeinput",n),e.addEventListener("input",r),document.addEventListener("selectionchange",o);const a=new ResizeObserver(()=>Ut());return a.observe(e),()=>{e.removeEventListener("beforeinput",n),e.removeEventListener("input",r),document.removeEventListener("selectionchange",o),a.disconnect(),cancelAnimationFrame(W.current),en(),J.current&&clearTimeout(J.current)}},[]),fe(()=>{Ut()},[Ut]),fe(()=>{const e=Ve.current;e&&qe.includes(e)&&(Ve.current=null,R.current?.querySelector(`input[data-note-input="${e}"]`)?.focus())},[qe]),fe(()=>{y&&k(!0)},[]);const cn=e=>an(()=>{const t=Ht(),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 Bt()){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")}Dt(t)}),dn=(e,t)=>an(()=>{for(const n of Bt())n.style["before"===e?"marginTop":"marginBottom"]=t?"10pt":"0pt"}),un=()=>{const e=Bt()[0];if(!e)return{};const t=getComputedStyle(e),n=parseFloat(t.fontSize)||14.67,r=parseFloat(t.lineHeight);return{before:vr(t.marginTop),after:vr(t.marginBottom),lineMultiple:Number.isFinite(r)?Math.round(r/n*100)/100:1.15,indentLeft:"LI"===e.tagName?void 0:vr(t.marginLeft),indentRight:vr(t.marginRight),firstLine:"LI"===e.tagName?void 0:vr(t.textIndent)}},mn=()=>{const e=Ie.current,t=document.getSelection();e&&t&&!t.isCollapsed&&jt(t.anchorNode)&&(Ie.current=null,We(!1),H.current=t.getRangeAt(0).cloneRange(),an(()=>{const t=(e,t)=>{!!t!==(e=>{try{return document.queryCommandState(e)}catch{return!1}})(e)&&document.execCommand(e)};t("bold",e.run.b),t("italic",e.run.i),t("underline",e.run.u),t("strikeThrough",e.run.strike),e.run.font&&document.execCommand("fontName",!1,e.run.font),e.run.color&&document.execCommand("foreColor",!1,e.run.color),document.execCommand("hiliteColor",!1,e.run.hl||"transparent"),e.run.size&&(document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7"),document.execCommand("styleWithCSS",!1,"true"),E.current?.querySelectorAll('font[size="7"]').forEach(t=>{const n=document.createElement("span");for(n.setAttribute("style",`font-size:${e.run.size}pt`);t.firstChild;)n.appendChild(t.firstChild);t.replaceWith(n)}));for(const t of Bt())"LI"!==t.tagName&&(e.styleId?t.setAttribute("data-pstyle",e.styleId):t.removeAttribute("data-pstyle"))}))},fn=e=>{br([e]),ln("fontName",e)},pn=e=>an(()=>{const t=E.current,n=Bt()[0];if(!t||!n)return;const r=Array.from(t.children).find(e=>e.contains(n));if(!r)return;r.setAttribute("data-section",e);const o=document.createElement("p");o.innerHTML="<br>",r.after(o),document.getSelection()?.collapse(o,0)}),hn=e=>{let t=e.getAttribute("data-bm");return t||(t=`_Toc${Math.floor(1e8+899999999*Math.random())}`,e.setAttribute("data-bm",t)),t},wn=()=>{const e=E.current;if(!e)return"";const t=e.getBoundingClientRect().height/(e.offsetHeight||1)||1,n=e.getBoundingClientRect().top+Y.page.top/20*(4/3)*t;return Hn(e).filter(e=>Number(e.tagName[1])<=3&&!e.closest("[data-toc]")).map(e=>{const r=(e.getBoundingClientRect().top-n)/t;let o=1;for(let e=0;e<rt.length;e++)rt[e]<=r+1&&(o=e+1);return v(Number(e.tagName[1]),hn(e),(e.textContent??"").trim(),String(o))}).join("")},bn=()=>{const e=[...m.footnotes.keys(),...qe].map(Number).filter(Number.isFinite),t=String(Math.max(0,...e)+1);m.footnotes.set(t,{text:"",editable:!0}),Ve.current=t,ln("insertHTML",`<span data-kind="note" data-note="${t}" contenteditable="false"></span>`)},yn=()=>Array.from(E.current?.querySelectorAll("[data-bookmark]")??[]).map(e=>e.getAttribute("data-bookmark")),vn=(e,t)=>{It();const n=H.current;if(n&&!n.collapsed)ln("createLink",`#${e}`);else{const n=document.createElement("a");n.href=`#${e}`,n.textContent=t,ln("insertHTML",n.outerHTML)}},xn=e=>{const t=E.current;return t&&/^[A-Za-z0-9_]+$/.test(e)?t.querySelector(`[data-bm="${e}"],[data-bookmark="${e}"],[data-toc-anchor="${e}"]`):null},kn=e=>an(()=>{const t=Bt(),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?Zn(t):er(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`:""}}),Nn=e=>ln({left:"justifyLeft",center:"justifyCenter",right:"justifyRight",justify:"justifyFull"}[e]),$n=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}));S(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||Ot,Ot),i=o?a*(r.naturalHeight/r.naturalWidth):0;ln("insertHTML",`<img src="${n}" alt="" style="width:${Math.round(100*a)/100}pt${i?`;height:${Math.round(100*i)/100}pt`:""}">`)}},An=async()=>{It();const e=H.current?.cloneRange()??null,t=e?.startContainer?1===e.startContainer.nodeType?e.startContainer:e.startContainer.parentElement:null,n=t?.closest("a")??null,r=await Re({title:P.link,message:P.linkPrompt,placeholder:"https://example.com",defaultValue:n?.getAttribute("href")??"",confirmLabel:P.ok,cancelLabel:P.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&&ln("unlink"));const a=/^[a-z][a-z0-9+.-]*:/i.test(o)?o:`https://${o}`;if(Cr.test(a))if(n)an(()=>{n.setAttribute("href",a)});else if(e?.collapsed){const e=document.createElement("a");e.href=a,e.textContent=o,ln("insertHTML",e.outerHTML)}else ln("createLink",a);else ze.error(P.linkInvalid)},Ln=()=>ln("insertHTML",'<span data-page-break="" contenteditable="false"></span>'),Pn=(e,t)=>{gt(!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(ar(e));i.appendChild(t)}return o.appendChild(i),o}(document,e,t,Ot);n.setAttribute("data-new",""),ln("insertHTML",`${n.outerHTML}<p><br></p>`);const r=E.current?.querySelector("table[data-new]");if(r){r.removeAttribute("data-new");const e=r.querySelector("td p");e&&document.getSelection()?.collapse(e,0)}};q.current=e=>{$n(e)};const Tn=e=>{if(!yt)return;const t=yt.el;an(()=>{const n=.75*t.naturalWidth,r=null===e?n:Ot*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"}),vt(null)},Mn=me((e,t)=>{const n=Ft.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"})},[]),Rn=()=>{const e=globalThis.CSS?.highlights;e?.delete("docs-find"),e?.delete("docs-find-current")},En=me((e,t,r)=>{const o=E.current,a=o?n(o,e,t):[];Ft.current=a,zt(a.length);const i=a.length?Math.min(r,a.length-1):0;Rt(i),Mn(i,!0)},[Mn]),Wn=me(()=>{const e=Ft.current[Mt];St(!1),Rn();const t=E.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),Ft.current=[]},[Mt]),qn=()=>{const e=document.getSelection(),t=e&&jt(e.anchorNode)?e.toString():"";St(!0);const n=t&&!t.includes("\n")?t:Nt;$t(n),setTimeout(()=>En(n,Pt,0),0)},Kn=ge(Wn);Kn.current=Wn;const Gn=ge(Ct);Gn.current=Ct,fe(()=>Ee(()=>!(!Gn.current||!R.current?.contains(document.activeElement))&&(Kn.current(),!0)),[]),fe(()=>()=>Rn(),[]),fe(()=>{const e=e=>{const{key:t,files:n}=e.detail;t===d&&q.current(n)};return window.addEventListener("docs-insert-images",e),()=>window.removeEventListener("docs-insert-images",e)},[d]);const Vn=$?f:(e=>e.replace(/\.[^.]+$/,"")||e)(f),Xn=`${Vn}.docx`,Qn=async()=>{try{const e=Q.current;Sn(await qt(),Xn,"application/vnd.openxmlformats-officedocument.wordprocessingml.document"),$||Q.current!==e||k(!1)}catch{ze.error(P.saveFailed)}},_n=e=>o({title:Vn,html:e,doc:{css:`${m.css}\n${ce}`},scope:M,page:Y.page,header:g(ee.headers.default),footer:g(ee.footers.default)}),Yn=()=>{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(_n(E.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()},gr=w.length?[...w,{type:"divider",key:"d1"},{key:"save",label:dr($r,{label:P.saveDocx,hint:"⌘S"}),onSelect:()=>{Qn()}}]:[],Nr=[{key:"docx",label:P.saveAsWord,onSelect:()=>{Qn()}},{key:"pdf",label:P.saveAsPdf,onSelect:Yn},{key:"html",label:P.saveAsWeb,onSelect:()=>{(async()=>{const e=document.createElement("div");e.innerHTML=E.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()),Sn(_n(e.innerHTML),`${Vn}.html`,"text/html")})()}},{key:"txt",label:P.saveAsText,onSelect:()=>{Sn(t(E.current),`${Vn}.txt`,"text/plain")}}],Ar=E.current?yn():[],Lr=[{key:"table",label:P.table,onSelect:()=>gt(!0)},{key:"image",label:P.image,onSelect:()=>z.current?.click()},{key:"link",label:dr($r,{label:P.link,hint:"⌘K"}),onSelect:()=>{An()}},{type:"submenu",key:"linkHeading",label:P.linkToHeading,items:at.length?at.map((e,t)=>({key:`h${t}`,label:dr("span",{style:{paddingLeft:8*(e.level-1)},children:e.text}),onSelect:()=>(e=>{const t=E.current,n=t?Hn(t)[e]:void 0;if(!n)return;It();const r=H.current?.cloneRange()??null;F.current.record(Zt());const o=hn(n);It(r),vn(o,(n.textContent??"").trim())})(t)})):[{type:"label",key:"none",label:P.noHeadings}]},{type:"submenu",key:"linkBookmark",label:P.linkToBookmark,items:Ar.length?Ar.map(e=>({key:e,label:e,onSelect:()=>vn(e,e)})):[{type:"label",key:"none",label:P.noBookmarks}]},{type:"divider",key:"d1"},{key:"toc",label:P.tableOfContents,onSelect:()=>{It();const e=wn();ln("insertHTML",`<div data-toc="" contenteditable="false">${e}</div><p><br></p>`)}},{key:"footnote",label:dr($r,{label:P.footnote,hint:"⌘⌥F"}),onSelect:bn},{key:"bookmark",label:P.bookmark,onSelect:()=>{(async()=>{It();const e=H.current?.cloneRange()??null,t=await Re({title:P.bookmark,message:P.bookmarkPrompt,placeholder:"Clause_4",confirmLabel:P.ok,cancelLabel:P.cancel});if(await new Promise(e=>setTimeout(e,0)),It(e),null===t)return;const n=t.trim();hr.test(n)?yn().includes(n)?ze.error(P.bookmarkTaken):ln("insertHTML",`<span data-kind="mark" data-bookmark="${n}" contenteditable="false"></span>`):ze.error(P.bookmarkInvalid)})()}},{type:"submenu",key:"breaks",label:P.breakMenu,items:[{key:"page",label:dr($r,{label:P.pageBreak,hint:"⌘↵"}),onSelect:Ln},{key:"next",label:P.sectionBreakNext,onSelect:()=>pn("nextPage")},{key:"cont",label:P.sectionBreakContinuous,onSelect:()=>pn("continuous")}]},{key:"number",label:P.pageNumber,onSelect:()=>re(!0)},{key:"line",label:P.horizontalLine,onSelect:()=>ln("insertHorizontalRule")}],Pr=(()=>{const e=E.current,t=H.current?1===H.current.startContainer.nodeType?H.current.startContainer:H.current.startContainer.parentElement:null;return e&&t?Array.from(e.children).find(e=>e.contains(t))??null:null})(),Tr=[{key:"setup",label:P.pageSetup,onSelect:()=>mt(!0)},{key:"hf",label:P.headersFooters,onSelect:()=>re(!0)},{type:"submenu",key:"cols",label:P.columns,items:[1,2,3].map(e=>({key:String(e),label:P.columnsCount(e),onSelect:()=>(e=>{const t=E.current,n=Bt()[0];if(!t)return;let r=n?Array.from(t.children).find(e=>e.contains(n))??null:null;for(;r&&!r.hasAttribute("data-section");)r=r.nextElementSibling;r?an(()=>{e>1?r.setAttribute("data-cols",String(e)):r.removeAttribute("data-cols")}):(ae(e),Yt())})(e)}))},...Pr?.hasAttribute("data-section")?[{key:"unsection",label:P.removeSectionBreak,onSelect:()=>{return e=Pr,an(()=>{e.removeAttribute("data-section"),e.removeAttribute("data-cols")});var e}}]:[]],Mr={Title:P.styleTitle,"heading 1":P.styleHeading1,"heading 2":P.styleHeading2,"heading 3":P.styleHeading3,"heading 4":P.styleHeading4,"heading 5":P.styleHeading5,"heading 6":P.styleHeading6,Quote:P.styleQuote},Rr=[{key:"normal",label:P.styleNormal,onSelect:()=>cn(null)},...m.styles.map(e=>{const t=Mr[e.name]??e.name;return{type:"submenu",key:e.id,label:t,items:[{key:"apply",label:P.applyStyle(t),onSelect:()=>cn(e.id)},{key:"update",label:P.updateStyle(t),onSelect:()=>((e,t)=>an(()=>{const n=Bt()[0];if(!n)return;const r=Array.from(n.querySelectorAll("*")).find(e=>(e.textContent??"").trim()&&!e.querySelector("*"))??n,o=getComputedStyle(r),a=getComputedStyle(n),i=parseFloat(o.fontSize)||14.67,l=parseFloat(a.lineHeight),s={b:Number(o.fontWeight)>=600,i:"italic"===o.fontStyle,u:/underline/.test(o.textDecorationLine),strike:/line-through/.test(o.textDecorationLine),font:o.fontFamily.split(",")[0].replace(/["']/g,"").trim(),size:Math.round(.75*i*2)/2,color:Un(o.color)||void 0},c=a.textAlign,d={align:"center"===c||"right"===c||"justify"===c?c:"left",before:vr(a.marginTop),after:vr(a.marginBottom),...Number.isFinite(l)?{lineMultiple:Math.round(l/(parseFloat(a.fontSize)||i)*100)/100}:{}};se.current.set(e,{run:s,para:d});const u=n.style.tabSize;n.removeAttribute("style"),u&&(n.style.tabSize=u),n.querySelectorAll("[style]").forEach(e=>{for(const t of["font-family","font-size","font-weight","font-style","color","text-decoration","text-decoration-line"])e.style.removeProperty(t)}),de([...se.current].map(([e,t])=>`.docs-page [data-pstyle="${e.replace(/["\\]/g,"")}"]{${[K(t.run),j(t.para)].filter(Boolean).join(";")}}`).join("\n")),br(s.font?[s.font]:[]),ze.success(P.styleUpdated(t))}))(e.id,t)}]}})],Er=he(()=>Array.from(new Set([...m.defaultFont?[m.defaultFont]:[],...mr])),[m.defaultFont]),zr=[{type:"label",key:"word",label:P.wordFonts},...Er.map(e=>({key:e,label:dr("span",{style:{fontFamily:`"${e}"`},children:e}),onSelect:()=>fn(e)})),{type:"label",key:"web",label:P.webFonts},...A.filter(e=>!Er.includes(e)).map(e=>({key:e,label:dr("span",{style:{fontFamily:`"${e}"`},children:e}),onSelect:()=>fn(e)}))],Fr=fr.map(e=>({key:String(e),label:String(e),onSelect:()=>(e=>an(()=>{B.current=e,document.execCommand("styleWithCSS",!1,"false"),document.execCommand("fontSize",!1,"7"),document.execCommand("styleWithCSS",!1,"true");const t=E.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)})),Or=E.current&&H.current?un():{},jr=[...pr.map(e=>({key:String(e),label:e.toFixed(1.15===e?2:1),onSelect:()=>{return t=e,an(()=>{for(const e of Bt())e.style.lineHeight=String(t)});var t}})),{type:"divider",key:"d1"},(Or.before??0)>0?{key:"before",label:P.removeSpaceBefore,onSelect:()=>dn("before",!1)}:{key:"before",label:P.addSpaceBefore,onSelect:()=>dn("before",!0)},(Or.after??0)>0?{key:"after",label:P.removeSpaceAfter,onSelect:()=>dn("after",!1)}:{key:"after",label:P.addSpaceAfter,onSelect:()=>dn("after",!0)},{type:"divider",key:"d2"},{key:"custom",label:P.customSpacing,onSelect:()=>{It(),Oe(un())}}],Hr=e=>e.preventDefault(),Dr="rounded px-2 py-0.5 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",Ir="inline-flex h-7 items-center gap-1 rounded px-2 text-xs text-ink-muted hover:bg-line-subtle hover:text-ink",Br=dr("div",{className:"mx-1 h-4 w-px bg-line"}),Ur=(e,t,n,r={})=>dr($e,{"aria-label":e,title:e,size:"sm",variant:"ghost",onMouseDown:Hr,onClick:n,disabled:r.disabled,...void 0!==r.pressed?{"aria-pressed":r.pressed}:{},children:t}),Wr=(e,t,n,r="")=>dr(Ne,{"aria-label":e,align:"start",items:n,triggerClassName:Ir,trigger:ur("span",{title:e,className:`flex items-center justify-between gap-1 ${r}`,children:[dr("span",{className:"truncate",children:t}),dr(xe,{name:"chevron-down",size:12})]})}),qr=(e,t,n,r,o)=>dr(Ae,{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:ur(cr,{children:[t,dr("span",{className:"h-0.5 w-4 rounded-sm",style:{background:n}})]}),children:({close:t})=>dr(Ce,{label:e,value:"",presets:r,clearable:!0,dragWrites:"end",onChange:e=>{"hiliteColor"===o?ln("hiliteColor",e||"transparent"):ln("foreColor",e||Dn[0]),Gr(t=>({...t,[o]:e||("hiliteColor"===o?"var(--line)":"var(--ink)")})),t()}})}),[Kr,Gr]=we({foreColor:"var(--ink)",hiliteColor:"var(--line)"}),Vr=O(Y.page),Xr=Vr?{a4:"A4",a3:"A3",a5:"A5",letter:P.paperLetter,legal:P.paperLegal}[Vr]:P.custom,Qr=he(()=>{if(!m.lang)return"";try{return new Intl.DisplayNames(T?[T]:void 0,{type:"language"}).of(m.lang)??m.lang}catch{return m.lang}},[m.lang,T]),_r=Y.page.width/20,Jr=Y.page.top/20,Yr=rt.length,Zr=ee.headers[h(1,ee.titlePage,ee.evenOdd)],eo=ee.footers[h(Yr,ee.titlePage,ee.evenOdd)],to=[`.docs-page [data-section="nextPage"]::after{content:${JSON.stringify(P.sectionBreakNext)}}`,`.docs-page [data-section="continuous"]::after{content:${JSON.stringify(P.sectionBreakContinuous)}}`,...[2,3].map(e=>`.docs-page [data-section][data-cols="${e}"]::after{content:${JSON.stringify(`${P.sectionBreakNext} · ${P.columnsCount(e)}`)}}`),`.docs-page [data-section="continuous"][data-cols]::after{content:${JSON.stringify(P.sectionBreakContinuous)}}`,`.docs-page [data-toc]:empty::before{content:${JSON.stringify(P.noHeadings)}}`,ce].join("\n").replaceAll(".docs-page",`.docs-page[data-doc="${M}"]`),no=m.notices,ro=[no.comments&&P.noticeComments(no.comments),no.tracked&&P.noticeTracked(no.tracked),no.objects&&P.noticeObjects(no.objects),no.footnotes&&P.noticeFootnotes(no.footnotes)].filter(Boolean);return ur("div",{ref:R,className:"es-editor docs-frame",onKeyDown:e=>{const t=e.metaKey||e.ctrlKey,n=e.key.toLowerCase(),r=jt(e.target),o=()=>{e.preventDefault(),e.stopPropagation()};if(t&&!e.altKey){if("s"===n)return o(),void($?Qt():Qn());if("o"===n)return o(),void C();if("p"===n)return o(),void Yn();if("f"===n)return o(),void qn();if("k"===n)return o(),void An()}if(t&&e.altKey&&("f"===n||"KeyF"===e.code)&&r)return o(),void bn();if(t&&!e.altKey&&r){if("z"===n&&!e.shiftKey)return o(),void nn();if("z"===n&&e.shiftKey||"y"===n)return o(),void on();if("b"===n)return o(),void ln("bold");if("i"===n)return o(),void ln("italic");if("u"===n)return o(),void ln("underline");if("Enter"===e.key)return o(),void Ln()}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&&an(()=>ir(e.closest("table"),e,!0))})(r,!e.shiftKey);if(n?.closest("li"))return o(),void kn(!e.shiftKey);if(!e.shiftKey)return o(),void ln("insertText","\t")}},children:[ur("style",{children:[i(m,M),to]}),dr("input",{ref:z,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files?.length&&$n(Array.from(e.target.files)),e.target.value=""}}),dr(Ye,{onClose:N,fileMenu:gr,name:b,saveState:$?be(Vt.state,Gt.save):{tone:x?"off-unsaved":"off",label:x?P.noStoreEdited:P.noStoreClean},canUndo:Ze.undo,canRedo:Ze.redo,onUndo:nn,onRedo:on,exportControl:dr(Ne,{"aria-label":P.export,align:"end",items:Nr,triggerClassName:"docs-export-trigger",trigger:ur(cr,{children:[dr(xe,{name:"download",size:16}),P.export]})})}),lt&&ur("div",{className:"docs-conflict",role:"alert",children:[dr("span",{children:P.conflict}),dr(ke,{variant:"secondary",onClick:L,children:P.reload})]}),ur("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1",children:[dr(Ne,{trigger:P.menuInsert,items:Lr,align:"start",triggerClassName:Dr}),dr(Ae,{open:ht,onOpenChange:gt,align:"start",triggerLabel:P.table,triggerClassName:"h-5 w-0 overflow-hidden",trigger:dr("span",{}),children:ur("div",{className:"p-1",children:[dr("div",{className:"mb-1 text-xs text-ink-muted",children:wt.rows?P.tableSize(wt.cols,wt.rows):P.table}),dr("div",{className:"grid gap-0.5",style:{gridTemplateColumns:"repeat(8, 1fr)"},onMouseLeave:()=>bt({rows:0,cols:0}),children:Array.from({length:48},(e,t)=>{const n=Math.floor(t/8)+1,r=t%8+1,o=n<=wt.rows&&r<=wt.cols;return dr("button",{type:"button","aria-label":P.tableSize(r,n),onMouseEnter:()=>bt({rows:n,cols:r}),onFocus:()=>bt({rows:n,cols:r}),onClick:()=>Pn(n,r),className:"h-4 w-4 rounded-sm border "+(o?"border-accent-fill bg-accent-tint-strong":"border-line bg-surface")},t)})})]})}),dr(Ne,{trigger:P.menuLayout,items:Tr,align:"start",triggerClassName:Dr}),Br,Ur(P.print,dr(xe,{name:"print",size:16}),Yn),Ur(P.find,dr(xe,{name:"search",size:16}),()=>Ct?Wn():qn(),{pressed:Ct}),Br,Wr(P.paragraphStyle,(e=>{if(!e)return P.styleNormal;const t=m.styles.find(t=>t.id===e);return t?Mr[t.name]??t.name:e})(_e.styleId),Rr,"w-20"),Wr(P.font,_e.font||m.defaultFont||"Calibri",zr,"w-20"),Wr(P.fontSize,_e.size??m.defaultSize??11,Fr),Br,Ur(P.bold,dr(xe,{name:"bold",size:16}),()=>ln("bold"),{pressed:_e.bold}),Ur(P.italic,dr(xe,{name:"italic",size:16}),()=>ln("italic"),{pressed:_e.italic}),Ur(P.underline,dr(xe,{name:"underline",size:16}),()=>ln("underline"),{pressed:_e.underline}),Ur(P.strikethrough,dr(xe,{name:"strike",size:16}),()=>ln("strikeThrough"),{pressed:_e.strike}),Ur(P.superscript,dr(xe,{name:"superscript",size:16}),()=>ln("superscript"),{pressed:_e.sup}),Ur(P.subscript,dr(xe,{name:"subscript",size:16}),()=>ln("subscript"),{pressed:_e.sub}),qr(P.textColor,dr(xe,{name:"text-color",size:14}),Kr.foreColor,Dn,"foreColor"),qr(P.highlight,dr(xe,{name:"palette",size:14}),Kr.hiliteColor,In,"hiliteColor"),Ur(P.paintFormat,dr(xe,{name:"paint-brush",size:16}),()=>{if(Ie.current)return Ie.current=null,void We(!1);It(),Ie.current=(()=>{const e=document.getSelection();if(!e?.anchorNode||!jt(e.anchorNode))return null;const t=1===e.anchorNode.nodeType?e.anchorNode:e.anchorNode.parentElement,n=getComputedStyle(t),r=t.closest(kr),o=e=>{try{return document.queryCommandState(e)}catch{return!1}};return{run:{b:o("bold"),i:o("italic"),u:o("underline"),strike:o("strikeThrough"),font:n.fontFamily.split(",")[0].replace(/["']/g,"").trim(),size:Math.round(.75*parseFloat(n.fontSize)*2)/2,color:Un(n.color),hl:Un(n.backgroundColor)||void 0},styleId:r?.getAttribute("data-pstyle")??null,tag:r?.tagName??"P"}})(),We(!!Ie.current),Ie.current&&ze.info(P.paintFormatHint)},{pressed:Be}),Ur(P.clearFormatting,dr(xe,{name:"clear-marks",size:16}),()=>an(()=>{document.execCommand("removeFormat");for(const e of Bt())e.style.removeProperty("text-align"),e.style.removeProperty("line-height"),e.style.removeProperty("margin-left")})),Br,Ur(P.bulletedList,dr(xe,{name:"list",size:16}),()=>sn("insertUnorderedList"),{pressed:_e.ul}),Ur(P.numberedList,dr(xe,{name:"numbered-list",size:16}),()=>sn("insertOrderedList"),{pressed:_e.ol}),Ur(P.checklist,dr(xe,{name:"checkbox",size:16}),()=>an(()=>{const e=E.current;if(!e)return;const t=Bt(),n=t.length>0&&t.every(e=>e.closest("ul[data-checklist]")),r=document.getSelection(),o=r?.anchorNode??null,a=r?.anchorOffset??0;if(n)document.execCommand("insertUnorderedList");else{const n=new Set(t.map(e=>e.closest("ul,ol")).filter(Boolean));n.size&&![...n].some(e=>"UL"!==e.tagName)||document.execCommand("insertUnorderedList");const r=(document.getSelection()?.anchorNode?.parentElement??o?.parentElement)?.closest("ul");e.querySelectorAll("p > ul").forEach(e=>{const t=e.parentElement;Array.from(t.childNodes).some(t=>t!==e&&(1===t.nodeType||(t.nodeValue??"").trim()))||t.replaceWith(e)});for(const e of[r,...n])e&&"UL"===e.tagName&&(e.setAttribute("data-checklist",""),e.removeAttribute("data-num-id"))}o&&o.isConnected&&r?.collapse(o,Math.min(a,3===o.nodeType?(o.nodeValue??"").length:o.childNodes.length))})),Ur(P.decreaseIndent,dr(xe,{name:"chevron-double-left",size:16}),()=>kn(!1)),Ur(P.increaseIndent,dr(xe,{name:"chevron-double-right",size:16}),()=>kn(!0)),Br,Ur(P.alignLeft,dr(xe,{name:"align-left",size:16}),()=>Nn("left"),{pressed:"left"===_e.align}),Ur(P.alignCenter,dr(xe,{name:"align-center",size:16}),()=>Nn("center"),{pressed:"center"===_e.align}),Ur(P.alignRight,dr(xe,{name:"align-right",size:16}),()=>Nn("right"),{pressed:"right"===_e.align}),Ur(P.justify,dr(xe,{name:"align-justify",size:16}),()=>Nn("justify"),{pressed:"justify"===_e.align}),dr(Ne,{"aria-label":P.paragraphSpacing,align:"start",items:jr,triggerClassName:Ir,trigger:ur("span",{title:P.paragraphSpacing,className:"flex items-center gap-0.5",children:[dr(xe,{name:"line-spacing",size:16}),dr(xe,{name:"chevron-down",size:12})]})})]}),ft&&ro.length>0&&ur("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:[dr(xe,{name:"info",size:14}),dr("span",{className:"min-w-0 flex-1",children:P.noticeLead(ro)}),dr($e,{size:"sm",variant:"ghost",ink:"inherit","aria-label":P.dismiss,title:P.dismiss,onClick:()=>pt(!1),children:dr(xe,{name:"close",size:14})})]}),Ct&&dr(zn,{query:Nt,replacement:At,matchCase:Pt,current:Mt,total:Et,onQuery:e=>{$t(e),En(e,Pt,0)},onReplacement:Lt,onMatchCase:e=>{Tt(e),En(Nt,e,0)},onStep:e=>{const t=Ft.current.length;if(!t)return;const n=(Mt+(e?1:-1)+t)%t;Rt(n),Mn(n,!0)},onReplace:()=>{const e=Ft.current[Mt];e&&(F.current.record(Zt()),l(e,At),Yt(),En(Nt,Pt,Mt))},onReplaceAll:()=>{const e=Ft.current;if(e.length){F.current.record(Zt());for(let t=e.length-1;t>=0;t--)l(e[t],At);Yt(),ze.success(P.replacedCount(e.length)),En(Nt,Pt,0)}},onClose:Wn}),ur("div",{className:"docs-body",children:[ur("div",{className:"docs-centre",children:[ur("div",{className:"min-h-0 flex-1 overflow-auto bg-surface-sunken px-6 pb-6",children:[dr("div",{className:"docs-ruler-row",children:dr(Cn,{pageWidth:_r,marginLeft:Y.page.left/20,marginRight:Y.page.right/20,zoom:ct,value:je,onChange:e=>{He(e),It(),De.current?clearTimeout(De.current):F.current.record(Zt()),De.current=setTimeout(()=>{De.current=null},500);for(const t of Bt()){"LI"!==t.tagName&&(t.style.marginLeft=e.indentLeft?`${e.indentLeft}pt`:"",t.style.textIndent=e.firstLine?`${e.firstLine}pt`:""),t.style.marginRight=e.indentRight?`${e.indentRight}pt`:"",e.tabs.length?t.setAttribute("data-tabs",X(e.tabs)):t.hasAttribute("data-tabs")&&t.setAttribute("data-tabs","");const n=V({indentLeft:e.indentLeft,tabs:e.tabs});t.style.tabSize=n?n.split(":")[1]:""}Yt()}})}),ur("div",{className:"docs-sheet relative mx-auto shadow",style:{width:`${_r}pt`,zoom:ct/100,minHeight:Y.page.height/20+"pt"},children:[dr("div",{ref:E,contentEditable:!0,suppressContentEditableWarning:!0,spellCheck:!0,lang:m.lang,role:"textbox","aria-multiline":"true","aria-label":f,"data-doc":M,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 ln("insertHTML",t.innerHTML)}t.length&&(e.preventDefault(),$n(t))})(e)},onMouseUp:mn,onKeyUp:e=>{e.shiftKey&&mn()},onClick:e=>{const t=e.target,n=t.closest("[data-toc]");if(n&&jt(n)){const r=t.closest("a"),o=r&&(e.metaKey||e.ctrlKey)?xn(r.getAttribute("data-anchor")??(r.getAttribute("href")??"").slice(1)):null;return o?void o.scrollIntoView({block:"start"}):void Qe({x:e.clientX,y:e.clientY,el:n})}if("LI"===t.tagName&&t.parentElement?.hasAttribute("data-checklist")&&e.nativeEvent.offsetX<0)return void an(()=>{t.toggleAttribute("data-checked")});if("IMG"===t.tagName&&null===t.closest('[contenteditable="false"]')&&!t.getAttribute("contenteditable"))return e.preventDefault(),void vt({x:e.clientX,y:e.clientY,el:t});const r=t.closest("a");if(r&&(e.metaKey||e.ctrlKey)){const e=r.getAttribute("href")??"";e.startsWith("#")?xn(e.slice(1))?.scrollIntoView({block:"start"}):Cr.test(e)&&window.open(e,"_blank","noopener,noreferrer")}},onContextMenu:e=>{const t=e.target.closest?.("td,th");t&&!e.shiftKey&&!t.closest("[data-locked]")&&jt(t)&&(e.preventDefault(),kt({x:e.clientX,y:e.clientY,cell:t}))},className:"docs-page",style:{paddingTop:`${Jr}pt`,paddingRight:Y.page.right/20+"pt",paddingBottom:Y.page.bottom/20+"pt",paddingLeft:Y.page.left/20+"pt",minHeight:Y.page.height/20+"pt",boxSizing:"border-box",...oe>1&&!ie?{columnCount:oe,columnGap:"36pt"}:{},...Be?{cursor:"copy"}:{}}}),dr("button",{type:"button",className:"docs-hf-preview docs-page","data-doc":M,title:P.headersFootersHint,"aria-label":P.headersFooters,onClick:()=>re(!0),"data-hint":P.headersFootersHint,style:{top:Y.page.header/20+"pt",left:Y.page.left/20+"pt",right:Y.page.right/20+"pt",minHeight:Math.max(Y.page.top-Y.page.header-120,240)/20+"pt",maxHeight:Math.max(Y.page.top-Y.page.header,240)/20+"pt"},dangerouslySetInnerHTML:{__html:yr(Zr,1,Yr)}}),qe.length>0&&dr("section",{className:"docs-footnotes","aria-label":P.footnotes,style:{marginLeft:Y.page.left/20+"pt",marginRight:Y.page.right/20+"pt",marginBottom:Y.page.bottom/20+"pt"},children:qe.map((e,t)=>{const n=m.footnotes.get(e);return ur("div",{className:"docs-footnote",children:[dr("sup",{children:t+1}),!1===n?.editable?dr("span",{title:P.footnoteLocked,children:n.text}):dr("input",{"data-note-input":e,value:n?.text??"",placeholder:P.footnotePlaceholder,"aria-label":`${P.footnote} ${t+1}`,onChange:t=>((e,t)=>{const n=m.footnotes.get(e);n?.editable&&(m.footnotes.set(e,{...n,text:t}),Ge(e=>e+1),Yt())})(e,t.target.value)})]},e)})}),rt.slice(1).map((e,t)=>dr("div",{className:"docs-sheet-line pointer-events-none absolute left-0 right-0 border-t border-dashed","aria-hidden":"true",style:{top:`calc(${Jr}pt + ${e}px)`},children:dr("span",{className:"docs-sheet absolute right-1 -top-2 px-1 text-2xs",children:P.pageLabel(t+2)})},e)),dr("button",{type:"button",className:"docs-hf-preview docs-page","data-doc":M,title:P.headersFootersHint,"aria-label":P.headersFooters,onClick:()=>re(!0),"data-hint":P.headersFootersHint,style:{bottom:Y.page.footer/20+"pt",left:Y.page.left/20+"pt",right:Y.page.right/20+"pt",minHeight:Math.max(Y.page.bottom-Y.page.footer-120,240)/20+"pt",maxHeight:Math.max(Y.page.bottom-Y.page.footer,240)/20+"pt"},dangerouslySetInnerHTML:{__html:yr(eo,Yr,Yr)}})]})]}),ur("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:[dr("span",{children:P.pageOf(Math.min(tt.pageNow,rt.length),rt.length)}),dr("span",{children:P.wordCount(tt.words)}),dr("span",{children:Xr}),Qr&&dr("span",{children:Qr}),ur("span",{className:"ml-auto flex items-center gap-1",children:[dr(ke,{size:"sm",variant:"ghost","aria-label":P.zoomOut,onClick:()=>dt(e=>[...xr].reverse().find(t=>t<e)??e),children:"−"}),ur("span",{className:"w-9 text-center tabular-nums",children:[ct,"%"]}),dr(ke,{size:"sm",variant:"ghost","aria-label":P.zoomIn,onClick:()=>dt(e=>xr.find(t=>t>e)??e),children:"+"})]})]})]}),dr(Ue,{page:Y.page,onPage:e=>{Z(t=>({...t,page:e})),Yt()},onMorePageSetup:()=>mt(!0),colour:_e.color,onColour:e=>{Je(t=>({...t,color:e})),Gr(t=>({...t,foreColor:e})),J.current&&clearTimeout(J.current),J.current=setTimeout(()=>{J.current=null,ln("foreColor",e)},150)},outline:at,onHeading:e=>{const t=E.current;t&&Hn(t)[e]?.scrollIntoView({block:"start"})}})]}),ut&&dr(Jn,{value:Y,onClose:()=>mt(!1),onApply:e=>{Z(e),mt(!1),Yt()}}),ne&&dr(rn,{value:ee,scope:M,locked:{headers:Object.fromEntries(wr.map(e=>[e,!m.headers[e].editable])),footers:Object.fromEntries(wr.map(e=>[e,!m.footers[e].editable]))},onClose:()=>re(!1),onApply:e=>{te(e),re(!1),Yt()}}),ue&&dr(gn,{value:ue,onClose:()=>Oe(null),onApply:e=>{var t;Oe(null),t=e,an(()=>{for(const e of Bt())void 0!==t.lineMultiple&&(e.style.lineHeight=String(t.lineMultiple)),void 0!==t.before&&(e.style.marginTop=`${t.before}pt`),void 0!==t.after&&(e.style.marginBottom=`${t.after}pt`),void 0!==t.indentRight&&(e.style.marginRight=t.indentRight?`${t.indentRight}pt`:""),"LI"!==e.tagName&&(void 0!==t.indentLeft&&(e.style.marginLeft=t.indentLeft?`${t.indentLeft}pt`:""),void 0!==t.firstLine&&(e.style.textIndent=t.firstLine?`${t.firstLine}pt`:""))})}}),Xe&&ur(Le,{minWidth:180,portal:!0,style:{position:"fixed",left:Xe.x,top:Xe.y},onClose:()=>Qe(null),children:[dr(Te,{onClick:()=>{var e;e=Xe.el,an(()=>{e.innerHTML=wn()}),Qe(null)},children:P.tocRefresh}),dr(Pe,{}),dr(Te,{danger:!0,onClick:()=>{const e=Xe.el;an(()=>{e.remove()}),Qe(null)},children:P.tocDelete})]}),yt&&ur(Le,{minWidth:150,portal:!0,style:{position:"fixed",left:yt.x,top:yt.y},onClose:()=>vt(null),children:[dr(Me,{children:P.imageWidth}),dr(Te,{onClick:()=>Tn(.25),children:"25%"}),dr(Te,{onClick:()=>Tn(.5),children:"50%"}),dr(Te,{onClick:()=>Tn(.75),children:"75%"}),dr(Te,{onClick:()=>Tn(1),children:"100%"}),dr(Te,{onClick:()=>Tn(null),children:P.imageOriginalSize}),dr(Pe,{}),dr(Te,{danger:!0,onClick:()=>{if(!yt)return;const e=yt.el;an(()=>{e.remove()}),vt(null)},children:P.imageRemove})]}),xt&&dr(Se,{at:{x:xt.x,y:xt.y},owner:xt.cell,onClose:()=>kt(null),items:(e=>{const t=e.closest("table"),n=(e,t,n,r={})=>({key:e,label:t,onSelect:()=>an(n),...r}),r=(e=>{const t=H.current;return t?Array.from(e.querySelectorAll("td,th")).filter(n=>n.closest("table")===e&&t.intersectsNode(n)):[]})(t);return[n("above",P.rowAbove,()=>ir(t,e,!1)),n("below",P.rowBelow,()=>ir(t,e,!0)),n("left",P.columnLeft,()=>lr(t,e,!1)),n("right",P.columnRight,()=>lr(t,e,!0)),{type:"divider",key:"d1"},n("merge",P.mergeCells,()=>{(function(e,t){if(t.length<2)return!1;const n=rr(e);let r=1/0,o=1/0,a=-1,i=-1;for(const e of t){const t=or(n,e);if(!t)return!1;r=Math.min(r,t.row),o=Math.min(o,t.col),a=Math.max(a,t.row+nr(e,"rowspan")-1),i=Math.max(i,t.col+nr(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=or(n,e);if(t.row<r||t.col<o||t.row+nr(e,"rowspan")-1>a||t.col+nr(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)||ze.error(P.mergeFailed)},{disabled:r.length<2}),{type:"submenu",key:"shade",label:P.cellShading,items:[...Bn.map(t=>({key:t,label:ur("span",{className:"flex items-center gap-2",children:[dr("span",{className:"h-3 w-5 rounded-sm border border-line",style:{background:t}}),t.toUpperCase()]}),onSelect:()=>an(()=>{for(const n of r.length?r:[e])n.style.backgroundColor=t})})),{key:"none",label:P.noColor,onSelect:()=>an(()=>{for(const t of r.length?r:[e])t.style.removeProperty("background-color")})}]},{type:"divider",key:"d2"},n("delRow",P.deleteRow,()=>{!function(e,t){const n=rr(e),r=or(n,t);if(!r)return!1;const o=tr(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=nr(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+nr(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",P.deleteColumn,()=>{!function(e,t){const n=rr(e),r=or(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=nr(t,"colspan");n>1?t.setAttribute("colspan",String(n-1)):t.remove()}sr(e,n.cols-1,null,r.col)}(t,e)}),n("delTable",P.deleteTable,()=>{t.remove()},{danger:!0})]})(xt.cell)})]})}function $r({label:e,hint:t}){return ur("span",{className:"flex w-full items-center justify-between gap-4",children:[dr("span",{children:e}),dr("span",{className:"text-2xs text-ink-faint",children:t})]})}import{useEffect as Ar,useRef as Lr,useState as Pr}from"react";import{Icon as Tr}from"efficient-shell/icons";import{Button as Mr,IconButton as Rr,registerModalEscapeInterceptor as Er,toast as zr}from"efficient-shell/ui";var Fr={LF:"\n",CRLF:"\r\n",CR:"\r"};function Or(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 jr(e){let t=1;for(let n=e.indexOf("\n");n>=0;n=e.indexOf("\n",n+1))t++;return t}import{jsx as Hr,jsxs as Dr}from"react/jsx-runtime";function Ir({filename:e,decoded:t,bytes:n,fileEntries:r,title:o,dirty:a,onDirty:i,onOpenFile:l,onClose:s}){const c=u(),d=Lr(null),m=Lr(null),f=Lr(t.text),p=Lr(!1),[h,g]=Pr(!0),[w,b]=Pr(!1),[y,v]=Pr({line:1,col:1,lines:jr(t.text)}),[x,k]=Pr(!1),[C,S]=Pr(""),[N,$]=Pr(""),[A,L]=Pr(!1),[P,T]=Pr(0),[M,R]=Pr([]),E=()=>m.current?.value??"",z=Lr(null),[F,O]=Pr(0),j=()=>{z.current&&m.current&&(z.current.scrollTop=m.current.scrollTop,z.current.scrollLeft=m.current.scrollLeft)};Ar(()=>{const e=z.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)),j()},[F,P,M,h]);const H=()=>{const e=m.current;e&&v({...Or(e.value,e.selectionStart),lines:jr(e.value)})},D=(e=C,t=A)=>{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}(E(),e,t);return R(n),n},I=(e,t,n=C)=>{const r=m.current;if(!r||!e.length)return;const o=(t%e.length+e.length)%e.length;T(o),r.setSelectionRange(e[o],e[o]+n.length),O(e=>e+1)},B=()=>{Sn(p.current?function(e,t,n){const r=e.replace(/\n/g,Fr[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}(E(),t.encoding,t.eol):n,e,"text/plain"),p.current&&"windows-1252"===t.encoding&&zr.info(c.savedAsUtf8),f.current=E(),i(!1)},U=()=>{p.current=!0,b(!0),i(E()!==f.current),H(),x&&D()},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=()=>{k(!1),m.current?.focus()};Ar(()=>{m.current?.focus(),m.current?.setSelectionRange(0,0)},[]);const G=Lr(x);G.current=x,Ar(()=>Er(()=>!(!G.current||!d.current?.contains(document.activeElement))&&(K(),!0)),[]);const V=[...r,{type:"divider",key:"d1"},{key:"save",label:c.saveKeepType,onSelect:B}],X=a?c.noStoreEdited:c.noStoreClean;return Dr("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(),k(!0);const t=m.current,n=t?t.value.slice(t.selectionStart,t.selectionEnd):"";n&&!n.includes("\n")&&(S(n),D(n))}else"Tab"!==e.key||t||e.shiftKey||e.target!==m.current||(e.preventDefault(),W("\t"))},children:[Hr(Ye,{onClose:s,fileMenu:V,name:o,saveState:{tone:a?"off-unsaved":"off",label:X},canUndo:w,canRedo:w,onUndo:()=>q("undo"),onRedo:()=>q("redo"),exportControl:Hr(Mr,{variant:"secondary",leftIcon:Hr(Tr,{name:"download",size:16}),onClick:B,children:c.export})}),Dr("div",{className:"flex shrink-0 flex-wrap items-center gap-0.5 border-b border-line bg-surface-sunken px-2 py-1",children:[Hr(Rr,{size:"sm",variant:"ghost","aria-label":c.find,title:c.find,"aria-pressed":x,onClick:()=>k(e=>!e),children:Hr(Tr,{name:"search",size:16})}),Hr(Rr,{size:"sm",variant:"ghost","aria-label":c.wrapLines,title:c.wrapLines,"aria-pressed":h,onClick:()=>g(e=>!e),children:Hr(Tr,{name:"wrap",size:16})})]}),x&&Hr(zn,{query:C,replacement:N,matchCase:A,current:P,total:M.length,onQuery:e=>{S(e);const t=D(e);T(0),I(t,0,e)},onReplacement:$,onMatchCase:e=>{L(e);const t=D(C,e);T(0),I(t,0)},onStep:e=>I(M,P+(e?1:-1)),onReplace:()=>{const e=m.current;if(!e||!M.length)return;e.focus(),e.setSelectionRange(M[P],M[P]+C.length),W(N);const t=D();I(t,P)},onReplaceAll:()=>{const e=m.current;if(!e||!M.length)return;const t=M.length;e.focus();for(let t=M.length-1;t>=0;t--)e.setSelectionRange(M[t],M[t]+C.length),W(N);D(),T(0),zr.success(c.replacedCount(t))},onClose:K}),Dr("div",{className:"relative min-h-0 flex-1 bg-surface",children:[x&&C&&M.length>0&&M.length<=2e3&&Hr("div",{ref:z,"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=E(),t=[];let n=0;return M.forEach((r,o)=>{t.push(e.slice(n,r)),n=r+C.length,t.push(Hr("mark",{...o===P?{"data-current":""}:{},className:"rounded-sm text-transparent "+(o===P?"bg-status-warning-line":"bg-status-warning-soft"),children:e.slice(r,n)},r))}),t.push(e.slice(n)),t})()}),Hr("textarea",{ref:m,defaultValue:t.text,"aria-label":e,spellCheck:!1,wrap:h?"soft":"off",onInput:U,onSelect:H,onKeyUp:H,onClick:H,onScroll:j,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")})]}),Dr("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:[Hr("span",{children:e}),Hr("span",{children:c.lineColumn(y.line,y.col)}),Hr("span",{children:c.lineCount(y.lines)}),Hr("span",{children:t.eol})]})]})}import{jsx as Br,jsxs as Ur}from"react/jsx-runtime";var Wr=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"]),qr=["docx"],Kr=`${Array.from(Wr,e=>`.${e}`).join(",")},.docx,text/*`,Gr=/^<!doctype html><meta charset="utf-8"><title>[^<]*<\/title>(?!<body style="font-family:ui-monospace)/,Vr=()=>"undefined"!=typeof navigator&&navigator.language||"en-AU";function Xr({value:e,onRename:t}){const n=u(),[r,o]=re(e);return te(()=>o(e),[e]),Br("div",{className:"docs-title",children:Br(se,{"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 Qr({documentId:e,onClose:t}){const n=u(),{store:r,canCreate:o=!0,canDelete:a=!0,chooseFile:i}=d(),[l,s]=re(null),[c,p]=re(null);if(!r||e)return Br(_r,{documentId:e,onClose:t});if(l)return Br(_r,{documentId:l.id,initialFile:l.file,onClose:()=>s(null)},l.key);return Br(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:Kr,choose:i&&{run:i,request:{title:n.files.choosing(n.fileKind,n.filesHeading),extensions:qr}},onOpen:e=>s({key:Date.now(),id:e}),onOpenFile:(e,t)=>{Z(e.name,qr)?c||(p(n.files.opening(e.name)),f(r,e).then(async r=>{const o=await ee(t,r.id);ue.success(n.files.savedCopy(r.title,e.name,o?t?.location:void 0)),s({key:Date.now(),id:r.id})}).catch(()=>ue.error(n.files.openFailed(e.name))).finally(()=>p(null))):s({key:Date.now(),file:e})},busy:c})}function _r({documentId:e,onClose:t,initialFile:n}){const r=u(),{store:o}=d(),a=o&&e?e:null,i=ne([]),l=ne(0),c=ne(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:b(R(Vr()),null,f(t))}},[h,g]=re(()=>a?null:p(r.untitled)),[v,x]=re(!1),[k,C]=re(0),[S,N]=re(!1),[$,A]=re(!1),[L,P]=re(!1);ae(L),te(()=>()=>{i.current.forEach(e=>URL.revokeObjectURL(e))},[]),te(()=>{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 w(t.bytes,f(n)):b(R(Vr()),null,f(n));e&&T({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,k]);const T=e=>{const t=i.current;if(i.current=[],"rich"===e.kind)for(const t of e.images.keys())i.current.push(t);g(e),P(!1),setTimeout(()=>t.filter(e=>!i.current.includes(e)).forEach(e=>URL.revokeObjectURL(e)),0)},M=async()=>!L||de({title:r.discardTitle(h?.filename??""),message:r.discardMessage,confirmLabel:r.discard,cancelLabel:r.keepEditing}),E=async e=>{if(!await M())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 w(n,f(t));T({key:++l.current,kind:"rich",doc:r,filename:e.name,images:t})}catch{ue.error(r.cannotRead(e.name))}}else if("doc"===t)ue.error(r.legacyDoc);else if(Wr.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||!Gr.test(o.text))T({key:++l.current,kind:"text",decoded:o,bytes:n,filename:e.name});else{const t=new Map,n=b(R(Vr()),null,f(t));n.html=s(o.text)||n.html,y(n),T({key:++l.current,kind:"rich",doc:n,images:t,filename:e.name.replace(/\.[^.]+$/,".docx"),imported:!0}),ue.info(r.openedOldSave)}}else ue.error(r.unsupported(t))}finally{N(!1)}};te(()=>{n&&E(n)},[]);const z=async()=>{await M()&&(P(!1),c.current?.click())},F="rich"===h?.kind&&!!h.stored,O=()=>ue.info(r.openFromFiles),j=[{key:"new",label:r.newDocument,onSelect:()=>{(async()=>{await M()&&T(p(r.untitled))})()}},{key:"open",label:Ur("span",{className:"flex w-full items-center justify-between gap-4",children:[Br("span",{children:r.open}),Br("span",{className:"text-2xs text-ink-faint",children:"⌘O"})]}),onSelect:()=>{z()}}],H=h&&Br(Xr,{value:h.filename,onRename:e=>{const t=h?.filename??e;g(t=>t?{...t,filename:e}:t),o&&"rich"===h?.kind&&h.stored&&o.rename(h.stored.id,e).catch(()=>{ue.error(r.renameFailed),g(e=>e?{...e,filename:t}:e)})}});return Ur("div",{className:"relative flex h-full flex-col bg-surface text-ink",onDragOver:e=>{e.dataTransfer.types.includes("Files")&&(e.preventDefault(),$||A(!0))},onDragLeave:e=>{e.currentTarget===e.target&&A(!1)},onDrop:e=>{if(!e.dataTransfer.types.includes("Files"))return;e.preventDefault(),A(!1);const t=Array.from(e.dataTransfer.files??[]);"rich"===h?.kind&&t.length&&t.every(e=>e.type.startsWith("image/"))?window.dispatchEvent(new CustomEvent("docs-insert-images",{detail:{key:h.key,files:t}})):t[0]&&F?O():t[0]&&E(t[0])},children:[h&&Br(oe,{title:`${D=h.filename,D.length>24?`${D.slice(0,23)}…`:D}${L?" •":""} - Documents`}),Br("input",{ref:c,type:"file",accept:Kr,className:"hidden",onChange:e=>{const t=e.target.files?.[0];t&&E(t),e.target.value=""}}),v?Br("div",{className:"docs-open-failed",children:Br(le,{title:r.openFailed,children:t&&Br(ie,{onClick:t,children:r.backToFiles})})}):S||!h?Br(ce,{size:"sm",padding:"",className:"h-full",label:r.loading}):"rich"===h.kind?Br(Nr,{sessionKey:h.key,doc:h.doc,filename:h.filename,images:h.images,fileEntries:F?[]:j,title:H,startsDirty:h.imported,dirty:L,onDirty:P,onOpenFile:()=>{F?O():z()},onNewImageUrl:e=>{i.current.push(e)},onClose:t,stored:o&&h.stored?{store:o,...h.stored}:void 0,onReload:()=>{P(!1),g(null),C(e=>e+1)}},h.key):Br(Ir,{filename:h.filename,decoded:h.decoded,bytes:h.bytes,fileEntries:j,title:H,dirty:L,onDirty:P,onOpenFile:()=>{z()},onClose:t},h.key),$&&Br("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:Br("div",{className:"rounded-md bg-accent-fill px-4 py-2 text-sm font-medium text-on-accent",children:r.dropHint})})]});var D}function Jr({id:e,onClose:t}){return Br(Qr,{documentId:e,onClose:t})}export{Jr as OpenDocument,Qr as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FileList as e}from"./chunk-PMGQ5GUH.js";import{importDeckFile as t}from"./chunk-
|
|
1
|
+
import{FileList as e}from"./chunk-PMGQ5GUH.js";import{importDeckFile as t}from"./chunk-ADXHTZ3Q.js";import{PptxPasswordError as n,PptxUnreadableError as i}from"./chunk-MDG2ADZ7.js";import{STARTERS as s,starterDeck as l}from"./chunk-Q7NVDOCX.js";import{useSlidesHost as o,useSlidesWords as r}from"./chunk-BGAR3P46.js";import{SlideView as a}from"./chunk-B2X3NIQR.js";import"./chunk-PXOQN7D6.js";import"./chunk-B32ASXHM.js";import{placeCopy as c}from"./chunk-XYVQTQ6N.js";import{lazy as d,Suspense as m,useCallback as p,useEffect as u,useState as h}from"react";import{Button as f,EmptyState as k,IconButton as y,toast as b}from"efficient-shell/ui";import{Icon as N}from"efficient-shell/icons";import{jsx as v,jsxs as C}from"react/jsx-runtime";var w=e=>({title:e.placeholderTitle,subtitle:e.placeholderSubtitle,body:e.placeholderBody,dealerPitch:e.dealerPitch,monthlyReport:e.monthlyReport}),D=d(()=>import("./SlidesEditor-ETCUQVJ7.js")),j=["pptx"];function F({id:e,onClose:t,note:n}){const i=r(),{store:s}=o(),[l,a]=h(null),[c,d]=h(!1),[b,w]=h(n??null),j=p(()=>{s.get(e).then(e=>a(t=>({deck:e,nonce:(t?.nonce??0)+1})),()=>d(!0))},[e,s]);if(u(j,[j]),c)return v("div",{className:"slides-list-empty",children:v(k,{title:i.openFailed,children:v(f,{onClick:t,children:i.backToDecks})})});if(!l)return null;const F=v(m,{fallback:null,children:v(D,{deck:l.deck,onClose:t,onReload:j},l.nonce)});return b?C("div",{className:"slides-with-note",children:[C("div",{className:"slides-import-note",role:"status",children:[v(N,{name:"info",size:16}),v("span",{children:b}),v(y,{"aria-label":i.dismiss,onClick:()=>w(null),children:v(N,{name:"close",size:14})})]}),v("div",{className:"slides-with-note-body",children:F})]}):F}function P(){const d=r(),{store:m,canCreate:u=!0,canDelete:f=!0,chooseFile:k,storeImage:y}=o(),[N,D]=h(null),[P,g]=h(null),x=p(()=>m.list(),[m]);if(N)return v(F,{id:N.id,note:N.note,onClose:()=>D(null)});const Q=u&&v("div",{className:"slides-starters","aria-label":d.startFrom,role:"group",children:s.map(e=>{const t="blank"===e?null:l(e,w(d));return C("button",{type:"button",className:"slides-starter",disabled:!!P,onClick:()=>{(async e=>{if(!P)try{const t=await m.create("blank"===e?d.untitledDeck:d.starterName(e));"blank"!==e&&await m.save(t.id,l(e,w(d)),t.version),D({id:t.id})}catch{b.error(d.createFailed)}})(e)},children:[v("span",{className:"slides-starter-thumb",children:t?v(a,{slide:t.slides[0],width:128}):v("span",{className:"slides-starter-blank"})}),v("span",{children:d.starterName(e)})]},e)})});return v(e,{extra:Q,words:{windowTitle:d.slidesPanel,heading:d.decks,newFile:d.newDeck,emptyTitle:d.emptyTitle,emptyBody:d.emptyBody,deleteConfirm:d.deleteConfirm,createFailed:d.createFailed,deleteFailed:d.deleteFailed},files:d.files,list:x,create:()=>m.create(d.untitledDeck),rename:m.rename,remove:m.remove,canCreate:u,canDelete:f,accept:".pptx,application/vnd.openxmlformats-officedocument.presentationml.presentation",choose:k&&{run:k,request:{title:d.files.choosing(d.fileKind,d.slidesPanel),extensions:j}},onOpen:e=>D({id:e}),onOpenFile:(e,s)=>{if(P)return;const l=d.files.opening(e.name);g(l),t(m,e,{storeImage:y,onProgress:e=>g(`${l} ${Math.round(100*e)}%`)}).then(async t=>{const n=await c(s,t.id);b.success(d.files.savedCopy(t.title,e.name,n?s?.location:void 0)),D({id:t.id,note:d.importNotes({skipped:t.notes.skipped,animations:t.notes.animationsDropped,fonts:t.notes.fontsReplaced})})}).catch(t=>{b.error(t instanceof n?d.pptxPasswordProtected:t instanceof i?t.message:d.files.openFailed(e.name))}).finally(()=>g(null))},busy:P})}export{F as OpenDeck,P as default,w as starterWords};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{importSpreadsheetFile as e,readWithSheetJs as t}from"./chunk-DG4VDXLL.js";import{readXlsx as r,writeXlsx as n}from"./chunk-MR7ZWQHF.js";import{SPREADSHEET_ACCEPT as o,SPREADSHEET_EXTENSIONS as l,SpreadsheetsConflict as a,sheetsOf as i,useSpreadsheetWords as c,useSpreadsheetsHost as s}from"./chunk-NRGUS5QY.js";import"./chunk-UKGIT2RS.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 x,cellLabel as b,changeStructure as y,clearValues as C,colLabel as k,columnValues as N,commitEntry as E,copyClip as S,cycleRefAbsolute as D,dataRegion as R,deleteSheet as T,duplicateSheet as M,editText as A,expandForMerges as z,fillRange as F,filteredRows as I,findCells as L,formatKey as O,formatNumber as P,isFormula as U,makeEvaluator as $,mergeRange as B,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 Q,rangeLabel as Z,rawAt as q,readEntry as J,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-ZS45QEF4.js";import{FileList as he}from"./chunk-PMGQ5GUH.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 xe}from"react";import{saveIndicator as be,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 Ee,useWindowDirty as Se}from"efficient-shell";import{Icon as De}from"efficient-shell/icons";import{Button as Re,Checkbox as Te,ColorPickerPanel as Me,ContextMenu as Ae,DropdownMenu as ze,EmptyState as Fe,IconButton as Ie,Input as Le,LoadingSpinner as Oe,Popover as Pe,PopupMenu as Ue,PopupMenuDivider as $e,PopupMenuItem as Be,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 Qe,useEffect as Ze,useImperativeHandle as qe,useMemo as Je,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:b,onAutoFitCol:y,onAutoFitRow:C,onHeaderMenu:N,onFilterButton:E,renderEditor:S,onKeyDown:D,onCopy:R,onCut:T,onPaste:M},A){const F=c(),I=et(null),[L,P]=tt({x:0,y:0}),[U,$]=tt({width:1e3,height:600}),[B,H]=tt(null),[W,X]=tt(null),[Y,G]=tt(null);Ze(()=>{const e=I.current;if(!e)return;const t=()=>{e.clientWidth&&e.clientHeight&&$({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=Je(()=>{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&&""!==q(e,a,i)){const n=(e.colWidths[i]??u)-8;s=x(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]),_=Je(()=>new Set(e.hiddenRows),[e.hiddenRows]),Q=Je(()=>new Set(e.hiddenCols),[e.hiddenCols]),Z=Je(()=>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]),J=Je(()=>st(e.colCount,t=>Q.has(t)?0:B?.col===t?B.width:e.colWidths[t]??u),[e.colCount,e.colWidths,Q,B]),ee=Math.min(e.frozenRows,e.rowCount),te=Math.min(e.frozenCols,e.colCount),re=Z[ee],ne=J[te],oe=J[e.colCount],le=Z[e.rowCount],ae=Qe(e=>at+J[e]-(e>=te?L.x:0),[J,te,L.x]),ie=Qe(e=>it+Z[e]-(e>=ee?L.y:0),[Z,ee,L.y]),ce=Qe(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=J[e.col]-ne,n=J[e.col+1]-ne;t<o?o=t:n>o+r&&(o=n-r)}if(e.row>=ee){const t=Z[e.row]-re,r=Z[e.row+1]-re;t<l?l=t:r>l+n&&(l=r-n)}t.scrollTo(o,l)},[J,Z,ne,re,te,ee]);qe(A,()=>({focus:()=>I.current?.focus({preventScroll:!0}),scrollTo:ce,measureColumn:n=>{let o=0;for(let l=0;l<e.cells.length;l++){if(""===q(e,l,n))continue;const a=e.formats[O(l,n)];o=Math.max(o,dt(x(e,t,r,l,n).text,a))}return Math.ceil(o+8+4)}}),[ce,e,t,r]);const se=Qe((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(Z,Math.max(0,Math.min(a,le-1))),col:ut(J,Math.max(0,Math.min(l,oe-1)))}},[J,Z,ne,re,oe,le]),ue=Qe((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=Qe((t,r)=>{const n=z(e,V(t,r));m({active:t,range:n})},[e,m]),fe=Math.max(0,U.width-at-ne),he=Math.max(0,U.height-it-re),me=ut(Z,re+L.y),ge=ut(J,ne+L.x),pe=Math.min(e.rowCount-1,ut(Z,re+L.y+he)),ve=Math.min(e.colCount-1,ut(J,ne+L.x+fe)),we=(n,o,i,c)=>{const s=[],u=[],f=new Set,h=(n,o,i)=>{const c=O(n,o);if(f.has(c))return;f.add(c);const h=i?i.r2:n,m=i?i.c2:o,g=J[o],p=Z[n],v=J[m+1]-g,w=Z[h+1]-p;if(v<=0||w<=0)return;const b=e.formats[c],y=q(e,n,o),C=a&&"="===y[0]?{text:y,color:null,align:"left",error:!1}:x(e,t,r,n,o),k=b?.border,N="1px solid var(--ink)",E=!!b?.fill||!!k||!!i,S=l?"1px solid var(--line-subtle)":"1px solid transparent",D={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:b?.fill??(i?"var(--surface)":void 0)};if((E||l)&&s.push(nt("div",{style:D},`b${c}`)),!C.text)return;const R=b?.align??C.align;let T=C.text;"string"==typeof T&&!C.error&&"right"===C.align&&!b?.wrap&&dt(T,b)>v-4&&(T="#".repeat(Math.max(1,Math.floor(v/8))));let M=v,A=0;if(!i&&!b?.wrap&&"left"===C.align&&dt(T,b)>v-8){if("left"===R||"center"===R)for(let t=o+1;t<=Math.min(o+40,e.colCount-1)&&(""===q(e,n,t)&&!K(e,n,t));t++)M+=J[t+1]-J[t];if("right"===R||"center"===R)for(let t=o-1;t>=Math.max(o-40,0)&&(""===q(e,n,t)&&!K(e,n,t));t--)A+=J[t+1]-J[t]}const z=b?.vAlign??"bottom",F=C.error?"var(--danger-text)":C.color??b?.color;u.push(nt("div",{"data-cell":c,className:"pointer-events-none",style:{position:"absolute",left:g-A,top:p,width:M+A,height:w,boxSizing:"border-box",padding:"0 4px",overflow:"hidden",display:"flex",alignItems:"top"===z?"flex-start":"middle"===z?"center":"flex-end",justifyContent:b?.wrap?void 0:"right"===R?"flex-end":"center"===R?"center":"flex-start",textAlign:R,whiteSpace:b?.wrap?"pre-wrap":"pre",wordBreak:b?.wrap?"break-word":void 0,fontSize:(b?.fontSize??d)*ct,lineHeight:1.3,paddingBottom:"bottom"===z?2:void 0,fontWeight:b?.bold?700:void 0,fontStyle:b?.italic?"italic":void 0,textDecoration:[b?.underline?"underline":"",b?.strike?"line-through":""].join(" ").trim()||void 0,color:F},children:nt("span",{style:b?.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]},xe=(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:J[e.c1],top:Z[e.r1],width:J[e.c2+1]-J[e.c1],height:Z[e.r2+1]-Z[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},be=[];ee&&te&&be.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&&be.push({key:"top",left:at+ne,top:it,width:fe,height:re,offsetX:L.x,offsetY:0,r1:0,r2:ee-1,c1:ge,c2:ve}),te&&be.push({key:"left",left:at,top:it+re,width:ne,height:he,offsetX:0,offsetY:L.y,r1:me,r2:pe,c1:0,c2:te-1}),be.push({key:"main",left:at+ne,top:it+re,width:fe,height:he,offsetX:L.x,offsetY:L.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,Ee=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",De="bg-accent-tint text-accent-text",Re="bg-surface-sunken text-ink-muted",Te=ye.r2<ee||ye.r2>=me,Me=ae(ye.c2+1),Ae=ie(ye.r2+1),ze=Te&&!h&&Me>=at&&Ae>=it&&Me<=U.width&&Ae<=U.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:J[Fe.c2+1]-J[Fe.c1],height:Z[Fe.r2+1]-Z[Fe.r1],viewportWidth:U.width,viewportHeight:U.height},{filter:Le}=e,Oe=Le?.range.r1??-1,Pe=[];if(Le&&(Oe<ee||Oe>=me&&Oe<=pe))for(let e=Le.range.c1;e<=Le.range.c2;e++)J[e+1]>J[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:D,onCopy:R,onCut:T,onPaste:M,children:nt("div",{style:{width:at+oe,height:it+le},children:ot("div",{className:"sticky top-0 left-0 overflow-hidden",style:{width:U.width,height:U.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:[be.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),xe(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(Oe),n=Z[Oe+1]-Z[Oe],o=(Le?.excluded[e]?.length??0)>0;return nt("button",{type:"button","aria-label":F.filterColumn(k(e)),onClick:t=>{t.stopPropagation(),E(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:Me-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=J[t+1]-J[t];if(r<=0)return null;const n=J[t]-(t>=te?L.x:0),l=t>=ye.c1&&t<=ye.c2;return ot("div",{className:`${Se} ${l?De:Re} ${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=J[t+1]-J[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=Z[t+1]-Z[t];if(r<=0)return null;const n=Z[t]-(t>=ee?L.y:0),l=t>=ye.r1&&t<=ye.r2;return ot("div",{className:`${Se} ${l?De:Re} ${l&&Ee?"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=Z[t+1]-Z[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&&b(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",CHAR:"number",CLEAN:"text",CODE:"text",ISERR:"value",ISEVEN:"value",ISODD:"value",MAXIFS:"max_range, range1, criterion1, ...",MINIFS:"min_range, range1, criterion1, ...",MROUND:"value, factor",PERCENTILE:"range, percentile","PERCENTILE.INC":"range, percentile",QUARTILE:"range, quartile","QUARTILE.INC":"range, quartile",QUOTIENT:"dividend, divisor",REGEXEXTRACT:"text, regular_expression",REGEXMATCH:"text, regular_expression",REGEXREPLACE:"text, regular_expression, replacement",SUBTOTAL:"function_code, range1, [range2, ...]",DATEVALUE:"text",ISOWEEKNUM:"date","NETWORKDAYS.INTL":"start, end, [weekend], [holidays]",TIMEVALUE:"text",WEEKNUM:"date, [type]",WORKDAY:"start, days, [holidays]","WORKDAY.INTL":"start, days, [weekend], [holidays]",YEARFRAC:"start, end, [basis]"};import{Fragment as wt,jsx as xt,jsxs as bt}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 Et=o;function St({spreadsheetId:t,onClose:r}){const n=c(),{store:o,canCreate:a=!0,canDelete:i=!0,chooseFile:u}=s(),[d]=xe(()=>null!=Ge()),[f,h]=xe(null),[m,g]=xe(null);if(!o||d)return xt(Mt,{onClose:r});if(t)return xt(Rt,{store:o,id:t,onClose:r});if(f?.id)return xt(Rt,{store:o,id:f.id,onClose:()=>h(null)},f.key);if(f?.file)return xt(Mt,{initialFile:f.file,hasStore:!0,onClose:()=>h(null)},f.key);return xt(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:Et,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 Dt({id:e,onClose:t}){return xt(St,{spreadsheetId:e,onClose:t})}function Rt({store:e,id:t,onClose:r,pane:n}){const o=c(),[l,a]=xe(null),[i,s]=xe(!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?xt("div",{className:"office-open-failed",children:xt(Fe,{title:o.storedOpenFailed,children:r&&xt(Re,{onClick:r,children:o.backToFiles})})}):l?xt(Mt,{stored:{store:e,...l.kept},onClose:r,onReload:u,pane:n},l.nonce):xt(Oe,{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?xt(Rt,{store:o,id:t,pane:l}):xt(Mt,{initial:e??{rows:[],filename:""},pane:l})}function Mt({stored:e,initialFile:o,hasStore:l,onClose:s,onReload:u,initial:f,pane:h}){const x=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]=xe(()=>{const e=k.current;if(!e)return null;const t=At(e.data,x.sheetName(1));return t?{sheet:t,title:e.data.filename.replace(/\.(csv|tsv|txt)$/i,"")}:-1===e.token&&e.data.filename?{sheet:W(x.sheetName(1)),title:e.data.filename}:null}),[Fe,Oe]=xe(()=>e?i(e.workbook,x.sheetName(1)):me?[me.sheet]:[W(x.sheetName(1))]),[_e,Qe]=xe(0),[Ze,qe]=xe(e?.title??me?.title??x.untitled),[Je,et]=xe(()=>k.current?.data.onEmail),tt=we(Fe),rt=we([]),nt=we([]),[,ot]=xe(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,Oe(r),ot(e=>e+1))},[]),at=ge(e=>{rt.current=[],nt.current=[],tt.current=e,Oe(e),Qe(0),ot(e=>e+1)},[]),it=ge(()=>{const e=rt.current.pop();e&&(nt.current.push(tt.current),tt.current=e,Oe(e),Qe(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,Oe(e),Qe(t=>Math.min(t,e.length-1)),ot(e=>e+1))},[]),st=we(Fe),ut=we(e?.version??""),dt=we(e?.title??""),[St,Dt]=xe(!1),Rt=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(),Dt(!0)):0===t&&Xe.error(x.saveFailed)}}),{push:Mt,flush:zt}=Tt,Ft=we(Fe);pe(()=>{e&&Fe!==Ft.current&&(Ft.current=Fe,Mt(Fe))},[Mt,Fe,e]),pe(()=>()=>{zt()},[zt]),Se(e?Tt.state.pending||St:Fe!==st.current);const It=ge(e=>{const t=At(e,x.sheetName(1));t&&(at([t]),st.current=tt.current,qe(e.filename.replace(/\.(csv|tsv|txt)$/i,"")),et(()=>e.onEmail))},[at,x]);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 Lt=Math.min(_e,Fe.length-1),Ot=Fe[Lt],Pt=ve(()=>$(Fe),[Fe]),Ut=ve(()=>I(Ot,Lt,Pt),[Ot,Lt,Pt]),$t=we(null),Bt=we(null),[Kt,Ht]=xe({}),Wt=Kt[Ot.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=Ot.formats[O(Yt.row,Yt.col)]??{},jt=q(Ot,Yt.row,Yt.col),[_t,Qt]=xe(null),Zt=we(_t);Zt.current=_t;const[qt,Jt]=xe(null),[er,tr]=xe(!0),[rr,nr]=xe(!1),[or,lr]=xe(null),[ar,ir]=xe(null),[cr,sr]=xe(!1),[ur,dr]=xe(null),[fr,hr]=xe(null),[mr,gr]=xe(!1),[pr,vr]=xe(""),[wr,xr]=xe(""),[br,yr]=xe({matchCase:!1,wholeCell:!1,inFormulas:!1}),Cr=we(null),kr=we(null),Nr=we(null),Er=Ve(),Sr=Ve(),Dr=ge(()=>{$t.current?.focus(),setTimeout(()=>{const e=document.activeElement;e&&e!==document.body&&!e.closest("[aria-haspopup]")||$t.current?.focus()},0)},[]),Rr=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),Mr=we(()=>!1);pe(()=>He(()=>!!Tr.current?.contains(document.activeElement)&&Mr.current()),[]);const Ar=ge(e=>Ot.hiddenRows.includes(e)||Ut.has(e),[Ot.hiddenRows,Ut]),zr=ge(e=>Ot.hiddenCols.includes(e),[Ot.hiddenCols]),Fr=ge(e=>{const t=K(Ot,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}),$t.current?.scrollTo(e)},[Ot,Vt]),Ir=ge((e,t,r)=>{let{row:n,col:o}=e;const l=K(Ot,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<Ot.rowCount&&o>=0&&o<Ot.colCount&&(Ar(n)||zr(o)));return n<0||n>=Ot.rowCount||o<0||o>=Ot.colCount?e:{row:n,col:o}},[Ot,Ar,zr]),Lr=ge((e,t,r)=>{const n=e=>""!==q(Ot,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},[Ot,Ir]),Or=ge(e=>{const t=z(Ot,V(Wt.active,e));Vt({active:Wt.active,range:t}),$t.current?.scrollTo(e)},[Ot,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]),Ur=we(null),$r=ge((e,t={})=>{const r=q(Ot,e.row,e.col),n=t.text??A(r,Ot.formats[O(e.row,e.col)]);Jt(e=>e?.cut?null:e),t.inBar||null!==Ur.current||(Ur.current=n.length),Qt({sheetId:Ot.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})},[Ot]),Br=ge(e=>{const t=Zt.current;if(!t)return!1;Zt.current=null,Qt(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(q(o,t.row,t.col),o.formats[O(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=U(t.text)?le(J(t.text).raw,r-t.row,n-t.col):t.text;l=E(l,r,n,e)}else l=E(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&&Qe(r),!0},[lt]),Kr=ge(()=>{const e=Zt.current;if(Zt.current=null,Qt(null),e){const t=tt.current.findIndex(t=>t.id===e.sheetId);t>=0&&t!==Xt.current&&Qe(t)}Dr()},[Dr]),Hr=ge((e,t)=>{Fr(Ir(Wt.active,e,t)),Dr()},[Dr,Fr,Wt.active,Ir]);Ee(()=>{if(!_t)return;const e=_t.inBar?Cr.current:kr.current;e&&(document.activeElement!==e&&e.focus({preventScroll:!0}),null!==Ur.current&&(e.setSelectionRange(Ur.current,Ur.current),Ur.current=null))},[_t]);const Wr=ge((e,t)=>{Qt(r=>r?{...r,text:e,caret:t,pick:null,suggestion:0}:r)},[]),Xr=_t?.sheetId===Ot.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,Ot.name,Xr,Ot.rowCount,Ot.colCount):[],[_t,Ot.name,Ot.rowCount,Ot.colCount,Xr]),_r=ge((e,t)=>{const r=Zt.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;Ur.current=i,Qt({...r,text:a,caret:i,pick:t?null:{start:o,end:i}})},[]),Qr=ge(e=>{const t=Zt.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);Ur.current=n.caret,Qt({...t,text:n.text,caret:n.caret,suggestion:0,pick:null})},[]),Zr=e=>{if(_t){if(e.stopPropagation(),Vr){if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();const t=Vr.matches.length;return void Qt({..._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 Qr(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 Ur.current=t+1,void Wr(o,t+1)}return e.preventDefault(),e.ctrlKey||e.metaKey?(Br(Wt.range),void Dr()):(Br(),void Hr(e.shiftKey?-1:1,0))}if("Tab"===e.key)return e.preventDefault(),Br(),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:D(t.ref.a),b:t.ref.b?D(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&&(Ur.current=t.caret,Wr(t.text,t.caret)))}"enter"!==_t.mode||_t.inBar||U(_t.text)||!e.key.startsWith("Arrow")||(e.preventDefault(),Br(),Hr("ArrowDown"===e.key?1:"ArrowUp"===e.key?-1:0,"ArrowRight"===e.key?1:"ArrowLeft"===e.key?-1:0))}},qr=e=>{const t=e.currentTarget.selectionStart;Qt(e=>e&&e.caret!==t?{...e,caret:t,pick:null}:e)},Jr=ge(e=>{Br(),e(),Dr()},[Br,Dr]),en=we(Wt);en.current=Wt;const tn=h?.bridge,rn=we(Ze);rn.current=Ze;const nn=Kt[Ot.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||x.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,x,it]),pe(()=>{tn?.changed()},[tn,nn,Lt,Fe,Ze]);const ln=ge(e=>{Jr(()=>Rr(t=>se(t,en.current.range,e)))},[Jr,Rr]),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(Lt,Yt.row,Yt.col),r=v(Gt.numFmt??"General",e,"number"==typeof t?t:null);cn(r)},[Yt,Gt.numFmt,Pt,Lt,cn]),un=ge((e,t)=>{const{range:r}=Wt,[n,o]="row"===e?[r.r1,r.r2]:[r.c1,r.c2],l="row"===e?Ot.rowCount:Ot.colCount,a=o-n+1>=l?1:o-n+1;l+a>("row"===e?g:m)||Jr(()=>lt(r=>y(r,Lt,e,t?o+1:n,a)))},[Ot.colCount,Ot.rowCount,lt,Lt,Jr,Wt]),dn=ge(e=>{const{range:t}=Wt,[r,n]="row"===e?[t.r1,t.r2]:[t.c1,t.c2],o="row"===e?Ot.rowCount:Ot.colCount,l=Math.min(n-r+1,o-1);l<1||Jr(()=>{lt(t=>y(t,Lt,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})})},[Ot.colCount,Ot.rowCount,lt,Lt,Jr,Fr,Wt]),fn=ge(e=>{const{range:t}=Wt;Jr(()=>Rr(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]}}))},[Jr,Wt,Rr]),hn=ge(e=>{Jr(()=>Rr(t=>"row"===e?{...t,hiddenRows:[]}:{...t,hiddenCols:[]}))},[Jr,Rr]),mn=ge(e=>{Jr(()=>Rr(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?R(t,Wt.range):Wt.range;return n&&(o={...o,r2:Math.max(o.r1,ue(t)?.row??0)}),t.filter&&Q(t.filter.range,Wt.active.row,Wt.active.col)&&(o={...t.filter.range,r1:t.filter.range.r1+1}),ae(t,Lt,Pt,o,Wt.active.col,e)}))},[Pt,Lt,Jr,Wt,Rr]),gn=ge(()=>{ir(null),Jr(()=>Rr(e=>{if(e.filter)return{...e,filter:null};const t=R(e,Wt.range);return t.r1===t.r2?e:{...e,filter:{range:t,excluded:{}}}}))},[Jr,Wt.range,Rr]),pn=ge(()=>{Jr(()=>Rr(e=>e.merges.some(e=>Q(Wt.range,e.r1,e.c1))?ce(e,Wt.range):B(e,Wt.range)))},[Jr,Wt.range,Rr]),vn=ge((e,t)=>{Jr(()=>Rr(r=>({...r,frozenRows:e??r.frozenRows,frozenCols:t??r.frozenCols})))},[Jr,Rr]),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(Lt,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=Z({r1:t,c1:r.col,r2:r.row-1,c2:r.col}):n<r.col&&(o=Z({r1:r.row,c1:n,r2:r.row,c2:r.col-1}))}else o=Z(t);const l=n?r:{row:t.r2+1,col:t.c1};Br(),n||Fr(l);const a=`=${e}(${o})`;Ur.current=a.length-1,$r(l,{text:a})},[Br,Pt,Lt,Fr,Wt,$r]),xn=ge((e,t)=>{const r=Wt.range,n={...r,r2:Math.min(r.r2,Math.max(r.r1,Ot.cells.length-1))},o=S(Ot,Lt,Pt,n,e);Jt(o),t?(t.preventDefault(),t.clipboardData.setData("text/plain",o.text)):navigator.clipboard?.writeText(o.text).catch(()=>{})},[Ot,Pt,Lt,Wt.range]),bn=ge((e,t)=>{const{range:r}=Wt;if(qt&&qt.text===e){if(qt.cut){const e=tt.current.findIndex(e=>e.id===qt.sheetId);if(e<0)return;let t=null;return lt(n=>{const o=H(n,e,qt,Lt,r);return t=o.range,o.sheets}),t&&Vt({active:{row:t.r1,col:t.c1},range:t}),void Jt(null)}return void Rr(e=>{const n=j(e,qt,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);Rr(e=>{let t=e;n.forEach((e,n)=>e.forEach((e,o)=>{t=E(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})},[qt,lt,Lt,Wt,Vt,Rr]),yn=ge(e=>{Jr(()=>{const t=navigator.clipboard?.readText?.();t?t.then(t=>bn(t,e)).catch(()=>{qt&&bn(qt.text,e)}):qt&&bn(qt.text,e)})},[qt,bn,Jr]);Mr.current=()=>Zt.current?(Kr(),!0):ar?(ir(null),Dr(),!0):ur?(dr(null),Dr(),!0):cr?(sr(!1),Dr(),!0):null!==fr?(hr(null),Dr(),!0):mr?(gr(!1),Dr(),!0):!(!qt&&!or)&&(Jt(null),lr(null),!0);const Cn=Ze||x.spreadsheetFile,kn=ge(async()=>{Br();try{const e=tt.current;Nt(await n(e,$(e)),"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",`${Cn}.xlsx`),st.current=e,ot(e=>e+1)}catch{Xe.error(x.saveFailed)}},[Br,Cn,x]),Nn=()=>{const e=tt.current,t=Math.min(Xt.current,e.length-1);return ne(e[t],t,$(e))},En=async n=>{const o=n.name.replace(/\.(csv|tsv|txt|xlsx|xls|ods)$/i,"");try{if(Br(),/\.(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),Qe(0)}else{const e=Y(await n.text());if(!e.length)return;Rr(t=>({...oe(t.name,e),id:t.id}))}e||qe(o)}catch{Xe.error(x.openFailed)}};pe(()=>{o&&En(o)},[]);const Sn=ve(()=>mr?L(Ot,Lt,Pt,pr,br):[],[Ot,Pt,mr,br,pr,Lt]),Dn=Sn.findIndex(e=>e.row===Wt.active.row&&e.col===Wt.active.col),Rn=e=>{if(!Sn.length)return;const t=Dn<0?e>0?0:Sn.length-1:(Dn+e+Sn.length)%Sn.length;Fr(Sn[t])},Tn=()=>{Br();const e=Lt+1;lt(t=>{const r=X(t,x.sheetBase);return[...t.slice(0,e),W(r),...t.slice(e)]}),Qe(e),Dr()},Mn=()=>{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(x.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===Lt?Qe(r):r===Lt&&Qe(e))},zn=ge(e=>{Zt.current&&Br(),Vt(e),or&&(Rr(t=>se(t,e.range,()=>or)),lr(null))},[Br,or,Vt,Rr]),Fn=ge((e,t,r)=>{"cell"!==t||Q(Wt.range,r.row,r.col)?"col"!==t||0===Wt.range.r1&&Wt.range.r2===Ot.rowCount-1&&r.col>=Wt.range.c1&&r.col<=Wt.range.c2?"row"!==t||0===Wt.range.c1&&Wt.range.c2===Ot.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:Ot.colCount-1}}):Vt({active:{row:0,col:r.col},range:{r1:0,c1:r.col,r2:Ot.rowCount-1,c2:r.col}}):Fr(r),Er.open(e,{kind:t,pos:r})},[Ot.colCount,Ot.rowCount,Er,Fr,Wt.range,Vt]),In=ge((e,t)=>{if(!Ot.filter)return;const r=N(Ot,Lt,Pt,Ot.filter.range,e);ir({col:e,x:t.left,y:t.bottom+2,values:r,unticked:new Set(Ot.filter.excluded[e]??[]),search:""})},[Ot,Pt,Lt]),Ln=(e,t)=>{ir(null),Jr(()=>Rr(r=>{if(!r.filter)return r;const{range:n}=r.filter;return ae(r,Lt,Pt,{...n,r1:n.r1+1},e,t)}))},On=ve(()=>{const{range:e}=Wt;return e.r1===e.r2&&e.c1===e.c2?null:re(Ot,Lt,Pt,e,Ut)},[Ot,Pt,Ut,Lt,Wt]),Pn=e=>P(Number(e.toPrecision(12)),On?.firstFormat??"#,##0.##").text,Un=(e,t)=>bt("span",{className:"flex w-full items-center justify-between gap-6",children:[xt("span",{children:e}),xt("span",{className:"text-xs text-ink-faint",children:t})]}),$n=(e,t,r,n={})=>({key:e,label:t,onSelect:r,...n}),Bn=e=>({type:"divider",key:e}),Kn=[{key:"general",label:x.formatGeneral,code:p.general},{key:"number",label:x.formatNumber,code:p.number},{key:"percent",label:x.formatPercent,code:p.percent},{key:"scientific",label:x.formatScientific,code:p.scientific},{key:"currency",label:x.formatCurrency,code:p.currency},{key:"date",label:x.formatDate,code:p.date},{key:"time",label:x.formatTime,code:p.time},{key:"dateTime",label:x.formatDateTime,code:p.dateTime},{key:"text",label:x.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",x.bordersAll],["outer",x.bordersOuter],["top",x.bordersTop],["bottom",x.bordersBottom],["left",x.bordersLeft],["right",x.bordersRight],["none",x.bordersNone]].map(([e,t])=>$n(e,t,()=>Jr(()=>Rr(t=>w(t,Wt.range,e))))),Wn=[...["left","center","right"].map(e=>({type:"radio",key:e,label:"left"===e?x.alignLeft:"center"===e?x.alignCenter:x.alignRight,checked:Gt.align===e,onSelect:()=>ln(t=>de(t,"align",e))})),Bn("v"),...["top","middle","bottom"].map(e=>({type:"radio",key:e,label:"top"===e?x.alignTop:"middle"===e?x.alignMiddle:x.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=>$n(e,e,()=>wn(e))),Yn=[...[0,1,2].map(e=>({type:"radio",key:`r${e}`,label:x.freezeRows(e),checked:Ot.frozenRows===e,onSelect:()=>vn(e,null)})),{type:"radio",key:"rUp",label:x.freezeUpToRow(Yt.row+1),checked:Ot.frozenRows===Yt.row+1&&Yt.row>1,onSelect:()=>vn(Yt.row+1,null)},Bn("c"),...[0,1,2].map(e=>({type:"radio",key:`c${e}`,label:x.freezeColumns(e),checked:Ot.frozenCols===e,onSelect:()=>vn(null,e)})),{type:"radio",key:"cUp",label:x.freezeUpToColumn(b(0,Yt.col).replace(/\d+$/,"")),checked:Ot.frozenCols===Yt.col+1&&Yt.col>1,onSelect:()=>vn(null,Yt.col+1)}],Gn=[...e?[]:[$n("new",x.menuNew,()=>Jr(()=>{lt(()=>[W(x.sheetName(1))]),Qe(0),qe(x.untitled)}))],$n("open",x.menuOpen,()=>Bt.current?.click()),Bn("a"),$n("xlsx",Un(x.saveExcel,`${kt}S`),()=>{kn()}),$n("csv",x.saveCsv,()=>Jr(()=>Nt(Nn(),"text/csv",`${Cn}.csv`))),...Je?[Bn("b"),$n("email",x.email,()=>Jr(()=>Je(Nn(),`${Cn}.csv`)))]:[],...!e&&h?.onSaveToFiles?[Bn("c"),$n("keep",x.saveToFiles,()=>Jr(()=>h.onSaveToFiles?.(Ze.trim()||x.untitled,tt.current)))]:[]],jn=[$n("undo",Un(x.undo,`${kt}Z`),()=>Jr(it),{disabled:0===rt.current.length}),$n("redo",Un(x.redo,Ct?"⇧⌘Z":"Ctrl+Y"),()=>Jr(ct),{disabled:0===nt.current.length}),Bn("a"),$n("cut",Un(x.cut,`${kt}X`),()=>Jr(()=>xn(!0))),$n("copy",Un(x.copy,`${kt}C`),()=>Jr(()=>xn(!1))),$n("paste",Un(x.paste,`${kt}V`),()=>yn("all")),$n("pasteValues",x.pasteValues,()=>yn("values")),$n("pasteFormats",x.pasteFormats,()=>yn("formats")),Bn("b"),$n("find",Un(x.findReplace,`${kt}F`),()=>{gr(!0),setTimeout(()=>Nr.current?.focus(),0)}),$n("clear",Un(x.clearValues,"Delete"),()=>Jr(()=>Rr(e=>C(e,Wt.range))))],_n=[{type:"submenu",key:"freeze",label:x.freeze,items:Yn},{type:"checkbox",key:"gridlines",label:x.gridlines,checked:er,onSelect:()=>tr(e=>!e)},{type:"checkbox",key:"formulas",label:Un(x.showFormulas,`${kt}\``),checked:rr,onSelect:()=>nr(e=>!e)}],Qn=[$n("rowAbove",x.rowsAbove,()=>un("row",!1)),$n("rowBelow",x.rowsBelow,()=>un("row",!0)),$n("colLeft",x.columnsLeft,()=>un("col",!1)),$n("colRight",x.columnsRight,()=>un("col",!0)),Bn("a"),$n("sheet",x.sheet,Tn),{type:"submenu",key:"fn",label:x.function,items:Vn}],Zn=[{type:"submenu",key:"number",label:x.number,items:Kn},Bn("a"),$n("bold",Un(x.bold,`${kt}B`),()=>an("bold")),$n("italic",Un(x.italic,`${kt}I`),()=>an("italic")),$n("underline",Un(x.underline,`${kt}U`),()=>an("underline")),$n("strike",x.strikethrough,()=>an("strike")),{type:"submenu",key:"size",label:x.fontSize,items:Xn},Bn("b"),{type:"submenu",key:"align",label:x.alignment,items:Wn},{type:"submenu",key:"borders",label:x.borders,items:Hn},$n("wrap",x.wrapText,()=>an("wrap")),$n("merge",x.mergeCells,pn),Bn("c"),$n("clearFormat",x.clearFormatting,()=>Jr(()=>Rr(e=>se(e,Wt.range,()=>({})))))],qn=[$n("asc",x.sortAscending,()=>mn(!0)),$n("desc",x.sortDescending,()=>mn(!1)),Bn("a"),{type:"checkbox",key:"filter",label:x.filter,checked:!!Ot.filter,onSelect:gn},Bn("b"),$n("hideRows",x.hideRows,()=>fn("row")),$n("hideCols",x.hideColumns,()=>fn("col")),$n("unhideRows",x.unhideRows,()=>hn("row"),{disabled:!Ot.hiddenRows.length}),$n("unhideCols",x.unhideColumns,()=>hn("col"),{disabled:!Ot.hiddenCols.length})],Jn="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=xt("div",{className:"mx-1 h-4 w-px bg-line"}),ro=e=>e.preventDefault(),no=(e,t,r,n={})=>xt(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)=>xt(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:bt(wt,{children:[t,xt("span",{className:"h-0.5 w-4 rounded-sm",style:{background:Gt[r]??("color"===r?"var(--ink)":"var(--line)")}})]}),children:({close:t})=>xt(Me,{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=Ot.formats[O(_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 xt("textarea",{ref:kr,"aria-label":x.cellEditor,value:_t.text,spellCheck:!1,rows:1,onChange:e=>Wr(e.target.value,e.target.selectionStart),onSelect:qr,onKeyDown:Zr,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 bt("div",{role:"listbox","aria-label":x.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)=>bt("div",{role:"option","aria-selected":t===_t.suggestion,onPointerDown:t=>{t.preventDefault(),t.stopPropagation(),Qr(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:[xt("span",{className:"font-medium",children:e}),xt("span",{className:"truncate "+(t===_t.suggestion?"text-accent-text":"text-ink-muted"),children:x.functionHelp(e)})]},e)),bt("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 bt("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:[bt("div",{className:"font-mono",children:[Yr.name,"(",e.map((t,r)=>bt("span",{children:[r>0?", ":"",xt("span",{className:r===Math.min(Yr.argIndex,e.length-1)?"font-semibold text-ink":"",children:t})]},t+r)),")"]}),xt("div",{className:"mt-0.5",children:x.functionHelp(Yr.name)})]})}return null},io=ar?ar.values.filter(e=>e.toLowerCase().includes(ar.search.toLowerCase())):[];return bt("div",{ref:Tr,className:"flex h-full flex-col bg-surface text-ink",children:[!h&&xt(Ne,{title:`${uo=Ze||x.untitled,uo.length>24?`${uo.slice(0,23)}…`:uo} - Spreadsheets`}),xt("input",{ref:Bt,type:"file",accept:Et,onChange:e=>{const t=e.target.files?.[0];Bt.current&&(Bt.current.value=""),t&&En(t)},className:"hidden"}),bt("div",{className:"flex shrink-0 items-center gap-1 border-b border-line bg-surface-sunken px-2 py-1",children:[s&&xt(Ie,{"aria-label":x.backToFiles,title:x.backToFiles,size:"sm",variant:"ghost",onClick:()=>{zt(),s()},children:xt(De,{name:"arrow-left",size:16})}),cr?xt("input",{type:"text",value:Ze,autoFocus:!0,"aria-label":x.rename,onChange:e=>qe(e.target.value),onBlur:()=>{sr(!1);const t=Ze.trim()||x.untitled;if(t!==Ze&&qe(t),e&&t!==dt.current){const r=dt.current;dt.current=t,e.store.rename(e.id,t).catch(()=>{Xe.error(x.renameFailed),dt.current=r,qe(r)})}},onKeyDown:e=>{"Enter"===e.key&&(e.currentTarget.blur(),Dr())},className:"w-40 rounded border border-line bg-surface px-2 py-0.5 text-sm font-medium text-ink"}):xt("button",{type:"button",onClick:()=>sr(!0),title:x.rename,className:"max-w-[200px] truncate rounded px-2 py-0.5 text-sm font-medium text-ink hover:bg-line-subtle",children:Ze||x.untitled}),xt(ze,{trigger:x.menuFile,items:Gn,align:"start",triggerClassName:Jn}),xt(ze,{trigger:x.menuEdit,items:jn,align:"start",triggerClassName:Jn}),xt(ze,{trigger:x.menuView,items:_n,align:"start",triggerClassName:Jn}),xt(ze,{trigger:x.menuInsert,items:Qn,align:"start",triggerClassName:Jn}),xt(ze,{trigger:x.menuFormat,items:Zn,align:"start",triggerClassName:Jn}),xt(ze,{trigger:x.menuData,items:qn,align:"start",triggerClassName:Jn}),(e||l)&&xt("span",{className:"office-save-state",children:xt(Ce,{...e?be(Tt.state,Rt.save):{tone:Fe!==st.current?"off-unsaved":"off",label:Fe!==st.current?x.noStoreEdited:x.noStoreClean}})})]}),St&&bt("div",{className:"office-conflict",role:"alert",children:[xt("span",{children:x.conflict}),xt(Re,{variant:"secondary",onClick:u,children:x.reload})]}),bt("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(x.undo,xt(De,{name:"undo",size:16}),()=>Jr(it),{disabled:0===rt.current.length}),no(x.redo,xt(De,{name:"redo",size:16}),()=>Jr(ct),{disabled:0===nt.current.length}),no(x.formatPainter,xt(De,{name:"copy-style",size:16}),()=>lr(e=>e?null:Gt),{pressed:!!or}),to,no(x.formatCurrency,xt(De,{name:"dollar",size:16}),()=>cn(Gt.numFmt===p.currency?"General":p.currency),{pressed:Gt.numFmt===p.currency}),no(x.formatPercent,xt(De,{name:"percent",size:16}),()=>cn(/%/.test(Gt.numFmt??"")?"General":"0%"),{pressed:/%/.test(Gt.numFmt??"")}),no(x.fewerDecimals,xt("span",{className:"text-xs",children:".0"}),()=>sn(-1)),no(x.moreDecimals,xt("span",{className:"text-xs",children:".00"}),()=>sn(1)),xt(ze,{trigger:bt("span",{title:x.number,className:"flex items-center gap-0.5",children:["123",xt(De,{name:"chevron-down",size:12})]}),"aria-label":x.number,items:Kn,align:"start",triggerClassName:eo}),to,xt(ze,{trigger:bt("span",{title:x.fontSize,className:"flex items-center gap-0.5",children:[Gt.fontSize??d,xt(De,{name:"chevron-down",size:12})]}),"aria-label":x.fontSize,items:Xn,align:"start",triggerClassName:eo}),no(x.bold,xt(De,{name:"bold",size:16}),()=>an("bold"),{pressed:!!Gt.bold}),no(x.italic,xt(De,{name:"italic",size:16}),()=>an("italic"),{pressed:!!Gt.italic}),no(x.underline,xt(De,{name:"underline",size:16}),()=>an("underline"),{pressed:!!Gt.underline}),no(x.strikethrough,xt(De,{name:"strike",size:16}),()=>an("strike"),{pressed:!!Gt.strike}),oo(x.textColor,xt(De,{name:"text-color",size:14}),"color"),oo(x.fillColor,xt(De,{name:"palette",size:14}),"fill"),to,xt(ze,{trigger:bt("span",{title:x.borders,className:"flex items-center gap-0.5",children:[xt(De,{name:"border-all",size:16}),xt(De,{name:"chevron-down",size:12})]}),"aria-label":x.borders,items:Hn,align:"start",triggerClassName:eo}),no(x.mergeCells,xt(De,{name:"grid",size:16}),pn,{pressed:Ot.merges.some(e=>Q(e,Yt.row,Yt.col))}),xt(ze,{trigger:bt("span",{title:x.alignment,className:"flex items-center gap-0.5",children:["center"===Gt.align?xt(De,{name:"align-center",size:16}):"right"===Gt.align?xt(De,{name:"align-right",size:16}):xt(De,{name:"align-left",size:16}),xt(De,{name:"chevron-down",size:12})]}),"aria-label":x.alignment,items:Wn,align:"start",triggerClassName:eo}),no(x.wrapText,xt(De,{name:"wrap",size:16}),()=>an("wrap"),{pressed:!!Gt.wrap}),to,no(x.filter,xt(De,{name:"filter",size:16}),gn,{pressed:!!Ot.filter}),no(x.sortAscending,xt(De,{name:"sort",size:16}),()=>mn(!0)),xt(ze,{trigger:bt("span",{title:x.functions,className:"flex items-center gap-0.5 text-sm",children:["Σ",xt(De,{name:"chevron-down",size:12})]}),"aria-label":x.functions,items:Vn,align:"end",triggerClassName:eo})]}),bt("div",{className:"flex shrink-0 items-start gap-1 border-b border-line bg-surface px-2 py-1",children:[xt("input",{type:"text","aria-label":x.nameBox,spellCheck:!1,value:fr??(_t&&Xr?b(_t.row,_t.col):Z(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<Ot.rowCount&&e.c2<Ot.colCount&&(Vt({active:{row:e.r1,col:e.c1},range:z(Ot,e)}),$t.current?.scrollTo({row:e.r1,col:e.c1})),hr(null),Dr()}},className:"w-20 shrink-0 rounded border border-line bg-surface px-2 py-0.5 text-center text-xs text-ink"}),xt("span",{className:"select-none pt-0.5 font-serif text-sm italic text-ink-faint","aria-hidden":"true",children:"fx"}),xt("textarea",{ref:Cr,"aria-label":x.formulaBar,spellCheck:!1,rows:1,value:_t?_t.text:A(jt,Gt),onFocus:()=>{_t?_t.inBar||Qt({..._t,inBar:!0}):$r(Yt,{inBar:!0,mode:"edit"})},onChange:e=>{_t&&Wr(e.target.value,e.target.selectionStart)},onSelect:qr,onKeyDown:Zr,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&&bt("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:[xt("div",{className:"w-44",children:xt(Le,{ref:Nr,size:"sm","aria-label":x.find,placeholder:x.find,value:pr,onChange:e=>vr(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),Rn(e.shiftKey?-1:1))}})}),xt("span",{className:"w-16 text-center text-ink-muted",children:pr?x.hitCount(Dn<0?0:Dn+1,Sn.length):""}),no(x.previous,xt(De,{name:"arrow-up",size:14}),()=>Rn(-1)),no(x.next,xt(De,{name:"arrow-down",size:14}),()=>Rn(1)),xt("div",{className:"w-44",children:xt(Le,{size:"sm","aria-label":x.replaceWith,placeholder:x.replaceWith,value:wr,onChange:e=>xr(e.target.value)})}),xt(Re,{size:"sm",variant:"secondary",disabled:!Sn.length,onClick:()=>{if(Dn<0)return void Rn(1);const{row:e,col:t}=Sn[Dn];Rr(r=>{const n=te(q(r,e,t),pr,wr,br);return n===q(r,e,t)?r:fe(r,[{row:e,col:t,raw:n}])}),Rn(1)},children:x.replace}),xt(Re,{size:"sm",variant:"secondary",disabled:!Sn.length,onClick:()=>{let e=0;Rr(t=>{const r=[];for(const{row:e,col:n}of Sn){const o=te(q(t,e,n),pr,wr,br);o!==q(t,e,n)&&r.push({row:e,col:n,raw:o})}return e=r.length,fe(t,r)}),Xe.success(x.replacedCount(e))},children:x.replaceAll}),xt(Te,{label:x.matchCase,checked:br.matchCase,onChange:e=>yr(t=>({...t,matchCase:e}))}),xt(Te,{label:x.wholeCell,checked:br.wholeCell,onChange:e=>yr(t=>({...t,wholeCell:e}))}),xt(Te,{label:x.inFormulas,checked:br.inFormulas,onChange:e=>yr(t=>({...t,inFormulas:e}))}),xt("div",{className:"ml-auto",children:no(x.close,xt(De,{name:"close",size:14}),()=>{gr(!1),Dr()})})]}),xt("div",{className:"min-h-0 flex-1",children:xt(ft,{ref:$t,sheet:Ot,sheetIndex:Lt,evaluator:Pt,filterHidden:Ut,selection:Wt,showGridlines:er,showFormulas:rr,clipRange:qt&&qt.sheetId===Ot.id?qt.range:null,highlights:jr,pointing:Gr,onSelect:zn,onPoint:_r,onEdit:e=>{Br(),Fr(e),$r(K(Ot,e.row,e.col)?{row:K(Ot,e.row,e.col).r1,col:K(Ot,e.row,e.col).c1}:e)},onFill:e=>{const t=Wt.range;Rr(r=>F(r,t,e)),Vt({active:Wt.active,range:e})},onResizeCol:(e,t)=>Rr(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)=>Rr(r=>({...r,rowHeights:{...r.rowHeights,[e]:t}})),onAutoFitCol:e=>{const t=Math.max(40,$t.current?.measureColumn(e)??0);Rr(r=>({...r,colWidths:{...r.colWidths,[e]:t}}))},onAutoFitRow:e=>Rr(t=>{const r={...t.rowHeights};return delete r[e],{...t,rowHeights:r}}),onHeaderMenu:Fn,onFilterButton:In,renderEditor:e=>bt(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?Lr(e,l[0],l[1]):Ir(e,l[0],l[1]);return void(t.shiftKey?Or(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 $t.current?.scrollTo({row:t,col:r})}return void Fr(Ir(Wt.active,o,l))}if("Home"===n)return t.preventDefault(),void Fr(r?{row:Ot.frozenRows,col:Ot.frozenCols}:{row:Wt.active.row,col:0});if("End"===n){t.preventDefault();const e=ue(Ot);return void Fr(r?{row:e?.row??0,col:e?.col??0}:{row:Wt.active.row,col:Math.max(0,(Ot.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(Ot.rowCount-1,Wt.active.row+e)),col:Wt.active.col})}if("Delete"===n||"Backspace"===n)return t.preventDefault(),void Rr(e=>C(e,Wt.range));if("F2"===n)return t.preventDefault(),void $r(Wt.active);if(" "===n&&(r||t.shiftKey))return t.preventDefault(),void Vt(r?{active:Wt.active,range:{r1:0,c1:Wt.range.c1,r2:Ot.rowCount-1,c2:Wt.range.c2}}:{active:Wt.active,range:{r1:Wt.range.r1,c1:0,r2:Wt.range.r2,c2:Ot.colCount-1}});if(!r)return!t.altKey||"="!==n&&"≠"!==n?1!==n.length||t.altKey?void("Process"!==n&&229!==t.keyCode||$r(Wt.active,{text:""})):(t.preventDefault(),void $r(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:Ot.rowCount-1,c2:Ot.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?Rr(t=>F(t,{...e,r2:e.r1},e)):e.r1>0&&Rr(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?Rr(t=>F(t,{...e,c2:e.c1},e)):e.c1>0&&Rr(t=>F(t,{...e,c1:e.c1-1,c2:e.c1-1},{...e,c1:e.c1-1})))}case";":return t.preventDefault(),void Rr(e=>E(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||xn(!1,e)},onCut:e=>{_t||xn(!0,e)},onPaste:e=>{_t||(e.preventDefault(),bn(e.clipboardData.getData("text/plain"),"all"))}})}),bt("div",{className:"flex shrink-0 items-center border-t border-line bg-surface-sunken",children:[bt("div",{className:"flex min-w-0 flex-1 items-center gap-0.5 overflow-x-auto px-1 py-1",children:[xt(Ie,{"aria-label":x.addSheet,title:x.addSheet,size:"sm",variant:"ghost",onClick:Tn,children:xt(De,{name:"add",size:14})}),Fe.map((e,t)=>xt("button",{type:"button",onClick:()=>(e=>{_t&&!Gr&&Br(),Qe(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===Lt?"bg-accent-tint text-accent-text":"text-ink-muted hover:bg-line-subtle hover:text-ink"),children:ur?.index===t?xt("input",{type:"text",value:ur.name,autoFocus:!0,"aria-label":x.rename,onChange:e=>dr({index:t,name:e.target.value}),onBlur:Mn,onKeyDown:e=>{e.stopPropagation(),"Enter"===e.key&&Mn()},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))]}),On&&On.count>0&&bt("div",{className:"flex shrink-0 items-center gap-3 border-l border-line px-3 py-1 text-xs text-ink-muted",children:[On.numbers>0&&bt("span",{children:[x.statSum,": ",Pn(On.sum)]}),null!==On.average&&bt("span",{children:[x.statAverage,": ",Pn(On.average)]}),bt("span",{children:[x.statCount,": ",On.count]}),On.numbers>0&&bt("span",{children:[x.statMin,": ",Pn(On.min)]}),On.numbers>0&&bt("span",{children:[x.statMax,": ",Pn(On.max)]})]})]}),Er.state&&xt(Ae,{...Er.props,items:(so=Er.state.data.kind,[$n("cut",x.cut,()=>Jr(()=>xn(!0))),$n("copy",x.copy,()=>Jr(()=>xn(!1))),$n("paste",x.paste,()=>yn("all")),$n("pasteValues",x.pasteValues,()=>yn("values")),Bn("a"),..."col"!==so?[$n("rowAbove",x.rowsAbove,()=>un("row",!1)),$n("rowBelow",x.rowsBelow,()=>un("row",!0))]:[],..."row"!==so?[$n("colLeft",x.columnsLeft,()=>un("col",!1)),$n("colRight",x.columnsRight,()=>un("col",!0))]:[],Bn("b"),..."col"!==so?[$n("delRows",x.deleteRows,()=>dn("row"),{danger:!0})]:[],..."row"!==so?[$n("delCols",x.deleteColumns,()=>dn("col"),{danger:!0})]:[],$n("clear",x.clearValues,()=>Jr(()=>Rr(e=>C(e,Wt.range)))),Bn("c"),..."col"!==so?[$n("hideRows",x.hideRows,()=>fn("row"))]:[],..."row"!==so?[$n("hideCols",x.hideColumns,()=>fn("col"))]:[],..."col"!==so&&Ot.hiddenRows.length?[$n("unhideRows",x.unhideRows,()=>hn("row"))]:[],..."row"!==so&&Ot.hiddenCols.length?[$n("unhideCols",x.unhideColumns,()=>hn("col"))]:[]])}),Sr.state&&xt(Ae,{...Sr.props,items:(co=Sr.state.data,[$n("rename",x.rename,()=>dr({index:co,name:Fe[co].name})),$n("duplicate",x.duplicate,()=>{lt(e=>M(e,co,X(e,Fe[co].name))),Qe(co+1)}),$n("left",x.moveLeft,()=>An(co,-1),{disabled:0===co}),$n("right",x.moveRight,()=>An(co,1),{disabled:co===Fe.length-1}),{type:"submenu",key:"colour",label:x.tabColor,items:[$n("none",x.noColor,()=>lt(e=>e.map((e,t)=>t===co?{...e,tabColor:void 0}:e))),...ht.slice(7,17).map(e=>$n(e,bt("span",{className:"flex items-center gap-2",children:[xt("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))))]},Bn("a"),$n("delete",x.deleteSheet,()=>{(async e=>{Fe.length<=1||(null===ue(Fe[e])||await Ke({title:x.deleteSheetTitle,message:x.deleteSheetMessage(Fe[e].name),confirmLabel:x.deleteSheet}))&&(lt(t=>T(t,e)),Qe(t=>t>e||t>=Fe.length-1?Math.max(0,t-1):t))})(co)},{danger:!0,disabled:Fe.length<=1})])}),ar&&bt(Ue,{portal:!0,minWidth:230,onClose:()=>ir(null),style:{position:"fixed",left:ar.x,top:ar.y},children:[xt(Be,{onClick:()=>Ln(ar.col,!0),children:x.sortAscending}),xt(Be,{onClick:()=>Ln(ar.col,!1),children:x.sortDescending}),xt($e,{}),xt("div",{className:"px-2 py-1",children:xt(Le,{size:"sm","aria-label":x.find,placeholder:x.find,value:ar.search,onChange:e=>ir({...ar,search:e.target.value})})}),xt("div",{className:"max-h-52 overflow-y-auto px-2 py-1",children:io.map(e=>xt("div",{className:"py-0.5",children:xt(Te,{label:e||x.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))}),bt("div",{className:"flex items-center justify-between gap-2 border-t border-line px-2 py-1",children:[xt(Re,{size:"sm",variant:"ghost",onClick:()=>ir({...ar,unticked:new Set}),children:x.clear}),xt(Re,{size:"sm",variant:"primary",onClick:()=>{if(!ar)return;const{col:e,unticked:t}=ar;ir(null),Jr(()=>Rr(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:x.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{Rt as OpenSpreadsheet,Dt as SpreadsheetById,Tt as SpreadsheetPane,St as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{titleOf as r}from"./chunk-XYVQTQ6N.js";var e=r=>new Promise((e,t)=>{const a=new FileReader;a.onload=()=>e(String(a.result)),a.onerror=()=>t(a.error??new Error("Unreadable picture")),a.readAsDataURL(r)});async function t(t,a,o={}){const{importPptx:n}=await(import("./pptxImport-
|
|
1
|
+
import{titleOf as r}from"./chunk-XYVQTQ6N.js";var e=r=>new Promise((e,t)=>{const a=new FileReader;a.onload=()=>e(String(a.result)),a.onerror=()=>t(a.error??new Error("Unreadable picture")),a.readAsDataURL(r)});async function t(t,a,o={}){const{importPptx:n}=await(import("./pptxImport-OACGHWQ6.js")),{document:i,notes:s}=await n(a,{storeImage:o.storeImage??e,onProgress:o.onProgress,signal:o.signal}),c=r(a.name),m=await t.create(c);try{await t.save(m.id,i,m.version)}catch(r){throw await t.remove(m.id).catch(()=>{}),r}return{id:m.id,title:c,notes:s}}export{t as importDeckFile};
|