revise 2.2.0 → 3.0.1

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 (134) hide show
  1. package/CHANGELOG.md +56 -1182
  2. package/LICENSE +24 -41
  3. package/README.md +103 -26
  4. package/agent.d.ts +139 -0
  5. package/chunks/chunk-U5X47PZ6.js +135 -0
  6. package/chunks/chunk-U6YKQBKL.js +15 -0
  7. package/chunks/chunk-ZLQVPMBN.js +1650 -0
  8. package/chunks/package-5SHL5FOJ.js +14 -0
  9. package/chunks/render-QD5VWKSV.js +109 -0
  10. package/cli-output.schema.json +1984 -0
  11. package/cli.js +3609 -0
  12. package/document.d.ts +320 -0
  13. package/docx.d.ts +73 -0
  14. package/errors.d.ts +14 -0
  15. package/index.d.ts +13 -975
  16. package/index.js +31 -1
  17. package/legacy/editor.d.ts +19 -0
  18. package/legacy/editor.js +16 -0
  19. package/legacy/server.d.ts +37 -0
  20. package/legacy/server.js +25 -0
  21. package/legacy/style.css +2 -0
  22. package/package.d.ts +23 -0
  23. package/package.json +49 -55
  24. package/render.d.ts +27 -0
  25. package/FONT-LICENSE-HAN-EXT-B.txt +0 -91
  26. package/FONT-LICENSE-KATEX.txt +0 -95
  27. package/FONT-LICENSE-LIBERATION.txt +0 -102
  28. package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +0 -93
  29. package/FONT-LICENSE-NOTO-SANS-SC.txt +0 -93
  30. package/FONT-LICENSE-NOTO.txt +0 -94
  31. package/FONT-LICENSE-SOURCE-CODE-PRO.txt +0 -94
  32. package/FONT-LICENSE-SOURCE-SERIF-4.txt +0 -93
  33. package/THIRD-PARTY-NOTICES.md +0 -3376
  34. package/assets/historyMaterializeWorker-B51R08XN.js +0 -612
  35. package/backend.d.ts +0 -161
  36. package/backend.js +0 -3
  37. package/chunks/AgentPageRenderer-CH8kSTJn.js +0 -1
  38. package/chunks/AgentPageRenderer-P23XVguo.js +0 -1
  39. package/chunks/AttachmentDocumentImporter-B1WOaa7d.js +0 -1
  40. package/chunks/AttachmentDocumentImporter-CT_PJp_e.js +0 -1
  41. package/chunks/BidiText-Swm5fl9J.js +0 -160
  42. package/chunks/ColorParserFull-BKH72fK8.js +0 -446
  43. package/chunks/DocumentMutator-btiDK57e.js +0 -31
  44. package/chunks/DocumentScrubber-CMPfm_HF.js +0 -18
  45. package/chunks/DocumentScrubber-Cm2kH8op.js +0 -1
  46. package/chunks/DocumentScrubber-bJoKijol.js +0 -1
  47. package/chunks/DocumentStylesheet-DreoD7sD.js +0 -7
  48. package/chunks/DocxConverter-BcVG-p5K.js +0 -13
  49. package/chunks/DocxConverter-D2bO5RE-.js +0 -1125
  50. package/chunks/DocxConverter-haCfRuWb.js +0 -13
  51. package/chunks/DocxGraft-BRKh4mHQ.js +0 -1
  52. package/chunks/DocxGraft-BxSQtl12.js +0 -7
  53. package/chunks/DocxGraft-C9MBQCnf.js +0 -1
  54. package/chunks/FileImporter-CszqRfVU.js +0 -1
  55. package/chunks/FileImporter-DObFoCCn.js +0 -1
  56. package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +0 -3
  57. package/chunks/HtmlConverter-DwXB4IDh.js +0 -267
  58. package/chunks/ListNumbering-Qlu6AuRZ.js +0 -23
  59. package/chunks/MarkdownConverter-CUC8GgsS.js +0 -57
  60. package/chunks/MathRenderer-DT6GyJXb.js +0 -68
  61. package/chunks/OdtConverter-7h9HHMpL.js +0 -125
  62. package/chunks/OdtConverter-Ct4qypJk.js +0 -6
  63. package/chunks/OdtConverter-DFl__sJc.js +0 -6
  64. package/chunks/OfficeImportShared-BY6FdZ8d.js +0 -1
  65. package/chunks/OfficeImportShared-BrZoDM0j.js +0 -30
  66. package/chunks/OfficeImportShared-Bvm-mOyj.js +0 -1
  67. package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +0 -36
  68. package/chunks/PdfConverter-1wyvoT7X.js +0 -21
  69. package/chunks/PdfConverter-BAoEHILo.js +0 -21
  70. package/chunks/PdfConverter-CKEvFj11.js +0 -448
  71. package/chunks/PdfImportService-BhLPp5uG.js +0 -2
  72. package/chunks/PdfImportService-xbzrN__L.js +0 -2
  73. package/chunks/RtfConverter-Bxn-enp8.js +0 -15
  74. package/chunks/RtfConverter-LZPzBDSr.js +0 -15
  75. package/chunks/RtfConverter-_bacXqr1.js +0 -186
  76. package/chunks/TableBorders-CwnF3jvH.js +0 -30
  77. package/chunks/TableGrid-DbroRucl.js +0 -12
  78. package/chunks/TextFileDecoder--rsVs3NR.js +0 -9
  79. package/chunks/TxtConverter-C7FOwHpH.js +0 -14
  80. package/chunks/UnicodeUtils-CXtusU4g.js +0 -10
  81. package/chunks/XmlConverter-7oo8oeQB.js +0 -2
  82. package/chunks/XmlConverter-DGORHJcZ.js +0 -96
  83. package/chunks/XmlConverter-DeLHReK_.js +0 -2
  84. package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
  85. package/chunks/_commonjsHelpers-DaMA6jEr.js +0 -2
  86. package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +0 -1
  87. package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +0 -1
  88. package/chunks/ar-ComXvtmh.js +0 -13
  89. package/chunks/backend-DecaBz-I.js +0 -490
  90. package/chunks/base64-sSPOzq-u.js +0 -198
  91. package/chunks/browser-module-CFmqfGkE.js +0 -1791
  92. package/chunks/browser-module-Dj5o3kuL.js +0 -3
  93. package/chunks/browser-module-UuM_O36W.js +0 -3
  94. package/chunks/bundle.min-DRpfgV69.js +0 -782
  95. package/chunks/capture-1btcWcPF.js +0 -9
  96. package/chunks/carrier-DQeng6yq.js +0 -6
  97. package/chunks/de-BkbpIKxx.js +0 -13
  98. package/chunks/es-CKkXujOF.js +0 -13
  99. package/chunks/fil-piIHMc8F.js +0 -13
  100. package/chunks/footnoteFlatten-DUQticYy.js +0 -6
  101. package/chunks/fr-DuA8qLje.js +0 -13
  102. package/chunks/graftExport-CYnStOdU.js +0 -82
  103. package/chunks/html2canvas.esm-CntiHiYW.js +0 -997
  104. package/chunks/index-2TBhRkX7.js +0 -387
  105. package/chunks/index-BWdRWxoH.js +0 -1807
  106. package/chunks/index-Bf14eTEW.js +0 -1096
  107. package/chunks/index-BwcX_r62.js +0 -387
  108. package/chunks/index.es-CI0QPo8w.js +0 -780
  109. package/chunks/index.es-CI7cDExj.js +0 -5
  110. package/chunks/index.es-DHpGt6Y5.js +0 -5
  111. package/chunks/ja-DgrSs555.js +0 -13
  112. package/chunks/jspdf.es.min--GshOuIm.js +0 -77
  113. package/chunks/jspdf.es.min-DU74zN8b.js +0 -1792
  114. package/chunks/jspdf.es.min-DurJZ1zW.js +0 -77
  115. package/chunks/jszip.min-CPW0h1Kx.js +0 -476
  116. package/chunks/katex-DWj8TvwO.js +0 -1462
  117. package/chunks/pdf-BLWDCiFF.js +0 -1828
  118. package/chunks/persistInlineDocumentImages-DQj2iaqg.js +0 -1
  119. package/chunks/pseudoLocale-BoYTjmiK.js +0 -1
  120. package/chunks/pseudoLocale-DG2NnZmz.js +0 -1
  121. package/chunks/purify.es-BwLardii.js +0 -107
  122. package/chunks/serverDocumentSession-CJ1EH3Tp.js +0 -15
  123. package/chunks/signatures-Bwt_OGik.js +0 -17
  124. package/chunks/suggestionAuthorship-B-IuLQlE.js +0 -1
  125. package/chunks/tree-sitter-D6zWWUMP.js +0 -4
  126. package/chunks/wasmInline.generated-CBYFkdSM.js +0 -1
  127. package/chunks/web-tree-sitter-BXGZGnNj.js +0 -2
  128. package/chunks/zh-9OF3SWWO.js +0 -13
  129. package/full.js +0 -1
  130. package/root.d.ts +0 -5
  131. package/root.js +0 -2
  132. package/serverToolContract.d.ts +0 -391
  133. package/serverToolInputs.generated.d.ts +0 -250
  134. package/style.css +0 -1
package/document.d.ts ADDED
@@ -0,0 +1,320 @@
1
+ import * as Y from "yjs";
2
+ import { ydocSourceFidelity, type ReviseServerExportFormat } from "@reviseio/engine";
3
+ import type { ImageFetchPolicy, ReviseDocumentMeasurementData, ReviseToolDefinition, ReviseJsonObject, ReviseToolArguments, ReviseToolName, ReviseToolResult, ServerDocumentSession } from "@reviseio/engine";
4
+ /** How faithfully the document exports back to its original Word file. */
5
+ export type SourceFidelity = Awaited<ReturnType<typeof ydocSourceFidelity>>;
6
+ import { type DocxExportOutcome } from "./docx.js";
7
+ import type { RenderOptions, RenderResult } from "./render.js";
8
+ export type DocumentMode = "suggesting" | "editing";
9
+ export type ExportFormat = ReviseServerExportFormat | "pdf";
10
+ /** Formats the library reads. */
11
+ export declare const READABLE: RegExp;
12
+ /** The export format a file name implies (`out.pdf` → "pdf"). */
13
+ export declare function formatForPath(file: string): ExportFormat | undefined;
14
+ /** A document to read: a path, or bytes with the file name they came from. */
15
+ export type DocumentSource = string | {
16
+ bytes: Uint8Array;
17
+ filename: string;
18
+ };
19
+ export interface OpenOptions {
20
+ /** Who edits and comments: shown as the author of tracked changes. */
21
+ author?: string;
22
+ /** "suggesting" records edits as tracked changes (the default for Word
23
+ * files); "editing" applies them directly (the default for plain text). */
24
+ mode?: DocumentMode;
25
+ /** A stable id for this document (tool sessions, collaboration). */
26
+ documentId?: string;
27
+ /** How images inserted by URL are fetched. By default only public http(s)
28
+ * hosts are reachable; see ImageFetchPolicy. */
29
+ images?: ImageFetchPolicy;
30
+ }
31
+ export interface ChangeEntry {
32
+ id: string;
33
+ type: string;
34
+ author: string;
35
+ blockId?: string;
36
+ blockIndex?: number;
37
+ /** The heading of the section the change is in. */
38
+ section?: string;
39
+ deleted: string;
40
+ inserted: string;
41
+ }
42
+ /** Which tracked changes to settle: exactly one of `ids`, `all`, or a
43
+ * section filter (`section` and/or `exceptSection`). */
44
+ export interface ChangeSelection {
45
+ ids?: string[];
46
+ all?: boolean;
47
+ /** "8", "8.", "Allocation of risk", or "8. Allocation". */
48
+ section?: string;
49
+ exceptSection?: string;
50
+ }
51
+ export interface SettleResult {
52
+ resolved: string[];
53
+ /** Requested ids that are not pending tracked changes. */
54
+ missing: string[];
55
+ /** Pending changes that could not be settled. */
56
+ unresolved: string[];
57
+ }
58
+ export interface GrepHit {
59
+ id: string;
60
+ blockIndex: number;
61
+ count: number;
62
+ text: string;
63
+ }
64
+ export interface ReplaceTextResult {
65
+ /** Occurrences replaced. */
66
+ replaced: number;
67
+ /** Ids of the blocks that contained the text. */
68
+ blocks: string[];
69
+ /** Tracked changes the replacement created (none in editing mode). */
70
+ changeIds: string[];
71
+ /** Blocks that contained the text but could not be edited. */
72
+ failures: Array<{
73
+ blockId: string;
74
+ code: string;
75
+ message: string;
76
+ }>;
77
+ }
78
+ export interface TextDiff {
79
+ /** Paragraph-level diff with word detail: `~ a [-old-]{+new+} b`. */
80
+ text: string;
81
+ changed: number;
82
+ }
83
+ export interface DocumentSummary {
84
+ text: string;
85
+ data: {
86
+ pages?: number;
87
+ words: number;
88
+ pageSize: string;
89
+ orientation: string;
90
+ pageInches: [number, number];
91
+ marginsInches: number[];
92
+ title?: string;
93
+ headings: Record<string, number>;
94
+ lists: number[];
95
+ tables: string[];
96
+ images: number;
97
+ headersFooters: Array<{
98
+ side: string;
99
+ slot: string;
100
+ text: string;
101
+ }>;
102
+ pendingTrackedChanges: number;
103
+ };
104
+ }
105
+ export interface ExportOptions {
106
+ format: ExportFormat;
107
+ /** "review" keeps tracked changes and comments; "final" accepts them.
108
+ * Only .docx can hold tracked changes: PDF, Markdown, HTML, and text
109
+ * always show them accepted. */
110
+ mode?: "review" | "final";
111
+ title?: string;
112
+ }
113
+ export interface ExportResult {
114
+ bytes: Uint8Array;
115
+ format: ExportFormat;
116
+ /** The mode the output actually has: only .docx can be "review". */
117
+ mode: "review" | "final";
118
+ /** Tracked changes still pending in the output. */
119
+ pendingTrackedChanges: number;
120
+ /** For .docx, what the export actually did: "graft" carried untouched
121
+ * content over byte for byte from the original file; "regenerated" wrote
122
+ * the whole file fresh (fallbackCode says why). */
123
+ fidelity: DocxExportOutcome | null;
124
+ warnings: string[];
125
+ }
126
+ /** Bytes of a document in a format, through graft export when the original
127
+ * Word package is available, with what the .docx export actually did. */
128
+ export declare function exportYDoc(ydoc: Y.Doc, pkg: Uint8Array | null, { format, mode, title }: ExportOptions): Promise<{
129
+ bytes: Uint8Array;
130
+ outcome: DocxExportOutcome | null;
131
+ }>;
132
+ /**
133
+ * One open document: a live Revise document model plus the agent tool
134
+ * session that edits it. Nothing touches disk unless you export it.
135
+ */
136
+ export declare class ReviseDocument {
137
+ private currentYDoc;
138
+ private currentSession;
139
+ private readonly settings;
140
+ private originalPackage;
141
+ /** False when the Y.Doc came from the caller (fromYDoc): it may be
142
+ * shared with an editor or a provider, so it is never replaced. */
143
+ private readonly ownsYDoc;
144
+ private disposed;
145
+ private queue;
146
+ private constructor();
147
+ /** Open a file (path) or bytes. Word files keep their original package,
148
+ * so untouched content exports byte for byte. */
149
+ static open(source: DocumentSource, options?: OpenOptions): Promise<ReviseDocument>;
150
+ /** Start a document from the HTML the tools read and write (headings,
151
+ * `data-style-id="Title"`, lists, tables), or from Markdown. */
152
+ static create(content?: {
153
+ html?: string;
154
+ markdown?: string;
155
+ title?: string;
156
+ }, options?: OpenOptions): Promise<ReviseDocument>;
157
+ /** Restore a document from `snapshot()` (or a bare Y.js update). Options
158
+ * override what the snapshot recorded. */
159
+ static restore(snapshot: Uint8Array, options?: OpenOptions): Promise<ReviseDocument>;
160
+ /** Wrap an existing Revise Y.Doc, e.g. one shared with an editor. The
161
+ * Y.Doc stays yours: `dispose()` leaves it intact, and `reload()` is not
162
+ * available (it would have to replace it). */
163
+ static fromYDoc(ydoc: Y.Doc, options?: OpenOptions & {
164
+ package?: Uint8Array | null;
165
+ title?: string;
166
+ }): Promise<ReviseDocument>;
167
+ private static build;
168
+ private static startSession;
169
+ private assertOpen;
170
+ /** Run `work` after every operation already queued on this document. */
171
+ private serial;
172
+ /** The live document model. Shared with `@reviseio/editor`. */
173
+ get ydoc(): Y.Doc;
174
+ /** The low-level tool session behind `tools`: an escape hatch for what
175
+ * the methods here don't cover. */
176
+ get session(): ServerDocumentSession;
177
+ get mode(): DocumentMode;
178
+ /** Switch between tracked changes ("suggesting") and direct edits. */
179
+ setMode(mode: DocumentMode): Promise<void>;
180
+ get author(): string | undefined;
181
+ get documentId(): string;
182
+ /** The original Word package that export grafts onto, if any. */
183
+ get package(): Uint8Array | null;
184
+ /** The complete document (versioned; includes the original Word package)
185
+ * to store or hand to `@reviseio/editor`, as of every operation queued
186
+ * before this call. Restore with `restore()`. */
187
+ snapshot(): Promise<Uint8Array>;
188
+ /** An opaque value that changes whenever the document does (including
189
+ * edits that only delete, which a state vector misses). */
190
+ version(): Uint8Array;
191
+ /**
192
+ * Re-read the document from new bytes (it changed elsewhere). Block ids
193
+ * carry over only where identity is provable (Word's paragraph ids, or
194
+ * identical content); `changedIds` lists kept ids whose content changed,
195
+ * so earlier reads of them are stale. Replaces the Y.Doc, so it is not
196
+ * available on a document made with `fromYDoc`.
197
+ */
198
+ reload(bytes: Uint8Array, filename: string): Promise<{
199
+ idsKept: number;
200
+ idsNew: number;
201
+ changedIds: string[];
202
+ removedIds: string[];
203
+ }>;
204
+ /** Start the tool session over: forget what the agent has read and
205
+ * searched (e.g. after the host compacts its transcript). */
206
+ resetToolContext(): Promise<void>;
207
+ /** Release the tool session. The document can't be used afterwards; a
208
+ * Y.Doc it created is destroyed, one passed to fromYDoc is left alone. */
209
+ dispose(): void;
210
+ readonly tools: {
211
+ /** Every editing tool's name, description, and JSON input schema. */
212
+ definitions: () => ReviseToolDefinition[];
213
+ /** Run a known tool with typed input. Expected failures come back as
214
+ * `{ ok: false, error }`; nothing throws for a bad edit. */
215
+ call: <Name extends ReviseToolName>(name: Name, ...args: ReviseToolArguments<Name>) => Promise<ReviseToolResult<Name>>;
216
+ /** Run a tool by name with untyped input (agent tool calls). Unknown
217
+ * tools and bad input come back as `{ ok: false, error }` too. */
218
+ run: (name: string, input?: ReviseJsonObject, options?: {
219
+ direct?: boolean;
220
+ }) => Promise<ReviseToolResult<string>>;
221
+ };
222
+ /** The document's title for exports: its saved title property (dc:title
223
+ * in a .docx, or set_title's), else the name it was opened under. */
224
+ private title;
225
+ /** set_title renames the document in the editor. In a file, the title is
226
+ * the document property (docProps/core.xml in a .docx, the PDF title), so
227
+ * it is saved there too; without this, the tool reported success and the
228
+ * saved file kept its old title. */
229
+ private afterTool;
230
+ /** Sections with their block ranges and word counts. */
231
+ outline(options?: {
232
+ limit?: number;
233
+ offset?: number;
234
+ }): Promise<ReviseDocumentMeasurementData>;
235
+ /** Blocks, words, pending changes, and how faithfully it exports to Word. */
236
+ status(): Promise<{
237
+ blocks: number;
238
+ words: number;
239
+ pendingSuggestions: number;
240
+ fidelity: SourceFidelity | null;
241
+ }>;
242
+ /** Text-bearing blocks matching a pattern (paragraphs, headings, list
243
+ * items, table-cell paragraphs), with their ids. */
244
+ grep(pattern: string | RegExp, options?: {
245
+ ignoreCase?: boolean;
246
+ }): GrepHit[];
247
+ /** What the document holds, in one glance: page setup, header and footer
248
+ * text with live fields, title, headings, lists, tables, review state. */
249
+ summary(): Promise<DocumentSummary>;
250
+ /** Replace every exact occurrence, block by block (tracked changes in
251
+ * suggesting mode). `ids` limits it to those blocks. Replacing text with
252
+ * itself changes nothing and is not a failure. */
253
+ replaceText(find: string, replace: string, options?: {
254
+ ids?: string[];
255
+ }): Promise<ReplaceTextResult>;
256
+ /** Pending tracked changes with where they are and what they do. */
257
+ changes(filter?: {
258
+ section?: string;
259
+ exceptSection?: string;
260
+ }): Promise<ChangeEntry[]>;
261
+ private filteredChanges;
262
+ /** The tracked changes a selection would settle, without settling them. */
263
+ preview(selection: ChangeSelection): Promise<ChangeEntry[]>;
264
+ accept(selection: ChangeSelection): Promise<SettleResult>;
265
+ reject(selection: ChangeSelection): Promise<SettleResult>;
266
+ private selectedIds;
267
+ private settle;
268
+ /**
269
+ * What the pending tracked changes do to the text (before → after), or
270
+ * what changed since `baseline` (a snapshot).
271
+ */
272
+ diff(baseline?: Uint8Array): Promise<TextDiff>;
273
+ /** Write the document in a format. Reports what the output actually
274
+ * contains: its pending changes, and for .docx how much of the original
275
+ * file was carried over byte for byte. */
276
+ export(options: ExportOptions): Promise<ExportResult>;
277
+ /** Pages as images, laid out exactly as the editor lays them out. */
278
+ renderPages(options?: RenderOptions): Promise<RenderResult>;
279
+ }
280
+ export interface CompareResult {
281
+ /** The revised document with every difference as a tracked change. */
282
+ document: ReviseDocument;
283
+ stats: {
284
+ inlineChanges: number;
285
+ insertedBlocks: number;
286
+ deletedBlocks: number;
287
+ unmarkedBlocks: number;
288
+ };
289
+ untrackedRegions: string[];
290
+ /** Accepting every change in the exported redline (read back from the
291
+ * .docx) gives the revised text; rejecting every change gives the
292
+ * original. Text only: formatting and comments are not compared. */
293
+ verified: {
294
+ acceptAllGivesRevised: boolean;
295
+ rejectAllGivesOriginal: boolean;
296
+ };
297
+ }
298
+ /** A redline: `revised` with every difference from `original` tracked. */
299
+ /**
300
+ * Seed a collaboration room (a Y.Doc your sync server owns) from a file, and
301
+ * say whether it wrote anything. A room that already holds a document is
302
+ * left alone, so call it on every connection:
303
+ *
304
+ * onLoadDocument: async ({ document }) => {
305
+ * await seedYDoc(document, "contract.docx");
306
+ * }
307
+ *
308
+ * Two peers that both seeded an empty room before syncing are repaired to a
309
+ * single copy. A Word file is stored in the room too, so any session over
310
+ * it (`ReviseDocument.fromYDoc`, or the editor) exports untouched content
311
+ * byte for byte.
312
+ */
313
+ export declare function seedYDoc(ydoc: Y.Doc, source: DocumentSource): Promise<boolean>;
314
+ export declare function compare(originalSource: DocumentSource, revisedSource: DocumentSource, options?: OpenOptions): Promise<CompareResult>;
315
+ /** Convert a document to another format in one step. */
316
+ export declare function convert(source: DocumentSource, format: ExportFormat, options?: {
317
+ mode?: "review" | "final";
318
+ }): Promise<Uint8Array>;
319
+ /** Section filter: "8", "8.", "Allocation of risk", or "8. Allocation". */
320
+ export declare function inSection(entry: ChangeEntry, query: string): boolean;
package/docx.d.ts ADDED
@@ -0,0 +1,73 @@
1
+ import * as Y from "yjs";
2
+ import type { DocRoot } from "@reviseio/engine";
3
+ /** What a .docx export actually did. */
4
+ export interface DocxExportOutcome {
5
+ /** "graft": untouched content copied byte for byte from the original;
6
+ * "regenerated": the whole file written fresh (no original, or graft
7
+ * refused it, see fallbackCode). */
8
+ method: "graft" | "regenerated";
9
+ exact: boolean;
10
+ regeneratedBlocks: number;
11
+ fallbackCode?: string;
12
+ }
13
+ /**
14
+ * The session as a .docx: the model's changes grafted onto the session's
15
+ * package. Without a package (a document not opened from .docx) it is the
16
+ * ordinary export. Paragraphs and rows the export writes fresh get a
17
+ * w14:paraId if they lack one (see stampParaIds); untouched ones never do.
18
+ * Reports what the converter actually did, not what it was asked to do.
19
+ */
20
+ export declare function exportSessionDocx(ydoc: Y.Doc, pkg: Uint8Array | null, mode?: "review" | "final"): Promise<{
21
+ bytes: Uint8Array;
22
+ outcome: DocxExportOutcome;
23
+ }>;
24
+ /** The w14:paraId revise writes for a block it created: derived from the
25
+ * block id, so it is the same on every save and maps back on re-read.
26
+ * Word's rules: 8 hex digits, below 0x80000000. */
27
+ export declare function derivedParaId(blockId: string, salt?: number): string;
28
+ /**
29
+ * Give paragraphs and table rows a w14:paraId where they lack one, but only
30
+ * in blocks the export writes fresh (`regenerated`; null = every block):
31
+ * untouched content keeps its exact bytes. Returns a copy.
32
+ */
33
+ /** What graft export copies from the original: whole parts, and changed
34
+ * rows whose own properties (their head) are unchanged. */
35
+ interface GraftKept {
36
+ whole: Set<string>;
37
+ head: Set<string>;
38
+ }
39
+ export declare function stampParaIds(doc: DocRoot, regenerated: ReadonlySet<string> | null,
40
+ /** Parts the graft copies from the original: never stamped. */
41
+ kept?: GraftKept): DocRoot;
42
+ export interface IdMatchReport {
43
+ /** Ids carried over to the re-read document. */
44
+ kept: number;
45
+ /** New blocks (or ones with no provable identity): fresh ids. */
46
+ fresh: number;
47
+ /** Kept ids whose content changed: earlier reads of them are stale. */
48
+ changedIds: string[];
49
+ /** Old ids that no longer exist. */
50
+ removedIds: string[];
51
+ }
52
+ /** Carry ids from `previous` onto the re-imported `next` (mutated). */
53
+ export declare function matchIds(previous: DocRoot, next: DocRoot): IdMatchReport;
54
+ export interface SyncResult {
55
+ ydoc: Y.Doc;
56
+ pkg: Uint8Array;
57
+ idsKept: number;
58
+ idsNew: number;
59
+ /** Kept ids whose content changed: earlier reads of them are stale. */
60
+ changedIds: string[];
61
+ /** Ids that no longer exist. */
62
+ removedIds: string[];
63
+ changedBlocks: number;
64
+ changedStyles: string[];
65
+ }
66
+ /**
67
+ * Make `bytes` (any supported format) the session's model: parse them, carry
68
+ * block ids over where identity is provable (see matchIds), and
69
+ * keep a .docx as the graft package. Used after an xml patch and when the
70
+ * file changed outside revise.
71
+ */
72
+ export declare function relearn(ydoc: Y.Doc, bytes: Uint8Array, filename: string): Promise<SyncResult>;
73
+ export {};
package/errors.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The one error type the library throws for expected failures (a missing
3
+ * file, an unsupported format, a malformed patch). `code` is stable and
4
+ * machine-readable; the CLI prints it as `error <code>: <message>`.
5
+ */
6
+ export declare class ReviseError extends Error {
7
+ readonly code: string;
8
+ /** The underlying error, when this one wraps another (a filesystem or
9
+ * parser failure). */
10
+ readonly cause?: unknown;
11
+ constructor(message: string, code?: string, options?: {
12
+ cause?: unknown;
13
+ });
14
+ }