@stll/folio-core 0.8.0 → 0.9.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 (152) hide show
  1. package/README.md +39 -0
  2. package/dist/ai-edits/apply.js +18 -4
  3. package/dist/ai-edits/headless.d.ts +31 -4
  4. package/dist/ai-edits/headless.js +148 -35
  5. package/dist/ai-edits/index.d.ts +3 -3
  6. package/dist/ai-edits/index.js +2 -1
  7. package/dist/ai-edits/snapshot.js +40 -3
  8. package/dist/ai-edits/types.d.ts +2 -1
  9. package/dist/compat/eigenpal.d.ts +6 -4
  10. package/dist/compat/eigenpal.js +5 -3
  11. package/dist/controller/latestRequestGate.d.ts +13 -0
  12. package/dist/controller/latestRequestGate.js +16 -0
  13. package/dist/controller/layoutPipeline.js +12 -1
  14. package/dist/document-operations.d.ts +10 -3
  15. package/dist/document-operations.js +29 -14
  16. package/dist/docx/blockContentParser.js +2 -2
  17. package/dist/docx/commentParser.js +1 -1
  18. package/dist/docx/compatibility.d.ts +3 -7
  19. package/dist/docx/compatibility.js +0 -11
  20. package/dist/docx/encryption/agileDecryption.js +1 -1
  21. package/dist/docx/encryption/encryptionInfo.js +1 -1
  22. package/dist/docx/encryption/openEncryptedDocx.js +1 -1
  23. package/dist/docx/fontTableParser.d.ts +6 -0
  24. package/dist/docx/fontTableParser.js +72 -0
  25. package/dist/docx/groupDrawingParser.js +7 -2
  26. package/dist/docx/headerFooterParser.js +1 -1
  27. package/dist/docx/normalizeBaseDirection.js +1 -1
  28. package/dist/docx/numberingParser.js +1 -0
  29. package/dist/docx/paragraphParser.js +12 -1
  30. package/dist/docx/parser.d.ts +1 -1
  31. package/dist/docx/parser.js +12 -9
  32. package/dist/docx/rezip.js +70 -5
  33. package/dist/docx/runConsolidator.js +4 -0
  34. package/dist/docx/runParser.js +19 -1
  35. package/dist/docx/selectiveSave.js +3 -3
  36. package/dist/docx/serializer/fontTableSerializer.d.ts +6 -0
  37. package/dist/docx/serializer/fontTableSerializer.js +26 -0
  38. package/dist/docx/serializer/headerFooterSerializer.js +1 -1
  39. package/dist/docx/serializer/paragraphSerializer.js +4 -0
  40. package/dist/docx/serializer/runSerializer.js +7 -0
  41. package/dist/docx/serializer/settingsSerializer.d.ts +6 -0
  42. package/dist/docx/serializer/settingsSerializer.js +16 -0
  43. package/dist/docx/serializer/stylesSerializer.d.ts +6 -0
  44. package/dist/docx/serializer/stylesSerializer.js +56 -0
  45. package/dist/docx/serializer/tableSerializer.js +25 -26
  46. package/dist/docx/serializer/themeSerializer.d.ts +6 -0
  47. package/dist/docx/serializer/themeSerializer.js +36 -0
  48. package/dist/docx/settingsParser.js +46 -0
  49. package/dist/docx/styleParser.js +26 -1
  50. package/dist/docx/tableParser.js +11 -1
  51. package/dist/docx/vmlImageParser.js +1 -0
  52. package/dist/i18n/messages/catalogs.gen.d.ts +5916 -5916
  53. package/dist/i18n/messages/catalogs.gen.js +5910 -5910
  54. package/dist/index.d.ts +6 -4
  55. package/dist/index.js +5 -3
  56. package/dist/layout-bridge/convert/footnoteLayout.d.ts +3 -0
  57. package/dist/layout-bridge/convert/footnoteLayout.js +3 -1
  58. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +3 -0
  59. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  60. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +14 -2
  61. package/dist/layout-bridge/convert/toFlowBlocks.js +51 -14
  62. package/dist/layout-bridge/engine/measuring/index.d.ts +2 -1
  63. package/dist/layout-bridge/engine/measuring/index.js +2 -1
  64. package/dist/layout-engine/index.js +36 -28
  65. package/dist/layout-engine/measure/cache.js +11 -3
  66. package/dist/layout-engine/measure/font-metrics.worker.js +1 -0
  67. package/dist/layout-engine/measure/index.d.ts +2 -1
  68. package/dist/layout-engine/measure/index.js +2 -1
  69. package/dist/layout-engine/measure/lineBreakProvider.d.ts +33 -0
  70. package/dist/layout-engine/measure/lineBreakProvider.js +252 -0
  71. package/dist/layout-engine/measure/lineBreaks.d.ts +7 -2
  72. package/dist/layout-engine/measure/lineBreaks.js +11 -18
  73. package/dist/layout-engine/measure/listMarkerWidth.d.ts +1 -0
  74. package/dist/layout-engine/measure/listMarkerWidth.js +12 -6
  75. package/dist/layout-engine/measure/measureBlocks.d.ts +1 -2
  76. package/dist/layout-engine/measure/measureBlocks.js +6 -36
  77. package/dist/layout-engine/measure/measureContainer.js +32 -9
  78. package/dist/layout-engine/measure/measureHelpers.js +5 -2
  79. package/dist/layout-engine/measure/measureParagraph.js +335 -72
  80. package/dist/layout-engine/measure/measureTypes.d.ts +2 -1
  81. package/dist/layout-engine/measure/measureWorker.d.ts +2 -2
  82. package/dist/layout-engine/measure/measureWorker.js +8 -19
  83. package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +3 -14
  84. package/dist/layout-engine/measure/tableCellFloating.d.ts +10 -3
  85. package/dist/layout-engine/measure/tableCellFloating.js +37 -29
  86. package/dist/layout-engine/measure/tableCellFlow.d.ts +27 -0
  87. package/dist/layout-engine/measure/tableCellFlow.js +73 -0
  88. package/dist/layout-engine/measure/tableCellGrid.js +1 -1
  89. package/dist/layout-engine/measure/textMeasurementPolicy.d.ts +18 -0
  90. package/dist/layout-engine/measure/textMeasurementPolicy.js +24 -0
  91. package/dist/layout-engine/renderedBreakReconciliation.d.ts +6 -1
  92. package/dist/layout-engine/renderedBreakReconciliation.js +34 -11
  93. package/dist/layout-engine/tableRowBreak.d.ts +5 -2
  94. package/dist/layout-engine/tableRowBreak.js +62 -29
  95. package/dist/layout-engine/types.d.ts +40 -7
  96. package/dist/layout-painter/anchoredImagePosition.d.ts +23 -0
  97. package/dist/layout-painter/anchoredImagePosition.js +95 -0
  98. package/dist/layout-painter/borderStroke.d.ts +23 -0
  99. package/dist/layout-painter/borderStroke.js +39 -0
  100. package/dist/layout-painter/renderImage.d.ts +5 -4
  101. package/dist/layout-painter/renderImage.js +18 -4
  102. package/dist/layout-painter/renderPage.d.ts +2 -27
  103. package/dist/layout-painter/renderPage.js +13 -99
  104. package/dist/layout-painter/renderParagraph.js +41 -23
  105. package/dist/layout-painter/renderTable.d.ts +2 -0
  106. package/dist/layout-painter/renderTable.js +223 -43
  107. package/dist/managers/DocumentLoaderManager.d.ts +1 -1
  108. package/dist/managers/DocumentLoaderManager.js +2 -2
  109. package/dist/prosemirror/attrs/index.d.ts +4 -2
  110. package/dist/prosemirror/attrs/index.js +21 -2
  111. package/dist/prosemirror/commands/propertyChangeScope.js +1 -1
  112. package/dist/prosemirror/conversion/fromProseDoc.js +33 -18
  113. package/dist/prosemirror/conversion/toProseDoc.js +50 -18
  114. package/dist/prosemirror/extensions/StarterKit.js +2 -0
  115. package/dist/prosemirror/extensions/core/ParagraphExtension.js +7 -2
  116. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
  117. package/dist/prosemirror/extensions/features/ListExtension.js +1 -0
  118. package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +1 -0
  119. package/dist/prosemirror/extensions/marks/HighlightExtension.js +1 -1
  120. package/dist/prosemirror/extensions/marks/LanguageExtension.d.ts +7 -0
  121. package/dist/prosemirror/extensions/marks/LanguageExtension.js +30 -0
  122. package/dist/prosemirror/extensions/marks/RunShadingExtension.js +1 -1
  123. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  124. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +1 -1
  125. package/dist/prosemirror/extensions/marks/markUtils.js +12 -0
  126. package/dist/prosemirror/extensions/nodes/ImageExtension.js +2 -1
  127. package/dist/prosemirror/extensions/nodes/TableExtension.js +4 -2
  128. package/dist/prosemirror/schema/index.d.ts +2 -2
  129. package/dist/prosemirror/schema/marks.d.ts +6 -1
  130. package/dist/prosemirror/schema/nodes.d.ts +13 -11
  131. package/dist/prosemirror/styles/resolvedStyleAttrs.js +1 -0
  132. package/dist/prosemirror/utils/tabCalculator.d.ts +3 -1
  133. package/dist/prosemirror/utils/tabCalculator.js +12 -10
  134. package/dist/prosemirror/validation.js +4 -1
  135. package/dist/redline.js +13 -3
  136. package/dist/server.d.ts +6 -3
  137. package/dist/server.js +5 -2
  138. package/dist/style-sets/extract.d.ts +35 -0
  139. package/dist/style-sets/extract.js +123 -0
  140. package/dist/style-sets/stellaStyle.d.ts +13 -0
  141. package/dist/style-sets/stellaStyle.js +516 -0
  142. package/dist/style-sets/types.d.ts +31 -0
  143. package/dist/style-sets/types.js +5 -0
  144. package/dist/utils/createDocument.d.ts +12 -2
  145. package/dist/utils/createDocument.js +42 -31
  146. package/dist/utils/fontResolver.js +6 -6
  147. package/dist/utils/formatToStyle.js +1 -1
  148. package/dist/utils/paragraphFormattingMerge.d.ts +14 -3
  149. package/dist/utils/paragraphFormattingMerge.js +14 -4
  150. package/package.json +5 -1
  151. package/dist/docx/capabilities.d.ts +0 -41
  152. package/dist/docx/capabilities.js +0 -322
@@ -86,6 +86,7 @@ function listAttrsFromResolvedStyle(resolved, numbering) {
86
86
  listMarkerHidden: rendering?.markerHidden ?? null,
87
87
  listMarkerFontFamily: rendering?.markerFontFamily ?? null,
88
88
  listMarkerFontSize: rendering?.markerFontSize ?? null,
89
+ listMarkerBold: rendering?.markerBold ?? null,
89
90
  listMarkerAlignment: rendering?.markerAlignment ?? null,
90
91
  listMarkerSuffix: rendering?.markerSuffix ?? null,
91
92
  listMarkerAllCaps: rendering?.markerAllCaps ?? null,
@@ -64,7 +64,9 @@ declare function pixelsToTwips(pixels: number): number;
64
64
  * Compute the list of effective tab stops for a paragraph
65
65
  *
66
66
  * Merges explicit stops with default stops at regular intervals.
67
- * Filters out stops that fall before the left indent.
67
+ * Explicit stops before the left indent remain available to a hanging first
68
+ * line. Continuation lines naturally skip them because their cursor already
69
+ * starts at the left indent.
68
70
  *
69
71
  * @param context - Tab context with explicit stops and settings
70
72
  * @returns Sorted array of tab stops in twips
@@ -27,25 +27,27 @@ function pixelsToTwips(pixels) {
27
27
  * Compute the list of effective tab stops for a paragraph
28
28
  *
29
29
  * Merges explicit stops with default stops at regular intervals.
30
- * Filters out stops that fall before the left indent.
30
+ * Explicit stops before the left indent remain available to a hanging first
31
+ * line. Continuation lines naturally skip them because their cursor already
32
+ * starts at the left indent.
31
33
  *
32
34
  * @param context - Tab context with explicit stops and settings
33
35
  * @returns Sorted array of tab stops in twips
34
36
  */
35
37
  function computeTabStops(context) {
36
38
  const { explicitStops = [], defaultTabInterval = 720, leftIndent = 0 } = context;
37
- const validExplicitStops = explicitStops.filter((stop) => stop.val !== "clear").filter((stop) => stop.pos >= leftIndent);
39
+ const validExplicitStops = explicitStops.filter((stop) => stop.val !== "clear");
38
40
  const clearPositions = explicitStops.filter((stop) => stop.val === "clear").map((stop) => stop.pos);
39
41
  let maxExplicit = 0;
40
42
  for (const stop of validExplicitStops) maxExplicit = Math.max(maxExplicit, stop.pos);
41
43
  const stops = [...validExplicitStops];
42
- if (leftIndent > 0 && !validExplicitStops.some((s) => s.pos <= leftIndent)) {
43
- if (!clearPositions.some((p) => Math.abs(p - leftIndent) < 20)) stops.push({
44
- val: "start",
45
- pos: leftIndent,
46
- leader: "none"
47
- });
48
- }
44
+ const hasLeftIndentClear = clearPositions.some((p) => Math.abs(p - leftIndent) < 20);
45
+ const addsImplicitLeftIndent = leftIndent > 0 && !hasLeftIndentClear && !validExplicitStops.some((stop) => stop.pos <= leftIndent);
46
+ if (addsImplicitLeftIndent) stops.push({
47
+ val: "start",
48
+ pos: leftIndent,
49
+ leader: "none"
50
+ });
49
51
  let pos = Math.floor(Math.max(maxExplicit, leftIndent) / defaultTabInterval) * defaultTabInterval;
50
52
  const limitPos = leftIndent + 14400;
51
53
  while (pos < limitPos) {
@@ -60,7 +62,7 @@ function computeTabStops(context) {
60
62
  hasClearStop = true;
61
63
  break;
62
64
  }
63
- const isAtLeftIndent = leftIndent > 0 && Math.abs(pos - leftIndent) < 20;
65
+ const isAtLeftIndent = addsImplicitLeftIndent && Math.abs(pos - leftIndent) < 20;
64
66
  if (!hasExplicitStop && !hasClearStop && !isAtLeftIndent) stops.push({
65
67
  val: "start",
66
68
  pos,
@@ -1,4 +1,4 @@
1
- import { readBlockSdtAttrs, readCharacterSpacingMarkAttrs, readCharacterStyleMarkAttrs, readCommentMarkAttrs, readEmphasisMarkAttrs, readFieldAttrs, readFontFamilyMarkAttrs, readFontSizeMarkAttrs, readFootnoteRefMarkAttrs, readHardBreakAttrs, readHighlightMarkAttrs, readHyperlinkMarkAttrs, readImageAttrs, readMathAttrs, readParagraphAttrs, readRunFormattingOverrideMarkAttrs, readRunShadingMarkAttrs, readSdtAttrs, readShapeAttrs, readStrikeMarkAttrs, readTableAttrs, readTableCellAttrs, readTableRowAttrs, readTextBoxAttrs, readTextColorMarkAttrs, readTextEffectMarkAttrs, readTrackedChangeMarkAttrs, readUnderlineMarkAttrs } from "./attrs/index.js";
1
+ import { readBlockSdtAttrs, readCharacterSpacingMarkAttrs, readCharacterStyleMarkAttrs, readCommentMarkAttrs, readEmphasisMarkAttrs, readFieldAttrs, readFontFamilyMarkAttrs, readFontSizeMarkAttrs, readFootnoteRefMarkAttrs, readHardBreakAttrs, readHighlightMarkAttrs, readHyperlinkMarkAttrs, readImageAttrs, readLanguageMarkAttrs, readMathAttrs, readParagraphAttrs, readRunFormattingOverrideMarkAttrs, readRunShadingMarkAttrs, readSdtAttrs, readShapeAttrs, readStrikeMarkAttrs, readTableAttrs, readTableCellAttrs, readTableRowAttrs, readTextBoxAttrs, readTextColorMarkAttrs, readTextEffectMarkAttrs, readTrackedChangeMarkAttrs, readUnderlineMarkAttrs } from "./attrs/index.js";
2
2
  //#region src/prosemirror/validation.ts
3
3
  var ProseMirrorDocumentValidationError = class extends Error {
4
4
  issues;
@@ -133,6 +133,9 @@ const validateMarks = (marks, path, issues) => {
133
133
  case "fontFamily":
134
134
  appendAttrIssues(markPath, readFontFamilyMarkAttrs(mark), issues);
135
135
  continue;
136
+ case "language":
137
+ appendAttrIssues(markPath, readLanguageMarkAttrs(mark), issues);
138
+ continue;
136
139
  case "characterSpacing":
137
140
  appendAttrIssues(markPath, readCharacterSpacingMarkAttrs(mark), issues);
138
141
  continue;
package/dist/redline.js CHANGED
@@ -69,7 +69,7 @@ const generateRedlineDocx = async (base, revised, options = {}) => {
69
69
  const operations = [];
70
70
  let operationSeq = 0;
71
71
  const nextOperationId = () => `redline-${++operationSeq}`;
72
- /** Additions past the last base block, inserted after it in reverse so the final order matches the revised document. */
72
+ /** Additions past the last base block, kept in revised-document order. */
73
73
  const trailingAdditions = [];
74
74
  const lastBaseBlockId = baseSnapshot.blocks.at(-1)?.id ?? null;
75
75
  events.forEach((event, eventIndex) => {
@@ -106,10 +106,20 @@ const generateRedlineDocx = async (base, revised, options = {}) => {
106
106
  ...event.block.styleId !== void 0 && { styleId: event.block.styleId }
107
107
  });
108
108
  });
109
- for (const addition of trailingAdditions.toReversed()) operations.push({
109
+ if (lastBaseBlockId === null && baseSnapshot.emptyDocumentAnchorId !== void 0) {
110
+ const firstAddition = trailingAdditions.shift();
111
+ if (firstAddition !== void 0) operations.push({
112
+ id: nextOperationId(),
113
+ type: "replaceBlock",
114
+ blockId: baseSnapshot.emptyDocumentAnchorId,
115
+ text: firstAddition.text,
116
+ ...firstAddition.styleId !== void 0 && { styleId: firstAddition.styleId }
117
+ });
118
+ }
119
+ for (const addition of trailingAdditions) operations.push({
110
120
  id: nextOperationId(),
111
121
  type: "insertAfterBlock",
112
- blockId: lastBaseBlockId ?? "redline-unanchored",
122
+ blockId: lastBaseBlockId ?? baseSnapshot.emptyDocumentAnchorId ?? "redline-unanchored",
113
123
  text: addition.text,
114
124
  ...addition.styleId !== void 0 && { styleId: addition.styleId }
115
125
  });
package/dist/server.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIComment, FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditSnapshot, FolioAIInlineFormatting, FolioAITextRangeHandle, FolioDocumentNavigationTarget, FolioDocumentOutline, FolioDocumentOutlineEntry, FolioDocumentSection, FolioDocumentSectionHandle, FolioDocumentSectionReadResult } from "./ai-edits/types.js";
2
- import { FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FolioDocumentOperation, FolioDocumentOperationAffectedTarget, FolioDocumentOperationBatch, FolioDocumentOperationCapabilities, FolioDocumentOperationIssue, FolioDocumentOperationMode, FolioDocumentOperationPrecondition, FolioDocumentOperationReceipt, FolioDocumentOperationRecovery, FolioDocumentOperationResult, FolioDocumentOperationStatus, FolioDocumentOperationType, FolioDocumentOperationUndoFailureReason, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "./document-operations.js";
2
+ import { FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FolioDocumentOperation, FolioDocumentOperationAffectedTarget, FolioDocumentOperationBatch, FolioDocumentOperationCapabilities, FolioDocumentOperationIssue, FolioDocumentOperationMode, FolioDocumentOperationPrecondition, FolioDocumentOperationReceipt, FolioDocumentOperationRecovery, FolioDocumentOperationResult, FolioDocumentOperationStatus, FolioDocumentOperationStory, FolioDocumentOperationType, FolioDocumentOperationUndoFailureReason, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "./document-operations.js";
3
3
  import { FolioReviewChange, FolioReviewChangeKind } from "./ai-edits/read.js";
4
- import { ApplyFolioAIEditsToBufferOptions, ApplyFolioAIEditsToBufferResult, FolioApplyDocumentOperationsOptions, FolioApplyOperationsOptions, FolioDocumentStory, FolioDocumentStoryHandle, FolioDocxReviewer, FolioDocxReviewerOptions, FolioReviewChangeFilter, FolioReviewComment, FolioReviewCommentFilter, FolioReviewCommentReply, FolioReviewReplyInput, applyFolioAIEditsToBuffer } from "./ai-edits/headless.js";
4
+ import { ApplyFolioAIEditsToBufferOptions, ApplyFolioAIEditsToBufferResult, FolioApplyDocumentOperationsOptions, FolioApplyDocumentOperationsToStoryOptions, FolioApplyOperationsOptions, FolioDocumentStory, FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, FolioDocxReviewer, FolioDocxReviewerOptions, FolioEditableDocumentStoryHandle, FolioReviewChangeFilter, FolioReviewComment, FolioReviewCommentFilter, FolioReviewCommentReply, FolioReviewReplyInput, applyFolioAIEditsToBuffer } from "./ai-edits/headless.js";
5
5
  import { createFolioAITextRangeHandle } from "./ai-edits/snapshot.js";
6
6
  import { getFolioDocumentOutline, readFolioDocumentSection } from "./ai-edits/scoped-reading.js";
7
7
  import { DeriveBlockIdInput, FolioBlockId, deriveBlockId, getFolioParaIdFromBlockId, isFolioBlockId, isSequentialFolioBlockId } from "./types/block-id.js";
8
+ import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocumentPreset, DocumentStyleSet } from "./style-sets/types.js";
8
9
  import { CreateEmptyDocumentOptions, createEmptyDocument } from "./utils/createDocument.js";
10
+ import { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSetOptions, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "./style-sets/extract.js";
11
+ import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
9
12
  import { createDocx } from "./docx/rezip.js";
10
13
  import { EnsureParaIdsError, EnsureParaIdsOptions, EnsureParaIdsResult, ensureParaIds } from "./docx/ensureParaIds.js";
11
14
  import { CreateCommentReplyInput, replyToComment } from "./docx/replyToComment.js";
@@ -13,4 +16,4 @@ import { DocxArchiveError } from "./docx/server/boundedArchive.js";
13
16
  import { DocxParagraphSource, ExtractedDocxParagraph, ExtractedDocxText, extractDocxText } from "./docx/server/extractDocxText.js";
14
17
  import { GenerateRedlineDocxOptions, GenerateRedlineDocxResult, generateRedlineDocx } from "./redline.js";
15
18
  import { FolioBlockDiff, FolioFormatProperty, FolioVersionDiff, FolioVersionDiffSegment, compareDocxVersions } from "./version-comparison.js";
16
- export { type ApplyFolioAIEditsToBufferOptions, type ApplyFolioAIEditsToBufferResult, type CreateCommentReplyInput, type CreateEmptyDocumentOptions, type DeriveBlockIdInput, DocxArchiveError, type DocxParagraphSource, EnsureParaIdsError, type EnsureParaIdsOptions, type EnsureParaIdsResult, type ExtractedDocxParagraph, type ExtractedDocxText, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIComment, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditSnapshot, type FolioAIInlineFormatting, type FolioAITextRangeHandle, type FolioApplyDocumentOperationsOptions, type FolioApplyOperationsOptions, type FolioBlockDiff, type FolioBlockId, type FolioDocumentNavigationTarget, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationStatus, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocumentOutline, type FolioDocumentOutlineEntry, type FolioDocumentSection, type FolioDocumentSectionHandle, type FolioDocumentSectionReadResult, type FolioDocumentStory, type FolioDocumentStoryHandle, FolioDocxReviewer, type FolioDocxReviewerOptions, type FolioFormatProperty, type FolioReviewChange, type FolioReviewChangeFilter, type FolioReviewChangeKind, type FolioReviewComment, type FolioReviewCommentFilter, type FolioReviewCommentReply, type FolioReviewReplyInput, type FolioVersionDiff, type FolioVersionDiffSegment, type GenerateRedlineDocxOptions, type GenerateRedlineDocxResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioAIEditsToBuffer, assertSupportedFolioDocumentOperationVersion, compareDocxVersions, createDocx, createEmptyDocument, createFolioAITextRangeHandle, deriveBlockId, ensureParaIds, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch, readFolioDocumentSection, replyToComment };
19
+ export { type ApplyFolioAIEditsToBufferOptions, type ApplyFolioAIEditsToBufferResult, type CreateCommentReplyInput, type CreateEmptyDocumentOptions, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, type DeriveBlockIdInput, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, DocxArchiveError, type DocxParagraphSource, EnsureParaIdsError, type EnsureParaIdsOptions, type EnsureParaIdsResult, type ExtractDocumentStyleSetOptions, type ExtractedDocxParagraph, type ExtractedDocxText, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIComment, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditSnapshot, type FolioAIInlineFormatting, type FolioAITextRangeHandle, type FolioApplyDocumentOperationsOptions, type FolioApplyDocumentOperationsToStoryOptions, type FolioApplyOperationsOptions, type FolioBlockDiff, type FolioBlockId, type FolioDocumentNavigationTarget, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocumentOutline, type FolioDocumentOutlineEntry, type FolioDocumentSection, type FolioDocumentSectionHandle, type FolioDocumentSectionReadResult, type FolioDocumentStory, type FolioDocumentStoryHandle, FolioDocumentStoryNotFoundError, FolioDocxReviewer, type FolioDocxReviewerOptions, type FolioEditableDocumentStoryHandle, type FolioFormatProperty, type FolioReviewChange, type FolioReviewChangeFilter, type FolioReviewChangeKind, type FolioReviewComment, type FolioReviewCommentFilter, type FolioReviewCommentReply, type FolioReviewReplyInput, type FolioVersionDiff, type FolioVersionDiffSegment, type GenerateRedlineDocxOptions, type GenerateRedlineDocxResult, InvalidFolioDocumentOperationBatchError, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, applyFolioAIEditsToBuffer, assertSupportedFolioDocumentOperationVersion, compareDocxVersions, createDocx, createEmptyDocument, createFolioAITextRangeHandle, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, ensureParaIds, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, inspectDocumentStyles, inspectDocumentStylesFromDocx, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch, readFolioDocumentSection, replyToComment };
package/dist/server.js CHANGED
@@ -1,14 +1,17 @@
1
1
  import { deriveBlockId, getFolioParaIdFromBlockId, isFolioBlockId, isSequentialFolioBlockId } from "./types/block-id.js";
2
2
  import { createFolioAITextRangeHandle } from "./ai-edits/snapshot.js";
3
3
  import { FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "./document-operations.js";
4
+ import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION } from "./style-sets/types.js";
4
5
  import { createEmptyDocument } from "./utils/createDocument.js";
6
+ import { extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "./style-sets/extract.js";
7
+ import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
5
8
  import { createDocx } from "./docx/rezip.js";
6
9
  import { getFolioDocumentOutline, readFolioDocumentSection } from "./ai-edits/scoped-reading.js";
7
10
  import { replyToComment } from "./docx/replyToComment.js";
8
- import { FolioDocxReviewer, applyFolioAIEditsToBuffer } from "./ai-edits/headless.js";
11
+ import { FolioDocumentStoryNotFoundError, FolioDocxReviewer, applyFolioAIEditsToBuffer } from "./ai-edits/headless.js";
9
12
  import { compareDocxVersions } from "./version-comparison.js";
10
13
  import { generateRedlineDocx } from "./redline.js";
11
14
  import { EnsureParaIdsError, ensureParaIds } from "./docx/ensureParaIds.js";
12
15
  import { DocxArchiveError } from "./docx/server/boundedArchive.js";
13
16
  import { extractDocxText } from "./docx/server/extractDocxText.js";
14
- export { DocxArchiveError, EnsureParaIdsError, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FolioDocxReviewer, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioAIEditsToBuffer, assertSupportedFolioDocumentOperationVersion, compareDocxVersions, createDocx, createEmptyDocument, createFolioAITextRangeHandle, deriveBlockId, ensureParaIds, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch, readFolioDocumentSection, replyToComment };
17
+ export { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocxArchiveError, EnsureParaIdsError, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FolioDocumentStoryNotFoundError, FolioDocxReviewer, InvalidFolioDocumentOperationBatchError, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, applyFolioAIEditsToBuffer, assertSupportedFolioDocumentOperationVersion, compareDocxVersions, createDocx, createEmptyDocument, createFolioAITextRangeHandle, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, ensureParaIds, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractDocxText, generateRedlineDocx, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOutline, getFolioParaIdFromBlockId, inspectDocumentStyles, inspectDocumentStylesFromDocx, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch, readFolioDocumentSection, replyToComment };
@@ -0,0 +1,35 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ import { DocumentStyleSet } from "./types.js";
3
+ import { DocxInput } from "../utils/docxInput.js";
4
+
5
+ //#region src/style-sets/extract.d.ts
6
+ type ExtractDocumentStyleSetOptions = {
7
+ name: string; /** Style IDs selected by the user. Omit to extract every style. */
8
+ styleIds?: readonly string[]; /** Defaults to the source document's default paragraph style. */
9
+ initialParagraphStyleId?: string;
10
+ };
11
+ type DocumentStyleCatalogEntry = {
12
+ styleId: string;
13
+ name: string;
14
+ type: document_d_exports.Style["type"];
15
+ role: "default" | "quick" | "available" | "supporting";
16
+ dependencies: string[];
17
+ numberingId?: number;
18
+ };
19
+ type DocumentStyleCatalog = {
20
+ defaultParagraphStyleId?: string;
21
+ styles: DocumentStyleCatalogEntry[];
22
+ };
23
+ declare const inspectDocumentStyles: (document: document_d_exports.Document) => DocumentStyleCatalog;
24
+ declare const inspectDocumentStylesFromDocx: (input: DocxInput) => Promise<DocumentStyleCatalog>;
25
+ /**
26
+ * Extract a sanitized style set from a parsed document.
27
+ *
28
+ * Selected styles expand to a dependency closure over basedOn, next, and link
29
+ * references. Only numbering definitions referenced by the resulting styles
30
+ * are retained. No source content or package relationship can enter the result.
31
+ */
32
+ declare const extractDocumentStyleSet: (document: document_d_exports.Document, options: ExtractDocumentStyleSetOptions) => DocumentStyleSet;
33
+ declare const extractDocumentStyleSetFromDocx: (input: DocxInput, options: ExtractDocumentStyleSetOptions) => Promise<DocumentStyleSet>;
34
+ //#endregion
35
+ export { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSetOptions, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx };
@@ -0,0 +1,123 @@
1
+ import "./types.js";
2
+ import { parseDocx } from "../docx/parser.js";
3
+ import { panic } from "better-result";
4
+ //#region src/style-sets/extract.ts
5
+ const inspectDocumentStyles = (document) => {
6
+ const styles = document.package.styles?.styles ?? [];
7
+ const defaultParagraphStyleId = styles.find((style) => style.type === "paragraph" && style.default)?.styleId;
8
+ return {
9
+ ...defaultParagraphStyleId ? { defaultParagraphStyleId } : {},
10
+ styles: styles.map(toCatalogEntry)
11
+ };
12
+ };
13
+ const inspectDocumentStylesFromDocx = async (input) => inspectDocumentStyles(await parseDocx(input, {
14
+ preloadFonts: false,
15
+ parseHeadersFooters: false,
16
+ parseNotes: false,
17
+ detectVariables: false
18
+ }));
19
+ /**
20
+ * Extract a sanitized style set from a parsed document.
21
+ *
22
+ * Selected styles expand to a dependency closure over basedOn, next, and link
23
+ * references. Only numbering definitions referenced by the resulting styles
24
+ * are retained. No source content or package relationship can enter the result.
25
+ */
26
+ const extractDocumentStyleSet = (document, options) => {
27
+ const definitions = document.package.styles;
28
+ if (!definitions || definitions.styles.length === 0) return panic("Cannot extract a style set from a document without styles");
29
+ const stylesById = new Map(definitions.styles.map((style) => [style.styleId, style]));
30
+ const selectedStyleIds = options.styleIds === void 0 ? new Set(stylesById.keys()) : collectStyleDependencyClosure(stylesById, options.styleIds);
31
+ const styles = definitions.styles.filter((style) => selectedStyleIds.has(style.styleId));
32
+ if (styles.length === 0) return panic("Cannot extract an empty style set");
33
+ const defaultParagraphStyle = styles.find((style) => style.type === "paragraph" && style.default);
34
+ const initialParagraphStyleId = options.initialParagraphStyleId ?? defaultParagraphStyle?.styleId ?? "Normal";
35
+ if (!styles.find((style) => style.styleId === initialParagraphStyleId && style.type === "paragraph")) return panic(`Initial paragraph style "${initialParagraphStyleId}" is not present in the extracted set`);
36
+ const numbering = extractReferencedNumbering(styles, document);
37
+ const fontTable = sanitizeFontTable(document.package.fontTable);
38
+ return structuredClone({
39
+ version: 1,
40
+ name: options.name,
41
+ initialParagraphStyleId,
42
+ styles: {
43
+ ...definitions.docDefaults ? { docDefaults: definitions.docDefaults } : {},
44
+ ...definitions.latentStyles ? { latentStyles: definitions.latentStyles } : {},
45
+ styles
46
+ },
47
+ ...numbering ? { numbering } : {},
48
+ ...document.package.theme ? { theme: document.package.theme } : {},
49
+ ...fontTable ? { fontTable } : {},
50
+ ...document.package.settings ? { settings: document.package.settings } : {}
51
+ });
52
+ };
53
+ const extractDocumentStyleSetFromDocx = async (input, options) => {
54
+ const document = await parseDocx(input, {
55
+ preloadFonts: false,
56
+ parseHeadersFooters: false,
57
+ parseNotes: false,
58
+ detectVariables: false
59
+ });
60
+ return extractDocumentStyleSet(document, options);
61
+ };
62
+ const collectStyleDependencyClosure = (stylesById, requestedStyleIds) => {
63
+ const selected = /* @__PURE__ */ new Set();
64
+ const pending = [...requestedStyleIds];
65
+ while (pending.length > 0) {
66
+ const styleId = pending.pop();
67
+ if (styleId === void 0 || selected.has(styleId)) continue;
68
+ const style = stylesById.get(styleId);
69
+ if (!style) return panic(`Cannot extract unknown style "${styleId}"`);
70
+ selected.add(styleId);
71
+ for (const dependency of [
72
+ style.basedOn,
73
+ style.next,
74
+ style.link
75
+ ]) if (dependency !== void 0 && !selected.has(dependency)) pending.push(dependency);
76
+ }
77
+ return selected;
78
+ };
79
+ const extractReferencedNumbering = (styles, document) => {
80
+ const source = document.package.numbering;
81
+ if (!source) return;
82
+ const referencedNumIds = /* @__PURE__ */ new Set();
83
+ for (const style of styles) {
84
+ const numId = style.pPr?.numPr?.numId;
85
+ if (numId !== void 0) referencedNumIds.add(numId);
86
+ }
87
+ if (referencedNumIds.size === 0) return;
88
+ const nums = source.nums.filter((numbering) => referencedNumIds.has(numbering.numId));
89
+ const referencedAbstractNumIds = new Set(nums.map((numbering) => numbering.abstractNumId));
90
+ return {
91
+ abstractNums: source.abstractNums.filter((numbering) => referencedAbstractNumIds.has(numbering.abstractNumId)),
92
+ nums
93
+ };
94
+ };
95
+ const sanitizeFontTable = (fontTable) => {
96
+ if (!fontTable) return;
97
+ return { fonts: fontTable.fonts.map(stripEmbeddedFontRelationships) };
98
+ };
99
+ const stripEmbeddedFontRelationships = ({ embedRegular: _embedRegular, embedBold: _embedBold, embedItalic: _embedItalic, embedBoldItalic: _embedBoldItalic, ...font }) => font;
100
+ const toCatalogEntry = (style) => {
101
+ const entry = {
102
+ styleId: style.styleId,
103
+ name: style.name ?? style.styleId,
104
+ type: style.type,
105
+ role: styleRole(style),
106
+ dependencies: [...new Set([
107
+ style.basedOn,
108
+ style.next,
109
+ style.link
110
+ ].filter((dependency) => dependency !== void 0))]
111
+ };
112
+ const numberingId = style.pPr?.numPr?.numId;
113
+ if (numberingId !== void 0) entry.numberingId = numberingId;
114
+ return entry;
115
+ };
116
+ const styleRole = (style) => {
117
+ if (style.default) return "default";
118
+ if (style.qFormat) return "quick";
119
+ if (!style.hidden && !style.semiHidden) return "available";
120
+ return "supporting";
121
+ };
122
+ //#endregion
123
+ export { extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx };
@@ -0,0 +1,13 @@
1
+ import { DocumentPreset, DocumentStyleSet } from "./types.js";
2
+
3
+ //#region src/style-sets/stellaStyle.d.ts
4
+ declare const STELLA_STYLE_SET_NAME = "Stella Style";
5
+ /**
6
+ * A conservative legal drafting system inspired by common continental and
7
+ * common-law contract structure. It uses explicit fonts and neutral punctuation
8
+ * so the package does not depend on a locale-specific Office theme.
9
+ */
10
+ declare const createStellaStyleSet: () => DocumentStyleSet;
11
+ declare const createStellaStyleDocumentPreset: () => DocumentPreset;
12
+ //#endregion
13
+ export { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet };