efficient-office 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Documents-ISV66NLW.js +1 -0
- package/dist/Slides-JI73C3NW.js +1 -0
- package/dist/SlidesEditor-5WCXE27J.js +1 -0
- package/dist/Spreadsheet-I3RO4HSS.js +1 -0
- package/dist/chunk-3RFDQOTI.js +1 -0
- package/dist/chunk-4NKXNXKY.js +1 -0
- package/dist/chunk-6ZFEBY6H.js +1 -0
- package/dist/chunk-7K7AY3V3.js +1 -0
- package/dist/chunk-B2X3NIQR.js +1 -0
- package/dist/chunk-B32ASXHM.js +1 -0
- package/dist/chunk-B6JN7D6G.js +1 -0
- package/dist/{chunk-QSM7NWZ2.js → chunk-BGAR3P46.js} +1 -1
- package/dist/chunk-COXKOQPZ.js +1 -0
- package/dist/chunk-GLT7O6TV.js +1 -0
- package/dist/{chunk-E4N3DBYM.js → chunk-HU4RI2OM.js} +1 -1
- package/dist/chunk-I3AC6PYR.js +1 -0
- package/dist/chunk-JCSB2PHB.js +1 -0
- package/dist/{chunk-USKJW3BA.js → chunk-MDG2ADZ7.js} +1 -1
- package/dist/chunk-PMGQ5GUH.js +1 -0
- package/dist/chunk-PXOQN7D6.js +1 -0
- package/dist/chunk-Q7NVDOCX.js +1 -0
- package/dist/chunk-XYVQTQ6N.js +1 -0
- package/dist/{deckPdf-Q4OXQ7HV.js → deckPdf-4RC7QJ45.js} +1 -1
- package/dist/documents/documents.css +4 -0
- package/dist/documents/index.d.ts +22 -7
- package/dist/documents/index.js +1 -1
- package/dist/docxPdf-EW5I5JR3.js +1 -0
- package/dist/importDocument-274VK7OM.js +1 -0
- package/dist/importSpreadsheet-4U3KEJ76.js +1 -0
- package/dist/pptxImport-Y7TB6PYP.js +1 -0
- package/dist/slides/index.d.ts +534 -7
- package/dist/slides/index.js +1 -1
- package/dist/slides/slides.css +102 -0
- package/dist/spreadsheet/index.d.ts +62 -44
- package/dist/spreadsheet/index.js +1 -1
- package/dist/spreadsheet/spreadsheet.css +4 -0
- package/dist/words-DK_ajpEa.d.ts +67 -0
- package/dist/workbookPdf-C5SSN226.js +1 -0
- package/package.json +2 -2
- package/dist/Documents-HT324TAY.js +0 -1
- package/dist/Slides-EUDBOA5K.js +0 -1
- package/dist/SlidesEditor-6KDRHX4H.js +0 -1
- package/dist/Spreadsheet-SOF7NDLP.js +0 -1
- package/dist/chunk-2AKHYM66.js +0 -1
- package/dist/chunk-2PIEDEY5.js +0 -1
- package/dist/chunk-2TZUCKZ7.js +0 -1
- package/dist/chunk-3SRMKGQW.js +0 -1
- package/dist/chunk-AVUZSUQD.js +0 -1
- package/dist/chunk-SB3YS3LH.js +0 -1
- package/dist/chunk-XKOHIZO5.js +0 -1
- package/dist/chunk-YYHJJIA4.js +0 -1
- package/dist/docxPdf-NCSEKI4J.js +0 -1
- package/dist/options-Djr917yc.d.ts +0 -10
- package/dist/pptxImport-QEKBZWT2.js +0 -1
- package/dist/workbookPdf-OJDSHKRR.js +0 -1
package/dist/slides/slides.css
CHANGED
|
@@ -70,3 +70,105 @@
|
|
|
70
70
|
.slides-list-rows { flex: 1; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
|
|
71
71
|
.slides-list-row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
|
|
72
72
|
.slides-list-date { flex: 1; text-align: right; font-size: 14px; opacity: 0.7; }
|
|
73
|
+
/* A deck opened from a PowerPoint file says, once, what didn't come across. */
|
|
74
|
+
.slides-with-note { display: flex; flex-direction: column; height: 100%; }
|
|
75
|
+
.slides-with-note-body { flex: 1; min-height: 0; }
|
|
76
|
+
.slides-import-note { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; color: var(--status-warning-text, var(--ink)); background: var(--status-warning-bg, var(--surface-raised)); border-bottom: 1px solid var(--line); }
|
|
77
|
+
.slides-import-note > span { flex: 1; }
|
|
78
|
+
|
|
79
|
+
/* Slides parity (2026-11-05): the text row, menus, panels, other editors, comments. */
|
|
80
|
+
.slides-toolbar { align-items: center; flex-wrap: wrap; }
|
|
81
|
+
.slides-texttools { background: var(--surface-raised); gap: 1px; }
|
|
82
|
+
.slides-tool-gap { width: 1px; height: 18px; margin: 0 4px; background: var(--line); }
|
|
83
|
+
.slides-tool-font { width: 150px; }
|
|
84
|
+
.slides-tool-size { width: 70px; }
|
|
85
|
+
.slides-export-trigger { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
|
|
86
|
+
.slides-shape-grid { display: grid; grid-template-columns: repeat(8, 30px); gap: 2px; padding: 4px; }
|
|
87
|
+
.slides-shape-grid button { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 4px; background: transparent; color: var(--ink); cursor: pointer; }
|
|
88
|
+
.slides-shape-grid button:hover, .slides-shape-grid button:focus-visible { background: var(--surface-raised); }
|
|
89
|
+
|
|
90
|
+
.slides-text-edit [data-paragraph] { min-height: 1em; }
|
|
91
|
+
.slides-cell-edit { min-width: 1em; outline: 2px solid var(--slides-accent); user-select: text; cursor: text; }
|
|
92
|
+
.slides-handle.slides-end { border-radius: 50%; }
|
|
93
|
+
.slides-handle.slides-end[data-held] { background: var(--slides-accent); }
|
|
94
|
+
.slides-lock { position: absolute; right: -8px; top: -8px; width: 12px; height: 12px; border-radius: 3px; background: var(--slides-accent); }
|
|
95
|
+
.slides-visitor { position: absolute; box-sizing: border-box; border: 2px solid; pointer-events: none; }
|
|
96
|
+
.slides-visitor-name { position: absolute; right: -2px; top: -20px; padding: 0 6px; border-radius: 4px 4px 0 0; color: #fff; font-size: 11px; line-height: 18px; white-space: nowrap; }
|
|
97
|
+
.slides-cells { position: absolute; border: 2px solid var(--slides-accent); background: color-mix(in srgb, var(--slides-accent) 10%, transparent); pointer-events: none; }
|
|
98
|
+
.slides-grid { position: absolute; inset: 0; pointer-events: none; background-image: linear-gradient(to right, color-mix(in srgb, var(--slides-accent) 18%, transparent) 1px, transparent 1px), linear-gradient(to bottom, color-mix(in srgb, var(--slides-accent) 18%, transparent) 1px, transparent 1px); }
|
|
99
|
+
.slides-pin { position: absolute; z-index: 2; min-width: 20px; height: 20px; padding: 0 5px; border: 0; border-radius: 10px 10px 10px 0; background: #ef9f27; color: #412402; font-size: 11px; font-weight: 600; cursor: pointer; }
|
|
100
|
+
.slides-preview { pointer-events: none; }
|
|
101
|
+
|
|
102
|
+
.slides-thumb-image { position: relative; }
|
|
103
|
+
.slides-thumb[data-skipped] .slides-thumb-image { opacity: 0.45; }
|
|
104
|
+
.slides-thumb-skip { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: var(--ink); }
|
|
105
|
+
.slides-thumb-visitors { position: absolute; right: 3px; bottom: 3px; display: flex; gap: 2px; }
|
|
106
|
+
.slides-thumb-visitors span { width: 8px; height: 8px; border-radius: 50%; border: 1px solid #fff; }
|
|
107
|
+
.slides-visitors { display: inline-flex; margin-right: 4px; }
|
|
108
|
+
|
|
109
|
+
.slides-themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
|
|
110
|
+
.slides-theme-tile { display: flex; flex-direction: column; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink); font-size: 11px; cursor: pointer; overflow: hidden; }
|
|
111
|
+
.slides-theme-tile[aria-pressed="true"] { border: 2px solid var(--slides-accent); padding: 2px; }
|
|
112
|
+
.slides-swatches { display: flex; gap: 4px; }
|
|
113
|
+
.slides-swatches span { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line); }
|
|
114
|
+
.slides-pills { display: flex; flex-wrap: wrap; gap: 4px; }
|
|
115
|
+
.slides-pill { padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink); font-size: 12px; cursor: pointer; }
|
|
116
|
+
.slides-pill[aria-checked="true"] { border-color: var(--slides-accent); background: color-mix(in srgb, var(--slides-accent) 12%, transparent); }
|
|
117
|
+
.slides-animation { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
|
|
118
|
+
.slides-animation-head { display: flex; align-items: center; gap: 4px; }
|
|
119
|
+
.slides-animation-number { min-width: 16px; opacity: 0.7; }
|
|
120
|
+
.slides-animation-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
121
|
+
.slides-hint { opacity: 0.7; }
|
|
122
|
+
.slides-empty { padding: 12px; opacity: 0.7; }
|
|
123
|
+
.slides-actions-words { gap: 4px; }
|
|
124
|
+
.slides-actions-end { justify-content: flex-end; }
|
|
125
|
+
.slides-actions-between { justify-content: space-between; align-items: center; }
|
|
126
|
+
.slides-grid-edit { display: grid; gap: 2px; }
|
|
127
|
+
.slides-grid-cell { min-width: 0; height: 26px; padding: 0 4px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); color: var(--ink); font: inherit; font-size: 12px; }
|
|
128
|
+
.slides-grid-cell[data-head] { background: var(--surface-raised); }
|
|
129
|
+
.slides-check { display: flex; align-items: center; gap: 6px; font-size: 12px; }
|
|
130
|
+
|
|
131
|
+
.slides-comments .slides-section:first-of-type { position: sticky; top: 0; z-index: 1; background: var(--surface); }
|
|
132
|
+
.slides-composer { position: relative; display: flex; flex-direction: column; gap: 6px; }
|
|
133
|
+
.slides-mentions { position: absolute; z-index: 3; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 4px 0; list-style: none; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
|
|
134
|
+
.slides-mentions li { padding: 4px 10px; cursor: pointer; }
|
|
135
|
+
.slides-mentions li:hover { background: var(--surface-raised); }
|
|
136
|
+
.slides-thread { display: flex; flex-direction: column; gap: 8px; margin: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
|
|
137
|
+
.slides-thread[data-focus] { border-color: var(--slides-accent); }
|
|
138
|
+
.slides-thread[data-resolved] { opacity: 0.7; }
|
|
139
|
+
.slides-thread-where { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--slides-accent); font-size: 11px; cursor: pointer; }
|
|
140
|
+
.slides-comment { display: flex; flex-direction: column; gap: 4px; }
|
|
141
|
+
.slides-comment-head { display: flex; align-items: center; gap: 6px; }
|
|
142
|
+
.slides-comment-author { font-weight: 600; }
|
|
143
|
+
.slides-comment-time { flex: 1; font-size: 11px; opacity: 0.6; }
|
|
144
|
+
.slides-comment-body { margin: 0; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
145
|
+
.slides-avatar { width: 22px; height: 22px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: color-mix(in srgb, var(--slides-accent) 18%, transparent); color: var(--ink); font-size: 10px; font-weight: 600; }
|
|
146
|
+
.slides-versions { margin: 0; padding: 0; list-style: none; }
|
|
147
|
+
.slides-versions li { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
|
|
148
|
+
.slides-versions li[data-current] { background: var(--surface-raised); }
|
|
149
|
+
.slides-version-name { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--ink); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
|
|
150
|
+
.slides-versions small { opacity: 0.7; }
|
|
151
|
+
|
|
152
|
+
.slides-starters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
|
|
153
|
+
.slides-starter { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--ink); font-size: 12px; cursor: pointer; }
|
|
154
|
+
.slides-starter:hover { border-color: var(--slides-accent); }
|
|
155
|
+
.slides-starter-thumb { display: block; width: 128px; height: 72px; overflow: hidden; border-radius: 3px; }
|
|
156
|
+
.slides-starter-blank { display: block; width: 100%; height: 100%; background: #ffffff; border: 1px solid var(--line); box-sizing: border-box; }
|
|
157
|
+
/* The file list Documents and Spreadsheet share (./FileList.tsx), laid out as
|
|
158
|
+
Slides' deck list is. The build appends this to documents.css and
|
|
159
|
+
spreadsheet.css, so a host loads it with the app's own stylesheet. */
|
|
160
|
+
.office-filelist { display: flex; flex-direction: column; height: 100%; background: var(--surface); color: var(--ink); }
|
|
161
|
+
.office-filelist-head { display: flex; align-items: center; gap: 8px; padding: 16px; border-bottom: 1px solid var(--line); }
|
|
162
|
+
.office-filelist-head h2 { flex: 1; margin: 0; font-size: 16px; font-weight: 500; }
|
|
163
|
+
.office-filelist-empty { padding: 24px; }
|
|
164
|
+
.office-filelist-rows { flex: 1; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
|
|
165
|
+
.office-filelist-row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
|
|
166
|
+
.office-filelist-date { flex: 1; text-align: right; font-size: 14px; opacity: 0.7; }
|
|
167
|
+
.office-filelist-input { display: none; }
|
|
168
|
+
.office-conflict { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; background: var(--status-warning-bg, var(--surface-raised)); border-bottom: 1px solid var(--line); font-size: 12px; }
|
|
169
|
+
.office-open-failed { padding: 24px; }
|
|
170
|
+
.office-save-state { margin-left: auto; }
|
|
171
|
+
.office-filelist-busy { padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--ink-muted, var(--ink)); background: var(--surface-sunken, var(--surface)); }
|
|
172
|
+
.office-filelist-rename { flex: 0 1 320px; min-width: 160px; }
|
|
173
|
+
.office-filelist-open { display: inline-flex; align-items: center; gap: 6px; }
|
|
174
|
+
.office-filelist:focus { outline: none; }
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, ComponentType } from 'react';
|
|
3
3
|
import { SpreadsheetPreviewData } from 'efficient-shell/apps';
|
|
4
|
-
import { P as PdfOptions } from '../
|
|
4
|
+
import { C as ChooseOfficeFile, F as FileWords, P as PdfOptions } from '../words-DK_ajpEa.js';
|
|
5
|
+
export { E as ENGLISH_FILE_WORDS, O as OfficeFileChoice, a as OfficeFileRequest, Z as ZH_HANS_FILE_WORDS, h as hasExtension } from '../words-DK_ajpEa.js';
|
|
5
6
|
|
|
6
7
|
interface CellRange {
|
|
7
8
|
r1: number;
|
|
@@ -181,6 +182,54 @@ declare function createSheetBridge(): {
|
|
|
181
182
|
};
|
|
182
183
|
type SheetBridge = ReturnType<typeof createSheetBridge>;
|
|
183
184
|
|
|
185
|
+
/** What a store holds for one spreadsheet. */
|
|
186
|
+
interface Workbook {
|
|
187
|
+
sheets: Sheet[];
|
|
188
|
+
}
|
|
189
|
+
interface SpreadsheetSummary {
|
|
190
|
+
id: string;
|
|
191
|
+
title: string;
|
|
192
|
+
updatedAt: string;
|
|
193
|
+
}
|
|
194
|
+
interface StoredSpreadsheet {
|
|
195
|
+
id: string;
|
|
196
|
+
title: string;
|
|
197
|
+
/** The workbook as stored. Null for a new spreadsheet, which opens on one blank sheet. */
|
|
198
|
+
workbook: Workbook | null;
|
|
199
|
+
/** The version this workbook was read at, opaque to this package. */
|
|
200
|
+
version: string;
|
|
201
|
+
}
|
|
202
|
+
/** A save refused because somebody saved since this editor read the spreadsheet. */
|
|
203
|
+
declare class SpreadsheetsConflict extends Error {
|
|
204
|
+
}
|
|
205
|
+
interface SpreadsheetsStore {
|
|
206
|
+
list: () => Promise<SpreadsheetSummary[]>;
|
|
207
|
+
get: (id: string) => Promise<StoredSpreadsheet>;
|
|
208
|
+
create: (title: string) => Promise<StoredSpreadsheet>;
|
|
209
|
+
rename: (id: string, title: string) => Promise<void>;
|
|
210
|
+
/** Writes the workbook whole, and answers its new version. Rejects with
|
|
211
|
+
* `SpreadsheetsConflict` when `version` is no longer the stored one. */
|
|
212
|
+
save: (id: string, workbook: Workbook, version: string) => Promise<string>;
|
|
213
|
+
remove: (id: string) => Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
interface SpreadsheetsHost {
|
|
216
|
+
/** Absent: nothing saves by itself. */
|
|
217
|
+
store?: SpreadsheetsStore;
|
|
218
|
+
/** Absent: a person may. */
|
|
219
|
+
canCreate?: boolean;
|
|
220
|
+
canDelete?: boolean;
|
|
221
|
+
/** Choose a file from the host's drive (../files/choose.ts). Absent: Open takes
|
|
222
|
+
* a file from this computer only. */
|
|
223
|
+
chooseFile?: ChooseOfficeFile;
|
|
224
|
+
}
|
|
225
|
+
declare function SpreadsheetsProvider({ value, children }: {
|
|
226
|
+
value: SpreadsheetsHost;
|
|
227
|
+
children: ReactNode;
|
|
228
|
+
}): react.JSX.Element;
|
|
229
|
+
|
|
230
|
+
/** The files Spreadsheet opens, apart from the readers so the package entry can name them without loading one. */
|
|
231
|
+
declare const SPREADSHEET_EXTENSIONS: readonly string[];
|
|
232
|
+
|
|
184
233
|
/**
|
|
185
234
|
* The Spreadsheets app's words: its English, and each language this package carries. A
|
|
186
235
|
* host hands a language in through `SpreadsheetWordsProvider`.
|
|
@@ -188,6 +237,7 @@ type SheetBridge = ReturnType<typeof createSheetBridge>;
|
|
|
188
237
|
* The zh-Hans words for the file list and saving (`backToFiles` to
|
|
189
238
|
* `deleteConfirm`) are machine-written, and no person has read them yet.
|
|
190
239
|
*/
|
|
240
|
+
|
|
191
241
|
interface SpreadsheetWords {
|
|
192
242
|
untitled: string;
|
|
193
243
|
backToFiles: string;
|
|
@@ -335,6 +385,10 @@ interface SpreadsheetWords {
|
|
|
335
385
|
/** One line about a formula function, by its name; the name itself for one it has none for. */
|
|
336
386
|
functionHelp: (name: string) => string;
|
|
337
387
|
pdfPageFailed: (page: number) => string;
|
|
388
|
+
/** The file list's shared words: Open, Rename and the rest. */
|
|
389
|
+
files: FileWords;
|
|
390
|
+
/** The kind of file Open takes from the drive, as the drive names it. */
|
|
391
|
+
fileKind: string;
|
|
338
392
|
}
|
|
339
393
|
declare const ENGLISH_WORDS: SpreadsheetWords;
|
|
340
394
|
declare const ZH_HANS_WORDS: SpreadsheetWords;
|
|
@@ -344,48 +398,6 @@ declare function SpreadsheetWordsProvider({ words, children }: {
|
|
|
344
398
|
children: ReactNode;
|
|
345
399
|
}): react.JSX.Element;
|
|
346
400
|
|
|
347
|
-
/** What a store holds for one spreadsheet. */
|
|
348
|
-
interface Workbook {
|
|
349
|
-
sheets: Sheet[];
|
|
350
|
-
}
|
|
351
|
-
interface SpreadsheetSummary {
|
|
352
|
-
id: string;
|
|
353
|
-
title: string;
|
|
354
|
-
updatedAt: string;
|
|
355
|
-
}
|
|
356
|
-
interface StoredSpreadsheet {
|
|
357
|
-
id: string;
|
|
358
|
-
title: string;
|
|
359
|
-
/** The workbook as stored. Null for a new spreadsheet, which opens on one blank sheet. */
|
|
360
|
-
workbook: Workbook | null;
|
|
361
|
-
/** The version this workbook was read at, opaque to this package. */
|
|
362
|
-
version: string;
|
|
363
|
-
}
|
|
364
|
-
/** A save refused because somebody saved since this editor read the spreadsheet. */
|
|
365
|
-
declare class SpreadsheetsConflict extends Error {
|
|
366
|
-
}
|
|
367
|
-
interface SpreadsheetsStore {
|
|
368
|
-
list: () => Promise<SpreadsheetSummary[]>;
|
|
369
|
-
get: (id: string) => Promise<StoredSpreadsheet>;
|
|
370
|
-
create: (title: string) => Promise<StoredSpreadsheet>;
|
|
371
|
-
rename: (id: string, title: string) => Promise<void>;
|
|
372
|
-
/** Writes the workbook whole, and answers its new version. Rejects with
|
|
373
|
-
* `SpreadsheetsConflict` when `version` is no longer the stored one. */
|
|
374
|
-
save: (id: string, workbook: Workbook, version: string) => Promise<string>;
|
|
375
|
-
remove: (id: string) => Promise<void>;
|
|
376
|
-
}
|
|
377
|
-
interface SpreadsheetsHost {
|
|
378
|
-
/** Absent: nothing saves by itself. */
|
|
379
|
-
store?: SpreadsheetsStore;
|
|
380
|
-
/** Absent: a person may. */
|
|
381
|
-
canCreate?: boolean;
|
|
382
|
-
canDelete?: boolean;
|
|
383
|
-
}
|
|
384
|
-
declare function SpreadsheetsProvider({ value, children }: {
|
|
385
|
-
value: SpreadsheetsHost;
|
|
386
|
-
children: ReactNode;
|
|
387
|
-
}): react.JSX.Element;
|
|
388
|
-
|
|
389
401
|
declare const Spreadsheet: ComponentType<{
|
|
390
402
|
spreadsheetId?: string;
|
|
391
403
|
onClose?: () => void;
|
|
@@ -422,5 +434,11 @@ declare const spreadsheetApp: {
|
|
|
422
434
|
declare function readXlsx(bytes: Uint8Array): Promise<Sheet[]>;
|
|
423
435
|
/** A PDF of each sheet's displayed values, A4 landscape, its header row on every page. */
|
|
424
436
|
declare function workbookToPdf(sheets: readonly Sheet[], options?: PdfOptions): Promise<Blob>;
|
|
437
|
+
/** An Excel, OpenDocument or CSV file as a spreadsheet of its own in `store`, which
|
|
438
|
+
* then opens by id. The file stays as it was. */
|
|
439
|
+
declare function importSpreadsheetFile(store: SpreadsheetsStore, file: File): Promise<{
|
|
440
|
+
id: string;
|
|
441
|
+
title: string;
|
|
442
|
+
}>;
|
|
425
443
|
|
|
426
|
-
export { ENGLISH_WORDS, PdfOptions, type Sheet, type SheetBridge, type SheetBridgeState, type SheetEditFormat, type SheetEditOp, SheetEditRefused, type SheetEditResult, type SheetEditorPort, type SheetSnapshot, Spreadsheet, SpreadsheetEditor, SpreadsheetPane, type SpreadsheetSummary, type SpreadsheetWords, SpreadsheetWordsProvider, SpreadsheetsConflict, type SpreadsheetsHost, SpreadsheetsProvider, type SpreadsheetsStore, type StoredSpreadsheet, type Workbook, ZH_HANS_WORDS, applySheetOps, createSheetBridge, readXlsx, spreadsheetApp, workbookToPdf };
|
|
444
|
+
export { ChooseOfficeFile, ENGLISH_WORDS, FileWords, PdfOptions, SPREADSHEET_EXTENSIONS, type Sheet, type SheetBridge, type SheetBridgeState, type SheetEditFormat, type SheetEditOp, SheetEditRefused, type SheetEditResult, type SheetEditorPort, type SheetSnapshot, Spreadsheet, SpreadsheetEditor, SpreadsheetPane, type SpreadsheetSummary, type SpreadsheetWords, SpreadsheetWordsProvider, SpreadsheetsConflict, type SpreadsheetsHost, SpreadsheetsProvider, type SpreadsheetsStore, type StoredSpreadsheet, type Workbook, ZH_HANS_WORDS, applySheetOps, createSheetBridge, importSpreadsheetFile, readXlsx, spreadsheetApp, workbookToPdf };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{SPREADSHEET_EXTENSIONS as e,SpreadsheetWordsProvider as t,SpreadsheetsConflict as n,SpreadsheetsProvider as s}from"../chunk-GLT7O6TV.js";import{ENGLISH_WORDS as r,ZH_HANS_WORDS as o}from"../chunk-7K7AY3V3.js";import{cellDisplay as a,cellLabel as i,changeStructure as l,clearValues as c,colIndex as h,commitEntry as u,isFormula as p,makeEvaluator as m,newSheet as d,parseRangeLabel as f,rangeLabel as w,renameSheet as g,sortRange as S,updateFormats as b,usedBounds as k}from"../chunk-VKCG3LPQ.js";import{ENGLISH_FILE_WORDS as j,ZH_HANS_FILE_WORDS as y}from"../chunk-B32ASXHM.js";import{hasExtension as _}from"../chunk-XYVQTQ6N.js";import{lazy as x}from"react";var C=class extends Error{};function L(e,t,n){if(!t)return Math.min(n,e.length-1);const s=e.findIndex(e=>e.name.toLowerCase()===t.trim().toLowerCase());if(s<0)throw new C(`there is no sheet "${t}" any more`);return s}function v(e){const t=f(e);if(!t)throw new C(`"${e}" is not a range`);return t}function I(e,t,n){return e.map((e,s)=>s===t?n(e):e)}function M(e,t){const n={...e},s=(e,t)=>{void 0!==t&&(null===t||!1===t?delete n[e]:n[e]=t)};return s("bold",t.bold),s("italic",t.italic),s("underline",t.underline),s("align",t.align),s("fill",t.fill),s("color",t.color),s("numFmt",t.numFmt),n}function O(e,t,n){let s=e;for(const e of n)switch(e.op){case"add_sheet":if(s.some(t=>t.name.toLowerCase()===e.name.toLowerCase()))throw new C(`there is already a sheet "${e.name}"`);s=[...s,d(e.name)];break;case"rename_sheet":s=g(s,L(s,e.sheet,t),e.name);break;case"set_cells":{const n=L(s,e.sheet,t),r=v(e.start);s=I(s,n,t=>{let n=t;return e.values.forEach((e,t)=>e.forEach((e,s)=>{n=u(n,r.r1+t,r.c1+s,e)})),n});break}case"clear":s=I(s,L(s,e.sheet,t),t=>c(t,v(e.range)));break;case"insert_rows":case"delete_rows":{const n=L(s,e.sheet,t);s=l(s,n,"row",e.at-1,"insert_rows"===e.op?e.count:-e.count);break}case"insert_columns":case"delete_columns":{const n=L(s,e.sheet,t);s=l(s,n,"col",h(e.at),"insert_columns"===e.op?e.count:-e.count);break}case"sort":{const n=L(s,e.sheet,t),r=m(s);s=I(s,n,t=>S(t,n,r,v(e.range),h(e.by),!e.descending));break}case"format":s=I(s,L(s,e.sheet,t),t=>b(t,v(e.range),t=>M(t,e.format)));break;default:throw new C("this spreadsheet does not make that change")}return s}function E(){let e=null,t={open:!1,title:"",selection:null};const n=new Set,s=new Map,r=e=>{if(e.open!==t.open||e.title!==t.title||e.selection?.sheet!==t.selection?.sheet||e.selection?.range!==t.selection?.range){t=e;for(const e of n)e()}};return{getState:()=>t,subscribe:e=>(n.add(e),()=>{n.delete(e)}),attach:t=>(e=t,s.clear(),()=>{e===t&&(e=null,s.clear(),r({open:!1,title:"",selection:null}))}),changed(){if(!e)return;const t=e.sheets(),n=e.selection();r({open:!0,title:e.title(),selection:n&&t[n.sheet]?{sheet:t[n.sheet].name,range:w(n.range)}:null})},snapshot:()=>e?function(e,t,n,s){const r=m(t);return{title:e,sheets:t.map((e,t)=>{const n=k(e),s=[],o={};if(n)for(let l=0;l<=Math.min(n.row,4999);l++){const n=[],c=Math.min(e.cells[l]?.length??0,200);for(let s=0;s<c;s++){const c=e.cells[l][s]??"";""!==c?(n.push(a(e,t,r,l,s).text),p(c)&&(o[i(l,s)]=c)):n.push("")}s.push(n)}return{name:e.name,rows:s,formulas:o}}),activeSheet:Math.min(n,t.length-1),selection:s?{sheet:s.sheet,range:w(s.range)}:null}}(e.title(),e.sheets(),e.activeSheet(),e.selection()):null,apply(t,n){if(!e)return{applied:!1,reason:"the spreadsheet is closed"};if(s.has(t))return{applied:!0};const r=e.sheets();let o;try{o=O(r,e.activeSheet(),n)}catch(e){return{applied:!1,reason:e instanceof C?e.message:"it no longer fits the sheet"}}return e.commit(o),s.set(t,{before:r,after:o}),{applied:!0}},undo(t){const n=s.get(t);return e&&n?e.sheets()!==n.after?{applied:!1,reason:"the sheet has changed since"}:(e.undoLast(),s.delete(t),{applied:!0}):{applied:!1,reason:"the spreadsheet has been closed since"}}}}var F=x(()=>import("../Spreadsheet-I3RO4HSS.js")),H=x(()=>import("../Spreadsheet-I3RO4HSS.js").then(e=>({default:e.SpreadsheetById}))),P=x(()=>import("../Spreadsheet-I3RO4HSS.js").then(e=>({default:e.SpreadsheetPane}))),T={"/spreadsheet":{component:F,label:"Spreadsheets",size:"2xl",appStyle:!0,multiInstance:!0}};async function V(e){const{readXlsx:t}=await(import("../xlsxFile-B2JCZCOL.js"));return t(e)}async function B(e,t){const{workbookToPdf:n}=await(import("../workbookPdf-C5SSN226.js"));return n(e,t)}async function K(e,t){const{importSpreadsheetFile:n}=await(import("../importSpreadsheet-4U3KEJ76.js"));return n(e,t)}export{j as ENGLISH_FILE_WORDS,r as ENGLISH_WORDS,e as SPREADSHEET_EXTENSIONS,C as SheetEditRefused,F as Spreadsheet,H as SpreadsheetEditor,P as SpreadsheetPane,t as SpreadsheetWordsProvider,n as SpreadsheetsConflict,s as SpreadsheetsProvider,y as ZH_HANS_FILE_WORDS,o as ZH_HANS_WORDS,O as applySheetOps,E as createSheetBridge,_ as hasExtension,K as importSpreadsheetFile,V as readXlsx,T as spreadsheetApp,B as workbookToPdf};
|
|
@@ -12,3 +12,7 @@
|
|
|
12
12
|
.office-conflict { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; background: var(--status-warning-bg, var(--surface-raised)); border-bottom: 1px solid var(--line); font-size: 12px; }
|
|
13
13
|
.office-open-failed { padding: 24px; }
|
|
14
14
|
.office-save-state { margin-left: auto; }
|
|
15
|
+
.office-filelist-busy { padding: 8px 16px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--ink-muted, var(--ink)); background: var(--surface-sunken, var(--surface)); }
|
|
16
|
+
.office-filelist-rename { flex: 0 1 320px; min-width: 160px; }
|
|
17
|
+
.office-filelist-open { display: inline-flex; align-items: center; gap: 6px; }
|
|
18
|
+
.office-filelist:focus { outline: none; }
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** How any of the three apps makes a PDF. */
|
|
2
|
+
interface PdfOptions {
|
|
3
|
+
/** Called after each page. */
|
|
4
|
+
onProgress?: (done: number, total: number) => void;
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
/** JPEG quality of each page, 0..1. */
|
|
7
|
+
quality?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A file from the host's own drive, for the Open menu on each app's file list
|
|
12
|
+
* (./FileList.tsx). This package has no drive: a host that keeps people's files
|
|
13
|
+
* (EFFICIENT's Files window, say) hands in `chooseFile`, and the list's Open menu
|
|
14
|
+
* gains "From Efficient Drive" beside "From this computer". The host chooses in
|
|
15
|
+
* its own window, so there is never a second copy of it here.
|
|
16
|
+
*
|
|
17
|
+
* What comes back is opened as a copy in the app's own store: the original stays
|
|
18
|
+
* as it was. `place` puts that copy beside the original, and `location` says where
|
|
19
|
+
* that is, for the message the person reads once it is saved.
|
|
20
|
+
*/
|
|
21
|
+
interface OfficeFileRequest {
|
|
22
|
+
/** What the host shows while it chooses: "Choosing a PowerPoint file for Slides". */
|
|
23
|
+
title: string;
|
|
24
|
+
/** The extensions the app opens, lower case, without the dot. */
|
|
25
|
+
extensions: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
interface OfficeFileChoice {
|
|
28
|
+
file: File;
|
|
29
|
+
/** Where the original is, as the person reads it: "My files › Sales". Said only
|
|
30
|
+
* once `place` put the copy there. */
|
|
31
|
+
location?: string;
|
|
32
|
+
/** Puts the app's new copy (by its id in the app's store) beside the original. */
|
|
33
|
+
place?: (id: string) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
type ChooseOfficeFile = (request: OfficeFileRequest) => Promise<OfficeFileChoice | null>;
|
|
36
|
+
/** Whether `name` ends in one of `extensions`. */
|
|
37
|
+
declare function hasExtension(name: string, extensions: readonly string[]): boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The words every app's file list shares (./FileList.tsx): the Open menu, the
|
|
41
|
+
* right-click menu, renaming in the row, and the message once a file from
|
|
42
|
+
* elsewhere is saved as a copy. Each app carries one of these in its own words
|
|
43
|
+
* (`files`), so a host's language reaches them the way it reaches the rest.
|
|
44
|
+
*
|
|
45
|
+
* The zh-Hans words are machine-written, and no person has read them yet.
|
|
46
|
+
*/
|
|
47
|
+
interface FileWords {
|
|
48
|
+
open: string;
|
|
49
|
+
fromComputer: string;
|
|
50
|
+
fromDrive: string;
|
|
51
|
+
rename: string;
|
|
52
|
+
delete: string;
|
|
53
|
+
/** The name field's label while a row is renamed. */
|
|
54
|
+
name: string;
|
|
55
|
+
renameFailed: string;
|
|
56
|
+
/** "Choosing a PowerPoint file for Slides". */
|
|
57
|
+
choosing: (kind: string, app: string) => string;
|
|
58
|
+
/** While a file is read and saved. */
|
|
59
|
+
opening: (name: string) => string;
|
|
60
|
+
openFailed: (name: string) => string;
|
|
61
|
+
/** Once a file from elsewhere is saved as a copy; `location` when it came from the drive. */
|
|
62
|
+
savedCopy: (title: string, original: string, location?: string) => string;
|
|
63
|
+
}
|
|
64
|
+
declare const ENGLISH_FILE_WORDS: FileWords;
|
|
65
|
+
declare const ZH_HANS_FILE_WORDS: FileWords;
|
|
66
|
+
|
|
67
|
+
export { type ChooseOfficeFile as C, ENGLISH_FILE_WORDS as E, type FileWords as F, type OfficeFileChoice as O, type PdfOptions as P, ZH_HANS_FILE_WORDS as Z, type OfficeFileRequest as a, hasExtension as h };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{rowPageStarts as t}from"./chunk-PWF37Y2N.js";import{ENGLISH_WORDS as e}from"./chunk-7K7AY3V3.js";import{DEFAULT_COL_WIDTH as o,cellDisplay as n,filteredRows as r,formatKey as s,makeEvaluator as a,usedBounds as i}from"./chunk-VKCG3LPQ.js";import{drawJpeg as c,embeddedFonts as l,jpegPdf as d,openStage as p,settled as h}from"./chunk-JKYJGXJE.js";import"./chunk-B32ASXHM.js";var m=t=>t*(4/3),f=m(842),u=m(595),w=f-2*m(36),g=u-2*m(36),y="Calibri,Carlito,Arial,sans-serif",b=t=>Array.from({length:t},(t,e)=>e);function x(t,e,a){const c=i(t);if(!c)return{name:t.name,widths:[],rows:[],headerRows:0};const l=new Set([...t.hiddenRows,...r(t,e,a)]),d=new Set(t.hiddenCols),p=b(c.col+1).filter(t=>!d.has(t)),h=b(c.row+1).filter(t=>!l.has(t)).map(o=>p.map(r=>{const{text:i,align:c,color:l}=n(t,e,a,o,r),d=t.formats[s(o,r)];return{text:i,align:d?.align??c,color:d?.color??l,format:d}}));return{name:t.name,widths:p.map(e=>t.colWidths[e]??o),rows:h,headerRows:Math.min(Math.max(t.frozenRows,1),h.length)}}function R(t){const e=document.createElement("td");e.textContent=t.text;const{format:o}=t;return e.style.cssText=`border:.5pt solid #bbb;padding:1pt 3pt;vertical-align:top;overflow-wrap:anywhere;white-space:pre-wrap;text-align:${t.align}`,t.color&&(e.style.color=t.color),o?.fill&&(e.style.background=o.fill),o?.bold&&(e.style.fontWeight="700"),o?.italic&&(e.style.fontStyle="italic"),o?.fontSize&&(e.style.fontSize=`${o.fontSize}pt`),e}function v(t){const e=document.createElement("tr");return e.append(...t.map(R)),e}function E(t,e){const o=document.createElement("table"),n=t.widths.reduce((t,e)=>t+e,0);o.style.cssText=`border-collapse:collapse;table-layout:fixed;width:${n}px;font:10pt ${y};color:#000`;const r=document.createElement("colgroup");r.append(...t.widths.map(t=>Object.assign(document.createElement("col"),{style:`width:${t}px`})));const s=document.createElement("tbody");return s.append(...e.map(v)),o.append(r,s),o}function $(t){const e=document.createElement("div");return e.textContent=t,e.style.cssText=`font:600 13pt ${y};color:#000;margin-bottom:6pt`,e}function C({table:t,scale:e,starts:o},n){const r=document.createElement("div");if(r.style.cssText=`position:relative;overflow:hidden;background:#fff;width:${f}px;height:${u}px;padding:${m(36)}px;box-sizing:border-box`,r.append($(t.name)),t.rows.length){const s=o[n+1]??t.rows.length,a=E(t,[...t.rows.slice(0,t.headerRows),...t.rows.slice(o[n],s)]);a.style.transform=`scale(${e})`,a.style.transformOrigin="0 0",r.append(a)}return r}async function k(t,e,o,n){e.append(t);try{await h(t);return{jpeg:await c(t,{width:f,height:u,pixelRatio:2,quality:n,fontCss:o}),width:842,height:595}}finally{t.remove()}}async function A(o,n={}){const{signal:r,onProgress:s,quality:i}=n;r?.throwIfAborted();const c=p();try{const n=a(o),p=o.map((e,o)=>function(e,o){const n=e.widths.reduce((t,e)=>t+e,0),r=n>w?w/n:1,s=$(e.name),a=E(e,e.rows);o.append(s,a);const i=s.getBoundingClientRect().height+m(6),c=Array.from(a.querySelectorAll("tr"),t=>t.getBoundingClientRect().height);s.remove(),a.remove();const l=c.slice(0,e.headerRows).reduce((t,e)=>t+e,0),d=(g-i)/r,p=t(c.slice(e.headerRows),d,l).map(t=>t+e.headerRows);return{table:e,scale:r,starts:p}}(x(e,o,n),c.root)),h=p.reduce((t,e)=>t+e.starts.length,0),f=await l(c.root),u=[];for(const t of p)for(const o of t.starts.keys())r?.throwIfAborted(),u.push(await k(C(t,o),c.root,f,i).catch(t=>{throw new Error(e.pdfPageFailed(u.length+1),{cause:t})})),s?.(u.length,h);return d(u)}finally{c.close()}}export{x as sheetTable,A as workbookToPdf};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "efficient-office",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Efficient Office: the EFFICIENT office apps, on efficient-shell and efficient-easel.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"./spreadsheet.css": "./dist/spreadsheet/spreadsheet.css"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
|
-
"build": "tsup &&
|
|
39
|
+
"build": "tsup && cat src/slides/slides.css src/files/files.css > dist/slides/slides.css && cat src/documents/documents.css src/files/files.css > dist/documents/documents.css && cp src/files/files.css dist/spreadsheet/spreadsheet.css",
|
|
40
40
|
"typecheck": "tsc --noEmit",
|
|
41
41
|
"test": "vitest run",
|
|
42
42
|
"standalone:dev": "vite standalone",
|
|
@@ -1 +0,0 @@
|
|
|
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};
|