@stll/folio-core 0.26.0 → 0.27.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.
@@ -1,4 +1,4 @@
1
- import { FolioAIEditSnapshot, FolioAITextRangeHandle } from "./types.js";
1
+ import { FolioAIBlockAnchor, FolioAIEditSnapshot, FolioAITextRangeHandle } from "./types.js";
2
2
  import { Node } from "prosemirror-model";
3
3
  //#region src/ai-edits/blockRange.d.ts
4
4
  type DocPositionRange = {
@@ -40,6 +40,21 @@ type ResolvePassageRangeOptions = {
40
40
  * the needle is empty, or the text does not occur in the block.
41
41
  */
42
42
  declare const resolvePassageRange: ({ blockId, text, doc, snapshot }: ResolvePassageRangeOptions) => DocPositionRange | null;
43
+ /**
44
+ * Resolve a `seq-NNNN` fallback id by document position.
45
+ *
46
+ * A sequential id is only minted for a paragraph the source DOCX left
47
+ * without a `w14:paraId`. The live editor's `ParaIdAllocator` fills
48
+ * that gap with a fresh random hex paraId, so a snapshot of the live
49
+ * document keys the block by that hex and never reproduces the
50
+ * server's `seq-NNNN`: the direct anchor lookup misses, and a
51
+ * paraId-based live lookup can't match either (no node carries a
52
+ * `seq-` paraId). The seq number is the block's 1-based position in
53
+ * the same non-empty-block walk the server extractor and
54
+ * `createFolioAIEditSnapshot` share, so it indexes the snapshot's
55
+ * ordered `blocks` directly.
56
+ */
57
+ declare const resolveSequentialBlockAnchor: (blockId: string, snapshot: FolioAIEditSnapshot) => FolioAIBlockAnchor | undefined;
43
58
  /**
44
59
  * Clamp a `{from, to}` pair so both endpoints fit inside a document of
45
60
  * `docSize` (in PM content positions). Block-boundary snapshots and stale
@@ -54,4 +69,4 @@ declare const resolvePassageRange: ({ blockId, text, doc, snapshot }: ResolvePas
54
69
  */
55
70
  declare function clampRangeToDocSize(docSize: number, range: DocPositionRange): DocPositionRange;
56
71
  //#endregion
57
- export { DocPositionRange, clampRangeToDocSize, resolveFolioAIBlockRange, resolveFolioAITextRange, resolvePassageRange };
72
+ export { DocPositionRange, clampRangeToDocSize, resolveFolioAIBlockRange, resolveFolioAITextRange, resolvePassageRange, resolveSequentialBlockAnchor };
@@ -142,4 +142,4 @@ function clampRangeToDocSize(docSize, range) {
142
142
  };
143
143
  }
144
144
  //#endregion
145
- export { clampRangeToDocSize, resolveFolioAIBlockRange, resolveFolioAITextRange, resolvePassageRange };
145
+ export { clampRangeToDocSize, resolveFolioAIBlockRange, resolveFolioAITextRange, resolvePassageRange, resolveSequentialBlockAnchor };
@@ -16,6 +16,7 @@ import { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSe
16
16
  import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "../style-sets/stellaStyle.js";
17
17
  import { createDocx } from "../docx/rezip.js";
18
18
  import { DocxCompatibility, DocxCompatibilityContext, DocxCompatibilityIssue, DocxCompatibilityLocation, DocxCompatibilityPart, FolioDocxCompatibilityHost, FolioDocxCompatibilityProfile, InspectDocxCompatibilityOptions, inspectDocxCompatibility } from "../docx/compatibility.js";
19
+ import { BlockRect } from "../paged-layout/blockGeometry.js";
19
20
  import { setAISuggestionsMeta, setFocusedSuggestionMeta } from "../prosemirror/plugins/aiSuggestionDecorations.js";
20
21
  import { scrollFolioPositionIntoView } from "../paged-layout/scrollToPmPosition.js";
21
22
  import { getFolioCaretViewportRect, getFolioSelectionViewportRect } from "../paged-layout/selectionViewportRect.js";
@@ -33,4 +34,4 @@ import { getGoogleFontsEnabled, setEmbeddedFontFamilyMap, setGoogleFontsEnabled
33
34
  import { DOCX_CONFORMANCE_CLASSES } from "../index.js";
34
35
  type Document = document_d_exports.Document;
35
36
  type DocxConformanceClass = document_d_exports.DocxConformanceClass;
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 };
37
+ 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, 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.d.ts CHANGED
@@ -17,6 +17,7 @@ import { DocumentStyleCatalog, DocumentStyleCatalogEntry, ExtractDocumentStyleSe
17
17
  import { STELLA_STYLE_SET_NAME, createStellaStyleDocumentPreset, createStellaStyleSet } from "./style-sets/stellaStyle.js";
18
18
  import { createDocx } from "./docx/rezip.js";
19
19
  import { DocxCompatibility, DocxCompatibilityContext, DocxCompatibilityIssue, DocxCompatibilityLocation, DocxCompatibilityPart, FolioDocxCompatibilityHost, FolioDocxCompatibilityProfile, InspectDocxCompatibilityOptions, inspectDocxCompatibility } from "./docx/compatibility.js";
20
+ import { BlockRect } from "./paged-layout/blockGeometry.js";
20
21
  import { setAISuggestionsMeta, setFocusedSuggestionMeta } from "./prosemirror/plugins/aiSuggestionDecorations.js";
21
22
  import { scrollFolioPositionIntoView } from "./paged-layout/scrollToPmPosition.js";
22
23
  import { getFolioCaretViewportRect, getFolioSelectionViewportRect } from "./paged-layout/selectionViewportRect.js";
@@ -34,4 +35,4 @@ import { getGoogleFontsEnabled, setEmbeddedFontFamilyMap, setGoogleFontsEnabled
34
35
  import { DOCX_CONFORMANCE_CLASSES } from "@stll/docx-core/model";
35
36
  type Document = document_d_exports.Document;
36
37
  type DocxConformanceClass = document_d_exports.DocxConformanceClass;
37
- 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 };
38
+ 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, 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 };
@@ -1597,6 +1597,7 @@ function renderPages(pages, container, options = {}) {
1597
1597
  const viewportHeight = window.innerHeight;
1598
1598
  const nearThreshold = viewportHeight * 3;
1599
1599
  const nearIndices = /* @__PURE__ */ new Set();
1600
+ let depopulated = false;
1600
1601
  for (const [el, data] of liveDataMap) {
1601
1602
  if (!data.rendered) continue;
1602
1603
  const rect = el.getBoundingClientRect();
@@ -1609,8 +1610,12 @@ function renderPages(pages, container, options = {}) {
1609
1610
  keepRendered = true;
1610
1611
  break;
1611
1612
  }
1612
- if (!keepRendered && nearIndices.size > 0) depopulatePageShell(el, liveDataMap);
1613
+ if (!keepRendered && nearIndices.size > 0) {
1614
+ depopulatePageShell(el, liveDataMap);
1615
+ depopulated = true;
1616
+ }
1613
1617
  }
1618
+ if (depopulated) emitPainterPainted(container);
1614
1619
  }, {
1615
1620
  root: null,
1616
1621
  rootMargin: `${VIRTUALIZATION_ROOT_MARGIN_PX}px 0px ${VIRTUALIZATION_ROOT_MARGIN_PX}px 0px`
@@ -0,0 +1,32 @@
1
+ import { FolioAIEditSnapshot } from "../ai-edits/types.js";
2
+ //#region src/paged-layout/blockGeometry.d.ts
3
+ /** Painted geometry for one AI-snapshot block in scroll-content coordinates. */
4
+ type BlockRect = {
5
+ blockId: string;
6
+ /** One-based painted page number. */
7
+ page: number;
8
+ /** Pixels from the scroll root's content origin. */
9
+ top: number;
10
+ /** Pixels from the scroll root's content origin. */
11
+ left: number;
12
+ width: number;
13
+ height: number;
14
+ };
15
+ type ReadBlockRectsOptions = {
16
+ blockIds: readonly string[];
17
+ snapshot: FolioAIEditSnapshot;
18
+ pagesContainer: HTMLElement;
19
+ scrollRoot: HTMLElement;
20
+ };
21
+ /**
22
+ * Measure painted snapshot blocks relative to one editor's scroll root.
23
+ *
24
+ * Missing snapshot ids and blocks on unpainted virtual pages are omitted. Each
25
+ * requested block is measured at most once; painted elements are collected in
26
+ * one DOM query per relevant page.
27
+ */
28
+ declare const readBlockRects: ({ blockIds, snapshot, pagesContainer, scrollRoot }: ReadBlockRectsOptions) => ReadonlyMap<string, BlockRect>;
29
+ /** Subscribe to instance-scoped painted-page changes. */
30
+ declare const onPaintedLayoutChange: (pagesContainer: HTMLElement, listener: () => void) => (() => void);
31
+ //#endregion
32
+ export { BlockRect, ReadBlockRectsOptions, onPaintedLayoutChange, readBlockRects };
@@ -0,0 +1,115 @@
1
+ import { resolveSequentialBlockAnchor } from "../ai-edits/blockRange.js";
2
+ import { PAINTER_PAINTED_EVENT, findPageShellForPmPos } from "../layout-painter/renderPage.js";
3
+ //#region src/paged-layout/blockGeometry.ts
4
+ const PAINTED_BLOCK_SELECTOR = "[data-block-id][data-pm-start]";
5
+ const PAGE_SELECTOR = "[data-page-number]";
6
+ const pageNumberOf = (page) => {
7
+ const raw = page.dataset["pageNumber"];
8
+ const pageNumber = raw === void 0 ? NaN : Number(raw);
9
+ return Number.isInteger(pageNumber) && pageNumber > 0 ? pageNumber : null;
10
+ };
11
+ const requestedBlocks = (blockIds, snapshot) => {
12
+ const uniqueIds = new Set(blockIds);
13
+ const requested = [];
14
+ for (const blockId of uniqueIds) {
15
+ const anchor = Object.hasOwn(snapshot.anchors, blockId) ? snapshot.anchors[blockId] : resolveSequentialBlockAnchor(blockId, snapshot);
16
+ if (anchor) requested.push({
17
+ blockId,
18
+ pmStart: anchor.from
19
+ });
20
+ }
21
+ return requested;
22
+ };
23
+ const paintedBlocksByPmStart = (page) => {
24
+ const blocks = /* @__PURE__ */ new Map();
25
+ for (const element of page.querySelectorAll(PAINTED_BLOCK_SELECTOR)) {
26
+ const pmStart = Number(element.dataset["pmStart"]);
27
+ if (Number.isFinite(pmStart) && !blocks.has(pmStart)) blocks.set(pmStart, element);
28
+ }
29
+ return blocks;
30
+ };
31
+ const groupVirtualizedRequestsByPage = (requests, pagesContainer) => {
32
+ const byPage = /* @__PURE__ */ new Map();
33
+ for (const request of requests) {
34
+ const page = findPageShellForPmPos(pagesContainer, request.pmStart)?.element;
35
+ if (!page) return null;
36
+ const pageRequests = byPage.get(page);
37
+ if (pageRequests) pageRequests.push(request);
38
+ else byPage.set(page, [request]);
39
+ }
40
+ return byPage;
41
+ };
42
+ const findPaintedElements = (requests, pagesContainer) => {
43
+ const found = /* @__PURE__ */ new Map();
44
+ const virtualizedRequests = groupVirtualizedRequestsByPage(requests, pagesContainer);
45
+ if (virtualizedRequests) {
46
+ for (const [page, pageRequests] of virtualizedRequests) {
47
+ const pageNumber = pageNumberOf(page);
48
+ if (pageNumber === null) continue;
49
+ const blocks = paintedBlocksByPmStart(page);
50
+ for (const request of pageRequests) {
51
+ const element = blocks.get(request.pmStart);
52
+ if (element) found.set(request.blockId, {
53
+ element,
54
+ page: pageNumber
55
+ });
56
+ }
57
+ }
58
+ return found;
59
+ }
60
+ const requestsByPmStart = new Map(requests.map((request) => [request.pmStart, request]));
61
+ for (const page of pagesContainer.querySelectorAll(PAGE_SELECTOR)) {
62
+ const pageNumber = pageNumberOf(page);
63
+ if (pageNumber === null) continue;
64
+ const blocks = paintedBlocksByPmStart(page);
65
+ for (const [pmStart, request] of requestsByPmStart) {
66
+ const element = blocks.get(pmStart);
67
+ if (element) {
68
+ found.set(request.blockId, {
69
+ element,
70
+ page: pageNumber
71
+ });
72
+ requestsByPmStart.delete(pmStart);
73
+ }
74
+ }
75
+ if (requestsByPmStart.size === 0) break;
76
+ }
77
+ return found;
78
+ };
79
+ /**
80
+ * Measure painted snapshot blocks relative to one editor's scroll root.
81
+ *
82
+ * Missing snapshot ids and blocks on unpainted virtual pages are omitted. Each
83
+ * requested block is measured at most once; painted elements are collected in
84
+ * one DOM query per relevant page.
85
+ */
86
+ const readBlockRects = ({ blockIds, snapshot, pagesContainer, scrollRoot }) => {
87
+ const requests = requestedBlocks(blockIds, snapshot);
88
+ const paintedElements = findPaintedElements(requests, pagesContainer);
89
+ if (paintedElements.size === 0) return /* @__PURE__ */ new Map();
90
+ const rootRect = scrollRoot.getBoundingClientRect();
91
+ const rects = /* @__PURE__ */ new Map();
92
+ for (const request of requests) {
93
+ const painted = paintedElements.get(request.blockId);
94
+ if (!painted) continue;
95
+ const rect = painted.element.getBoundingClientRect();
96
+ rects.set(request.blockId, {
97
+ blockId: request.blockId,
98
+ page: painted.page,
99
+ top: rect.top - rootRect.top - scrollRoot.clientTop + scrollRoot.scrollTop,
100
+ left: rect.left - rootRect.left - scrollRoot.clientLeft + scrollRoot.scrollLeft,
101
+ width: rect.width,
102
+ height: rect.height
103
+ });
104
+ }
105
+ return rects;
106
+ };
107
+ /** Subscribe to instance-scoped painted-page changes. */
108
+ const onPaintedLayoutChange = (pagesContainer, listener) => {
109
+ pagesContainer.addEventListener(PAINTER_PAINTED_EVENT, listener);
110
+ return () => {
111
+ pagesContainer.removeEventListener(PAINTER_PAINTED_EVENT, listener);
112
+ };
113
+ };
114
+ //#endregion
115
+ export { onPaintedLayoutChange, readBlockRects };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stll/folio-core",
3
- "version": "0.26.0",
3
+ "version": "0.27.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",