@stll/folio-core 0.54.2 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) hide show
  1. package/dist/ai-edits/apply.js +185 -33
  2. package/dist/ai-edits/headless.js +3 -2
  3. package/dist/ai-edits/types.d.ts +7 -1
  4. package/dist/compare/compare.js +1 -0
  5. package/dist/compare/content-types.d.ts +3 -15
  6. package/dist/compare/reproducible-package.d.ts +0 -17
  7. package/dist/compare/reproducible-package.js +12 -18
  8. package/dist/controller/canonicalClipboard.d.ts +23 -0
  9. package/dist/controller/canonicalClipboard.js +476 -0
  10. package/dist/controller/canonicalClipboardResources.d.ts +21 -0
  11. package/dist/controller/canonicalClipboardResources.js +382 -0
  12. package/dist/controller/canonicalComposition.d.ts +53 -0
  13. package/dist/controller/canonicalComposition.js +296 -0
  14. package/dist/controller/canonicalInlineProjection.d.ts +113 -0
  15. package/dist/controller/canonicalInlineProjection.js +393 -0
  16. package/dist/controller/canonicalInput.d.ts +54 -0
  17. package/dist/controller/canonicalInput.js +377 -0
  18. package/dist/controller/canonicalInputTimer.d.ts +7 -0
  19. package/dist/controller/canonicalInputTimer.js +11 -0
  20. package/dist/controller/canonicalOperations.d.ts +22 -0
  21. package/dist/controller/canonicalOperations.js +85 -0
  22. package/dist/controller/canonicalPublicOperations.d.ts +48 -0
  23. package/dist/controller/canonicalPublicOperations.js +556 -0
  24. package/dist/controller/canonicalReview.d.ts +12 -0
  25. package/dist/controller/canonicalReview.js +19 -0
  26. package/dist/controller/canonicalSession.d.ts +167 -0
  27. package/dist/controller/canonicalSession.js +1186 -0
  28. package/dist/controller/canonicalStoryEditor.d.ts +36 -0
  29. package/dist/controller/canonicalStoryEditor.js +87 -0
  30. package/dist/controller/canonicalStructure.d.ts +16 -0
  31. package/dist/controller/canonicalStructure.js +322 -0
  32. package/dist/controller/canonicalTocSelection.d.ts +11 -0
  33. package/dist/controller/canonicalTocSelection.js +43 -0
  34. package/dist/controller/folioEditor.d.ts +3 -10
  35. package/dist/controller/folioEditor.js +14 -4
  36. package/dist/controller/headerFooterEditorManager.d.ts +5 -0
  37. package/dist/controller/headerFooterEditorManager.js +72 -3
  38. package/dist/controller/hiddenEditorApi.d.ts +45 -0
  39. package/dist/controller/hiddenEditorApi.js +29 -8
  40. package/dist/controller/hiddenEditorManager.d.ts +13 -2
  41. package/dist/controller/hiddenEditorManager.js +639 -31
  42. package/dist/controller/layoutPipeline.d.ts +1 -1
  43. package/dist/controller/layoutPipeline.js +2 -0
  44. package/dist/controller/noteEditorManager.d.ts +5 -0
  45. package/dist/controller/noteEditorManager.js +114 -15
  46. package/dist/document-operations.d.ts +8 -1
  47. package/dist/document-operations.js +6 -4
  48. package/dist/docx/attributeRemainder.js +1 -0
  49. package/dist/docx/blockPlainText.d.ts +1 -1
  50. package/dist/docx/blockPlainText.js +11 -3
  51. package/dist/docx/canonicalResourceSave.d.ts +16 -0
  52. package/dist/docx/canonicalResourceSave.js +27 -0
  53. package/dist/docx/canonicalSave.d.ts +29 -0
  54. package/dist/docx/canonicalSave.js +101 -0
  55. package/dist/docx/canonicalSessionInput.d.ts +11 -0
  56. package/dist/docx/canonicalSessionInput.js +27 -0
  57. package/dist/docx/canonicalStoryRepack.d.ts +10 -0
  58. package/dist/docx/canonicalStoryRepack.js +74 -0
  59. package/dist/docx/contentTypeRegistry.d.ts +8 -0
  60. package/dist/docx/contentTypeRegistry.js +64 -0
  61. package/dist/docx/documentParser.d.ts +1 -13
  62. package/dist/docx/documentParser.js +1 -47
  63. package/dist/docx/ensureParaIds.d.ts +7 -1
  64. package/dist/docx/ensureParaIds.js +173 -215
  65. package/dist/docx/foldedListNumberFields.d.ts +85 -0
  66. package/dist/docx/foldedListNumberFields.js +267 -0
  67. package/dist/docx/footnoteParser.d.ts +1 -11
  68. package/dist/docx/footnoteParser.js +1 -16
  69. package/dist/docx/headerFooterParser.d.ts +1 -9
  70. package/dist/docx/headerFooterParser.js +1 -12
  71. package/dist/docx/headerFooterVerbatim.d.ts +39 -1
  72. package/dist/docx/headerFooterVerbatim.js +173 -2
  73. package/dist/docx/imageParser.d.ts +13 -1
  74. package/dist/docx/imageParser.js +20 -11
  75. package/dist/docx/metadataPrivacy.js +6 -1
  76. package/dist/docx/noteIds.d.ts +5 -0
  77. package/dist/docx/noteIds.js +6 -2
  78. package/dist/docx/noteReferenceMark.d.ts +3 -1
  79. package/dist/docx/noteReferenceMark.js +15 -14
  80. package/dist/docx/numberingParser.d.ts +3 -1
  81. package/dist/docx/numberingParser.js +17 -3
  82. package/dist/docx/packageParts.d.ts +3 -1
  83. package/dist/docx/packageParts.js +74 -19
  84. package/dist/docx/paragraphMarkPropertyPresence.d.ts +9 -0
  85. package/dist/docx/paragraphMarkPropertyPresence.js +21 -0
  86. package/dist/docx/paragraphParser.js +101 -53
  87. package/dist/docx/paragraphPropertySource.d.ts +15 -1
  88. package/dist/docx/paragraphPropertySource.js +77 -22
  89. package/dist/docx/parser.js +3 -1
  90. package/dist/docx/removeHeaderFooterParts.js +17 -6
  91. package/dist/docx/reviewHistoryNamespace.d.ts +4 -0
  92. package/dist/docx/reviewHistoryNamespace.js +4 -0
  93. package/dist/docx/reviewResolutionProvenance.d.ts +25 -0
  94. package/dist/docx/reviewResolutionProvenance.js +153 -0
  95. package/dist/docx/rezip.d.ts +54 -6
  96. package/dist/docx/rezip.js +835 -257
  97. package/dist/docx/runConsolidator.d.ts +2 -58
  98. package/dist/docx/runConsolidator.js +3 -175
  99. package/dist/docx/runParser.d.ts +2 -1
  100. package/dist/docx/runParser.js +156 -116
  101. package/dist/docx/saveDiagnostics.d.ts +22 -0
  102. package/dist/docx/saveDiagnostics.js +0 -0
  103. package/dist/docx/selectiveSave.d.ts +3 -1
  104. package/dist/docx/selectiveSave.js +36 -4
  105. package/dist/docx/selectiveXmlPatch.d.ts +16 -8
  106. package/dist/docx/selectiveXmlPatch.js +81 -7
  107. package/dist/docx/serializer/documentSerializer.d.ts +9 -2
  108. package/dist/docx/serializer/documentSerializer.js +29 -10
  109. package/dist/docx/serializer/headerFooterSerializer.d.ts +5 -1
  110. package/dist/docx/serializer/headerFooterSerializer.js +19 -11
  111. package/dist/docx/serializer/noteSerializer.d.ts +2 -2
  112. package/dist/docx/serializer/noteSerializer.js +24 -8
  113. package/dist/docx/serializer/paragraphSerializer.js +41 -4
  114. package/dist/docx/serializer/partNamespaces.js +2 -1
  115. package/dist/docx/serializer/runSerializer.js +3 -1
  116. package/dist/docx/server/applyDocxXmlPatchProposal.js +14 -9
  117. package/dist/docx/settingsHeaderFooterUpdate.d.ts +5 -0
  118. package/dist/docx/settingsHeaderFooterUpdate.js +90 -0
  119. package/dist/docx/settingsParser.d.ts +1 -2
  120. package/dist/docx/settingsParser.js +5 -6
  121. package/dist/docx/storyBlockReplay.d.ts +31 -0
  122. package/dist/docx/storyBlockReplay.js +471 -0
  123. package/dist/docx/storyPlainText.d.ts +20 -0
  124. package/dist/docx/storyPlainText.js +23 -0
  125. package/dist/docx/streamingXmlParser.d.ts +22 -1
  126. package/dist/docx/streamingXmlParser.js +49 -3
  127. package/dist/docx/structuralXmlPatch.js +18 -23
  128. package/dist/docx/styleParser.d.ts +5 -1
  129. package/dist/docx/styleParser.js +1 -1
  130. package/dist/docx/tableParser.d.ts +1 -8
  131. package/dist/docx/tableParser.js +1 -28
  132. package/dist/docx/textBoxParser.d.ts +1 -5
  133. package/dist/docx/textBoxParser.js +1 -20
  134. package/dist/docx/unzip.js +6 -1
  135. package/dist/docx/verbatimCapture.d.ts +3 -1
  136. package/dist/docx/verbatimCapture.js +49 -6
  137. package/dist/i18n/messages/ar.gen.d.ts +5 -0
  138. package/dist/i18n/messages/ar.gen.js +656 -0
  139. package/dist/i18n/messages/cs.gen.d.ts +5 -0
  140. package/dist/i18n/messages/cs.gen.js +656 -0
  141. package/dist/i18n/messages/de.gen.d.ts +5 -0
  142. package/dist/i18n/messages/de.gen.js +656 -0
  143. package/dist/i18n/messages/en.gen.d.ts +5 -0
  144. package/dist/i18n/messages/en.gen.js +656 -0
  145. package/dist/i18n/messages/es.gen.d.ts +5 -0
  146. package/dist/i18n/messages/es.gen.js +656 -0
  147. package/dist/i18n/messages/et.gen.d.ts +5 -0
  148. package/dist/i18n/messages/et.gen.js +656 -0
  149. package/dist/i18n/messages/fr.gen.d.ts +5 -0
  150. package/dist/i18n/messages/fr.gen.js +656 -0
  151. package/dist/i18n/messages/he.gen.d.ts +5 -0
  152. package/dist/i18n/messages/he.gen.js +656 -0
  153. package/dist/i18n/messages/hi.gen.d.ts +5 -0
  154. package/dist/i18n/messages/hi.gen.js +656 -0
  155. package/dist/i18n/messages/hu.gen.d.ts +5 -0
  156. package/dist/i18n/messages/hu.gen.js +656 -0
  157. package/dist/i18n/messages/locales.d.ts +5 -0
  158. package/dist/i18n/messages/locales.js +22 -0
  159. package/dist/i18n/messages/lt.gen.d.ts +5 -0
  160. package/dist/i18n/messages/lt.gen.js +656 -0
  161. package/dist/i18n/messages/lv.gen.d.ts +5 -0
  162. package/dist/i18n/messages/lv.gen.js +656 -0
  163. package/dist/i18n/messages/pl.gen.d.ts +5 -0
  164. package/dist/i18n/messages/pl.gen.js +656 -0
  165. package/dist/i18n/messages/pt-BR.gen.d.ts +5 -0
  166. package/dist/i18n/messages/pt-BR.gen.js +656 -0
  167. package/dist/i18n/messages/sk.gen.d.ts +5 -0
  168. package/dist/i18n/messages/sk.gen.js +656 -0
  169. package/dist/i18n/messages/tr.gen.d.ts +5 -0
  170. package/dist/i18n/messages/tr.gen.js +656 -0
  171. package/dist/i18n/messages/zh-CN.gen.d.ts +5 -0
  172. package/dist/i18n/messages/zh-CN.gen.js +656 -0
  173. package/dist/i18n/messages.d.ts +2 -3
  174. package/dist/i18n/messages.js +1 -19
  175. package/dist/internal/acceptedBlockProjection.d.ts +12 -0
  176. package/dist/internal/acceptedBlockProjection.js +45 -0
  177. package/dist/internal/noteMarkerAttrs.d.ts +8 -0
  178. package/dist/internal/noteMarkerAttrs.js +16 -0
  179. package/dist/internal/pageBreakRunSourceDescendantIndex.js +1 -0
  180. package/dist/internal/prosemirrorAttrBoundary.d.ts +21 -0
  181. package/dist/internal/prosemirrorAttrBoundary.js +50 -0
  182. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  183. package/dist/layout-bridge/convert/footnoteLayout.js +3 -3
  184. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  185. package/dist/layout-bridge/convert/headerFooterLayout.js +1 -0
  186. package/dist/layout-bridge/convert/noteReferences.d.ts +1 -3
  187. package/dist/layout-bridge/convert/noteReferences.js +1 -6
  188. package/dist/layout-bridge/convert/paragraphRuns.js +2 -4
  189. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -2
  190. package/dist/layout-bridge/convert/toFlowBlocks.js +2 -2
  191. package/dist/managers/DocumentLoaderManager.d.ts +1 -0
  192. package/dist/managers/DocumentLoaderManager.js +9 -1
  193. package/dist/markdown/escape.d.ts +3 -1
  194. package/dist/markdown/escape.js +9 -2
  195. package/dist/markdown/renderBlock.js +20 -121
  196. package/dist/markdown/renderParagraph.js +13 -15
  197. package/dist/markdown/renderRuns.d.ts +7 -1
  198. package/dist/markdown/renderRuns.js +35 -15
  199. package/dist/markdown/renderTable.js +2 -0
  200. package/dist/markdown/types.d.ts +3 -9
  201. package/dist/prosemirror/attrs/index.d.ts +2 -12
  202. package/dist/prosemirror/attrs/index.js +22 -48
  203. package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -1
  204. package/dist/prosemirror/canonicalCommands.d.ts +121 -0
  205. package/dist/prosemirror/canonicalCommands.js +35 -0
  206. package/dist/prosemirror/canonicalSelectionRange.d.ts +9 -0
  207. package/dist/prosemirror/canonicalSelectionRange.js +15 -0
  208. package/dist/prosemirror/clipboardIntent.d.ts +7 -0
  209. package/dist/prosemirror/clipboardIntent.js +9 -0
  210. package/dist/prosemirror/commands/pageBreak.js +15 -1
  211. package/dist/prosemirror/commands/pastePlainText.js +2 -1
  212. package/dist/prosemirror/commentReferenceAttrs.d.ts +2 -1
  213. package/dist/prosemirror/conversion/fromProseDoc.js +91 -19
  214. package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +8 -0
  215. package/dist/prosemirror/conversion/hyphenTextCarriers.js +8 -0
  216. package/dist/prosemirror/conversion/listRenderingDefinition.d.ts +6 -0
  217. package/dist/prosemirror/conversion/listRenderingDefinition.js +97 -0
  218. package/dist/prosemirror/conversion/toProseDoc.d.ts +11 -4
  219. package/dist/prosemirror/conversion/toProseDoc.js +55 -14
  220. package/dist/prosemirror/executeEditorCommand.d.ts +11 -0
  221. package/dist/prosemirror/executeEditorCommand.js +26 -0
  222. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  223. package/dist/prosemirror/extensions/core/ParagraphExtension.js +88 -48
  224. package/dist/prosemirror/extensions/features/ListExtension.js +18 -5
  225. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +5 -2
  226. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +13 -1
  227. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +56 -28
  228. package/dist/prosemirror/extensions/marks/TextColorExtension.js +3 -2
  229. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -0
  230. package/dist/prosemirror/extensions/marks/markUtils.js +72 -8
  231. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.d.ts +6 -0
  232. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +36 -0
  233. package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +4 -2
  234. package/dist/prosemirror/insertOperations.js +2 -1
  235. package/dist/prosemirror/listMarker.d.ts +1 -0
  236. package/dist/prosemirror/listMarker.js +16 -7
  237. package/dist/prosemirror/listNumbering.js +26 -5
  238. package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
  239. package/dist/prosemirror/listRenderingAttrs.js +3 -0
  240. package/dist/prosemirror/markupViewNotes.js +3 -2
  241. package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +2 -1
  242. package/dist/prosemirror/noteReferenceReview.js +5 -3
  243. package/dist/prosemirror/paragraphPropertyCarry.d.ts +7 -1
  244. package/dist/prosemirror/paragraphPropertyCarry.js +8 -3
  245. package/dist/prosemirror/plugins/suggestionMode.js +57 -7
  246. package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -1
  247. package/dist/prosemirror/runFormattingFromMarks.d.ts +4 -1
  248. package/dist/prosemirror/runFormattingFromMarks.js +15 -1
  249. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -1
  250. package/dist/prosemirror/runFormattingInlineCarriers.js +4 -1
  251. package/dist/prosemirror/schema/marks.d.ts +2 -0
  252. package/dist/prosemirror/schema/nodes.d.ts +10 -2
  253. package/dist/prosemirror/textBoxAnchorAttrs.d.ts +2 -1
  254. package/dist/prosemirror/textInput.js +5 -1
  255. package/dist/prosemirror/trackedRevisionPath.js +2 -1
  256. package/dist/prosemirror/trackedRunInlineAtoms.d.ts +1 -0
  257. package/dist/prosemirror/trackedRunInlineAtoms.js +1 -0
  258. package/dist/prosemirror/validation.js +4 -0
  259. package/dist/types/canonicalCapabilities.d.ts +215 -0
  260. package/dist/types/canonicalCapabilities.js +212 -0
  261. package/dist/types/canonicalSave.d.ts +11 -0
  262. package/dist/types/canonicalSave.js +0 -0
  263. package/dist/types/content.d.ts +2 -2
  264. package/dist/types/docxSerialization.d.ts +14 -0
  265. package/dist/types/docxSerialization.js +7 -0
  266. package/dist/utils/createDocument.js +2 -2
  267. package/package.json +16 -4
@@ -0,0 +1,4 @@
1
+ //#region src/docx/reviewHistoryNamespace.ts
2
+ const FOLIO_REVIEW_HISTORY_NAMESPACE = "urn:stella:folio:review-history:1";
3
+ //#endregion
4
+ export { FOLIO_REVIEW_HISTORY_NAMESPACE };
@@ -0,0 +1,25 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { XmlElement } from "./xmlParser.js";
3
+ //#region src/docx/reviewResolutionProvenance.d.ts
4
+ type ResolutionJoins = NonNullable<document_d_exports.Insertion["resolutionJoins"]>;
5
+ type BoundaryJoins = NonNullable<document_d_exports.RunPropertyChange["boundaryJoins"]>;
6
+ declare const isResolutionJoins: (value: unknown) => value is ResolutionJoins;
7
+ declare const isParagraphMarkResolutionJoin: (value: unknown) => value is NonNullable<document_d_exports.ParagraphMarkChange["resolutionJoin"]>;
8
+ declare const isBoundaryJoins: (value: unknown) => value is BoundaryJoins;
9
+ declare const ReviewResolutionProvenanceError_base: import("better-result").TaggedErrorClass<"ReviewResolutionProvenanceError">;
10
+ declare class ReviewResolutionProvenanceError extends ReviewResolutionProvenanceError_base<{
11
+ message: string;
12
+ attribute: string;
13
+ reason: "invalid" | "unsupportedVersion" | "unrepresentable";
14
+ }> {}
15
+ declare const parseResolutionJoins: (node: XmlElement) => ResolutionJoins | undefined;
16
+ declare const parseBoundaryJoins: (node: XmlElement) => BoundaryJoins | undefined;
17
+ declare const serializeResolutionJoins: (value: document_d_exports.Insertion["resolutionJoins"]) => string;
18
+ declare const serializeBoundaryJoins: (value: document_d_exports.RunPropertyChange["boundaryJoins"]) => string;
19
+ /** Null carries an owned undefined depth; a missing attribute carries no field. */
20
+ declare const parseParagraphMarkResolutionJoin: (node: XmlElement) => Pick<document_d_exports.ParagraphMarkChange, "resolutionJoin">;
21
+ declare const serializeParagraphMarkResolutionJoin: (mark: document_d_exports.ParagraphMarkChange) => string;
22
+ /** Captured paragraph properties compose the same envelope into a parsed XML element. */
23
+ declare const paragraphMarkResolutionJoinAttributes: (mark: document_d_exports.ParagraphMarkChange) => Record<string, string>;
24
+ //#endregion
25
+ export { ReviewResolutionProvenanceError, isBoundaryJoins, isParagraphMarkResolutionJoin, isResolutionJoins, paragraphMarkResolutionJoinAttributes, parseBoundaryJoins, parseParagraphMarkResolutionJoin, parseResolutionJoins, serializeBoundaryJoins, serializeParagraphMarkResolutionJoin, serializeResolutionJoins };
@@ -0,0 +1,153 @@
1
+ import { FOLIO_REVIEW_HISTORY_NAMESPACE } from "./reviewHistoryNamespace.js";
2
+ import { getAttributeByNamespaceUri } from "./xmlParser.js";
3
+ import { Result, TaggedError } from "better-result";
4
+ import { escapeXmlAttribute } from "@stll/docx-core";
5
+ import { MAX_REVISION_ID } from "@stll/docx-core/model";
6
+ //#region src/docx/reviewResolutionProvenance.ts
7
+ const NAMESPACES = /* @__PURE__ */ new Set([FOLIO_REVIEW_HISTORY_NAMESPACE]);
8
+ const VERSION = 1;
9
+ const MAX_ATTRIBUTE_LENGTH = 32768;
10
+ const SLOT_FIELDS = {
11
+ space: true,
12
+ id: true
13
+ };
14
+ const RETAINED_FIELDS = {
15
+ depth: true,
16
+ source: true,
17
+ target: true
18
+ };
19
+ const JOIN_FIELDS = {
20
+ before: true,
21
+ after: true,
22
+ remove: true,
23
+ retainedAfter: true,
24
+ deferredRemove: true,
25
+ acceptance: true
26
+ };
27
+ const ACCEPTANCE_POLICIES = { "merge-plain-runs": true };
28
+ const PARAGRAPH_MARK_FIELDS = {
29
+ kind: { type: "ooxml" },
30
+ info: { type: "ooxml" },
31
+ resolutionJoin: {
32
+ type: "private",
33
+ attribute: "resolutionJoin"
34
+ }
35
+ };
36
+ const DEFERRED_REMOVAL_FIELDS = {
37
+ depth: true,
38
+ blockers: true
39
+ };
40
+ const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
41
+ const natural = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
42
+ const slots = (value) => Array.isArray(value) && value.every((slot) => record(slot) && Object.keys(slot).every((key) => Object.hasOwn(SLOT_FIELDS, key)) && (slot["space"] === "revision" || slot["space"] === "control") && natural(slot["id"]) && slot["id"] <= MAX_REVISION_ID);
43
+ const retained = (value) => Array.isArray(value) && value.every((item) => {
44
+ if (!record(item)) return false;
45
+ const source = item["source"];
46
+ const target = item["target"];
47
+ return Object.keys(item).every((key) => Object.hasOwn(RETAINED_FIELDS, key)) && natural(item["depth"]) && slots(source) && slots(target) && source.length === target.length && source.every((slot, index) => slot.space === target.at(index)?.space);
48
+ });
49
+ const deferredRemoval = (value) => {
50
+ if (!record(value) || Object.keys(value).some((key) => !Object.hasOwn(DEFERRED_REMOVAL_FIELDS, key))) return false;
51
+ const depth = value["depth"];
52
+ const blockers = value["blockers"];
53
+ return natural(depth) && depth <= MAX_REVISION_ID && Array.isArray(blockers) && blockers.length > 0 && !blockers.includes(void 0) && new Set(blockers).size === blockers.length && blockers.every((blocker) => natural(blocker) && blocker <= MAX_REVISION_ID);
54
+ };
55
+ const deferredRemovals = (value) => {
56
+ if (!Array.isArray(value) || value.length === 0 || value.includes(void 0) || !value.every(deferredRemoval)) return false;
57
+ const groups = value.map(({ depth, blockers }) => JSON.stringify({
58
+ depth,
59
+ blockers
60
+ }));
61
+ return new Set(groups).size === groups.length;
62
+ };
63
+ const isResolutionJoins = (value) => record(value) && Object.keys(value).every((key) => Object.hasOwn(JOIN_FIELDS, key)) && natural(value["before"]) && natural(value["after"]) && natural(value["remove"]) && (!Object.hasOwn(value, "acceptance") || typeof value["acceptance"] === "string" && Object.hasOwn(ACCEPTANCE_POLICIES, value["acceptance"])) && (value["retainedAfter"] === void 0 || retained(value["retainedAfter"])) && (!Object.hasOwn(value, "deferredRemove") || deferredRemovals(value["deferredRemove"]));
64
+ const isParagraphMarkResolutionJoin = (value) => natural(value) && value <= MAX_REVISION_ID;
65
+ const isEncodedParagraphMarkResolutionJoin = (value) => value === null || isParagraphMarkResolutionJoin(value);
66
+ const isBoundaryJoins = (value) => Array.isArray(value) && value.length <= 2 && new Set(value).size === value.length && value.every((side) => side === "before" || side === "after");
67
+ var ReviewResolutionProvenanceError = class extends TaggedError("ReviewResolutionProvenanceError") {};
68
+ const parseAttribute = ({ node, attribute, valid }) => {
69
+ const encoded = getAttributeByNamespaceUri(node, NAMESPACES, attribute);
70
+ if (encoded === null) return void 0;
71
+ const failed = (reason = "invalid") => new ReviewResolutionProvenanceError({
72
+ attribute,
73
+ message: `Invalid or unsupported ${attribute} review provenance.`,
74
+ reason
75
+ });
76
+ if (encoded.length > MAX_ATTRIBUTE_LENGTH) throw failed();
77
+ const parsed = Result.try({
78
+ try: () => JSON.parse(encoded),
79
+ catch: () => failed()
80
+ });
81
+ if (parsed.isErr()) throw parsed.error;
82
+ const decoded = parsed.value;
83
+ if (!record(decoded) || Object.keys(decoded).some((key) => key !== "version" && key !== "value")) throw failed();
84
+ const value = decoded["value"];
85
+ if (!valid(value)) throw failed();
86
+ if (decoded["version"] !== VERSION) throw failed("unsupportedVersion");
87
+ return value;
88
+ };
89
+ const encodeAttribute = ({ attribute, value, valid }) => {
90
+ if (value === void 0) return void 0;
91
+ if (!valid(value)) throw new ReviewResolutionProvenanceError({
92
+ attribute,
93
+ reason: "invalid",
94
+ message: `Invalid or oversized ${attribute} review provenance.`
95
+ });
96
+ const encoded = JSON.stringify({
97
+ version: VERSION,
98
+ value
99
+ });
100
+ if (encoded.length > MAX_ATTRIBUTE_LENGTH) throw new ReviewResolutionProvenanceError({
101
+ attribute,
102
+ reason: "invalid",
103
+ message: `Oversized ${attribute} review provenance.`
104
+ });
105
+ return encoded;
106
+ };
107
+ const serializeAttribute = (options) => {
108
+ const encoded = encodeAttribute(options);
109
+ return encoded === void 0 ? "" : ` folio:${options.attribute}="${escapeXmlAttribute(encoded)}"`;
110
+ };
111
+ const parseResolutionJoins = (node) => parseAttribute({
112
+ node,
113
+ attribute: "resolutionJoins",
114
+ valid: isResolutionJoins
115
+ });
116
+ const parseBoundaryJoins = (node) => parseAttribute({
117
+ node,
118
+ attribute: "boundaryJoins",
119
+ valid: isBoundaryJoins
120
+ });
121
+ const serializeResolutionJoins = (value) => serializeAttribute({
122
+ attribute: "resolutionJoins",
123
+ value,
124
+ valid: isResolutionJoins
125
+ });
126
+ const serializeBoundaryJoins = (value) => serializeAttribute({
127
+ attribute: "boundaryJoins",
128
+ value,
129
+ valid: isBoundaryJoins
130
+ });
131
+ /** Null carries an owned undefined depth; a missing attribute carries no field. */
132
+ const parseParagraphMarkResolutionJoin = (node) => {
133
+ const value = parseAttribute({
134
+ node,
135
+ attribute: PARAGRAPH_MARK_FIELDS.resolutionJoin.attribute,
136
+ valid: isEncodedParagraphMarkResolutionJoin
137
+ });
138
+ return value === void 0 ? {} : { resolutionJoin: value === null ? void 0 : value };
139
+ };
140
+ const paragraphMarkResolutionJoinOptions = (mark) => ({
141
+ attribute: PARAGRAPH_MARK_FIELDS.resolutionJoin.attribute,
142
+ value: Object.hasOwn(mark, "resolutionJoin") ? mark.resolutionJoin ?? null : void 0,
143
+ valid: isEncodedParagraphMarkResolutionJoin
144
+ });
145
+ const serializeParagraphMarkResolutionJoin = (mark) => serializeAttribute(paragraphMarkResolutionJoinOptions(mark));
146
+ /** Captured paragraph properties compose the same envelope into a parsed XML element. */
147
+ const paragraphMarkResolutionJoinAttributes = (mark) => {
148
+ const options = paragraphMarkResolutionJoinOptions(mark);
149
+ const encoded = encodeAttribute(options);
150
+ return encoded === void 0 ? {} : { [`folio:${options.attribute}`]: encoded };
151
+ };
152
+ //#endregion
153
+ export { ReviewResolutionProvenanceError, isBoundaryJoins, isParagraphMarkResolutionJoin, isResolutionJoins, paragraphMarkResolutionJoinAttributes, parseBoundaryJoins, parseParagraphMarkResolutionJoin, parseResolutionJoins, serializeBoundaryJoins, serializeParagraphMarkResolutionJoin, serializeResolutionJoins };
@@ -1,5 +1,8 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
+ import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
3
+ import { SaveDiagnosticOptions } from "./saveDiagnostics.js";
2
4
  import { BlockContent, Hyperlink } from "../types/content.js";
5
+ import { DocumentBodyAuthorityOptions } from "./serializer/documentSerializer.js";
3
6
  import { RawDocxContent } from "./unzip.js";
4
7
  import JSZip from "jszip";
5
8
  //#region src/docx/rezip.d.ts
@@ -37,16 +40,46 @@ declare class DocxDuplicateSectionCarrierError extends DocxPackageFidelityError
37
40
  */
38
41
  declare function findMaxRId(relsXml: string): number;
39
42
  /**
40
- * Collect all hyperlinks that have an href but no rId from block content.
41
- * These are newly created hyperlinks that need relationship entries.
43
+ * Every serialized section has exactly one model record, and vice versa.
44
+ *
45
+ * A split paragraph's duplicated `w:sectPr` is a section nobody added,
46
+ * repeating the real one's `w:rsidSect` and claiming its revision history too.
47
+ * Two carriers over one record are therefore invalid regardless of whether a
48
+ * separate deletion makes the total section count rise, fall, or stay equal.
49
+ *
50
+ * The count is a separate invariant: `serializeSectionProperties` fails closed
51
+ * to `""` for a record holding settings it cannot write, so carrier uniqueness
52
+ * alone does not prove the package states the sections the model holds.
42
53
  */
54
+ declare const assertSectionCarriersMatchModel: ({ doc, serializedSectionCount }: {
55
+ doc: document_d_exports.Document;
56
+ serializedSectionCount: number;
57
+ }) => void;
58
+ declare const CanonicalImageRelationshipRefusalError_base: import("better-result").TaggedErrorClass<"CanonicalImageRelationshipRefusalError">;
59
+ declare class CanonicalImageRelationshipRefusalError extends CanonicalImageRelationshipRefusalError_base<{
60
+ message: string;
61
+ gap: typeof CANONICAL_GAP.save;
62
+ part: string;
63
+ relationshipId: string;
64
+ reason: "conflict" | "unresolved" | "missingMedia" | "unsafeTarget";
65
+ }> {}
66
+ type PublishCanonicalImageResourcesOptions = {
67
+ document: document_d_exports.Document;
68
+ zip: JSZip;
69
+ compressionLevel: number;
70
+ };
71
+ /** Publish allocated pictures into each owning story without rebinding canonical ids. */
72
+ declare const publishCanonicalImageResources: ({ document, zip, compressionLevel }: PublishCanonicalImageResourcesOptions) => Promise<void>;
73
+ /** Newly authored text links; the census shares the complete owning-part traversal. */
43
74
  declare function collectHyperlinksWithoutRId(blocks: BlockContent[]): Hyperlink[];
44
75
  /** The selective save boundary must use the same resource census as full repack. */
45
76
  declare const hasUnmaterializedInlineResources: (blocks: BlockContent[]) => boolean;
77
+ /** Compare against the already loaded source ZIP, without mutating model or package. */
78
+ declare const hasUnmaterializedHyperlinkBindings: (document: document_d_exports.Document, zip: JSZip) => Promise<boolean>;
46
79
  /**
47
80
  * Options for repacking DOCX
48
81
  */
49
- type RepackOptions = {
82
+ type RepackOptions = SaveDiagnosticOptions & DocumentBodyAuthorityOptions & {
50
83
  /** Compression level (0-9, default: 6) */
51
84
  compressionLevel?: number;
52
85
  /** Whether to update modification date in docProps/core.xml */
@@ -185,7 +218,22 @@ declare function hasModelDrivenPictureWatermark(doc: document_d_exports.Document
185
218
  * `sourceZip` supplies each part as it stands before the save so the rebuilt
186
219
  * root can keep any prefix binding only the source document declared.
187
220
  */
188
- declare function collectHeaderFooterUpdates(doc: document_d_exports.Document, sourceZip: JSZip): Promise<Map<string, string>>;
221
+ type CollectHeaderFooterUpdatesOptions = SaveDiagnosticOptions & {
222
+ sourceZip: JSZip;
223
+ };
224
+ declare function collectHeaderFooterUpdates(doc: document_d_exports.Document, { sourceZip, onDiagnostic }: CollectHeaderFooterUpdatesOptions): Promise<Map<string, string>>;
225
+ type AddedStylesPlan = {
226
+ type: "unchanged";
227
+ } | {
228
+ type: "materialize";
229
+ styles: document_d_exports.StyleDefinitions;
230
+ } | {
231
+ type: "patch";
232
+ path: string;
233
+ xml: string;
234
+ };
235
+ /** One append-only style owner for full repack and selective overlays. */
236
+ declare function planAddedStyles(doc: document_d_exports.Document, originalZip: JSZip): Promise<AddedStylesPlan>;
189
237
  /** `word/Footnotes.xml` -> `word/_rels/Footnotes.xml.rels` (casing preserved). */
190
238
  declare function notePartRelsPath(partPath: string): string;
191
239
  /** Update existing core-property values without synthesizing absent metadata. */
@@ -219,7 +267,7 @@ declare function isDocxBuffer(buffer: ArrayBuffer): boolean;
219
267
  * ignored for a document that carries a source package, which keeps the
220
268
  * properties that package already states.
221
269
  */
222
- type DocumentPropertiesOptions = {
270
+ type DocumentPropertiesOptions = SaveDiagnosticOptions & DocumentBodyAuthorityOptions & {
223
271
  /** `dc:creator` in `docProps/core.xml`. Omitted when absent. */
224
272
  creator?: string;
225
273
  /** `Application` in `docProps/app.xml`. Omitted, with `AppVersion`, when absent. */
@@ -242,4 +290,4 @@ declare function createEmptyDocx(properties?: DocumentPropertiesOptions): Promis
242
290
  */
243
291
  declare function createDocx(doc: document_d_exports.Document, properties?: DocumentPropertiesOptions): Promise<ArrayBuffer>;
244
292
  //#endregion
245
- export { COMMENTS_CONTENT_TYPE, COMMENTS_EXTENDED_CONTENT_TYPE, COMMENTS_EXTENDED_PART, COMMENTS_EXTENDED_PART_LOWER, DocumentPropertiesOptions, DocxDuplicateSectionCarrierError, DocxPackageFidelityError, RepackOptions, addCommentsExtendedOverride, addCommentsExtendedRelationship, addMedia, addRelationship, applyUpdatesToZip, collectHeaderFooterUpdates, collectHyperlinksWithoutRId, createDocx, createEmptyDocx, findMaxRId, hasModelDrivenPictureWatermark, hasUnmaterializedHeaderFooter, hasUnmaterializedInlineResources, isDocxBuffer, notePartRelsPath, removeCommentsExtendedOverride, removeCommentsExtendedRelationship, repackDocx, repackDocxFromRaw, updateCoreProperties, updateDocumentXml, updateMultipleFiles, updateXmlFile, validateDocx, withoutAttachedTemplate };
293
+ export { COMMENTS_CONTENT_TYPE, COMMENTS_EXTENDED_CONTENT_TYPE, COMMENTS_EXTENDED_PART, COMMENTS_EXTENDED_PART_LOWER, CanonicalImageRelationshipRefusalError, DocumentPropertiesOptions, DocxDuplicateSectionCarrierError, DocxPackageFidelityError, RepackOptions, addCommentsExtendedOverride, addCommentsExtendedRelationship, addMedia, addRelationship, applyUpdatesToZip, assertSectionCarriersMatchModel, collectHeaderFooterUpdates, collectHyperlinksWithoutRId, createDocx, createEmptyDocx, findMaxRId, hasModelDrivenPictureWatermark, hasUnmaterializedHeaderFooter, hasUnmaterializedHyperlinkBindings, hasUnmaterializedInlineResources, isDocxBuffer, notePartRelsPath, planAddedStyles, publishCanonicalImageResources, removeCommentsExtendedOverride, removeCommentsExtendedRelationship, repackDocx, repackDocxFromRaw, updateCoreProperties, updateDocumentXml, updateMultipleFiles, updateXmlFile, validateDocx, withoutAttachedTemplate };