@stll/docx-core 0.31.0 → 0.33.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,4 @@
1
- import { $t as ParagraphMarkChange, Br as TableCellFormatting, Dr as NumberingDefinitions, Fn as Table, Kr as TableRowFormatting, M as BlockContent, Or as NumberingInstance, Pn as TabContent, Pr as ParagraphFormatting, Qt as ParagraphContent, R as BreakContent, Vr as TableFormatting, Wn as TableRow, X as DocumentBody, Yr as TextFormatting, Zt as Paragraph, _t as INSERTION_SEAM_POLICIES, bn as SectionProperties, c as ExhaustiveFields, i as DocumentSettings, mn as RunContent, mt as HeaderFooterType, nt as Endnote, o as DocxPackage, pn as Run, pt as HeaderFooter, r as Document, tn as ParagraphPropertyChange, ut as Footnote, vr as AbstractNumbering, yn as Section } from "../document-w6pPLpob.js";
1
+ import { $t as ParagraphContent, Fn as TabContent, Fr as ParagraphFormatting, Gn as TableRow, Hr as TableFormatting, In as Table, N as BlockContent, Or as NumberingDefinitions, Qt as Paragraph, V as Comment, Vr as TableCellFormatting, Xr as TextFormatting, Z as DocumentBody, a as DocumentSettings, b as StyleDefinitions, bn as Section, dt as Footnote, en as ParagraphMarkChange, g as Relationship, h as MediaFile, hi as HeadingOutlineLevel, hn as RunContent, ht as HeaderFooterType, i as Document, kr as NumberingInstance, l as ExhaustiveFields, mn as Run, mt as HeaderFooter, nn as ParagraphPropertyChange, qr as TableRowFormatting, rt as Endnote, s as DocxPackage, vt as INSERTION_SEAM_POLICIES, xn as SectionProperties, yr as AbstractNumbering, z as BreakContent } from "../document-YlRuGzLX.js";
2
2
  import { Result } from "better-result";
3
3
  //#region src/ops/noteMarks.d.ts
4
4
  declare const noteUsesCustomMark: (document: Document, note: Footnote | Endnote) => boolean;
@@ -35,6 +35,7 @@ type SectionViewChange = {
35
35
  /**
36
36
  * The operation schema this module reads and writes.
37
37
  *
38
+ * Version 9 adds exact, JSON-safe package resource replacement for clipboard imports.
38
39
  * Version 8 adds semantic table edits and exact whole-table restoration.
39
40
  * Version 7 adds lossless own-undefined operation snapshot presence and
40
41
  * explicit revision-boundary provenance. An explicit undefined patch value now
@@ -56,7 +57,7 @@ type SectionViewChange = {
56
57
  * and paragraph operations, and the review operations `setParagraphReview`,
57
58
  * `replaceInline` and `resolveRevision`.
58
59
  */
59
- declare const DOCUMENT_OP_SCHEMA_VERSION = 8;
60
+ declare const DOCUMENT_OP_SCHEMA_VERSION = 10;
60
61
  /**
61
62
  * The main story has a fixed address; other editable parts use their stable
62
63
  * relationship id or note id. Comment bodies are not yet editable stories.
@@ -171,8 +172,13 @@ declare const SECTION_BOUNDARY_POLICIES: Readonly<{
171
172
  readonly REMOVE: "remove";
172
173
  readonly REPLACE: "replace";
173
174
  }>;
174
- /** The operation kinds of schema version 8. */
175
+ /** The operation kinds of schema version 10. */
175
176
  declare const DOCUMENT_OP_TYPES: Readonly<{
177
+ readonly CREATE_COMMENT: "createComment";
178
+ readonly UPDATE_COMMENT_CONTENT: "updateCommentContent";
179
+ readonly SET_COMMENT_RESOLUTION: "setCommentResolution";
180
+ readonly DELETE_COMMENT: "deleteComment";
181
+ readonly RESTORE_COMMENT_STATE: "restoreCommentState";
176
182
  readonly CREATE_HEADER_FOOTER: "createHeaderFooter";
177
183
  readonly REMOVE_HEADER_FOOTER: "removeHeaderFooter";
178
184
  readonly ADD_NOTE: "addNote";
@@ -212,6 +218,7 @@ declare const DOCUMENT_OP_TYPES: Readonly<{
212
218
  readonly CREATE_NUMBERING_INSTANCE: "createNumberingInstance";
213
219
  readonly DELETE_NUMBERING_INSTANCE: "deleteNumberingInstance";
214
220
  readonly SET_SECTION_ENDPOINT: "setSectionEndpoint";
221
+ readonly SET_PACKAGE_RESOURCES: "setPackageResources";
215
222
  }>;
216
223
  /** One of {@link DOCUMENT_OP_TYPES}. */
217
224
  type DocumentOpType = (typeof DOCUMENT_OP_TYPES)[keyof typeof DOCUMENT_OP_TYPES];
@@ -676,6 +683,50 @@ type DeleteNumberingInstanceOp = {
676
683
  expected?: NumberingPartState;
677
684
  restore?: NumberingPartState;
678
685
  };
686
+ /** Presence is explicit so inverses restore omitted and undefined package fields exactly. */
687
+ type PackageResourcePart<Value> = {
688
+ type: "omitted";
689
+ } | {
690
+ type: "undefined";
691
+ } | {
692
+ type: "present";
693
+ value: Value;
694
+ };
695
+ /** JSON-safe media bytes, rather than an ArrayBuffer that JSON discards. */
696
+ type PackageResourceMedia = Omit<MediaFile, "data"> & {
697
+ data: readonly number[];
698
+ };
699
+ /** Package definitions captured before and after an explicit clipboard import. */
700
+ type PackageResources = {
701
+ styles: PackageResourcePart<StyleDefinitions>;
702
+ numbering: PackageResourcePart<NumberingDefinitions>;
703
+ };
704
+ type PackageResourcePresence = PackageResourcePart<unknown>["type"];
705
+ type PackageResourceEntry<Value> = {
706
+ type: "absent";
707
+ } | {
708
+ type: "present";
709
+ value: Value;
710
+ };
711
+ type PackageResourceEntryChange<Value> = {
712
+ key: string;
713
+ expected: PackageResourceEntry<Value>;
714
+ next: PackageResourceEntry<Value>;
715
+ };
716
+ /** Keyed changes to a package map; entries the operation leaves alone are not carried. */
717
+ type PackageResourceMapChange<Value> = {
718
+ expected: PackageResourcePresence;
719
+ next: PackageResourcePresence;
720
+ entries: readonly PackageResourceEntryChange<Value>[];
721
+ };
722
+ /** Replace merged definitions and change keyed package entries, refusing stale package data. */
723
+ type SetPackageResourcesOp = {
724
+ type: typeof DOCUMENT_OP_TYPES.SET_PACKAGE_RESOURCES;
725
+ expected: PackageResources;
726
+ resources: PackageResources;
727
+ relationships: PackageResourceMapChange<Relationship>;
728
+ media: PackageResourceMapChange<PackageResourceMedia>;
729
+ };
679
730
  /** A section endpoint is either a paragraph's sectPr or the body's final sectPr. */
680
731
  type SectionEndpoint = {
681
732
  type: "paragraph";
@@ -773,6 +824,18 @@ type SetSectionPropsOp = {
773
824
  };
774
825
  /** JSON-safe lifecycle deltas: omitted fields are unowned, null restores absence. */
775
826
  type StoryParts = {
827
+ /** Owned fields whose source explicitly had an undefined own property. */
828
+ undefinedFields?: readonly ({
829
+ target: "body";
830
+ keys: readonly (keyof NonNullable<StoryParts["body"]>)[];
831
+ } | {
832
+ target: "package";
833
+ keys: readonly (keyof Omit<StoryParts, "body" | "sections" | "undefinedFields">)[];
834
+ } | {
835
+ target: "section";
836
+ index: number;
837
+ keys: readonly (keyof Omit<NonNullable<StoryParts["sections"]>[number], "index">)[];
838
+ })[];
776
839
  body?: { [Key in keyof Omit<DocumentBody, "sections">]?: Key extends "content" ? DocumentBody[Key] : Exclude<DocumentBody[Key], undefined> | null; };
777
840
  /** Section contents remain derived from the body's content and are never duplicated. */
778
841
  sections?: readonly {
@@ -855,8 +918,74 @@ type TableEditOp = InsertColumnOp | DeleteColumnOp | MergeCellsOp | SplitCellOp
855
918
  type TableIntentOperation = { [Kind in TableEditOp["type"]]: Omit<Extract<TableEditOp, {
856
919
  type: Kind;
857
920
  }>, "revision" | "newIds" | "newBlockIds">; }[TableEditOp["type"]];
858
- /** A schema-version-8 document operation. */
859
- type DocumentOp = (CreateHeaderFooterOp | RemoveHeaderFooterOp | AddNoteOp | RemoveNoteOp | SetSectionPropsOp | RestoreStoryPartsOp | DeleteBlocksOp | InsertTableOp | DeleteTableOp | SetContainerBlocksOp | InsertBlocksOp | InsertTextOp | InsertContentOp | DeleteRangeOp | SplitInlineOp | JoinInlineOp | SetRunPropsOp | SetParagraphPropsOp | SplitBlockOp | JoinBlocksOp | ReplaceBlocksOp | SetParagraphReviewOp | ReplaceInlineOp | ResolveRevisionOp | InsertRowOp | DeleteRowOp | SetTableRowsOp | TableEditOp | SetTableOp | CreateNumberingInstanceOp | DeleteNumberingInstanceOp | SetSectionEndpointOp) & {
921
+ /** A comment definition owns one range, point, thread relation or revision association. */
922
+ type CommentAnchor = {
923
+ kind: "range";
924
+ from: TextPosition;
925
+ to: TextPosition;
926
+ } | {
927
+ kind: "point";
928
+ at: TextPosition;
929
+ } | {
930
+ kind: "reply";
931
+ parentId: number;
932
+ } | {
933
+ kind: "revision";
934
+ story: OpStory;
935
+ revisionId: number;
936
+ };
937
+ type CreateCommentOp = {
938
+ type: typeof DOCUMENT_OP_TYPES.CREATE_COMMENT;
939
+ comment: Omit<Comment, "parentId">;
940
+ anchor: CommentAnchor;
941
+ newIds?: NewIds;
942
+ };
943
+ type UpdateCommentContentOp = {
944
+ type: typeof DOCUMENT_OP_TYPES.UPDATE_COMMENT_CONTENT;
945
+ id: number;
946
+ content: readonly Paragraph[];
947
+ patch?: FormattingPatch<Pick<Comment, "author" | "initials" | "date">>;
948
+ };
949
+ type SetCommentResolutionOp = {
950
+ type: typeof DOCUMENT_OP_TYPES.SET_COMMENT_RESOLUTION;
951
+ id: number;
952
+ status: "open" | "resolved";
953
+ };
954
+ type DeleteCommentOp = {
955
+ type: typeof DOCUMENT_OP_TYPES.DELETE_COMMENT;
956
+ id: number;
957
+ scope: "thread" | "reply";
958
+ };
959
+ /** Exact owned comment records and the paragraph fragments containing their anchors. */
960
+ type CommentState = {
961
+ relationshipPresence: "absent" | "undefined" | "present";
962
+ relationships: readonly {
963
+ index: number;
964
+ key: string;
965
+ relationship: Relationship;
966
+ }[];
967
+ listPresence: "absent" | "undefined" | "present";
968
+ records: readonly {
969
+ index: number;
970
+ comment: Comment;
971
+ }[];
972
+ anchors: readonly {
973
+ story: OpStory;
974
+ blockId: string;
975
+ content: readonly ParagraphContent[];
976
+ }[];
977
+ };
978
+ type RestoreCommentStateOp = {
979
+ type: typeof DOCUMENT_OP_TYPES.RESTORE_COMMENT_STATE;
980
+ ids: readonly number[];
981
+ /** Only identities introduced or retired by anchor scaffolding cuts. */
982
+ scaffoldIds: NewIds;
983
+ expected: CommentState;
984
+ state: CommentState;
985
+ };
986
+ type CommentOp = CreateCommentOp | UpdateCommentContentOp | SetCommentResolutionOp | DeleteCommentOp | RestoreCommentStateOp;
987
+ /** A schema-version-10 document operation. */
988
+ 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 | InsertRowOp | DeleteRowOp | SetTableRowsOp | TableEditOp | SetTableOp | CreateNumberingInstanceOp | DeleteNumberingInstanceOp | SetSectionEndpointOp | SetPackageResourcesOp) & {
860
989
  /** Own undefined fields recorded by the operation capture boundary. */
861
990
  undefinedFields?: readonly (readonly string[])[];
862
991
  };
@@ -1011,91 +1140,51 @@ declare const documentStories: (document: Document) => OpStory[];
1011
1140
  /** Capture own undefined fields before an operation enters its JSON journal. */
1012
1141
  declare const captureDocumentOp: (op: DocumentOp) => DocumentOp;
1013
1142
  //#endregion
1014
- //#region src/ops/apply.d.ts
1015
- /** A document an operation produced, the operations that undo it, and what it changed. */
1016
- type AppliedDocumentOp = {
1017
- document: Document;
1018
- /** Apply in order to restore the input document. */
1019
- inverse: readonly DocumentOp[];
1020
- touched: TouchedBlocks;
1021
- /**
1022
- * Newly allocated tracked revision ids, in document order: its stamp's
1023
- * id and the new ids its other records took. Existing ids retained by a
1024
- * folded or continued review are excluded; a direct operation reports none.
1025
- */
1026
- revisions: readonly number[];
1143
+ //#region src/ops/leaves.d.ts
1144
+ /** A place between two leaves. */
1145
+ type Gap = {
1146
+ offset: number;
1147
+ zeroWidthBefore: number;
1027
1148
  };
1028
- /** Apply one operation to a document that meets the seed contract. */
1029
- declare const applyDocumentOp: (document: Document, input: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1030
- /** Apply a journal envelope only when its schema matches this reader. */
1031
- declare const applyDocumentOpEnvelope: (document: Document, envelope: {
1032
- schema: number;
1033
- op: DocumentOp;
1034
- }) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1149
+ /** A node of a paragraph's content tree: a paragraph child or a run child. */
1150
+ type InlineNode = ParagraphContent | RunContent;
1151
+ /** The zero-width leaves at an offset, in document order. */
1152
+ declare const zeroWidthLeavesAt: (items: readonly InlineNode[], offset: number) => InlineNode[];
1035
1153
  /**
1036
- * Apply operations in order, atomically: the first refusal is returned and
1037
- * the document is unchanged. The inverse undoes the whole list, and
1038
- * `revisions` lists each operation's in turn.
1154
+ * The gap an insertion defaults to: before the first zero-width leaf at the
1155
+ * offset that opens a range, so a marker opening there stays with what
1156
+ * follows it and every other one with what precedes it.
1039
1157
  */
1040
- declare const applyDocumentOps: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1158
+ declare const defaultInsertionGap: (items: readonly InlineNode[], offset: number) => Gap;
1159
+ /** Source leaf coordinates without the ancestry needed by edit planning. */
1160
+ declare const inlineLeafSpans: (items: readonly InlineNode[]) => {
1161
+ node: InlineNode;
1162
+ before: Gap;
1163
+ after: Gap;
1164
+ }[];
1165
+ /** Gaps in document order: by offset, then by the zero-width leaves before them. */
1166
+ declare const compareGaps: (left: Gap, right: Gap) => number;
1041
1167
  //#endregion
1042
- //#region src/ops/runMerge.d.ts
1043
- /**
1044
- * Every `TextFormatting` field, named so the comparison below is total.
1045
- *
1046
- * A field this comparison forgets is a field one of two merged runs loses,
1047
- * silently and at parse time. Naming them turns a field added to the model
1048
- * without a comparison into a compile error rather than a fidelity defect.
1049
- */
1050
- type ComparedTextFormattingField = "bold" | "boldCs" | "italic" | "italicCs" | "underline" | "strike" | "doubleStrike" | "vertAlign" | "smallCaps" | "allCaps" | "hidden" | "noProof" | "color" | "highlight" | "shading" | "fontSize" | "fontSizeCs" | "fontFamily" | "language" | "spacing" | "position" | "scale" | "kerning" | "effect" | "emphasisMark" | "emboss" | "imprint" | "outline" | "shadow" | "rtl" | "cs" | "styleId" | "preserved";
1051
- type ComparedTextFormatting = ExhaustiveFields<TextFormatting, ComparedTextFormattingField>;
1052
- /**
1053
- * Check if two TextFormatting objects are equivalent
1054
- *
1055
- * Uses deep comparison of all properties to determine if runs
1056
- * can be merged without losing formatting information.
1057
- */
1058
- declare function formattingEquals(a: ComparedTextFormatting | undefined, b: ComparedTextFormatting | undefined): boolean;
1059
- /**
1060
- * Check if a run contains only text content
1061
- * (runs with special content like images, fields, etc. should not be merged)
1062
- */
1063
- declare function isTextOnlyRun(run: Run): boolean;
1064
- /**
1065
- * Every `Run` field, named by what a merge does with it.
1066
- *
1067
- * The merged run is the survivor spread whole, so a field added to the model
1068
- * is carried over from one side by default. Naming each one here forces the
1069
- * next field to state whether that default is right before it can compile.
1070
- */
1071
- type MergeDecidedRunField =
1072
- /** Identical for every run. */
1073
- "type" |
1074
- /** Concatenated; see {@link mergeRunContent}. */
1075
- "content" |
1076
- /** Must be equal, and the survivor keeps it. */
1077
- "formatting" |
1078
- /** Must be equal, and the survivor keeps it. */
1079
- "preservedAttributes" |
1080
- /** Refuses the merge outright; see {@link canMergeRun}. */
1081
- "propertyChanges";
1082
- type MergeDecidedRun = ExhaustiveFields<Run, MergeDecidedRunField>;
1083
- /**
1084
- * May two adjacent runs become one?
1085
- *
1086
- * Every consolidation site asks this one question, because a merge that any
1087
- * one site decides differently is a merge the next parse undoes. A run holds
1088
- * three records a merged run can hold only one of: its typed formatting, the
1089
- * attributes `w:r` carried that the model has no field for, and the `w:rPr`
1090
- * children no reader took a value from. Merging two runs that disagree on any
1091
- * of them discards the loser's copy, which is how both runs' `w:rsid*` used to
1092
- * vanish at parse time — before the editor, before any gate could see it.
1093
- */
1094
- declare function runsMergeable(a: MergeDecidedRun, b: MergeDecidedRun): boolean;
1095
- /**
1096
- * Merge the content of two runs into a single content array
1097
- */
1098
- declare function mergeRunContent(content1: RunContent[], content2: RunContent[]): RunContent[];
1168
+ //#region src/ops/hyperlinkIntent.d.ts
1169
+ type HyperlinkEditorIntent = {
1170
+ type: "setHyperlink";
1171
+ from: TextPosition;
1172
+ to: TextPosition;
1173
+ href: string;
1174
+ tooltip?: string;
1175
+ } | {
1176
+ type: "removeHyperlink";
1177
+ from: TextPosition;
1178
+ to: TextPosition;
1179
+ hyperlinkStyleId?: string;
1180
+ } | {
1181
+ type: "insertHyperlink";
1182
+ from: TextPosition;
1183
+ to: TextPosition;
1184
+ text: string;
1185
+ href: string;
1186
+ tooltip?: string;
1187
+ };
1099
1188
  //#endregion
1100
1189
  //#region src/ops/editorIntent.d.ts
1101
1190
  type SplitParagraphIntent = {
@@ -1104,9 +1193,24 @@ type SplitParagraphIntent = {
1104
1193
  to?: TextPosition;
1105
1194
  };
1106
1195
  /** Positions use canonical physical offsets, including retained deleted content. */
1107
- type EditorIntent = {
1196
+ type EditorIntent = HyperlinkEditorIntent | GenerateTOCIntent | {
1108
1197
  type: "table";
1109
1198
  operation: TableIntentOperation;
1199
+ } | {
1200
+ type: "replaceFragment";
1201
+ from: TextPosition;
1202
+ to: TextPosition;
1203
+ paragraphs: readonly Paragraph[];
1204
+ openStart: 0 | 1;
1205
+ openEnd: 0 | 1;
1206
+ } | {
1207
+ type: "moveFragment";
1208
+ from: TextPosition;
1209
+ to: TextPosition;
1210
+ target: TextPosition;
1211
+ paragraphs: readonly Paragraph[];
1212
+ openStart: 0 | 1;
1213
+ openEnd: 0 | 1;
1110
1214
  } | {
1111
1215
  type: "replaceText";
1112
1216
  from: TextPosition;
@@ -1154,16 +1258,21 @@ type EditorIntent = {
1154
1258
  };
1155
1259
  /** Revision metadata and every fresh identity are supplied before compilation. */
1156
1260
  type EditorIntentMode = {
1261
+ /** Identities consumed during this editor lifetime, including undone insertions. */
1262
+ reservedBlockIds?: ReadonlySet<string>;
1263
+ } & ({
1157
1264
  type: "editing";
1158
1265
  newIds?: NewIds;
1159
1266
  } | {
1160
1267
  type: "suggesting";
1161
1268
  revision: RevisionStamp;
1162
1269
  newIds: NewIds;
1163
- };
1270
+ });
1164
1271
  type CompileEditorIntentOptions = {
1165
1272
  intent: EditorIntent;
1166
1273
  mode: EditorIntentMode;
1274
+ /** Lowest candidate for compiler-owned pasted block IDs, including retired session IDs. */
1275
+ firstBlockId?: number;
1167
1276
  };
1168
1277
  type CompiledEditorIntent = {
1169
1278
  ops: DocumentOp[];
@@ -1195,7 +1304,120 @@ declare const editorParagraphGroups: (document: Document, story: OpStory) => {
1195
1304
  text: string;
1196
1305
  }[];
1197
1306
  /** Compile one batch; the caller applies it atomically and journals its exact inverse. */
1198
- declare const compileEditorIntent: (document: Document, { intent, mode }: CompileEditorIntentOptions) => Result<CompiledEditorIntent, DocumentOpRefusal>;
1307
+ declare const compileEditorIntent: (document: Document, { intent, mode, firstBlockId }: CompileEditorIntentOptions) => Result<CompiledEditorIntent, DocumentOpRefusal>;
1308
+ //#endregion
1309
+ //#region src/ops/tocIntent.d.ts
1310
+ type TocHeading = {
1311
+ blockId: string;
1312
+ text: string;
1313
+ /** Zero-based OOXML outline level, from 0 through 8. */
1314
+ level: HeadingOutlineLevel;
1315
+ styleId?: string;
1316
+ };
1317
+ type GenerateTOCIntent = {
1318
+ type: "generateTOC";
1319
+ at: TextPosition;
1320
+ title: string;
1321
+ headings: readonly TocHeading[];
1322
+ titleStyleId?: string;
1323
+ tabPosition: number;
1324
+ };
1325
+ /** Map original endpoints through the bookmark wrappers emitted by TOC compilation. */
1326
+ declare const mapTocBookmarkPosition: (position: TextPosition, ops: readonly DocumentOp[]) => TextPosition;
1327
+ //#endregion
1328
+ //#region src/ops/packageResources.d.ts
1329
+ type PackageResourcesOpOptions = {
1330
+ before: Document;
1331
+ after: Document;
1332
+ };
1333
+ /** Describe the package resource difference as one operation carrying only changed entries. */
1334
+ declare const packageResourcesOpOf: ({ before, after }: PackageResourcesOpOptions) => SetPackageResourcesOp;
1335
+ //#endregion
1336
+ //#region src/ops/apply.d.ts
1337
+ /** A document an operation produced, the operations that undo it, and what it changed. */
1338
+ type AppliedDocumentOp = {
1339
+ document: Document;
1340
+ /** Apply in order to restore the input document. */
1341
+ inverse: readonly DocumentOp[];
1342
+ touched: TouchedBlocks;
1343
+ /**
1344
+ * Newly allocated tracked revision ids, in document order: its stamp's
1345
+ * id and the new ids its other records took. Existing ids retained by a
1346
+ * folded or continued review are excluded; a direct operation reports none.
1347
+ */
1348
+ revisions: readonly number[];
1349
+ };
1350
+ /** Apply one operation to a document that meets the seed contract. */
1351
+ declare const applyDocumentOp: (document: Document, input: DocumentOp) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1352
+ /** Apply a journal envelope only when its schema matches this reader. */
1353
+ declare const applyDocumentOpEnvelope: (document: Document, envelope: {
1354
+ schema: number;
1355
+ op: DocumentOp;
1356
+ }) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1357
+ /**
1358
+ * Apply operations in order, atomically: the first refusal is returned and
1359
+ * the document is unchanged. The inverse undoes the whole list, and
1360
+ * `revisions` lists each operation's in turn.
1361
+ */
1362
+ declare const applyDocumentOps: (document: Document, ops: readonly DocumentOp[]) => Result<AppliedDocumentOp, DocumentOpRefusal>;
1363
+ //#endregion
1364
+ //#region src/ops/runMerge.d.ts
1365
+ /**
1366
+ * Every `TextFormatting` field, named so the comparison below is total.
1367
+ *
1368
+ * A field this comparison forgets is a field one of two merged runs loses,
1369
+ * silently and at parse time. Naming them turns a field added to the model
1370
+ * without a comparison into a compile error rather than a fidelity defect.
1371
+ */
1372
+ type ComparedTextFormattingField = "bold" | "boldCs" | "italic" | "italicCs" | "underline" | "strike" | "doubleStrike" | "vertAlign" | "smallCaps" | "allCaps" | "hidden" | "noProof" | "color" | "highlight" | "shading" | "fontSize" | "fontSizeCs" | "fontFamily" | "language" | "spacing" | "position" | "scale" | "kerning" | "effect" | "emphasisMark" | "emboss" | "imprint" | "outline" | "shadow" | "rtl" | "cs" | "styleId" | "preserved";
1373
+ type ComparedTextFormatting = ExhaustiveFields<TextFormatting, ComparedTextFormattingField>;
1374
+ /**
1375
+ * Check if two TextFormatting objects are equivalent
1376
+ *
1377
+ * Uses deep comparison of all properties to determine if runs
1378
+ * can be merged without losing formatting information.
1379
+ */
1380
+ declare function formattingEquals(a: ComparedTextFormatting | undefined, b: ComparedTextFormatting | undefined): boolean;
1381
+ /**
1382
+ * Check if a run contains only text content
1383
+ * (runs with special content like images, fields, etc. should not be merged)
1384
+ */
1385
+ declare function isTextOnlyRun(run: Run): boolean;
1386
+ /**
1387
+ * Every `Run` field, named by what a merge does with it.
1388
+ *
1389
+ * The merged run is the survivor spread whole, so a field added to the model
1390
+ * is carried over from one side by default. Naming each one here forces the
1391
+ * next field to state whether that default is right before it can compile.
1392
+ */
1393
+ type MergeDecidedRunField =
1394
+ /** Identical for every run. */
1395
+ "type" |
1396
+ /** Concatenated; see {@link mergeRunContent}. */
1397
+ "content" |
1398
+ /** Must be equal, and the survivor keeps it. */
1399
+ "formatting" |
1400
+ /** Must be equal, and the survivor keeps it. */
1401
+ "preservedAttributes" |
1402
+ /** Refuses the merge outright; see {@link canMergeRun}. */
1403
+ "propertyChanges";
1404
+ type MergeDecidedRun = ExhaustiveFields<Run, MergeDecidedRunField>;
1405
+ /**
1406
+ * May two adjacent runs become one?
1407
+ *
1408
+ * Every consolidation site asks this one question, because a merge that any
1409
+ * one site decides differently is a merge the next parse undoes. A run holds
1410
+ * three records a merged run can hold only one of: its typed formatting, the
1411
+ * attributes `w:r` carried that the model has no field for, and the `w:rPr`
1412
+ * children no reader took a value from. Merging two runs that disagree on any
1413
+ * of them discards the loser's copy, which is how both runs' `w:rsid*` used to
1414
+ * vanish at parse time — before the editor, before any gate could see it.
1415
+ */
1416
+ declare function runsMergeable(a: MergeDecidedRun, b: MergeDecidedRun): boolean;
1417
+ /**
1418
+ * Merge the content of two runs into a single content array
1419
+ */
1420
+ declare function mergeRunContent(content1: RunContent[], content2: RunContent[]): RunContent[];
1199
1421
  //#endregion
1200
1422
  //#region src/ops/contract.d.ts
1201
1423
  declare const DocumentOpsContractError_base: import("better-result").TaggedErrorClass<"DocumentOpsContractError">;
@@ -1227,8 +1449,16 @@ declare const paragraphLogicalText: (paragraph: Paragraph) => string;
1227
1449
  //#region src/ops/ids.d.ts
1228
1450
  /** Every paragraph id of a package, each story walked once. */
1229
1451
  declare const packageParagraphIds: (pkg: DocxPackage) => string[];
1452
+ /**
1453
+ * The key two spellings of one id share. `ST_LongHexNumber` is hex, so
1454
+ * `0000abcd` and `0000ABCD` are the same id; every lookup and comparison of
1455
+ * paragraph ids goes through this.
1456
+ */
1457
+ declare const idKey: (id: string) => string;
1230
1458
  //#endregion
1231
1459
  //#region src/ops/plan.d.ts
1460
+ /** Package-aware explicit pools for every semantic comment anchor cut, including replies. */
1461
+ declare const allocateCommentAnchorIds: (document: Document, op: CreateCommentOp) => Result<NewIds, DocumentOpRefusal>;
1232
1462
  /**
1233
1463
  * How many `newIds.revision` entries an operation takes on a document,
1234
1464
  * besides its stamp's id: the length of the shortest list of unused ids it
@@ -1258,10 +1488,12 @@ declare const planTrackedDeletion: (document: Document, options: PlanTrackedDele
1258
1488
  * paragraph, and the inline tail inserted into the retained original paragraph.
1259
1489
  * Each new paragraph's own fields apply to it, including when it takes the
1260
1490
  * source prefix. The last fragment keeps the original survivor's identity.
1261
- * Closed inline slices are required; review and content-control ids in the
1262
- * fragment, and section-bearing paragraphs, are unsupported.
1491
+ * Closed inline slices are required. Imported review and content-control ids
1492
+ * must already be distinct from destination identities; section-bearing
1493
+ * paragraphs require an explicit package import policy.
1263
1494
  */
1264
1495
  type PlanTrackedReplaceOptions = PlanTrackedDeletionOptions & {
1496
+ sourceContainerPolicy: "join" | "separate";
1265
1497
  seamPolicy?: Extract<DocumentOp, {
1266
1498
  type: "insertContent";
1267
1499
  }>["seamPolicy"];
@@ -1382,4 +1614,13 @@ declare const createClient: (document: Document) => {
1382
1614
  readonly notices: readonly ClientNotice[];
1383
1615
  };
1384
1616
  //#endregion
1385
- export { type AddNoteOp, type AppliedDocumentOp, BATCH_REJECTION_REASONS, BATCH_WIRE_OP_TYPES, BatchRejection, type BatchRejectionReason, type BlockInsertionPoint, type CreateHeaderFooterOp, type CreateNumberingInstanceOp, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteBlocksOp, type DeleteColumnOp, type DeleteNumberingInstanceOp, type DeleteRangeOp, type DeleteRowOp, type DeleteTableOp, type DocumentBatch, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EditorIntent, type EditorIntentMode, type EmptyPropertySet, type FormattingPatch, type HeaderFooterStory, INHERIT_RUN_PROPS, type InlineSlice, type InsertBlocksOp, type InsertColumnOp, type InsertContentOp, type InsertRowOp, type InsertTableOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, MAX_BATCH_WIRE_BYTES, type MergeCellsOp, type NewIds, type NoteStory, type NumberingPartState, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, PARAGRAPH_MARK_FORMATTING_KEYS, PROPERTY_REVIEW_POLICIES, type ParagraphPropsPatch, type ParagraphReviewFields, type PlanTrackedDeletionOptions, type PlanTrackedReplaceOptions, REVISION_DECISIONS, type RemoveHeaderFooterOp, type RemoveNoteOp, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RestoreStoryPartsOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SectionEndpoint, type SectionMapState, type SectionPropertiesState, type SectionViewEntry, type SectionViewState, type SequencedBatch, type SetCellPropsOp, type SetContainerBlocksOp, type SetParagraphPropsOp, type SetParagraphReviewOp, type SetRowPropsOp, type SetRunPropsOp, type SetSectionEndpointOp, type SetSectionPropsOp, type SetTableGridOp, type SetTableOp, type SetTablePropsOp, type SetTableRowsOp, type SplitBlockOp, type SplitCellOp, type SplitHalf, type SplitInlineOp, type SplitParagraphFields, type TableEditOp, type TableIntentOperation, type TextPosition, type TouchedBlocks, applyDocumentOp, applyDocumentOpEnvelope, applyDocumentOps, captureDocumentOp, combineEdits, compileEditorIntent, createClient, createEditorIntentIdAllocator, createSequencer, documentStories, editorParagraphGroups, findStoryBody, formattingEquals, isTextOnlyRun, mergeRunContent, normalizeForOps, noteUsesCustomMark, packageParagraphIds, paragraphLength, paragraphLogicalText, paragraphVisibleText, parseDocumentBatch, physicalOffsetAtVisibleOffset, planTrackedDeletion, planTrackedReplace, revisionIdDemand, runsMergeable, sameStory, sectionPropertiesAt, storyBody, toOpEnvelope, transformBatch, validateDocumentBatch, validateOpsDocument, validateSequencedBatch };
1617
+ //#region src/ops/comments.d.ts
1618
+ /**
1619
+ * Shared loaded-comment activation contract; legacy parentId revision associations stay explicit.
1620
+ * `allowedOrphans` names unanchored root comments the caller accepts ("all" for a loaded package).
1621
+ */
1622
+ declare const commentDocumentIssue: (document: Document, allowedOrphans?: ReadonlySet<number> | "all") => string | undefined;
1623
+ /** Allocate from the package's annotation domains without a hidden mutable counter. */
1624
+ declare const freshCommentId: (document: Document) => Result<number, DocumentOpRefusal>;
1625
+ //#endregion
1626
+ export { type AddNoteOp, type AppliedDocumentOp, BATCH_REJECTION_REASONS, BATCH_WIRE_OP_TYPES, BatchRejection, type BatchRejectionReason, type BlockInsertionPoint, type CommentAnchor, type CommentState, type CreateCommentOp, type CreateHeaderFooterOp, type CreateNumberingInstanceOp, DOCUMENT_OP_REFUSAL_REASONS, DOCUMENT_OP_SCHEMA_VERSION, DOCUMENT_OP_TYPES, type DeleteBlocksOp, type DeleteColumnOp, type DeleteCommentOp, type DeleteNumberingInstanceOp, type DeleteRangeOp, type DeleteRowOp, type DeleteTableOp, type DocumentBatch, type DocumentOp, type DocumentOpEnvelope, DocumentOpRefusal, type DocumentOpRefusalReason, type DocumentOpType, DocumentOpsContractError, EMPTY_PROPERTY_SETS, type EditorIntent, type EditorIntentMode, type EmptyPropertySet, type FormattingPatch, type HeaderFooterStory, INHERIT_RUN_PROPS, type InlineSlice, type InsertBlocksOp, type InsertColumnOp, type InsertContentOp, type InsertRowOp, type InsertTableOp, type InsertTextOp, type InsertedRunProps, type JoinBlocksOp, type JoinInlineOp, MAX_BATCH_WIRE_BYTES, type MergeCellsOp, type NewIds, type NoteStory, type NumberingPartState, OBJECT_REPLACEMENT_CHARACTER, OP_STORIES, type OpStory, PARAGRAPH_MARK_FORMATTING_KEYS, PROPERTY_REVIEW_POLICIES, type PackageResourceEntry, type PackageResourceEntryChange, type PackageResourceMapChange, type PackageResourceMedia, type PackageResourcePart, type PackageResources, type ParagraphPropsPatch, type ParagraphReviewFields, type PlanTrackedDeletionOptions, type PlanTrackedReplaceOptions, REVISION_DECISIONS, type RemoveHeaderFooterOp, type RemoveNoteOp, type ReplaceBlocksOp, type ReplaceInlineOp, type ResolveRevisionOp, type RestoreCommentStateOp, type RestoreStoryPartsOp, type RevisionDecision, type RevisionStamp, type RunPropsPatch, SPLIT_HALVES, type SectionEndpoint, type SectionMapState, type SectionPropertiesState, type SectionViewEntry, type SectionViewState, type SequencedBatch, type SetCellPropsOp, type SetCommentResolutionOp, type SetContainerBlocksOp, type SetPackageResourcesOp, type SetParagraphPropsOp, type SetParagraphReviewOp, type SetRowPropsOp, type SetRunPropsOp, type SetSectionEndpointOp, type SetSectionPropsOp, type SetTableGridOp, type SetTableOp, type SetTablePropsOp, type SetTableRowsOp, type SplitBlockOp, type SplitCellOp, type SplitHalf, type SplitInlineOp, type SplitParagraphFields, type TableEditOp, type TableIntentOperation, type TextPosition, type TouchedBlocks, type UpdateCommentContentOp, allocateCommentAnchorIds, applyDocumentOp, applyDocumentOpEnvelope, applyDocumentOps, captureDocumentOp, combineEdits, commentDocumentIssue, compareGaps, compileEditorIntent, createClient, createEditorIntentIdAllocator, createSequencer, defaultInsertionGap, documentStories, editorParagraphGroups, findStoryBody, formattingEquals, freshCommentId, idKey, inlineLeafSpans, isTextOnlyRun, mapTocBookmarkPosition, mergeRunContent, normalizeForOps, noteUsesCustomMark, packageParagraphIds, packageResourcesOpOf, paragraphLength, paragraphLogicalText, paragraphVisibleText, parseDocumentBatch, physicalOffsetAtVisibleOffset, planTrackedDeletion, planTrackedReplace, revisionIdDemand, runsMergeable, sameStory, sectionPropertiesAt, storyBody, toOpEnvelope, transformBatch, validateDocumentBatch, validateOpsDocument, validateSequencedBatch, zeroWidthLeavesAt };