@betteroffice/docx 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +586 -3
  2. package/dist/chunk-24Z6ZVFZ.mjs +1 -0
  3. package/dist/chunk-2QHGQA3V.mjs +1 -0
  4. package/dist/{chunk-ACGKK7IB.mjs → chunk-3CYO46ML.mjs} +1 -1
  5. package/dist/chunk-6CHGYCFU.mjs +1 -0
  6. package/dist/chunk-AOWJ4WDE.mjs +1 -0
  7. package/dist/chunk-DLXIZBB6.mjs +1 -0
  8. package/dist/chunk-F2VBW6RB.mjs +1 -0
  9. package/dist/chunk-HPZFJGGM.mjs +0 -0
  10. package/dist/chunk-L2ML3DDI.mjs +1 -0
  11. package/dist/chunk-LIGZ75FP.mjs +1 -0
  12. package/dist/chunk-LT2GCWZ3.mjs +0 -0
  13. package/dist/chunk-ND3FBCB3.mjs +16 -0
  14. package/dist/chunk-NMDQHUQB.mjs +57 -0
  15. package/dist/chunk-NVN26RHH.mjs +1 -0
  16. package/dist/chunk-OK5UFGX3.mjs +1 -0
  17. package/dist/chunk-RZQ3OXZY.mjs +2 -0
  18. package/dist/chunk-YLFKV2NT.mjs +1 -0
  19. package/dist/collaboration/index.d.mts +9 -6
  20. package/dist/compareDocx-IHFPGIGV.mjs +1 -0
  21. package/dist/computeLayout-4MNWHE2T.mjs +1 -0
  22. package/dist/{content-CvEtPl0c.d.mts → content-BzoC6bSz.d.mts} +48 -8
  23. package/dist/core.d.mts +172 -9
  24. package/dist/core.mjs +1 -1
  25. package/dist/{displayListQueries-DF8F6fMl.d.mts → displayListQueries-H5YnU_hX.d.mts} +23 -5
  26. package/dist/docx/index.d.mts +5 -4
  27. package/dist/docx/index.mjs +1 -1
  28. package/dist/editor/index.d.mts +19 -9
  29. package/dist/editor/index.mjs +1 -1
  30. package/dist/{fontLoader-b8eicJKV.d.mts → fontLoader-BNSs0E8K.d.mts} +55 -2
  31. package/dist/{formatting-7zKCTu5a.d.mts → formatting-gqLFeJ9X.d.mts} +8 -0
  32. package/dist/{frameDelta-pA4jrQ1G.d.mts → frameDelta-ByU7HBuB.d.mts} +34 -3
  33. package/dist/generated/edit/docx_edit_bg.wasm +0 -0
  34. package/dist/generated/layout/docx_layout_bg.wasm +0 -0
  35. package/dist/generated/opc/ooxml_opc_bg.wasm +0 -0
  36. package/dist/generated/parse/docx_parse_bg.wasm +0 -0
  37. package/dist/index-CHy6_Yuo.d.mts +2026 -0
  38. package/dist/layout/index.d.mts +6 -6
  39. package/dist/layout/index.mjs +1 -1
  40. package/dist/layout/pagination/index.d.mts +4 -4
  41. package/dist/layout/render/index.d.mts +122 -33
  42. package/dist/layout/render/index.mjs +1 -1
  43. package/dist/loadWasmAsset-Cr95TImt.d.mts +25 -0
  44. package/dist/pagedExport---0Dlmzo.d.mts +907 -0
  45. package/dist/parseWasm-NLAG22EU.mjs +1 -0
  46. package/dist/plugin-api/RenderedDomContext.d.mts +12 -9
  47. package/dist/plugin-api/RenderedDomContext.mjs +1 -1
  48. package/dist/plugin-api/index.d.mts +21 -4
  49. package/dist/plugin-api/resolveItemPositions.d.mts +3 -3
  50. package/dist/rezip-Bxiq4Z_R.d.mts +24 -0
  51. package/dist/{rustDisplayList-BJqaN9tt.d.mts → rustDisplayList-LcRZHCSL.d.mts} +12 -4
  52. package/dist/{rustMeasureSource-C0EZB055.d.mts → rustMeasureSource-BkCx1FDx.d.mts} +14 -4
  53. package/dist/{selectiveSave-CRh-_Y_C.d.mts → selectiveSave-r-NMK6aI.d.mts} +1 -22
  54. package/dist/styles/index.d.mts +2 -2
  55. package/dist/{styles-7e-mq3c-.d.mts → styles-AryxLAhx.d.mts} +1 -1
  56. package/dist/types/content.d.mts +2 -2
  57. package/dist/types/document.d.mts +9 -6
  58. package/dist/{types-C4A8mWjU.d.mts → types-D6Pra38E.d.mts} +31 -5
  59. package/dist/utils/comments.d.mts +2 -2
  60. package/dist/utils/index.d.mts +20 -5
  61. package/dist/utils/index.mjs +1 -1
  62. package/dist/utils/stylePreview.d.mts +2 -2
  63. package/dist/wasm-GSI2XMOH.mjs +1 -0
  64. package/dist/wasm-K6DRABAA.mjs +1 -0
  65. package/dist/wasm-NF6B3AH7.mjs +1 -0
  66. package/dist/wasm-edit.d.mts +420 -28
  67. package/dist/wasm-edit.mjs +1 -1
  68. package/dist/wasm-layout.d.mts +9 -2
  69. package/dist/wasm-layout.mjs +1 -1
  70. package/dist/wasm-opc.d.mts +1 -1
  71. package/dist/wasm-opc.mjs +1 -1
  72. package/dist/wasm-parse.d.mts +1 -1
  73. package/dist/wasm-parse.mjs +1 -1
  74. package/dist/yrs/index.d.mts +8 -5
  75. package/dist/yrs/index.mjs +1 -1
  76. package/dist/yrs/residentEngineWorker.mjs +1 -1
  77. package/package.json +2 -2
  78. package/dist/chunk-5F6DLQZP.mjs +0 -1
  79. package/dist/chunk-6LQJAKOC.mjs +0 -1
  80. package/dist/chunk-AFMVSI4Z.mjs +0 -57
  81. package/dist/chunk-GD4VNJ64.mjs +0 -1
  82. package/dist/chunk-HLDJMU3R.mjs +0 -1
  83. package/dist/chunk-J7LNO6SM.mjs +0 -1
  84. package/dist/chunk-JHJLG4I6.mjs +0 -16
  85. package/dist/chunk-PGMXWI5X.mjs +0 -1
  86. package/dist/chunk-WRWRCBLK.mjs +0 -1
  87. package/dist/chunk-WTFRNX5K.mjs +0 -1
  88. package/dist/index-CHl2zLJ7.d.mts +0 -1142
  89. package/dist/loadWasmAsset-CMvnVkfA.d.mts +0 -3
  90. package/dist/wasm-7SOSHNGP.mjs +0 -1
  91. package/dist/wasm-ZQAVP7P2.mjs +0 -1
@@ -1,1142 +0,0 @@
1
- import { Document } from './types/document.mjs';
2
- import { R as RetainedFrame } from './frameDelta-pA4jrQ1G.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
- user?: CollaborationUser;
50
- }
51
- interface CollaborationUser {
52
- name: string;
53
- color?: string;
54
- }
55
- interface CollaborationResolvedUser {
56
- name: string;
57
- color: string;
58
- }
59
- interface CollaborationCursor {
60
- story: string;
61
- anchor: Uint8Array;
62
- head: Uint8Array;
63
- }
64
- interface CollaborationTextInsertion {
65
- clientId: number;
66
- story: string;
67
- paraId: string;
68
- endOffset: number;
69
- }
70
- interface CollaborationAwarenessState {
71
- clientId: number;
72
- clock: number;
73
- user: CollaborationResolvedUser;
74
- cursor: CollaborationCursor | null;
75
- }
76
- interface CollaborationPeer extends CollaborationAwarenessState {
77
- lastSeenAt: number;
78
- cursorMovedAt: number;
79
- inferredCursor: CollaborationTextInsertion | null;
80
- }
81
- type CollaborationPeerListener = (peers: readonly CollaborationPeer[]) => void;
82
- interface CollaborationPresence {
83
- readonly peers: readonly CollaborationPeer[];
84
- setCursor(cursor: CollaborationCursor | null, broadcast?: boolean): void;
85
- onPeers(listener: CollaborationPeerListener): () => void;
86
- }
87
- type CollaborationStatusListener = (change: CollaborationStatusChange) => void;
88
- type CollaborationErrorListener = (error: CollaborationError) => void;
89
-
90
- /** One native paragraph in the yrs-backed display-position projection. */
91
- interface YrsInputParagraphSpan {
92
- paraId: string;
93
- /** Number of UTF-16/inline units before the paragraph's pilcrow. */
94
- length: number;
95
- /** Block start emitted by the yrs display-position projection. */
96
- displayStart: number;
97
- }
98
- /**
99
- * Live converter between display-list positions and public yrs Locs.
100
- *
101
- * A native paragraph of length N occupies N+2 display positions (open token,
102
- * content, close token), so this map can be rebuilt directly from the live yrs
103
- * paragraph spans after every structural edit.
104
- */
105
- interface YrsInputPositionMap {
106
- story: string;
107
- paragraphs: readonly YrsInputParagraphSpan[];
108
- }
109
- interface YrsInputParagraphSeed {
110
- paraId: string;
111
- length: number;
112
- }
113
- declare function createYrsInputPositionMap(story: string, seeds: readonly YrsInputParagraphSeed[]): YrsInputPositionMap;
114
- /** Convert a live yrs location to the position used by display-list geometry. */
115
- declare function yrsLocToDisplayPosition(map: YrsInputPositionMap, loc: YrsLoc): number;
116
- /** Convert a display-list hit position to a paragraph-keyed yrs location. */
117
- declare function displayPositionToYrsLoc(map: YrsInputPositionMap, position: number): YrsLoc | null;
118
- /** Compare two Locs in document order using one live map. */
119
- declare function compareYrsLocs(map: YrsInputPositionMap, a: YrsLoc, b: YrsLoc): number;
120
-
121
- /** Resolved styling for the worker-painted caret (the worker cannot read CSS vars). */
122
- interface ResidentCaretPaintStyle {
123
- color: string;
124
- /** CSS-px stroke width, matching the DOM caret's un-zoomed width. */
125
- width: number;
126
- }
127
- /** Device-px caret rect: geometry scales by dpr*zoom, stroke width by dpr only
128
- * (the DOM caret keeps its CSS-px width across zoom levels). */
129
- declare function residentCaretDeviceRect(rect: Pick<YrsResidentCaretRect, 'x' | 'y' | 'height'>, style: ResidentCaretPaintStyle, devicePixelRatio: number, zoom: number): {
130
- x: number;
131
- y: number;
132
- width: number;
133
- height: number;
134
- };
135
- declare function residentCaretSnapshotForFrame(snapshot: YrsResidentCaretSnapshot, frame: RetainedFrame): YrsResidentCaretSnapshot | null;
136
-
137
- type ResidentEngineWorkerRequest = {
138
- id: number;
139
- type: 'bootstrap';
140
- snapshot: YrsResidentWorkerSnapshot;
141
- extras: string;
142
- expectedFrameEpoch: number;
143
- } | {
144
- id: number;
145
- type: 'sync';
146
- snapshot: YrsResidentWorkerSnapshot;
147
- extras: string;
148
- expectedFrameEpoch: number;
149
- paintCaret: boolean;
150
- } | {
151
- id: number;
152
- type: 'buildFrame';
153
- extras: string;
154
- expectedFrameEpoch: number;
155
- paintCaret: boolean;
156
- } | {
157
- id: number;
158
- type: 'applyInput';
159
- text: string;
160
- selection: YrsSelection;
161
- expectedFrameEpoch: number;
162
- profile: boolean;
163
- paintCaret: boolean;
164
- } | {
165
- id: number;
166
- type: 'applyDelete';
167
- direction: 'backward' | 'forward';
168
- selection: YrsSelection;
169
- expectedFrameEpoch: number;
170
- profile: boolean;
171
- paintCaret: boolean;
172
- } | {
173
- id: number;
174
- type: 'applyUpdate';
175
- update: Uint8Array;
176
- selection: YrsSelection | null;
177
- } | {
178
- id: number;
179
- type: 'attachCanvases';
180
- pages: Array<{
181
- pageId: string;
182
- canvas: OffscreenCanvas;
183
- }>;
184
- activePageIds: string[];
185
- devicePixelRatio: number;
186
- zoom: number;
187
- caretStyle: ResidentCaretPaintStyle;
188
- } | {
189
- id: number;
190
- type: 'eraseCaret';
191
- } | {
192
- id: number;
193
- type: 'destroy';
194
- };
195
- type ResidentEngineWorkerResponse = {
196
- id: number;
197
- ok: true;
198
- frame?: ArrayBuffer;
199
- updates?: ArrayBuffer[];
200
- engineMs?: number;
201
- workerTotalMs?: number;
202
- engineProfile?: YrsEngineApplyProfile;
203
- caret?: YrsResidentCaretSnapshot;
204
- selection?: YrsSelection | null;
205
- /** The presented frame carries the worker-painted caret line. */
206
- caretPainted?: boolean;
207
- replayMs?: number;
208
- replayedPages?: number;
209
- layoutRevision?: number;
210
- /** The worker replica's yrs state vector after this operation, so the
211
- * next sync can ship a diff instead of the whole document state. */
212
- stateVector?: ArrayBuffer;
213
- } | {
214
- id: number;
215
- ok: false;
216
- error: string;
217
- residentUnavailable?: boolean;
218
- /** A wasm trap poisoned the worker; it refuses every later request. */
219
- terminal?: boolean;
220
- };
221
-
222
- interface ResidentEngineWorkerFrame {
223
- frame: Uint8Array;
224
- updates: Uint8Array[];
225
- engineMs: number;
226
- workerTotalMs: number;
227
- engineProfile?: YrsEngineApplyProfile;
228
- caret: YrsResidentCaretSnapshot;
229
- selection: YrsSelection | null;
230
- /** The presented frame carries the worker-painted caret line. */
231
- caretPainted: boolean;
232
- replayMs: number;
233
- replayedPages: number;
234
- layoutRevision: number;
235
- }
236
- interface ResidentEngineOffscreenPage {
237
- pageId: string;
238
- canvas: OffscreenCanvas;
239
- }
240
- interface ResidentEngineWorkerApplyResult extends ResidentEngineWorkerFrame {
241
- applied: true;
242
- }
243
- interface ResidentEngineWorkerPort {
244
- onmessage: ((event: MessageEvent<ResidentEngineWorkerResponse>) => void) | null;
245
- onerror: ((event: ErrorEvent) => void) | null;
246
- onmessageerror: ((event: MessageEvent) => void) | null;
247
- postMessage(message: ResidentEngineWorkerRequest, transfer?: Transferable[]): void;
248
- terminate(): void;
249
- }
250
- /** Dedicated-worker owner for resident input, pagination, and FrameDelta output. */
251
- declare class ResidentEngineWorkerClient {
252
- private readonly worker;
253
- private readonly pending;
254
- private nextId;
255
- private terminalError;
256
- private ready;
257
- private revision;
258
- private remoteVector;
259
- private appliedFontsRevision;
260
- constructor(worker?: ResidentEngineWorkerPort);
261
- isReady(): boolean;
262
- layoutRevision(): number;
263
- /** The worker replica's last reported yrs state vector (null before any). */
264
- remoteStateVector(): Uint8Array | null;
265
- /** The fonts revision this worker last applied (null before bootstrap). */
266
- syncedFontsRevision(): number | null;
267
- bootstrap(snapshot: YrsResidentWorkerSnapshot, extras: string): Promise<ResidentEngineWorkerFrame>;
268
- sync(snapshot: YrsResidentWorkerSnapshot, extras: string, expectedFrameEpoch: number, paintCaret?: boolean): Promise<ResidentEngineWorkerFrame>;
269
- buildFrame(extras: string, expectedFrameEpoch: number, paintCaret?: boolean): Promise<ResidentEngineWorkerFrame>;
270
- applyInput(text: string, selection: YrsSelection, expectedFrameEpoch: number, profile?: boolean, paintCaret?: boolean): Promise<ResidentEngineWorkerApplyResult | {
271
- applied: false;
272
- }>;
273
- applyDelete(direction: 'backward' | 'forward', selection: YrsSelection, expectedFrameEpoch: number, profile?: boolean, paintCaret?: boolean): Promise<ResidentEngineWorkerApplyResult | {
274
- applied: false;
275
- }>;
276
- /** Drop the worker-painted caret line by re-presenting the caret page's
277
- * retained raster. Fire-and-forget and idempotent. */
278
- eraseCaret(): void;
279
- invalidate(update: Uint8Array, selection: YrsSelection | null): void;
280
- attachCanvases(pages: ResidentEngineOffscreenPage[], activePageIds: string[], devicePixelRatio: number, zoom: number, caretStyle: ResidentCaretPaintStyle): Promise<void>;
281
- destroy(): void;
282
- private request;
283
- /** Record a successfully applied bootstrap/sync payload's fonts revision.
284
- * The state vector is tracked centrally in `onmessage`. */
285
- private recordSync;
286
- private fail;
287
- }
288
- /** The worker itself failed (crash, timeout, torn-down, corrupt reply). */
289
- declare class ResidentWorkerFailureError extends Error {
290
- }
291
- declare function canUseResidentEngineWorker(): boolean;
292
-
293
- /** Direct Document-to-yrs load projection. */
294
-
295
- /**
296
- * Seeds every yrs-owned editable story directly from a parsed Document.
297
- *
298
- * Stories are `body`, `hf:{rId}`, `fn:{id}`, `en:{id}`, and recursively generated table
299
- * cell / block-SDT stories. The target session must not already contain any of
300
- * those story ids.
301
- *
302
- * @public
303
- */
304
- declare function documentToYrs(session: YrsSession, document: Document): void;
305
-
306
- /** yrs-to-OOXML save projection. */
307
-
308
- /**
309
- * Rebuild all yrs-owned editable stories into the serializer-facing Document
310
- * while preserving every package part the editor does not own.
311
- */
312
- interface YrsToDocumentOptions {
313
- /**
314
- * Root stories to project. Omit to rebuild every editable story. A `body`
315
- * projection includes its nested table/content-control stories.
316
- */
317
- storyIds?: ReadonlySet<string>;
318
- }
319
- declare function yrsToDocument(session: YrsSession, base: Document, options?: YrsToDocumentOptions): Document;
320
-
321
- /**
322
- * Typed facade over the Rust yrs editing core (`crates/docx-edit`).
323
- *
324
- * This module is the ONLY JS entry to that crate — the `docx/zipContainer.ts`
325
- * facade precedent. It is types + JSON marshaling only; every editing
326
- * semantic (pilcrow-as-character stories, explicit-attribute inserts,
327
- * suggesting mode, sticky comment anchors) lives in Rust.
328
- *
329
- * `createYrsSession()` lazily loads the embedded wasm (`./wasm`) on first call.
330
- *
331
- * Addressing is the op-contract public vocabulary: a {@link YrsLoc} is
332
- * `(story, paraId, offset)` with UTF-16 offsets scoped to one paragraph
333
- * (`offset ∈ [0, paragraphLength]`; the paragraph's own pilcrow is excluded
334
- * from its offset space). Story-global indices never cross this boundary.
335
- */
336
-
337
- interface YrsDocxHost {
338
- document: Document;
339
- referencedFonts: string[];
340
- embeddedFonts: Map<string, ArrayBuffer>;
341
- fontTableRelationshipsXml?: string;
342
- }
343
- /** Durable authorship metadata for one suggested (tracked-change) operation. */
344
- interface YrsAuthor {
345
- name: string;
346
- /** ISO timestamp supplied by the host so all peers share one clock policy. */
347
- date: string;
348
- }
349
- /** One position: `(story, paraId, offset)` — offsets are UTF-16 units within the paragraph. */
350
- interface YrsLoc {
351
- story: string;
352
- paraId: string;
353
- offset: number;
354
- }
355
- /** One binary Yrs position that transforms with collaborative edits. */
356
- interface YrsStickyPosition {
357
- story: string;
358
- encoded: Uint8Array;
359
- }
360
- /** A paragraph-addressed position without the story (used inside {@link YrsStoryRange}). */
361
- interface YrsParaOffset {
362
- paraId: string;
363
- offset: number;
364
- }
365
- /**
366
- * A half-open range `[start, end)` inside one story. Ends may sit in
367
- * different paragraphs; the boundary pilcrows are then part of the range
368
- * (deleting such a range merges paragraphs).
369
- */
370
- interface YrsStoryRange {
371
- story: string;
372
- start: YrsParaOffset;
373
- end: YrsParaOffset;
374
- }
375
- /** One run-level mark for {@link YrsSession.toggleMark}. */
376
- type YrsRunMark = {
377
- type: 'bold';
378
- } | {
379
- type: 'italic';
380
- } | {
381
- type: 'underline';
382
- } | {
383
- type: 'fontFamily';
384
- value: string;
385
- } | {
386
- type: 'fontSize';
387
- value: number;
388
- } | {
389
- type: 'color';
390
- value: string;
391
- };
392
- /** A direct text color written by {@link YrsSession.formatRange}. */
393
- type YrsTextColor = {
394
- rgb: string;
395
- themeColor?: never;
396
- } | {
397
- rgb?: never;
398
- themeColor: string;
399
- };
400
- /**
401
- * Set-valued inline formatting for {@link YrsSession.formatRange}. Omitted
402
- * fields are left unchanged; `null` clears a field. Boolean `false` also
403
- * clears the corresponding mark.
404
- */
405
- interface YrsInlineFormatDelta {
406
- bold?: boolean | null;
407
- italic?: boolean | null;
408
- underline?: boolean | {
409
- style?: string;
410
- color?: string;
411
- } | null;
412
- strike?: boolean | {
413
- double?: boolean;
414
- } | null;
415
- color?: YrsTextColor | null;
416
- highlight?: string | null;
417
- /** Font size in points; Rust writes both OOXML half-point size fields. */
418
- fontSize?: number | null;
419
- fontFamily?: {
420
- ascii: string;
421
- hAnsi?: string;
422
- } | null;
423
- /** Passive run properties not covered by the typed fields. `null` clears. */
424
- other?: Readonly<Record<string, unknown | null>>;
425
- }
426
- interface YrsHyperlinkAttrs {
427
- href: string;
428
- tooltip?: string | null;
429
- rId?: string | null;
430
- }
431
- /** Seed shape for {@link YrsSession.loadStories}. */
432
- interface YrsParagraphSeed {
433
- /** Paragraph text; must not contain paragraph breaks. */
434
- text: string;
435
- /** Defaults to `"Normal"`. */
436
- pStyle?: string;
437
- /** Defaults to `"left"`. */
438
- alignment?: string;
439
- }
440
- /** One story to seed via {@link YrsSession.loadStories}. */
441
- interface YrsStorySeed {
442
- storyId: string;
443
- /** At least one paragraph. */
444
- paragraphs: readonly YrsParagraphSeed[];
445
- }
446
- /** Snapshot of one paragraph from {@link YrsSession.paragraphs}. */
447
- interface YrsParagraph {
448
- paraId: string;
449
- text: string;
450
- /** pStyle / alignment plus any op-set extras. */
451
- properties: Record<string, unknown>;
452
- }
453
- /** One direct numbering reference (`w:numPr`) on a paragraph. */
454
- interface YrsNumberingProperties {
455
- numId?: number;
456
- ilvl?: number;
457
- }
458
- /** One paragraph tab stop, measured in twips from the left margin. */
459
- interface YrsParagraphTabStop {
460
- position: number;
461
- alignment: 'left' | 'center' | 'right' | 'decimal' | 'bar' | 'clear' | 'num';
462
- leader?: 'none' | 'dot' | 'hyphen' | 'underscore' | 'heavy' | 'middleDot';
463
- }
464
- /**
465
- * Tri-state properties for {@link YrsSession.setParagraphAttrs}. Omitted
466
- * fields are kept and `null` clears. Numeric spacing and indents are OOXML
467
- * twips/line-spacing units, never CSS pixels.
468
- */
469
- interface YrsParagraphAttrs {
470
- alignment?: 'left' | 'center' | 'right' | 'both' | 'distribute' | 'mediumKashida' | 'highKashida' | 'lowKashida' | 'thaiDistribute' | null;
471
- lineSpacing?: number | null;
472
- lineSpacingRule?: 'auto' | 'exact' | 'atLeast' | null;
473
- spaceBefore?: number | null;
474
- spaceAfter?: number | null;
475
- indentLeft?: number | null;
476
- indentRight?: number | null;
477
- indentFirstLine?: number | null;
478
- hangingIndent?: boolean | null;
479
- bidi?: boolean | null;
480
- tabs?: readonly YrsParagraphTabStop[] | null;
481
- defaultTextFormatting?: Readonly<Record<string, unknown>> | null;
482
- numPr?: YrsNumberingProperties | null;
483
- numPrFromStyle?: YrsNumberingProperties | null;
484
- listNumFmt?: string | null;
485
- listIsBullet?: boolean | null;
486
- listMarker?: string | null;
487
- listMarkerHidden?: boolean | null;
488
- listMarkerFontFamily?: string | null;
489
- listMarkerFontSize?: number | null;
490
- listMarkerSuffix?: 'tab' | 'space' | 'nothing' | null;
491
- listLevelNumFmts?: readonly string[] | null;
492
- listAbstractNumId?: number | null;
493
- listStartOverride?: number | null;
494
- /** Passive pPr/model properties not covered by the typed fields. */
495
- other?: Readonly<Record<string, unknown | null>>;
496
- }
497
- /** Typed value stored on a structured document tag (content control). */
498
- type YrsContentControlValue = {
499
- kind: 'dropdown';
500
- value: string;
501
- } | {
502
- kind: 'checkbox';
503
- checked: boolean;
504
- } | {
505
- kind: 'date';
506
- date: string;
507
- } | string;
508
- /** Image geometry authored in OOXML EMUs plus wrapping/position metadata. */
509
- interface YrsImageGeometry {
510
- widthEmu: number;
511
- heightEmu: number;
512
- wrap?: 'inline' | 'square' | 'tight' | 'through' | 'topAndBottom' | 'behind' | 'inFront';
513
- hOffsetEmu?: number | null;
514
- vOffsetEmu?: number | null;
515
- distTopEmu?: number | null;
516
- distBottomEmu?: number | null;
517
- distLeftEmu?: number | null;
518
- distRightEmu?: number | null;
519
- relativeFromHorizontal?: string | null;
520
- relativeFromVertical?: string | null;
521
- /** Additional image payload fields; `null` clears an existing field. */
522
- other?: Readonly<Record<string, unknown | null>>;
523
- }
524
- /** A text or picture watermark payload for {@link YrsSession.insertWatermark}. */
525
- type YrsWatermark = {
526
- kind: 'text';
527
- text: string;
528
- font: string;
529
- color: string;
530
- semitransparent: boolean;
531
- layout: 'diagonal' | 'horizontal';
532
- fontSize?: number;
533
- decorative?: boolean;
534
- } | {
535
- kind: 'picture';
536
- relId?: string;
537
- mediaPath?: string;
538
- dataUrl?: string;
539
- contentType?: string;
540
- scale: number;
541
- washout: boolean;
542
- widthEmu?: number;
543
- heightEmu?: number;
544
- decorative?: boolean;
545
- };
546
- /**
547
- * One formatted segment from {@link YrsSession.storySegments} — the render
548
- * bridge's input. `attributes` carries run marks plus `ins` / `del` revision
549
- * values (suggested deletions are retained text with a `del` attribute).
550
- */
551
- type YrsStorySegment = {
552
- kind: 'text';
553
- text: string;
554
- attributes: Record<string, unknown>;
555
- } | {
556
- kind: 'pilcrow';
557
- paraId: string;
558
- properties: Record<string, unknown>;
559
- attributes: Record<string, unknown>;
560
- } | {
561
- kind: 'embed';
562
- /** Map-backed embed discriminator (`table`, `noteRef`, `image`, …). */
563
- embedKind: string;
564
- /** Authored map entries excluding the discriminator. */
565
- payload: Record<string, unknown>;
566
- attributes: Record<string, unknown>;
567
- };
568
- /** Current offsets of one sticky comment anchor. */
569
- interface YrsResolvedCommentAnchor {
570
- story: string;
571
- start: number;
572
- end: number;
573
- }
574
- /** A paragraph's story span; `end` is its pilcrow, so `end - start` is the paragraph length. */
575
- interface YrsParagraphSpan {
576
- start: number;
577
- end: number;
578
- }
579
- /** Compact paragraph entry used to build the live input-position projection. */
580
- interface YrsParagraphLength {
581
- paraId: string;
582
- /** UTF-16 text and inline embed units before the paragraph's pilcrow. */
583
- length: number;
584
- }
585
- /** Receipt of an op that minted a paragraph id. */
586
- interface YrsParagraphReceipt {
587
- paraId: string;
588
- }
589
- /** Receipt of an op that may have minted a tracked-change revision (suggesting mode). */
590
- interface YrsRevisionReceipt {
591
- revisionId: string | null;
592
- }
593
- /**
594
- * Receipt of {@link YrsSession.splitParagraph}. The first half keeps the
595
- * original paraId and the second half is re-minted; suggesting
596
- * mode stamps a `pPrIns` revision on the first half.
597
- */
598
- interface YrsSplitReceipt {
599
- firstParaId: string;
600
- secondParaId: string;
601
- revisionId: string | null;
602
- }
603
- /** Low-level UTF-16 story operation for {@link YrsSession.applyRawOps}. */
604
- type YrsRawOp = {
605
- op: 'insert';
606
- index: number;
607
- text: string;
608
- attrs?: Record<string, unknown>;
609
- } | {
610
- op: 'delete';
611
- index: number;
612
- len: number;
613
- } | {
614
- op: 'format';
615
- index: number;
616
- len: number;
617
- attrs?: Record<string, unknown>;
618
- } | {
619
- op: 'insertEmbed';
620
- index: number;
621
- kind: string;
622
- payload?: Record<string, unknown>;
623
- attrs?: Record<string, unknown>;
624
- } | {
625
- op: 'setEmbedAttr';
626
- index: number;
627
- key: string;
628
- value: unknown;
629
- } | {
630
- /** Upserts a side-map comment with sticky story-unit ranges. */
631
- op: 'setComment';
632
- id: string;
633
- ranges: ReadonlyArray<readonly [number, number]>;
634
- author?: string;
635
- date?: string;
636
- body?: unknown;
637
- } | {
638
- /** Removes the side-map comment keyed by `id`; errors when missing. */
639
- op: 'removeComment';
640
- id: string;
641
- };
642
- /** Host context for {@link YrsSession.yrsBlocksForStory} (theme + list numbering). */
643
- interface YrsRenderEnv {
644
- tocStyleIds?: string[];
645
- paragraphSpacingLinePx?: number;
646
- defaultParagraphStyleId?: string;
647
- /** Theme color name → hex (`accent1` → `4472C4`), for theme-color resolution. */
648
- themeColors?: Record<string, string>;
649
- /** The document default tab stop in twips. */
650
- defaultTabStopTwips?: number | null;
651
- /** Current page content height in CSS px, for proportional drawing constraints. */
652
- pageContentHeight?: number | null;
653
- /** yrs revision/paragraph id → dense numeric layout id (list markers, revisions). */
654
- numericIds?: Record<string, number>;
655
- /** Include hidden text in visible layout without changing the document. */
656
- showHiddenText?: boolean;
657
- }
658
- /** Receipt of {@link YrsSession.addComment}. */
659
- interface YrsCommentReceipt {
660
- commentId: string;
661
- }
662
- /**
663
- * Target of {@link YrsSession.acceptChange} / {@link YrsSession.rejectChange}:
664
- * one coalesced revision id (resolved at every site, in any story — the
665
- * `acceptChangeById` twin) or an explicit story range (the range-command twin;
666
- * every tracked change overlapping the range resolves, no id filtering).
667
- */
668
- type YrsChangeTarget = {
669
- revisionId: string;
670
- } | YrsStoryRange;
671
- /** Receipt of {@link YrsSession.acceptChange} / {@link YrsSession.rejectChange}. */
672
- interface YrsResolveReceipt {
673
- /** The revision ids resolved by the op (resolution order, deduplicated). */
674
- revisionIds: string[];
675
- }
676
- /** This peer's awareness selection, resolved from two yrs sticky positions. */
677
- interface YrsSelection {
678
- anchor: YrsLoc;
679
- head: YrsLoc;
680
- }
681
- interface YrsResidentCaretRect {
682
- pageIndex: number;
683
- pageId: string;
684
- x: number;
685
- y: number;
686
- height: number;
687
- }
688
- interface YrsResidentCaretSnapshot {
689
- frameEpoch: number;
690
- caretRect: YrsResidentCaretRect | null;
691
- /** Selection the rect was computed for. Absent on raw engine snapshots. */
692
- selection?: YrsSelection | null;
693
- }
694
- declare function sameYrsSelection(left: YrsSelection | null, right: YrsSelection | null): boolean;
695
- /** Opt-in internal stage timings for one resident engine input. @internal */
696
- interface YrsEngineApplyProfile {
697
- selectionMs: number;
698
- editMs: number;
699
- lowerMs: number;
700
- measureMs: number;
701
- paginateMs: number;
702
- displayInputMs: number;
703
- displayBuildMs: number;
704
- displayFinalizeMs: number;
705
- displayMs: number;
706
- encodeMs: number;
707
- }
708
- /**
709
- * Serializable bootstrap state for the dedicated resident-layout worker.
710
- * The main-thread yrs replica records the inputs that established resident
711
- * render, measurement, and pagination state; the worker replays them once and
712
- * then owns every ordinary input-to-frame transaction.
713
- *
714
- * @internal
715
- */
716
- interface YrsResidentWorkerSnapshot {
717
- clientId: number;
718
- /** Full document state, or a state-vector diff when the caller supplied
719
- * the worker's known vector — both apply through the same merge path. */
720
- state: Uint8Array;
721
- selection: YrsSelection | null;
722
- /** Empty when the caller declared the worker's fonts current
723
- * (`knownFontsRevision` matches); the worker then keeps its registrations. */
724
- fonts: Uint8Array[];
725
- /** Monotonic revision of the resident font set (bumped by register/clear). */
726
- fontsRevision: number;
727
- renderInputs: Array<{
728
- story: string;
729
- env: YrsRenderEnv;
730
- }>;
731
- measureInputs: string[];
732
- layoutInput: string;
733
- layoutWithRegions: boolean;
734
- layoutRevision: number;
735
- }
736
- /**
737
- * What the sync target already holds, so a snapshot can ship deltas instead
738
- * of the whole world.
739
- *
740
- * @internal
741
- */
742
- interface YrsResidentWorkerSyncOptions {
743
- /** The worker replica's last reported yrs state vector. */
744
- knownStateVector?: Uint8Array | null;
745
- /** The `fontsRevision` the worker last applied. */
746
- knownFontsRevision?: number | null;
747
- }
748
- /** A range-aggregated toggle mark. @public */
749
- type YrsTriState = boolean | 'mixed';
750
- /**
751
- * Read-only toolbar/a11y state aggregated from yrs over one story range.
752
- * Toggle marks are tri-state; value marks are `null` when absent or mixed.
753
- *
754
- * @public
755
- */
756
- interface YrsSelectionContext {
757
- bold: YrsTriState;
758
- italic: YrsTriState;
759
- underline: YrsTriState;
760
- strike: YrsTriState;
761
- /** Uniform ASCII font family, or `null` when absent/mixed. */
762
- fontFamily: string | null;
763
- /** Uniform font size in half-points (the OOXML `w:sz` unit). */
764
- fontSize: number | null;
765
- /** Uniform RGB hex or theme-color name, or `null` when absent/mixed. */
766
- color: string | null;
767
- /** Paragraph containing the range start. */
768
- paraId: string;
769
- styleId: string | null;
770
- alignment: string | null;
771
- /**
772
- * Full authored pilcrow property bag. Known toolbar fields retain their
773
- * names (`indentLeft`, `spaceBefore`, `lineSpacing`, `numPr`, and so on);
774
- * paragraph style is stored as `pStyle`.
775
- */
776
- paragraphProperties: {
777
- [key: string]: unknown;
778
- pStyle?: string;
779
- alignment?: string;
780
- indentLeft?: number;
781
- indentRight?: number;
782
- indentFirstLine?: number;
783
- hangingIndent?: boolean;
784
- spaceBefore?: number;
785
- spaceAfter?: number;
786
- lineSpacing?: number;
787
- lineSpacingRule?: string;
788
- numPr?: {
789
- numId?: number;
790
- ilvl?: number;
791
- };
792
- };
793
- hasSelection: boolean;
794
- isMultiParagraph: boolean;
795
- /** The range belongs to a table-cell story. */
796
- inTable: boolean;
797
- /** The range covers exactly one non-pilcrow embed unit. */
798
- isSingleEmbed: boolean;
799
- /** Embed discriminator (`image`, `drawing`, …), else `null`. */
800
- embedKind: string | null;
801
- /** Convenience flag for a single `image` embed selection. */
802
- isImage: boolean;
803
- inInsertion: boolean;
804
- inDeletion: boolean;
805
- }
806
- /**
807
- * One tracked insertion, deletion, or paragraph-mark revision read from yrs.
808
- *
809
- * @public
810
- */
811
- interface YrsRevisionInfo {
812
- revisionId: string;
813
- author: string;
814
- date: string;
815
- kind: 'insertion' | 'deletion' | 'pPrIns' | 'pPrDel' | 'pPrChange' | 'trIns' | 'trDel' | 'tableIns' | 'tableDel';
816
- story: string;
817
- /** Raw affected text, capped at 80 Unicode code points. */
818
- preview: string;
819
- range: YrsStoryRange;
820
- }
821
- /**
822
- * Story-local locator for one native table embed.
823
- *
824
- * @public
825
- */
826
- interface YrsTableLoc {
827
- story: string;
828
- /** Zero-based table ordinal in the parent story. */
829
- tableIndex: number;
830
- }
831
- /**
832
- * One table cell addressed in the resolved rectangular grid.
833
- *
834
- * @public
835
- */
836
- interface YrsCellLoc extends YrsTableLoc {
837
- row: number;
838
- column: number;
839
- }
840
- /**
841
- * Anchor-cell to head-cell rectangular selection, addressed by grid
842
- * coordinates rather than document positions.
843
- *
844
- * @public
845
- */
846
- interface YrsTableRange {
847
- anchor: YrsCellLoc;
848
- head: YrsCellLoc;
849
- }
850
- /**
851
- * Receipt shared by native table-structure and cell-format operations.
852
- *
853
- * @public
854
- */
855
- interface YrsTableReceipt {
856
- table: YrsTableLoc;
857
- rows: number;
858
- columns: number;
859
- createdStoryIds: string[];
860
- deletedStoryIds: string[];
861
- newParaIds: string[];
862
- deletedTable: boolean;
863
- revisionIds: string[];
864
- }
865
- /**
866
- * OOXML-shaped cell border value passed through to `tcPr.borders`.
867
- *
868
- * @public
869
- */
870
- interface YrsCellBorder {
871
- style: string;
872
- size?: number;
873
- color?: {
874
- rgb: string;
875
- };
876
- }
877
- /**
878
- * Per-side border patch for {@link YrsSession.setCellBorders}. An omitted side
879
- * is left alone, `style: 'none'` authors an explicit no-border, and `null`
880
- * drops the authored side.
881
- *
882
- * @public
883
- */
884
- type YrsCellBorders = Partial<Record<'top' | 'bottom' | 'left' | 'right' | 'insideH' | 'insideV', YrsCellBorder | null>>;
885
- /**
886
- * One live replica of the yrs editing model. Thin typed wrapper over the
887
- * wasm `EditSession` — no editing logic on this side of the boundary.
888
- */
889
- interface YrsSession extends CollaborationReplica {
890
- /** The yrs client id this replica writes with. */
891
- readonly clientId: number;
892
- /** Register raw sfnt bytes in the session's measurement/display font store. */
893
- registerFont(bytes: Uint8Array): number;
894
- /** Clear the session's registered measurement/display fonts. */
895
- clearFonts(): void;
896
- /** Measure one paragraph through the session's resident text engine. */
897
- measureParagraphJson(input: string): string;
898
- /** Paginate and retain the measured input and Layout in the session. */
899
- layoutDocumentJson(input: string): string;
900
- /** Return the compact font requirements for resident region layout. */
901
- layoutFontRequirementsJson(input: string): string;
902
- /** Paginate and compose section/page regions in the resident engine. */
903
- layoutDocumentWithRegionsJson(input: string): string;
904
- /** Same pass, but the reply omits the measured arena (fetch it on demand
905
- * through {@link YrsSession.retainedKernelInputsJson}). */
906
- layoutDocumentWithRegionsRetainedJson(input: string): string;
907
- /** Retained `{ measured, options }` for the main-thread display fallback. */
908
- retainedKernelInputsJson(expectedLayoutRevision: number): string;
909
- /** Build display primitives against the session's resident font store. */
910
- buildDisplayListJson(input: string): string;
911
- /** Build a binary FrameDelta v1 against the last host-applied frame. */
912
- buildDisplayListFrame(input: string, expectedFrameEpoch: number): Uint8Array;
913
- /** Caret geometry from the current resident display frame. */
914
- residentCaretSnapshot(): YrsResidentCaretSnapshot;
915
- /** Apply a collapsed plain-text insertion and return its resident FrameDelta. */
916
- applyInput(text: string, expectedFrameEpoch: number): Uint8Array;
917
- /** Apply a collapsed character deletion/paragraph merge and return its resident FrameDelta. */
918
- applyDelete(direction: 'backward' | 'forward', expectedFrameEpoch: number): Uint8Array;
919
- /** Instrumented apply used only by opt-in browser performance traces. */
920
- applyInputProfiled(text: string, expectedFrameEpoch: number): {
921
- frame: Uint8Array;
922
- profile: YrsEngineApplyProfile;
923
- };
924
- /** Instrumented deletion used only by opt-in browser performance traces. */
925
- applyDeleteProfiled(direction: 'backward' | 'forward', expectedFrameEpoch: number): {
926
- frame: Uint8Array;
927
- profile: YrsEngineApplyProfile;
928
- };
929
- /** Snapshot the inputs needed to move resident layout ownership to a worker. */
930
- residentWorkerSnapshot(options?: YrsResidentWorkerSyncOptions): YrsResidentWorkerSnapshot | null;
931
- /**
932
- * Cheap worker-sync probe: the resident layout revision when a worker
933
- * snapshot would be available, without encoding document state or copying
934
- * font bytes. Steady-state frame builds consult this instead of building a
935
- * full snapshot.
936
- */
937
- residentWorkerProbe(): {
938
- layoutRevision: number;
939
- } | null;
940
- /** Resident display-list hit/range queries; results are small JSON records. */
941
- displayHitTestRegionsJson(pageIndex: number, x: number, y: number): string;
942
- displayVerticalMoveJson(position: number, direction: 'up' | 'down', goalX: number): string;
943
- displayRangeRectsJson(from: number, to: number): string;
944
- displayRangeRectsRegionJson(region: 'body' | 'header' | 'footer', rId: string, from: number, to: number): string;
945
- /** Read a glyph outline from the session's resident font store. */
946
- outlineGlyphJson(fontId: number, glyphId: number): string;
947
- /** Hydrates from an encoded yrs v1 update (typically a peer's {@link encodeState} output). */
948
- loadState(update: Uint8Array): void;
949
- /** Parses a DOCX, seeds its stories, and returns thin host metadata. */
950
- seedFromDocx(bytes: Uint8Array): YrsDocxHost;
951
- /** Parses a DOCX and optionally seeds its stories. */
952
- openDocx(bytes: Uint8Array, seedStories: boolean): YrsDocxHost;
953
- /** Materializes the retained canonical package for compatibility APIs. */
954
- materializeDocx(): Document | null;
955
- /** Seeds stories and returns paragraph IDs in document order. */
956
- loadStories(stories: readonly YrsStorySeed[]): Record<string, string[]>;
957
- /** Full document state as one yrs v1 update (Yjs wire format). */
958
- encodeState(): Uint8Array;
959
- /** Current Yrs state vector in the Yjs v1 wire format. */
960
- encodeStateVector(): Uint8Array;
961
- /** Full state, or only the state missing from a peer vector. */
962
- encodeStateAsUpdate(remoteStateVector?: Uint8Array): Uint8Array;
963
- /** Applies a remote/incremental yrs v1 update. */
964
- applyUpdate(update: Uint8Array): CollaborationTextInsertion | null;
965
- /** Apply a same-user worker update under the local undo origin. @internal */
966
- applyLocalUpdate(update: Uint8Array): void;
967
- /**
968
- * Subscribes to every committed transaction's v1 update (local AND
969
- * applied-remote). Returns an unsubscribe function.
970
- */
971
- onUpdate(listener: (update: Uint8Array, origin: CollaborationUpdateOrigin) => void): () => void;
972
- /** Encode one location as a binary Yrs sticky position. */
973
- encodeStickyPosition(loc: YrsLoc): YrsStickyPosition;
974
- /** Resolve a binary Yrs sticky position against this replica. */
975
- resolveStickyPosition(position: YrsStickyPosition): YrsLoc | null;
976
- /** Store this peer's awareness selection as sticky positions. */
977
- setSelection(anchor: YrsLoc, head?: YrsLoc): void;
978
- /** Resolve this peer's current sticky selection, or null before initialization. */
979
- selection(): YrsSelection | null;
980
- /** Encode the current selection as binary Yrs sticky indices. */
981
- encodeSelection(): CollaborationCursor | null;
982
- /** Resolve a peer's binary Yrs sticky indices against this replica. */
983
- resolveSelection(cursor: CollaborationCursor): YrsSelection | null;
984
- /** Store this peer's rectangular table selection outside the document. */
985
- setCellSelection(range: YrsTableRange): void;
986
- /** Resolve the current sticky cell selection, or null before initialization. */
987
- cellSelection(): YrsTableRange | null;
988
- /** Begin local-origin undo capture once import/seeding has completed. */
989
- beginUndoCapture(): void;
990
- /** Stories changed by the latest undo or redo, sorted. */
991
- historyStories(): string[];
992
- /** Undo/redo only local-origin direct operations (never remote/system transactions). */
993
- undo(): boolean;
994
- redo(): boolean;
995
- canUndo(): boolean;
996
- canRedo(): boolean;
997
- /** Adds a story with one paragraph; the receipt carries its paraId. */
998
- createStory(storyId: string, initialText: string, pStyle?: string, alignment?: string): YrsParagraphReceipt;
999
- /** Removes a complete story (including an unreachable table-cell story). */
1000
- deleteStory(storyId: string): void;
1001
- /** Inserts a row above or below the cell that `at` resolves into. */
1002
- insertRow(at: YrsCellLoc, side: 'above' | 'below', suggesting?: YrsAuthor): YrsTableReceipt;
1003
- /** Inserts a rectangular structural table at a paragraph-keyed location. */
1004
- insertTable(at: YrsLoc, rows: number, columns: number, suggesting?: YrsAuthor): YrsTableReceipt;
1005
- /** Inserts a column left or right of the cell that `at` resolves into. */
1006
- insertColumn(at: YrsCellLoc, side: 'left' | 'right'): YrsTableReceipt;
1007
- /** Deletes every row covered by an explicit rectangular cell range. */
1008
- deleteRow(range: YrsTableRange, suggesting?: YrsAuthor): YrsTableReceipt;
1009
- /** Deletes every column covered by an explicit rectangular cell range. */
1010
- deleteColumn(range: YrsTableRange): YrsTableReceipt;
1011
- /** Removes a complete table plus its reachable cell stories. */
1012
- deleteTable(table: YrsTableLoc): YrsTableReceipt;
1013
- /** Merges a rectangular range into its top-left cell. */
1014
- mergeCells(range: YrsTableRange): YrsTableReceipt;
1015
- /** Splits the merged cell covering `at` into one cell per grid slot. */
1016
- splitCell(at: YrsCellLoc, rows?: number, columns?: number): YrsTableReceipt;
1017
- /** Sets or clears the selected cells' background color. */
1018
- setCellShading(range: YrsTableRange, color: string | null): YrsTableReceipt;
1019
- /**
1020
- * Merges an OOXML-shaped patch into selected cells' `tcPr`. JSON `null`
1021
- * clears a property; merge/split-owned span keys are rejected.
1022
- */
1023
- setCellTextFormat(range: YrsTableRange, patch: Readonly<Record<string, unknown>>): YrsTableReceipt;
1024
- /**
1025
- * Merges border sides into the selected cells. `insideH`/`insideV` resolve
1026
- * per cell to the physical edges interior to the selection.
1027
- */
1028
- setCellBorders(range: YrsTableRange, borders: YrsCellBorders): YrsTableReceipt;
1029
- /** Sets one authored grid-column width in twips. */
1030
- setColumnWidth(at: YrsCellLoc, widthTwips: number): YrsTableReceipt;
1031
- /** Sets the table-wide preferred width in twips. */
1032
- setTableWidth(table: YrsTableLoc, widthTwips: number): YrsTableReceipt;
1033
- /** Inserts paragraph-break-free text. Suggesting mode mints a revision. */
1034
- insertText(at: YrsLoc, text: string, suggesting?: YrsAuthor): YrsRevisionReceipt;
1035
- /**
1036
- * Deletes a range (plain) or marks it as a suggested deletion (suggesting).
1037
- * A range spanning paragraphs also merges them (pilcrow-as-character).
1038
- */
1039
- deleteRange(range: YrsStoryRange, suggesting?: YrsAuthor): YrsRevisionReceipt;
1040
- /** Replaces a range with text in one transaction (one shared revision when suggesting). */
1041
- replaceRange(range: YrsStoryRange, text: string, suggesting?: YrsAuthor): YrsRevisionReceipt;
1042
- /**
1043
- * Splits a paragraph by inserting one pilcrow. The FIRST half keeps the
1044
- * original paraId; the SECOND half is re-minted (`secondParaId`).
1045
- */
1046
- splitParagraph(at: YrsLoc, suggesting?: YrsAuthor): YrsSplitReceipt;
1047
- /** Merges `paraId` with the FOLLOWING paragraph. Errors on the final paragraph. */
1048
- mergeParagraphs(story: string, paraId: string, suggesting?: YrsAuthor): YrsRevisionReceipt;
1049
- /**
1050
- * Toggles one run mark across a range: removes it when every unit already
1051
- * carries it, otherwise adds it.
1052
- */
1053
- toggleMark(range: YrsStoryRange, mark: YrsRunMark): void;
1054
- /** Applies set-valued direct formatting; omitted fields are kept and `null` fields clear. */
1055
- formatRange(range: YrsStoryRange, delta: YrsInlineFormatDelta): void;
1056
- /** Sets or clears the protected hyperlink attribute over a non-empty range. */
1057
- setHyperlink(range: YrsStoryRange, hyperlink: YrsHyperlinkAttrs | null): void;
1058
- /** Clears direct formatting while retaining hyperlinks and tracked-change stamps. */
1059
- clearFormatting(range: YrsStoryRange): void;
1060
- /** Applies a paragraph style id to every paragraph intersecting the range. */
1061
- applyParagraphStyle(range: YrsStoryRange, styleId: string, suggesting?: YrsAuthor): void;
1062
- /** Applies tri-state paragraph properties to every paragraph intersecting the range. */
1063
- setParagraphAttrs(range: YrsStoryRange, attrs: YrsParagraphAttrs, suggesting?: YrsAuthor): void;
1064
- /** Inserts one inline image embed, optionally as a tracked insertion. */
1065
- insertImage(at: YrsLoc, image: Readonly<Record<string, unknown>>, suggesting?: YrsAuthor): YrsRevisionReceipt;
1066
- /** Sets the authored value on a content-control embed addressed by stable payload id. */
1067
- setContentControlValue(embedId: string, value: YrsContentControlValue): void;
1068
- /** Sets a content-control value at a paragraph-keyed embed position. */
1069
- setContentControlValueAt(at: YrsLoc, value: YrsContentControlValue): void;
1070
- /** Removes the authored value from a content-control embed. */
1071
- clearContentControlValue(embedId: string): void;
1072
- /** Commits image size/wrapping/position fields in one transaction. */
1073
- setImageGeometry(embedId: string, geometry: YrsImageGeometry): void;
1074
- /** Inserts a native page-break embed at a paragraph-keyed location. */
1075
- insertPageBreak(at: YrsLoc): void;
1076
- /** Inserts a native section-break embed at a paragraph-keyed location. */
1077
- insertSectionBreak(at: YrsLoc, type: 'nextPage' | 'continuous' | 'oddPage' | 'evenPage'): void;
1078
- /** Inserts a typed watermark embed at a paragraph-keyed location. */
1079
- insertWatermark(at: YrsLoc, watermark: YrsWatermark): void;
1080
- /** Applies raw story operations in one transaction. */
1081
- applyRawOps(story: string, ops: readonly YrsRawOp[]): void;
1082
- /** Applies seed raw operations with deterministic item ordering. */
1083
- applySeedRawOps(story: string, ops: readonly YrsRawOp[]): void;
1084
- /** Sets one paragraph property (any JSON value). `paraId` is reserved. */
1085
- setParagraphAttr(paraId: string, key: string, value: unknown): void;
1086
- /** Adds a sticky-anchored comment over one or more ranges. */
1087
- addComment(ranges: readonly YrsStoryRange[], author: string, date: string, body: unknown): YrsCommentReceipt;
1088
- /**
1089
- * Accepts tracked changes: pending insertions become plain content,
1090
- * pending deletions are carried out; a `pPrIns` paragraph mark clears (the
1091
- * split stays), a `pPrDel` mark joins with the following paragraph (whose
1092
- * pPr survives — Word's surviving-`w:p` rule). Resolving never stamps a new
1093
- * revision. Throws on an unknown revision id.
1094
- */
1095
- acceptChange(target: YrsChangeTarget): YrsResolveReceipt;
1096
- /**
1097
- * Rejects tracked changes — the inverse of {@link acceptChange}: pending
1098
- * insertions roll back, pending deletions restore their text; a `pPrIns`
1099
- * mark joins back with the following paragraph, a `pPrDel` mark clears.
1100
- */
1101
- rejectChange(target: YrsChangeTarget): YrsResolveReceipt;
1102
- /** Aggregate toolbar/a11y state from yrs over one paragraph-addressed range. */
1103
- selectionContext(range: YrsStoryRange): YrsSelectionContext;
1104
- /** Enumerate tracked changes across every story in deterministic order. */
1105
- listRevisions(): YrsRevisionInfo[];
1106
- /** Current offsets of a comment's sticky anchors. Throws when an anchor no longer resolves. */
1107
- resolveComment(commentId: string): YrsResolvedCommentAnchor[];
1108
- /** Story ids in the document, sorted. */
1109
- storyIds(): string[];
1110
- /** Story length in UTF-16 units (every embed, pilcrows included, counts 1). */
1111
- storyLength(story: string): number;
1112
- /** Returns the story's canonical-stream checksum. */
1113
- storyChecksum(story: string): bigint;
1114
- /** Lowers a story to layout blocks and rejects unsupported embeds. */
1115
- yrsBlocksForStory(story: string, env?: YrsRenderEnv): unknown[];
1116
- /** Paragraph snapshots in document order. */
1117
- paragraphs(story: string): YrsParagraph[];
1118
- /** Paragraph ids and inline-unit lengths, resolved in one Rust story traversal. */
1119
- paragraphSpans(story: string): YrsParagraphLength[];
1120
- /** The raw formatted-segment view (the render bridge's input). */
1121
- storySegments(story: string): YrsStorySegment[];
1122
- /** A paragraph's story span (start unit, pilcrow index). */
1123
- locateParagraph(story: string, paraId: string): YrsParagraphSpan;
1124
- /** Drops the observer and frees the wasm-side replica. Idempotent. */
1125
- destroy(): void;
1126
- }
1127
- /** Options for {@link createYrsSession}. */
1128
- interface CreateYrsSessionOptions {
1129
- /**
1130
- * The yrs client id (non-negative safe integer). Omit to allocate a random
1131
- * 32-bit id, yjs-style.
1132
- */
1133
- clientId?: number;
1134
- }
1135
- /**
1136
- * Creates a yrs editing replica. The first call dynamically imports and
1137
- * initializes the embedded docx-edit wasm (~440KB base64) — callers must
1138
- * load it lazily so non-editor consumers avoid the wasm startup cost.
1139
- */
1140
- declare function createYrsSession(options?: CreateYrsSessionOptions): Promise<YrsSession>;
1141
-
1142
- export { type YrsParagraphSpan as $, type ResidentEngineWorkerFrame as A, ResidentWorkerFailureError as B, type CollaborationReplica as C, type YrsAuthor as D, type YrsCellBorder as E, type YrsCellBorders as F, type YrsCellLoc as G, type YrsChangeTarget as H, type YrsCommentReceipt as I, type YrsContentControlValue as J, type YrsDocxHost as K, type YrsEngineApplyProfile as L, type YrsHyperlinkAttrs as M, type YrsImageGeometry as N, type YrsInlineFormatDelta as O, type YrsInputParagraphSeed as P, type YrsInputParagraphSpan as Q, type ResidentCaretPaintStyle as R, type YrsInputPositionMap as S, type YrsNumberingProperties as T, type YrsParaOffset as U, type YrsParagraph as V, type YrsParagraphAttrs as W, type YrsParagraphLength as X, type YrsSession as Y, type YrsParagraphReceipt as Z, type YrsParagraphSeed as _, type YrsRenderEnv as a, type YrsParagraphTabStop as a0, type YrsRawOp as a1, type YrsResidentCaretRect as a2, type YrsResidentCaretSnapshot as a3, type YrsResidentWorkerSnapshot as a4, type YrsResidentWorkerSyncOptions as a5, type YrsResolveReceipt as a6, type YrsResolvedCommentAnchor as a7, type YrsRevisionReceipt as a8, type YrsRunMark as a9, type YrsSelectionContext as aa, type YrsSplitReceipt as ab, type YrsStickyPosition as ac, type YrsStoryRange as ad, type YrsStorySeed as ae, type YrsStorySegment as af, type YrsTableLoc as ag, type YrsTableRange as ah, type YrsTableReceipt as ai, type YrsTextColor as aj, type YrsTriState as ak, type YrsWatermark as al, canUseResidentEngineWorker as am, compareYrsLocs as an, createYrsInputPositionMap as ao, createYrsSession as ap, displayPositionToYrsLoc as aq, documentToYrs as ar, residentCaretDeviceRect as as, residentCaretSnapshotForFrame as at, sameYrsSelection as au, yrsLocToDisplayPosition as av, yrsToDocument as aw, type CollaborationTransport as b, type CollaborationProviderOptions as c, type CollaborationStatus as d, type CollaborationPeer as e, type CollaborationCursor as f, type CollaborationPeerListener as g, type CollaborationStatusListener as h, type CollaborationErrorListener as i, type YrsSelection as j, type CollaborationAwarenessState as k, CollaborationError as l, type CollaborationErrorCode as m, type CollaborationPresence as n, type CollaborationResolvedUser as o, type CollaborationStatusChange as p, type CollaborationTextInsertion as q, type CollaborationTransportEvent as r, type CollaborationUpdateOrigin as s, type CollaborationUser as t, type YrsLoc as u, type YrsRevisionInfo as v, type CreateYrsSessionOptions as w, type ResidentEngineOffscreenPage as x, type ResidentEngineWorkerApplyResult as y, ResidentEngineWorkerClient as z };