@stll/folio-core 0.58.5 → 0.59.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 (101) hide show
  1. package/dist/ai-edits/apply.d.ts +11 -12
  2. package/dist/ai-edits/apply.js +179 -168
  3. package/dist/ai-edits/headless.d.ts +15 -13
  4. package/dist/ai-edits/headless.js +40 -13
  5. package/dist/ai-edits/index.d.ts +3 -3
  6. package/dist/ai-edits/newListNumbering.d.ts +3 -9
  7. package/dist/ai-edits/newListNumbering.js +36 -41
  8. package/dist/ai-edits/referenceClassification.d.ts +22 -0
  9. package/dist/ai-edits/referenceClassification.js +21 -0
  10. package/dist/ai-edits/snapshot.js +39 -40
  11. package/dist/ai-edits/types.d.ts +24 -32
  12. package/dist/compare/column-alignment.d.ts +4 -4
  13. package/dist/compare/compare.d.ts +3 -7
  14. package/dist/compare/compare.js +25 -27
  15. package/dist/compare/content-alignment.d.ts +9 -9
  16. package/dist/compare/content-types.d.ts +23 -10
  17. package/dist/compare/content-types.js +14 -0
  18. package/dist/compare/content.d.ts +16 -17
  19. package/dist/compare/content.js +30 -7
  20. package/dist/compare/formatting.d.ts +3 -3
  21. package/dist/compare/import-style-closure.d.ts +22 -0
  22. package/dist/compare/import-style-closure.js +33 -0
  23. package/dist/compare/inserted-resource-snapshot.d.ts +15 -0
  24. package/dist/compare/inserted-resource-snapshot.js +63 -0
  25. package/dist/compare/plan.js +20 -13
  26. package/dist/compare/scenario.js +12 -2
  27. package/dist/compare/style-resources.d.ts +8 -2
  28. package/dist/compare/style-resources.js +63 -14
  29. package/dist/compare/verification.d.ts +15 -3
  30. package/dist/compare/verification.js +47 -8
  31. package/dist/compat/eigenpal.d.ts +4 -4
  32. package/dist/controller/canonicalListRendering.js +13 -22
  33. package/dist/controller/canonicalPublicOperations.js +1 -1
  34. package/dist/controller/canonicalStructure.js +45 -21
  35. package/dist/document-operations.d.ts +4 -9
  36. package/dist/document-operations.js +45 -41
  37. package/dist/docx/attributeRemainder.d.ts +1 -1
  38. package/dist/docx/index.d.ts +1 -1
  39. package/dist/docx/listMarkerComputation.js +9 -14
  40. package/dist/docx/listTemplate.d.ts +22 -0
  41. package/dist/docx/listTemplate.js +40 -0
  42. package/dist/docx/numberingParser.js +2 -2
  43. package/dist/docx/numberingReferenceNormalization.js +3 -3
  44. package/dist/docx/paragraphParser.js +3 -4
  45. package/dist/docx/rezip.js +2 -2
  46. package/dist/docx/server/materializeYjsDocx.js +2 -2
  47. package/dist/docx/server/migrateYjsAttrSchema.js +5 -5
  48. package/dist/generated/text_shaper.js +8 -4
  49. package/dist/generated/text_shaper_bg.wasm +0 -0
  50. package/dist/index.d.ts +4 -4
  51. package/dist/internal/paragraphFormattingSerialization.d.ts +1 -8
  52. package/dist/internal/paragraphFormattingSerialization.js +6 -20
  53. package/dist/layout-bridge/convert/flowConversionShared.d.ts +1 -1
  54. package/dist/layout-bridge/convert/listMarkers.d.ts +1 -2
  55. package/dist/layout-bridge/convert/listMarkers.js +3 -11
  56. package/dist/layout-bridge/convert/paragraphAttrs.d.ts +1 -1
  57. package/dist/layout-bridge/convert/paragraphAttrs.js +8 -4
  58. package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -1
  59. package/dist/layout-bridge/convert/toFlowBlocks.js +2 -1
  60. package/dist/markdown/renderParagraph.js +29 -3
  61. package/dist/prosemirror/commands/comments.js +5 -32
  62. package/dist/prosemirror/commands/paragraphBookmarkJoin.d.ts +7 -1
  63. package/dist/prosemirror/commands/paragraphBookmarkJoin.js +35 -1
  64. package/dist/prosemirror/commands/propertyChangeScope.js +6 -0
  65. package/dist/prosemirror/commands/resolveParagraphProperties.js +10 -5
  66. package/dist/prosemirror/conversion/fromProseDoc.js +23 -9
  67. package/dist/prosemirror/conversion/toProseDoc.js +31 -7
  68. package/dist/prosemirror/extensions/core/ParagraphExtension.js +29 -14
  69. package/dist/prosemirror/extensions/features/ListExtension.js +51 -21
  70. package/dist/prosemirror/listInstanceReferences.js +21 -15
  71. package/dist/prosemirror/listLabels.d.ts +4 -3
  72. package/dist/prosemirror/listLabels.js +18 -51
  73. package/dist/prosemirror/listMarker.d.ts +2 -19
  74. package/dist/prosemirror/listMarker.js +28 -57
  75. package/dist/prosemirror/listNumbering.js +16 -6
  76. package/dist/prosemirror/listRendering.d.ts +4 -3
  77. package/dist/prosemirror/listRendering.js +22 -3
  78. package/dist/prosemirror/listRenderingAttrs.d.ts +2 -1
  79. package/dist/prosemirror/listRenderingAttrs.js +6 -11
  80. package/dist/prosemirror/numberedRefFields.js +9 -5
  81. package/dist/prosemirror/numberingAttr.d.ts +19 -1
  82. package/dist/prosemirror/numberingAttr.js +16 -2
  83. package/dist/prosemirror/paragraphIndentation.js +5 -2
  84. package/dist/prosemirror/paragraphMarkJoin.js +17 -3
  85. package/dist/prosemirror/paragraphPropertyCarry.js +5 -6
  86. package/dist/prosemirror/plugins/transactionInvariants.js +6 -2
  87. package/dist/prosemirror/schema/nodes.d.ts +2 -1
  88. package/dist/prosemirror/selectionState.js +5 -1
  89. package/dist/prosemirror/storyListNumbering.js +11 -12
  90. package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -6
  91. package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +11 -4
  92. package/dist/prosemirror/styles/resolvedStyleAttrs.js +28 -18
  93. package/dist/prosemirror/yjsDocumentMetadata.d.ts +9 -3
  94. package/dist/prosemirror/yjsDocumentMetadata.js +42 -10
  95. package/dist/redline.d.ts +17 -1
  96. package/dist/redline.js +118 -57
  97. package/dist/server.d.ts +3 -3
  98. package/dist/server.js +2 -2
  99. package/dist/version-comparison.d.ts +1 -2
  100. package/dist/version-comparison.js +1 -2
  101. package/package.json +4 -3
@@ -1,8 +1,8 @@
1
1
  import { document_d_exports } from "../types/document.js";
2
- import { FolioContentBlock, FolioContentContainerPathEntry, FolioContentFormatRange, FolioContentIdStability, FolioContentInlineBooleanProperty, FolioContentInlineComparisonResult, FolioContentInlineFormatting, FolioContentInlineFormattingPatch, FolioContentLineSpacingRule, FolioContentParagraphAlignment, FolioContentParagraphKind, FolioContentParagraphSpacing, FolioContentRun, FolioContentSnapshot, FolioContentTableLocation } from "../compare/content-types.js";
3
- import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIBlockStructuralBoundary, FolioAIBlockTableLocation, FolioAIComment, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditNormalization, FolioAIEditNormalizationCode, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAIInlineBooleanProperty, FolioAIInlineFormatting, FolioAIInlineFormattingPatch, FolioAIParagraphSpacing, FolioAISignatureParty } from "../ai-edits/types.js";
2
+ import { FolioContentBlock, FolioContentContainerPathEntry, FolioContentFormatRange, FolioContentIdStability, FolioContentInlineBooleanProperty, FolioContentInlineComparisonResult, FolioContentInlineFormatting, FolioContentInlineFormattingPatch, FolioContentLineSpacingRule, FolioContentParagraphAlignment, FolioContentParagraphKind, FolioContentParagraphSpacing, FolioContentRun, FolioContentSnapshot, FolioContentStatedNumbering, FolioContentTableLocation } from "../compare/content-types.js";
3
+ import { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIBlockStructuralBoundary, FolioAIBlockTableLocation, FolioAIComment, FolioAIDiagnosticBlock, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditNormalization, FolioAIEditNormalizationCode, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAIInlineBooleanProperty, FolioAIInlineFormatting, FolioAIInlineFormattingPatch, FolioAIParagraphBlock, FolioAIParagraphSpacing, FolioAISignatureParty } from "../ai-edits/types.js";
4
4
  import { WORD_DIFF_GRANULARITIES, WordDiffGranularity, WordDiffNormalization, WordDiffOptions, WordDiffSegment, diffWordSegments } from "../ai-edits/word-diff.js";
5
- import { FolioAIEditApplyOutcome, FolioRevisionStamp, FolioWordDiffOptions, applyFolioAIEditOperations } from "../ai-edits/apply.js";
5
+ import { FolioAIEditApplyOutcome, FolioRevisionStamp, FolioUndefinedReferencePolicy, FolioWordDiffOptions, applyFolioAIEditOperations } from "../ai-edits/apply.js";
6
6
  import { ApplyFolioDocumentOperationsOptions, 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, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FolioDocumentOperation, FolioDocumentOperationAffectedTarget, FolioDocumentOperationBatch, FolioDocumentOperationCapabilities, FolioDocumentOperationIssue, FolioDocumentOperationMode, FolioDocumentOperationPrecondition, FolioDocumentOperationReceipt, FolioDocumentOperationRecovery, FolioDocumentOperationResult, FolioDocumentOperationResultBase, FolioDocumentOperationStatus, FolioDocumentOperationStory, FolioDocumentOperationType, FolioDocumentOperationUndoFailureReason, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "../document-operations.js";
7
7
  import { createFolioAIEditSnapshot, hashFolioAIBlockText, isFolioAIContentBlock, normalizeFolioAIBlockText } from "../ai-edits/snapshot.js";
8
8
  import { DeriveBlockIdInput, FolioBlockId, currentFolioBlockId, deriveBlockId, getFolioParaIdFromBlockId, isFolioBlockId, isSequentialFolioBlockId } from "../types/block-id.js";
@@ -42,4 +42,4 @@ import { FOLIO_YJS_ATTR_SCHEMA_VERSION, FolioYjsAttrSchemaVersion, FolioYjsAttrS
42
42
  import { DOCX_CONFORMANCE_CLASSES } from "../index.js";
43
43
  type Document = document_d_exports.Document;
44
44
  type DocxConformanceClass = document_d_exports.DocxConformanceClass;
45
- export { type AIBarStatus, type AIChatMode, type AICitation, type AICitationRange, type AICitationSource, type AIGenerateInput, type AISuggestion, type AISuggestionApplyMode, type AISuggestionPreset, type AISuggestionSeverity, type AISuggestionStatus, type AcceptAutocompleteResult, type AnonymizationMatch, type AnonymizationTerm, type ApplyFolioDocumentOperationsOptions, type ApplyResult, type AutocompleteSuggestionPluginOptions, type AutocompleteSuggestionState, type AutocompleteSuggestionStatus, type AutocompleteTriggerCheck, type AutocompleteTriggerOptions, type AutocompleteTriggerSkipReason, type BlockRect, COMPARE_REVISION_FORMATS, COMPARE_UNSUPPORTED_REASONS, COMPARE_VERIFICATION_CAUSES, COMPARE_VERIFICATION_INVARIANTS, type CompareChange, type CompareChangeLocation, type CompareCompatibility, type CompareContentOptions, CompareDocxApplyError, type CompareDocxError, CompareDocxFinalParagraphMarkError, CompareDocxOperationLimitError, type CompareDocxOptions, CompareDocxParseError, CompareDocxRoundTripError, CompareDocxSerializeError, type CompareFolioRequirement, type CompareResult, type CompareRevisionFormat, type CompareUnsupportedPart, type CompareUnsupportedReason, type CompareVerification, type CompareVerificationCause, type CompareVerificationFailure, type CompareVerificationInvariant, type CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DEFAULT_OUTLINE_DEPTH, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, DRAWING_SAFETY_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentPropertiesOptions, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type DocxDrawingClassification, type DrawingSafetyClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, FOLIO_CONTENT_COMPARISON_LIMITS, 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, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_YJS_ATTR_SCHEMA_VERSION, type FinalParagraphMarkRevision, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockStructuralBoundary, type FolioAIBlockTableLocation, type FolioAIComment, type FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyOutcome, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAIInlineBooleanProperty, type FolioAIInlineFormatting, type FolioAIInlineFormattingPatch, type FolioAIParagraphSpacing, type FolioAISignatureParty, type FolioBlockId, type FolioContentBlock, type FolioContentBlockProperty, type FolioContentComparison, type FolioContentComparisonError, type FolioContentComparisonEvent, type FolioContentComparisonLimit, FolioContentComparisonLimitError, type FolioContentContainerPathEntry, type FolioContentFormatRange, type FolioContentFormattingChange, type FolioContentIdStability, type FolioContentInlineBooleanProperty, type FolioContentInlineComparisonResult, type FolioContentInlineFormatting, type FolioContentInlineFormattingPatch, FolioContentInlinePresentationProjectionError, type FolioContentLineSpacingRule, type FolioContentParagraphAlignment, type FolioContentParagraphFormattingPatch, type FolioContentParagraphKind, type FolioContentParagraphSpacing, type FolioContentRun, type FolioContentSnapshot, type FolioContentStructuralChange, type FolioContentTableLocation, type FolioContentTextSegment, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type FolioRevisionStamp, type FolioWordDiffOptions, type FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidCompareDocxOptionsError, InvalidFolioContentComparisonError, InvalidFolioDocumentOperationBatchError, MAX_COMPARE_OPERATIONS, type MarkdownOptions, type MarkdownResult, type OutlineDepth, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewHiddenRange, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, WORD_DIFF_GRANULARITIES, type WordDiffGranularity, type WordDiffNormalization, type WordDiffOptions, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, compareContent, compareDocx, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, currentFolioBlockId, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, filterHeadingsByDepth, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, mergeDocumentContent, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
45
+ export { type AIBarStatus, type AIChatMode, type AICitation, type AICitationRange, type AICitationSource, type AIGenerateInput, type AISuggestion, type AISuggestionApplyMode, type AISuggestionPreset, type AISuggestionSeverity, type AISuggestionStatus, type AcceptAutocompleteResult, type AnonymizationMatch, type AnonymizationTerm, type ApplyFolioDocumentOperationsOptions, type ApplyResult, type AutocompleteSuggestionPluginOptions, type AutocompleteSuggestionState, type AutocompleteSuggestionStatus, type AutocompleteTriggerCheck, type AutocompleteTriggerOptions, type AutocompleteTriggerSkipReason, type BlockRect, COMPARE_REVISION_FORMATS, COMPARE_UNSUPPORTED_REASONS, COMPARE_VERIFICATION_CAUSES, COMPARE_VERIFICATION_INVARIANTS, type CompareChange, type CompareChangeLocation, type CompareCompatibility, type CompareContentOptions, CompareDocxApplyError, type CompareDocxError, CompareDocxFinalParagraphMarkError, CompareDocxOperationLimitError, type CompareDocxOptions, CompareDocxParseError, CompareDocxRoundTripError, CompareDocxSerializeError, type CompareFolioRequirement, type CompareResult, type CompareRevisionFormat, type CompareUnsupportedPart, type CompareUnsupportedReason, type CompareVerification, type CompareVerificationCause, type CompareVerificationFailure, type CompareVerificationInvariant, type CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DEFAULT_OUTLINE_DEPTH, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, DRAWING_SAFETY_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentPropertiesOptions, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type DocxDrawingClassification, type DrawingSafetyClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, FOLIO_CONTENT_COMPARISON_LIMITS, 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, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FOLIO_YJS_ATTR_SCHEMA_VERSION, type FinalParagraphMarkRevision, type FolioAIBlock, type FolioAIBlockAnchor, type FolioAIBlockKind, type FolioAIBlockPreviewRun, type FolioAIBlockStructuralBoundary, type FolioAIBlockTableLocation, type FolioAIComment, type FolioAIDiagnosticBlock, type FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyOutcome, type FolioAIEditApplyResult, type FolioAIEditNormalization, type FolioAIEditNormalizationCode, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAIInlineBooleanProperty, type FolioAIInlineFormatting, type FolioAIInlineFormattingPatch, type FolioAIParagraphBlock, type FolioAIParagraphSpacing, type FolioAISignatureParty, type FolioBlockId, type FolioContentBlock, type FolioContentBlockProperty, type FolioContentComparison, type FolioContentComparisonError, type FolioContentComparisonEvent, type FolioContentComparisonLimit, FolioContentComparisonLimitError, type FolioContentContainerPathEntry, type FolioContentFormatRange, type FolioContentFormattingChange, type FolioContentIdStability, type FolioContentInlineBooleanProperty, type FolioContentInlineComparisonResult, type FolioContentInlineFormatting, type FolioContentInlineFormattingPatch, FolioContentInlinePresentationProjectionError, type FolioContentLineSpacingRule, type FolioContentParagraphAlignment, type FolioContentParagraphFormattingPatch, type FolioContentParagraphKind, type FolioContentParagraphSpacing, type FolioContentRun, type FolioContentSnapshot, type FolioContentStatedNumbering, type FolioContentStructuralChange, type FolioContentTableLocation, type FolioContentTextSegment, type FolioDocumentOperation, type FolioDocumentOperationAffectedTarget, type FolioDocumentOperationBatch, type FolioDocumentOperationCapabilities, type FolioDocumentOperationIssue, type FolioDocumentOperationMode, type FolioDocumentOperationPrecondition, type FolioDocumentOperationReceipt, type FolioDocumentOperationRecovery, type FolioDocumentOperationResult, type FolioDocumentOperationResultBase, type FolioDocumentOperationStatus, type FolioDocumentOperationStory, type FolioDocumentOperationType, type FolioDocumentOperationUndoFailureReason, type FolioDocumentOperationUndoHandle, type FolioDocumentOperationUndoResult, type FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type FolioRevisionStamp, type FolioUndefinedReferencePolicy, type FolioWordDiffOptions, type FolioYjsAttrSchemaVersion, FolioYjsAttrSchemaVersionError, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidCompareDocxOptionsError, InvalidFolioContentComparisonError, InvalidFolioDocumentOperationBatchError, MAX_COMPARE_OPERATIONS, type MarkdownOptions, type MarkdownResult, type OutlineDepth, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewHiddenRange, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, WORD_DIFF_GRANULARITIES, type WordDiffGranularity, type WordDiffNormalization, type WordDiffOptions, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, compareContent, compareDocx, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, currentFolioBlockId, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, filterHeadingsByDepth, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioAIContentBlock, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, mergeDocumentContent, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
@@ -2,8 +2,8 @@ import { foldListNumberFields, planParagraphListNumberFold, unfoldedListNumberCo
2
2
  import { computeListMarker } from "../docx/listMarkerComputation.js";
3
3
  import { listRenderingDefinitionsMatch } from "../docx/listRendering.js";
4
4
  import { computeListRendering, getCachedNumberingMap } from "../docx/numberingParser.js";
5
- import { mergeParagraphNumbering, paragraphNumberingReferenceId, sameStatedParagraphNumbering } from "../docx/numberingReference.js";
6
5
  import { assignParagraphIndentationProjection, cloneParagraphWithPropertySource, paragraphFormattingWithAuthoredIndentation, sameParagraphIndentationProjection } from "../docx/paragraphPropertySource.js";
6
+ import { effectiveParagraphNumberingReference, paragraphNumberingSourcesFromBoundary } from "../prosemirror/numberingAttr.js";
7
7
  import { paragraphIndentationFromFormatting } from "../prosemirror/paragraphIndentation.js";
8
8
  import { listIndentationProvenancePatch } from "../prosemirror/styles/resolvedStyleAttrs.js";
9
9
  import { createStyleResolver } from "../prosemirror/styles/styleResolver.js";
@@ -35,16 +35,8 @@ const normalizeCanonicalListRendering = (document) => {
35
35
  snapshot: paragraphFormattingWithAuthoredIndentation(paragraph)
36
36
  });
37
37
  const formatting = paragraph.formatting;
38
- const numPr = mergeParagraphNumbering(formatting?.numPrFromStyle, formatting?.numPr);
39
- if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
40
- computeListMarker(paragraph, counters);
41
- return paragraph;
42
- }
43
- const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
44
- const cached = paragraph.listRendering;
45
- const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
46
38
  const next = cloneParagraphWithPropertySource(paragraph, {});
47
- if (formatting?.numPrFromStyle !== void 0 && formatting.numPr !== void 0 && paragraphNumberingReferenceId(numPr) !== paragraphNumberingReferenceId(formatting.numPrFromStyle)) {
39
+ if (formatting?.numPrFromStyle !== void 0 && (formatting.numPr?.kind === "reference" || formatting.numPr?.kind === "none")) {
48
40
  next.formatting = { ...formatting };
49
41
  delete next.formatting.numPrFromStyle;
50
42
  inverse.push({
@@ -54,18 +46,17 @@ const normalizeCanonicalListRendering = (document) => {
54
46
  patch: { numPrFromStyle: formatting.numPrFromStyle }
55
47
  });
56
48
  }
57
- if (formatting?.numPrFromStyle !== void 0 && numPr?.kind === "reference" && !sameStatedParagraphNumbering(formatting.numPr, numPr)) {
58
- next.formatting = {
59
- ...next.formatting,
60
- numPr
61
- };
62
- inverse.push({
63
- type: DOCUMENT_OP_TYPES.SET_PARAGRAPH_PROPS,
64
- story,
65
- blockId: paragraph.paraId ?? panic("Canonical numbering normalization requires paragraph identities."),
66
- patch: { numPr: formatting.numPr ?? null }
67
- });
49
+ const numPr = effectiveParagraphNumberingReference(paragraphNumberingSourcesFromBoundary({
50
+ numPr: next.formatting?.numPr,
51
+ numPrFromStyle: next.formatting?.numPrFromStyle
52
+ }));
53
+ if (paragraph.listRendering === void 0 && formatting?.numPrFromStyle === void 0 && (numPr?.kind !== "reference" || numbering === null)) {
54
+ computeListMarker(paragraph, counters);
55
+ return paragraph;
68
56
  }
57
+ const definition = numPr?.kind === "reference" && numbering !== null ? computeListRendering(numPr, numbering) : null;
58
+ const cached = paragraph.listRendering;
59
+ const rendering = definition !== null && cached !== void 0 && listRenderingDefinitionsMatch(cached, definition) ? { ...cached } : definition;
69
60
  const authoredFormatting = paragraphFormattingWithAuthoredIndentation(next);
70
61
  assignParagraphIndentationProjection({
71
62
  paragraph: next,
@@ -73,7 +64,7 @@ const normalizeCanonicalListRendering = (document) => {
73
64
  inherited: paragraphIndentationFromFormatting(listIndentationProvenancePatch({
74
65
  direct: paragraphIndentationFromFormatting(authoredFormatting),
75
66
  styleFormatting: styles.resolveParagraphStyle(next.formatting?.styleId).paragraphFormatting,
76
- numberingSource: next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
67
+ numberingSource: next.formatting?.numPr?.kind === "reference" || next.formatting?.numPrFromStyle === void 0 ? "paragraph" : "style",
77
68
  numPr: numPr?.kind === "reference" ? {
78
69
  numId: numPr.numId,
79
70
  ilvl: numPr.ilvl ?? 0
@@ -193,7 +193,7 @@ var CanonicalPublicOperations = class {
193
193
  skip(operation.id, "unsupportedMode", "Canonical pending suggestions are unavailable.");
194
194
  continue;
195
195
  }
196
- if (options.tableTemplates !== void 0 || options.undefinedStyles === "keep") {
196
+ if (options.tableTemplates !== void 0 || options.undefinedReferences === "keep") {
197
197
  refusals.set(operation.id, { gap: CANONICAL_GAP.publicUnsupportedInline });
198
198
  skip(operation.id, "unsupportedBlock", "This canonical compiler does not support the supplied execution options.");
199
199
  continue;
@@ -1,6 +1,7 @@
1
1
  import { BUILT_IN_STYLE_NAME, createBuiltInStyleIndex } from "../docx/builtInStyles.js";
2
2
  import { getCachedNumberingMap, numberingLevelUsesBulletMarker } from "../docx/numberingParser.js";
3
3
  import { listRequestsForMarker } from "../prosemirror/listAutoformatMarkers.js";
4
+ import { effectiveParagraphNumbering, paragraphNumberingSourcesFromBoundary } from "../prosemirror/numberingAttr.js";
4
5
  import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
5
6
  import { collectHeadings } from "../utils/headingCollector.js";
6
7
  import { CanonicalSessionError } from "./canonicalSession.js";
@@ -27,6 +28,10 @@ const selectedParagraphs = (session, state) => {
27
28
  });
28
29
  return session.document.package.document.content.filter((paragraph) => paragraph.type === "paragraph" && ids.has(paragraph.paraId ?? ""));
29
30
  };
31
+ const effectiveNumbering = (paragraph) => effectiveParagraphNumbering(paragraphNumberingSourcesFromBoundary({
32
+ numPr: paragraph?.formatting?.numPr,
33
+ numPrFromStyle: paragraph?.formatting?.numPrFromStyle
34
+ }));
30
35
  const numberingIntent = (session, paragraphs, request) => {
31
36
  const definitions = session.document.package.numbering;
32
37
  const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
@@ -184,8 +189,8 @@ const prepareCanonicalCommands = (session, state, commands) => {
184
189
  case "toggleList": {
185
190
  const definitions = session.document.package.numbering;
186
191
  const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
187
- if (!(paragraphs.length > 0 && paragraphs.every(({ formatting }) => {
188
- const numPr = formatting?.numPr;
192
+ if (!(paragraphs.length > 0 && paragraphs.every((paragraph) => {
193
+ const numPr = effectiveNumbering(paragraph);
189
194
  return numPr?.kind === "reference" && numberingLevelUsesBulletMarker(map?.getLevel(numPr.numId, numPr.ilvl ?? 0)) === (command.kind === "bullet");
190
195
  }))) {
191
196
  intents.push(numberingIntent(session, paragraphs, { kind: command.kind === "bullet" ? "bullet" : "numbered" }));
@@ -215,7 +220,7 @@ const prepareCanonicalCommands = (session, state, commands) => {
215
220
  break;
216
221
  case "changeListLevel":
217
222
  for (const paragraph of paragraphs) {
218
- const numPr = paragraph.formatting?.numPr;
223
+ const numPr = effectiveNumbering(paragraph);
219
224
  if (numPr?.kind !== "reference") continue;
220
225
  const at = {
221
226
  story: OP_STORIES.MAIN,
@@ -227,30 +232,46 @@ const prepareCanonicalCommands = (session, state, commands) => {
227
232
  intents.push({
228
233
  type: "formatParagraph",
229
234
  at,
230
- patch: { numPr: level < 0 ? { kind: "none" } : paragraphNumberingReference({
231
- numId: numPr.numId,
232
- ilvl: level
233
- }) }
235
+ patch: { numPr: (() => {
236
+ if (level < 0) return { kind: "none" };
237
+ if (paragraph.formatting?.numPr?.kind !== "reference" && paragraph.formatting?.numPrFromStyle?.kind === "reference") return {
238
+ kind: "levelOnly",
239
+ ilvl: level
240
+ };
241
+ return paragraphNumberingReference({
242
+ numId: numPr.numId,
243
+ ilvl: level
244
+ });
245
+ })() }
234
246
  });
235
247
  }
236
248
  break;
237
249
  case "restartNumbering":
238
250
  case "continueNumbering": {
239
251
  const source = paragraphs.at(0);
240
- const numPr = source?.formatting?.numPr;
252
+ const numPr = effectiveNumbering(source);
241
253
  const definitions = session.document.package.numbering;
242
254
  if (source === void 0 || numPr?.kind !== "reference" || definitions === void 0) return noChange("Numbering changes require a list paragraph.");
243
255
  const body = session.document.package.document.content;
244
256
  const index = body.findIndex((item) => item === source);
245
- const affected = body.slice(index).filter((item) => item.type === "paragraph" && item.formatting?.numPr?.kind === "reference" && item.formatting.numPr.numId === numPr.numId);
257
+ const affected = body.slice(index).filter((item) => {
258
+ if (item.type !== "paragraph") return false;
259
+ const effective = effectiveNumbering(item);
260
+ return effective?.kind === "reference" && effective.numId === numPr.numId;
261
+ });
246
262
  let targetId;
247
263
  let target;
248
264
  if (command.type === "continueNumbering") {
249
265
  const map = getCachedNumberingMap(definitions);
250
266
  const bullet = numberingLevelUsesBulletMarker(map.getLevel(numPr.numId, numPr.ilvl ?? 0));
251
- const earlier = body.slice(0, index).findLast((item) => item.type === "paragraph" && item.formatting?.numPr?.kind === "reference" && item.formatting.numPr.numId !== numPr.numId && numberingLevelUsesBulletMarker(map.getLevel(item.formatting.numPr.numId, item.formatting.numPr.ilvl ?? 0)) === bullet);
252
- if (earlier?.type !== "paragraph" || earlier.formatting?.numPr?.kind !== "reference") return noChange("There is no preceding compatible list.");
253
- targetId = earlier.formatting.numPr.numId;
267
+ const earlier = body.slice(0, index).findLast((item) => {
268
+ if (item.type !== "paragraph") return false;
269
+ const effective = effectiveNumbering(item);
270
+ return effective?.kind === "reference" && effective.numId !== numPr.numId && numberingLevelUsesBulletMarker(map.getLevel(effective.numId, effective.ilvl ?? 0)) === bullet;
271
+ });
272
+ const earlierNumbering = earlier?.type === "paragraph" ? effectiveNumbering(earlier) : void 0;
273
+ if (earlierNumbering?.kind !== "reference") return noChange("There is no preceding compatible list.");
274
+ targetId = earlierNumbering.numId;
254
275
  target = {
255
276
  type: "existing",
256
277
  numId: targetId
@@ -278,14 +299,17 @@ const prepareCanonicalCommands = (session, state, commands) => {
278
299
  intents.push({
279
300
  type: "setList",
280
301
  target,
281
- items: affected.map((paragraph) => ({
282
- at: {
283
- story: OP_STORIES.MAIN,
284
- blockId: paragraph.paraId ?? "",
285
- offset: 0
286
- },
287
- ilvl: paragraph.formatting?.numPr?.kind === "reference" ? paragraph.formatting.numPr.ilvl ?? 0 : 0
288
- }))
302
+ items: affected.map((paragraph) => {
303
+ const effective = effectiveNumbering(paragraph);
304
+ return {
305
+ at: {
306
+ story: OP_STORIES.MAIN,
307
+ blockId: paragraph.paraId ?? "",
308
+ offset: 0
309
+ },
310
+ ilvl: effective?.kind === "reference" ? effective.ilvl ?? 0 : 0
311
+ };
312
+ })
289
313
  });
290
314
  break;
291
315
  }
@@ -299,7 +323,7 @@ const prepareCanonicalAutoformat = (session, state, { from, to, text }) => {
299
323
  const at = session.projection.addressAt(from);
300
324
  if (at.isErr()) return void 0;
301
325
  const address = session.projection.paragraph(at.value.blockId);
302
- if (address === void 0 || address.source.formatting?.numPr?.kind === "reference") return void 0;
326
+ if (address === void 0 || effectiveNumbering(address.source)?.kind === "reference") return void 0;
303
327
  const source = address.source;
304
328
  const prefix = address.text.slice(0, at.value.offset) + text;
305
329
  const requests = listRequestsForMarker(prefix);
@@ -1,7 +1,7 @@
1
1
  import { document_d_exports } from "./types/document.js";
2
2
  import { FolioTableTemplates } from "./ai-edits/table-template.js";
3
3
  import { FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditNormalization, FolioAIEditOperation, FolioAIEditPrecondition, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAITextRangeHandle } from "./ai-edits/types.js";
4
- import { FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioUndefinedStylePolicy, FolioWordDiffOptions } from "./ai-edits/apply.js";
4
+ import { FolioAIEditView, FolioReplacementBackground, FolioRevisionStamp, FolioUndefinedReferencePolicy, FolioWordDiffOptions } from "./ai-edits/apply.js";
5
5
  //#region src/document-operations.d.ts
6
6
  declare const FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION: 1;
7
7
  /** Direct paragraph-alignment values accepted by the operation contract. */
@@ -298,14 +298,9 @@ type ApplyFolioDocumentOperationsOptions = {
298
298
  * revised document — keeps them instead.
299
299
  */
300
300
  replacementBackground?: FolioReplacementBackground;
301
- /**
302
- * What an operation naming a paragraph style the document does not define
303
- * does. Refusing it (`missingStyle`) is the default; a caller copying the
304
- * style references of another document — a comparison reproducing the
305
- * revised one — keeps them instead.
306
- */
307
- undefinedStyles?: FolioUndefinedStylePolicy;
301
+ /** Required policy for undefined style and numbering references. */
302
+ undefinedReferences: FolioUndefinedReferencePolicy;
308
303
  };
309
- declare const applyFolioDocumentOperations: ({ view, snapshot, batch, story, author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedStyles }: ApplyFolioDocumentOperationsOptions) => FolioDocumentOperationResult;
304
+ declare const applyFolioDocumentOperations: ({ view, snapshot, batch, story, author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences }: ApplyFolioDocumentOperationsOptions) => FolioDocumentOperationResult;
310
305
  //#endregion
311
306
  export { ApplyFolioDocumentOperationsOptions, FOLIO_DOCUMENT_OPERATION_BATCH_MODES, FOLIO_DOCUMENT_OPERATION_BATCH_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION, FOLIO_DOCUMENT_OPERATION_KEYS_BY_TYPE, FOLIO_DOCUMENT_OPERATION_MODES, FOLIO_DOCUMENT_OPERATION_MODES_BY_TYPE, FOLIO_DOCUMENT_OPERATION_PRECONDITIONS, FOLIO_DOCUMENT_OPERATION_STORIES, FOLIO_DOCUMENT_OPERATION_TYPES, FOLIO_LINE_SPACING_RULE_VALUES, FOLIO_PAGE_BREAK_CLEAR_VALUES, FOLIO_PARAGRAPH_ALIGNMENT_VALUES, FolioDocumentOperation, FolioDocumentOperationAffectedTarget, FolioDocumentOperationBatch, FolioDocumentOperationBatchPrecondition, FolioDocumentOperationCapabilities, FolioDocumentOperationIssue, FolioDocumentOperationMode, FolioDocumentOperationPrecondition, FolioDocumentOperationQueuedOperation, FolioDocumentOperationReceipt, FolioDocumentOperationRecovery, FolioDocumentOperationResult, FolioDocumentOperationResultBase, FolioDocumentOperationStatus, FolioDocumentOperationStory, FolioDocumentOperationType, FolioDocumentOperationUndoFailureReason, FolioDocumentOperationUndoHandle, FolioDocumentOperationUndoResult, InvalidFolioDocumentOperationBatchError, UnsupportedFolioDocumentOperationVersionError, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioDocumentOperationReceiptsForStory, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch };
@@ -1,13 +1,13 @@
1
1
  import { applyFolioAIEditOperations, previewFolioAIEditOperationsWithResult } from "./ai-edits/apply.js";
2
2
  import { describeModelError, findIntroducedModelErrors } from "./ai-edits/result-validation.js";
3
3
  import { LIST_KINDS } from "./docx/listNumberingInstances.js";
4
- import { isNumberingReference } from "./docx/numberingReference.js";
5
4
  import { completeNumberingForDoc } from "./prosemirror/listInstanceReferences.js";
6
5
  import { outlineLevelFromAttrValue } from "./prosemirror/outlineLevelAttr.js";
7
6
  import { getStatedDocumentNumbering } from "./prosemirror/plugins/documentNumbering.js";
8
7
  import { LINE_SPACING_RULE_VALUES, PARAGRAPH_ALIGNMENT_VALUES } from "./types/documentEnumValues.js";
9
8
  import { TaggedError } from "better-result";
10
9
  import { sanitizeXmlCharacters } from "@stll/docx-core";
10
+ import { isNumberingReference, paragraphNumberingReference } from "@stll/docx-core/model";
11
11
  //#region src/document-operations.ts
12
12
  const FOLIO_DOCUMENT_OPERATION_CONTRACT_VERSION = 1;
13
13
  /** Direct paragraph-alignment values accepted by the operation contract. */
@@ -210,16 +210,6 @@ const readNonNegativeInteger = (value, key, path) => {
210
210
  if (typeof candidate === "number" && Number.isSafeInteger(candidate) && candidate >= 0) return candidate;
211
211
  return invalidBatch(`${path}.${key}`, "expected a non-negative safe integer");
212
212
  };
213
- /**
214
- * A non-negative integer that may also be cleared. `undefined` is "say
215
- * nothing"; `null` is "there is none", which is a different instruction and
216
- * the one absence alone cannot give.
217
- */
218
- const readClearableNonNegativeInteger = (value, key, path) => {
219
- const candidate = value[key];
220
- if (candidate === void 0) return;
221
- return candidate === null ? null : readNonNegativeInteger(value, key, path);
222
- };
223
213
  const readClearableParagraphAlignment = ({ value, key, path }) => {
224
214
  const candidate = value[key];
225
215
  if (candidate === void 0 || candidate === null) return candidate;
@@ -302,43 +292,64 @@ const readClearableParagraphIndentation = ({ value, key, path }) => {
302
292
  const MAX_NEW_LIST_LEVEL = 8;
303
293
  const LIST_KIND_SET = new Set(LIST_KINDS);
304
294
  const isListKind = (value) => LIST_KIND_SET.has(value);
305
- /** `{ start: "new", kind, level? }`: a list the operation starts. */
295
+ /** `{ kind: "newList", format, level? }`: a list the operation starts. */
306
296
  const readNewListReference = (candidate, numberingPath) => {
307
297
  assertAllowedKeys(candidate, numberingPath, [
308
- "start",
309
298
  "kind",
299
+ "format",
310
300
  "level"
311
301
  ]);
312
- const kind = candidate["kind"];
313
- if (typeof kind !== "string" || !isListKind(kind)) return invalidBatch(`${numberingPath}.kind`, `expected one of ${LIST_KINDS.join(", ")}`);
302
+ const format = candidate["format"];
303
+ if (typeof format !== "string" || !isListKind(format)) return invalidBatch(`${numberingPath}.format`, `expected one of ${LIST_KINDS.join(", ")}`);
314
304
  if (candidate["level"] === void 0) return {
315
- start: "new",
316
- kind
305
+ kind: "newList",
306
+ format
317
307
  };
318
308
  const level = readNonNegativeInteger(candidate, "level", numberingPath);
319
309
  if (level > MAX_NEW_LIST_LEVEL) return invalidBatch(`${numberingPath}.level`, `expected at most ${MAX_NEW_LIST_LEVEL}`);
320
310
  return {
321
- start: "new",
322
- kind,
311
+ kind: "newList",
312
+ format,
323
313
  level
324
314
  };
325
315
  };
326
316
  const readClearableNumbering = ({ value, key, path }) => {
327
317
  const candidate = value[key];
328
- if (candidate === void 0 || candidate === null) return candidate;
318
+ if (candidate === void 0) return void 0;
329
319
  const numberingPath = `${path}.${key}`;
330
- if (!isPlainObject(candidate)) return invalidBatch(numberingPath, "expected an object or null when provided");
331
- if (candidate["start"] !== void 0) {
332
- if (candidate["start"] !== "new") return invalidBatch(`${numberingPath}.start`, "expected \"new\"");
333
- return readNewListReference(candidate, numberingPath);
320
+ if (!isPlainObject(candidate)) return invalidBatch(numberingPath, "expected a numbering object");
321
+ const kind = candidate["kind"];
322
+ if (kind === "none" || kind === "inherit") {
323
+ assertAllowedKeys(candidate, numberingPath, ["kind"]);
324
+ return { kind };
334
325
  }
335
- assertAllowedKeys(candidate, numberingPath, ["numId", "level"]);
336
- const numId = readNonNegativeInteger(candidate, "numId", numberingPath);
337
- if (!isNumberingReference(numId)) return invalidBatch(`${numberingPath}.numId`, "expected a positive integer");
338
- return {
339
- numId,
340
- level: readNonNegativeInteger(candidate, "level", numberingPath)
341
- };
326
+ if (kind === "levelOnly") {
327
+ assertAllowedKeys(candidate, numberingPath, ["kind", "ilvl"]);
328
+ const ilvl = readNonNegativeInteger(candidate, "ilvl", numberingPath);
329
+ if (ilvl > MAX_NEW_LIST_LEVEL) return invalidBatch(`${numberingPath}.ilvl`, `expected at most ${MAX_NEW_LIST_LEVEL}`);
330
+ return {
331
+ kind,
332
+ ilvl
333
+ };
334
+ }
335
+ if (kind === "reference") {
336
+ assertAllowedKeys(candidate, numberingPath, [
337
+ "kind",
338
+ "numId",
339
+ "ilvl"
340
+ ]);
341
+ const numId = readNonNegativeInteger(candidate, "numId", numberingPath);
342
+ if (!isNumberingReference(numId)) return invalidBatch(`${numberingPath}.numId`, "expected a positive integer");
343
+ if (candidate["ilvl"] === void 0) return paragraphNumberingReference({ numId });
344
+ const ilvl = readNonNegativeInteger(candidate, "ilvl", numberingPath);
345
+ if (ilvl > MAX_NEW_LIST_LEVEL) return invalidBatch(`${numberingPath}.ilvl`, `expected at most ${MAX_NEW_LIST_LEVEL}`);
346
+ return paragraphNumberingReference({
347
+ numId,
348
+ ilvl
349
+ });
350
+ }
351
+ if (kind === "newList") return readNewListReference(candidate, numberingPath);
352
+ return invalidBatch(`${numberingPath}.kind`, "expected \"none\", \"inherit\", \"levelOnly\", \"reference\", or \"newList\"");
342
353
  };
343
354
  /**
344
355
  * A rectangular grid of cell texts. Rectangular because a table whose rows
@@ -376,7 +387,6 @@ const readParagraphProperties = ({ value, key, path }) => {
376
387
  assertAllowedKeys(candidate, propertiesPath, [
377
388
  "styleId",
378
389
  "outlineLevel",
379
- "listLevel",
380
390
  "numbering",
381
391
  "alignment",
382
392
  "spacing",
@@ -384,7 +394,6 @@ const readParagraphProperties = ({ value, key, path }) => {
384
394
  ]);
385
395
  const styleId = candidate["styleId"] === null ? null : readOptionalString(candidate, "styleId", propertiesPath);
386
396
  const outlineLevel = readClearableOutlineLevel(candidate, propertiesPath);
387
- const listLevel = readClearableNonNegativeInteger(candidate, "listLevel", propertiesPath);
388
397
  const numbering = readClearableNumbering({
389
398
  value: candidate,
390
399
  key: "numbering",
@@ -405,11 +414,10 @@ const readParagraphProperties = ({ value, key, path }) => {
405
414
  key: "indentation",
406
415
  path: propertiesPath
407
416
  });
408
- if (styleId === void 0 && outlineLevel === void 0 && listLevel === void 0 && numbering === void 0 && alignment === void 0 && spacing === void 0 && indentation === void 0) return invalidBatch(propertiesPath, "expected at least one property to set");
417
+ if (styleId === void 0 && outlineLevel === void 0 && numbering === void 0 && alignment === void 0 && spacing === void 0 && indentation === void 0) return invalidBatch(propertiesPath, "expected at least one property to set");
409
418
  return {
410
419
  ...styleId !== void 0 && { styleId },
411
420
  ...outlineLevel !== void 0 && { outlineLevel },
412
- ...listLevel !== void 0 && { listLevel },
413
421
  ...numbering !== void 0 && { numbering },
414
422
  ...alignment !== void 0 && { alignment },
415
423
  ...spacing !== void 0 && { spacing },
@@ -555,7 +563,6 @@ const OPERATION_KEY_DECISIONS = {
555
563
  indentation: true,
556
564
  lineBreakMode: true,
557
565
  formattingScope: true,
558
- listLevel: true,
559
566
  numbering: true,
560
567
  moveId: true,
561
568
  pageBreakBefore: true,
@@ -573,7 +580,6 @@ const OPERATION_KEY_DECISIONS = {
573
580
  indentation: true,
574
581
  lineBreakMode: true,
575
582
  formattingScope: true,
576
- listLevel: true,
577
583
  numbering: true,
578
584
  moveId: true,
579
585
  pageBreakBefore: true,
@@ -833,7 +839,6 @@ const parseDocumentOperation = (value, index) => {
833
839
  const styleId = value["styleId"] === null ? null : readOptionalString(value, "styleId", path);
834
840
  const outlineLevel = readClearableOutlineLevel(value, path);
835
841
  const moveId = readOptionalString(value, "moveId", path);
836
- const listLevel = readClearableNonNegativeInteger(value, "listLevel", path);
837
842
  const numbering = readClearableNumbering({
838
843
  value,
839
844
  key: "numbering",
@@ -874,7 +879,6 @@ const parseDocumentOperation = (value, index) => {
874
879
  ...indentation !== void 0 && { indentation },
875
880
  ...lineBreakMode !== void 0 && { lineBreakMode },
876
881
  ...formattingScope !== void 0 && { formattingScope },
877
- ...listLevel !== void 0 && { listLevel },
878
882
  ...numbering !== void 0 && { numbering },
879
883
  ...moveId !== void 0 && { moveId },
880
884
  ...pageBreakBefore !== void 0 && { pageBreakBefore },
@@ -1250,7 +1254,7 @@ const inOperationOrder = (operations, skipped) => {
1250
1254
  const indexById = new Map(operations.map(({ id }, index) => [id, index]));
1251
1255
  return [...skipped].sort((left, right) => (indexById.get(left.id) ?? -1) - (indexById.get(right.id) ?? -1));
1252
1256
  };
1253
- const applyFolioDocumentOperations = ({ view, snapshot, batch, story = "main", author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedStyles }) => {
1257
+ const applyFolioDocumentOperations = ({ view, snapshot, batch, story = "main", author, createCommentId, createUndoHandle, revisionStamp, wordDiff, tableTemplates, replacementBackground, undefinedReferences }) => {
1254
1258
  const parsedBatch = parseFolioDocumentOperationBatch(batch);
1255
1259
  const isAtomic = parsedBatch.atomic === true;
1256
1260
  const beforeDoc = view.state.doc;
@@ -1265,7 +1269,7 @@ const applyFolioDocumentOperations = ({ view, snapshot, batch, story = "main", a
1265
1269
  ...wordDiff !== void 0 && { wordDiff },
1266
1270
  ...tableTemplates !== void 0 && { tableTemplates },
1267
1271
  ...replacementBackground !== void 0 && { replacementBackground },
1268
- ...undefinedStyles !== void 0 && { undefinedStyles }
1272
+ undefinedReferences
1269
1273
  };
1270
1274
  if (preview) return {
1271
1275
  ...previewFolioAIEditOperationsWithResult({
@@ -1,5 +1,5 @@
1
- import { XmlElement } from "./xmlParser.js";
2
1
  import { ModelledAttributes } from "./propertyElementAttributes.js";
2
+ import { XmlElement } from "./xmlParser.js";
3
3
  import { PreservedAttribute } from "@stll/docx-core/model";
4
4
  //#region src/docx/attributeRemainder.d.ts
5
5
  declare const InvalidPreservedAttributeError_base: import("better-result").TaggedErrorClass<"InvalidPreservedAttributeError">;
@@ -1,6 +1,6 @@
1
1
  import { getCachedNumberingMap } from "./numberingParser.js";
2
- import { NO_NUMBERING_NUM_ID, NO_PARAGRAPH_NUMBERING, ParagraphNumberingOverride, ParagraphNumberingSlots, ResolvedParagraphNumbering, isNumberingReference, mergeParagraphNumbering, paragraphNumberingFromSlots, paragraphNumberingLevel, paragraphNumberingReferenceId, paragraphNumberingSlots, readParagraphNumbering, resolveParagraphNumbering, sameEffectiveParagraphNumbering, sameStatedParagraphNumbering } from "./numberingReference.js";
3
2
  import { DOCX_ENCRYPTION_ERROR_CODES, DocxEncryptionError, DocxEncryptionErrorCode, isDocxEncryptionError } from "./encryption/errors.js";
4
3
  import { DecryptDocxOptions, DecryptDocxResult, decryptDocxIfNeeded, openDocxBuffer } from "./encryption/openEncryptedDocx.js";
4
+ import { NO_NUMBERING_NUM_ID, NO_PARAGRAPH_NUMBERING, ParagraphNumberingOverride, ParagraphNumberingSlots, ResolvedParagraphNumbering, isNumberingReference, mergeParagraphNumbering, paragraphNumberingFromSlots, paragraphNumberingLevel, paragraphNumberingReferenceId, paragraphNumberingSlots, readParagraphNumbering, resolveParagraphNumbering, sameEffectiveParagraphNumbering, sameStatedParagraphNumbering } from "./numberingReference.js";
5
5
  import { FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, FolioDocumentMetadataProperty, FolioDocumentPrivacyArchiveError, FolioDocumentPrivacyOptions, FolioDocumentPrivacyReport, FolioDocumentPrivacyTransform, InvalidFolioDocumentPrivacyOptionsError, RewriteDocxMetadataPrivacyResult, isFolioDocumentPrivacyTransform, rewriteDocxMetadataPrivacy } from "./metadataPrivacy.js";
6
6
  export { DOCX_ENCRYPTION_ERROR_CODES, type DecryptDocxOptions, type DecryptDocxResult, DocxEncryptionError, type DocxEncryptionErrorCode, FOLIO_DOCUMENT_METADATA_PROPERTIES, FOLIO_DOCUMENT_PRIVACY_TRANSFORMS, type FolioDocumentMetadataProperty, FolioDocumentPrivacyArchiveError, type FolioDocumentPrivacyOptions, type FolioDocumentPrivacyReport, type FolioDocumentPrivacyTransform, InvalidFolioDocumentPrivacyOptionsError, NO_NUMBERING_NUM_ID, NO_PARAGRAPH_NUMBERING, type ParagraphNumberingOverride, type ParagraphNumberingSlots, type ResolvedParagraphNumbering, type RewriteDocxMetadataPrivacyResult, decryptDocxIfNeeded, getCachedNumberingMap, isDocxEncryptionError, isFolioDocumentPrivacyTransform, isNumberingReference, mergeParagraphNumbering, openDocxBuffer, paragraphNumberingFromSlots, paragraphNumberingLevel, paragraphNumberingReferenceId, paragraphNumberingSlots, readParagraphNumbering, resolveParagraphNumbering, rewriteDocxMetadataPrivacy, sameEffectiveParagraphNumbering, sameStatedParagraphNumbering };
@@ -1,6 +1,6 @@
1
1
  import { bulletMarkerFontName, convertBulletToUnicode } from "./bulletMarkers.js";
2
+ import { resolveListTemplate } from "./listTemplate.js";
2
3
  import { isNumberingReference } from "./numberingReference.js";
3
- import { formatOoxmlCounter } from "./ooxmlCounterFormatter.js";
4
4
  //#region src/docx/listMarkerComputation.ts
5
5
  const computeListMarker = (paragraph, { numbering, listCounters, abstractCounters, restartedNumIds, previousList }) => {
6
6
  const listRendering = paragraph.listRendering;
@@ -22,7 +22,7 @@ const computeListMarker = (paragraph, { numbering, listCounters, abstractCounter
22
22
  let counters = listCounters.get(numId);
23
23
  if (!counters) return;
24
24
  const abstractNumId = numbering.getAbstractNumId(numId);
25
- const styleNumbering = paragraph.formatting?.numPrFromStyle;
25
+ const styleNumbering = paragraph.formatting?.numPr?.kind !== "reference" && paragraph.formatting?.numPrFromStyle?.kind === "reference";
26
26
  const resumesRestartedInstance = firstEncounter && listRendering.startOverride === void 0 && abstractNumId !== null && previousList.abstractNumId === abstractNumId && previousList.numId !== null && previousList.numId !== numId && restartedNumIds.has(previousList.numId);
27
27
  const resumesStyleInstance = firstEncounter && !styleNumbering && listRendering.startOverride === void 0 && abstractNumId !== null && previousList.abstractNumId === abstractNumId && previousList.fromStyle === true;
28
28
  if (abstractNumId !== null && (styleNumbering || resumesRestartedInstance || resumesStyleInstance)) {
@@ -60,18 +60,13 @@ const computeListMarker = (paragraph, { numbering, listCounters, abstractCounter
60
60
  previousList.numId = null;
61
61
  return;
62
62
  }
63
- let computedMarker = pattern;
64
- const useLegalNumbering = numbering.getLevel(numId, level)?.isLgl === true || listRendering.isLegal === true;
65
- for (let lvl = 0; lvl <= level; lvl += 1) {
66
- const placeholder = `%${lvl + 1}`;
67
- if (computedMarker.includes(placeholder)) {
68
- const value = counters[lvl] ?? 0;
69
- const levelInfo = numbering.getLevel(numId, lvl);
70
- const formatted = formatOoxmlCounter(value, useLegalNumbering ? "decimal" : levelInfo?.numFmt || "decimal");
71
- computedMarker = computedMarker.replaceAll(placeholder, formatted);
72
- }
73
- }
74
- listRendering.marker = computedMarker;
63
+ const currentLevelInfo = numbering.getLevel(numId, level);
64
+ listRendering.marker = resolveListTemplate({
65
+ template: pattern,
66
+ counters,
67
+ levelFormats: listRendering.levelNumFmts ?? counters.map((_counter, ilvl) => numbering.getLevel(numId, ilvl)?.numFmt),
68
+ forceDecimal: currentLevelInfo?.isLgl === true || listRendering.isLegal === true
69
+ });
75
70
  };
76
71
  //#endregion
77
72
  export { computeListMarker };
@@ -0,0 +1,22 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ //#region src/docx/listTemplate.d.ts
3
+ type ResolvedListComponent = {
4
+ level: number;
5
+ relativeStart: number;
6
+ start: number;
7
+ end: number;
8
+ };
9
+ type ResolvedListTemplate = {
10
+ value: string;
11
+ components: readonly ResolvedListComponent[];
12
+ };
13
+ type ResolveListTemplateOptions = {
14
+ template: string;
15
+ counters: readonly number[];
16
+ levelFormats?: readonly (document_d_exports.CounterFormat | undefined)[] | undefined;
17
+ forceDecimal?: boolean | undefined;
18
+ };
19
+ declare function resolveListTemplate(options: ResolveListTemplateOptions): string;
20
+ declare function resolveListTemplateWithComponents({ template, counters, levelFormats, forceDecimal }: ResolveListTemplateOptions): ResolvedListTemplate;
21
+ //#endregion
22
+ export { ResolvedListComponent, ResolvedListTemplate, resolveListTemplate, resolveListTemplateWithComponents };
@@ -0,0 +1,40 @@
1
+ import { formatOoxmlCounter } from "./ooxmlCounterFormatter.js";
2
+ //#region src/docx/listTemplate.ts
3
+ function resolveListTemplate(options) {
4
+ return resolveListTemplateWithComponents(options).value;
5
+ }
6
+ function resolveListTemplateWithComponents({ template, counters, levelFormats, forceDecimal = false }) {
7
+ const components = [];
8
+ let value = "";
9
+ let sourceEnd = 0;
10
+ for (const match of template.matchAll(/%(?<digit>\d)(?<punct>[.):\]])?/gu)) {
11
+ const sourceStart = match.index;
12
+ const relativeStart = value.length;
13
+ value += template.slice(sourceEnd, sourceStart);
14
+ sourceEnd = sourceStart + match[0].length;
15
+ const index = Number.parseInt(match.groups?.["digit"] ?? "", 10) - 1;
16
+ const counter = counters[index];
17
+ if (index < 0 || counter === void 0 || !Number.isFinite(counter)) {
18
+ value += match.groups?.["punct"] ?? "";
19
+ continue;
20
+ }
21
+ const formatted = formatOoxmlCounter(counter, forceDecimal ? "decimal" : levelFormats?.[index]);
22
+ if (!formatted) continue;
23
+ const start = value.length;
24
+ value += formatted;
25
+ components.push({
26
+ level: index,
27
+ relativeStart,
28
+ start,
29
+ end: value.length
30
+ });
31
+ value += match.groups?.["punct"] ?? "";
32
+ }
33
+ value += template.slice(sourceEnd);
34
+ return {
35
+ value,
36
+ components
37
+ };
38
+ }
39
+ //#endregion
40
+ export { resolveListTemplate, resolveListTemplateWithComponents };