@betteroffice/docx 0.0.1 → 0.0.3

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 (165) hide show
  1. package/README.md +19 -0
  2. package/dist/chunk-AEQOEQJ7.mjs +57 -0
  3. package/dist/chunk-AZ52IWB6.mjs +16 -0
  4. package/dist/{chunk-SINEY6ZF.mjs → chunk-B4IR6YP4.mjs} +1 -1
  5. package/dist/chunk-GGEGIQRK.mjs +1 -0
  6. package/dist/chunk-IFT6DUJX.mjs +1 -0
  7. package/dist/chunk-J7LNO6SM.mjs +1 -0
  8. package/dist/{chunk-H3JCIGWK.mjs → chunk-NJHOPXZW.mjs} +1 -1
  9. package/dist/{chunk-KXNZFTTK.mjs → chunk-WBH3SXI6.mjs} +1 -1
  10. package/dist/chunk-WON6K4FY.mjs +1 -0
  11. package/dist/chunk-Y7RUNRU2.mjs +1 -0
  12. package/dist/collaboration/index.d.mts +65 -0
  13. package/dist/collaboration/index.mjs +1 -0
  14. package/dist/{content-sSHuWw49.d.mts → content-MOZ6hKP4.d.mts} +357 -357
  15. package/dist/core.d.mts +148 -341
  16. package/dist/core.mjs +1 -1
  17. package/dist/{displayListQueries-p-ijSzdh.d.mts → displayListQueries-BJlo7Jkz.d.mts} +24 -6
  18. package/dist/docx/index.d.mts +40 -520
  19. package/dist/docx/index.mjs +2 -2
  20. package/dist/editor/index.d.mts +36 -151
  21. package/dist/editor/index.mjs +1 -1
  22. package/dist/{fontLoader-Bx6DK6-2.d.mts → fontLoader-aSewHMKF.d.mts} +65 -63
  23. package/dist/{formatting-DoL7KBSL.d.mts → formatting-D1EPSaJP.d.mts} +1 -1
  24. package/dist/{rustDisplayList-dqunvwxH.d.mts → frameDelta-D965X8yK.d.mts} +3 -274
  25. package/dist/generated/edit/docx_edit_bg.wasm +0 -0
  26. package/dist/generated/layout/docx_layout_bg.wasm +0 -0
  27. package/dist/generated/opc/ooxml_opc_bg.wasm +0 -0
  28. package/dist/generated/parse/docx_parse_bg.wasm +0 -0
  29. package/dist/index-Dx4Z3lkz.d.mts +1010 -0
  30. package/dist/layout/index.d.mts +19 -240
  31. package/dist/layout/index.mjs +1 -1
  32. package/dist/layout/pagination/index.d.mts +10 -58
  33. package/dist/layout/pagination/index.mjs +1 -1
  34. package/dist/layout/render/index.d.mts +11 -11
  35. package/dist/layout/render/index.mjs +1 -1
  36. package/dist/plugin-api/RenderedDomContext.d.mts +9 -9
  37. package/dist/plugin-api/index.d.mts +191 -6
  38. package/dist/plugin-api/resolveItemPositions.d.mts +4 -5
  39. package/dist/rustDisplayList-BRuZBqdL.d.mts +278 -0
  40. package/dist/rustMeasureSource-D1KsQvVC.d.mts +106 -0
  41. package/dist/selectiveSave-CVoajSKE.d.mts +56 -0
  42. package/dist/styles/index.d.mts +4 -39
  43. package/dist/styles/index.mjs +1 -1
  44. package/dist/{styles-VxNcXLdi.d.mts → styles-Dn_o3Vo5.d.mts} +2 -2
  45. package/dist/types/content.d.mts +2 -2
  46. package/dist/types/document.d.mts +40 -14
  47. package/dist/{types-DNrYr6yQ.d.mts → types-BfqUl2h_.d.mts} +3 -71
  48. package/dist/utils/comments.d.mts +2 -2
  49. package/dist/utils/index.d.mts +110 -576
  50. package/dist/utils/index.mjs +1 -84
  51. package/dist/utils/stylePreview.d.mts +2 -2
  52. package/dist/utils/units.d.mts +33 -2
  53. package/dist/wasm-DO3BUV7C.mjs +1 -0
  54. package/dist/wasm-NWXX4H5G.mjs +1 -0
  55. package/dist/wasm-edit.d.mts +14 -5
  56. package/dist/wasm-edit.mjs +1 -1
  57. package/dist/wasm-layout.d.mts +10 -1
  58. package/dist/wasm-layout.mjs +1 -1
  59. package/dist/wasm-opc.mjs +1 -1
  60. package/dist/wasm-parse.mjs +1 -1
  61. package/dist/yrs/index.d.mts +6 -881
  62. package/dist/yrs/index.mjs +1 -1
  63. package/dist/yrs/residentEngineWorker.mjs +1 -1
  64. package/package.json +16 -139
  65. package/dist/Subscribable-DOz6Ohoo.d.mts +0 -33
  66. package/dist/agent/index.d.mts +0 -531
  67. package/dist/agent/index.mjs +0 -1
  68. package/dist/chunk-34K66SY4.mjs +0 -1
  69. package/dist/chunk-4RCISPPE.mjs +0 -1
  70. package/dist/chunk-52GB3Y42.mjs +0 -1
  71. package/dist/chunk-6NEKRDXF.mjs +0 -1
  72. package/dist/chunk-6PW4CWUG.mjs +0 -1
  73. package/dist/chunk-7DEIW7FL.mjs +0 -1
  74. package/dist/chunk-7PCO5I2O.mjs +0 -1
  75. package/dist/chunk-BI3B33LI.mjs +0 -1
  76. package/dist/chunk-BIQWVK5P.mjs +0 -2
  77. package/dist/chunk-CIRN3LZA.mjs +0 -1
  78. package/dist/chunk-DXKG3HQ5.mjs +0 -16
  79. package/dist/chunk-FPZBTOD6.mjs +0 -1
  80. package/dist/chunk-FZIA7OFY.mjs +0 -1
  81. package/dist/chunk-GWKJ2Y4Y.mjs +0 -1
  82. package/dist/chunk-HJGAQIU7.mjs +0 -2
  83. package/dist/chunk-I6KKMUUC.mjs +0 -1
  84. package/dist/chunk-IL5JZJT7.mjs +0 -1
  85. package/dist/chunk-JY6ILTNS.mjs +0 -1
  86. package/dist/chunk-KEE52TT5.mjs +0 -1
  87. package/dist/chunk-KVKLLTDP.mjs +0 -58
  88. package/dist/chunk-L5ISVQ3W.mjs +0 -1
  89. package/dist/chunk-LDUWIM7M.mjs +0 -1
  90. package/dist/chunk-N5Q3YN64.mjs +0 -1
  91. package/dist/chunk-NEWOMDTX.mjs +0 -1
  92. package/dist/chunk-O2QSE2I7.mjs +0 -1
  93. package/dist/chunk-OJOHXQNQ.mjs +0 -1
  94. package/dist/chunk-OMR3TWCD.mjs +0 -2
  95. package/dist/chunk-P3KDV4M2.mjs +0 -1
  96. package/dist/chunk-Q7PO7V73.mjs +0 -1
  97. package/dist/chunk-QOUFE3VX.mjs +0 -1
  98. package/dist/chunk-TYHI7RAD.mjs +0 -1
  99. package/dist/chunk-UIEJWORW.mjs +0 -1
  100. package/dist/chunk-VAOUFAUH.mjs +0 -1
  101. package/dist/chunk-VBOTMRXV.mjs +0 -1
  102. package/dist/chunk-VCER63GQ.mjs +0 -1
  103. package/dist/chunk-WAUF2UC7.mjs +0 -2
  104. package/dist/chunk-X4XDO3LZ.mjs +0 -1
  105. package/dist/chunk-XQBCCJBO.mjs +0 -9
  106. package/dist/chunk-XWUOLYRQ.mjs +0 -2
  107. package/dist/chunk-XYH6XWP3.mjs +0 -10
  108. package/dist/chunk-YBIM6UJV.mjs +0 -8
  109. package/dist/chunk-YCIH2Q3E.mjs +0 -1
  110. package/dist/chunk-ZOV5KL7C.mjs +0 -1
  111. package/dist/colorResolver-n0o7H7ep.d.mts +0 -290
  112. package/dist/core-plugins.d.mts +0 -37
  113. package/dist/core-plugins.mjs +0 -1
  114. package/dist/docx/parser.d.mts +0 -41
  115. package/dist/docx/parser.mjs +0 -1
  116. package/dist/docx/rezip.d.mts +0 -148
  117. package/dist/docx/rezip.mjs +0 -1
  118. package/dist/docx/serializer/index.d.mts +0 -42
  119. package/dist/docx/serializer/index.mjs +0 -1
  120. package/dist/editorTree-DO5PyDK8.d.mts +0 -37
  121. package/dist/executor-7O2RBJ2B.mjs +0 -1
  122. package/dist/headerFooterLayout-0zPT64Qc.d.mts +0 -316
  123. package/dist/headless.d.mts +0 -69
  124. package/dist/headless.mjs +0 -1
  125. package/dist/layout/flow/index.d.mts +0 -149
  126. package/dist/layout/flow/index.mjs +0 -1
  127. package/dist/layout/measure/index.d.mts +0 -324
  128. package/dist/layout/measure/index.mjs +0 -1
  129. package/dist/layout/pagination/types.d.mts +0 -4
  130. package/dist/layout/pagination/types.mjs +0 -1
  131. package/dist/managers/AutoSaveManager.d.mts +0 -81
  132. package/dist/managers/AutoSaveManager.mjs +0 -1
  133. package/dist/managers/TableSelectionManager.d.mts +0 -74
  134. package/dist/managers/TableSelectionManager.mjs +0 -1
  135. package/dist/managers/types.d.mts +0 -113
  136. package/dist/managers/types.mjs +0 -0
  137. package/dist/mcp-cli.mjs +0 -142
  138. package/dist/mcp.d.mts +0 -162
  139. package/dist/mcp.mjs +0 -16
  140. package/dist/measureBlocksPipeline-Df0Bbrwy.d.mts +0 -109
  141. package/dist/measuredBlock-DZwz8zhD.d.mts +0 -26
  142. package/dist/plugin-api/types.d.mts +0 -193
  143. package/dist/plugin-api/types.mjs +0 -0
  144. package/dist/processTemplate-HDUIZFJ5.mjs +0 -1
  145. package/dist/registry-DMM5VTdT.d.mts +0 -165
  146. package/dist/rustPagination-Bj2hq013.d.mts +0 -106
  147. package/dist/sectionConfigs-DW3J8q0X.d.mts +0 -55
  148. package/dist/selectionContext-Buc9BCU1.d.mts +0 -570
  149. package/dist/selectiveSave-oFBJ1n71.d.mts +0 -16
  150. package/dist/selectiveXmlPatch-ypkxlTD_.d.mts +0 -23
  151. package/dist/settingsParser-CcGvtmCK.d.mts +0 -33
  152. package/dist/types/agentApi.d.mts +0 -456
  153. package/dist/types/agentApi.mjs +0 -1
  154. package/dist/types-dYdjUZMo.d.mts +0 -311
  155. package/dist/units-O5Y02RKQ.d.mts +0 -34
  156. package/dist/utils/headingCollector.d.mts +0 -28
  157. package/dist/utils/headingCollector.mjs +0 -1
  158. package/dist/utils/highlightColors.d.mts +0 -14
  159. package/dist/utils/highlightColors.mjs +0 -1
  160. package/dist/utils/textSelection.d.mts +0 -92
  161. package/dist/utils/textSelection.mjs +0 -1
  162. package/dist/variableDetector-Borj29SF.d.mts +0 -115
  163. package/dist/wasm-FZQ5XB2Y.mjs +0 -1
  164. package/dist/wasm-SA237OSP.mjs +0 -1
  165. package/dist/watermarkApi-DCxjutkg.d.mts +0 -38
@@ -0,0 +1,1010 @@
1
+ import { R as RetainedFrame } from './frameDelta-D965X8yK.mjs';
2
+ import { Document } from './types/document.mjs';
3
+
4
+ type CollaborationUpdateOrigin = 'local' | 'remote';
5
+ interface CollaborationReplica {
6
+ readonly clientId: number;
7
+ encodeStateVector(): Uint8Array;
8
+ encodeStateAsUpdate(remoteStateVector?: Uint8Array): Uint8Array;
9
+ applyUpdate(update: Uint8Array): unknown;
10
+ onUpdate(listener: (update: Uint8Array, origin: CollaborationUpdateOrigin) => void): () => void;
11
+ }
12
+ type CollaborationTransportEvent = {
13
+ type: 'open';
14
+ } | {
15
+ type: 'message';
16
+ data: Uint8Array;
17
+ } | {
18
+ type: 'close';
19
+ reason?: string;
20
+ } | {
21
+ type: 'error';
22
+ error: unknown;
23
+ } | {
24
+ type: 'drain';
25
+ };
26
+ interface CollaborationTransport {
27
+ /** Starts one connection attempt; transports may also reopen while still subscribed. */
28
+ connect(): void | Promise<void>;
29
+ disconnect(): void | Promise<void>;
30
+ /** Returns true only when the owned frame was accepted; false requires a later drain event. */
31
+ send(data: Uint8Array): boolean;
32
+ onEvent(listener: (event: CollaborationTransportEvent) => void): () => void;
33
+ }
34
+ type CollaborationStatus = 'disconnected' | 'connecting' | 'connected' | 'destroyed';
35
+ interface CollaborationStatusChange {
36
+ status: CollaborationStatus;
37
+ synced: boolean;
38
+ }
39
+ type CollaborationErrorCode = 'backpressure' | 'protocol' | 'replica' | 'transport';
40
+ declare class CollaborationError extends Error {
41
+ readonly code: CollaborationErrorCode;
42
+ readonly cause: unknown;
43
+ constructor(code: CollaborationErrorCode, message: string, cause?: unknown);
44
+ }
45
+ interface CollaborationProviderOptions {
46
+ maxFrameBytes?: number;
47
+ maxMessagesPerFrame?: number;
48
+ maxPendingBytes?: number;
49
+ }
50
+ type CollaborationStatusListener = (change: CollaborationStatusChange) => void;
51
+ type CollaborationErrorListener = (error: CollaborationError) => void;
52
+
53
+ /** One native paragraph in the yrs-backed display-position projection. */
54
+ interface YrsInputParagraphSpan {
55
+ paraId: string;
56
+ /** Number of UTF-16/inline units before the paragraph's pilcrow. */
57
+ length: number;
58
+ /** Block start emitted by the yrs display-position projection. */
59
+ displayStart: number;
60
+ }
61
+ /**
62
+ * Live converter between display-list positions and public yrs Locs.
63
+ *
64
+ * A native paragraph of length N occupies N+2 display positions (open token,
65
+ * content, close token), so this map can be rebuilt directly from the live yrs
66
+ * paragraph spans after every structural edit.
67
+ */
68
+ interface YrsInputPositionMap {
69
+ story: string;
70
+ paragraphs: readonly YrsInputParagraphSpan[];
71
+ }
72
+ interface YrsInputParagraphSeed {
73
+ paraId: string;
74
+ length: number;
75
+ }
76
+ declare function createYrsInputPositionMap(story: string, seeds: readonly YrsInputParagraphSeed[]): YrsInputPositionMap;
77
+ /** Convert a live yrs location to the position used by display-list geometry. */
78
+ declare function yrsLocToDisplayPosition(map: YrsInputPositionMap, loc: YrsLoc): number;
79
+ /** Convert a display-list hit position to a paragraph-keyed yrs location. */
80
+ declare function displayPositionToYrsLoc(map: YrsInputPositionMap, position: number): YrsLoc | null;
81
+ /** Compare two Locs in document order using one live map. */
82
+ declare function compareYrsLocs(map: YrsInputPositionMap, a: YrsLoc, b: YrsLoc): number;
83
+
84
+ /** Resolved styling for the worker-painted caret (the worker cannot read CSS vars). */
85
+ interface ResidentCaretPaintStyle {
86
+ color: string;
87
+ /** CSS-px stroke width, matching the DOM caret's un-zoomed width. */
88
+ width: number;
89
+ }
90
+ /** Device-px caret rect: geometry scales by dpr*zoom, stroke width by dpr only
91
+ * (the DOM caret keeps its CSS-px width across zoom levels). */
92
+ declare function residentCaretDeviceRect(rect: Pick<YrsResidentCaretRect, 'x' | 'y' | 'height'>, style: ResidentCaretPaintStyle, devicePixelRatio: number, zoom: number): {
93
+ x: number;
94
+ y: number;
95
+ width: number;
96
+ height: number;
97
+ };
98
+ declare function residentCaretSnapshotForFrame(snapshot: YrsResidentCaretSnapshot, frame: RetainedFrame): YrsResidentCaretSnapshot | null;
99
+
100
+ interface ResidentEngineWorkerFrame {
101
+ frame: Uint8Array;
102
+ updates: Uint8Array[];
103
+ engineMs: number;
104
+ workerTotalMs: number;
105
+ engineProfile?: YrsEngineApplyProfile;
106
+ caret: YrsResidentCaretSnapshot;
107
+ selection: YrsSelection | null;
108
+ /** The presented frame carries the worker-painted caret line. */
109
+ caretPainted: boolean;
110
+ replayMs: number;
111
+ replayedPages: number;
112
+ layoutRevision: number;
113
+ }
114
+ interface ResidentEngineOffscreenPage {
115
+ pageId: string;
116
+ canvas: OffscreenCanvas;
117
+ }
118
+ interface ResidentEngineWorkerApplyResult extends ResidentEngineWorkerFrame {
119
+ applied: true;
120
+ }
121
+ /** Dedicated-worker owner for resident input, pagination, and FrameDelta output. */
122
+ declare class ResidentEngineWorkerClient {
123
+ private readonly worker;
124
+ private readonly pending;
125
+ private nextId;
126
+ private destroyed;
127
+ private ready;
128
+ private revision;
129
+ private remoteVector;
130
+ private appliedFontsRevision;
131
+ constructor();
132
+ isReady(): boolean;
133
+ layoutRevision(): number;
134
+ /** The worker replica's last reported yrs state vector (null before any). */
135
+ remoteStateVector(): Uint8Array | null;
136
+ /** The fonts revision this worker last applied (null before bootstrap). */
137
+ syncedFontsRevision(): number | null;
138
+ bootstrap(snapshot: YrsResidentWorkerSnapshot, extras: string): Promise<ResidentEngineWorkerFrame>;
139
+ sync(snapshot: YrsResidentWorkerSnapshot, extras: string, expectedFrameEpoch: number, paintCaret?: boolean): Promise<ResidentEngineWorkerFrame>;
140
+ buildFrame(extras: string, expectedFrameEpoch: number, paintCaret?: boolean): Promise<ResidentEngineWorkerFrame>;
141
+ applyInput(text: string, selection: YrsSelection, expectedFrameEpoch: number, profile?: boolean, paintCaret?: boolean): Promise<ResidentEngineWorkerApplyResult | {
142
+ applied: false;
143
+ }>;
144
+ applyDelete(direction: 'backward' | 'forward', selection: YrsSelection, expectedFrameEpoch: number, profile?: boolean, paintCaret?: boolean): Promise<ResidentEngineWorkerApplyResult | {
145
+ applied: false;
146
+ }>;
147
+ /** Drop the worker-painted caret line by re-presenting the caret page's
148
+ * retained raster. Fire-and-forget and idempotent. */
149
+ eraseCaret(): void;
150
+ invalidate(update: Uint8Array, selection: YrsSelection | null): void;
151
+ attachCanvases(pages: ResidentEngineOffscreenPage[], activePageIds: string[], devicePixelRatio: number, zoom: number, caretStyle: ResidentCaretPaintStyle): Promise<void>;
152
+ destroy(): void;
153
+ private request;
154
+ /** Record a successfully applied bootstrap/sync payload's fonts revision.
155
+ * The state vector is tracked centrally in `onmessage`. */
156
+ private recordSync;
157
+ private failAll;
158
+ }
159
+ declare function canUseResidentEngineWorker(): boolean;
160
+
161
+ /**
162
+ * Direct Document -> yrs load projection.
163
+ *
164
+ * This is the Document-model twin of the coexistence seed path. It emits the
165
+ * same flat story vocabulary as `seedFromPm`, but never constructs a
166
+ * ProseMirror node: text becomes attributed Y.Text, paragraphs become pilcrow
167
+ * embeds, tables/block SDTs become structural embeds with child stories, and
168
+ * comments become root-story side-map entries.
169
+ */
170
+
171
+ /**
172
+ * Seeds every yrs-owned editable story directly from a parsed Document.
173
+ *
174
+ * Stories are `body`, `hf:{rId}`, `fn:{id}`, `en:{id}`, and recursively generated table
175
+ * cell / block-SDT stories. The target session must not already contain any of
176
+ * those story ids.
177
+ *
178
+ * @public
179
+ */
180
+ declare function documentToYrs(session: YrsSession, document: Document): void;
181
+
182
+ /**
183
+ * yrs -> OOXML Document save projection.
184
+ *
185
+ * The yrs coexistence model stores each editable container as a flat story:
186
+ * text carries inline formatting attributes, pilcrows carry paragraph
187
+ * properties, and structural/inline atoms are map embeds. This module reads
188
+ * that representation directly and rebuilds the serializer-facing Document.
189
+ */
190
+
191
+ /**
192
+ * Rebuild all yrs-owned editable stories into the serializer-facing Document
193
+ * while preserving every package part the editor does not own.
194
+ */
195
+ interface YrsToDocumentOptions {
196
+ /**
197
+ * Root stories to project. Omit to rebuild every editable story. A `body`
198
+ * projection includes its nested table/content-control stories.
199
+ */
200
+ storyIds?: ReadonlySet<string>;
201
+ }
202
+ declare function yrsToDocument(session: YrsSession, base: Document, options?: YrsToDocumentOptions): Document;
203
+
204
+ /**
205
+ * Typed facade over the Rust yrs editing core (`crates/docx-edit`).
206
+ *
207
+ * This module is the ONLY JS entry to that crate — the `docx/zipContainer.ts`
208
+ * facade precedent. It is types + JSON marshaling only; every editing
209
+ * semantic (pilcrow-as-character stories, explicit-attribute inserts,
210
+ * suggesting mode, sticky comment anchors) lives in Rust.
211
+ *
212
+ * `createYrsSession()` lazily loads the embedded wasm (`./wasm`) on first call.
213
+ *
214
+ * Addressing is the op-contract public vocabulary: a {@link YrsLoc} is
215
+ * `(story, paraId, offset)` with UTF-16 offsets scoped to one paragraph
216
+ * (`offset ∈ [0, paragraphLength]`; the paragraph's own pilcrow is excluded
217
+ * from its offset space). Story-global indices never cross this boundary.
218
+ */
219
+
220
+ /** Durable authorship metadata for one suggested (tracked-change) operation. */
221
+ interface YrsAuthor {
222
+ name: string;
223
+ /** ISO timestamp supplied by the host so all peers share one clock policy. */
224
+ date: string;
225
+ }
226
+ /** One position: `(story, paraId, offset)` — offsets are UTF-16 units within the paragraph. */
227
+ interface YrsLoc {
228
+ story: string;
229
+ paraId: string;
230
+ offset: number;
231
+ }
232
+ /** A paragraph-addressed position without the story (used inside {@link YrsStoryRange}). */
233
+ interface YrsParaOffset {
234
+ paraId: string;
235
+ offset: number;
236
+ }
237
+ /**
238
+ * A half-open range `[start, end)` inside one story. Ends may sit in
239
+ * different paragraphs; the boundary pilcrows are then part of the range
240
+ * (deleting such a range merges paragraphs).
241
+ */
242
+ interface YrsStoryRange {
243
+ story: string;
244
+ start: YrsParaOffset;
245
+ end: YrsParaOffset;
246
+ }
247
+ /** One run-level mark for {@link YrsSession.toggleMark}. */
248
+ type YrsRunMark = {
249
+ type: 'bold';
250
+ } | {
251
+ type: 'italic';
252
+ } | {
253
+ type: 'underline';
254
+ } | {
255
+ type: 'fontFamily';
256
+ value: string;
257
+ } | {
258
+ type: 'fontSize';
259
+ value: number;
260
+ } | {
261
+ type: 'color';
262
+ value: string;
263
+ };
264
+ /** A direct text color written by {@link YrsSession.formatRange}. */
265
+ type YrsTextColor = {
266
+ rgb: string;
267
+ themeColor?: never;
268
+ } | {
269
+ rgb?: never;
270
+ themeColor: string;
271
+ };
272
+ /**
273
+ * Set-valued inline formatting for {@link YrsSession.formatRange}. Omitted
274
+ * fields are left unchanged; `null` clears a field. Boolean `false` also
275
+ * clears the corresponding mark.
276
+ */
277
+ interface YrsInlineFormatDelta {
278
+ bold?: boolean | null;
279
+ italic?: boolean | null;
280
+ underline?: boolean | {
281
+ style?: string;
282
+ color?: string;
283
+ } | null;
284
+ strike?: boolean | {
285
+ double?: boolean;
286
+ } | null;
287
+ color?: YrsTextColor | null;
288
+ highlight?: string | null;
289
+ /** Font size in points; Rust writes both OOXML half-point size fields. */
290
+ fontSize?: number | null;
291
+ fontFamily?: {
292
+ ascii: string;
293
+ hAnsi?: string;
294
+ } | null;
295
+ /** Passive run properties not covered by the typed fields. `null` clears. */
296
+ other?: Readonly<Record<string, unknown | null>>;
297
+ }
298
+ interface YrsHyperlinkAttrs {
299
+ href: string;
300
+ tooltip?: string | null;
301
+ rId?: string | null;
302
+ }
303
+ /** Seed shape for {@link YrsSession.loadStories}. */
304
+ interface YrsParagraphSeed {
305
+ /** Paragraph text; must not contain paragraph breaks. */
306
+ text: string;
307
+ /** Defaults to `"Normal"`. */
308
+ pStyle?: string;
309
+ /** Defaults to `"left"`. */
310
+ alignment?: string;
311
+ }
312
+ /** One story to seed via {@link YrsSession.loadStories}. */
313
+ interface YrsStorySeed {
314
+ storyId: string;
315
+ /** At least one paragraph. */
316
+ paragraphs: readonly YrsParagraphSeed[];
317
+ }
318
+ /** Snapshot of one paragraph from {@link YrsSession.paragraphs}. */
319
+ interface YrsParagraph {
320
+ paraId: string;
321
+ text: string;
322
+ /** pStyle / alignment plus any op-set extras. */
323
+ properties: Record<string, unknown>;
324
+ }
325
+ /** One direct numbering reference (`w:numPr`) on a paragraph. */
326
+ interface YrsNumberingProperties {
327
+ numId?: number;
328
+ ilvl?: number;
329
+ }
330
+ /** One paragraph tab stop, measured in twips from the left margin. */
331
+ interface YrsParagraphTabStop {
332
+ position: number;
333
+ alignment: 'left' | 'center' | 'right' | 'decimal' | 'bar' | 'clear' | 'num';
334
+ leader?: 'none' | 'dot' | 'hyphen' | 'underscore' | 'heavy' | 'middleDot';
335
+ }
336
+ /**
337
+ * Tri-state properties for {@link YrsSession.setParagraphAttrs}. Omitted
338
+ * fields are kept and `null` clears. Numeric spacing and indents are OOXML
339
+ * twips/line-spacing units, never CSS pixels.
340
+ */
341
+ interface YrsParagraphAttrs {
342
+ alignment?: 'left' | 'center' | 'right' | 'both' | 'distribute' | 'mediumKashida' | 'highKashida' | 'lowKashida' | 'thaiDistribute' | null;
343
+ lineSpacing?: number | null;
344
+ lineSpacingRule?: 'auto' | 'exact' | 'atLeast' | null;
345
+ spaceBefore?: number | null;
346
+ spaceAfter?: number | null;
347
+ indentLeft?: number | null;
348
+ indentRight?: number | null;
349
+ indentFirstLine?: number | null;
350
+ hangingIndent?: boolean | null;
351
+ bidi?: boolean | null;
352
+ tabs?: readonly YrsParagraphTabStop[] | null;
353
+ defaultTextFormatting?: Readonly<Record<string, unknown>> | null;
354
+ numPr?: YrsNumberingProperties | null;
355
+ numPrFromStyle?: YrsNumberingProperties | null;
356
+ listNumFmt?: string | null;
357
+ listIsBullet?: boolean | null;
358
+ listMarker?: string | null;
359
+ listMarkerHidden?: boolean | null;
360
+ listMarkerFontFamily?: string | null;
361
+ listMarkerFontSize?: number | null;
362
+ listMarkerSuffix?: 'tab' | 'space' | 'nothing' | null;
363
+ listLevelNumFmts?: readonly string[] | null;
364
+ listAbstractNumId?: number | null;
365
+ listStartOverride?: number | null;
366
+ /** Passive pPr/model properties not covered by the typed fields. */
367
+ other?: Readonly<Record<string, unknown | null>>;
368
+ }
369
+ /** Typed value stored on a structured document tag (content control). */
370
+ type YrsContentControlValue = {
371
+ kind: 'dropdown';
372
+ value: string;
373
+ } | {
374
+ kind: 'checkbox';
375
+ checked: boolean;
376
+ } | {
377
+ kind: 'date';
378
+ date: string;
379
+ } | string;
380
+ /** Image geometry authored in OOXML EMUs plus wrapping/position metadata. */
381
+ interface YrsImageGeometry {
382
+ widthEmu: number;
383
+ heightEmu: number;
384
+ wrap?: 'inline' | 'square' | 'tight' | 'through' | 'topAndBottom' | 'behind' | 'inFront';
385
+ hOffsetEmu?: number | null;
386
+ vOffsetEmu?: number | null;
387
+ distTopEmu?: number | null;
388
+ distBottomEmu?: number | null;
389
+ distLeftEmu?: number | null;
390
+ distRightEmu?: number | null;
391
+ relativeFromHorizontal?: string | null;
392
+ relativeFromVertical?: string | null;
393
+ /** Additional image payload fields; `null` clears an existing field. */
394
+ other?: Readonly<Record<string, unknown | null>>;
395
+ }
396
+ /** A text or picture watermark payload for {@link YrsSession.insertWatermark}. */
397
+ type YrsWatermark = {
398
+ kind: 'text';
399
+ text: string;
400
+ font: string;
401
+ color: string;
402
+ semitransparent: boolean;
403
+ layout: 'diagonal' | 'horizontal';
404
+ fontSize?: number;
405
+ decorative?: boolean;
406
+ } | {
407
+ kind: 'picture';
408
+ relId?: string;
409
+ mediaPath?: string;
410
+ dataUrl?: string;
411
+ contentType?: string;
412
+ scale: number;
413
+ washout: boolean;
414
+ widthEmu?: number;
415
+ heightEmu?: number;
416
+ decorative?: boolean;
417
+ };
418
+ /**
419
+ * One formatted segment from {@link YrsSession.storySegments} — the render
420
+ * bridge's input. `attributes` carries run marks plus `ins` / `del` revision
421
+ * values (suggested deletions are retained text with a `del` attribute).
422
+ */
423
+ type YrsStorySegment = {
424
+ kind: 'text';
425
+ text: string;
426
+ attributes: Record<string, unknown>;
427
+ } | {
428
+ kind: 'pilcrow';
429
+ paraId: string;
430
+ properties: Record<string, unknown>;
431
+ attributes: Record<string, unknown>;
432
+ } | {
433
+ kind: 'embed';
434
+ /** Map-backed embed discriminator (`table`, `noteRef`, `image`, …). */
435
+ embedKind: string;
436
+ /** Authored map entries excluding the discriminator. */
437
+ payload: Record<string, unknown>;
438
+ attributes: Record<string, unknown>;
439
+ };
440
+ /** Current offsets of one sticky comment anchor. */
441
+ interface YrsResolvedCommentAnchor {
442
+ story: string;
443
+ start: number;
444
+ end: number;
445
+ }
446
+ /** A paragraph's story span; `end` is its pilcrow, so `end - start` is the paragraph length. */
447
+ interface YrsParagraphSpan {
448
+ start: number;
449
+ end: number;
450
+ }
451
+ /** Compact paragraph entry used to build the live input-position projection. */
452
+ interface YrsParagraphLength {
453
+ paraId: string;
454
+ /** UTF-16 text and inline embed units before the paragraph's pilcrow. */
455
+ length: number;
456
+ }
457
+ /** Receipt of an op that minted a paragraph id. */
458
+ interface YrsParagraphReceipt {
459
+ paraId: string;
460
+ }
461
+ /** Receipt of an op that may have minted a tracked-change revision (suggesting mode). */
462
+ interface YrsRevisionReceipt {
463
+ revisionId: string | null;
464
+ }
465
+ /**
466
+ * Receipt of {@link YrsSession.splitParagraph}. Under the S1 split the FIRST
467
+ * half keeps the original paraId and the SECOND half is re-minted; suggesting
468
+ * mode stamps a `pPrIns` revision on the first half.
469
+ */
470
+ interface YrsSplitReceipt {
471
+ firstParaId: string;
472
+ secondParaId: string;
473
+ revisionId: string | null;
474
+ }
475
+ /**
476
+ * One low-level story mirror operation for {@link YrsSession.applyRawOps}. The
477
+ * coexistence bridge lowers a ProseMirror transaction to a list of these and
478
+ * applies them in one yrs transaction. Indices are UTF-16 story units, each read
479
+ * against the story state after all prior ops in the batch.
480
+ */
481
+ type YrsRawOp = {
482
+ op: 'insert';
483
+ index: number;
484
+ text: string;
485
+ attrs?: Record<string, unknown>;
486
+ } | {
487
+ op: 'delete';
488
+ index: number;
489
+ len: number;
490
+ } | {
491
+ op: 'format';
492
+ index: number;
493
+ len: number;
494
+ attrs?: Record<string, unknown>;
495
+ } | {
496
+ op: 'insertEmbed';
497
+ index: number;
498
+ kind: string;
499
+ payload?: Record<string, unknown>;
500
+ attrs?: Record<string, unknown>;
501
+ } | {
502
+ op: 'setEmbedAttr';
503
+ index: number;
504
+ key: string;
505
+ value: unknown;
506
+ } | {
507
+ /**
508
+ * Upserts the side-map comment keyed by `id`, (re-)anchoring it to
509
+ * `ranges` — non-empty `[start, end)` story-unit spans in the batch's
510
+ * story (sticky `Assoc::After` starts / `Assoc::Before` ends). The
511
+ * coexistence bridge keys by the PM comment id so identity survives the
512
+ * mirror.
513
+ */
514
+ op: 'setComment';
515
+ id: string;
516
+ ranges: ReadonlyArray<readonly [number, number]>;
517
+ author?: string;
518
+ date?: string;
519
+ body?: unknown;
520
+ } | {
521
+ /** Removes the side-map comment keyed by `id`; errors when missing. */
522
+ op: 'removeComment';
523
+ id: string;
524
+ };
525
+ /** Host context for {@link YrsSession.yrsBlocksForStory} (theme + list numbering). */
526
+ interface YrsRenderEnv {
527
+ /** Theme color name → hex (`accent1` → `4472C4`), for theme-color resolution. */
528
+ themeColors?: Record<string, string>;
529
+ /** The document default tab stop in twips. */
530
+ defaultTabStopTwips?: number | null;
531
+ /** Current page content height in CSS px, for proportional drawing constraints. */
532
+ pageContentHeight?: number | null;
533
+ /** yrs revision/paragraph id → dense numeric layout id (list markers, revisions). */
534
+ numericIds?: Record<string, number>;
535
+ }
536
+ /** Receipt of {@link YrsSession.addComment}. */
537
+ interface YrsCommentReceipt {
538
+ commentId: string;
539
+ }
540
+ /**
541
+ * Target of {@link YrsSession.acceptChange} / {@link YrsSession.rejectChange}:
542
+ * one coalesced revision id (resolved at every site, in any story — the
543
+ * `acceptChangeById` twin) or an explicit story range (the range-command twin;
544
+ * every tracked change overlapping the range resolves, no id filtering).
545
+ */
546
+ type YrsChangeTarget = {
547
+ revisionId: string;
548
+ } | YrsStoryRange;
549
+ /** Receipt of {@link YrsSession.acceptChange} / {@link YrsSession.rejectChange}. */
550
+ interface YrsResolveReceipt {
551
+ /** The revision ids resolved by the op (resolution order, deduplicated). */
552
+ revisionIds: string[];
553
+ }
554
+ /** This peer's awareness selection, resolved from two yrs sticky positions. */
555
+ interface YrsSelection {
556
+ anchor: YrsLoc;
557
+ head: YrsLoc;
558
+ }
559
+ interface YrsResidentCaretRect {
560
+ pageIndex: number;
561
+ pageId: string;
562
+ x: number;
563
+ y: number;
564
+ height: number;
565
+ }
566
+ interface YrsResidentCaretSnapshot {
567
+ frameEpoch: number;
568
+ caretRect: YrsResidentCaretRect | null;
569
+ /** Selection the rect was computed for. Absent on raw engine snapshots. */
570
+ selection?: YrsSelection | null;
571
+ }
572
+ declare function sameYrsSelection(left: YrsSelection | null, right: YrsSelection | null): boolean;
573
+ /** Opt-in internal stage timings for one resident engine input. @internal */
574
+ interface YrsEngineApplyProfile {
575
+ selectionMs: number;
576
+ editMs: number;
577
+ lowerMs: number;
578
+ measureMs: number;
579
+ paginateMs: number;
580
+ displayInputMs: number;
581
+ displayBuildMs: number;
582
+ displayFinalizeMs: number;
583
+ displayMs: number;
584
+ encodeMs: number;
585
+ }
586
+ /**
587
+ * Serializable bootstrap state for the dedicated resident-layout worker.
588
+ * The main-thread yrs replica records the inputs that established resident
589
+ * render, measurement, and pagination state; the worker replays them once and
590
+ * then owns every ordinary input-to-frame transaction.
591
+ *
592
+ * @internal
593
+ */
594
+ interface YrsResidentWorkerSnapshot {
595
+ clientId: number;
596
+ /** Full document state, or a state-vector diff when the caller supplied
597
+ * the worker's known vector — both apply through the same merge path. */
598
+ state: Uint8Array;
599
+ selection: YrsSelection | null;
600
+ /** Empty when the caller declared the worker's fonts current
601
+ * (`knownFontsRevision` matches); the worker then keeps its registrations. */
602
+ fonts: Uint8Array[];
603
+ /** Monotonic revision of the resident font set (bumped by register/clear). */
604
+ fontsRevision: number;
605
+ renderInputs: Array<{
606
+ story: string;
607
+ env: YrsRenderEnv;
608
+ }>;
609
+ measureInputs: string[];
610
+ layoutInput: string;
611
+ layoutWithRegions: boolean;
612
+ layoutRevision: number;
613
+ }
614
+ /**
615
+ * What the sync target already holds, so a snapshot can ship deltas instead
616
+ * of the whole world.
617
+ *
618
+ * @internal
619
+ */
620
+ interface YrsResidentWorkerSyncOptions {
621
+ /** The worker replica's last reported yrs state vector. */
622
+ knownStateVector?: Uint8Array | null;
623
+ /** The `fontsRevision` the worker last applied. */
624
+ knownFontsRevision?: number | null;
625
+ }
626
+ /** A range-aggregated toggle mark. @public */
627
+ type YrsTriState = boolean | 'mixed';
628
+ /**
629
+ * Read-only toolbar/a11y state aggregated from yrs over one story range.
630
+ * Toggle marks are tri-state; value marks are `null` when absent or mixed.
631
+ *
632
+ * @public
633
+ */
634
+ interface YrsSelectionContext {
635
+ bold: YrsTriState;
636
+ italic: YrsTriState;
637
+ underline: YrsTriState;
638
+ strike: YrsTriState;
639
+ /** Uniform ASCII font family, or `null` when absent/mixed. */
640
+ fontFamily: string | null;
641
+ /** Uniform font size in half-points (the PM/OOXML `w:sz` unit). */
642
+ fontSize: number | null;
643
+ /** Uniform RGB hex or theme-color name, or `null` when absent/mixed. */
644
+ color: string | null;
645
+ /** Paragraph containing the range start. */
646
+ paraId: string;
647
+ styleId: string | null;
648
+ alignment: string | null;
649
+ /**
650
+ * Full authored pilcrow property bag. Known toolbar fields retain their PM
651
+ * names (`indentLeft`, `spaceBefore`, `lineSpacing`, `numPr`, and so on);
652
+ * paragraph style is stored as `pStyle`.
653
+ */
654
+ paragraphProperties: {
655
+ [key: string]: unknown;
656
+ pStyle?: string;
657
+ alignment?: string;
658
+ indentLeft?: number;
659
+ indentRight?: number;
660
+ indentFirstLine?: number;
661
+ hangingIndent?: boolean;
662
+ spaceBefore?: number;
663
+ spaceAfter?: number;
664
+ lineSpacing?: number;
665
+ lineSpacingRule?: string;
666
+ numPr?: {
667
+ numId?: number;
668
+ ilvl?: number;
669
+ };
670
+ };
671
+ hasSelection: boolean;
672
+ isMultiParagraph: boolean;
673
+ /** The range belongs to a table-cell story. */
674
+ inTable: boolean;
675
+ /** The range covers exactly one non-pilcrow embed unit. */
676
+ isSingleEmbed: boolean;
677
+ /** Embed discriminator (`image`, `drawing`, …), else `null`. */
678
+ embedKind: string | null;
679
+ /** Convenience flag for a single `image` embed selection. */
680
+ isImage: boolean;
681
+ inInsertion: boolean;
682
+ inDeletion: boolean;
683
+ }
684
+ /**
685
+ * One tracked insertion, deletion, or paragraph-mark revision read from yrs.
686
+ *
687
+ * @public
688
+ */
689
+ interface YrsRevisionInfo {
690
+ revisionId: string;
691
+ author: string;
692
+ date: string;
693
+ kind: 'insertion' | 'deletion' | 'pPrIns' | 'pPrDel' | 'pPrChange' | 'trIns' | 'trDel' | 'tableIns' | 'tableDel';
694
+ story: string;
695
+ /** Raw affected text, capped at 80 Unicode code points. */
696
+ preview: string;
697
+ range: YrsStoryRange;
698
+ }
699
+ /**
700
+ * Story-local locator for one native table embed.
701
+ *
702
+ * @public
703
+ */
704
+ interface YrsTableLoc {
705
+ story: string;
706
+ /** Zero-based table ordinal in the parent story. */
707
+ tableIndex: number;
708
+ }
709
+ /**
710
+ * One table cell addressed in the resolved rectangular grid.
711
+ *
712
+ * @public
713
+ */
714
+ interface YrsCellLoc extends YrsTableLoc {
715
+ row: number;
716
+ column: number;
717
+ }
718
+ /**
719
+ * Anchor-cell to head-cell rectangular selection, analogous to PM's
720
+ * `CellSelection` but independent of ProseMirror positions.
721
+ *
722
+ * @public
723
+ */
724
+ interface YrsTableRange {
725
+ anchor: YrsCellLoc;
726
+ head: YrsCellLoc;
727
+ }
728
+ /**
729
+ * Receipt shared by native table-structure and cell-format operations.
730
+ *
731
+ * @public
732
+ */
733
+ interface YrsTableReceipt {
734
+ table: YrsTableLoc;
735
+ rows: number;
736
+ columns: number;
737
+ createdStoryIds: string[];
738
+ deletedStoryIds: string[];
739
+ newParaIds: string[];
740
+ deletedTable: boolean;
741
+ revisionIds: string[];
742
+ }
743
+ /**
744
+ * OOXML/PM-shaped cell border value passed through to `tcPr.borders`.
745
+ *
746
+ * @public
747
+ */
748
+ interface YrsCellBorder {
749
+ style: string;
750
+ size?: number;
751
+ color?: {
752
+ rgb: string;
753
+ };
754
+ }
755
+ /**
756
+ * Complete per-side border object for {@link YrsSession.setCellBorders}.
757
+ *
758
+ * @public
759
+ */
760
+ type YrsCellBorders = Partial<Record<'top' | 'bottom' | 'left' | 'right' | 'insideH' | 'insideV', YrsCellBorder>>;
761
+ /**
762
+ * One live replica of the yrs editing model. Thin typed wrapper over the
763
+ * wasm `EditSession` — no editing logic on this side of the boundary.
764
+ */
765
+ interface YrsSession extends CollaborationReplica {
766
+ /** The yrs client id this replica writes with. */
767
+ readonly clientId: number;
768
+ /** Register raw sfnt bytes in the session's measurement/display font store. */
769
+ registerFont(bytes: Uint8Array): number;
770
+ /** Clear the session's registered measurement/display fonts. */
771
+ clearFonts(): void;
772
+ /** Measure one paragraph through the session's resident text engine. */
773
+ measureParagraphJson(input: string): string;
774
+ /** Paginate and retain the measured input and Layout in the session. */
775
+ layoutDocumentJson(input: string): string;
776
+ /** Return the compact font requirements for resident region layout. */
777
+ layoutFontRequirementsJson(input: string): string;
778
+ /** Paginate and compose section/page regions in the resident engine. */
779
+ layoutDocumentWithRegionsJson(input: string): string;
780
+ /** Build display primitives against the session's resident font store. */
781
+ buildDisplayListJson(input: string): string;
782
+ /** Build a binary FrameDelta v1 against the last host-applied frame. */
783
+ buildDisplayListFrame(input: string, expectedFrameEpoch: number): Uint8Array;
784
+ /** Caret geometry from the current resident display frame. */
785
+ residentCaretSnapshot(): YrsResidentCaretSnapshot;
786
+ /** Apply a collapsed plain-text insertion and return its resident FrameDelta. */
787
+ applyInput(text: string, expectedFrameEpoch: number): Uint8Array;
788
+ /** Apply a collapsed character deletion/paragraph merge and return its resident FrameDelta. */
789
+ applyDelete(direction: 'backward' | 'forward', expectedFrameEpoch: number): Uint8Array;
790
+ /** Instrumented apply used only by opt-in browser performance traces. */
791
+ applyInputProfiled(text: string, expectedFrameEpoch: number): {
792
+ frame: Uint8Array;
793
+ profile: YrsEngineApplyProfile;
794
+ };
795
+ /** Instrumented deletion used only by opt-in browser performance traces. */
796
+ applyDeleteProfiled(direction: 'backward' | 'forward', expectedFrameEpoch: number): {
797
+ frame: Uint8Array;
798
+ profile: YrsEngineApplyProfile;
799
+ };
800
+ /** Snapshot the inputs needed to move resident layout ownership to a worker. */
801
+ residentWorkerSnapshot(options?: YrsResidentWorkerSyncOptions): YrsResidentWorkerSnapshot | null;
802
+ /**
803
+ * Cheap worker-sync probe: the resident layout revision when a worker
804
+ * snapshot would be available, without encoding document state or copying
805
+ * font bytes. Steady-state frame builds consult this instead of building a
806
+ * full snapshot.
807
+ */
808
+ residentWorkerProbe(): {
809
+ layoutRevision: number;
810
+ } | null;
811
+ /** Resident display-list hit/range queries; results are small JSON records. */
812
+ displayHitTestRegionsJson(pageIndex: number, x: number, y: number): string;
813
+ displayRangeRectsJson(from: number, to: number): string;
814
+ displayRangeRectsRegionJson(region: 'body' | 'header' | 'footer', rId: string, from: number, to: number): string;
815
+ /** Read a glyph outline from the session's resident font store. */
816
+ outlineGlyphJson(fontId: number, glyphId: number): string;
817
+ /** Hydrates from an encoded yrs v1 update (typically a peer's {@link encodeState} output). */
818
+ loadState(update: Uint8Array): void;
819
+ /**
820
+ * Seeds stories from parsed content (S1 scaffold; the real
821
+ * `load(ParsedDocument)` lands with the ops track). Returns paraIds per
822
+ * story in document order.
823
+ */
824
+ loadStories(stories: readonly YrsStorySeed[]): Record<string, string[]>;
825
+ /** Full document state as one yrs v1 update (Yjs wire format). */
826
+ encodeState(): Uint8Array;
827
+ /** Current Yrs state vector in the Yjs v1 wire format. */
828
+ encodeStateVector(): Uint8Array;
829
+ /** Full state, or only the state missing from a peer vector. */
830
+ encodeStateAsUpdate(remoteStateVector?: Uint8Array): Uint8Array;
831
+ /** Applies a remote/incremental yrs v1 update. */
832
+ applyUpdate(update: Uint8Array): void;
833
+ /** Apply a same-user worker update under the local undo origin. @internal */
834
+ applyLocalUpdate(update: Uint8Array, story: string): void;
835
+ /**
836
+ * Subscribes to every committed transaction's v1 update (local AND
837
+ * applied-remote). Returns an unsubscribe function.
838
+ */
839
+ onUpdate(listener: (update: Uint8Array, origin: CollaborationUpdateOrigin) => void): () => void;
840
+ /** Store this peer's awareness selection as sticky positions. */
841
+ setSelection(anchor: YrsLoc, head?: YrsLoc): void;
842
+ /** Resolve this peer's current sticky selection, or null before initialization. */
843
+ selection(): YrsSelection | null;
844
+ /** Store this peer's rectangular table selection outside the document. */
845
+ setCellSelection(range: YrsTableRange): void;
846
+ /** Resolve the current sticky cell selection, or null before initialization. */
847
+ cellSelection(): YrsTableRange | null;
848
+ /** Lazily begin local-origin undo capture after import/seeding has completed. */
849
+ beginUndoCapture(story: string, includeTableStories?: boolean): void;
850
+ /** Coalesce the stack entries added since `startDepth` into one host undo intent. */
851
+ markUndoGroup(startDepth: number): void;
852
+ /** Undo/redo only local-origin direct operations (never remote/system transactions). */
853
+ undo(): boolean;
854
+ redo(): boolean;
855
+ canUndo(): boolean;
856
+ canRedo(): boolean;
857
+ /** Current local undo/redo stack sizes (zero before tracking starts). */
858
+ undoDepth(): number;
859
+ redoDepth(): number;
860
+ /** Adds a story with one paragraph; the receipt carries its paraId. */
861
+ createStory(storyId: string, initialText: string, pStyle?: string, alignment?: string): YrsParagraphReceipt;
862
+ /** Removes a complete story (including an unreachable table-cell story). */
863
+ deleteStory(storyId: string): void;
864
+ /** Inserts a row above or below the cell that `at` resolves into. */
865
+ insertRow(at: YrsCellLoc, side: 'above' | 'below', suggesting?: YrsAuthor): YrsTableReceipt;
866
+ /** Inserts a rectangular structural table at a paragraph-keyed location. */
867
+ insertTable(at: YrsLoc, rows: number, columns: number, suggesting?: YrsAuthor): YrsTableReceipt;
868
+ /** Inserts a column left or right of the cell that `at` resolves into. */
869
+ insertColumn(at: YrsCellLoc, side: 'left' | 'right'): YrsTableReceipt;
870
+ /** Deletes every row covered by an explicit rectangular cell range. */
871
+ deleteRow(range: YrsTableRange, suggesting?: YrsAuthor): YrsTableReceipt;
872
+ /** Deletes every column covered by an explicit rectangular cell range. */
873
+ deleteColumn(range: YrsTableRange): YrsTableReceipt;
874
+ /** Removes a complete table plus its reachable cell stories. */
875
+ deleteTable(table: YrsTableLoc): YrsTableReceipt;
876
+ /** Merges a rectangular range into its top-left cell. */
877
+ mergeCells(range: YrsTableRange): YrsTableReceipt;
878
+ /** Splits the merged cell covering `at` into one cell per grid slot. */
879
+ splitCell(at: YrsCellLoc, rows?: number, columns?: number): YrsTableReceipt;
880
+ /** Sets or clears the selected cells' background color. */
881
+ setCellShading(range: YrsTableRange, color: string | null): YrsTableReceipt;
882
+ /**
883
+ * Merges an OOXML/PM-shaped patch into selected cells' `tcPr`. JSON `null`
884
+ * clears a property; merge/split-owned span keys are rejected.
885
+ */
886
+ setCellTextFormat(range: YrsTableRange, patch: Readonly<Record<string, unknown>>): YrsTableReceipt;
887
+ /** Replaces the complete selected-cell border property object. */
888
+ setCellBorders(range: YrsTableRange, borders: YrsCellBorders): YrsTableReceipt;
889
+ /** Sets one authored grid-column width in twips. */
890
+ setColumnWidth(at: YrsCellLoc, widthTwips: number): YrsTableReceipt;
891
+ /** Sets the table-wide preferred width in twips. */
892
+ setTableWidth(table: YrsTableLoc, widthTwips: number): YrsTableReceipt;
893
+ /** Inserts paragraph-break-free text. Suggesting mode mints a revision. */
894
+ insertText(at: YrsLoc, text: string, suggesting?: YrsAuthor): YrsRevisionReceipt;
895
+ /**
896
+ * Deletes a range (plain) or marks it as a suggested deletion (suggesting).
897
+ * A range spanning paragraphs also merges them (pilcrow-as-character).
898
+ */
899
+ deleteRange(range: YrsStoryRange, suggesting?: YrsAuthor): YrsRevisionReceipt;
900
+ /** Replaces a range with text in one transaction (one shared revision when suggesting). */
901
+ replaceRange(range: YrsStoryRange, text: string, suggesting?: YrsAuthor): YrsRevisionReceipt;
902
+ /**
903
+ * Splits a paragraph by inserting one pilcrow. The FIRST half keeps the
904
+ * original paraId; the SECOND half is re-minted (`secondParaId`).
905
+ */
906
+ splitParagraph(at: YrsLoc, suggesting?: YrsAuthor): YrsSplitReceipt;
907
+ /** Merges `paraId` with the FOLLOWING paragraph. Errors on the final paragraph. */
908
+ mergeParagraphs(story: string, paraId: string, suggesting?: YrsAuthor): YrsRevisionReceipt;
909
+ /** Toggles one run mark across a range (PM toggleMark range semantics). */
910
+ toggleMark(range: YrsStoryRange, mark: YrsRunMark): void;
911
+ /** Applies set-valued direct formatting; omitted fields are kept and `null` fields clear. */
912
+ formatRange(range: YrsStoryRange, delta: YrsInlineFormatDelta): void;
913
+ /** Sets or clears the protected hyperlink attribute over a non-empty range. */
914
+ setHyperlink(range: YrsStoryRange, hyperlink: YrsHyperlinkAttrs | null): void;
915
+ /** Clears direct formatting while retaining hyperlinks and tracked-change stamps. */
916
+ clearFormatting(range: YrsStoryRange): void;
917
+ /** Applies a paragraph style id to every paragraph intersecting the range. */
918
+ applyParagraphStyle(range: YrsStoryRange, styleId: string, suggesting?: YrsAuthor): void;
919
+ /** Applies tri-state paragraph properties to every paragraph intersecting the range. */
920
+ setParagraphAttrs(range: YrsStoryRange, attrs: YrsParagraphAttrs, suggesting?: YrsAuthor): void;
921
+ /** Inserts one inline image embed, optionally as a tracked insertion. */
922
+ insertImage(at: YrsLoc, image: Readonly<Record<string, unknown>>, suggesting?: YrsAuthor): YrsRevisionReceipt;
923
+ /** Sets the authored value on a content-control embed addressed by stable payload id. */
924
+ setContentControlValue(embedId: string, value: YrsContentControlValue): void;
925
+ /** Sets a content-control value at a paragraph-keyed embed position. */
926
+ setContentControlValueAt(at: YrsLoc, value: YrsContentControlValue): void;
927
+ /** Removes the authored value from a content-control embed. */
928
+ clearContentControlValue(embedId: string): void;
929
+ /** Commits image size/wrapping/position fields in one transaction. */
930
+ setImageGeometry(embedId: string, geometry: YrsImageGeometry): void;
931
+ /** Inserts a native page-break embed at a paragraph-keyed location. */
932
+ insertPageBreak(at: YrsLoc): void;
933
+ /** Inserts a native section-break embed at a paragraph-keyed location. */
934
+ insertSectionBreak(at: YrsLoc, type: 'nextPage' | 'continuous' | 'oddPage' | 'evenPage'): void;
935
+ /** Inserts a typed watermark embed at a paragraph-keyed location. */
936
+ insertWatermark(at: YrsLoc, watermark: YrsWatermark): void;
937
+ /**
938
+ * Applies a batch of raw story mirror ops in one transaction — the coexistence
939
+ * bridge's mirror-into-yrs path (a faithful mirror of lowered PM state, not a
940
+ * user-intent op). Not for direct app use.
941
+ */
942
+ applyRawOps(story: string, ops: readonly YrsRawOp[]): void;
943
+ /** Sets one paragraph property (any JSON value). `paraId` is reserved. */
944
+ setParagraphAttr(paraId: string, key: string, value: unknown): void;
945
+ /** Adds a sticky-anchored comment over one or more ranges. */
946
+ addComment(ranges: readonly YrsStoryRange[], author: string, date: string, body: unknown): YrsCommentReceipt;
947
+ /**
948
+ * Accepts tracked changes (S4b): pending insertions become plain content,
949
+ * pending deletions are carried out; a `pPrIns` paragraph mark clears (the
950
+ * split stays), a `pPrDel` mark joins with the following paragraph (whose
951
+ * pPr survives — Word's surviving-`w:p` rule). Resolving never stamps a new
952
+ * revision. Throws on an unknown revision id.
953
+ */
954
+ acceptChange(target: YrsChangeTarget): YrsResolveReceipt;
955
+ /**
956
+ * Rejects tracked changes — the inverse of {@link acceptChange}: pending
957
+ * insertions roll back, pending deletions restore their text; a `pPrIns`
958
+ * mark joins back with the following paragraph, a `pPrDel` mark clears.
959
+ */
960
+ rejectChange(target: YrsChangeTarget): YrsResolveReceipt;
961
+ /** Aggregate toolbar/a11y state from yrs over one paragraph-addressed range. */
962
+ selectionContext(range: YrsStoryRange): YrsSelectionContext;
963
+ /** Enumerate tracked changes across every story in deterministic order. */
964
+ listRevisions(): YrsRevisionInfo[];
965
+ /** Current offsets of a comment's sticky anchors. Throws when an anchor no longer resolves. */
966
+ resolveComment(commentId: string): YrsResolvedCommentAnchor[];
967
+ /** Story ids in the document, sorted. */
968
+ storyIds(): string[];
969
+ /** Story length in UTF-16 units (every embed, pilcrows included, counts 1). */
970
+ storyLength(story: string): number;
971
+ /**
972
+ * The story's `canonical-stream-v1` FNV-1a checksum. The coexistence watchdog
973
+ * compares it against the PM projector's checksum after every mirrored edit.
974
+ */
975
+ storyChecksum(story: string): bigint;
976
+ /**
977
+ * Lowers a story through the resident Rust bridge. Throws with an
978
+ * unsupported-embed message on any non-native content (opaque blobs) until
979
+ * that class is promoted to native.
980
+ * The return is the layout pipeline's `LayoutBlock[]` (kept as `unknown[]` to
981
+ * keep this facade decoupled from the layout types).
982
+ */
983
+ yrsBlocksForStory(story: string, env?: YrsRenderEnv): unknown[];
984
+ /** Paragraph snapshots in document order. */
985
+ paragraphs(story: string): YrsParagraph[];
986
+ /** Paragraph ids and inline-unit lengths, resolved in one Rust story traversal. */
987
+ paragraphSpans(story: string): YrsParagraphLength[];
988
+ /** The raw formatted-segment view (the render bridge's input). */
989
+ storySegments(story: string): YrsStorySegment[];
990
+ /** A paragraph's story span (start unit, pilcrow index). */
991
+ locateParagraph(story: string, paraId: string): YrsParagraphSpan;
992
+ /** Drops the observer and frees the wasm-side replica. Idempotent. */
993
+ destroy(): void;
994
+ }
995
+ /** Options for {@link createYrsSession}. */
996
+ interface CreateYrsSessionOptions {
997
+ /**
998
+ * The yrs client id (non-negative safe integer). Omit to allocate a random
999
+ * 32-bit id, yjs-style.
1000
+ */
1001
+ clientId?: number;
1002
+ }
1003
+ /**
1004
+ * Creates a yrs editing replica. The first call dynamically imports and
1005
+ * initializes the embedded docx-edit wasm (~440KB base64) — callers must
1006
+ * load it lazily so non-editor consumers avoid the wasm startup cost.
1007
+ */
1008
+ declare function createYrsSession(options?: CreateYrsSessionOptions): Promise<YrsSession>;
1009
+
1010
+ export { type YrsRunMark as $, type YrsEngineApplyProfile as A, type YrsHyperlinkAttrs as B, type CollaborationReplica as C, type YrsImageGeometry as D, type YrsInlineFormatDelta as E, type YrsInputParagraphSeed as F, type YrsInputParagraphSpan as G, type YrsInputPositionMap as H, type YrsNumberingProperties as I, type YrsParaOffset as J, type YrsParagraph as K, type YrsParagraphAttrs as L, type YrsParagraphLength as M, type YrsParagraphReceipt as N, type YrsParagraphSeed as O, type YrsParagraphSpan as P, type YrsParagraphTabStop as Q, type ResidentCaretPaintStyle as R, type YrsRawOp as S, type YrsResidentCaretRect as T, type YrsResidentCaretSnapshot as U, type YrsResidentWorkerSnapshot as V, type YrsResidentWorkerSyncOptions as W, type YrsResolveReceipt as X, type YrsSession as Y, type YrsResolvedCommentAnchor as Z, type YrsRevisionReceipt as _, type YrsRenderEnv as a, type YrsSelectionContext as a0, type YrsSplitReceipt as a1, type YrsStoryRange as a2, type YrsStorySeed as a3, type YrsStorySegment as a4, type YrsTableLoc as a5, type YrsTableRange as a6, type YrsTableReceipt as a7, type YrsTextColor as a8, type YrsTriState as a9, type YrsWatermark as aa, canUseResidentEngineWorker as ab, compareYrsLocs as ac, createYrsInputPositionMap as ad, createYrsSession as ae, displayPositionToYrsLoc as af, documentToYrs as ag, residentCaretDeviceRect as ah, residentCaretSnapshotForFrame as ai, sameYrsSelection as aj, yrsLocToDisplayPosition as ak, yrsToDocument as al, type CollaborationTransport as b, type CollaborationProviderOptions as c, type CollaborationStatus as d, type CollaborationStatusListener as e, type CollaborationErrorListener as f, type YrsSelection as g, CollaborationError as h, type CollaborationErrorCode as i, type CollaborationStatusChange as j, type CollaborationTransportEvent as k, type CollaborationUpdateOrigin as l, type YrsLoc as m, type YrsRevisionInfo as n, type CreateYrsSessionOptions as o, type ResidentEngineOffscreenPage as p, type ResidentEngineWorkerApplyResult as q, ResidentEngineWorkerClient as r, type ResidentEngineWorkerFrame as s, type YrsAuthor as t, type YrsCellBorder as u, type YrsCellBorders as v, type YrsCellLoc as w, type YrsChangeTarget as x, type YrsCommentReceipt as y, type YrsContentControlValue as z };