@stll/folio-core 0.72.0 → 0.74.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 (244) hide show
  1. package/README.md +12 -6
  2. package/dist/ai-edits/applyTypes.d.ts +85 -0
  3. package/dist/ai-edits/applyTypes.js +24 -0
  4. package/dist/ai-edits/clean-text.d.ts +7 -1
  5. package/dist/ai-edits/clean-text.js +23 -2
  6. package/dist/ai-edits/finalSectionReview.d.ts +1 -1
  7. package/dist/ai-edits/headless.d.ts +29 -147
  8. package/dist/ai-edits/headless.js +215 -1639
  9. package/dist/ai-edits/index.d.ts +3 -3
  10. package/dist/ai-edits/index.js +2 -3
  11. package/dist/ai-edits/pending-suggestions.d.ts +14 -4
  12. package/dist/ai-edits/pending-suggestions.js +183 -90
  13. package/dist/ai-edits/pendingJoin.js +6 -1
  14. package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
  15. package/dist/ai-edits/snapshot.js +9 -4
  16. package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
  17. package/dist/ai-edits/table-cell-mutations.js +2 -2
  18. package/dist/ai-edits/table-geometry.d.ts +1 -1
  19. package/dist/ai-edits/table-geometry.js +1 -1
  20. package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
  21. package/dist/ai-edits/table-row-column-mutations.js +1 -1
  22. package/dist/ai-edits/tableNodes.d.ts +38 -0
  23. package/dist/ai-edits/tableNodes.js +86 -0
  24. package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
  25. package/dist/ai-edits/tracked-batch-fidelity.js +1 -1
  26. package/dist/ai-edits/undefinedReferences.d.ts +7 -0
  27. package/dist/canonical/batchCommentReferences.js +1 -0
  28. package/dist/canonical/canonicalInlineGaps.d.ts +56 -0
  29. package/dist/canonical/canonicalInlineGaps.js +118 -0
  30. package/dist/canonical/canonicalInlineProjection.d.ts +4 -13
  31. package/dist/canonical/canonicalInlineProjection.js +5 -27
  32. package/dist/canonical/canonicalProjectionBlocks.d.ts +4 -4
  33. package/dist/canonical/canonicalPublicOperations.js +282 -75
  34. package/dist/canonical/canonicalSelection.js +1 -1
  35. package/dist/canonical/canonicalSession.d.ts +9 -1
  36. package/dist/canonical/canonicalSession.js +106 -33
  37. package/dist/compare/compare.d.ts +1 -1
  38. package/dist/compare/inline-atoms-model.d.ts +1 -1
  39. package/dist/compare/inline-atoms.d.ts +2 -2
  40. package/dist/compare/inline-provenance-model.d.ts +1 -1
  41. package/dist/compare/inline-provenance.d.ts +2 -2
  42. package/dist/compat/eigenpal.d.ts +3 -3
  43. package/dist/compat/eigenpal.js +2 -3
  44. package/dist/controller/autocompleteSuggestion.js +1 -1
  45. package/dist/controller/canonicalClipboard.d.ts +13 -3
  46. package/dist/controller/canonicalClipboard.js +186 -50
  47. package/dist/controller/canonicalClipboardResources.d.ts +9 -1
  48. package/dist/controller/canonicalClipboardResources.js +22 -2
  49. package/dist/controller/canonicalComposition.js +1 -1
  50. package/dist/controller/canonicalInput.js +1 -1
  51. package/dist/controller/canonicalPresence.js +1 -1
  52. package/dist/controller/canonicalReview.d.ts +1 -1
  53. package/dist/controller/canonicalReview.js +1 -1
  54. package/dist/controller/canonicalRoomAuthority.js +1 -1
  55. package/dist/controller/canonicalRoomWire.js +1 -1
  56. package/dist/controller/canonicalStructure.js +1 -1
  57. package/dist/controller/canonicalTabRoom.js +1 -1
  58. package/dist/controller/canonicalWatermark.d.ts +10 -0
  59. package/dist/controller/canonicalWatermark.js +37 -0
  60. package/dist/controller/canonicalYjsRoom.js +1 -1
  61. package/dist/controller/hiddenEditorApi.d.ts +1 -1
  62. package/dist/controller/hiddenEditorApi.js +2 -17
  63. package/dist/controller/hiddenEditorManager.d.ts +4 -3
  64. package/dist/controller/hiddenEditorManager.js +79 -23
  65. package/dist/document-operations.d.ts +1 -14
  66. package/dist/document-operations.js +1 -278
  67. package/dist/docx/canonicalSave.d.ts +1 -1
  68. package/dist/docx/canonicalSave.js +1 -1
  69. package/dist/docx/canonicalSessionInput.js +1 -1
  70. package/dist/docx/containerChildren.js +1 -1
  71. package/dist/docx/createDocx.d.ts +4 -0
  72. package/dist/docx/createDocx.js +6 -0
  73. package/dist/docx/paragraphParser.js +2 -2
  74. package/dist/docx/paragraphPropertySource.d.ts +1 -1
  75. package/dist/docx/parser.js +1 -1
  76. package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
  77. package/dist/docx/reviewResolutionProvenance.js +31 -8
  78. package/dist/docx/revisionIdNormalization.js +30 -7
  79. package/dist/docx/rezip.d.ts +1 -1
  80. package/dist/docx/rezip.js +1 -1
  81. package/dist/docx/serializer/tableSerializer.js +4 -36
  82. package/dist/docx/server/templatePlan/apply.d.ts +15 -0
  83. package/dist/docx/server/templatePlan/apply.js +658 -0
  84. package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
  85. package/dist/docx/server/templatePlan/blocks.js +355 -0
  86. package/dist/docx/server/templatePlan/builders.d.ts +72 -0
  87. package/dist/docx/server/templatePlan/builders.js +237 -0
  88. package/dist/docx/server/templatePlan/emit.d.ts +118 -0
  89. package/dist/docx/server/templatePlan/emit.js +466 -0
  90. package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
  91. package/dist/docx/server/templatePlan/emphasis.js +173 -0
  92. package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
  93. package/dist/docx/server/templatePlan/inspect.js +230 -0
  94. package/dist/docx/server/templatePlan/labels.d.ts +45 -0
  95. package/dist/docx/server/templatePlan/labels.js +155 -0
  96. package/dist/docx/server/templatePlan/package.d.ts +34 -0
  97. package/dist/docx/server/templatePlan/package.js +99 -0
  98. package/dist/docx/server/templatePlan/plan.d.ts +145 -0
  99. package/dist/docx/server/templatePlan/plan.js +875 -0
  100. package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
  101. package/dist/docx/server/templatePlan/planShape.js +180 -0
  102. package/dist/docx/server/templatePlan/resources.d.ts +41 -0
  103. package/dist/docx/server/templatePlan/resources.js +136 -0
  104. package/dist/docx/server/templatePlan/story.d.ts +128 -0
  105. package/dist/docx/server/templatePlan/story.js +440 -0
  106. package/dist/docx/server/templatePlan/types.d.ts +442 -0
  107. package/dist/docx/server/templatePlan/types.js +29 -0
  108. package/dist/docx/server/templatePlan/verify.d.ts +40 -0
  109. package/dist/docx/server/templatePlan/verify.js +976 -0
  110. package/dist/docx/server/templatePlan/xml.d.ts +74 -0
  111. package/dist/docx/server/templatePlan/xml.js +125 -0
  112. package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
  113. package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
  114. package/dist/docx/structuralXmlPatch.js +9 -1
  115. package/dist/docx/tableGridXml.d.ts +30 -0
  116. package/dist/docx/tableGridXml.js +54 -0
  117. package/dist/docx/tableParser.js +7 -0
  118. package/dist/i18n/loadMessages.d.ts +5 -0
  119. package/dist/i18n/loadMessages.js +46 -0
  120. package/dist/i18n/locales.d.ts +3 -0
  121. package/dist/i18n/locales.js +17 -0
  122. package/dist/i18n/messages.d.ts +3 -2
  123. package/dist/i18n/messages.js +4 -16
  124. package/dist/index.d.ts +3 -3
  125. package/dist/index.js +2 -3
  126. package/dist/internal/clipboardTransformPlugin.d.ts +3 -0
  127. package/dist/internal/clipboardTransformPlugin.js +13 -0
  128. package/dist/internal/extensionRuntime.d.ts +7 -0
  129. package/dist/internal/extensionRuntime.js +28 -0
  130. package/dist/internal/starterKitExtensions.d.ts +20 -0
  131. package/dist/internal/starterKitExtensions.js +123 -0
  132. package/dist/internal/wholeStoryRevisionResolution.js +1 -1
  133. package/dist/managers/ContextMenuManager.js +2 -1
  134. package/dist/managers/editorShortcuts.d.ts +1 -1
  135. package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
  136. package/dist/prosemirror/attrs/index.js +1 -1
  137. package/dist/prosemirror/canonicalCommands.d.ts +1 -1
  138. package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
  139. package/dist/prosemirror/canonicalSelectionRange.js +1 -1
  140. package/dist/prosemirror/canonicalTableCommands.js +3 -3
  141. package/dist/prosemirror/commands/comments.js +4 -4
  142. package/dist/prosemirror/commands/contentControls.d.ts +1 -1
  143. package/dist/prosemirror/commands/contentControls.js +1 -1
  144. package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
  145. package/dist/prosemirror/commands/formatting.d.ts +1 -1
  146. package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
  147. package/dist/prosemirror/commands/pastePlainText.js +2 -3
  148. package/dist/prosemirror/commands/replaceRangeText.js +1 -1
  149. package/dist/prosemirror/commands/sectionBreak.js +1 -1
  150. package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
  151. package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
  152. package/dist/prosemirror/commentRecords.d.ts +1 -1
  153. package/dist/prosemirror/commentRecords.js +2 -2
  154. package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
  155. package/dist/prosemirror/conversion/fromProseDoc.d.ts +0 -5
  156. package/dist/prosemirror/conversion/fromProseDoc.js +2 -9
  157. package/dist/prosemirror/conversion/index.d.ts +2 -2
  158. package/dist/prosemirror/conversion/index.js +2 -2
  159. package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
  160. package/dist/prosemirror/documentStructureCounts.js +76 -0
  161. package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
  162. package/dist/prosemirror/extensions/ExtensionManager.js +4 -22
  163. package/dist/prosemirror/extensions/StarterKit.d.ts +4 -27
  164. package/dist/prosemirror/extensions/StarterKit.js +29 -115
  165. package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
  166. package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
  167. package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
  168. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  169. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +1 -1
  170. package/dist/prosemirror/extensions/features/ListExtension.js +7 -2
  171. package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
  172. package/dist/prosemirror/extensions/index.d.ts +2 -1
  173. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +8 -3
  174. package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
  175. package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
  176. package/dist/prosemirror/extensions/nodes/TableExtension.js +8 -41
  177. package/dist/prosemirror/extensions/types.d.ts +1 -1
  178. package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
  179. package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
  180. package/dist/prosemirror/hyperlinkRemoval.js +7 -2
  181. package/dist/prosemirror/index.d.ts +3 -3
  182. package/dist/prosemirror/index.js +3 -3
  183. package/dist/prosemirror/insertionGaps.d.ts +1 -1
  184. package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
  185. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  186. package/dist/prosemirror/listNumbering.d.ts +1 -1
  187. package/dist/prosemirror/listNumbering.js +1 -1
  188. package/dist/prosemirror/lockedControls.d.ts +1 -1
  189. package/dist/prosemirror/markupViewProjection.d.ts +1 -1
  190. package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
  191. package/dist/prosemirror/noteReferenceOccurrences.js +1 -1
  192. package/dist/prosemirror/noteReferenceReview.d.ts +2 -56
  193. package/dist/prosemirror/noteReferenceReview.js +2 -243
  194. package/dist/prosemirror/{extensions/features/ParaIdAllocatorExtension.d.ts → paraIds.d.ts} +13 -23
  195. package/dist/prosemirror/paraIds.js +152 -0
  196. package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
  197. package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
  198. package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
  199. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
  200. package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
  201. package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
  202. package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
  203. package/dist/prosemirror/plugins/documentNumbering.js +1 -1
  204. package/dist/prosemirror/plugins/documentStyles.js +1 -1
  205. package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
  206. package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
  207. package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
  208. package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
  209. package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
  210. package/dist/prosemirror/replacedAnnotations.js +17 -2
  211. package/dist/prosemirror/revisionCarriers.d.ts +1 -1
  212. package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
  213. package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
  214. package/dist/prosemirror/selectionBounds.d.ts +10 -0
  215. package/dist/prosemirror/selectionBounds.js +22 -0
  216. package/dist/prosemirror/storyListNumbering.d.ts +1 -1
  217. package/dist/prosemirror/suggestionCommands.d.ts +47 -0
  218. package/dist/prosemirror/suggestionCommands.js +31 -0
  219. package/dist/prosemirror/tableCellPaste.d.ts +1 -1
  220. package/dist/prosemirror/tableCellPaste.js +1 -1
  221. package/dist/prosemirror/tableGridMutation.d.ts +1 -1
  222. package/dist/prosemirror/tableRunIn.js +1 -1
  223. package/dist/prosemirror/textInput.d.ts +1 -1
  224. package/dist/prosemirror/textInput.js +1 -1
  225. package/dist/server.d.ts +7 -2
  226. package/dist/server.js +6 -1
  227. package/dist/types/canonicalCapabilities.d.ts +13 -92
  228. package/dist/types/canonicalCapabilities.js +11 -85
  229. package/package.json +4 -4
  230. package/dist/ai-edits/apply.d.ts +0 -202
  231. package/dist/ai-edits/apply.js +0 -6759
  232. package/dist/ai-edits/note-story-inventory.d.ts +0 -5
  233. package/dist/ai-edits/note-story-inventory.js +0 -10
  234. package/dist/ai-edits/revisionStretches.d.ts +0 -32
  235. package/dist/ai-edits/revisionStretches.js +0 -147
  236. package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +0 -18
  237. package/dist/prosemirror/extensions/core/HistoryExtension.js +0 -122
  238. package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +0 -408
  239. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +0 -135
  240. package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +0 -566
  241. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -92
  242. package/dist/prosemirror/plugins/suggestionMode.js +0 -1515
  243. package/dist/prosemirror/tablePositionedBookmarks.d.ts +0 -8
  244. package/dist/prosemirror/tablePositionedBookmarks.js +0 -80
@@ -0,0 +1,173 @@
1
+ import { wAttr, wChild, wChildVal, wChildren } from "./xml.js";
2
+ // src/docx/server/templatePlan/emphasis.ts
3
+ /**
4
+ * In `CT_RPr` order. Bold and italic for complex scripts are properties of
5
+ * their own: a run may state one and not the other.
6
+ */
7
+ const TOGGLES = [
8
+ "b",
9
+ "bCs",
10
+ "i",
11
+ "iCs",
12
+ "caps",
13
+ "smallCaps",
14
+ "strike",
15
+ "dstrike",
16
+ "vanish"
17
+ ];
18
+ const NO_EMPHASIS = Object.freeze({
19
+ b: false,
20
+ bCs: false,
21
+ i: false,
22
+ iCs: false,
23
+ caps: false,
24
+ smallCaps: false,
25
+ strike: false,
26
+ dstrike: false,
27
+ vanish: false,
28
+ u: null,
29
+ vertAlign: null,
30
+ highlight: null
31
+ });
32
+ /** Toggle properties: stated on at two style tiers, they cancel (ECMA-376 §17.7.3). */
33
+ const XOR_TOGGLES = /* @__PURE__ */ new Set([
34
+ "b",
35
+ "bCs",
36
+ "i",
37
+ "iCs",
38
+ "caps",
39
+ "smallCaps",
40
+ "strike",
41
+ "vanish"
42
+ ]);
43
+ const formattingToggle = (rPr, toggle) => {
44
+ switch (toggle) {
45
+ case "b": return rPr?.bold;
46
+ case "bCs": return rPr?.boldCs;
47
+ case "i": return rPr?.italic;
48
+ case "iCs": return rPr?.italicCs;
49
+ case "caps": return rPr?.allCaps;
50
+ case "smallCaps": return rPr?.smallCaps;
51
+ case "strike": return rPr?.strike;
52
+ case "dstrike": return rPr?.doubleStrike;
53
+ case "vanish": return rPr?.hidden;
54
+ default: return toggle;
55
+ }
56
+ };
57
+ const underlineOf = (value) => value === void 0 || value === null || value === "none" ? null : value;
58
+ const vertAlignOf = (value) => value === "superscript" || value === "subscript" ? value : null;
59
+ const highlightOf = (value) => value === void 0 || value === null || value === "none" ? null : value;
60
+ /** `base` under one more style tier's resolved run formatting. */
61
+ const withStyleTier = (base, rPr) => {
62
+ if (rPr === void 0) return base;
63
+ const next = { ...base };
64
+ for (const toggle of TOGGLES) {
65
+ const stated = formattingToggle(rPr, toggle);
66
+ if (XOR_TOGGLES.has(toggle)) {
67
+ if (stated === true) next[toggle] = !base[toggle];
68
+ } else if (stated !== void 0) next[toggle] = stated;
69
+ }
70
+ if (rPr.underline !== void 0) next.u = underlineOf(rPr.underline.style);
71
+ if (rPr.vertAlign !== void 0) next.vertAlign = vertAlignOf(rPr.vertAlign);
72
+ if (rPr.highlight !== void 0) next.highlight = highlightOf(rPr.highlight);
73
+ return next;
74
+ };
75
+ /** The emphasis the document defaults give every run. */
76
+ const defaultsBaseline = (rPr) => withStyleTier(NO_EMPHASIS, rPr);
77
+ /**
78
+ * The emphasis every run of a paragraph starts from: the document defaults
79
+ * under the paragraph's style.
80
+ */
81
+ const paragraphBaseline = (style, defaults) => withStyleTier(defaults, style?.rPr);
82
+ /** `base` under a character style. */
83
+ const withCharacterStyle = (base, style) => withStyleTier(base, style?.rPr);
84
+ const OFF_VALUES = /* @__PURE__ */ new Set([
85
+ "0",
86
+ "false",
87
+ "off"
88
+ ]);
89
+ /** What a `w:rPr` states directly. */
90
+ const readDirectEmphasis = (rPr) => {
91
+ const override = {};
92
+ if (!rPr) return override;
93
+ for (const toggle of TOGGLES) {
94
+ const stated = wChildren(rPr, toggle).at(-1);
95
+ if (stated !== void 0) override[toggle] = !OFF_VALUES.has(wAttr(stated, "val") ?? "");
96
+ }
97
+ if (wChild(rPr, "u") !== null) override.u = underlineOf(wChildVal(rPr, "u") ?? "single");
98
+ if (wChild(rPr, "vertAlign") !== null) override.vertAlign = vertAlignOf(wChildVal(rPr, "vertAlign"));
99
+ if (wChild(rPr, "highlight") !== null) override.highlight = highlightOf(wChildVal(rPr, "highlight"));
100
+ return override;
101
+ };
102
+ const withOverride = (base, override) => ({
103
+ ...base,
104
+ ...override
105
+ });
106
+ /** The part of `effective` that differs from `baseline`, stated explicitly. */
107
+ const emphasisDeviation = (effective, baseline) => {
108
+ const deviation = {};
109
+ for (const toggle of TOGGLES) if (effective[toggle] !== baseline[toggle]) deviation[toggle] = effective[toggle];
110
+ if (effective.u !== baseline.u) deviation.u = effective.u;
111
+ if (effective.vertAlign !== baseline.vertAlign) deviation.vertAlign = effective.vertAlign;
112
+ if (effective.highlight !== baseline.highlight) deviation.highlight = effective.highlight;
113
+ return deviation;
114
+ };
115
+ const SIGNATURE_SEPARATOR = ";";
116
+ /** One canonical string per override; the empty string states nothing. */
117
+ const emphasisSignature = (override) => {
118
+ const parts = [];
119
+ for (const toggle of TOGGLES) {
120
+ const stated = override[toggle];
121
+ if (stated !== void 0) parts.push(`${toggle}=${stated ? "1" : "0"}`);
122
+ }
123
+ if (override.highlight !== void 0) parts.push(`highlight=${override.highlight ?? "none"}`);
124
+ if (override.u !== void 0) parts.push(`u=${override.u ?? "none"}`);
125
+ if (override.vertAlign !== void 0) parts.push(`vertAlign=${override.vertAlign ?? "baseline"}`);
126
+ return parts.join(SIGNATURE_SEPARATOR);
127
+ };
128
+ /** The highlight a signature states, or null when it states none. */
129
+ const signatureHighlight = (signature) => {
130
+ const color = signature.split(SIGNATURE_SEPARATOR).find((entry) => entry.startsWith("highlight="))?.slice(10);
131
+ return color === void 0 || color === "none" ? null : color;
132
+ };
133
+ /** A signature without its highlight entry. */
134
+ const signatureWithoutHighlight = (signature) => signature.split(SIGNATURE_SEPARATOR).filter((entry) => entry !== "" && !entry.startsWith("highlight=")).join(SIGNATURE_SEPARATOR);
135
+ /** Whether a signature states anything besides a highlight. */
136
+ const signatureHasEmphasis = (signature) => signature.split(SIGNATURE_SEPARATOR).some((entry) => entry !== "" && !entry.startsWith("highlight="));
137
+ const withSignatureHighlight = (signature, color) => {
138
+ const parts = signature.split(SIGNATURE_SEPARATOR).filter((entry) => entry !== "" && !entry.startsWith("highlight="));
139
+ const toggles = parts.filter((entry) => !/^(?:u|vertAlign)=/u.test(entry));
140
+ const rest = parts.filter((entry) => /^(?:u|vertAlign)=/u.test(entry));
141
+ return [
142
+ ...toggles,
143
+ `highlight=${color}`,
144
+ ...rest
145
+ ].join(SIGNATURE_SEPARATOR);
146
+ };
147
+ const onOff = (prefix, name, value) => value ? `<${prefix}:${name}/>` : `<${prefix}:${name} ${prefix}:val="0"/>`;
148
+ /**
149
+ * The `w:rPr` for a signature, children in `CT_RPr` order; the empty string
150
+ * when there is nothing to state.
151
+ */
152
+ const runPropertiesXml = ({ prefix, signature, rStyle, escapeAttribute }) => {
153
+ const stated = new Map(signature.split(SIGNATURE_SEPARATOR).filter((entry) => entry !== "").map((entry) => {
154
+ const equals = entry.indexOf("=");
155
+ return [entry.slice(0, equals), entry.slice(equals + 1)];
156
+ }));
157
+ const out = [];
158
+ if (rStyle) out.push(`<${prefix}:rStyle ${prefix}:val="${escapeAttribute(rStyle)}"/>`);
159
+ for (const name of TOGGLES) {
160
+ const value = stated.get(name);
161
+ if (value !== void 0) out.push(onOff(prefix, name, value === "1"));
162
+ }
163
+ for (const name of [
164
+ "highlight",
165
+ "u",
166
+ "vertAlign"
167
+ ]) {
168
+ const value = stated.get(name);
169
+ if (value !== void 0) out.push(`<${prefix}:${name} ${prefix}:val="${escapeAttribute(value)}"/>`);
170
+ }
171
+ return out.length === 0 ? "" : `<${prefix}:rPr>${out.join("")}</${prefix}:rPr>`;
172
+ };
173
+ export { NO_EMPHASIS, defaultsBaseline, emphasisDeviation, emphasisSignature, paragraphBaseline, readDirectEmphasis, runPropertiesXml, signatureHasEmphasis, signatureHighlight, signatureWithoutHighlight, withCharacterStyle, withOverride, withSignatureHighlight };
@@ -0,0 +1,22 @@
1
+ /** A template's inventory: what a plan may name when it places blocks onto it. */
2
+ import { AnalyzedDocument } from "./blocks.js";
3
+ import { StoryField } from "./story.js";
4
+ import { DocxTemplateInspection, TemplatePlanError } from "./types.js";
5
+ import { RawPart } from "./xml.js";
6
+ import { Result } from "better-result";
7
+ /** The fields of a part other than the main document, read as one story. */
8
+ export declare const partFields: (part: RawPart) => StoryField[];
9
+ /** The header and footer parts the main document names, in relationship order. */
10
+ export declare const headerFooterPaths: ({ pkg }: AnalyzedDocument) => string[];
11
+ /**
12
+ * The header and footer parts of a package, read. A part the document names
13
+ * that has no readable root is a refusal: skipping it would hide its fields.
14
+ */
15
+ export declare const readHeaderFooterParts: (analyzed: AnalyzedDocument) => Promise<Result<RawPart[], TemplatePlanError>>;
16
+ /** Build the inspection of an analysed template. */
17
+ export declare const inspectAnalyzedTemplate: (analyzed: AnalyzedDocument) => Promise<Result<DocxTemplateInspection, TemplatePlanError>>;
18
+ /**
19
+ * Read a template into what a plan may name: the block manifest plus its
20
+ * styles, numbering definitions, fields, sections and bookmarks.
21
+ */
22
+ export declare const inspectDocxTemplate: (docx: Uint8Array) => Promise<Result<DocxTemplateInspection, TemplatePlanError>>;
@@ -0,0 +1,230 @@
1
+ import { RELATIONSHIP_TYPES } from "../../relsParser.js";
2
+ import { parseSectionProperties } from "../../sectionParser.js";
3
+ import { analyzeDocument, styleOutlineLevel } from "./blocks.js";
4
+ import { styleNumbering } from "./labels.js";
5
+ import { guarded, readPartText } from "./package.js";
6
+ import { createStoryState, endStory, readParagraph, walkBlocks } from "./story.js";
7
+ import { TemplatePlanError } from "./types.js";
8
+ import { integerOrNull, isW, readRawPart, twipsOrNull, wAttr, wChild, wChildVal, wChildren, walkElements } from "./xml.js";
9
+ import { Result } from "better-result";
10
+ // src/docx/server/templatePlan/inspect.ts
11
+ /** A template's inventory: what a plan may name when it places blocks onto it. */
12
+ const DEFAULT_LEVEL_START = 1;
13
+ /** The `w:jc` each style of the styles part states itself, by style id. */
14
+ const statedAlignments = ({ stylesPath, stylesXml }) => {
15
+ const alignments = /* @__PURE__ */ new Map();
16
+ const part = stylesPath === null || stylesXml === null ? null : readRawPart(stylesPath, stylesXml);
17
+ for (const style of wChildren(part?.root, "style")) {
18
+ const styleId = wAttr(style, "styleId");
19
+ const alignment = wChildVal(wChild(style, "pPr"), "jc");
20
+ if (styleId !== null && alignment !== null) alignments.set(styleId, alignment);
21
+ }
22
+ return alignments;
23
+ };
24
+ /** The indent each level of the numbering part states, by definition and level. */
25
+ const statedIndents = ({ numberingPath, numberingXml }) => {
26
+ const indents = /* @__PURE__ */ new Map();
27
+ const part = numberingPath === null || numberingXml === null ? null : readRawPart(numberingPath, numberingXml);
28
+ for (const definition of wChildren(part?.root, "abstractNum")) for (const level of wChildren(definition, "lvl")) {
29
+ const indent = wChild(wChild(level, "pPr"), "ind");
30
+ const stated = (name) => twipsOrNull(wAttr(indent, name));
31
+ indents.set(`${String(integerOrNull(wAttr(definition, "abstractNumId")))}:${String(integerOrNull(wAttr(level, "ilvl")))}`, {
32
+ left: stated("left") ?? stated("start"),
33
+ hanging: stated("hanging"),
34
+ firstLine: stated("firstLine")
35
+ });
36
+ }
37
+ return indents;
38
+ };
39
+ const NO_INDENT = {
40
+ left: null,
41
+ hanging: null,
42
+ firstLine: null
43
+ };
44
+ const inspectStyles = (analyzed) => {
45
+ const { styles, numbering } = analyzed;
46
+ const stated = statedAlignments(analyzed);
47
+ /** The alignment of the nearest style in the `basedOn` chain that states one. */
48
+ const alignmentOf = (styleId) => {
49
+ const seen = /* @__PURE__ */ new Set();
50
+ let cursor = styleId;
51
+ while (cursor !== void 0 && !seen.has(cursor)) {
52
+ seen.add(cursor);
53
+ const alignment = stated.get(cursor);
54
+ if (alignment !== void 0) return alignment;
55
+ cursor = styles.get(cursor)?.basedOn;
56
+ }
57
+ return null;
58
+ };
59
+ return [...styles.values()].map((style) => {
60
+ const bound = styleNumbering(style.styleId, styles, numbering);
61
+ return {
62
+ styleId: style.styleId,
63
+ name: style.name ?? null,
64
+ type: style.type,
65
+ basedOn: style.basedOn ?? null,
66
+ numPr: bound?.kind === "reference" ? {
67
+ numId: bound.numId,
68
+ ilvl: bound.ilvl ?? 0
69
+ } : null,
70
+ outlineLvl: styleOutlineLevel(style),
71
+ alignment: alignmentOf(style.styleId),
72
+ isDefault: style.default === true
73
+ };
74
+ });
75
+ };
76
+ const inspectNumbering = (analyzed) => {
77
+ const { numbering } = analyzed;
78
+ const indents = statedIndents(analyzed);
79
+ return {
80
+ abstractNums: (numbering?.definitions.abstractNums ?? []).map(({ abstractNumId, levels }) => ({
81
+ abstractNumId,
82
+ levels: levels.map((level) => ({
83
+ ilvl: level.ilvl,
84
+ numFmt: level.numFmt,
85
+ lvlText: level.lvlText,
86
+ start: level.start ?? DEFAULT_LEVEL_START,
87
+ suff: level.suffix ?? "tab",
88
+ pStyle: level.pStyle ?? null,
89
+ indent: indents.get(`${String(abstractNumId)}:${String(level.ilvl)}`) ?? NO_INDENT
90
+ }))
91
+ })),
92
+ nums: (numbering?.definitions.nums ?? []).map(({ numId, abstractNumId, levelOverrides }) => ({
93
+ numId,
94
+ abstractNumId,
95
+ overrides: (levelOverrides ?? []).map(({ ilvl, startOverride }) => ({
96
+ ilvl,
97
+ startOverride: startOverride ?? null
98
+ }))
99
+ }))
100
+ };
101
+ };
102
+ const inspectSections = ({ story, pkg }) => story.sections.map((sectPr, index) => {
103
+ const properties = parseSectionProperties(sectPr);
104
+ const partOf = (rId) => {
105
+ const relationship = pkg.documentRelationships.get(rId);
106
+ return relationship === void 0 ? null : pkg.resolveDocumentTarget(relationship.target);
107
+ };
108
+ return {
109
+ index,
110
+ orientation: properties.orientation ?? "portrait",
111
+ size: {
112
+ width: properties.pageWidth ?? null,
113
+ height: properties.pageHeight ?? null
114
+ },
115
+ margins: {
116
+ top: properties.marginTop ?? null,
117
+ right: properties.marginRight ?? null,
118
+ bottom: properties.marginBottom ?? null,
119
+ left: properties.marginLeft ?? null
120
+ },
121
+ headers: (properties.headerReferences ?? []).map(({ type, rId }) => ({
122
+ type,
123
+ part: partOf(rId)
124
+ })),
125
+ footers: (properties.footerReferences ?? []).map(({ type, rId }) => ({
126
+ type,
127
+ part: partOf(rId)
128
+ }))
129
+ };
130
+ });
131
+ const fieldOf = (part, { instruction, kind, result }) => ({
132
+ part,
133
+ instruction: instruction.trim(),
134
+ kind,
135
+ result
136
+ });
137
+ /** The fields of a part other than the main document, read as one story. */
138
+ const partFields = (part) => {
139
+ const state = createStoryState();
140
+ const readUnder = (container) => {
141
+ walkBlocks(container, {
142
+ paragraph: (paragraph) => {
143
+ readParagraph(paragraph, state);
144
+ },
145
+ tableStart: () => {},
146
+ cellStart: () => {},
147
+ tableEnd: () => {},
148
+ unread: () => {},
149
+ tracked: () => {}
150
+ });
151
+ };
152
+ if (isW(part.root, "footnotes") || isW(part.root, "endnotes")) {
153
+ for (const note of part.root.elements ?? []) if (note.type === "element") {
154
+ readUnder(note);
155
+ endStory(state);
156
+ }
157
+ } else readUnder(part.root);
158
+ return state.fields;
159
+ };
160
+ const bookmarksOf = (part) => {
161
+ const bookmarks = [];
162
+ walkElements(part.root, (element) => {
163
+ if (isW(element, "bookmarkStart")) bookmarks.push({
164
+ name: wAttr(element, "name") ?? "",
165
+ id: wAttr(element, "id") ?? "",
166
+ part: part.path
167
+ });
168
+ });
169
+ return bookmarks;
170
+ };
171
+ /** The header and footer parts the main document names, in relationship order. */
172
+ const headerFooterPaths = ({ pkg }) => [...pkg.documentRelationships.values()].filter(({ type, targetMode }) => (type === RELATIONSHIP_TYPES.header || type === RELATIONSHIP_TYPES.footer) && targetMode !== "External").map(({ target }) => pkg.resolveDocumentTarget(target)).filter((path) => pkg.paths.has(path));
173
+ /**
174
+ * The header and footer parts of a package, read. A part the document names
175
+ * that has no readable root is a refusal: skipping it would hide its fields.
176
+ */
177
+ const readHeaderFooterParts = async (analyzed) => {
178
+ const parts = [];
179
+ for (const path of headerFooterPaths(analyzed)) {
180
+ const xml = await readPartText(analyzed.pkg, path);
181
+ if (Result.isError(xml)) return xml;
182
+ const part = xml.value === null ? null : readRawPart(path, xml.value);
183
+ if (part === null) return Result.err(new TemplatePlanError({
184
+ message: `The part ${path} could not be read.`,
185
+ code: "xml-unreadable",
186
+ part: path
187
+ }));
188
+ parts.push(part);
189
+ }
190
+ return Result.ok(parts);
191
+ };
192
+ /** Build the inspection of an analysed template. */
193
+ const inspectAnalyzedTemplate = async (analyzed) => {
194
+ const { pkg, story, document, footnotes, endnotes, manifest } = analyzed;
195
+ const fields = story.state.fields.map((field) => {
196
+ const inspected = fieldOf(pkg.documentPath, field);
197
+ const block = story.paragraphs[field.paragraphOrdinal];
198
+ if (block !== void 0) inspected.blockId = block.topLevelId;
199
+ const endBlock = story.paragraphs[field.endParagraphOrdinal];
200
+ if (endBlock !== void 0 && field.closed) inspected.endBlockId = endBlock.topLevelId;
201
+ return inspected;
202
+ });
203
+ const bookmarks = bookmarksOf(document);
204
+ const headersAndFooters = await readHeaderFooterParts(analyzed);
205
+ if (Result.isError(headersAndFooters)) return headersAndFooters;
206
+ const others = [...headersAndFooters.value];
207
+ for (const notes of [footnotes, endnotes]) if (notes.part !== null) others.push(notes.part);
208
+ for (const part of others) {
209
+ fields.push(...partFields(part).map((field) => fieldOf(part.path, field)));
210
+ bookmarks.push(...bookmarksOf(part));
211
+ }
212
+ return Result.ok({
213
+ ...manifest,
214
+ styles: inspectStyles(analyzed),
215
+ numbering: inspectNumbering(analyzed),
216
+ fields,
217
+ sections: inspectSections(analyzed),
218
+ bookmarks
219
+ });
220
+ };
221
+ /**
222
+ * Read a template into what a plan may name: the block manifest plus its
223
+ * styles, numbering definitions, fields, sections and bookmarks.
224
+ */
225
+ const inspectDocxTemplate = async (docx) => await guarded(async () => {
226
+ const analyzed = await analyzeDocument(docx);
227
+ if (Result.isError(analyzed)) return Result.err(analyzed.error);
228
+ return await inspectAnalyzedTemplate(analyzed.value);
229
+ });
230
+ export { headerFooterPaths, inspectAnalyzedTemplate, inspectDocxTemplate, partFields, readHeaderFooterParts };
@@ -0,0 +1,45 @@
1
+ import { NumberingMap } from "../../numberingParser.js";
2
+ import { StyleMap } from "../../styleParser.js";
3
+ import { DocxBlockNumbering } from "./types.js";
4
+ import { LevelSuffix, ParagraphNumberingOverride } from "@stll/docx-core/model";
5
+ export type ParagraphLabel = {
6
+ label: string | null;
7
+ numbering: DocxBlockNumbering | null;
8
+ /**
9
+ * The label as a `REF \n \t` field shows it: number parts and delimiters,
10
+ * without the words of the level text and without a trailing period.
11
+ */
12
+ numberOnly: string | null;
13
+ /** The label as a `REF \n` field shows it: without a trailing period. */
14
+ paragraphNumber: string | null;
15
+ /**
16
+ * The label and what its list puts after it, when the label can stand as
17
+ * text: it reads the same wherever the file is opened. Null for a bullet,
18
+ * whose glyph belongs to a font, and for a number a language spells.
19
+ */
20
+ asText: {
21
+ label: string;
22
+ suffix: LevelSuffix;
23
+ } | null;
24
+ };
25
+ /**
26
+ * The numbering a style binds its paragraphs to. A style that names a list
27
+ * without a level takes the level of that list which names the style back
28
+ * (`w:pStyle`), as the consumer that wrote it does.
29
+ */
30
+ export declare const styleNumbering: (styleId: string | null, styles: StyleMap, numbering: NumberingMap | null) => ParagraphNumberingOverride | undefined;
31
+ export type LabelCounter = {
32
+ next: (paragraph: {
33
+ styleId: string | null;
34
+ numPr: ParagraphNumberingOverride | undefined;
35
+ }) => ParagraphLabel;
36
+ };
37
+ type LabelCounterOptions = {
38
+ numbering: NumberingMap | null;
39
+ styles: StyleMap;
40
+ /** The style a paragraph without `w:pStyle` takes. */
41
+ defaultStyleId: string | null;
42
+ };
43
+ /** A counter over one story; call `next` for every paragraph in document order. */
44
+ export declare const createLabelCounter: ({ numbering, styles, defaultStyleId }: LabelCounterOptions) => LabelCounter;
45
+ export {};
@@ -0,0 +1,155 @@
1
+ import { computeListMarker } from "../../listMarkerComputation.js";
2
+ import { resolveListTemplateWithComponents } from "../../listTemplate.js";
3
+ import { computeListRendering } from "../../numberingParser.js";
4
+ import { mergeParagraphNumbering, paragraphNumberingReference, resolveParagraphNumbering } from "../../numberingReference.js";
5
+ import { finalizeParagraphFormatting } from "@stll/docx-core";
6
+ // src/docx/server/templatePlan/labels.ts
7
+ /**
8
+ * The automatic list label each paragraph of a story renders, counted with
9
+ * the same marker code the document parser uses.
10
+ */
11
+ const NO_LABEL = {
12
+ label: null,
13
+ numbering: null,
14
+ numberOnly: null,
15
+ paragraphNumber: null,
16
+ asText: null
17
+ };
18
+ /** Counter formats every consumer and language writes with the same characters. */
19
+ const PLAIN_FORMATS = /* @__PURE__ */ new Set([
20
+ "decimal",
21
+ "decimalZero",
22
+ "upperRoman",
23
+ "lowerRoman",
24
+ "upperLetter",
25
+ "lowerLetter"
26
+ ]);
27
+ const LEVEL_PLACEHOLDER = /%([1-9])/gu;
28
+ const labelAsText = ({ label, template, levelFormats, suffix }) => {
29
+ if (label.trim() === "") return null;
30
+ for (const [, digit] of template.matchAll(LEVEL_PLACEHOLDER)) {
31
+ const format = levelFormats?.[Number(digit) - 1];
32
+ if (format === void 0 || !PLAIN_FORMATS.has(format)) return null;
33
+ }
34
+ return {
35
+ label,
36
+ suffix: suffix ?? "tab"
37
+ };
38
+ };
39
+ /**
40
+ * The numbering a style binds its paragraphs to. A style that names a list
41
+ * without a level takes the level of that list which names the style back
42
+ * (`w:pStyle`), as the consumer that wrote it does.
43
+ */
44
+ const styleNumbering = (styleId, styles, numbering) => {
45
+ if (styleId === null) return;
46
+ const stated = styles.get(styleId)?.pPr?.numPr;
47
+ if (stated === void 0 || stated.kind !== "reference" || stated.ilvl !== void 0 || numbering === null) return stated;
48
+ const abstractNumId = numbering.getAbstractNumId(stated.numId);
49
+ const abstract = abstractNumId === null ? null : numbering.getAbstract(abstractNumId);
50
+ const levelByStyle = new Map((abstract?.levels ?? []).flatMap(({ pStyle, ilvl }) => pStyle === void 0 ? [] : [[pStyle, ilvl]]));
51
+ let cursor = styleId;
52
+ const seen = /* @__PURE__ */ new Set();
53
+ while (cursor !== void 0 && !seen.has(cursor)) {
54
+ seen.add(cursor);
55
+ const ilvl = levelByStyle.get(cursor);
56
+ if (ilvl !== void 0) return paragraphNumberingReference({
57
+ numId: stated.numId,
58
+ ilvl
59
+ });
60
+ cursor = styles.get(cursor)?.basedOn;
61
+ }
62
+ return stated;
63
+ };
64
+ const stripTrailingPeriods = (value) => value.replace(/\.+$/u, "");
65
+ /** Drop the literal runs of a level text that hold a letter; keep delimiters. */
66
+ const numberOnlyLabel = ({ template, counters, levelFormats, forceDecimal }) => {
67
+ const { value, components } = resolveListTemplateWithComponents({
68
+ template,
69
+ counters,
70
+ levelFormats,
71
+ forceDecimal
72
+ });
73
+ let out = "";
74
+ let cursor = 0;
75
+ const literal = (text) => /\p{L}/u.test(text) ? "" : text;
76
+ for (const { start, end } of components) {
77
+ out += literal(value.slice(cursor, start)) + value.slice(start, end);
78
+ cursor = end;
79
+ }
80
+ out += literal(value.slice(cursor));
81
+ return stripTrailingPeriods(out.trim());
82
+ };
83
+ /** A counter over one story; call `next` for every paragraph in document order. */
84
+ const createLabelCounter = ({ numbering, styles, defaultStyleId }) => {
85
+ const counters = {
86
+ numbering,
87
+ listCounters: /* @__PURE__ */ new Map(),
88
+ abstractCounters: /* @__PURE__ */ new Map(),
89
+ restartedNumIds: /* @__PURE__ */ new Set(),
90
+ previousList: {
91
+ abstractNumId: null,
92
+ fromStyle: false,
93
+ numId: null
94
+ }
95
+ };
96
+ return { next: ({ styleId, numPr }) => {
97
+ const fromStyle = styleNumbering(styleId ?? defaultStyleId, styles, numbering);
98
+ const inherits = fromStyle !== void 0 && (numPr === void 0 || numPr.kind === "levelOnly");
99
+ const effective = inherits ? mergeParagraphNumbering(fromStyle, numPr) : numPr;
100
+ const resolved = resolveParagraphNumbering(effective);
101
+ const listRendering = numbering !== null && resolved.kind === "reference" ? computeListRendering({
102
+ numId: resolved.numId,
103
+ ilvl: resolved.ilvl
104
+ }, numbering) : null;
105
+ const formatting = finalizeParagraphFormatting({
106
+ ...numPr === void 0 ? {} : { numPr },
107
+ ...inherits ? { numPrFromStyle: fromStyle } : {}
108
+ });
109
+ const paragraph = {
110
+ type: "paragraph",
111
+ content: [],
112
+ ...formatting === void 0 ? {} : { formatting },
113
+ ...listRendering === null ? {} : { listRendering }
114
+ };
115
+ const template = listRendering?.marker ?? "";
116
+ const advance = computeListMarker(paragraph, counters);
117
+ if (advance === null || listRendering === null || numbering === null || resolved.kind !== "reference") return NO_LABEL;
118
+ const abstractNumId = numbering.getAbstractNumId(resolved.numId);
119
+ const label = listRendering.marker;
120
+ const numberingInfo = abstractNumId === null ? null : {
121
+ numId: resolved.numId,
122
+ ilvl: resolved.ilvl,
123
+ abstractNumId
124
+ };
125
+ if (listRendering.markerHidden === true) return {
126
+ ...NO_LABEL,
127
+ numbering: numberingInfo
128
+ };
129
+ if (listRendering.isBullet) return {
130
+ label,
131
+ numbering: numberingInfo,
132
+ numberOnly: null,
133
+ paragraphNumber: null,
134
+ asText: null
135
+ };
136
+ return {
137
+ label,
138
+ numbering: numberingInfo,
139
+ asText: labelAsText({
140
+ label,
141
+ template,
142
+ levelFormats: listRendering.levelNumFmts,
143
+ suffix: listRendering.markerSuffix
144
+ }),
145
+ paragraphNumber: stripTrailingPeriods(label.trim()),
146
+ numberOnly: numberOnlyLabel({
147
+ template,
148
+ counters: advance.counters,
149
+ levelFormats: listRendering.levelNumFmts,
150
+ forceDecimal: listRendering.isLegal === true
151
+ })
152
+ };
153
+ } };
154
+ };
155
+ export { createLabelCounter, styleNumbering };
@@ -0,0 +1,34 @@
1
+ /** A DOCX package opened for reading: its parts, and the parts its main document names. */
2
+ import { document_d_exports } from "../../../types/document.js";
3
+ import { TemplatePlanError } from "./types.js";
4
+ import { Result } from "better-result";
5
+ export declare const sha256Hex: (bytes: Uint8Array | string) => string;
6
+ export declare const relationshipsPathFor: (partPath: string) => string;
7
+ export type DocumentPartKind = "styles" | "numbering" | "footnotes" | "endnotes" | "settings" | "comments";
8
+ export type LoadedPackage = {
9
+ bytes: Uint8Array;
10
+ sha256: string;
11
+ paths: ReadonlySet<string>;
12
+ readText: (path: string) => Promise<string | null>;
13
+ readBytes: (path: string) => Promise<Uint8Array | null>;
14
+ documentPath: string;
15
+ documentXml: string;
16
+ documentRelationshipsPath: string;
17
+ documentRelationships: document_d_exports.RelationshipMap;
18
+ /** The path of the part the main document names for `kind`, when it names one. */
19
+ partPath: (kind: DocumentPartKind) => string | null;
20
+ /** The path the main document names for `kind` when the package holds no such entry. */
21
+ missingPartPath: (kind: DocumentPartKind) => string | null;
22
+ /** The package path a relationship of the main document points at. */
23
+ resolveDocumentTarget: (target: string) => string;
24
+ };
25
+ /** Open `bytes` within folio's archive and XML limits. */
26
+ export declare const loadPackage: (bytes: Uint8Array) => Promise<Result<LoadedPackage, TemplatePlanError>>;
27
+ /** Read an XML part, refusing one the archive could not hand out. */
28
+ export declare const readPartText: (pkg: LoadedPackage, path: string | null) => Promise<Result<string | null, TemplatePlanError>>;
29
+ /**
30
+ * Run one public entry of the module. Whatever a hostile or malformed
31
+ * package makes a shared helper throw comes back as a typed refusal, so no
32
+ * caller has to guard the call.
33
+ */
34
+ export declare const guarded: <Value>(run: () => Promise<Result<Value, TemplatePlanError>>) => Promise<Result<Value, TemplatePlanError>>;