@ai-matrx/office 0.3.1 → 0.5.2

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 (74) hide show
  1. package/CHANGELOG.md +47 -2
  2. package/dist/chunk-2UBGQUXW.cjs +37 -0
  3. package/dist/chunk-2UBGQUXW.cjs.map +1 -0
  4. package/dist/chunk-5T2M6LSI.js +529 -0
  5. package/dist/chunk-5T2M6LSI.js.map +1 -0
  6. package/dist/chunk-BWMAYLW4.cjs +272 -0
  7. package/dist/chunk-BWMAYLW4.cjs.map +1 -0
  8. package/dist/chunk-IDEA5UXK.js +272 -0
  9. package/dist/chunk-IDEA5UXK.js.map +1 -0
  10. package/dist/chunk-MPKXXZZV.js +37 -0
  11. package/dist/chunk-MPKXXZZV.js.map +1 -0
  12. package/dist/chunk-O6FTSXHE.cjs +463 -0
  13. package/dist/chunk-O6FTSXHE.cjs.map +1 -0
  14. package/dist/chunk-PI473GES.js +463 -0
  15. package/dist/chunk-PI473GES.js.map +1 -0
  16. package/dist/chunk-QZE7HBZB.cjs +529 -0
  17. package/dist/chunk-QZE7HBZB.cjs.map +1 -0
  18. package/dist/chunk-WKBWRG7N.js +209 -0
  19. package/dist/chunk-WKBWRG7N.js.map +1 -0
  20. package/dist/chunk-ZDZCCOUB.cjs +209 -0
  21. package/dist/chunk-ZDZCCOUB.cjs.map +1 -0
  22. package/dist/core.d.cts +5 -1
  23. package/dist/core.d.ts +5 -1
  24. package/dist/docs-io.cjs +496 -0
  25. package/dist/docs-io.cjs.map +1 -0
  26. package/dist/docs-io.d.cts +147 -0
  27. package/dist/docs-io.d.ts +147 -0
  28. package/dist/docs-io.js +496 -0
  29. package/dist/docs-io.js.map +1 -0
  30. package/dist/docs-tools.cjs +217 -0
  31. package/dist/docs-tools.cjs.map +1 -0
  32. package/dist/docs-tools.d.cts +150 -0
  33. package/dist/docs-tools.d.ts +150 -0
  34. package/dist/docs-tools.js +217 -0
  35. package/dist/docs-tools.js.map +1 -0
  36. package/dist/docs.cjs +657 -0
  37. package/dist/docs.cjs.map +1 -0
  38. package/dist/docs.d.cts +582 -0
  39. package/dist/docs.d.ts +582 -0
  40. package/dist/docs.js +657 -0
  41. package/dist/docs.js.map +1 -0
  42. package/dist/matrxImagePorts-JDFYE4QI.cjs +59 -0
  43. package/dist/matrxImagePorts-JDFYE4QI.cjs.map +1 -0
  44. package/dist/matrxImagePorts-VPBBUADM.js +59 -0
  45. package/dist/matrxImagePorts-VPBBUADM.js.map +1 -0
  46. package/dist/sheets-xlsx.cjs +525 -0
  47. package/dist/sheets-xlsx.cjs.map +1 -0
  48. package/dist/sheets-xlsx.d.cts +153 -0
  49. package/dist/sheets-xlsx.d.ts +153 -0
  50. package/dist/sheets-xlsx.js +525 -0
  51. package/dist/sheets-xlsx.js.map +1 -0
  52. package/dist/sheets.cjs +921 -0
  53. package/dist/sheets.cjs.map +1 -0
  54. package/dist/sheets.d.cts +605 -0
  55. package/dist/sheets.d.ts +605 -0
  56. package/dist/sheets.js +921 -0
  57. package/dist/sheets.js.map +1 -0
  58. package/dist/univer-collab.cjs +4 -77
  59. package/dist/univer-collab.cjs.map +1 -1
  60. package/dist/univer-collab.d.cts +8 -15
  61. package/dist/univer-collab.d.ts +8 -15
  62. package/dist/univer-collab.js +4 -77
  63. package/dist/univer-collab.js.map +1 -1
  64. package/dist/univer-realtime.cjs +102 -0
  65. package/dist/univer-realtime.cjs.map +1 -0
  66. package/dist/univer-realtime.d.cts +15 -0
  67. package/dist/univer-realtime.d.ts +15 -0
  68. package/dist/univer-realtime.js +80 -0
  69. package/dist/univer-realtime.js.map +1 -0
  70. package/dist/xlsx-to-univer-AQAXU3TC.cjs +7 -0
  71. package/dist/xlsx-to-univer-AQAXU3TC.cjs.map +1 -0
  72. package/dist/xlsx-to-univer-OPMMBWEW.js +7 -0
  73. package/dist/xlsx-to-univer-OPMMBWEW.js.map +1 -0
  74. package/package.json +75 -4
@@ -0,0 +1,153 @@
1
+ import { WorkbookJson } from '@ai-matrx/alchemy/operate/read';
2
+ import { IWorkbookData } from '@univerjs/core';
3
+
4
+ /**
5
+ * Shared vocabulary between the xlsx importer and exporter: how Univer's
6
+ * style numbers, colours and units map to the xlsx file's.
7
+ *
8
+ * Univer enums are written as numbers here so these helpers stay free of any
9
+ * Univer import (they run in tests and in both directions).
10
+ */
11
+ declare const RESOURCE: {
12
+ readonly validation: "SHEET_DATA_VALIDATION_PLUGIN";
13
+ readonly conditional: "SHEET_CONDITIONAL_FORMATTING_PLUGIN";
14
+ readonly filter: "SHEET_FILTER_PLUGIN";
15
+ readonly note: "SHEET_NOTE_PLUGIN";
16
+ readonly comments: "SHEET_UNIVER_THREAD_COMMENT_PLUGIN";
17
+ readonly drawing: "SHEET_DRAWING_PLUGIN";
18
+ readonly table: "SHEET_TABLE_PLUGIN";
19
+ };
20
+ type UniverResource = {
21
+ name: string;
22
+ data: string;
23
+ };
24
+ declare function readResource<T = unknown>(resources: readonly UniverResource[] | undefined, name: string): T | undefined;
25
+ declare function writeResource(resources: UniverResource[], name: string, value: unknown): void;
26
+ /** Excel column width (characters) <-> Univer pixels. */
27
+ declare const colPxToChars: (px: number) => number;
28
+ declare const colCharsToPx: (chars: number) => number;
29
+ /** Excel row height (points) <-> Univer pixels. */
30
+ declare const rowPxToPt: (px: number) => number;
31
+ declare const rowPtToPx: (pt: number) => number;
32
+ /** Univer colour ("#rrggbb", "rgb(r,g,b)", "rgba(...)") -> ARGB hex, or undefined. */
33
+ declare function colorToArgb(input: string | undefined | null): string | undefined;
34
+ /** ARGB (or RGB) hex from a file -> Univer "#rrggbb". */
35
+ declare function argbToColor(argb: string | undefined | null): string | undefined;
36
+ declare const borderToExcel: (n: number | undefined) => string | undefined;
37
+ declare const borderFromExcel: (name: string | undefined) => number | undefined;
38
+ declare const H_ALIGN_OUT: Record<number, string>;
39
+ declare const V_ALIGN_OUT: Record<number, string>;
40
+ declare const H_ALIGN_IN: Record<string, number>;
41
+ declare const V_ALIGN_IN: Record<string, number>;
42
+ /** 0-based (row, col) -> "A1" (no $). */
43
+ declare function a1(row: number, col: number): string;
44
+ type RangeLike = {
45
+ startRow: number;
46
+ endRow: number;
47
+ startColumn: number;
48
+ endColumn: number;
49
+ };
50
+ declare const rangeToA1: (r: RangeLike) => string;
51
+ /** "A1" or "A1:C5" -> range (0-based), or null. */
52
+ declare function parseA1Range(ref: string): RangeLike | null;
53
+
54
+ /**
55
+ * univerToXlsx — convert a Univer IWorkbookData snapshot to an .xlsx file.
56
+ *
57
+ * Symmetric counterpart to `xlsx-to-univer.ts`. Carries everything the xlsx
58
+ * format can hold from what Univer holds: values, formulas, merged ranges,
59
+ * cell styles and number formats, column widths, row heights, frozen panes,
60
+ * data validation, conditional formatting, the header-row filter range,
61
+ * notes, comment threads (as notes), cell links, and pictures.
62
+ *
63
+ * What it cannot carry is NAMED in the returned report and shown to the person
64
+ * at export time — never dropped silently.
65
+ *
66
+ * Engine: ExcelJS (the xlsx reader/writer that holds styles, validation,
67
+ * conditional formatting, notes, links and images; the registered
68
+ * `xlsx-workbook` format writes values only). It is loaded on demand, so
69
+ * the editor bundle does not pay for it until someone exports or imports.
70
+ */
71
+
72
+ type ExportXlsxOptions = {
73
+ /** File name without extension. Defaults to "workbook". */
74
+ filename?: string;
75
+ /** Reads a picture's bytes (a `matrx-file:` reference or a URL). Pictures it cannot read are reported. */
76
+ resolveImage?: ExportImagePort;
77
+ };
78
+ type ExportImagePort = (source: string) => Promise<{
79
+ bytes: Uint8Array;
80
+ extension: "png" | "jpeg" | "gif";
81
+ } | null>;
82
+ /** What an export could not carry, in words for the person. Empty when nothing was lost. */
83
+ type XlsxExportReport = {
84
+ dropped: string[];
85
+ };
86
+ type Snapshot = Partial<IWorkbookData>;
87
+ /** A Univer snapshot as the `xlsx-workbook` format's value (sheets of typed cells + merges). */
88
+ declare function univerSnapshotToWorkbookJson(snapshot: Snapshot): WorkbookJson;
89
+ /** Full-fidelity bytes. Does NOT trigger a download. */
90
+ declare function univerSnapshotToXlsxBytes(snapshot: Snapshot, options?: Pick<ExportXlsxOptions, "resolveImage">): Promise<Uint8Array>;
91
+ /** Convert + trigger a browser download; returns what could not be carried. */
92
+ declare function downloadUniverAsXlsx(snapshot: Snapshot, options?: ExportXlsxOptions): Promise<XlsxExportReport>;
93
+ declare function buildXlsxFromUniver(snapshot: Snapshot, options?: Pick<ExportXlsxOptions, "resolveImage">): Promise<{
94
+ bytes: Uint8Array;
95
+ report: XlsxExportReport;
96
+ }>;
97
+ declare function univerSnapshotToRegisteredXlsxBytes(snapshot: Snapshot): Promise<Uint8Array>;
98
+
99
+ /**
100
+ * Full-fidelity .xlsx -> Univer reader (ExcelJS). The inverse of
101
+ * `univer-to-xlsx.ts`: styles, number formats, column widths, row heights,
102
+ * frozen panes, merges, data validation, conditional formatting, the filter
103
+ * range, notes, cell links and pictures. Free of Univer runtime imports (enums
104
+ * are numbers) so it runs under tests as well as in the browser.
105
+ */
106
+
107
+ type XlsxImportOptions = {
108
+ /** Stores a picture and returns its file id; without it pictures are reported, not imported. */
109
+ uploadImage?: (bytes: Uint8Array, extension: string) => Promise<string>;
110
+ /** Called once per thing the file held that could not be carried. */
111
+ onDropped?: (what: string) => void;
112
+ };
113
+
114
+ /**
115
+ * xlsxToUniverWorkbook — parse a spreadsheet file into a Univer IWorkbookData
116
+ * suitable for `apiRef.createWorkbook(...)` and for persistence as the initial
117
+ * snapshot of a new workbook.
118
+ *
119
+ * ONE reader: ExcelJS (`xlsx-to-univer-excel`) holds styles, number formats,
120
+ * widths, heights, frozen panes, merges, validation, conditional formatting,
121
+ * filter range, notes, links and pictures. A file that is not already an
122
+ * .xlsx (.xls, .ods, .csv, .tsv) is first re-written as an .xlsx by the
123
+ * Alchemy workbook door — values, formulas and merges — and read by that same
124
+ * reader, so there is no second import path to drift.
125
+ */
126
+
127
+ /**
128
+ * Parse a spreadsheet file into a Univer workbook. Whatever could not be
129
+ * carried is reported through `options.onDropped` (the caller tells the person).
130
+ */
131
+ declare function xlsxToUniverWorkbook(file: File, options?: XlsxImportOptions): Promise<Partial<IWorkbookData>>;
132
+
133
+ /**
134
+ * Spreadsheet file → a NEW workbook, the ONE import path: the Workbooks home and the editor's
135
+ * File → Import both run it. The file is parsed before anything is created (a malformed file leaves
136
+ * no empty workbook behind), the lossless original is stashed (non-fatal), and a failed save rolls
137
+ * the new row back.
138
+ */
139
+ /**
140
+ * Pre-flight import file check. We deliberately do NOT use the `accept`
141
+ * attribute on the picker (it greys out everything in Drive / Google
142
+ * Sheets pickers on iOS and many Android pickers), so we validate after
143
+ * pick. Returns null when the file is accepted, or a short user-facing
144
+ * reason string when it isn't.
145
+ */
146
+ declare function unsupportedFileReason(file: File): string | null;
147
+ declare function importWorkbookFile(file: File, organizationId: string | null): Promise<{
148
+ id: string;
149
+ name: string;
150
+ notCarried: string[];
151
+ }>;
152
+
153
+ export { type ExportImagePort, type ExportXlsxOptions, H_ALIGN_IN, H_ALIGN_OUT, RESOURCE, type RangeLike, type UniverResource, V_ALIGN_IN, V_ALIGN_OUT, type XlsxExportReport, a1, argbToColor, borderFromExcel, borderToExcel, buildXlsxFromUniver, colCharsToPx, colPxToChars, colorToArgb, downloadUniverAsXlsx, importWorkbookFile, parseA1Range, rangeToA1, readResource, rowPtToPx, rowPxToPt, univerSnapshotToRegisteredXlsxBytes, univerSnapshotToWorkbookJson, univerSnapshotToXlsxBytes, unsupportedFileReason, writeResource, xlsxToUniverWorkbook };
@@ -0,0 +1,153 @@
1
+ import { WorkbookJson } from '@ai-matrx/alchemy/operate/read';
2
+ import { IWorkbookData } from '@univerjs/core';
3
+
4
+ /**
5
+ * Shared vocabulary between the xlsx importer and exporter: how Univer's
6
+ * style numbers, colours and units map to the xlsx file's.
7
+ *
8
+ * Univer enums are written as numbers here so these helpers stay free of any
9
+ * Univer import (they run in tests and in both directions).
10
+ */
11
+ declare const RESOURCE: {
12
+ readonly validation: "SHEET_DATA_VALIDATION_PLUGIN";
13
+ readonly conditional: "SHEET_CONDITIONAL_FORMATTING_PLUGIN";
14
+ readonly filter: "SHEET_FILTER_PLUGIN";
15
+ readonly note: "SHEET_NOTE_PLUGIN";
16
+ readonly comments: "SHEET_UNIVER_THREAD_COMMENT_PLUGIN";
17
+ readonly drawing: "SHEET_DRAWING_PLUGIN";
18
+ readonly table: "SHEET_TABLE_PLUGIN";
19
+ };
20
+ type UniverResource = {
21
+ name: string;
22
+ data: string;
23
+ };
24
+ declare function readResource<T = unknown>(resources: readonly UniverResource[] | undefined, name: string): T | undefined;
25
+ declare function writeResource(resources: UniverResource[], name: string, value: unknown): void;
26
+ /** Excel column width (characters) <-> Univer pixels. */
27
+ declare const colPxToChars: (px: number) => number;
28
+ declare const colCharsToPx: (chars: number) => number;
29
+ /** Excel row height (points) <-> Univer pixels. */
30
+ declare const rowPxToPt: (px: number) => number;
31
+ declare const rowPtToPx: (pt: number) => number;
32
+ /** Univer colour ("#rrggbb", "rgb(r,g,b)", "rgba(...)") -> ARGB hex, or undefined. */
33
+ declare function colorToArgb(input: string | undefined | null): string | undefined;
34
+ /** ARGB (or RGB) hex from a file -> Univer "#rrggbb". */
35
+ declare function argbToColor(argb: string | undefined | null): string | undefined;
36
+ declare const borderToExcel: (n: number | undefined) => string | undefined;
37
+ declare const borderFromExcel: (name: string | undefined) => number | undefined;
38
+ declare const H_ALIGN_OUT: Record<number, string>;
39
+ declare const V_ALIGN_OUT: Record<number, string>;
40
+ declare const H_ALIGN_IN: Record<string, number>;
41
+ declare const V_ALIGN_IN: Record<string, number>;
42
+ /** 0-based (row, col) -> "A1" (no $). */
43
+ declare function a1(row: number, col: number): string;
44
+ type RangeLike = {
45
+ startRow: number;
46
+ endRow: number;
47
+ startColumn: number;
48
+ endColumn: number;
49
+ };
50
+ declare const rangeToA1: (r: RangeLike) => string;
51
+ /** "A1" or "A1:C5" -> range (0-based), or null. */
52
+ declare function parseA1Range(ref: string): RangeLike | null;
53
+
54
+ /**
55
+ * univerToXlsx — convert a Univer IWorkbookData snapshot to an .xlsx file.
56
+ *
57
+ * Symmetric counterpart to `xlsx-to-univer.ts`. Carries everything the xlsx
58
+ * format can hold from what Univer holds: values, formulas, merged ranges,
59
+ * cell styles and number formats, column widths, row heights, frozen panes,
60
+ * data validation, conditional formatting, the header-row filter range,
61
+ * notes, comment threads (as notes), cell links, and pictures.
62
+ *
63
+ * What it cannot carry is NAMED in the returned report and shown to the person
64
+ * at export time — never dropped silently.
65
+ *
66
+ * Engine: ExcelJS (the xlsx reader/writer that holds styles, validation,
67
+ * conditional formatting, notes, links and images; the registered
68
+ * `xlsx-workbook` format writes values only). It is loaded on demand, so
69
+ * the editor bundle does not pay for it until someone exports or imports.
70
+ */
71
+
72
+ type ExportXlsxOptions = {
73
+ /** File name without extension. Defaults to "workbook". */
74
+ filename?: string;
75
+ /** Reads a picture's bytes (a `matrx-file:` reference or a URL). Pictures it cannot read are reported. */
76
+ resolveImage?: ExportImagePort;
77
+ };
78
+ type ExportImagePort = (source: string) => Promise<{
79
+ bytes: Uint8Array;
80
+ extension: "png" | "jpeg" | "gif";
81
+ } | null>;
82
+ /** What an export could not carry, in words for the person. Empty when nothing was lost. */
83
+ type XlsxExportReport = {
84
+ dropped: string[];
85
+ };
86
+ type Snapshot = Partial<IWorkbookData>;
87
+ /** A Univer snapshot as the `xlsx-workbook` format's value (sheets of typed cells + merges). */
88
+ declare function univerSnapshotToWorkbookJson(snapshot: Snapshot): WorkbookJson;
89
+ /** Full-fidelity bytes. Does NOT trigger a download. */
90
+ declare function univerSnapshotToXlsxBytes(snapshot: Snapshot, options?: Pick<ExportXlsxOptions, "resolveImage">): Promise<Uint8Array>;
91
+ /** Convert + trigger a browser download; returns what could not be carried. */
92
+ declare function downloadUniverAsXlsx(snapshot: Snapshot, options?: ExportXlsxOptions): Promise<XlsxExportReport>;
93
+ declare function buildXlsxFromUniver(snapshot: Snapshot, options?: Pick<ExportXlsxOptions, "resolveImage">): Promise<{
94
+ bytes: Uint8Array;
95
+ report: XlsxExportReport;
96
+ }>;
97
+ declare function univerSnapshotToRegisteredXlsxBytes(snapshot: Snapshot): Promise<Uint8Array>;
98
+
99
+ /**
100
+ * Full-fidelity .xlsx -> Univer reader (ExcelJS). The inverse of
101
+ * `univer-to-xlsx.ts`: styles, number formats, column widths, row heights,
102
+ * frozen panes, merges, data validation, conditional formatting, the filter
103
+ * range, notes, cell links and pictures. Free of Univer runtime imports (enums
104
+ * are numbers) so it runs under tests as well as in the browser.
105
+ */
106
+
107
+ type XlsxImportOptions = {
108
+ /** Stores a picture and returns its file id; without it pictures are reported, not imported. */
109
+ uploadImage?: (bytes: Uint8Array, extension: string) => Promise<string>;
110
+ /** Called once per thing the file held that could not be carried. */
111
+ onDropped?: (what: string) => void;
112
+ };
113
+
114
+ /**
115
+ * xlsxToUniverWorkbook — parse a spreadsheet file into a Univer IWorkbookData
116
+ * suitable for `apiRef.createWorkbook(...)` and for persistence as the initial
117
+ * snapshot of a new workbook.
118
+ *
119
+ * ONE reader: ExcelJS (`xlsx-to-univer-excel`) holds styles, number formats,
120
+ * widths, heights, frozen panes, merges, validation, conditional formatting,
121
+ * filter range, notes, links and pictures. A file that is not already an
122
+ * .xlsx (.xls, .ods, .csv, .tsv) is first re-written as an .xlsx by the
123
+ * Alchemy workbook door — values, formulas and merges — and read by that same
124
+ * reader, so there is no second import path to drift.
125
+ */
126
+
127
+ /**
128
+ * Parse a spreadsheet file into a Univer workbook. Whatever could not be
129
+ * carried is reported through `options.onDropped` (the caller tells the person).
130
+ */
131
+ declare function xlsxToUniverWorkbook(file: File, options?: XlsxImportOptions): Promise<Partial<IWorkbookData>>;
132
+
133
+ /**
134
+ * Spreadsheet file → a NEW workbook, the ONE import path: the Workbooks home and the editor's
135
+ * File → Import both run it. The file is parsed before anything is created (a malformed file leaves
136
+ * no empty workbook behind), the lossless original is stashed (non-fatal), and a failed save rolls
137
+ * the new row back.
138
+ */
139
+ /**
140
+ * Pre-flight import file check. We deliberately do NOT use the `accept`
141
+ * attribute on the picker (it greys out everything in Drive / Google
142
+ * Sheets pickers on iOS and many Android pickers), so we validate after
143
+ * pick. Returns null when the file is accepted, or a short user-facing
144
+ * reason string when it isn't.
145
+ */
146
+ declare function unsupportedFileReason(file: File): string | null;
147
+ declare function importWorkbookFile(file: File, organizationId: string | null): Promise<{
148
+ id: string;
149
+ name: string;
150
+ notCarried: string[];
151
+ }>;
152
+
153
+ export { type ExportImagePort, type ExportXlsxOptions, H_ALIGN_IN, H_ALIGN_OUT, RESOURCE, type RangeLike, type UniverResource, V_ALIGN_IN, V_ALIGN_OUT, type XlsxExportReport, a1, argbToColor, borderFromExcel, borderToExcel, buildXlsxFromUniver, colCharsToPx, colPxToChars, colorToArgb, downloadUniverAsXlsx, importWorkbookFile, parseA1Range, rangeToA1, readResource, rowPtToPx, rowPxToPt, univerSnapshotToRegisteredXlsxBytes, univerSnapshotToWorkbookJson, univerSnapshotToXlsxBytes, unsupportedFileReason, writeResource, xlsxToUniverWorkbook };