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