@stll/docx-core 0.43.1 → 0.44.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.
@@ -1,4 +1,5 @@
1
- import { $r as NumberingDefinitions, Bi as HeadingOutlineLevel, Bn as RunContent, Bt as HeaderFooterType, C as Relationship, Cn as Paragraph, D as StyleDefinitions, Dn as ParagraphPropertyChange, Gn as Section, It as Footnote, Kn as SectionProperties, Ot as Endnote, S as MediaFile, Sr as TrackedChangeInfo, St as DocumentBody, Tn as ParagraphMarkChange, Ut as INSERTION_SEAM_POLICIES, Wr as AbstractNumbering, a as DocumentSettings, ei as NumberingInstance, fi as TableCellFormatting, ft as Comment, g as ExhaustiveFields, gr as TableRow, i as Document, it as BlockContent, oi as ParagraphFormatting, or as TabContent, pi as TableFormatting, s as DocxPackage, sr as Table, st as BookmarkEnd, ut as BreakContent, vi as TableRowFormatting, wn as ParagraphContent, xi as TextFormatting, zn as Run, zt as HeaderFooter } from "../document-CaGfolcU.js";
1
+ import { Bt as HeaderFooter, C as Relationship, Ct as DocumentBody, D as StyleDefinitions, Dn as ParagraphContent, En as Paragraph, Er as TrackedChangeInfo, Jr as AbstractNumbering, Lt as Footnote, On as ParagraphMarkChange, S as MediaFile, Si as TableRowFormatting, Ti as TextFormatting, Un as Run, Vt as HeaderFooterType, Wi as HeadingOutlineLevel, Wn as RunContent, Wt as INSERTION_SEAM_POLICIES, Xn as SectionProperties, Yn as Section, Zn as SectionPropertyChange, _i as TableFormatting, a as DocumentSettings, an as KeptCut, at as BlockContent, br as TableRow, ct as BookmarkEnd, dr as Table, dt as BreakContent, g as ExhaustiveFields, gi as TableCellFormatting, i as Document, ii as NumberingInstance, jn as ParagraphPropertyChange, kt as Endnote, pt as Comment, qn as SdtProperties, ri as NumberingDefinitions, s as DocxPackage, st as BlockSdt, ui as ParagraphFormatting, ur as TabContent } from "../document-f4_h6JMT.js";
2
+ import { a as DeepReadonly, n as PreservedChild, o as RecordField } from "../preservedMarkup-BWpGhchw.js";
2
3
  import { Result, TaggedErrorClass } from "better-result";
3
4
  /** JSON-safe map presence, including an explicitly undefined section map. */
4
5
  type SectionMapState = {
@@ -31,6 +32,22 @@ type SectionViewChange = {
31
32
  /**
32
33
  * The operation schema this module reads and writes.
33
34
  *
35
+ * Version 18 adds `comments` and `newCommentIds` to `insertContent`: a
36
+ * pasted copy of a standing comment's anchors takes a fresh comment id and a
37
+ * copy of the thread the paste carries, or is left out without one.
38
+ * Version 17 adds the `containerStart` insertion point: paragraphs or a table
39
+ * before the first block of a block list, whatever kind that block is.
40
+ * Version 16 adds `createdSince` to `restoreCommentState`: a restoration
41
+ * rebased over concurrent comment creations keeps them.
42
+ * Version 15 adds paragraph insertion beside tables and exact empty block
43
+ * replacements. Older envelopes receive an unsupportedSchema refusal; old
44
+ * operation payloads retain their meaning, with no automatic schema rewrite.
45
+ * Version 14 restores section-view topology in story lifecycle inverses.
46
+ * Older envelopes receive an unsupportedSchema refusal.
47
+ * Version 12 adds `setContentControl`, which sets a block-level content
48
+ * control's properties by its id.
49
+ * Version 11 records, as a sequenced format's effect, the run a direct
50
+ * format cut (`setRunProps` effect).
34
51
  * Version 9 adds exact, JSON-safe package resource replacement for clipboard imports.
35
52
  * Version 8 adds semantic table edits and exact whole-table restoration.
36
53
  * Version 7 adds lossless own-undefined operation snapshot presence and
@@ -53,7 +70,7 @@ type SectionViewChange = {
53
70
  * and paragraph operations, and the review operations `setParagraphReview`,
54
71
  * `replaceInline` and `resolveRevision`.
55
72
  */
56
- export declare const DOCUMENT_OP_SCHEMA_VERSION = 10;
73
+ export declare const DOCUMENT_OP_SCHEMA_VERSION = 18;
57
74
  /**
58
75
  * The main story has a fixed address; other editable parts use their stable
59
76
  * relationship id or note id. Comment bodies are not yet editable stories.
@@ -221,6 +238,7 @@ export declare const DOCUMENT_OP_TYPES: Readonly<{
221
238
  readonly DELETE_NUMBERING_INSTANCE: "deleteNumberingInstance";
222
239
  readonly SET_SECTION_ENDPOINT: "setSectionEndpoint";
223
240
  readonly SET_PACKAGE_RESOURCES: "setPackageResources";
241
+ readonly SET_CONTENT_CONTROL: "setContentControl";
224
242
  }>;
225
243
  /** One of {@link DOCUMENT_OP_TYPES}. */
226
244
  type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES];
@@ -230,8 +248,11 @@ type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES]
230
248
  * `runProps` is either {@link INHERIT_RUN_PROPS} or the exact property set the
231
249
  * text carries. When the set differs from the run at the position, the text
232
250
  * becomes a run of its own and that run is split around it; `newIds` names
233
- * the ids of the second half when the run carries some. The run decides where
234
- * the text goes, so `at.zeroWidthBefore` is not read.
251
+ * the ids of the second half when the run carries some. The text goes in
252
+ * exactly at the gap `at` names: after the zero-width leaves
253
+ * `at.zeroWidthBefore` counts (all of them when it is absent) and before the
254
+ * rest. It joins the run holding the leaf before that gap, else the one
255
+ * holding the leaf after it, whatever kind of leaf either is.
235
256
  *
236
257
  * With `revision`, the text is a tracked insertion: it is wrapped in an
237
258
  * `Insertion` carrying the stamp, cutting the records around it down to a
@@ -261,6 +282,15 @@ type InsertTextOp = {
261
282
  * {@link InsertTextOp}. It is refused inside tracked-removed content, and
262
283
  * when it holds a comment boundary or reference, which no tracked change can
263
284
  * hold.
285
+ *
286
+ * A comment owns one range. A comment anchor of the slice whose kind its
287
+ * comment already has standing in the document is a copy: when `comments`
288
+ * carries that comment's thread and the slice holds the comment's range (or
289
+ * point) whole, the thread's anchors take the ids `newCommentIds` lists and
290
+ * the thread is copied under them; otherwise those anchors are left out. An
291
+ * anchor completing a comment's range goes in as it is, a repeated one is
292
+ * left out, and a carried thread none of whose anchors stand joins the
293
+ * records unless they hold it. A thread it adds belongs to its suggestion.
264
294
  */
265
295
  type InsertContentOp = {
266
296
  type: typeof DOCUMENT_OP_TYPES.INSERT_CONTENT;
@@ -269,6 +299,17 @@ type InsertContentOp = {
269
299
  seamPolicy?: typeof INSERTION_SEAM_POLICIES.MERGE_PLAIN_RUNS;
270
300
  newIds?: NewIds;
271
301
  revision?: RevisionStamp;
302
+ /**
303
+ * The comment threads the slice carries, as a paste copies them: each
304
+ * root names, by its id, anchors of the slice; replies follow their root.
305
+ * Their paragraphs need ids the package does not use.
306
+ */
307
+ comments?: readonly Comment[];
308
+ /**
309
+ * Fresh comment ids for the carried threads a paste copies, one per
310
+ * comment of each copied thread, in carried order. Unused ones are left.
311
+ */
312
+ newCommentIds?: readonly number[];
272
313
  };
273
314
  /**
274
315
  * Remove what lies between two positions of one paragraph: its units and the
@@ -288,10 +329,12 @@ type InsertContentOp = {
288
329
  * already inside a deletion or moved away is left as it is; content inside an
289
330
  * insertion or a move gets a deletion nested inside that record; everything
290
331
  * else is wrapped in a `Deletion` carrying the stamp, an inline content
291
- * control the range covers whole going in with its content. A range holding
292
- * a comment boundary or reference is refused, since no tracked change can
293
- * hold one; `planTrackedDeletion` plans the deletions around them. A tracked
294
- * deletion joins nothing, so `join` must be absent.
332
+ * control the range covers whole going in with its content. A record the
333
+ * range covers whole goes in with the comment anchors it holds, and accepting
334
+ * the deletion removes them, as the direct deletion does. A range holding a
335
+ * bare comment boundary or reference is refused, since no tracked change
336
+ * takes one in; `planTrackedDeletion` plans the deletions around them. A
337
+ * tracked deletion joins nothing, so `join` must be absent.
295
338
  */
296
339
  type DeleteRangeOp = {
297
340
  type: typeof DOCUMENT_OP_TYPES.DELETE_RANGE;
@@ -317,11 +360,19 @@ type SplitInlineOp = {
317
360
  * already run across it. Merged records must be alike in everything but
318
361
  * their content and ids; the first's ids stand for both. Absent
319
362
  * `zeroWidthBefore` is `0`.
363
+ *
364
+ * With `ifAlike`, the join is the seam of an edit rather than a record it
365
+ * restores: records that are not alike, that carry ids the merge would
366
+ * retire, or that a run already runs across, and a position where no
367
+ * records meet are left as they are, and the operation changes nothing. Typing joins its run to alike runs this
368
+ * way, so the join still applies, or keeps out, where a concurrent edit has
369
+ * changed the records beside it.
320
370
  */
321
371
  type JoinInlineOp = {
322
372
  type: typeof DOCUMENT_OP_TYPES.JOIN_INLINE;
323
373
  at: TextPosition;
324
374
  depth: number;
375
+ ifAlike?: true;
325
376
  };
326
377
  /** Whether a tracked run patch appends an independently rejectable review. */
327
378
  export declare const PROPERTY_REVIEW_POLICIES: Readonly<{
@@ -339,6 +390,9 @@ export declare const PROPERTY_REVIEW_POLICIES: Readonly<{
339
390
  * levels once the patch is applied, as {@link JoinInlineOp} does; the inverse
340
391
  * of a patch that cut runs uses them.
341
392
  *
393
+ * Under `propertyReview: "append"`, a run patched back to the formatting its
394
+ * pending change started from keeps no pending change.
395
+ *
342
396
  * With `revision`, every run the patch changes records a tracked property
343
397
  * change (`w:rPrChange`) whose previous formatting is the run's own property
344
398
  * set before the patch. A run already carrying one keeps it, and with it the
@@ -346,6 +400,8 @@ export declare const PROPERTY_REVIEW_POLICIES: Readonly<{
346
400
  * and `joinEnd` must be absent.
347
401
  * `propertyReview: "append"` coalesces an editor action into one pending review.
348
402
  * It retains the first baseline and records the latest formatter's metadata.
403
+ * A suggestion's patch of a run whose pending change is not that suggestion's
404
+ * is refused: rejecting the suggestion would discard the other change too.
349
405
  */
350
406
  type SetRunPropsOp = {
351
407
  type: typeof DOCUMENT_OP_TYPES.SET_RUN_PROPS;
@@ -486,7 +542,11 @@ type BlockInsertionPoint = {
486
542
  blockId: string;
487
543
  };
488
544
  /**
489
- * Insert paragraphs beside an existing paragraph, with pre-minted ids.
545
+ * Insert paragraphs beside an existing paragraph or table, or at the start of
546
+ * a block list, with pre-minted ids. A table is addressed by a paragraph of
547
+ * its own, and a list by a paragraph it holds, as in TableInsertionPoint.
548
+ * Tracked table-side insertion refuses an earlier pending first-paragraph
549
+ * source owner in the same containing block list.
490
550
  * Section-bearing paragraphs are refused. With `revision`, each inserted
491
551
  * paragraph receives an inserted mark and its content an insertion wrapper.
492
552
  * A tracked insertion after a paragraph no paragraph follows marks the
@@ -499,7 +559,7 @@ type BlockInsertionPoint = {
499
559
  type InsertBlocksOp = {
500
560
  type: typeof DOCUMENT_OP_TYPES.INSERT_BLOCKS;
501
561
  story: OpStory;
502
- at: BlockInsertionPoint;
562
+ at: TableInsertionPoint;
503
563
  blocks: readonly Paragraph[];
504
564
  revision?: RevisionStamp;
505
565
  /** With `revision`, the insertion is the destination of a move: `w:moveTo`. */
@@ -529,7 +589,11 @@ type DeleteBlocksOp = {
529
589
  newIds?: NewIds;
530
590
  };
531
591
  /**
532
- * Replace a run of adjacent paragraphs with other paragraphs.
592
+ * Replace a run of adjacent paragraphs with other paragraphs, or remove it.
593
+ * An empty replacement must preserve the containing story/cell invariants;
594
+ * its inverse inserts the exact captured paragraphs at the surviving boundary.
595
+ * Container-final marks and owned empty formatting refuse when that insertion
596
+ * cannot restore the capture exactly.
533
597
  *
534
598
  * `expected` is the paragraphs as they stand: they are found by `paraId` and
535
599
  * compared structurally (without the fields a relayout recomputes), so a
@@ -738,6 +802,24 @@ type PackageResourceMapChange<Value> = {
738
802
  next: PackageResourcePresence;
739
803
  entries: readonly PackageResourceEntryChange<Value>[];
740
804
  };
805
+ /**
806
+ * Set one content control's properties exactly: its value (`w:lastValue`,
807
+ * `w14:checked`, `w:fullDate`), placeholder state and binding. The control is
808
+ * addressed by its `w:sdtPr/w:id`, block-level or inline, in one story.
809
+ * `expected` is what its properties are now and `properties` what they become;
810
+ * the inverse swaps the two. The control's id and type do not change, and its
811
+ * content is edited by the text operations. `blockIds` names the paragraphs
812
+ * the control holds (block-level) or sits in (inline), in document order: the
813
+ * blocks a concurrent change conflicts with.
814
+ */
815
+ type SetContentControlOp = {
816
+ type: typeof DOCUMENT_OP_TYPES.SET_CONTENT_CONTROL;
817
+ story: OpStory;
818
+ controlId: number;
819
+ blockIds: readonly string[];
820
+ expected: SdtProperties;
821
+ properties: SdtProperties;
822
+ };
741
823
  /** Replace merged definitions and change keyed package entries, refusing stale package data. */
742
824
  type SetPackageResourcesOp = {
743
825
  type: typeof DOCUMENT_OP_TYPES.SET_PACKAGE_RESOURCES;
@@ -770,15 +852,37 @@ type SetSectionEndpointOp = {
770
852
  sectionMetadata?: SectionViewState;
771
853
  };
772
854
  /**
773
- * Insert a table before or after a paragraph. Tracking records each row,
774
- * cell content and cell-ending paragraph mark. At a container's end,
775
- * `terminal` moves the source content into a new preceding paragraph while
776
- * retaining the source id and fields on the untracked final paragraph.
855
+ * Where a table goes: beside a paragraph, or beside the innermost table
856
+ * holding the paragraph `blockId` names, in the block list holding that
857
+ * table, touching it, where no paragraph stands on that side to name; or,
858
+ * with `containerStart`, before the first block of the block list (a story,
859
+ * cell, note, text box or block content control) that holds the paragraph
860
+ * `blockId` names directly, whatever kind that first block is: the one place
861
+ * no paragraph or table names when the list starts with a block that holds
862
+ * no paragraph, such as an empty content control. Every container ends with
863
+ * a paragraph, so one is always there to name the list by.
864
+ */
865
+ type TableInsertionPoint = BlockInsertionPoint | {
866
+ type: "beforeTable";
867
+ blockId: string;
868
+ } | {
869
+ type: "afterTable";
870
+ blockId: string;
871
+ } | {
872
+ type: "containerStart";
873
+ blockId: string;
874
+ };
875
+ /**
876
+ * Insert a table before or after a paragraph, or beside a table. Tracking
877
+ * records each row, cell content and cell-ending paragraph mark. At a
878
+ * container's end, `terminal` moves the source content into a new preceding
879
+ * paragraph while retaining the source id and fields on the untracked final
880
+ * paragraph.
777
881
  */
778
882
  type InsertTableOp = {
779
883
  type: typeof DOCUMENT_OP_TYPES.INSERT_TABLE;
780
884
  story: OpStory;
781
- at: BlockInsertionPoint;
885
+ at: TableInsertionPoint;
782
886
  table: Table;
783
887
  revision?: RevisionStamp;
784
888
  newIds?: NewIds;
@@ -846,33 +950,39 @@ type SetSectionPropsOp = {
846
950
  patch: FormattingPatch<SectionProperties>;
847
951
  };
848
952
  /** JSON-safe lifecycle deltas: omitted fields are unowned, null restores absence. */
849
- type StoryParts = {
953
+ type StoryPartFields = {
850
954
  /** Owned fields whose source explicitly had an undefined own property. */
851
955
  undefinedFields?: readonly ({
852
956
  target: "body";
853
957
  keys: readonly (keyof NonNullable<StoryParts["body"]>)[];
854
958
  } | {
855
959
  target: "package";
856
- keys: readonly (keyof Omit<StoryParts, "body" | "sections" | "undefinedFields">)[];
960
+ keys: readonly (keyof Omit<StoryParts, "body" | "sections" | "sectionView" | "undefinedFields">)[];
857
961
  } | {
858
962
  target: "section";
859
963
  index: number;
860
964
  keys: readonly (keyof Omit<NonNullable<StoryParts["sections"]>[number], "index">)[];
861
965
  })[];
862
- body?: { [Key in keyof Omit<DocumentBody, "sections">]?: Key extends "content" ? DocumentBody[Key] : Exclude<DocumentBody[Key], undefined> | null; };
863
- /** Section contents remain derived from the body's content and are never duplicated. */
864
- sections?: readonly {
865
- index: number;
866
- properties?: Section["properties"];
867
- headers?: readonly (readonly [HeaderFooterType, HeaderFooter])[] | null;
868
- footers?: readonly (readonly [HeaderFooterType, HeaderFooter])[] | null;
869
- }[];
966
+ body?: { [Key in Exclude<RecordField<DocumentBody>, "sections">]?: Key extends "content" ? DocumentBody[Key] : Exclude<DocumentBody[Key], undefined> | null; };
870
967
  headers?: readonly (readonly [string, HeaderFooter])[] | null;
871
968
  footers?: readonly (readonly [string, HeaderFooter])[] | null;
872
969
  footnotes?: readonly Footnote[] | null;
873
970
  endnotes?: readonly Endnote[] | null;
874
971
  settings?: DocumentSettings | null;
875
972
  };
973
+ /** Section contents stay derived; a complete view and narrow metadata never overlap. */
974
+ type StoryParts = StoryPartFields & ({
975
+ sectionView?: never;
976
+ sections?: readonly {
977
+ index: number;
978
+ properties?: Section["properties"];
979
+ headers?: readonly (readonly [HeaderFooterType, HeaderFooter])[] | null;
980
+ footers?: readonly (readonly [HeaderFooterType, HeaderFooter])[] | null;
981
+ }[];
982
+ } | {
983
+ sectionView: SectionViewState;
984
+ sections?: never;
985
+ });
876
986
  /** Exact stale-checked lifecycle inverse; unrelated package parts stay untouched. */
877
987
  type RestoreStoryPartsOp = {
878
988
  type: typeof DOCUMENT_OP_TYPES.RESTORE_STORY_PARTS;
@@ -886,11 +996,16 @@ type TableEditTarget = {
886
996
  revision?: RevisionStamp;
887
997
  newIds?: NewIds;
888
998
  };
889
- /** Insert before column (including the final boundary); fresh ids are in row order. */
999
+ /**
1000
+ * Insert `count` adjacent columns (one when absent), each `width` wide,
1001
+ * before column (including the final boundary); fresh ids are in reading
1002
+ * order, row by row. Tracked, the columns share one grid change.
1003
+ */
890
1004
  type InsertColumnOp = TableEditTarget & {
891
1005
  type: typeof DOCUMENT_OP_TYPES.INSERT_COLUMN;
892
1006
  column: number;
893
1007
  width: number;
1008
+ count?: number;
894
1009
  newBlockIds: readonly string[];
895
1010
  };
896
1011
  type DeleteColumnOp = TableEditTarget & {
@@ -980,6 +1095,27 @@ type DeleteCommentOp = {
980
1095
  id: number;
981
1096
  scope: "thread" | "reply";
982
1097
  };
1098
+ /**
1099
+ * A comment range marker standing between blocks rather than in a paragraph,
1100
+ * addressed by the nearest block of its own block list that holds a
1101
+ * paragraph: the nearest such block after it, or before it when none follows.
1102
+ */
1103
+ type CommentBoundaryAnchor = {
1104
+ story: OpStory;
1105
+ /** That block's first paragraph after the marker, or its last before it. */
1106
+ blockId: string;
1107
+ /** How many block lists that paragraph's own list lies below the marker's. */
1108
+ depth: number;
1109
+ /** Whether the marker stands before or after that block. */
1110
+ side: "before" | "after";
1111
+ /** How many blocks, other markers of the same comments aside, stand between the two. */
1112
+ gap: number;
1113
+ node: Extract<BlockContent, {
1114
+ type: "commentRangeStart";
1115
+ } | {
1116
+ type: "commentRangeEnd";
1117
+ }>;
1118
+ };
983
1119
  /** Exact owned comment records and the paragraph fragments containing their anchors. */
984
1120
  type CommentState = {
985
1121
  relationshipPresence: "absent" | "undefined" | "present";
@@ -998,6 +1134,12 @@ type CommentState = {
998
1134
  blockId: string;
999
1135
  content: readonly ParagraphContent[];
1000
1136
  }[];
1137
+ /**
1138
+ * The owned markers standing between blocks, in document order; absent
1139
+ * when there are none. Each one's addressing paragraph is also one of
1140
+ * `anchors`, so an edit to it conflicts with the restoration.
1141
+ */
1142
+ boundaries?: readonly CommentBoundaryAnchor[];
1001
1143
  };
1002
1144
  type RestoreCommentStateOp = {
1003
1145
  type: typeof DOCUMENT_OP_TYPES.RESTORE_COMMENT_STATE;
@@ -1006,10 +1148,17 @@ type RestoreCommentStateOp = {
1006
1148
  scaffoldIds: NewIds;
1007
1149
  expected: CommentState;
1008
1150
  state: CommentState;
1151
+ /**
1152
+ * Comments created concurrently since the restoration was captured, in the
1153
+ * order they were created: it applies as if they were absent, then each
1154
+ * takes its place again before the first comment with a greater id, as its
1155
+ * creation does. Absent when there are none.
1156
+ */
1157
+ createdSince?: readonly number[];
1009
1158
  };
1010
1159
  type CommentOp = CreateCommentOp | UpdateCommentContentOp | SetCommentResolutionOp | DeleteCommentOp | RestoreCommentStateOp;
1011
1160
  /** A schema-version-10 document operation. */
1012
- type DocumentOp = (CommentOp | CreateHeaderFooterOp | RemoveHeaderFooterOp | AddNoteOp | RemoveNoteOp | SetSectionPropsOp | RestoreStoryPartsOp | DeleteBlocksOp | InsertTableOp | DeleteTableOp | SetContainerBlocksOp | InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | SetRevisionInfoOp | InsertRowOp | DeleteRowOp | SetTableRowsOp | TableEditOp | SetTableOp | CreateNumberingInstanceOp | DeleteNumberingInstanceOp | SetSectionEndpointOp | SetPackageResourcesOp) & {
1161
+ type DocumentOp = (CommentOp | CreateHeaderFooterOp | RemoveHeaderFooterOp | AddNoteOp | RemoveNoteOp | SetSectionPropsOp | RestoreStoryPartsOp | DeleteBlocksOp | InsertTableOp | DeleteTableOp | SetContainerBlocksOp | InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | SetRevisionInfoOp | InsertRowOp | DeleteRowOp | SetTableRowsOp | TableEditOp | SetTableOp | CreateNumberingInstanceOp | DeleteNumberingInstanceOp | SetSectionEndpointOp | SetPackageResourcesOp | SetContentControlOp) & {
1013
1162
  /** Own undefined fields recorded by the operation capture boundary. */
1014
1163
  undefinedFields?: readonly (readonly string[])[];
1015
1164
  };
@@ -1029,6 +1178,34 @@ type TouchedBlocks = {
1029
1178
  modified: readonly string[];
1030
1179
  inserted: readonly string[];
1031
1180
  removed: readonly string[];
1181
+ /**
1182
+ * Removed paragraphs whose content an edit joined into another paragraph,
1183
+ * each with the paragraph that holds it now. A join keeps the second
1184
+ * paragraph's id (a paragraph mark that goes leaves the one after it); a
1185
+ * host holding a removed id re-anchors on its survivor.
1186
+ */
1187
+ absorbed?: readonly ParagraphAbsorption[];
1188
+ /**
1189
+ * Tracked changes a resolution joined into the alike change they met, the
1190
+ * pieces of one change rejoining where what stood between them went, each
1191
+ * with the change that holds their content now and keeps its id. A host
1192
+ * holding an absorbed revision id decides the survivor instead.
1193
+ */
1194
+ absorbedRevisions?: readonly RevisionAbsorption[];
1195
+ };
1196
+ /** A tracked change a resolution joined into another, and the one it joined. */
1197
+ type RevisionAbsorption = {
1198
+ /** The id no record carries any more. */
1199
+ absorbed: number;
1200
+ /** The id of the change that holds its content now. */
1201
+ survivor: number;
1202
+ };
1203
+ /** A paragraph an edit joined into another, and the paragraph it joined. */
1204
+ type ParagraphAbsorption = {
1205
+ /** The removed paragraph's id. */
1206
+ absorbed: string;
1207
+ /** The id of the paragraph that holds its content now. */
1208
+ survivor: string;
1032
1209
  };
1033
1210
  /** What applying operations produced: the document, its inverse, and the blocks it changed. */
1034
1211
  type DocumentEdit = {
@@ -1037,8 +1214,89 @@ type DocumentEdit = {
1037
1214
  inverse: readonly DocumentOp[];
1038
1215
  touched: TouchedBlocks;
1039
1216
  };
1217
+ type DocumentEditEffects = Pick<DocumentEdit, "inverse" | "touched">;
1218
+ /** Effects of edits made in turn, with their final document. */
1219
+ export declare const combineEditEffects: (final: Document, edits: readonly DocumentEditEffects[]) => DocumentEdit;
1040
1220
  /** Edits made in turn, starting from `document`, as one edit. */
1041
1221
  export declare const combineEdits: (document: Document, edits: readonly DocumentEdit[]) => DocumentEdit;
1222
+ /** Every `paraId` of every paragraph in a value, nested ones included, in document order. */
1223
+ export declare const paragraphIdsIn: (value: unknown) => string[];
1224
+ /** Every paragraph id of a package, each story walked once. */
1225
+ export declare const packageParagraphIds: (pkg: DocxPackage) => string[];
1226
+ /**
1227
+ * The key two spellings of one id share. `ST_LongHexNumber` is hex, so
1228
+ * `0000abcd` and `0000ABCD` are the same id; every lookup and comparison of
1229
+ * paragraph ids goes through this.
1230
+ */
1231
+ export declare const idKey: (id: string) => string;
1232
+ /** A paragraph id's spelling for its number. */
1233
+ export declare const formatParaId: (id: number) => string;
1234
+ export declare const ID_LEASE_KINDS: Readonly<{
1235
+ readonly PARAGRAPH: "paragraph";
1236
+ readonly REVISION: "revision";
1237
+ readonly CONTROL: "control";
1238
+ readonly COMMENT: "comment";
1239
+ }>;
1240
+ type IdLeaseKind = (typeof ID_LEASE_KINDS)[keyof typeof ID_LEASE_KINDS];
1241
+ /**
1242
+ * One past the largest id of each kind: a paragraph id stays below
1243
+ * 0x80000000, and `w:id` is a signed 32-bit integer.
1244
+ */
1245
+ export declare const ID_KIND_LIMITS: Readonly<Record<IdLeaseKind, number>>;
1246
+ /** Ids from `start` up to, not including, `end`. */
1247
+ type IdRange = {
1248
+ readonly start: number;
1249
+ readonly end: number;
1250
+ };
1251
+ /** One leased range of one id kind. */
1252
+ type IdBlock = IdRange & {
1253
+ readonly kind: IdLeaseKind;
1254
+ };
1255
+ /** The ids one author may still mint: disjoint blocks, ascending per kind. */
1256
+ type IdLease = {
1257
+ readonly blocks: readonly IdBlock[];
1258
+ };
1259
+ /** Whether `lease` holds `id` of `kind`. */
1260
+ export declare const idLeaseHolds: (lease: IdLease, kind: IdLeaseKind, id: number) => boolean;
1261
+ /** How many ids of `kind` the lease still holds. */
1262
+ export declare const idLeaseRemaining: (lease: IdLease, kind: IdLeaseKind) => number;
1263
+ /** The ids of each kind a document holds anywhere in its package. */
1264
+ type LeasedIdCensus = Readonly<Record<IdLeaseKind, ReadonlySet<number>>>;
1265
+ /** Every paragraph, revision, content-control and comment id of a document. */
1266
+ export declare const leasedIdCensus: (document: Document) => LeasedIdCensus;
1267
+ /** One id of one kind. */
1268
+ type LeasedId = {
1269
+ readonly kind: IdLeaseKind;
1270
+ readonly id: number;
1271
+ };
1272
+ /** The ids `after` holds that `before` does not, by kind and then by id. */
1273
+ export declare const introducedIds: (before: LeasedIdCensus, after: LeasedIdCensus) => LeasedId[];
1274
+ /** The IDs introduced between package versions, in the same order as the census difference. */
1275
+ export declare const introducedDocumentIds: ({ before, after }: {
1276
+ before: Document;
1277
+ after: Document;
1278
+ }) => LeasedId[];
1279
+ /**
1280
+ * `lease` without any id at or below the highest of `ids` it holds, per kind:
1281
+ * an author mints upward through its lease and never mints an id twice, so an
1282
+ * id it minted and later removed cannot meet another author's restoration of it.
1283
+ */
1284
+ export declare const trimIdLease: (lease: IdLease, ids: readonly LeasedId[]) => IdLease;
1285
+ type FreshLeasedIdsOptions = {
1286
+ lease: IdLease | undefined;
1287
+ kind: IdLeaseKind;
1288
+ count: number;
1289
+ /** Whether an id is already in use and cannot be minted. */
1290
+ taken: (id: number) => boolean;
1291
+ /** The lowest candidate, 1 by default. */
1292
+ from?: number;
1293
+ };
1294
+ /**
1295
+ * Up to `count` ids of `kind` that `taken` refuses, lowest first, from the
1296
+ * lease, or from the whole space without one. Fewer come back only when the
1297
+ * lease or the space has no more: the caller refuses the edit, never wraps.
1298
+ */
1299
+ export declare const freshLeasedIds: ({ lease, kind, count, taken, from }: FreshLeasedIdsOptions) => number[];
1042
1300
  /** A place between two leaves. */
1043
1301
  type Gap = {
1044
1302
  offset: number;
@@ -1094,8 +1352,6 @@ export declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
1094
1352
  readonly BLOCK_NOT_FOUND: "blockNotFound";
1095
1353
  /** A raw operation is missing required fields or supplies their wrong shape. */
1096
1354
  readonly INVALID_OPERATION: "invalidOperation";
1097
- /** Removing a column would leave a row with no active cells. */
1098
- readonly TABLE_ROW_EMPTY: "tableRowEmpty";
1099
1355
  /** The requested topology edit changes nothing. */
1100
1356
  readonly NO_CHANGE: "noChange";
1101
1357
  /** Removed content carries anchors or review records that require coordinated resolution. */
@@ -1123,7 +1379,8 @@ export declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
1123
1379
  /**
1124
1380
  * The operation would move or remove a section break (joining a paragraph
1125
1381
  * that ends a section, replacing paragraphs across or at one); that is a
1126
- * section operation.
1382
+ * section operation. Or it would put one inside a table cell, where no
1383
+ * section ends.
1127
1384
  */
1128
1385
  readonly SECTION_BOUNDARY: "sectionBoundary";
1129
1386
  /** Direct text would land inside tracked-deleted or moved-away content. */
@@ -1157,19 +1414,93 @@ export declare const DOCUMENT_OP_REFUSAL_REASONS: Readonly<{
1157
1414
  /** A replacement names no paragraph to replace, or none to put in its place. */
1158
1415
  readonly EMPTY_BLOCK_LIST: "emptyBlockList";
1159
1416
  /**
1160
- * The operation would record a tracked change over one the target already
1161
- * carries (a paragraph mark, a split that would drop a paragraph's property
1162
- * change), or would give a tracked split a mark of its own.
1417
+ * The operation would give a tracked split a mark or property change of
1418
+ * its own, or would put a pasted paragraph's review over the review the
1419
+ * destination already carries.
1163
1420
  */
1164
1421
  readonly REVISION_CONFLICT: "revisionConflict";
1422
+ /**
1423
+ * The operation cannot preserve an existing table, row, cell or grid
1424
+ * review, or would overwrite one of the same kind. Resolve it before
1425
+ * changing the table.
1426
+ */
1427
+ readonly PENDING_TABLE_CHANGE: "pendingTableChange";
1428
+ /**
1429
+ * A suggestion would fold into a run's pending property change that is not
1430
+ * its own. A run holds one property change and a suggestion is resolved by
1431
+ * its id: rejecting it would discard the other change with its own.
1432
+ */
1433
+ readonly PENDING_RUN_PROPERTY_CHANGE: "pendingRunPropertyChange";
1434
+ /**
1435
+ * A suggestion would fold into a paragraph's pending property change that
1436
+ * is not its own, for the same reason as
1437
+ * {@link DOCUMENT_OP_REFUSAL_REASONS.PENDING_RUN_PROPERTY_CHANGE}; or a
1438
+ * tracked insertion after a container's final paragraph would take over
1439
+ * the mark of one whose properties carry a pending change.
1440
+ */
1441
+ readonly PENDING_PARAGRAPH_PROPERTY_CHANGE: "pendingParagraphPropertyChange";
1442
+ /**
1443
+ * A tracked join would run a paragraph, through one whose own mark is
1444
+ * already going, into the table after it while that table's first row or
1445
+ * cell has a pending insertion and cannot receive what runs in.
1446
+ */
1447
+ readonly JOIN_INTO_PENDING_TABLE: "joinIntoPendingTable";
1165
1448
  /** The operation would put a mark on a paragraph that ends its story body or table cell. */
1166
1449
  readonly CONTAINER_FINAL_MARK: "containerFinalMark";
1450
+ /**
1451
+ * A paragraph break inside an inline content control: the control lives in
1452
+ * one paragraph, so the break has no form.
1453
+ */
1454
+ readonly INSIDE_INLINE_CONTROL: "insideInlineControl";
1167
1455
  /**
1168
1456
  * No tracked change can record the edit, or no resolution op can carry it
1169
1457
  * out yet: comment boundaries in a tracked range, the paragraph mark's run
1170
1458
  * properties, a join at a section break, a record inside a field.
1171
1459
  */
1172
1460
  readonly UNTRACKABLE: "untrackable";
1461
+ /**
1462
+ * A tracked paragraph would take over the mark of a paragraph whose break
1463
+ * is pending deletion or moving away. No placement of that record keeps
1464
+ * both laws: accepting equals the direct edit, and rejecting the insertion
1465
+ * alone gives the original back.
1466
+ */
1467
+ readonly PENDING_BREAK_TAKEOVER: "pendingBreakTakeover";
1468
+ /**
1469
+ * A tracked operation would record a change of a paragraph mark whose
1470
+ * break is pending deletion (deleted, moving away, or added and then
1471
+ * deleted), which holds one such record: joining or deleting through it,
1472
+ * putting a table or row against it, or, after a container's final
1473
+ * paragraph, taking it over, since the container's new final paragraph
1474
+ * keeps no record a pending change moves to it.
1475
+ */
1476
+ readonly PENDING_PARAGRAPH_MARK_DELETION: "pendingParagraphMarkDeletion";
1477
+ /**
1478
+ * As {@link DOCUMENT_OP_REFUSAL_REASONS.PENDING_PARAGRAPH_MARK_DELETION},
1479
+ * for a paragraph mark whose break is pending insertion (inserted or moved
1480
+ * here) and not deleted since.
1481
+ */
1482
+ readonly PENDING_PARAGRAPH_MARK_INSERTION: "pendingParagraphMarkInsertion";
1483
+ /**
1484
+ * A paragraph the operation would edit separately joins the next one
1485
+ * through a mark pending deletion (deleted or moving away): accepting that
1486
+ * deletion gives the joined paragraph the next paragraph's properties, so
1487
+ * the edit would land on another paragraph or merge two named ones.
1488
+ */
1489
+ readonly PENDING_PARAGRAPH_JOIN: "pendingParagraphJoin";
1490
+ /**
1491
+ * A tracked column insertion in a table whose columns already carry a
1492
+ * pending change. A table records one previous grid (`w:tblGridChange`), so
1493
+ * a second insertion could not be rejected alone: the columns of one change
1494
+ * go in one operation (`InsertColumnOp.count`).
1495
+ */
1496
+ readonly PENDING_GRID_CHANGE: "pendingGridChange";
1497
+ /**
1498
+ * A suggested link change would leave a piece of a link holding only
1499
+ * bookmark or comment markers, or would copy content that names a record of
1500
+ * its own (preserved run markup, a marker inside a copied text box, or a
1501
+ * note holding a tracked change, comment or bookmark).
1502
+ */
1503
+ readonly UNRECORDABLE_LINK_SUGGESTION: "unrecordableLinkSuggestion";
1173
1504
  /** Seed contract: a main-story paragraph has no `paraId`. */
1174
1505
  readonly MISSING_BLOCK_ID: "missingBlockId";
1175
1506
  /** Seed contract: two paragraphs in the package carry one id. */
@@ -1188,7 +1519,21 @@ export declare class DocumentOpRefusal extends DocumentOpRefusalBase<{
1188
1519
  message: string;
1189
1520
  reason: DocumentOpRefusalReason;
1190
1521
  opType: DocumentOpType | undefined;
1522
+ /** Paragraph-mark revision that would move text across a standing range boundary. */
1523
+ blockedParagraphMarkRevisionId?: number;
1191
1524
  }> {}
1525
+ /**
1526
+ * What a run of a story's blocks adds to the document's comment anchors, as
1527
+ * {@link commentDocumentIssue} reads them: each anchor's kind and id in
1528
+ * document order, those of the run's own blocks, then those of the text
1529
+ * boxes inside them. A range marker between blocks attaches to a paragraph
1530
+ * beside it, which may lie outside the run, so the sequence also marks which
1531
+ * markers wait for the run's first paragraph and which are held past its
1532
+ * last, or that it has no paragraph. Two runs alike here leave the issue as
1533
+ * it was when one replaces the other in the same story, whatever blocks
1534
+ * surround it.
1535
+ */
1536
+ export declare const commentAnchorSequence: (blocks: readonly BlockContent[]) => string[];
1192
1537
  type CommentExhaustionInput = {
1193
1538
  type: "document";
1194
1539
  document: Document;
@@ -1198,22 +1543,38 @@ type CommentExhaustionInput = {
1198
1543
  anchorKind: Comment["anchorKind"];
1199
1544
  survivingNonCarrierContent: boolean;
1200
1545
  };
1201
- /** Whether a statically ranged comment currently covers no document content. */
1546
+ /** Whether a known range lost its content or a known point lost its anchor. */
1202
1547
  export declare const isCommentExhausted: (input: CommentExhaustionInput) => boolean;
1203
1548
  /** Comment definitions whose root remains covered or projected, with replies. */
1204
1549
  export declare const survivingComments: (document: Document, projectedRootIds?: ReadonlySet<number>) => Comment[];
1205
1550
  /** Remove each supplied root and its recursive replies, preserving input order. */
1206
1551
  export declare const withoutCommentThreads: (comments: readonly Comment[], removedRootIds: ReadonlySet<number>) => Comment[];
1552
+ /**
1553
+ * Root comments without any owned source anchor. Loaded packages may carry
1554
+ * them; they stay preserved as read-only entries rather than refusing the
1555
+ * document, and no comment operation may create or target one.
1556
+ */
1557
+ export declare const orphanRootCommentIds: (document: Document) => Set<number>;
1207
1558
  /**
1208
1559
  * Shared loaded-comment activation contract; legacy parentId revision associations stay explicit.
1209
1560
  * `allowedOrphans` names unanchored root comments the caller accepts ("all" for a loaded package).
1210
1561
  */
1211
1562
  export declare const commentDocumentIssue: (document: Document, allowedOrphans?: ReadonlySet<number> | "all") => string | undefined;
1212
- /** Allocate from the package's annotation domains without a hidden mutable counter. */
1213
- export declare const freshCommentId: (document: Document) => Result<number, DocumentOpRefusal>;
1563
+ /**
1564
+ * Allocate from the package's annotation domains without a hidden mutable
1565
+ * counter: one past every annotation id, the lowest free one once the
1566
+ * highest id is taken, or, for an author holding a lease, the lowest leased
1567
+ * comment id no annotation carries.
1568
+ */
1569
+ export declare const freshCommentId: (document: Document, lease?: IdLease) => Result<number, DocumentOpRefusal>;
1214
1570
  /** Reconcile modeled comment and numbering parts with their document relationships. */
1215
1571
  export declare const reconcileDocumentPartRelationships: (document: Document) => Document;
1216
1572
  type CopyOriginAncestorList = NonNullable<BookmarkEnd["copyOriginAncestors"]>;
1573
+ /**
1574
+ * Whether a copy of `node` carries copy ancestry: true of bookmark and move
1575
+ * range boundaries, false of comment boundaries and anything else.
1576
+ */
1577
+ export declare const recordsCopyOrigin: (node: InlineNode) => boolean;
1217
1578
  export declare const isCopyOriginAncestors: (value: unknown) => value is CopyOriginAncestorList;
1218
1579
  export declare const shiftCopyOriginAncestors: (origins: CopyOriginAncestorList | undefined, insertedOrdinal: number) => CopyOriginAncestorList | undefined;
1219
1580
  export declare const addCopyOriginAncestor: (origins: CopyOriginAncestorList | undefined, addedOrdinal: number) => CopyOriginAncestorList | undefined;
@@ -1225,15 +1586,136 @@ type RejectedCopyOriginAncestors = {
1225
1586
  copyOriginAncestors?: CopyOriginAncestorList;
1226
1587
  };
1227
1588
  export declare const rejectCopyOriginAncestors: (origins: CopyOriginAncestorList | undefined, removedAddedAncestors: number) => RejectedCopyOriginAncestors;
1589
+ /** Tracked insertions, deletions and moves. */
1590
+ type TrackedWrapper = Extract<InlineNode, {
1591
+ type: "insertion" | "deletion" | "moveFrom" | "moveTo";
1592
+ }>;
1593
+ /** The review fields a paragraph states, each only when present. */
1594
+ export declare const reviewFieldsOf: (paragraph: ParagraphReviewFields) => ParagraphReviewFields;
1595
+ type SeamJoins = NonNullable<TrackedWrapper["resolutionJoins"]>;
1596
+ /**
1597
+ * Kept markers a change's joins name in review history version 1: the
1598
+ * revision they were kept from and how many boundaries they are, nearest
1599
+ * the seam (all of those standing there when no count is given).
1600
+ */
1601
+ type VersionOneKeptMarkers = {
1602
+ keptFrom: string;
1603
+ keptCount?: number;
1604
+ };
1605
+ /**
1606
+ * What review history version 1 wrote on a change about kept markers: those
1607
+ * its own joins name (`change`), and those each of its deferred seam groups
1608
+ * names, by the group's place in `deferredRemove`.
1609
+ */
1610
+ type VersionOneKept = {
1611
+ change?: VersionOneKeptMarkers;
1612
+ groups: readonly (VersionOneKeptMarkers | undefined)[];
1613
+ };
1614
+ /** {@link withKeptCutsFromChanges} over a paragraph's content. */
1615
+ export declare const paragraphKeptCutsFromChanges: (content: readonly ParagraphContent[], writtenOnChange: (joins: SeamJoins) => VersionOneKept | undefined) => ParagraphContent[];
1616
+ /**
1617
+ * Whether `cut` is a well-formed kept cut: exactly its fields, kept from a
1618
+ * dated revision, naming one side as its piece if any. The contract and the
1619
+ * review history reader share it.
1620
+ */
1621
+ export declare const isKeptCut: (cut: unknown) => cut is KeptCut;
1622
+ type NoteDeletionOpsOptions = {
1623
+ /** The document before the tracked edit. */
1624
+ before: Document;
1625
+ /** The document the tracked edit left. */
1626
+ after: Document;
1627
+ /** The edit's stamp: the notes whose last live reference it deleted follow it. */
1628
+ stamp: RevisionStamp;
1629
+ /** Ids the note records may take; those `after` holds are passed over. */
1630
+ revisionIds: readonly number[];
1631
+ };
1632
+ /** The operations deleting notes with their references, and the revision ids their records took. */
1633
+ type NoteDeletion = {
1634
+ ops: readonly DocumentOp[];
1635
+ revisions: readonly number[];
1636
+ };
1637
+ /**
1638
+ * The operations deleting the notes whose last live reference, in any
1639
+ * story, a tracked edit deleted: each note's text and paragraph marks,
1640
+ * deleted by the reference deletion's author at its date, as the reference
1641
+ * implementation records it. Rejecting the reference's deletion gives the
1642
+ * note its text back, and accepting it removes the note. A suggestion stays
1643
+ * its author's until it is accepted, so it deletes no note.
1644
+ *
1645
+ * The edit itself leaves the notes alone, so an operation touches only the
1646
+ * paragraphs it names; a compiler emitting the edit appends these.
1647
+ */
1648
+ export declare const noteDeletionOps: ({ before, after, stamp, revisionIds }: NoteDeletionOpsOptions) => Result<NoteDeletion, DocumentOpRefusal>;
1228
1649
  export declare const noteUsesCustomMark: (document: Document, note: Footnote | Endnote) => boolean;
1650
+ type WithParagraphCopiesOptions = {
1651
+ document: Document;
1652
+ story: OpStory;
1653
+ /**
1654
+ * Each paragraph of the story, at any depth or in a text box drawn there,
1655
+ * and the copy that takes its place.
1656
+ */
1657
+ copies: ReadonlyMap<Paragraph, Paragraph>;
1658
+ };
1659
+ /**
1660
+ * `document` with paragraphs of `story`, at any depth, replaced by copies
1661
+ * that hold the same value under every field, in its section views too. A
1662
+ * copy may differ only in what is kept for it outside its fields, which the
1663
+ * contract never reads, so the result meets the contract when `document` is
1664
+ * known to.
1665
+ */
1666
+ export declare const withParagraphCopies: ({ document, story, copies }: WithParagraphCopiesOptions) => Document;
1667
+ type WithParagraphRenderingsOptions = {
1668
+ document: Document;
1669
+ story: OpStory;
1670
+ /**
1671
+ * Each paragraph of the story, at any depth or in a text box drawn there,
1672
+ * and its list rendering normalized.
1673
+ */
1674
+ renderings: ReadonlyMap<Paragraph, Paragraph>;
1675
+ };
1676
+ /**
1677
+ * `document` with paragraphs of `story` replaced by ones whose list rendering
1678
+ * was normalized: each may differ from the paragraph it replaces only in its
1679
+ * list rendering and the formatting fields that rendering derives, which the
1680
+ * contract never reads, so the result meets the contract when `document` is
1681
+ * known to. A rendering depends on where its paragraph stands, so a paragraph
1682
+ * the story holds at more than one place has no one rendering: then the
1683
+ * result is undefined, and the caller replaces the story's blocks by place.
1684
+ */
1685
+ export declare const withParagraphRenderings: ({ document, story, renderings }: WithParagraphRenderingsOptions) => Document | undefined;
1686
+ /** Capture only fields owned by the lifecycle delta; absent values survive JSON as null. */
1687
+ export declare const captureStoryParts: (document: Document, owned: StoryParts) => StoryParts;
1229
1688
  export declare const sectionPropertiesAt: (document: Document, sectionIndex: number) => SectionProperties | undefined;
1230
- export declare const sameStory: (left: OpStory, right: OpStory) => boolean;
1231
- export declare const findStoryBody: (document: Document, story: OpStory) => DocumentBody | undefined;
1232
- export declare const storyBody: (document: Document, story: OpStory) => DocumentBody;
1689
+ /**
1690
+ * A text box's `w:txbxContent`: a story drawn in a paragraph of another
1691
+ * story. Its paragraphs share the package's paragraph id space, so an
1692
+ * operation names them through the story that draws the box (see
1693
+ * `textBoxRouting.ts`); this address exists only while an operation is
1694
+ * applied to the box's own body.
1695
+ */
1696
+ type TextBoxStory = {
1697
+ readonly kind: "textBox";
1698
+ /** The story whose paragraph draws the box. */
1699
+ readonly host: StoryAddress;
1700
+ /** That paragraph's `w14:paraId`. */
1701
+ readonly blockId: string;
1702
+ /** Which of the paragraph's text boxes, in leaf order. */
1703
+ readonly index: number;
1704
+ };
1705
+ /** A package story, or a text box inside one. */
1706
+ type StoryAddress = OpStory | TextBoxStory;
1233
1707
  export declare const documentStories: (document: Document) => OpStory[];
1708
+ /**
1709
+ * Whether `story` lacks the paragraph a story ends with: the one a caret goes
1710
+ * in and a reader shows after a final table. The body, headers, footers and
1711
+ * notes end with one (a table cell already reads the paragraph it implies);
1712
+ * a story that ends in a table or holds no paragraph gains an empty one. A
1713
+ * separator note is left as read.
1714
+ */
1715
+ export declare const storyLacksClosingParagraph: (document: Document, story: OpStory) => boolean;
1234
1716
  type ReplaceStoryBodyOptions = {
1235
1717
  document: Document;
1236
- story: OpStory;
1718
+ story: StoryAddress;
1237
1719
  body: DocumentBody;
1238
1720
  };
1239
1721
  export declare const replaceStoryBody: ({ document, story, body }: ReplaceStoryBodyOptions) => Document;
@@ -1264,11 +1746,46 @@ export declare const storyParagraphs: (body: DocumentBody) => ParagraphLocation[
1264
1746
  * for {@link sectionsInStep} to report.
1265
1747
  */
1266
1748
  export declare const withBodyContent: (body: DocumentBody, content: BlockContent[]) => DocumentBody;
1749
+ /** The paragraph and its physical siblings, within the same body, wrapper or cell. */
1750
+ export declare const locateParagraphInBlockList: (body: DocumentBody, blockId: string) => {
1751
+ paragraph: Paragraph;
1752
+ blocks: readonly BlockContent[];
1753
+ index: number;
1754
+ } | undefined;
1755
+ /**
1756
+ * The content of each text box drawn in `story`, at any depth, a box before
1757
+ * the boxes drawn in it.
1758
+ */
1759
+ export declare const textBoxContentsIn: (document: Document, story: OpStory) => readonly (readonly BlockContent[])[];
1760
+ type CloseTextBoxesOptions = {
1761
+ document: Document;
1762
+ story: OpStory;
1763
+ /** A new empty paragraph, with an id of its own. */
1764
+ closing: () => Paragraph;
1765
+ };
1766
+ /**
1767
+ * `document` with an empty paragraph after the blocks of each text box drawn
1768
+ * in `story`, nested ones included, that end without one: a text box is a
1769
+ * container, and a container ends with a paragraph.
1770
+ */
1771
+ export declare const withTextBoxesClosed: ({ document, story, closing }: CloseTextBoxesOptions) => Document;
1772
+ /** A story's own paragraphs, then those of each text box drawn in it. */
1773
+ export declare const paragraphsThroughTextBoxes: (document: Document, story: OpStory) => ParagraphLocation[];
1774
+ /**
1775
+ * The paragraph `blockId` names in `story` and its physical siblings: one of
1776
+ * the story's own, or one in a text box drawn there.
1777
+ */
1778
+ export declare const locateParagraphThroughTextBoxes: (document: Document, story: OpStory, blockId: string) => ReturnType<typeof locateParagraphInBlockList>;
1779
+ /** The innermost block-level control holding a paragraph, and every paragraph it holds. */
1780
+ export declare const blockControlHolding: (blocks: readonly BlockContent[], blockId: string) => {
1781
+ control: BlockSdt;
1782
+ paragraphs: Paragraph[];
1783
+ } | undefined;
1267
1784
  /**
1268
1785
  * The zero-width items a paragraph can hold, and whether each is content its
1269
1786
  * mark must not take away. None is. A range boundary is a position, not
1270
- * content: a paragraph that goes leaves it where the paragraph was
1271
- * (`paragraphRemains` in `rangeBoundaries.ts`), so it keeps no blank
1787
+ * content: a paragraph that goes hands it to the nearest paragraph that
1788
+ * stays (`paragraphRemains` in `rangeBoundaries.ts`), so it keeps no blank
1272
1789
  * paragraph standing. A comment reference remains one logical offset unit,
1273
1790
  * but moves as an anchor when its paragraph goes. A cached page break and a
1274
1791
  * note's own marker mark nothing a reader placed.
@@ -1304,6 +1821,13 @@ export declare const paragraphContentVerdict: ({ width, zeroWidthItems }: {
1304
1821
  }) => ParagraphContentVerdict;
1305
1822
  /** The number of logical units in a paragraph: its largest valid offset. */
1306
1823
  export declare const paragraphLength: (paragraph: Paragraph) => number;
1824
+ /** A comment reference and the offset of the unit it takes. */
1825
+ type CommentReferenceOffset = {
1826
+ id: number;
1827
+ offset: number;
1828
+ };
1829
+ /** Where each comment reference of a paragraph stands, in document order. */
1830
+ export declare const commentReferenceOffsets: (paragraph: Paragraph) => CommentReferenceOffset[];
1307
1831
  /** The character a unit that is not run text stands for in {@link paragraphLogicalText}. */
1308
1832
  export declare const OBJECT_REPLACEMENT_CHARACTER = "";
1309
1833
  /**
@@ -1313,7 +1837,7 @@ export declare const OBJECT_REPLACEMENT_CHARACTER = "";
1313
1837
  */
1314
1838
  export declare const paragraphLogicalText: (paragraph: Paragraph) => string;
1315
1839
  /** The single structural outcome of resolving a paragraph mark. */
1316
- export declare const paragraphMarkOutcome: ({ follows, holdsContent, markWasAdded, containerStillEndsWithParagraph, followingTableCanReceiveRunIn, holdsContentOnceAccepted, followingBlockCanReceiveRunIn, needsFollowingCommentHost, tableRemovalIsTrackable, removedSectionProperties, precedingSectionOwner, followingHasSectionProperties }: {
1840
+ export declare const paragraphMarkOutcome: ({ follows, holdsContent, markWasAdded, containerStillEndsWithParagraph, followingTableCanReceiveRunIn, holdsContentOnceAccepted, followingBlockCanReceiveRunIn, needsFollowingCommentHost, tableRemovalIsTrackable, emptyInsertedTableBoundary, precededByBlock }: {
1317
1841
  /** `block` is a follower {@link isOpaqueFollower} admits. */
1318
1842
  follows: "paragraph" | "table" | "block" | "nothing";
1319
1843
  /** From {@link paragraphHoldsContent} or the editor's view of the same rule, never re-derived. */
@@ -1338,23 +1862,21 @@ export declare const paragraphMarkOutcome: ({ follows, holdsContent, markWasAdde
1338
1862
  followingBlockCanReceiveRunIn?: boolean;
1339
1863
  needsFollowingCommentHost?: boolean;
1340
1864
  tableRemovalIsTrackable?: boolean;
1341
- removedSectionProperties?: boolean;
1342
- precedingSectionOwner?: "unavailable" | "available" | "same" | "occupied";
1343
- followingHasSectionProperties?: boolean;
1344
- }) => ({
1865
+ /** Only a pending-review boundary proved free of source section/structure blockers. */
1866
+ emptyInsertedTableBoundary?: "unavailable" | "pendingReview";
1867
+ /** Whether a block stays before the paragraph to anchor what its removal leaves. */
1868
+ precededByBlock?: boolean;
1869
+ }) => {
1345
1870
  kind: "join";
1346
- } & SectionTransfer) | ({
1871
+ } | {
1347
1872
  kind: "remove";
1348
- } & SectionTransfer) | ({
1873
+ } | {
1349
1874
  kind: "run-in";
1350
- } & SectionTransfer) | ({
1875
+ } | {
1351
1876
  kind: "keep";
1352
- } & SectionTransfer) | ({
1877
+ } | {
1353
1878
  kind: "refuse";
1354
1879
  reason: "untrackable";
1355
- } & SectionTransfer);
1356
- type SectionTransfer = {
1357
- sectionDestination: "none" | "preceding" | "following";
1358
1880
  };
1359
1881
  declare const BOUNDARY_SIDES: {
1360
1882
  readonly bookmarkStart: {
@@ -1398,19 +1920,10 @@ type CommentAnchor$1 = CommentAnchorCarrier;
1398
1920
  /** A boundary a block list holds between its blocks. */
1399
1921
  type BlockBoundary = Exclude<Boundary, CommentAnchor$1>;
1400
1922
  /**
1401
- * What a paragraph that goes whole leaves where it was: every bookmark and
1402
- * move range boundary it holds, at any depth, as blocks in its place, and its
1403
- * comment anchors for the nearest paragraph that stays to take. When a
1404
- * comment needs that host, every carrier travels there together in source
1405
- * order. A comment with both anchors there becomes a point there, so the
1406
- * comment and its anchor survive the paragraph.
1923
+ * Whether a block-list entry is a range boundary standing between blocks. A
1924
+ * block list holds no comment anchor, so every boundary in it is one of these.
1407
1925
  */
1408
- export declare const paragraphRemains: (content: readonly InlineNode[]) => {
1409
- all: (Boundary | CommentAnchor$1)[];
1410
- blocks: BlockBoundary[];
1411
- comments: CommentAnchor$1[];
1412
- placement: "blocks" | "previous";
1413
- };
1926
+ export declare const isBlockBoundary: (block: BlockContent) => block is BlockBoundary;
1414
1927
  /** One range boundary in document order, as {@link planWellFormedRanges} reads it. */
1415
1928
  type BoundaryOccurrence = {
1416
1929
  /** The marker's element and id: what two copies of one boundary share. */
@@ -1420,6 +1933,18 @@ type BoundaryOccurrence = {
1420
1933
  side: "start" | "end";
1421
1934
  /** Whether a rejection kept it from removed content. */
1422
1935
  kept: boolean;
1936
+ /**
1937
+ * Whether it is a copy an added revision still owns (its
1938
+ * `copyOriginAncestors`): rejecting that revision takes it away, so it is
1939
+ * never the boundary itself.
1940
+ */
1941
+ copied: boolean;
1942
+ /**
1943
+ * Whether its kind records copies in copy ancestry, as bookmark and move
1944
+ * range boundaries do. Comment boundaries record none, so a kept one the
1945
+ * story holds otherwise is taken for a copy.
1946
+ */
1947
+ copiesMarked: boolean;
1423
1948
  /**
1424
1949
  * The date of the revision a kept boundary came from. Of a kept start and
1425
1950
  * end out of order, the one kept from the later revision moves: that edit
@@ -1439,13 +1964,23 @@ type WellFormedRangePlan = {
1439
1964
  };
1440
1965
  /**
1441
1966
  * The one rule that makes every range a rejection kept boundaries of
1442
- * well-formed, for the engine's model and the editor's document alike. A
1443
- * kept copy of a boundary the story still holds is no boundary of its own and
1444
- * goes (of several kept copies, the first stays); then, where such a range's
1445
- * end comes before its start, the half the rejection kept closes on the
1446
- * other: a kept end moves to just after the start, or else a kept start to
1447
- * just before the end. A boundary that was standing never moves, and a range
1448
- * still with more than one start or end is left as it is.
1967
+ * well-formed, for the engine's model and the editor's document alike.
1968
+ *
1969
+ * A bookmark or move range boundary that records copies never goes here,
1970
+ * whatever else the story holds: one without copy ancestry is the boundary
1971
+ * itself, and one with it goes only when its owner is rejected. Dropping
1972
+ * either because another occurrence stands would make the result depend on
1973
+ * which resolution came first, since accepting a copy leaves it standing as
1974
+ * inserting it directly does. A comment boundary records no copies, so a
1975
+ * kept one goes where the story holds it otherwise (of several kept and
1976
+ * nothing else, the first stays).
1977
+ *
1978
+ * A copy an added revision still owns that stands counts for no range's
1979
+ * order. Then, where such a range's end comes before its start, the
1980
+ * half the rejection kept closes on the other: a kept end moves to just
1981
+ * after the start, or else a kept start to just before the end. A boundary
1982
+ * that was standing never moves, and a range still with more than one start
1983
+ * or end is left as it is.
1449
1984
  */
1450
1985
  export declare const planWellFormedRanges: (occurrences: readonly BoundaryOccurrence[]) => WellFormedRangePlan;
1451
1986
  /** Capture own undefined fields before an operation enters its JSON journal. */
@@ -1484,7 +2019,23 @@ type AppliedDocumentOp = {
1484
2019
  * folded or continued review are excluded; a direct operation reports none.
1485
2020
  */
1486
2021
  revisions: readonly number[];
2022
+ /**
2023
+ * Existing revision ids whose pending property changes the operation
2024
+ * folded its edit into, in document order: the changes now carry its
2025
+ * stamp and record the properties it set, so accepting or rejecting one
2026
+ * of them accepts or rejects the edit too. Disjoint from `revisions`; a
2027
+ * direct operation reports none.
2028
+ */
2029
+ folded: readonly number[];
1487
2030
  };
2031
+ /** The revision ids a tracked operation's records carry. */
2032
+ type RecordedRevisionIds = Pick<AppliedDocumentOp, "revisions" | "folded">;
2033
+ /**
2034
+ * The revision ids of operations applied in turn, as one operation's: every
2035
+ * step's new ids, and the existing ids a step folded into that no step of
2036
+ * them allocated.
2037
+ */
2038
+ export declare const combineRecordedRevisions: (steps: readonly RecordedRevisionIds[]) => RecordedRevisionIds;
1488
2039
  /** Apply one operation to a document that meets the seed contract. */
1489
2040
  export declare const applyDocumentOp: (document: Document, input: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1490
2041
  /** Apply a journal envelope only when its schema matches this reader. */
@@ -1492,6 +2043,18 @@ export declare const applyDocumentOpEnvelope: (document: Document, envelope: {
1492
2043
  schema: number;
1493
2044
  op: DocumentOp;
1494
2045
  }) => Result<AppliedDocumentOp, DocumentOpRefusal>;
2046
+ /**
2047
+ * An inverse whose whole-part restores expect the parts they meet when the
2048
+ * inverse runs, in order, on `document`.
2049
+ *
2050
+ * A restore records the parts its operation left, and refuses as stale when
2051
+ * the document it meets holds other ones. A caller that changes the document
2052
+ * after an operation (a derivation over the whole document, such as list
2053
+ * rendering) and puts its own inverse first rebases the restores onto that
2054
+ * document, so undo meets exactly what each restore expects. The inverse is
2055
+ * returned as it is when it holds no restore, or when it does not apply.
2056
+ */
2057
+ export declare const inverseMeetingDocument: (document: Document, inverse: readonly DocumentOp[]) => readonly DocumentOp[];
1495
2058
  /**
1496
2059
  * Apply operations in order, atomically: the first refusal is returned and
1497
2060
  * the document is unchanged. The inverse undoes the whole list, and
@@ -1517,6 +2080,8 @@ type HyperlinkEditorIntent = {
1517
2080
  href: string;
1518
2081
  tooltip?: string;
1519
2082
  };
2083
+ /** Accepted-view text without changing the canonical paragraph or its offset space. */
2084
+ export declare const paragraphVisibleText: (paragraph: Paragraph) => string;
1520
2085
  type SplitParagraphIntent = {
1521
2086
  type: "splitParagraph";
1522
2087
  at: TextPosition;
@@ -1536,31 +2101,64 @@ type SplitParagraphIntent = {
1536
2101
  type TableRowIntentOperation = Omit<InsertRowOp, "revision" | "newIds"> | Omit<DeleteRowOp, "revision" | "newIds">;
1537
2102
  /**
1538
2103
  * A table inserted after the paragraph `blockId`, with an empty paragraph
1539
- * after it, as the editor inserts one; or the table holding `blockId`,
2104
+ * after it, as the editor inserts one, or between the blocks beside that
2105
+ * paragraph alone; or the table holding `blockId`,
1540
2106
  * removed, or in suggesting mode recorded as deleted. An inserted table's
1541
2107
  * paragraphs take fresh identities from the compiler.
1542
2108
  */
1543
- type TableBlockIntentOperation = Omit<DeleteTableOp, "revision" | "newIds" | "expected"> | {
2109
+ type TableBlockIntentOperation = Omit<DeleteTableOp, "revision" | "newIds" | "expected"> | ({
1544
2110
  type: typeof DOCUMENT_OP_TYPES.INSERT_TABLE;
1545
2111
  story: OpStory;
1546
2112
  blockId: string;
1547
2113
  table: Table;
1548
2114
  /**
1549
- * Where the table goes against the anchor paragraph: after it (the
2115
+ * Where the table goes against the anchor: after it (the
1550
2116
  * default, as from a caret), or before it, as from a selection of the
1551
2117
  * whole story, which the editor fills at the story's start.
1552
2118
  */
1553
2119
  side?: "after" | "before";
2120
+ } & ({
2121
+ /** Existing callers default to a paragraph anchor. */
2122
+ anchor?: "paragraph";
1554
2123
  /**
1555
2124
  * An empty paragraph ahead of the table as well, as the editor writes
1556
2125
  * a table it inserts after another, so the two never touch.
1557
2126
  */
1558
2127
  separated?: boolean;
1559
- };
2128
+ /**
2129
+ * The empty paragraph after the table: written, as the editor gives
2130
+ * the caret a place after a table it inserts (the default), or left
2131
+ * out, for a table that goes between blocks already standing on both
2132
+ * sides of it.
2133
+ */
2134
+ paragraphAfter?: "empty" | "none";
2135
+ } | {
2136
+ /** Beside the innermost table holding blockId, without added paragraphs. */
2137
+ anchor: "table";
2138
+ separated?: never;
2139
+ paragraphAfter?: never;
2140
+ } | {
2141
+ /**
2142
+ * Before the first block of the block list holding blockId, without
2143
+ * added paragraphs: where no paragraph or table names the place.
2144
+ */
2145
+ anchor: "containerStart";
2146
+ side?: never;
2147
+ separated?: never;
2148
+ paragraphAfter?: never;
2149
+ }));
1560
2150
  /** Positions use canonical physical offsets, including retained deleted content. */
1561
2151
  type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
1562
2152
  type: "table";
1563
2153
  operation: TableIntentOperation;
2154
+ /**
2155
+ * What each cell an inserted column creates holds, in row order: the
2156
+ * compiler writes it into the new cells after the column, as text
2157
+ * typed there, so a suggestion records it as inserted. A cell past
2158
+ * the list, or given no paragraphs, stays empty. Only a column
2159
+ * insertion takes it.
2160
+ */
2161
+ cellContent?: readonly (readonly Paragraph[])[];
1564
2162
  } | {
1565
2163
  type: "tableRow";
1566
2164
  operation: TableRowIntentOperation;
@@ -1569,13 +2167,13 @@ type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
1569
2167
  operation: TableBlockIntentOperation;
1570
2168
  } | {
1571
2169
  /**
1572
- * Whole paragraphs beside a paragraph, which keeps its identity: the
1573
- * compiler gives each a fresh id, and a suggestion records each as
1574
- * inserted.
2170
+ * Whole paragraphs beside a paragraph or table: the compiler gives
2171
+ * each a fresh id, and a suggestion records each as inserted. Table-side
2172
+ * suggestions refuse boundaries without a reversible review plan.
1575
2173
  */
1576
2174
  type: "insertParagraphs";
1577
2175
  story: OpStory;
1578
- at: BlockInsertionPoint;
2176
+ at: TableInsertionPoint;
1579
2177
  paragraphs: readonly Paragraph[];
1580
2178
  /** A suggestion records the paragraphs as a move's destination. */
1581
2179
  move?: true;
@@ -1588,6 +2186,13 @@ type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
1588
2186
  blockIds: readonly string[];
1589
2187
  /** A suggestion records the paragraphs as a move's source. */
1590
2188
  move?: true;
2189
+ /**
2190
+ * Tracked, what the deletion does with the paragraphs a pending join
2191
+ * runs into the first one (`paragraphsJoinedInto`), read as the
2192
+ * document stands when it compiles: `deleted`, they go with it, as the
2193
+ * joined paragraph they make carries its id.
2194
+ */
2195
+ joinedWords?: "deleted";
1591
2196
  } | {
1592
2197
  type: "replaceFragment";
1593
2198
  from: TextPosition;
@@ -1608,6 +2213,13 @@ type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
1608
2213
  from: TextPosition;
1609
2214
  to: TextPosition;
1610
2215
  text: string;
2216
+ /** Where each piece of the inserted text takes its authored formatting. */
2217
+ formattingSources?: readonly {
2218
+ /** Exclusive UTF-16 offset in `text`, with contiguous pieces. */
2219
+ end: number;
2220
+ at: TextPosition;
2221
+ type: "character" | "caret";
2222
+ }[];
1611
2223
  runProps?: TextFormatting;
1612
2224
  runPropsPatch?: RunPropsPatch;
1613
2225
  /**
@@ -1673,6 +2285,8 @@ type NewListInstance = {
1673
2285
  type EditorIntentMode = {
1674
2286
  /** Identities consumed during this editor lifetime, including undone insertions. */
1675
2287
  reservedBlockIds?: ReadonlySet<string>;
2288
+ /** The only ids the compiler may mint, when the author holds a lease. */
2289
+ idLease?: IdLease;
1676
2290
  } & ({
1677
2291
  type: "editing";
1678
2292
  newIds?: NewIds;
@@ -1681,9 +2295,23 @@ type EditorIntentMode = {
1681
2295
  revision: RevisionStamp;
1682
2296
  newIds: NewIds;
1683
2297
  });
2298
+ /**
2299
+ * Where text an intent adds takes its formatting from: the caret's, as typing
2300
+ * continues the run it stands in, or the body text's, as an operation's text
2301
+ * is body text and never continues a note reference.
2302
+ */
2303
+ export declare const TYPED_TEXT_FORMATTING: Readonly<{
2304
+ readonly CARET: "caret";
2305
+ readonly BODY_TEXT: "bodyText";
2306
+ }>;
2307
+ type TypedTextFormatting = (typeof TYPED_TEXT_FORMATTING)[keyof typeof TYPED_TEXT_FORMATTING];
1684
2308
  type CompileEditorIntentOptions = {
1685
2309
  intent: EditorIntent;
1686
2310
  mode: EditorIntentMode;
2311
+ /** By default the caret's. */
2312
+ typedFormatting?: TypedTextFormatting;
2313
+ /** Source before this operation's other replacement pieces are compiled. */
2314
+ replacementFormattingDocument?: Document;
1687
2315
  /** Lowest candidate for compiler-owned pasted block IDs, including retired session IDs. */
1688
2316
  firstBlockId?: number;
1689
2317
  };
@@ -1705,7 +2333,7 @@ type EditorIntentAllocation = EditorIntent | SplitParagraphIntent;
1705
2333
  */
1706
2334
  export declare const createEditorIntentIdAllocator: ({ reservedBlockIds }?: {
1707
2335
  reservedBlockIds?: ReadonlySet<string>;
1708
- }) => (document: Document, intent: EditorIntentAllocation) => {
2336
+ }) => (document: Document, requested: EditorIntentAllocation, lease?: IdLease) => {
1709
2337
  revisionId: number;
1710
2338
  newBlockId: string;
1711
2339
  newIds: {
@@ -1713,8 +2341,6 @@ export declare const createEditorIntentIdAllocator: ({ reservedBlockIds }?: {
1713
2341
  control: number[];
1714
2342
  };
1715
2343
  };
1716
- /** Accepted-view text without changing the canonical paragraph or its offset space. */
1717
- export declare const paragraphVisibleText: (paragraph: Paragraph) => string;
1718
2344
  /**
1719
2345
  * Right-affine translation: a visible gap follows retained deleted content at
1720
2346
  * that gap, so a new insertion never lands inside a deletion wrapper.
@@ -1727,12 +2353,70 @@ export declare const editorParagraphGroups: (document: Document, story: OpStory)
1727
2353
  paragraphs: Paragraph[];
1728
2354
  text: string;
1729
2355
  }[];
2356
+ /**
2357
+ * {@link editorParagraphGroups} of `story` and of every text box drawn in it,
2358
+ * each box grouped within its own story: a box's paragraphs are named
2359
+ * through the story drawing it, and a mark pending deletion in a box joins
2360
+ * the box's next paragraph.
2361
+ */
2362
+ export declare const editorParagraphGroupsThroughTextBoxes: (document: Document, story: OpStory) => ReturnType<typeof editorParagraphGroups>;
1730
2363
  /** One logical paragraph and visible offset for a physical canonical address. */
1731
2364
  export declare const editorPositionAtPhysicalPosition: (document: Document, at: TextPosition) => TextPosition;
1732
2365
  /** Translate an editing-view paragraph gap to its physical canonical address. */
1733
2366
  export declare const physicalPositionAtEditorOffset: (document: Document, at: TextPosition) => TextPosition;
2367
+ type JoinPropertyChangeLinkOptions = {
2368
+ /** The document before the operation that joined the paragraphs. */
2369
+ before: Document;
2370
+ /** The document after it. */
2371
+ after: Document;
2372
+ story: OpStory;
2373
+ /** The paragraph whose mark the join deletes. */
2374
+ blockId: string;
2375
+ /** The paragraph the operation set the joined properties on. */
2376
+ propertiesBlockId: string;
2377
+ };
2378
+ /**
2379
+ * The review op that makes the property change an operation left on the
2380
+ * paragraph its tracked join keeps belong to the paragraph-mark deletion the
2381
+ * operation recorded, so accepting or rejecting the join decides both.
2382
+ * `undefined` when the operation recorded no mark deletion (a mark already
2383
+ * pending deletion, an own added mark taken back), the paragraph holds no
2384
+ * change the operation made, or the change already belongs to a revision.
2385
+ */
2386
+ export declare const joinPropertyChangeLink: ({ before, after, story, blockId, propertiesBlockId }: JoinPropertyChangeLinkOptions) => SetParagraphReviewOp | undefined;
1734
2387
  /** Compile one batch; the caller applies it atomically and journals its exact inverse. */
1735
- export declare const compileEditorIntent: (document: Document, { intent, mode, firstBlockId }: CompileEditorIntentOptions) => Result<CompiledEditorIntent, DocumentOpRefusal>;
2388
+ export declare const compileEditorIntent: (document: Document, input: CompileEditorIntentOptions) => Result<CompiledEditorIntent, DocumentOpRefusal>;
2389
+ type InsertParagraphsIntent = Extract<EditorIntent, {
2390
+ type: "insertParagraphs";
2391
+ }>;
2392
+ type TrackedBatchOptions = {
2393
+ document: Document;
2394
+ count: number;
2395
+ reservedBlockIds?: ReadonlySet<string>;
2396
+ };
2397
+ type TrackedMemberOptions = {
2398
+ index: number;
2399
+ intent: InsertParagraphsIntent;
2400
+ mode: EditorIntentMode;
2401
+ };
2402
+ type TrackedInsertionCompilation = {
2403
+ type: "unsupported";
2404
+ } | {
2405
+ type: "operation";
2406
+ op: InsertBlocksOp;
2407
+ };
2408
+ type TrackedInsertionCompiler = {
2409
+ type: "unsupported";
2410
+ } | {
2411
+ type: "ready";
2412
+ compile: (options: TrackedMemberOptions) => Result<TrackedInsertionCompilation, DocumentOpRefusal>;
2413
+ };
2414
+ /**
2415
+ * Reserve the selection of fresh paragraph IDs for a private monotone run.
2416
+ * The caller uses each index once, in order, and discards the whole run if
2417
+ * any step fails or changes the original class of operations.
2418
+ */
2419
+ export declare const beginTrackedInsertionCompilation: ({ document, count, reservedBlockIds }: TrackedBatchOptions) => TrackedInsertionCompiler;
1736
2420
  type TocHeading = {
1737
2421
  blockId: string;
1738
2422
  text: string;
@@ -1756,12 +2440,89 @@ type PackageResourcesOpOptions = {
1756
2440
  };
1757
2441
  /** Describe the package resource difference as one operation carrying only changed entries. */
1758
2442
  export declare const packageResourcesOpOf: ({ before, after }: PackageResourcesOpOptions) => SetPackageResourcesOp;
2443
+ type MemberEffect = DocumentEditEffects & RecordedRevisionIds & {
2444
+ op: InsertBlocksOp;
2445
+ };
2446
+ type FallbackReason = "compiler" | "sourceShape" | "sectionView" | "memberShape" | "effectShape" | "wideSpan" | "materialization";
2447
+ type TrackedInsertionGroupResult = {
2448
+ type: "fallback";
2449
+ reason: FallbackReason;
2450
+ } | {
2451
+ type: "fallback";
2452
+ reason: "refusal";
2453
+ index: number;
2454
+ refusal: DocumentOpRefusal;
2455
+ } | {
2456
+ type: "materialized";
2457
+ document: Document;
2458
+ members: readonly MemberEffect[];
2459
+ };
2460
+ type NextMember = {
2461
+ type: "member";
2462
+ op: InsertBlocksOp;
2463
+ } | {
2464
+ type: "done";
2465
+ } | {
2466
+ type: "fallback";
2467
+ };
2468
+ type TrackedInsertionGroupOptions = {
2469
+ document: Document;
2470
+ next: (previousRevisions: readonly number[] | undefined) => NextMember;
2471
+ };
2472
+ /**
2473
+ * Attempt a precompiled journal run at one physical main-story anchor. The
2474
+ * prepared members see all prior ids and the real current source/follower.
2475
+ * Publish a document and journal effects only when the whole group succeeds.
2476
+ * Keep the source document and all emitted operations immutable during the
2477
+ * synchronous compiler callback. The caller owns its journal copies.
2478
+ */
2479
+ export declare const tryTrackedInsertionGroup: ({ document, next }: TrackedInsertionGroupOptions) => TrackedInsertionGroupResult;
2480
+ type SectionRejectPropertiesOptions = {
2481
+ live: SectionProperties;
2482
+ previousProperties: SectionProperties | undefined;
2483
+ previousReferences?: SectionPropertyChange["previousReferences"];
2484
+ };
2485
+ /**
2486
+ * Rejected section properties: the stored old sectPr wholesale, preserving
2487
+ * the live header/footer references — `EG_HdrFtrReferences` is not part of
2488
+ * the `CT_SectPrBase` payload a `w:sectPrChange` stores (ECMA-376
2489
+ * §17.13.5.32), so those children survive a native reject. An explicit
2490
+ * reference history replaces that selection, including restoring its
2491
+ * absence. The caller re-attaches whatever `propertyChanges` remain
2492
+ * unresolved.
2493
+ */
2494
+ export declare const sectionRejectProperties: ({ live, previousProperties, previousReferences }: SectionRejectPropertiesOptions) => SectionProperties;
2495
+ type ResolveSectionChangeOptions = {
2496
+ current: SectionProperties;
2497
+ decision: RevisionDecision;
2498
+ id: number;
2499
+ };
2500
+ /**
2501
+ * `current` with its change `id` resolved, the changes after it rebased onto
2502
+ * what that resolution leaves; `null` when no change of `current` is `id`.
2503
+ */
2504
+ export declare const resolveSectionChange: ({ current, decision, id }: ResolveSectionChangeOptions) => SectionProperties | null;
2505
+ /** `current` with its whole change history resolved; `null` when it has none. */
2506
+ export declare const resolveSectionChanges: (current: SectionProperties, decision: RevisionDecision) => SectionProperties | null;
2507
+ type SectionResolutionPatchOptions = {
2508
+ current: SectionProperties;
2509
+ next: SectionProperties;
2510
+ };
2511
+ /** The patch from `current` to `next`: explicit nulls remove what `next` no longer carries. */
2512
+ export declare const sectionResolutionPatch: ({ current, next }: SectionResolutionPatchOptions) => FormattingPatch<SectionProperties>;
1759
2513
  type RegisterParagraphPropertySnapshotOptions = {
1760
- paragraph: Paragraph;
2514
+ /** A paragraph, or review fields an operation gives one. */
2515
+ paragraph: Pick<Paragraph, "formatting">;
1761
2516
  snapshot: ParagraphFormatting | undefined;
1762
2517
  };
1763
2518
  /** Bind effective formatting to the authored properties a review must record. */
1764
2519
  export declare const registerParagraphPropertySnapshot: ({ paragraph, snapshot }: RegisterParagraphPropertySnapshotOptions) => void;
2520
+ /**
2521
+ * Register `paragraph`'s formatting as exactly what it states, as a rejected
2522
+ * property change restores the recorded properties: no list level or style
2523
+ * projects a value onto it.
2524
+ */
2525
+ export declare const registerStatedParagraphFormatting: (paragraph: Pick<Paragraph, "formatting">) => void;
1765
2526
  /**
1766
2527
  * The registration a paragraph's snapshot stands on, as an opaque token: the
1767
2528
  * same object while nothing registers or transfers another one for it. A pass
@@ -1769,6 +2530,18 @@ export declare const registerParagraphPropertySnapshot: ({ paragraph, snapshot }
1769
2530
  * change nothing.
1770
2531
  */
1771
2532
  export declare const paragraphPropertySnapshotToken: (paragraph: Paragraph) => object | undefined;
2533
+ type TransferParagraphPropertySnapshotOptions = {
2534
+ source: object;
2535
+ target: object;
2536
+ };
2537
+ /** Retain paragraph-owned snapshot bindings through sanctioned model copies. */
2538
+ export declare const transferParagraphPropertySnapshot: ({ source, target }: TransferParagraphPropertySnapshotOptions) => void;
2539
+ /**
2540
+ * Whether `paragraph`'s formatting is still the formatting an edit registered
2541
+ * as stated. A projector that infers stated properties from the effective
2542
+ * ones it projected before keeps every value such formatting holds.
2543
+ */
2544
+ export declare const paragraphStatesItsFormatting: (paragraph: Pick<Paragraph, "formatting">) => boolean;
1772
2545
  /**
1773
2546
  * Every `TextFormatting` field, named so the comparison below is total.
1774
2547
  *
@@ -1784,7 +2557,7 @@ type ComparedTextFormatting = ExhaustiveFields<TextFormatting, ComparedTextForma
1784
2557
  * Uses deep comparison of all properties to determine if runs
1785
2558
  * can be merged without losing formatting information.
1786
2559
  */
1787
- export declare function formattingEquals(a: ComparedTextFormatting | undefined, b: ComparedTextFormatting | undefined): boolean;
2560
+ export declare function formattingEquals(a: DeepReadonly<ComparedTextFormatting> | undefined, b: DeepReadonly<ComparedTextFormatting> | undefined): boolean;
1788
2561
  /**
1789
2562
  * Check if a run contains only text content
1790
2563
  * (runs with special content like images, fields, etc. should not be merged)
@@ -1828,18 +2601,10 @@ export declare const validateOpsDocument: (document: Document) => Result<Documen
1828
2601
  * removed, and its section view derived again. Nothing else changes.
1829
2602
  */
1830
2603
  export declare const normalizeForOps: (document: Document) => Document;
1831
- /** Every `paraId` of every paragraph in a value, nested ones included, in document order. */
1832
- export declare const paragraphIdsIn: (value: unknown) => string[];
1833
- /** Every paragraph id of a package, each story walked once. */
1834
- export declare const packageParagraphIds: (pkg: DocxPackage) => string[];
1835
- /**
1836
- * The key two spellings of one id share. `ST_LongHexNumber` is hex, so
1837
- * `0000abcd` and `0000ABCD` are the same id; every lookup and comparison of
1838
- * paragraph ids goes through this.
1839
- */
1840
- export declare const idKey: (id: string) => string;
2604
+ /** The author of an edit and, for a pending suggestion, the suggestion it belongs to. */
2605
+ type RevisionOwner = Pick<RevisionStamp, "author" | "suggestionId">;
1841
2606
  /** Package-aware explicit pools for every semantic comment anchor cut, including replies. */
1842
- export declare const allocateCommentAnchorIds: (document: Document, op: CreateCommentOp) => Result<NewIds, DocumentOpRefusal>;
2607
+ export declare const allocateCommentAnchorIds: (document: Document, op: CreateCommentOp, lease?: IdLease) => Result<NewIds, DocumentOpRefusal>;
1843
2608
  /**
1844
2609
  * How many `newIds.revision` entries an operation takes on a document,
1845
2610
  * besides its stamp's id: the length of the shortest list of unused ids it
@@ -1883,11 +2648,7 @@ type PlanTrackedReplaceOptions = PlanTrackedDeletionOptions & {
1883
2648
  tail: InlineSlice;
1884
2649
  };
1885
2650
  };
1886
- /**
1887
- * Plan a tracked replacement of a same-list range: the range's tracked
1888
- * deletion followed by the replacement fragment as tracked insertions.
1889
- * All physical revision ids come from one pool for the complete batch.
1890
- */
2651
+ /** Plan a same-list range deletion followed by tracked replacement insertions. */
1891
2652
  export declare const planTrackedReplace: (document: Document, options: PlanTrackedReplaceOptions) => Result<DocumentOp[], DocumentOpRefusal>;
1892
2653
  /** A batch applies atomically, in array order, against its stated revision. */
1893
2654
  type DocumentBatch = {
@@ -1908,9 +2669,55 @@ type SequencedOpEffect = {
1908
2669
  } | {
1909
2670
  type: "joinBlocks";
1910
2671
  firstLength: number;
2672
+ } | {
2673
+ type: "insertContent";
2674
+ /**
2675
+ * Whether the insertion cut a record carrying an id (a revision or a
2676
+ * content control) in two, its second half taking a new id.
2677
+ */
2678
+ cutIdentified: boolean;
2679
+ } | {
2680
+ type: "deleteRange";
2681
+ /**
2682
+ * A direct deletion whose range held its note's own reference mark,
2683
+ * which it keeps: the gap before the mark. A point after the mark that
2684
+ * the deletion closes up to its start lands after the mark.
2685
+ */
2686
+ keptMark?: Gap;
2687
+ } | {
2688
+ type: "setRunProps";
2689
+ /**
2690
+ * The records a direct format cut at both of its ends, outermost
2691
+ * first, by the gaps before their first leaf and after their last one
2692
+ * before the format: a run, and the text the range lay inside. Where
2693
+ * a concurrent deletion holds the format's range and reaches past
2694
+ * neither end of such a record, the deletion keeps it one record. In a
2695
+ * note, `keptMark` is the gap before the note's own reference mark a
2696
+ * record holds, which a direct deletion keeps as well.
2697
+ */
2698
+ cutRecords?: readonly {
2699
+ from: Gap;
2700
+ to: Gap;
2701
+ keptMark?: Gap;
2702
+ }[];
1911
2703
  } | {
1912
2704
  type: "touchedBlocks";
2705
+ /** Paragraphs the operation changed, inserted or removed. */
1913
2706
  blockIds: readonly string[];
2707
+ /**
2708
+ * For a table structure edit, every paragraph of the table before and
2709
+ * after it: another structure edit of that table conflicts with it.
2710
+ */
2711
+ tableBlockIds?: readonly string[];
2712
+ /**
2713
+ * For a comment operation, the comments it added, removed or changed,
2714
+ * replies of a deleted thread among them, and whether it removed a
2715
+ * package relationship of the comment parts.
2716
+ */
2717
+ comments?: {
2718
+ ids: readonly number[];
2719
+ relationshipRemoved: boolean;
2720
+ };
1914
2721
  } | {
1915
2722
  type: typeof NO_SEQUENCED_EFFECT;
1916
2723
  };
@@ -1925,9 +2732,35 @@ export declare const BATCH_REJECTION_REASONS: {
1925
2732
  readonly CONFLICT: "conflict";
1926
2733
  readonly STALE_BASE: "staleBase";
1927
2734
  readonly INVALID_OPERATION: "invalidOperation";
2735
+ /** A concurrent operation restructured the table this one restructures. */
1928
2736
  readonly TABLE_REQUIRES_EXCLUSIVE_EDIT: "tableRequiresExclusiveEdit";
2737
+ /** A concurrent operation changed a paragraph this one addresses. */
2738
+ readonly BLOCK_CONFLICT: "blockConflict";
2739
+ /** A concurrent operation wrote a package part this one uses (`part`). */
2740
+ readonly PART_CONFLICT: "partConflict";
2741
+ /** The batch introduces an id its actor does not lease. */
2742
+ readonly OUTSIDE_ID_LEASE: "outsideIdLease";
1929
2743
  };
1930
2744
  type BatchRejectionReason = (typeof BATCH_REJECTION_REASONS)[keyof typeof BATCH_REJECTION_REASONS];
2745
+ /**
2746
+ * Package parts an operation reads or writes besides the paragraphs it
2747
+ * addresses. Concurrent operations conflict on a part when one writes it and
2748
+ * both name the same entry, or one names the whole part.
2749
+ */
2750
+ export declare const EXCLUSIVE_PARTS: Readonly<{
2751
+ readonly NUMBERING: "numbering";
2752
+ readonly STYLES: "styles";
2753
+ readonly RELATIONSHIPS: "relationships";
2754
+ readonly MEDIA: "media";
2755
+ readonly SECTIONS: "sections";
2756
+ readonly HEADERS_FOOTERS: "headersFooters";
2757
+ readonly NOTES: "notes";
2758
+ readonly SETTINGS: "settings";
2759
+ readonly REVISIONS: "revisions";
2760
+ readonly COMMENTS: "comments";
2761
+ }>;
2762
+ /** One of {@link EXCLUSIVE_PARTS}. */
2763
+ type ExclusivePart = (typeof EXCLUSIVE_PARTS)[keyof typeof EXCLUSIVE_PARTS];
1931
2764
  declare const BatchRejectionBase: TaggedErrorClass<"BatchRejection">;
1932
2765
  export declare class BatchRejection extends BatchRejectionBase<{
1933
2766
  message: string;
@@ -1935,6 +2768,10 @@ export declare class BatchRejection extends BatchRejectionBase<{
1935
2768
  opId?: string;
1936
2769
  opType?: DocumentOpType;
1937
2770
  overType?: DocumentOpType;
2771
+ /** The kind of the id an out-of-lease batch introduces. */
2772
+ idKind?: IdLeaseKind;
2773
+ /** The package part a part conflict names. */
2774
+ part?: ExclusivePart;
1938
2775
  }> {}
1939
2776
  export declare const BATCH_WIRE_OP_TYPES: readonly string[];
1940
2777
  /** Bound recursion and refuse values except JSON data and absent object fields. */
@@ -1950,6 +2787,57 @@ type TransformOptions = {
1950
2787
  };
1951
2788
  /** Rebase an atomic batch over an ordered journal tail. */
1952
2789
  export declare const transformBatch: (batch: DocumentBatch, over: readonly SequencedBatch[], options?: TransformOptions) => Result<DocumentBatch, BatchRejection>;
2790
+ /**
2791
+ * Where a position lands after an ordered journal tail, by paragraph identity
2792
+ * and offset, never by an editor's own coordinates. At a foreign insertion's
2793
+ * or split's own offset, `before` keeps the position ahead of what was
2794
+ * inserted and `after` moves it past. Undefined when the tail removes the
2795
+ * position's paragraph or changes it in a way an offset cannot follow.
2796
+ */
2797
+ export declare const transformPosition: (position: TextPosition, over: readonly SequencedBatch[], affinity?: "before" | "after") => TextPosition | undefined;
2798
+ type AppliedBatch = {
2799
+ document: Document;
2800
+ inverse: readonly DocumentOp[];
2801
+ effects: NonNullable<SequencedBatch["effects"]>;
2802
+ };
2803
+ /** Capture position facts before each operation, including within an atomic batch. */
2804
+ export declare const applyBatch: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedBatch, DocumentOpRefusal>;
2805
+ /** How many ids one grant or renewal leases, per kind. */
2806
+ export declare const DEFAULT_ID_BLOCK_SIZES: Readonly<Record<IdLeaseKind, number>>;
2807
+ /** One block leased to one actor. */
2808
+ type IdLeaseGrant = {
2809
+ readonly actor: string;
2810
+ readonly block: IdBlock;
2811
+ };
2812
+ /** The highest id of a kind one actor's sequenced batches introduced. */
2813
+ type IdLeaseMinted = {
2814
+ readonly actor: string;
2815
+ readonly kind: IdLeaseKind;
2816
+ readonly highest: number;
2817
+ };
2818
+ /**
2819
+ * A room's lease table, part of its sequenced state: kept with the journal
2820
+ * and given back to a restarted sequencer, so each actor keeps its blocks.
2821
+ */
2822
+ type IdLeaseState = {
2823
+ readonly blockSizes: Readonly<Record<IdLeaseKind, number>>;
2824
+ /** Every block granted, in grant order. */
2825
+ readonly grants: readonly IdLeaseGrant[];
2826
+ readonly minted: readonly IdLeaseMinted[];
2827
+ };
2828
+ export declare const ID_LEASE_REFUSAL_REASONS: Readonly<{
2829
+ readonly EXHAUSTED: "exhausted";
2830
+ readonly NOT_DUE: "notDue";
2831
+ readonly INVALID_STATE: "invalidState";
2832
+ readonly UNAVAILABLE: "unavailable";
2833
+ }>;
2834
+ type IdLeaseRefusalReason = (typeof ID_LEASE_REFUSAL_REASONS)[keyof typeof ID_LEASE_REFUSAL_REASONS];
2835
+ declare const IdLeaseRefusalBase: TaggedErrorClass<"IdLeaseRefusal">;
2836
+ export declare class IdLeaseRefusal extends IdLeaseRefusalBase<{
2837
+ message: string;
2838
+ reason: IdLeaseRefusalReason;
2839
+ kind?: IdLeaseKind;
2840
+ }> {}
1953
2841
  type BatchAck = {
1954
2842
  type: "ack";
1955
2843
  opId: string;
@@ -1962,30 +2850,73 @@ type BatchReject = {
1962
2850
  headRev: number;
1963
2851
  };
1964
2852
  type BatchSubmission = BatchAck | BatchReject;
1965
- /** Deterministic append-only authority; the caller supplies delivery and storage. */
1966
- export declare const createSequencer: (document: Document) => {
2853
+ type SequencerOptions = {
2854
+ /** The room's lease table, as `idLeases` gave it before a restart. */
2855
+ idLeases?: IdLeaseState;
2856
+ };
2857
+ /**
2858
+ * Deterministic append-only authority; the caller supplies delivery and
2859
+ * storage. Every actor mints fresh ids only from the blocks the sequencer
2860
+ * leases it, and a batch introducing an id outside its actor's lease is
2861
+ * rejected, so concurrent actors never mint the same id.
2862
+ */
2863
+ export declare const createSequencer: (document: Document, options?: SequencerOptions) => {
1967
2864
  submit: (batch: DocumentBatch) => BatchSubmission;
2865
+ /** The actor's remaining lease; the first call grants one block per kind. */
2866
+ grantIdLease: (actor: string) => Result<IdLease, IdLeaseRefusal>;
2867
+ /** One more block of `kind` for an actor running low. */
2868
+ renewIdLease: (actor: string, kind: IdLeaseKind) => Result<IdBlock, IdLeaseRefusal>;
1968
2869
  readonly document: Document;
1969
2870
  readonly headRev: number;
1970
2871
  readonly broadcasts: readonly SequencedBatch[];
2872
+ /** The lease table to persist with the journal. */
2873
+ readonly idLeases: IdLeaseState;
1971
2874
  };
1972
2875
  type ClientNotice = {
1973
2876
  opId: string;
1974
2877
  reason: BatchRejection;
1975
2878
  ops: readonly DocumentOp[];
1976
2879
  };
2880
+ /**
2881
+ * How the optimistic `document` moved when the authority answered: applied in
2882
+ * order to the document before the answer, `batch.ops` give the one after it.
2883
+ * `rebased`: a foreign revision rebased over every pending local batch, or a
2884
+ * refused local batch's inverse rebased over the ones after it, so positions
2885
+ * and history can be transformed over it. `replaced`: a pending batch could not
2886
+ * be rebased, or the rebased change would not reach the replayed document, so
2887
+ * the change undoes every pending batch, applies what the authority sequenced
2888
+ * and replays the survivors; only the document is exact. When every pending
2889
+ * batch survived and the rebased change reaches a document with the same
2890
+ * paragraphs at the same lengths (the two differ only in how records are cut
2891
+ * or which tracked change holds some content), `moves` is that rebased
2892
+ * change: positions move over it exactly as over a `rebased` one.
2893
+ */
2894
+ type ClientDocumentChange = {
2895
+ type: "rebased";
2896
+ batch: SequencedBatch;
2897
+ } | {
2898
+ type: "replaced";
2899
+ batch: SequencedBatch;
2900
+ moves?: SequencedBatch;
2901
+ };
1977
2902
  /** Optimistic state with ordered authoritative replay and one causal submission in flight. */
1978
2903
  export declare const createClient: (document: Document) => {
1979
2904
  enqueue: (batch: DocumentBatch) => Result<DocumentBatch, BatchRejection>;
1980
2905
  nextSubmission: () => DocumentBatch | undefined;
1981
2906
  receiveAck: (ack: BatchAck) => void;
1982
- receiveReject: (rejection: BatchReject) => void;
1983
- receiveBroadcast: (batch: SequencedBatch) => Result<void, BatchRejection>;
2907
+ receiveReject: (rejection: BatchReject) => readonly ClientDocumentChange[];
2908
+ receiveBroadcast: (batch: SequencedBatch) => Result<readonly ClientDocumentChange[], BatchRejection>;
1984
2909
  readonly document: Document;
1985
2910
  readonly headRev: number;
1986
2911
  readonly pending: readonly DocumentBatch[];
1987
2912
  readonly notices: readonly ClientNotice[];
1988
2913
  };
2914
+ /** What an annotation adds: run formatting, or a comment's anchor. */
2915
+ export declare const BATCH_ANNOTATION_KINDS: Readonly<{
2916
+ FORMATTING: "formatting";
2917
+ COMMENT: "comment";
2918
+ }>;
2919
+ type BatchAnnotationKind = (typeof BATCH_ANNOTATION_KINDS)[keyof typeof BATCH_ANNOTATION_KINDS];
1989
2920
  /**
1990
2921
  * The execution coordinates of an operation resolved against a batch's
1991
2922
  * pre-state. Positions and table coordinates are ordered from right to left;
@@ -1993,9 +2924,14 @@ export declare const createClient: (document: Document) => {
1993
2924
  * Annotations run before moving edits, while table-shape and column edits run
1994
2925
  * after ordinary content edits. Table mutations in nested tables still run
1995
2926
  * right to left before the phase order is applied within the same table.
2927
+ *
2928
+ * Formatting moves no position, and a later write of a property replaces an
2929
+ * earlier one, so formatting annotations run first and in input order, as
2930
+ * one at a time; comment annotations follow them.
1996
2931
  */
1997
2932
  type BatchOrderAddress = {
1998
2933
  type: "annotation";
2934
+ kind: BatchAnnotationKind;
1999
2935
  position: number;
2000
2936
  inputIndex: number;
2001
2937
  } | {
@@ -2039,6 +2975,40 @@ type BatchBlockAccess<Block> = {
2039
2975
  /** Blocks the operation deletes, or merges into the block before them. */
2040
2976
  removes: readonly Block[];
2041
2977
  };
2978
+ /** A paragraph before a container's final paragraph, and whether the batch deletes it. */
2979
+ type FinalBreakCandidate<Paragraph> = {
2980
+ paragraph: Paragraph;
2981
+ deleted: boolean;
2982
+ };
2983
+ /**
2984
+ * Which paragraph settles the deletion of a container's final paragraph:
2985
+ *
2986
+ * - `kept`: the nearest one before it the batch keeps. The final paragraph
2987
+ * goes, and its break retires onto that one.
2988
+ * - `runStart`: the batch deletes every paragraph back to the container's
2989
+ * start or another block. The final paragraph stays, emptied, with the
2990
+ * properties of the run's first paragraph: applied right to left, the run
2991
+ * collapses into that one. One at a time, the final paragraph's deletion
2992
+ * runs while that paragraph still stands, and the paragraph's own deletion
2993
+ * follows it.
2994
+ * - `none`: no paragraph precedes it; it stays, emptied, as it is.
2995
+ */
2996
+ type FinalBreakCarrier<Paragraph> = {
2997
+ type: "kept";
2998
+ paragraph: Paragraph;
2999
+ } | {
3000
+ type: "runStart";
3001
+ paragraph: Paragraph;
3002
+ } | {
3003
+ type: "none";
3004
+ };
3005
+ /**
3006
+ * The carrier of a deleted final paragraph's break, from the paragraphs
3007
+ * before it in its container, nearest first, up to the container's start or
3008
+ * another block. The engine's batch and the one-at-a-time replay both read
3009
+ * it from here, so they settle the deletion on the same paragraph.
3010
+ */
3011
+ export declare const finalBreakCarrier: <Paragraph>(before: readonly FinalBreakCandidate<Paragraph>[]) => FinalBreakCarrier<Paragraph>;
2042
3012
  /**
2043
3013
  * Whether deleting a block takes it out of the document. A container (a
2044
3014
  * story, cell, note or text box) has to end with a paragraph, so deleting its
@@ -2047,7 +3017,7 @@ type BatchBlockAccess<Block> = {
2047
3017
  */
2048
3018
  export declare const deletionRemovesBlock: (deletion: {
2049
3019
  endsContainer: boolean;
2050
- hasKeptParagraphBefore: boolean;
3020
+ carrier: FinalBreakCarrier<unknown>["type"];
2051
3021
  }) => boolean;
2052
3022
  /**
2053
3023
  * A batch equals its operations applied one at a time with every operation
@@ -2069,4 +3039,54 @@ export declare const orderAddressingBeforeRemoval: <T, Block>(ordered: readonly
2069
3039
  * requested sequence, which no series of single edits produces.
2070
3040
  */
2071
3041
  export declare const groupInsertionRuns: <T>(operations: readonly T[], insertionPositionOf: (operation: T) => number | null, keepsGap?: (operation: T) => boolean) => T[][];
2072
- export type { AddNoteOp, AppliedDocumentOp, BatchBlockAccess, BatchOrderAddress, BatchRejectionReason, BlockInsertionPoint, BoundaryOccurrence, CommentAnchor, CommentExhaustionInput, CommentState, CopyOriginAncestorList, CreateCommentOp, CreateHeaderFooterOp, CreateNumberingInstanceOp, DeleteBlocksOp, DeleteColumnOp, DeleteCommentOp, DeleteNumberingInstanceOp, DeleteRangeOp, DeleteRowOp, DeleteTableOp, DocumentBatch, DocumentOp, DocumentOpEnvelope, DocumentOpRefusalReason, DocumentOpType, EditorIntent, EditorIntentMode, EmptyPropertySet, FormattingPatch, HeaderFooterStory, InlineSlice, InsertBlocksOp, InsertColumnOp, InsertContentOp, InsertRowOp, InsertTableOp, InsertTextOp, InsertedRunProps, JoinBlocksOp, JoinInlineOp, MergeCellsOp, NewIds, NewListInstance, NoteStory, NumberingPartState, OpStory, PackageResourceEntry, PackageResourceEntryChange, PackageResourceMapChange, PackageResourceMedia, PackageResourcePart, PackageResources, ParagraphContentVerdict, ParagraphPropsPatch, ParagraphReviewFields, PlanTrackedDeletionOptions, PlanTrackedReplaceOptions, RemoveHeaderFooterOp, RemoveNoteOp, ReplaceBlocksOp, ReplaceInlineOp, ResolveRevisionOp, RestoreCommentStateOp, RestoreStoryPartsOp, RevisionDecision, RevisionStamp, RunPropsPatch, SectionEndpoint, SectionMapState, SectionPropertiesState, SectionViewEntry, SectionViewState, SequencedBatch, SetCellPropsOp, SetCommentResolutionOp, SetContainerBlocksOp, SetPackageResourcesOp, SetParagraphPropsOp, SetParagraphReviewOp, SetRowPropsOp, SetRunPropsOp, SetSectionEndpointOp, SetSectionPropsOp, SetTableGridOp, SetTableOp, SetTablePropsOp, SetTableRowsOp, SplitBlockOp, SplitCellOp, SplitHalf, SplitInlineOp, SplitParagraphFields, TableBlockIntentOperation, TableEditOp, TableIntentOperation, TableRowIntentOperation, TextPosition, TouchedBlocks, UpdateCommentContentOp, WellFormedRangePlan, ZeroWidthItem };
3042
+ /** A document with its changes resolved one way, and what could not be. */
3043
+ type ResolvedDocumentView = {
3044
+ document: Document;
3045
+ /**
3046
+ * The stories whose resolution refused, left as they were: a reader shows
3047
+ * them with their changes still in place and says so.
3048
+ */
3049
+ unresolved: readonly OpStory[];
3050
+ };
3051
+ /**
3052
+ * `document` with every revision resolved by `decision`, story by story. A
3053
+ * story the resolution of an earlier one removed (a note whose every
3054
+ * reference went) is not read again.
3055
+ */
3056
+ export declare const resolvedDocumentView: (document: Document, decision: RevisionDecision) => ResolvedDocumentView;
3057
+ type WholeParagraphReplacementOptions = {
3058
+ document: Document;
3059
+ from: TextPosition;
3060
+ to: TextPosition;
3061
+ /**
3062
+ * Who a suggesting replacement records, absent for a direct edit. A
3063
+ * suggestion retracts only its own pending insertions; a host with
3064
+ * another owner's stays with the ordinary range planner.
3065
+ */
3066
+ suggesting?: RevisionOwner | undefined;
3067
+ };
3068
+ type WholeParagraphReplacementPlan = {
3069
+ blockIds: readonly string[];
3070
+ commentIds: ReadonlySet<number>;
3071
+ };
3072
+ /**
3073
+ * Whole source hosts before a surviving paragraph can retire through range
3074
+ * deletion and joins. Their complete comment ownership needs no alignment
3075
+ * inside a surviving host. Partial first hosts, section endpoints and pending
3076
+ * removals, moves or property changes in a host stay with the ordinary range
3077
+ * planner.
3078
+ */
3079
+ export declare const planWholeParagraphReplacement: ({ document, from, to, suggesting }: WholeParagraphReplacementOptions) => Result<WholeParagraphReplacementPlan | null, DocumentOpRefusal>;
3080
+ type PreservedCommentRangeMarker = {
3081
+ type: "commentRangeStart" | "commentRangeEnd";
3082
+ id: number;
3083
+ };
3084
+ /** Read the boundaries before the named row or cell, in authored order. */
3085
+ export declare const preservedCommentRangeMarkersAt: (children: readonly PreservedChild[] | undefined, { at, childCount }: {
3086
+ at: number;
3087
+ childCount: number;
3088
+ }) => PreservedCommentRangeMarker[];
3089
+ export declare const storyBody: (document: Document, story: OpStory) => DocumentBody;
3090
+ export declare const findStoryBody: (document: Document, story: OpStory) => DocumentBody | undefined;
3091
+ export declare const sameStory: (left: OpStory, right: OpStory) => boolean;
3092
+ export type { AddNoteOp, AppliedDocumentOp, BatchAck, BatchAnnotationKind, BatchBlockAccess, BatchOrderAddress, BatchReject, BatchRejectionReason, BatchSubmission, BlockBoundary, BlockInsertionPoint, BoundaryOccurrence, ClientDocumentChange, ClientNotice, CommentAnchor, CommentExhaustionInput, CommentReferenceOffset, CommentState, CopyOriginAncestorList, CreateCommentOp, CreateHeaderFooterOp, CreateNumberingInstanceOp, DeleteBlocksOp, DeleteColumnOp, DeleteCommentOp, DeleteNumberingInstanceOp, DeleteRangeOp, DeleteRowOp, DeleteTableOp, DocumentBatch, DocumentOp, DocumentOpEnvelope, DocumentOpRefusalReason, DocumentOpType, EditorIntent, EditorIntentMode, EmptyPropertySet, ExclusivePart, FinalBreakCandidate, FinalBreakCarrier, FormattingPatch, HeaderFooterStory, IdBlock, IdLease, IdLeaseGrant, IdLeaseKind, IdLeaseMinted, IdLeaseRefusalReason, IdLeaseState, InlineSlice, InsertBlocksOp, InsertColumnOp, InsertContentOp, InsertRowOp, InsertTableOp, InsertTextOp, InsertedRunProps, JoinBlocksOp, JoinInlineOp, LeasedId, LeasedIdCensus, MergeCellsOp, NewIds, NewListInstance, NoteStory, NumberingPartState, OpStory, PackageResourceEntry, PackageResourceEntryChange, PackageResourceMapChange, PackageResourceMedia, PackageResourcePart, PackageResources, ParagraphAbsorption, ParagraphContentVerdict, ParagraphPropsPatch, ParagraphReviewFields, PlanTrackedDeletionOptions, PlanTrackedReplaceOptions, PreservedCommentRangeMarker, RecordedRevisionIds, RemoveHeaderFooterOp, RemoveNoteOp, ReplaceBlocksOp, ReplaceInlineOp, ResolveRevisionOp, ResolvedDocumentView, RestoreCommentStateOp, RestoreStoryPartsOp, RevisionAbsorption, RevisionDecision, RevisionStamp, RunPropsPatch, SectionEndpoint, SectionMapState, SectionPropertiesState, SectionViewEntry, SectionViewState, SequencedBatch, SequencerOptions, SetCellPropsOp, SetCommentResolutionOp, SetContainerBlocksOp, SetContentControlOp, SetPackageResourcesOp, SetParagraphPropsOp, SetParagraphReviewOp, SetRowPropsOp, SetRunPropsOp, SetSectionEndpointOp, SetSectionPropsOp, SetTableGridOp, SetTableOp, SetTablePropsOp, SetTableRowsOp, SplitBlockOp, SplitCellOp, SplitHalf, SplitInlineOp, SplitParagraphFields, StoryParts, TableBlockIntentOperation, TableEditOp, TableInsertionPoint, TableIntentOperation, TableRowIntentOperation, TextPosition, TouchedBlocks, UpdateCommentContentOp, VersionOneKept, VersionOneKeptMarkers, WellFormedRangePlan, ZeroWidthItem };