@ai-matrx/office 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +13 -4
  2. package/dist/chunk-5T2M6LSI.js +529 -0
  3. package/dist/chunk-5T2M6LSI.js.map +1 -0
  4. package/dist/chunk-QZE7HBZB.cjs +529 -0
  5. package/dist/chunk-QZE7HBZB.cjs.map +1 -0
  6. package/dist/chunk-WKBWRG7N.js +209 -0
  7. package/dist/chunk-WKBWRG7N.js.map +1 -0
  8. package/dist/chunk-ZDZCCOUB.cjs +209 -0
  9. package/dist/chunk-ZDZCCOUB.cjs.map +1 -0
  10. package/dist/core.d.cts +5 -1
  11. package/dist/core.d.ts +5 -1
  12. package/dist/matrxImagePorts-JDFYE4QI.cjs +59 -0
  13. package/dist/matrxImagePorts-JDFYE4QI.cjs.map +1 -0
  14. package/dist/matrxImagePorts-VPBBUADM.js +59 -0
  15. package/dist/matrxImagePorts-VPBBUADM.js.map +1 -0
  16. package/dist/sheets-xlsx.cjs +525 -0
  17. package/dist/sheets-xlsx.cjs.map +1 -0
  18. package/dist/sheets-xlsx.d.cts +153 -0
  19. package/dist/sheets-xlsx.d.ts +153 -0
  20. package/dist/sheets-xlsx.js +525 -0
  21. package/dist/sheets-xlsx.js.map +1 -0
  22. package/dist/sheets.cjs +921 -0
  23. package/dist/sheets.cjs.map +1 -0
  24. package/dist/sheets.d.cts +605 -0
  25. package/dist/sheets.d.ts +605 -0
  26. package/dist/sheets.js +921 -0
  27. package/dist/sheets.js.map +1 -0
  28. package/dist/univer-collab.cjs +1 -77
  29. package/dist/univer-collab.cjs.map +1 -1
  30. package/dist/univer-collab.d.cts +1 -15
  31. package/dist/univer-collab.d.ts +1 -15
  32. package/dist/univer-collab.js +1 -77
  33. package/dist/univer-collab.js.map +1 -1
  34. package/dist/univer-realtime.cjs +102 -0
  35. package/dist/univer-realtime.cjs.map +1 -0
  36. package/dist/univer-realtime.d.cts +15 -0
  37. package/dist/univer-realtime.d.ts +15 -0
  38. package/dist/univer-realtime.js +80 -0
  39. package/dist/univer-realtime.js.map +1 -0
  40. package/dist/xlsx-to-univer-AQAXU3TC.cjs +7 -0
  41. package/dist/xlsx-to-univer-AQAXU3TC.cjs.map +1 -0
  42. package/dist/xlsx-to-univer-OPMMBWEW.js +7 -0
  43. package/dist/xlsx-to-univer-OPMMBWEW.js.map +1 -0
  44. package/package.json +41 -4
@@ -0,0 +1,605 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ import { ServiceResult } from '@ai-matrx/records/core';
3
+
4
+ /**
5
+ * The host ports of the Sheets model and io.
6
+ *
7
+ * The package owns the workbook service, the page-setup store and the import flow, but three things
8
+ * belong to the app that mounts them: the database client (a package owns no client), the
9
+ * organization a write acts in (the active-organization ladder is app state) and the file store that
10
+ * keeps a lossless copy of an imported file. The host states them once at start-up with
11
+ * `configureSheetsHost`. State sits on a `globalThis` slot so a dual-bundled copy of the package
12
+ * still sees one host. An unconfigured port THROWS naming itself (nothing fails silently).
13
+ */
14
+
15
+ /** A Supabase client over any schema: the package cannot import the app's generated database types. */
16
+ type SheetsSupabase = SupabaseClient<any, any, any>;
17
+ interface SheetsHostPorts {
18
+ /** The app's database client (signed in as the person). */
19
+ getSupabase(): SheetsSupabase;
20
+ /** The organization a write acts in: the record's own when given, otherwise the active one. */
21
+ ensureOrgId(organizationId: string | null): Promise<string>;
22
+ /** Keep the original of an imported spreadsheet in the file store, in `folderPath`. */
23
+ uploadOriginalFile(file: File, options: {
24
+ folderPath: string;
25
+ }): Promise<{
26
+ fileId: string;
27
+ }>;
28
+ }
29
+ declare function configureSheetsHost(ports: SheetsHostPorts): void;
30
+ declare function getSheetsHost(): SheetsHostPorts;
31
+
32
+ /**
33
+ * The Office record rows: the workbook and document rows and their snapshots, exactly as the
34
+ * `workbench` schema returns them (moved from matrx-frontend `features/data-tables/types`, W1-G1a).
35
+ * Written out here because a package cannot import an app's generated database types; the app proves
36
+ * the two agree with a compile-time check against its generated `Database` type.
37
+ *
38
+ * `Json` columns are `unknown`: a reader narrows what it reads, nothing is assumed.
39
+ */
40
+ type WorkbookSource = "created" | "imported_xlsx" | "imported_gsheet" | "imported_csv" | "linked_gsheet";
41
+ /** `platform.shown_to`. */
42
+ type ShownTo = "only_me" | "my_team" | "everyone" | "everyone_on_ai_matrx";
43
+ /** `platform.visibility`. */
44
+ type Visibility = "personal" | "internal" | "link" | "public";
45
+ /** Origin of a snapshot. Free text in the database; this union is advisory. */
46
+ type WorkbookSnapshotOrigin = "autosave" | "manual" | "imported" | "restored" | "named";
47
+ /** A row of `workbench.udt_workbooks`. */
48
+ interface Workbook$1 {
49
+ created_at: string;
50
+ created_by: string;
51
+ custom_fields: unknown;
52
+ deleted_at: string | null;
53
+ description: string | null;
54
+ id: string;
55
+ is_public: boolean;
56
+ metadata: unknown;
57
+ organization_id: string;
58
+ original_file_id: string | null;
59
+ project_id: string | null;
60
+ published_to_web: boolean;
61
+ published_to_web_at: string | null;
62
+ published_to_web_by: string | null;
63
+ shown_to: ShownTo | null;
64
+ source: WorkbookSource;
65
+ task_id: string | null;
66
+ updated_at: string;
67
+ updated_by: string | null;
68
+ user_id: string;
69
+ version: number;
70
+ visibility: Visibility;
71
+ workbook_name: string;
72
+ }
73
+ /** A row of `workbench.udt_workbook_snapshots`. */
74
+ interface WorkbookSnapshot {
75
+ created_at: string;
76
+ created_by: string | null;
77
+ custom_fields: unknown;
78
+ id: string;
79
+ label: string | null;
80
+ metadata: unknown;
81
+ organization_id: string;
82
+ /** Free text in the database; "autosave" | "manual" | "imported" | "restored" by convention. */
83
+ origin: string;
84
+ snapshot: unknown;
85
+ workbook_id: string;
86
+ }
87
+
88
+ /** Honest, human label for `udt_workbooks.source`. */
89
+ declare function workbookSourceLabel(source: string): string;
90
+ type CreateWorkbookArgs = {
91
+ name: string;
92
+ description?: string | null;
93
+ /** Origin label for the workbook itself, mirrors `udt_workbooks.source`. */
94
+ source?: "created" | "imported_xlsx" | "imported_gsheet" | "imported_csv" | "linked_gsheet";
95
+ organizationId: string;
96
+ projectId?: string | null;
97
+ taskId?: string | null;
98
+ isPublic?: boolean;
99
+ /**
100
+ * cld_files.id of the source upload (XLSX / CSV blob). Set on the import
101
+ * flow so the lossless original is recoverable; FK is ON DELETE SET NULL,
102
+ * so deleting the file just nulls the link — the workbook survives.
103
+ */
104
+ originalFileId?: string | null;
105
+ };
106
+ declare function createWorkbook(args: CreateWorkbookArgs): Promise<ServiceResult<Workbook$1>>;
107
+ declare function listAccessibleWorkbooks(): Promise<ServiceResult<Workbook$1[]>>;
108
+ declare function getWorkbook(workbookId: string): Promise<ServiceResult<Workbook$1>>;
109
+ declare function renameWorkbook(workbookId: string, name: string): Promise<ServiceResult<Workbook$1>>;
110
+ /**
111
+ * Move the workbook into a project (or out of one with `null`). Sibling of
112
+ * `renameWorkbook`: the one named setter for `project_id`.
113
+ */
114
+ declare function moveWorkbook(workbookId: string, projectId: string | null): Promise<ServiceResult<Workbook$1>>;
115
+ /**
116
+ * Rewrite the workbook's description. Sibling of `renameWorkbook` — the two
117
+ * human-authored fields on `udt_workbooks` each get a named setter so callers
118
+ * never hand-roll a `.from("udt_workbooks").update(...)`. Pass `null` (or an
119
+ * empty string) to clear it.
120
+ *
121
+ * Written by the import flow at creation ("Imported from <file>") and, since
122
+ * the workbooks surface became agent-writable, by the `workbook_description`
123
+ * write target on `/workbooks/[id]`.
124
+ */
125
+ declare function updateWorkbookDescription(workbookId: string, description: string | null): Promise<ServiceResult<Workbook$1>>;
126
+ /**
127
+ * Soft delete — the workbook is tombstoned, not destroyed, and its snapshots stay
128
+ * with it. Every read path filters `deleted_at is null`. Pair with
129
+ * restoreWorkbook for undo.
130
+ */
131
+ declare function deleteWorkbook(workbookId: string): Promise<ServiceResult<true>>;
132
+ /**
133
+ * Archive (delete means archive: never a hard delete) — only for rolling back a workbook this very flow just created and
134
+ * failed to populate (see the import path in app/(core)/workbooks/page.tsx).
135
+ * Never use this for a user-initiated delete: that is deleteWorkbook, which
136
+ * tombstones and stays recoverable.
137
+ */
138
+ declare function discardFailedWorkbook(workbookId: string): Promise<ServiceResult<true>>;
139
+ declare function restoreWorkbook(workbookId: string): Promise<ServiceResult<true>>;
140
+ /** Trash view: the caller's own archived workbooks (RLS decides what is readable). */
141
+ declare function listTrashedWorkbooks(): Promise<ServiceResult<Workbook$1[]>>;
142
+ /**
143
+ * An independent copy of a workbook: its own row in the original's organization
144
+ * and project, with the latest snapshot copied over. Editing the copy never
145
+ * touches the original.
146
+ */
147
+ declare function copyWorkbook(workbookId: string, name?: string): Promise<ServiceResult<Workbook$1>>;
148
+ /**
149
+ * Latest-snapshot fetch — what an opened workbook hydrates from. Returns
150
+ * `data: null` (success path) when the workbook has no snapshots yet (newly
151
+ * created, never saved). Distinguish "no snapshot" from "load error" by
152
+ * checking `result.data === null`.
153
+ */
154
+ declare function getLatestSnapshot(workbookId: string): Promise<ServiceResult<WorkbookSnapshot | null>>;
155
+ type SaveSnapshotArgs = {
156
+ workbookId: string;
157
+ snapshot: unknown;
158
+ label?: string | null;
159
+ origin?: WorkbookSnapshotOrigin;
160
+ };
161
+ declare function saveSnapshot(args: SaveSnapshotArgs): Promise<ServiceResult<WorkbookSnapshot>>;
162
+ declare function listSnapshots(workbookId: string, limit?: number): Promise<ServiceResult<WorkbookSnapshot[]>>;
163
+
164
+ /**
165
+ * features/workbooks/univer-snapshot-rows.ts
166
+ *
167
+ * Snapshot → rows: read a Univer `IWorkbookData` snapshot back out as a plain
168
+ * string grid. The missing half of the workbook round trip — `export-targets`
169
+ * pushes rows INTO a workbook; this reads the (possibly user-edited) values
170
+ * back OUT so features can offer "edit in the workbook, then import your
171
+ * changes". Values only (formulas come back as their cached value); first
172
+ * sheet by `sheetOrder` unless a sheet id is named. A number shown through a date format reads as
173
+ * its ISO date (a spreadsheet keeps dates as day serials). Reusable — do not fork a per-feature
174
+ * snapshot walker. Callers: the workbook's "Make this sheet a table" (features/workbooks/table-link).
175
+ */
176
+ interface SnapshotRows {
177
+ sheetName: string;
178
+ /** Dense rectangular grid, trailing empty rows/columns trimmed. */
179
+ rows: string[][];
180
+ /** Rows pinned at the top of the sheet (Freeze rows), counted in `rows`. */
181
+ frozenRows: number;
182
+ /** Columns pinned at the left of the sheet (Freeze columns), counted in each row. */
183
+ frozenCols: number;
184
+ }
185
+ /** A zero-based, inclusive cell range (a selection). */
186
+ interface CellRange {
187
+ startRow: number;
188
+ endRow: number;
189
+ startColumn: number;
190
+ endColumn: number;
191
+ }
192
+ /** Sheet ids in tab order. */
193
+ declare function univerSheetIds(snapshot: unknown): string[];
194
+ /**
195
+ * Extract the first worksheet of a Univer workbook snapshot as a string grid.
196
+ * Returns null when the value is not snapshot-shaped or has no sheets.
197
+ * `skipHidden` leaves out hidden columns and rows: every read-only view (a share page, an agent's
198
+ * read) passes it, so the table link's hidden Record ID column never reaches a reader.
199
+ */
200
+ declare function univerSnapshotToRows(snapshot: unknown, options?: {
201
+ sheetId?: string;
202
+ skipHidden?: boolean;
203
+ range?: CellRange;
204
+ }): SnapshotRows | null;
205
+
206
+ /**
207
+ * features/workbooks/snapshot-grid.ts
208
+ *
209
+ * Snapshot → a formatted, read-only grid model: what a spreadsheet VIEW needs and the plain-string
210
+ * `univer-snapshot-rows` does not carry — number/currency/date formats applied, checkbox cells
211
+ * (data-validation ranges of type checkbox), alignment, bold/italic, fill and text colour, column
212
+ * widths, merges, frozen rows/columns, hidden rows/columns and sheets. Pure (no DOM, no Univer
213
+ * runtime): the signed-out share page draws it. The number formatter is the thumbnail's
214
+ * (`formatCellValue`) so a tile, a share link and the editor read the same.
215
+ */
216
+ interface GridCell {
217
+ text: string;
218
+ /** A checkbox cell (a data-validation checkbox range): `checked` says its state. */
219
+ checkbox?: {
220
+ checked: boolean;
221
+ } | undefined;
222
+ align: "left" | "center" | "right";
223
+ bold: boolean;
224
+ italic: boolean;
225
+ /** Font size in px (the snapshot stores points). */
226
+ fontPx: number;
227
+ bg?: string | undefined;
228
+ color?: string | undefined;
229
+ wrap: boolean;
230
+ rowSpan: number;
231
+ colSpan: number;
232
+ /** Covered by a merge that starts elsewhere: draw nothing. */
233
+ covered: boolean;
234
+ }
235
+ interface GridSheet {
236
+ id: string;
237
+ name: string;
238
+ /** Visible column indexes (hidden columns left out) with their pixel widths. */
239
+ columns: Array<{
240
+ index: number;
241
+ width: number;
242
+ }>;
243
+ rows: Array<{
244
+ index: number;
245
+ height: number;
246
+ cells: GridCell[];
247
+ }>;
248
+ /** How many leading VISIBLE rows / columns stay put while scrolling. */
249
+ frozenRows: number;
250
+ frozenColumns: number;
251
+ gridlines: boolean;
252
+ /** Rows beyond the cap were left out. */
253
+ truncatedFrom: number | null;
254
+ }
255
+ declare const GRID_MAX_ROWS = 500;
256
+ declare const GRID_MAX_COLUMNS = 60;
257
+ /** Every visible sheet that has something in it, in tab order. Empty and hidden sheets are left out. */
258
+ declare function snapshotToGridSheets(snapshot: unknown): GridSheet[];
259
+
260
+ /**
261
+ * snapshot → SVG: a faithful miniature of a Univer workbook's first sheet or a
262
+ * Univer document's first page — the gallery tile Google draws. Pure (no DOM,
263
+ * no Univer runtime), so it runs in the browser (thumbnail capture), in tests
264
+ * and in node. Reads only what a snapshot stores: cell values + styles +
265
+ * column widths + merges + conditional formats + checkboxes for sheets; the
266
+ * dataStream + text runs + paragraph styles + tables for documents.
267
+ */
268
+ declare const THUMB_WIDTH = 320;
269
+ declare const THUMB_HEIGHT = 414;
270
+ type Rgb = {
271
+ rgb?: string | null;
272
+ } | null | undefined;
273
+ type CellStyle = {
274
+ bg?: Rgb;
275
+ cl?: Rgb;
276
+ bl?: number;
277
+ it?: number;
278
+ fs?: number;
279
+ ht?: number;
280
+ n?: {
281
+ pattern?: string;
282
+ } | null;
283
+ bd?: Record<string, unknown> | null;
284
+ };
285
+ type Cell = {
286
+ v?: unknown;
287
+ s?: string | CellStyle | null;
288
+ t?: number;
289
+ f?: string;
290
+ };
291
+ type Sheet = {
292
+ id?: string;
293
+ name?: string;
294
+ cellData?: Record<string, Record<string, Cell>>;
295
+ columnData?: Record<string, {
296
+ w?: number;
297
+ hd?: number;
298
+ }>;
299
+ rowData?: Record<string, {
300
+ h?: number;
301
+ hd?: number;
302
+ }>;
303
+ defaultColumnWidth?: number;
304
+ defaultRowHeight?: number;
305
+ mergeData?: Array<{
306
+ startRow: number;
307
+ endRow: number;
308
+ startColumn: number;
309
+ endColumn: number;
310
+ }>;
311
+ showGridlines?: number;
312
+ freeze?: {
313
+ ySplit?: number;
314
+ xSplit?: number;
315
+ };
316
+ };
317
+ type Workbook = {
318
+ sheetOrder?: string[];
319
+ sheets?: Record<string, Sheet>;
320
+ styles?: Record<string, CellStyle | null>;
321
+ resources?: Array<{
322
+ name?: string;
323
+ data?: string;
324
+ }>;
325
+ };
326
+ declare function formatCellValue(v: unknown, pattern?: string | null): string;
327
+ type CfRule = {
328
+ rule?: {
329
+ type?: string;
330
+ subType?: string;
331
+ operator?: string;
332
+ value?: unknown;
333
+ style?: CellStyle;
334
+ };
335
+ ranges?: Array<{
336
+ startRow: number;
337
+ endRow: number;
338
+ startColumn: number;
339
+ endColumn: number;
340
+ }>;
341
+ };
342
+ declare function parseResource<T>(wb: Workbook, name: string): T | null;
343
+ declare function cfMatch(rule: NonNullable<CfRule["rule"]>, v: unknown): boolean;
344
+ declare function workbookPreviewSvg(snapshot: unknown): string;
345
+ declare function documentPreviewSvg(snapshot: unknown): string;
346
+ declare function snapshotPreviewSvg(kind: "workbook" | "document", snapshot: unknown): string;
347
+
348
+ /**
349
+ * The ONE page geometry every Matrx cloud document is laid out with.
350
+ *
351
+ * Univer lays a document out inside `documentStyle.pageSize`. With no pageSize
352
+ * the docs renderer has no page box at all: text never wraps (it runs off the
353
+ * right edge) and the vertical extent is unbounded, so the docs viewport
354
+ * reports nothing to scroll — the wheel is swallowed and the page sits frozen
355
+ * at the top. Every writer of a Univer snapshot MUST stamp this style.
356
+ *
357
+ * Consumers: `DocumentEditor` (new empty doc), `markdown-to-univer-doc`
358
+ * (markdown import), and `sanitizeUniverDocSnapshot` (recovery for snapshots
359
+ * that reached storage without it — notably `origin='agent'` writes).
360
+ */
361
+
362
+ /** Paper sizes the Page setup dialog offers, in 96-dpi pixels, portrait (width x height). */
363
+ declare const PAPER_SIZES: {
364
+ readonly Letter: {
365
+ readonly width: 816;
366
+ readonly height: 1056;
367
+ readonly label: "Letter (8.5 x 11 in)";
368
+ };
369
+ readonly Legal: {
370
+ readonly width: 816;
371
+ readonly height: 1344;
372
+ readonly label: "Legal (8.5 x 14 in)";
373
+ };
374
+ readonly Tabloid: {
375
+ readonly width: 1056;
376
+ readonly height: 1632;
377
+ readonly label: "Tabloid (11 x 17 in)";
378
+ };
379
+ readonly Executive: {
380
+ readonly width: 696;
381
+ readonly height: 1008;
382
+ readonly label: "Executive (7.25 x 10.5 in)";
383
+ };
384
+ readonly Statement: {
385
+ readonly width: 528;
386
+ readonly height: 816;
387
+ readonly label: "Statement (5.5 x 8.5 in)";
388
+ };
389
+ readonly A3: {
390
+ readonly width: 1123;
391
+ readonly height: 1587;
392
+ readonly label: "A3 (11.69 x 16.54 in)";
393
+ };
394
+ readonly A4: {
395
+ readonly width: 794;
396
+ readonly height: 1124;
397
+ readonly label: "A4 (8.27 x 11.69 in)";
398
+ };
399
+ readonly A5: {
400
+ readonly width: 559;
401
+ readonly height: 794;
402
+ readonly label: "A5 (5.83 x 8.27 in)";
403
+ };
404
+ };
405
+ type PaperSizeName = keyof typeof PAPER_SIZES;
406
+
407
+ /**
408
+ * A workbook's print settings — Google Sheets' File → Page setup / Print, as pure data and pure
409
+ * pagination (no React, no IO). They live on the workbook (`udt_workbooks.metadata.page_setup`),
410
+ * so Print, Download as PDF and the Page setup dialog all read the same values.
411
+ *
412
+ * Geometry is in 96-dpi CSS pixels, like the rest of the document stack (`PX_PER_INCH`).
413
+ */
414
+
415
+ declare const SHEET_SCALES: readonly ["normal", "width", "height", "page"];
416
+ type SheetScale = (typeof SHEET_SCALES)[number];
417
+ declare const SHEET_MARGIN_PRESETS: readonly ["normal", "narrow", "wide", "custom"];
418
+ type SheetMarginPreset = (typeof SHEET_MARGIN_PRESETS)[number];
419
+ declare const SHEET_PRINT_SCOPES: readonly ["sheet", "workbook", "selection"];
420
+ type SheetPrintScope = (typeof SHEET_PRINT_SCOPES)[number];
421
+ type SheetPageOrder = "down-over" | "over-down";
422
+ type SheetAlignH = "left" | "center" | "right";
423
+ type SheetAlignV = "top" | "middle" | "bottom";
424
+ interface SheetPageSetup {
425
+ paper: PaperSizeName;
426
+ orientation: "portrait" | "landscape";
427
+ scale: SheetScale;
428
+ margins: SheetMarginPreset;
429
+ /** Inches; read only when `margins` is "custom". */
430
+ customMargins: {
431
+ top: number;
432
+ bottom: number;
433
+ left: number;
434
+ right: number;
435
+ };
436
+ scope: SheetPrintScope;
437
+ gridlines: boolean;
438
+ repeatFrozenRows: boolean;
439
+ repeatFrozenColumns: boolean;
440
+ pageOrder: SheetPageOrder;
441
+ alignH: SheetAlignH;
442
+ alignV: SheetAlignV;
443
+ }
444
+ /** Google Sheets' defaults: Letter, portrait, 100%, normal margins, current sheet, gridlines on. */
445
+ declare const DEFAULT_SHEET_PAGE_SETUP: SheetPageSetup;
446
+ /** Google's three preset margins, in inches. */
447
+ declare const MARGIN_PRESET_INCHES: Record<Exclude<SheetMarginPreset, "custom">, {
448
+ top: number;
449
+ bottom: number;
450
+ left: number;
451
+ right: number;
452
+ }>;
453
+ /** Any stored value → a complete, valid setup. Unknown or broken parts fall back to the default. */
454
+ declare function normalizeSheetPageSetup(raw: unknown): SheetPageSetup;
455
+ /** The setup stored on a workbook's metadata (`metadata.page_setup`), complete and valid. */
456
+ declare function pageSetupFromMetadata(metadata: unknown): SheetPageSetup;
457
+ interface PrintGeometry {
458
+ /** Paper as printed (orientation applied), px. */
459
+ paperWidth: number;
460
+ paperHeight: number;
461
+ marginTop: number;
462
+ marginBottom: number;
463
+ marginLeft: number;
464
+ marginRight: number;
465
+ /** The printable box inside the margins, px. */
466
+ areaWidth: number;
467
+ areaHeight: number;
468
+ }
469
+ declare function printGeometry(setup: SheetPageSetup): PrintGeometry;
470
+ declare const PRINT_ROW_HEIGHT = 22;
471
+ /** Column widths (px) fitted to the text the column holds. */
472
+ declare function printColumnWidths(rows: readonly (readonly string[])[]): number[];
473
+ interface PrintPage {
474
+ /** Grid row indexes drawn on this page, in order (repeated frozen rows first). */
475
+ rows: number[];
476
+ /** Grid column indexes drawn on this page, in order (repeated frozen columns first). */
477
+ cols: number[];
478
+ }
479
+ interface PrintPlan {
480
+ scale: number;
481
+ geometry: PrintGeometry;
482
+ colWidths: number[];
483
+ pages: PrintPage[];
484
+ }
485
+ /** The pages one grid prints on under `setup`: scale, repeated frozen panes, and page order. */
486
+ declare function planSheetPrint(rows: readonly (readonly string[])[], setup: SheetPageSetup, frozen?: {
487
+ rows: number;
488
+ cols: number;
489
+ }): PrintPlan;
490
+
491
+ type PageSetupResult = {
492
+ ok: true;
493
+ data: SheetPageSetup;
494
+ } | {
495
+ ok: false;
496
+ error: string;
497
+ };
498
+ declare function readSheetPageSetup(workbookId: string): Promise<PageSetupResult>;
499
+ declare function writeSheetPageSetup(workbookId: string, setup: SheetPageSetup): Promise<PageSetupResult>;
500
+
501
+ /**
502
+ * The pages a workbook prints on: the snapshot's cells → paper-sized HTML pages that follow the
503
+ * workbook's print settings (`sheet-page-setup.ts`). Print and Download as PDF both draw these
504
+ * same pages, so what the browser prints is what the PDF holds.
505
+ */
506
+
507
+ interface PrintSheet {
508
+ name: string;
509
+ rows: string[][];
510
+ frozenRows: number;
511
+ frozenCols: number;
512
+ }
513
+ /** The sheets the setup's "what to print" asks for (empty sheets left out). */
514
+ declare function collectPrintSheets(snapshot: unknown, setup: SheetPageSetup, options: {
515
+ sheetId?: string;
516
+ selection?: CellRange | null;
517
+ }): PrintSheet[];
518
+ interface PrintDocument {
519
+ /** Every page, in print order. */
520
+ pagesHtml: string[];
521
+ pageWidth: number;
522
+ pageHeight: number;
523
+ /** `@page` size in inches, for the browser's print engine. */
524
+ pageSizeInches: {
525
+ width: number;
526
+ height: number;
527
+ };
528
+ }
529
+ /** All the printed pages of the chosen sheets under the setup (empty when there is nothing to print). */
530
+ declare function buildPrintDocument(sheets: readonly PrintSheet[], setup: SheetPageSetup): PrintDocument | null;
531
+ /** The whole printable web page: `@page` set to the paper, one section per page. */
532
+ declare function printDocumentHtml(doc: PrintDocument, title: string): string;
533
+
534
+ /**
535
+ * Outputs of a workbook: CSV/TSV/HTML downloads of the current sheet, and Print / PDF of what its page setup asks for.
536
+ * Both read the same string grid the rest of the workbook code reads
537
+ * (`univerSnapshotToRows`) — one source of what "the sheet" contains.
538
+ */
539
+
540
+ declare function rowsToCsv(rows: readonly (readonly string[])[]): string;
541
+ declare function downloadSheetAsCsv(snapshot: unknown, options: {
542
+ sheetId?: string;
543
+ filename: string;
544
+ }): boolean;
545
+ /** Tab-separated values of the current sheet (Google's .tsv download). */
546
+ declare function downloadSheetAsTsv(snapshot: unknown, options: {
547
+ sheetId?: string;
548
+ filename: string;
549
+ }): boolean;
550
+ /** The current sheet as a standalone web page (Google's .html download). */
551
+ declare function downloadSheetAsHtml(snapshot: unknown, options: {
552
+ sheetId?: string;
553
+ filename: string;
554
+ }): boolean;
555
+ /** What a print or PDF needs besides the snapshot: the workbook's page setup and the live selection. */
556
+ interface SheetPrintOptions {
557
+ sheetId?: string;
558
+ title: string;
559
+ setup: SheetPageSetup;
560
+ /** The cells selected right now (used when the setup prints "selected cells"). */
561
+ selection?: CellRange | null;
562
+ }
563
+ /** Opens the browser print sheet for what the workbook's page setup asks to print (choose "Save as PDF" there). */
564
+ declare function printSheet(snapshot: unknown, options: SheetPrintOptions): boolean;
565
+ /** The sheet's grid as a markdown table (first row is the header row). */
566
+ declare function rowsToMarkdownTable(rows: readonly (readonly string[])[]): string;
567
+ /**
568
+ * Real PDF download of what the workbook's page setup prints: the same pages Print draws, each one
569
+ * captured and laid on a PDF page of the chosen paper size and orientation. Returns false when empty.
570
+ */
571
+ declare function downloadSheetAsPdf(snapshot: unknown, options: SheetPrintOptions): Promise<boolean>;
572
+
573
+ interface WorkbookLiveScope {
574
+ sheets: Array<{
575
+ id: string;
576
+ name: string;
577
+ index: number;
578
+ }>;
579
+ activeSheetId: string | null;
580
+ activeSheetName: string | null;
581
+ snapshot: Record<string, unknown> | null;
582
+ bootState: "booting" | "ready" | "load_error";
583
+ loadError: string | null;
584
+ saveStatus: string;
585
+ collab: {
586
+ enabled: boolean;
587
+ is_host: boolean;
588
+ self_uid: string;
589
+ remote_peers: number;
590
+ };
591
+ }
592
+ interface Registration {
593
+ workbookId: string;
594
+ read: () => WorkbookLiveScope | null;
595
+ }
596
+ /** Called by `WorkbookEditor` while mounted. Returns an unregister. */
597
+ declare function registerWorkbookScopeSource(registration: Registration): () => void;
598
+ /**
599
+ * Read the live editor state for `workbookId`. Returns null when no editor is
600
+ * mounted, when a different workbook is mounted, or when Univer has not
601
+ * booted yet — never a fabricated shape.
602
+ */
603
+ declare function readWorkbookScopeSource(workbookId: string): WorkbookLiveScope | null;
604
+
605
+ export { type CellRange, type CfRule, type CreateWorkbookArgs, DEFAULT_SHEET_PAGE_SETUP, GRID_MAX_COLUMNS, GRID_MAX_ROWS, type GridCell, type GridSheet, MARGIN_PRESET_INCHES, PRINT_ROW_HEIGHT, type PageSetupResult, type PrintDocument, type PrintGeometry, type PrintPage, type PrintPlan, type PrintSheet, SHEET_MARGIN_PRESETS, SHEET_PRINT_SCOPES, SHEET_SCALES, type SaveSnapshotArgs, type SheetAlignH, type SheetAlignV, type SheetMarginPreset, type SheetPageOrder, type SheetPageSetup, type SheetPrintOptions, type SheetPrintScope, type SheetScale, type SheetsHostPorts, type SheetsSupabase, type SnapshotRows, THUMB_HEIGHT, THUMB_WIDTH, type Workbook, type WorkbookLiveScope, buildPrintDocument, cfMatch, collectPrintSheets, configureSheetsHost, copyWorkbook, createWorkbook, deleteWorkbook, discardFailedWorkbook, documentPreviewSvg, downloadSheetAsCsv, downloadSheetAsHtml, downloadSheetAsPdf, downloadSheetAsTsv, formatCellValue, getLatestSnapshot, getSheetsHost, getWorkbook, listAccessibleWorkbooks, listSnapshots, listTrashedWorkbooks, moveWorkbook, normalizeSheetPageSetup, pageSetupFromMetadata, parseResource, planSheetPrint, printColumnWidths, printDocumentHtml, printGeometry, printSheet, readSheetPageSetup, readWorkbookScopeSource, registerWorkbookScopeSource, renameWorkbook, restoreWorkbook, rowsToCsv, rowsToMarkdownTable, saveSnapshot, snapshotPreviewSvg, snapshotToGridSheets, univerSheetIds, univerSnapshotToRows, updateWorkbookDescription, workbookPreviewSvg, workbookSourceLabel, writeSheetPageSetup };