@stll/folio-core 0.14.1 → 0.15.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.
- package/dist/compat/eigenpal.d.ts +2 -1
- package/dist/compat/eigenpal.js +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/markdown/fromMarkdown.js +55 -5
- package/dist/utils/mergeDocumentContent.d.ts +29 -0
- package/dist/utils/mergeDocumentContent.js +145 -0
- package/package.json +2 -2
|
@@ -11,6 +11,7 @@ import { ResolvedAnchor, isSuggestionStale, resolveSuggestionAnchor } from "../a
|
|
|
11
11
|
import { PositionalText, buildPositionalText } from "../ai-suggestions/text-positions.js";
|
|
12
12
|
import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocumentPreset, DocumentStyleSet } from "../style-sets/types.js";
|
|
13
13
|
import { CreateEmptyDocumentOptions, createEmptyDocument } from "../utils/createDocument.js";
|
|
14
|
+
import { mergeDocumentContent } from "../utils/mergeDocumentContent.js";
|
|
14
15
|
import { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSetOptions, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "../style-sets/extract.js";
|
|
15
16
|
import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "../style-sets/stellaStyle.js";
|
|
16
17
|
import { createDocx } from "../docx/rezip.js";
|
|
@@ -32,4 +33,4 @@ import { getGoogleFontsEnabled, setEmbeddedFontFamilyMap, setGoogleFontsEnabled
|
|
|
32
33
|
import { DOCX_CONFORMANCE_CLASSES } from "../index.js";
|
|
33
34
|
type Document = document_d_exports.Document;
|
|
34
35
|
type DocxConformanceClass = document_d_exports.DocxConformanceClass;
|
|
35
|
-
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 CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, 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 FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAISignatureParty, type FolioBlockId, 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 FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidFolioDocumentOperationBatchError, type MarkdownOptions, type MarkdownResult, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
|
|
36
|
+
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 CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, 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 FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAISignatureParty, type FolioBlockId, 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 FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidFolioDocumentOperationBatchError, type MarkdownOptions, type MarkdownResult, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, 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 };
|
package/dist/compat/eigenpal.js
CHANGED
|
@@ -6,6 +6,7 @@ import { applyFolioAIEditOperations } from "../ai-edits/apply.js";
|
|
|
6
6
|
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, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "../document-operations.js";
|
|
7
7
|
import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION } from "../style-sets/types.js";
|
|
8
8
|
import { createEmptyDocument } from "../utils/createDocument.js";
|
|
9
|
+
import { mergeDocumentContent } from "../utils/mergeDocumentContent.js";
|
|
9
10
|
import { extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "../style-sets/extract.js";
|
|
10
11
|
import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "../style-sets/stellaStyle.js";
|
|
11
12
|
import { createDocx } from "../docx/rezip.js";
|
|
@@ -27,4 +28,4 @@ import { fromMarkdown } from "../markdown/fromMarkdown.js";
|
|
|
27
28
|
import { toMarkdown, toMarkdownResult } from "../markdown/index.js";
|
|
28
29
|
import { buildEmbeddedFontFamilyMap, extractEmbeddedFonts, getEmbeddedFontFaces, scopeEmbeddedFontFamily } from "../fonts/embeddedFonts.js";
|
|
29
30
|
import { DOCX_CONFORMANCE_CLASSES } from "../index.js";
|
|
30
|
-
export { DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, 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, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
|
|
31
|
+
export { DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, 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, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { ResolvedAnchor, isSuggestionStale, resolveSuggestionAnchor } from "./ai
|
|
|
11
11
|
import { PositionalText, buildPositionalText } from "./ai-suggestions/text-positions.js";
|
|
12
12
|
import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DocumentPreset, DocumentStyleSet } from "./style-sets/types.js";
|
|
13
13
|
import { CreateEmptyDocumentOptions, createEmptyDocument } from "./utils/createDocument.js";
|
|
14
|
+
import { mergeDocumentContent } from "./utils/mergeDocumentContent.js";
|
|
14
15
|
import { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSetOptions, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "./style-sets/extract.js";
|
|
15
16
|
import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
|
|
16
17
|
import { createDocx } from "./docx/rezip.js";
|
|
@@ -32,4 +33,4 @@ import { getGoogleFontsEnabled, setEmbeddedFontFamilyMap, setGoogleFontsEnabled
|
|
|
32
33
|
import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
|
|
33
34
|
type Document = document_d_exports.Document;
|
|
34
35
|
type DocxConformanceClass = document_d_exports.DocxConformanceClass;
|
|
35
|
-
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 CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, 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 FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAISignatureParty, type FolioBlockId, 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 FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidFolioDocumentOperationBatchError, type MarkdownOptions, type MarkdownResult, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
|
|
36
|
+
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 CreateEmptyDocumentOptions, DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, type DeriveBlockIdInput, type DirectiveKind, type DirectiveRange, type Document, type DocumentPreset, type DocumentStyleCatalog, type DocumentStyleCatalogEntry, type DocumentStyleSet, type DocxCompatibility, type DocxCompatibilityContext, type DocxCompatibilityIssue, type DocxCompatibilityLocation, type DocxCompatibilityPart, type DocxConformanceClass, type EmbeddedFont, type EmbeddedFontParts, type ExtractDocumentStyleSetOptions, 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 FolioAIEditAppliedOperation, type FolioAIEditApplyMode, type FolioAIEditApplyResult, type FolioAIEditOperation, type FolioAIEditPrecondition, type FolioAIEditReviewMeta, type FolioAIEditSeverity, type FolioAIEditSkipReason, type FolioAIEditSkippedOperation, type FolioAIEditSnapshot, type FolioAISignatureParty, type FolioBlockId, 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 FolioDocxCompatibilityHost, type FolioDocxCompatibilityProfile, type ImageMeta, type ImageRef, type InspectDocxCompatibilityOptions, InvalidFolioDocumentOperationBatchError, type MarkdownOptions, type MarkdownResult, type PositionalText, type ResolvedAnchor, STELLA_STYLE_SET_NAME, type TemplatePreviewSpan, type TemplatePreviewValue, type TemplatePreviewValues, type TemplateSlashMenuKeyAction, type TemplateSlashMenuState, UnsupportedFolioDocumentOperationVersionError, type WordDiffSegment, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, 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 };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { applyFolioAIEditOperations } from "./ai-edits/apply.js";
|
|
|
6
6
|
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, applyFolioDocumentOperations, assertSupportedFolioDocumentOperationVersion, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, isFolioDocumentOperationModeSupported, isSupportedFolioDocumentOperationVersion, parseFolioDocumentOperationBatch } from "./document-operations.js";
|
|
7
7
|
import { DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION } from "./style-sets/types.js";
|
|
8
8
|
import { createEmptyDocument } from "./utils/createDocument.js";
|
|
9
|
+
import { mergeDocumentContent } from "./utils/mergeDocumentContent.js";
|
|
9
10
|
import { extractDocumentStyleSet, extractDocumentStyleSetFromDocx, inspectDocumentStyles, inspectDocumentStylesFromDocx } from "./style-sets/extract.js";
|
|
10
11
|
import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
|
|
11
12
|
import { createDocx } from "./docx/rezip.js";
|
|
@@ -27,4 +28,4 @@ import { fromMarkdown } from "./markdown/fromMarkdown.js";
|
|
|
27
28
|
import { toMarkdown, toMarkdownResult } from "./markdown/index.js";
|
|
28
29
|
import { buildEmbeddedFontFamilyMap, extractEmbeddedFonts, getEmbeddedFontFaces, scopeEmbeddedFontFamily } from "./fonts/embeddedFonts.js";
|
|
29
30
|
import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
|
|
30
|
-
export { DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, 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, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, isFolioBlockId, isFolioDocumentOperationModeSupported, isSequentialFolioBlockId, isSuggestionStale, isSupportedFolioDocumentOperationVersion, normalizeFolioAIBlockText, parseFolioDocumentOperationBatch, resetTemplateSlashQuery, resolveSuggestionAnchor, scanDirectives, scopeEmbeddedFontFamily, scrollFolioPositionIntoView, setAICitationsMeta, setAISuggestionsMeta, setActiveCitationMeta, setAnonymizationTermsMeta, setEmbeddedFontFamilyMap, setFocusedSuggestionMeta, setGoogleFontsEnabled, setTemplatePreviewValues, shouldTriggerAutocomplete, startAutocompleteSuggestion, templateSlashMenuKey, toMarkdown, toMarkdownResult };
|
|
31
|
+
export { DEFAULT_AI_SUGGESTION_PRESETS, DEFAULT_AUTOCOMPLETE_DEAD_ZONE_NODES, DOCUMENT_PRESET_VERSION, DOCUMENT_STYLE_SET_VERSION, DOCX_CONFORMANCE_CLASSES, 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, STELLA_STYLE_SET_NAME, UnsupportedFolioDocumentOperationVersionError, acceptAutocompleteSuggestion, acceptAutocompleteWord, anonymizationDecorationsKey, appendAutocompleteToken, applyFolioAIEditOperations, applyFolioDocumentOperations, applySuggestions, assertSupportedFolioDocumentOperationVersion, autocompleteSuggestionKey, autocompleteSuggestionPlugin, buildEmbeddedFontFamilyMap, buildPositionalText, clearAutocompleteSuggestion, clearTemplateSlashMenu, consumeTemplateSlashQuery, createAICitationDecorationsPlugin, createDocx, createEmptyDocument, createFolioAIEditSnapshot, createStellaStyleDocumentPreset, createStellaStyleSet, deriveBlockId, diffWordSegments, extractDocumentStyleSet, extractDocumentStyleSetFromDocx, extractEmbeddedFonts, finishAutocompleteSuggestion, fromMarkdown, getAnonymizationMatches, getAutocompleteSuggestion, getEmbeddedFontFaces, getFolioCaretViewportRect, getFolioDocumentOperationCapabilities, getFolioDocumentOperationIssues, getFolioDocumentOperationReceipts, getFolioParaIdFromBlockId, getFolioSelectionViewportRect, getGoogleFontsEnabled, getTemplateDirectives, getTemplateSlashMenu, hashFolioAIBlockText, inspectDocumentStyles, inspectDocumentStylesFromDocx, inspectDocxCompatibility, 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 };
|
|
@@ -21,6 +21,13 @@ import { marked } from "marked";
|
|
|
21
21
|
* continuous, header/footer-free band (a skill body is a document, not a
|
|
22
22
|
* Word page). Headers/footers live outside `document.content` and are never
|
|
23
23
|
* produced here.
|
|
24
|
+
* - Every markdown list also gets a matching `w:abstractNum`/`w:num` pair in
|
|
25
|
+
* `document.package.numbering` (see {@link buildNumbering}), so the result
|
|
26
|
+
* is self-consistent and `createDocx` never has to fail with a missing
|
|
27
|
+
* numbering definition. Merging this content onto another document that
|
|
28
|
+
* has its own numbering (e.g. a styled preset) needs `mergeDocumentContent`
|
|
29
|
+
* to renumber the two numbering namespaces apart — appending
|
|
30
|
+
* `document.package.document.content` directly can collide.
|
|
24
31
|
*/
|
|
25
32
|
const MONO_FONT = {
|
|
26
33
|
ascii: "Courier New",
|
|
@@ -146,10 +153,24 @@ const tableFromToken = (token) => ({
|
|
|
146
153
|
cells: row.map((c) => cellOf(c))
|
|
147
154
|
}))]
|
|
148
155
|
});
|
|
149
|
-
const
|
|
156
|
+
const LIST_INDENT_STEP_TWIPS = 720;
|
|
157
|
+
const buildListLevel = (ilvl, isBullet, start) => ({
|
|
158
|
+
ilvl,
|
|
159
|
+
...!isBullet && { start },
|
|
160
|
+
numFmt: isBullet ? "bullet" : "decimal",
|
|
161
|
+
lvlText: isBullet ? "•" : `%${ilvl + 1}.`,
|
|
162
|
+
suffix: "tab",
|
|
163
|
+
pPr: {
|
|
164
|
+
indentLeft: LIST_INDENT_STEP_TWIPS * (ilvl + 1),
|
|
165
|
+
indentFirstLine: -360,
|
|
166
|
+
hangingIndent: true
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const listBlocks = (list, level, numId, levels) => {
|
|
150
170
|
const out = [];
|
|
151
171
|
const start = Number(list.start) || 1;
|
|
152
172
|
const decimalLevels = Array.from({ length: level + 1 }, () => "decimal");
|
|
173
|
+
if (!levels.has(level)) levels.set(level, buildListLevel(level, !list.ordered, start));
|
|
153
174
|
for (const item of list.items) {
|
|
154
175
|
const rendering = list.ordered ? {
|
|
155
176
|
marker: `%${level + 1}.`,
|
|
@@ -170,7 +191,7 @@ const listBlocks = (list, level, numId) => {
|
|
|
170
191
|
for (const child of item.tokens) if (isTokenType(child, "list")) nestedLists.push(child);
|
|
171
192
|
else inlineTokens.push(child);
|
|
172
193
|
out.push(listPara(inlineToRuns(inlineTokens, item.text, {}), rendering));
|
|
173
|
-
for (const nested of nestedLists) out.push(...listBlocks(nested, level + 1, numId));
|
|
194
|
+
for (const nested of nestedLists) out.push(...listBlocks(nested, level + 1, numId, levels));
|
|
174
195
|
}
|
|
175
196
|
return out;
|
|
176
197
|
};
|
|
@@ -180,8 +201,12 @@ const blocksFromTokens = (tokens, numIds) => {
|
|
|
180
201
|
const level = Math.min(Math.max(token.depth, 1), 4);
|
|
181
202
|
blocks.push(para(inlineToRuns(token.tokens, token.text, {}), `Heading${level}`));
|
|
182
203
|
} else if (isTokenType(token, "paragraph")) blocks.push(para(inlineToRuns(token.tokens, token.text, {})));
|
|
183
|
-
else if (isTokenType(token, "list"))
|
|
184
|
-
|
|
204
|
+
else if (isTokenType(token, "list")) {
|
|
205
|
+
const numId = numIds.next++;
|
|
206
|
+
const levels = /* @__PURE__ */ new Map();
|
|
207
|
+
numIds.levels.set(numId, levels);
|
|
208
|
+
blocks.push(...listBlocks(token, 0, numId, levels));
|
|
209
|
+
} else if (isTokenType(token, "table")) blocks.push(tableFromToken(token));
|
|
185
210
|
else if (isTokenType(token, "code")) for (const line of token.text.split("\n")) blocks.push(para([textRun(line.length > 0 ? line : " ", { mono: true })]));
|
|
186
211
|
else if (isTokenType(token, "blockquote")) for (const inner of blocksFromTokens(token.tokens, numIds)) {
|
|
187
212
|
const styled = inner.type === "paragraph" ? {
|
|
@@ -207,6 +232,26 @@ const applyMarkdownPageGeometry = (document) => {
|
|
|
207
232
|
section.headerDistance = 0;
|
|
208
233
|
section.footerDistance = 0;
|
|
209
234
|
};
|
|
235
|
+
const buildNumbering = (numIdLevels) => {
|
|
236
|
+
const abstractNums = [];
|
|
237
|
+
const nums = [];
|
|
238
|
+
for (const [numId, levels] of numIdLevels) {
|
|
239
|
+
const sortedLevels = [...levels.entries()].sort(([a], [b]) => a - b).map(([, lvl]) => lvl);
|
|
240
|
+
abstractNums.push({
|
|
241
|
+
abstractNumId: numId,
|
|
242
|
+
multiLevelType: sortedLevels.length > 1 ? "multilevel" : "singleLevel",
|
|
243
|
+
levels: sortedLevels
|
|
244
|
+
});
|
|
245
|
+
nums.push({
|
|
246
|
+
numId,
|
|
247
|
+
abstractNumId: numId
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
abstractNums,
|
|
252
|
+
nums
|
|
253
|
+
};
|
|
254
|
+
};
|
|
210
255
|
/**
|
|
211
256
|
* Convert a markdown string to a parsed `Document`. Synchronous. The result is
|
|
212
257
|
* ready to hand to the editor (`<DocxEditor document={…} />`) and to re-export
|
|
@@ -214,8 +259,13 @@ const applyMarkdownPageGeometry = (document) => {
|
|
|
214
259
|
*/
|
|
215
260
|
function fromMarkdown(markdown) {
|
|
216
261
|
const document = createEmptyDocument();
|
|
217
|
-
const
|
|
262
|
+
const numIds = {
|
|
263
|
+
next: 1,
|
|
264
|
+
levels: /* @__PURE__ */ new Map()
|
|
265
|
+
};
|
|
266
|
+
const blocks = blocksFromTokens(marked.lexer(markdown), numIds);
|
|
218
267
|
if (blocks.length > 0) document.package.document.content = blocks;
|
|
268
|
+
if (numIds.levels.size > 0) document.package.numbering = buildNumbering(numIds.levels);
|
|
219
269
|
applyMarkdownPageGeometry(document);
|
|
220
270
|
return document;
|
|
221
271
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/mergeDocumentContent.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Append `source`'s body content onto `target`'s. Both documents keep their
|
|
6
|
+
* own identity — this returns a new `Document`; neither argument is mutated.
|
|
7
|
+
*
|
|
8
|
+
* `target` wins on everything except content and numbering: its style set,
|
|
9
|
+
* theme, font table, settings, and section/page geometry are unchanged, so
|
|
10
|
+
* merging markdown (or any other document) into a styled preset keeps that
|
|
11
|
+
* preset's look. Only `source`'s numbering — the `w:abstractNum`/`w:num`
|
|
12
|
+
* definitions its content's `numPr` references — travels with it, and every
|
|
13
|
+
* `abstractNumId`/`numId` it carries is renumbered to sit strictly above
|
|
14
|
+
* whatever `target` already uses. This is unconditional (not just on a
|
|
15
|
+
* detected collision): it is simpler to reason about, and makes repeated
|
|
16
|
+
* merges into the same target safe too (merging two sources that each mint
|
|
17
|
+
* `numId` 1 does not collide with each other either).
|
|
18
|
+
*
|
|
19
|
+
* A typical caller composes `fromMarkdown` with a styled preset:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const target = createEmptyDocument({ preset: createStellaStyleDocumentPreset() });
|
|
23
|
+
* const merged = mergeDocumentContent(target, fromMarkdown(markdown));
|
|
24
|
+
* const bytes = await createDocx(merged);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare function mergeDocumentContent(target: document_d_exports.Document, source: document_d_exports.Document): document_d_exports.Document;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { mergeDocumentContent };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
//#region src/utils/mergeDocumentContent.ts
|
|
2
|
+
/**
|
|
3
|
+
* Append `source`'s body content onto `target`'s. Both documents keep their
|
|
4
|
+
* own identity — this returns a new `Document`; neither argument is mutated.
|
|
5
|
+
*
|
|
6
|
+
* `target` wins on everything except content and numbering: its style set,
|
|
7
|
+
* theme, font table, settings, and section/page geometry are unchanged, so
|
|
8
|
+
* merging markdown (or any other document) into a styled preset keeps that
|
|
9
|
+
* preset's look. Only `source`'s numbering — the `w:abstractNum`/`w:num`
|
|
10
|
+
* definitions its content's `numPr` references — travels with it, and every
|
|
11
|
+
* `abstractNumId`/`numId` it carries is renumbered to sit strictly above
|
|
12
|
+
* whatever `target` already uses. This is unconditional (not just on a
|
|
13
|
+
* detected collision): it is simpler to reason about, and makes repeated
|
|
14
|
+
* merges into the same target safe too (merging two sources that each mint
|
|
15
|
+
* `numId` 1 does not collide with each other either).
|
|
16
|
+
*
|
|
17
|
+
* A typical caller composes `fromMarkdown` with a styled preset:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const target = createEmptyDocument({ preset: createStellaStyleDocumentPreset() });
|
|
21
|
+
* const merged = mergeDocumentContent(target, fromMarkdown(markdown));
|
|
22
|
+
* const bytes = await createDocx(merged);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function mergeDocumentContent(target, source) {
|
|
26
|
+
const targetNumbering = target.package.numbering;
|
|
27
|
+
const sourceNumbering = source.package.numbering;
|
|
28
|
+
if (sourceNumbering === void 0 || sourceNumbering.abstractNums.length === 0 && sourceNumbering.nums.length === 0) return {
|
|
29
|
+
...target,
|
|
30
|
+
package: {
|
|
31
|
+
...target.package,
|
|
32
|
+
document: {
|
|
33
|
+
...target.package.document,
|
|
34
|
+
content: [...target.package.document.content, ...source.package.document.content]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const remappedSource = remapContentNumbering(source.package.document.content, sourceNumbering);
|
|
39
|
+
return {
|
|
40
|
+
...target,
|
|
41
|
+
package: {
|
|
42
|
+
...target.package,
|
|
43
|
+
document: {
|
|
44
|
+
...target.package.document,
|
|
45
|
+
content: [...target.package.document.content, ...remappedSource.content]
|
|
46
|
+
},
|
|
47
|
+
numbering: {
|
|
48
|
+
abstractNums: [...targetNumbering?.abstractNums ?? [], ...remappedSource.numbering.abstractNums],
|
|
49
|
+
nums: [...targetNumbering?.nums ?? [], ...remappedSource.numbering.nums]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function remapContentNumbering(content, numbering) {
|
|
54
|
+
const abstractNumIdBase = Math.max(0, ...(targetNumbering?.abstractNums ?? []).map((abstractNum) => abstractNum.abstractNumId));
|
|
55
|
+
const numIdBase = Math.max(0, ...(targetNumbering?.nums ?? []).map((num) => num.numId));
|
|
56
|
+
const abstractNumIdRemap = /* @__PURE__ */ new Map();
|
|
57
|
+
const remappedAbstractNums = numbering.abstractNums.map((abstractNum, index) => {
|
|
58
|
+
const remappedAbstractNumId = abstractNumIdBase + index + 1;
|
|
59
|
+
abstractNumIdRemap.set(abstractNum.abstractNumId, remappedAbstractNumId);
|
|
60
|
+
return {
|
|
61
|
+
...abstractNum,
|
|
62
|
+
abstractNumId: remappedAbstractNumId
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
const numIdRemap = /* @__PURE__ */ new Map();
|
|
66
|
+
const remappedNums = numbering.nums.map((num, index) => {
|
|
67
|
+
const remappedNumId = numIdBase + index + 1;
|
|
68
|
+
numIdRemap.set(num.numId, remappedNumId);
|
|
69
|
+
return {
|
|
70
|
+
...num,
|
|
71
|
+
numId: remappedNumId,
|
|
72
|
+
abstractNumId: abstractNumIdRemap.get(num.abstractNumId) ?? num.abstractNumId
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
content: content.map((block) => remapBlock(block, numIdRemap, abstractNumIdRemap)),
|
|
77
|
+
numbering: {
|
|
78
|
+
abstractNums: remappedAbstractNums,
|
|
79
|
+
nums: remappedNums
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function remapBlock(block, numIdRemap, abstractNumIdRemap) {
|
|
85
|
+
if (block.type === "paragraph") return remapParagraph(block, numIdRemap, abstractNumIdRemap);
|
|
86
|
+
if (block.type === "table") return remapTable(block, numIdRemap, abstractNumIdRemap);
|
|
87
|
+
if ("content" in block && Array.isArray(block.content)) return {
|
|
88
|
+
...block,
|
|
89
|
+
content: block.content.map((child) => remapBlock(child, numIdRemap, abstractNumIdRemap))
|
|
90
|
+
};
|
|
91
|
+
return block;
|
|
92
|
+
}
|
|
93
|
+
function remapTable(table, numIdRemap, abstractNumIdRemap) {
|
|
94
|
+
return {
|
|
95
|
+
...table,
|
|
96
|
+
rows: table.rows.map((row) => ({
|
|
97
|
+
...row,
|
|
98
|
+
cells: row.cells.map((cell) => ({
|
|
99
|
+
...cell,
|
|
100
|
+
content: cell.content.map((item) => remapCellItem(item, numIdRemap, abstractNumIdRemap))
|
|
101
|
+
}))
|
|
102
|
+
}))
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `TableCell.content` is typed as `(Paragraph | Table)[]` — narrower than
|
|
107
|
+
* `BlockContent` — because folio's own DOCX parser flattens a `w:sdt` inside
|
|
108
|
+
* a cell into its `sdtContent` children (see `tableParser.ts`) rather than
|
|
109
|
+
* keeping a `blockSdt` wrapper. A hand-built `Document` is not bound by that
|
|
110
|
+
* invariant, so delegate to `remapBlock` (which fully handles paragraph,
|
|
111
|
+
* table, and container blocks, including nested tables) and only accept its
|
|
112
|
+
* result back into the cell when it is still a `Paragraph | Table` — an
|
|
113
|
+
* anomalous `blockSdt` (or any other shape `remapBlock` had to pass through
|
|
114
|
+
* unchanged) is left as-is rather than smuggled into a field the type system
|
|
115
|
+
* says can't hold it.
|
|
116
|
+
*/
|
|
117
|
+
function remapCellItem(item, numIdRemap, abstractNumIdRemap) {
|
|
118
|
+
const remapped = remapBlock(item, numIdRemap, abstractNumIdRemap);
|
|
119
|
+
return remapped.type === "blockSdt" ? item : remapped;
|
|
120
|
+
}
|
|
121
|
+
function remapParagraph(paragraph, numIdRemap, abstractNumIdRemap) {
|
|
122
|
+
const numId = paragraph.formatting?.numPr?.numId;
|
|
123
|
+
const remappedNumId = numId === void 0 ? void 0 : numIdRemap.get(numId);
|
|
124
|
+
if (remappedNumId === void 0) return paragraph;
|
|
125
|
+
return {
|
|
126
|
+
...paragraph,
|
|
127
|
+
formatting: {
|
|
128
|
+
...paragraph.formatting,
|
|
129
|
+
numPr: {
|
|
130
|
+
...paragraph.formatting?.numPr,
|
|
131
|
+
numId: remappedNumId
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
...paragraph.listRendering && { listRendering: remapListRendering(paragraph.listRendering, remappedNumId, abstractNumIdRemap) }
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function remapListRendering(rendering, remappedNumId, abstractNumIdRemap) {
|
|
138
|
+
return {
|
|
139
|
+
...rendering,
|
|
140
|
+
numId: remappedNumId,
|
|
141
|
+
...rendering.abstractNumId !== void 0 && { abstractNumId: abstractNumIdRemap.get(rendering.abstractNumId) ?? rendering.abstractNumId }
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { mergeDocumentContent };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/folio-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Headless, framework-neutral core of folio: the OOXML (.docx) parser, document model, ProseMirror integration, and page-layout engine. No React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"document-model",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"perf": "bun scripts/profile-editor.ts"
|
|
108
108
|
},
|
|
109
109
|
"dependencies": {
|
|
110
|
-
"@stll/docx-core": "^0.
|
|
110
|
+
"@stll/docx-core": "^0.5.0",
|
|
111
111
|
"@stll/docx-utils": "^0.1.0",
|
|
112
112
|
"@stll/template-conditions": "^0.1.0",
|
|
113
113
|
"better-result": "2.9.2",
|