@stll/folio-core 0.67.0 → 0.69.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/ai-edits/apply.d.ts +9 -1
- package/dist/ai-edits/apply.js +94 -8
- package/dist/ai-edits/headless.d.ts +36 -21
- package/dist/ai-edits/headless.js +106 -36
- package/dist/ai-edits/index.d.ts +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/note-references.d.ts +6 -0
- package/dist/ai-edits/note-references.js +7 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/ai-edits/read.d.ts +19 -0
- package/dist/ai-edits/snapshot.d.ts +6 -0
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/types.d.ts +9 -1
- package/dist/ai-suggestions/apply.js +13 -4
- package/dist/compare/compare.js +2 -1
- package/dist/compare/inserted-resource-snapshot.d.ts +4 -1
- package/dist/compare/inserted-resource-snapshot.js +7 -3
- package/dist/controller/canonicalClipboard.js +31 -14
- package/dist/controller/canonicalComposition.js +35 -6
- package/dist/controller/canonicalInlineProjection.d.ts +35 -10
- package/dist/controller/canonicalInlineProjection.js +192 -28
- package/dist/controller/canonicalInput.d.ts +2 -1
- package/dist/controller/canonicalInput.js +32 -7
- package/dist/controller/canonicalListRendering.d.ts +2 -1
- package/dist/controller/canonicalListRendering.js +1 -1
- package/dist/controller/canonicalLockGuard.d.ts +23 -0
- package/dist/controller/canonicalLockGuard.js +133 -0
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.d.ts +12 -4
- package/dist/controller/canonicalPublicOperations.js +676 -46
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +133 -21
- package/dist/controller/canonicalSession.js +738 -205
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +4 -3
- package/dist/controller/canonicalStoryEditor.js +20 -15
- package/dist/controller/canonicalStructure.d.ts +2 -1
- package/dist/controller/canonicalStructure.js +129 -7
- package/dist/controller/contentControlWidgetController.d.ts +5 -0
- package/dist/controller/contentControlWidgetController.js +13 -1
- package/dist/controller/folioEditor.js +4 -0
- package/dist/controller/headerFooterEditorManager.d.ts +7 -2
- package/dist/controller/headerFooterEditorManager.js +11 -6
- package/dist/controller/hiddenEditorApi.d.ts +17 -2
- package/dist/controller/hiddenEditorApi.js +4 -0
- package/dist/controller/hiddenEditorManager.d.ts +11 -3
- package/dist/controller/hiddenEditorManager.js +157 -48
- package/dist/controller/layoutPipeline.js +50 -16
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +7 -2
- package/dist/controller/noteEditorManager.js +11 -6
- package/dist/display-list/build/pageFurniture.js +41 -19
- package/dist/display-list/build/tablePrimitives.js +23 -4
- package/dist/display-list/dom/renderDisplayListToDom.js +13 -11
- package/dist/document-operations.d.ts +9 -1
- package/dist/document-operations.js +4 -3
- package/dist/docx/blockContentParser.d.ts +7 -3
- package/dist/docx/blockContentParser.js +2 -3
- package/dist/docx/blockPlainText.js +2 -0
- package/dist/docx/bookmarkRangeJoin.d.ts +6 -0
- package/dist/docx/bookmarkRangeJoin.js +43 -0
- package/dist/docx/canonicalSave.js +11 -2
- package/dist/docx/canonicalSessionInput.d.ts +5 -1
- package/dist/docx/canonicalSessionInput.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +40 -5
- package/dist/docx/commentAnchorIndex.js +94 -12
- package/dist/docx/commentRangeIntegrity.js +30 -24
- package/dist/docx/commentRangeJoin.d.ts +4 -0
- package/dist/docx/commentRangeJoin.js +26 -12
- package/dist/docx/commentReferenceCompletion.js +5 -4
- package/dist/docx/commentReferenceNormalization.js +40 -18
- package/dist/docx/compatibility.js +9 -2
- package/dist/docx/containerChildren.js +22 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/encryption/compoundFile.js +9 -1
- package/dist/docx/encryption/encryptionInfo.js +16 -2
- package/dist/docx/ensureParaIds.js +46 -7
- package/dist/docx/ensureUniqueControlIds.d.ts +25 -0
- package/dist/docx/ensureUniqueControlIds.js +110 -0
- package/dist/docx/headerFooterVerbatim.d.ts +7 -0
- package/dist/docx/headerFooterVerbatim.js +13 -2
- package/dist/docx/hostCommentThreads.d.ts +27 -0
- package/dist/docx/hostCommentThreads.js +72 -0
- package/dist/docx/hyperlinkParser.js +9 -2
- package/dist/docx/inlineWrapperContent.d.ts +8 -1
- package/dist/docx/inlineWrapperContent.js +9 -2
- package/dist/docx/listMarkerComputation.d.ts +35 -1
- package/dist/docx/listMarkerComputation.js +39 -1
- package/dist/docx/listModelNormalization.d.ts +44 -1
- package/dist/docx/listModelNormalization.js +226 -96
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/markupRangeMarker.d.ts +14 -0
- package/dist/docx/markupRangeMarker.js +15 -1
- package/dist/docx/metadataPrivacy.js +43 -22
- package/dist/docx/normalizeBaseDirection.js +3 -1
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphParser.js +159 -48
- package/dist/docx/paragraphPropertySource.d.ts +29 -0
- package/dist/docx/paragraphPropertySource.js +106 -16
- package/dist/docx/paragraphTextBoxEnrichment.js +2 -1
- package/dist/docx/paragraphTraversal.js +2 -0
- package/dist/docx/parseWarningMessage.js +2 -1
- package/dist/docx/parser.js +8 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/renderedPageBreakNormalization.js +1 -1
- package/dist/docx/reviewProvenanceDiagnostics.d.ts +7 -0
- package/dist/docx/reviewProvenanceDiagnostics.js +39 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +29 -3
- package/dist/docx/reviewResolutionProvenance.js +171 -33
- package/dist/docx/rezip.d.ts +6 -0
- package/dist/docx/rezip.js +38 -21
- package/dist/docx/selectiveSave.js +6 -10
- package/dist/docx/selectiveXmlPatch.d.ts +5 -4
- package/dist/docx/selectiveXmlPatch.js +11 -7
- package/dist/docx/serializer/documentSerializer.js +5 -2
- package/dist/docx/serializer/headerFooterSerializer.js +3 -1
- package/dist/docx/serializer/markupRangeAttributes.d.ts +6 -1
- package/dist/docx/serializer/markupRangeAttributes.js +6 -1
- package/dist/docx/serializer/noteSerializer.d.ts +17 -4
- package/dist/docx/serializer/noteSerializer.js +23 -16
- package/dist/docx/serializer/paragraphSerializer.js +56 -12
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/serializer/runSerializer.d.ts +1 -3
- package/dist/docx/serializer/runSerializer.js +2 -2
- package/dist/docx/serializer/tableSerializer.d.ts +4 -0
- package/dist/docx/serializer/tableSerializer.js +4 -2
- package/dist/docx/server/applyDocxXmlPatchProposal.js +8 -4
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/server/createBilingualDocument.js +27 -5
- package/dist/docx/server/migrateYjsAttrSchema.js +4 -0
- package/dist/docx/sessionListPruning.d.ts +2 -0
- package/dist/docx/sessionListPruning.js +50 -0
- package/dist/docx/splitRevisionPieces.d.ts +10 -0
- package/dist/docx/splitRevisionPieces.js +14 -0
- package/dist/docx/storyBlockReplay.js +19 -2
- package/dist/docx/structuralXmlPatch.js +44 -11
- package/dist/docx/tableParser.d.ts +6 -2
- package/dist/docx/tableParser.js +2 -3
- package/dist/docx/textBoxContentParser.d.ts +11 -0
- package/dist/docx/textBoxContentParser.js +51 -0
- package/dist/docx/textBoxParser.d.ts +0 -5
- package/dist/docx/textBoxParser.js +1 -23
- package/dist/docx/verticalMergeProjection.js +1 -1
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/fonts/fontsourceFaces.d.ts +2 -8
- package/dist/fonts/fontsourceFaces.js +1 -7
- package/dist/i18n/messages/ar.gen.js +3 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +51 -0
- package/dist/i18n/messages/catalogs.gen.js +51 -0
- package/dist/i18n/messages/cs.gen.js +3 -0
- package/dist/i18n/messages/de.gen.js +3 -0
- package/dist/i18n/messages/en.gen.js +3 -0
- package/dist/i18n/messages/es.gen.js +3 -0
- package/dist/i18n/messages/et.gen.js +3 -0
- package/dist/i18n/messages/fr.gen.js +3 -0
- package/dist/i18n/messages/he.gen.js +3 -0
- package/dist/i18n/messages/hi.gen.js +3 -0
- package/dist/i18n/messages/hu.gen.js +3 -0
- package/dist/i18n/messages/lt.gen.js +3 -0
- package/dist/i18n/messages/lv.gen.js +3 -0
- package/dist/i18n/messages/messages.gen.d.ts +3 -0
- package/dist/i18n/messages/pl.gen.js +3 -0
- package/dist/i18n/messages/pt-BR.gen.js +3 -0
- package/dist/i18n/messages/sk.gen.js +3 -0
- package/dist/i18n/messages/tr.gen.js +3 -0
- package/dist/i18n/messages/zh-CN.gen.js +3 -0
- package/dist/internal/acceptedBlockProjection.js +2 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/pageBreakRunSourceDescendantIndex.d.ts +5 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +5 -0
- package/dist/internal/revisionResolutionInline.js +1 -2
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/tableConversion.js +19 -8
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/engine/blockIndex.d.ts +7 -0
- package/dist/layout-bridge/engine/blockIndex.js +12 -0
- package/dist/layout-bridge/engine/hitTest.js +9 -10
- package/dist/layout-bridge/engine/selectionRects.js +6 -6
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/footnoteContinuation.d.ts +36 -0
- package/dist/layout-engine/footnoteContinuation.js +210 -0
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +7 -2
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +16 -6
- package/dist/layout-engine/measure/measureParagraph.js +1 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/tableLayout.js +29 -5
- package/dist/layout-engine/tableRowBreak.d.ts +36 -0
- package/dist/layout-engine/tableRowBreak.js +43 -1
- package/dist/layout-engine/types.d.ts +42 -1
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.d.ts +4 -4
- package/dist/layout-painter/renderPage.js +54 -46
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +16 -16
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/managers/AutoSaveManager.d.ts +5 -1
- package/dist/managers/FindReplaceManager.js +3 -10
- package/dist/markdown/escape.d.ts +20 -1
- package/dist/markdown/escape.js +43 -1
- package/dist/markdown/renderBlock.js +4 -1
- package/dist/markdown/renderParagraph.js +13 -27
- package/dist/markdown/renderTable.js +6 -2
- package/dist/markdown/trailers.js +1 -0
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/pdf/images.d.ts +17 -1
- package/dist/pdf/images.js +22 -4
- package/dist/pdf/writePdf.js +4 -2
- package/dist/prosemirror/attrs/index.js +2 -0
- package/dist/prosemirror/canonicalCommands.d.ts +39 -1
- package/dist/prosemirror/canonicalTableCommands.d.ts +28 -0
- package/dist/prosemirror/canonicalTableCommands.js +362 -0
- package/dist/prosemirror/commands/comments.d.ts +30 -2
- package/dist/prosemirror/commands/comments.js +189 -18
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/index.d.ts +1 -1
- package/dist/prosemirror/commentIdAllocator.js +2 -2
- package/dist/prosemirror/commentRangeBoundaryAttrs.d.ts +6 -0
- package/dist/prosemirror/commentRangeBoundaryAttrs.js +9 -3
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/commentReferenceIntegrity.js +3 -4
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +2 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +85 -34
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/toProseDoc.d.ts +140 -4
- package/dist/prosemirror/conversion/toProseDoc.js +432 -76
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/JoinedRunStyleExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +23 -1
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/features/pastedHtmlLists.js +5 -4
- package/dist/prosemirror/extensions/marks/CommentExtension.js +8 -3
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.d.ts +4 -0
- package/dist/prosemirror/extensions/nodes/BlockCommentRangeBoundaryExtension.js +49 -0
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +12 -3
- package/dist/prosemirror/extensions/nodes/TableExtension.js +32 -31
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +1 -1
- package/dist/prosemirror/index.d.ts +3 -3
- package/dist/prosemirror/listLabels.js +3 -2
- package/dist/prosemirror/listNumbering.d.ts +6 -0
- package/dist/prosemirror/listNumbering.js +12 -9
- package/dist/prosemirror/lockedControls.d.ts +13 -0
- package/dist/prosemirror/lockedControls.js +106 -0
- package/dist/prosemirror/markupViewProjection.js +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/noteReferenceReview.js +2 -2
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +37 -15
- package/dist/prosemirror/plugins/suggestionMode.js +33 -10
- package/dist/prosemirror/plugins/templatePreviewValues.js +16 -1
- package/dist/prosemirror/rebaseParagraphRuns.js +1 -1
- package/dist/prosemirror/replacedAnnotations.js +1 -0
- package/dist/prosemirror/runFormattingFromMarks.d.ts +0 -1
- package/dist/prosemirror/runFormattingFromMarks.js +2 -4
- package/dist/prosemirror/runFormattingReconciliation.js +2 -2
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/runPropertyChangeResolution.js +1 -2
- package/dist/prosemirror/runStyleFormatting.d.ts +14 -4
- package/dist/prosemirror/runStyleFormatting.js +16 -13
- package/dist/prosemirror/schema/marks.d.ts +13 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/styles/paragraphStyleCascade.js +2 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +79 -5
- package/dist/redline.js +23 -9
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/server.d.ts +2 -2
- package/dist/style-sets/extract.js +2 -2
- package/dist/types/canonicalCapabilities.d.ts +38 -16
- package/dist/types/canonicalCapabilities.js +21 -18
- package/dist/utils/cssString.d.ts +7 -0
- package/dist/utils/cssString.js +9 -0
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/fontResolver.js +4 -1
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/dist/utils/replaceText.d.ts +11 -0
- package/dist/utils/replaceText.js +39 -7
- package/dist/version-comparison.d.ts +9 -1
- package/dist/version-comparison.js +11 -5
- package/package.json +2 -3
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { subtreeHolds } from "../../internal/subtreeHolds.js";
|
|
2
|
+
import { cloneListCounterState } from "../../prosemirror/listMarker.js";
|
|
3
|
+
// src/layout-bridge/convert/topLevelConversion.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether kept conversions freeze their blocks. Tests set it, so code that
|
|
6
|
+
* writes to a block handed out again fails where it writes instead of
|
|
7
|
+
* changing what a later conversion hands out.
|
|
8
|
+
*/
|
|
9
|
+
const freezesKeptBlocks = () => globalThis.__folioFreezeKeptBlocks?.enabled === true;
|
|
10
|
+
/** Freeze every plain object and array `value` holds, and `value`. */
|
|
11
|
+
const freezeKeptBlock = (value) => {
|
|
12
|
+
if (typeof value !== "object" || value === null || Object.isFrozen(value)) return;
|
|
13
|
+
const prototype = Object.getPrototypeOf(value);
|
|
14
|
+
if (prototype !== Object.prototype && prototype !== Array.prototype) return;
|
|
15
|
+
Object.freeze(value);
|
|
16
|
+
for (const nested of Object.values(value)) freezeKeptBlock(nested);
|
|
17
|
+
};
|
|
18
|
+
const readsOtherNodes = subtreeHolds((node) => {
|
|
19
|
+
switch (node.type.name) {
|
|
20
|
+
case "field":
|
|
21
|
+
case "structuredField":
|
|
22
|
+
case "textBoxAnchor":
|
|
23
|
+
case "textBox":
|
|
24
|
+
case "pageBreak":
|
|
25
|
+
case "horizontalRule": return true;
|
|
26
|
+
case "paragraph": return node.attrs["_sectionProperties"] != null;
|
|
27
|
+
default: return false;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
/** Whether converting `node` reads anything besides itself and the state before it. */
|
|
31
|
+
const convertsWithOtherNodes = (node) => readsOtherNodes(node);
|
|
32
|
+
/** Two counter arrays read alike, `NaN` (no counter yet) included. */
|
|
33
|
+
const sameCounters = (left, right) => left.length === right.length && left.every((value, index) => Object.is(value, right[index]));
|
|
34
|
+
const sameMembers = (left, right) => {
|
|
35
|
+
const leftSize = left?.size ?? 0;
|
|
36
|
+
if (leftSize !== (right?.size ?? 0)) return false;
|
|
37
|
+
if (leftSize === 0) return true;
|
|
38
|
+
for (const member of left ?? []) if (!right?.has(member)) return false;
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Two counter states that number every paragraph after them alike. Advancing
|
|
43
|
+
* a list writes one array that a numbering instance and its abstract
|
|
44
|
+
* definition may both hold, so which arrays are shared is compared too.
|
|
45
|
+
*/
|
|
46
|
+
const sameListCounterState = (left, right) => {
|
|
47
|
+
if (left === right) return true;
|
|
48
|
+
if (left.counters.size !== right.counters.size || left.abstractCounters.size !== right.abstractCounters.size || left.lastAdvancedNumId !== right.lastAdvancedNumId || !sameMembers(left.seenLevels, right.seenLevels) || !sameMembers(left.restartedNumIds, right.restartedNumIds)) return false;
|
|
49
|
+
const leftList = left.previousList;
|
|
50
|
+
const rightList = right.previousList;
|
|
51
|
+
if ((leftList?.abstractNumId ?? null) !== (rightList?.abstractNumId ?? null) || (leftList?.fromStyle ?? false) !== (rightList?.fromStyle ?? false) || (leftList?.numId ?? null) !== (rightList?.numId ?? null)) return false;
|
|
52
|
+
const paired = /* @__PURE__ */ new Map();
|
|
53
|
+
const pairs = (leftArray, rightArray) => {
|
|
54
|
+
if (rightArray === void 0) return false;
|
|
55
|
+
const known = paired.get(leftArray);
|
|
56
|
+
if (known !== void 0) return known === rightArray;
|
|
57
|
+
if (!sameCounters(leftArray, rightArray)) return false;
|
|
58
|
+
paired.set(leftArray, rightArray);
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
const sameMap = (leftMap, rightMap) => {
|
|
62
|
+
const rightEntries = rightMap.entries();
|
|
63
|
+
for (const [key, values] of leftMap) {
|
|
64
|
+
const next = rightEntries.next();
|
|
65
|
+
if (next.done === true) return false;
|
|
66
|
+
const [rightKey, rightValues] = next.value;
|
|
67
|
+
if (key !== rightKey || !pairs(values, rightValues)) return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
return sameMap(left.counters, right.counters) && sameMap(left.abstractCounters, right.abstractCounters) && new Set(paired.values()).size === paired.size;
|
|
72
|
+
};
|
|
73
|
+
const sameCheckpoint = (left, right) => left === right || left.sectionBlocks === right.sectionBlocks && left.margins.top === right.margins.top && left.margins.bottom === right.margins.bottom && left.margins.left === right.margins.left && left.margins.right === right.margins.right && sameListCounterState(left.final, right.final) && sameListCounterState(left.original, right.original);
|
|
74
|
+
const takeCheckpoint = (final, original, margins, sectionBlocks) => ({
|
|
75
|
+
final: cloneListCounterState(final),
|
|
76
|
+
original: cloneListCounterState(original),
|
|
77
|
+
margins,
|
|
78
|
+
sectionBlocks
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Make `target` the state `source` holds, in place: the conversion options
|
|
82
|
+
* hold `target`'s maps and sets themselves. Arrays `source` shares stay
|
|
83
|
+
* shared in `target`, and `source` is never written.
|
|
84
|
+
*/
|
|
85
|
+
const restoreListCounterState = (target, source) => {
|
|
86
|
+
const copies = /* @__PURE__ */ new Map();
|
|
87
|
+
const copyOf = (values) => {
|
|
88
|
+
const known = copies.get(values);
|
|
89
|
+
if (known !== void 0) return known;
|
|
90
|
+
const copy = [...values];
|
|
91
|
+
copies.set(values, copy);
|
|
92
|
+
return copy;
|
|
93
|
+
};
|
|
94
|
+
target.counters.clear();
|
|
95
|
+
for (const [key, values] of source.counters) target.counters.set(key, copyOf(values));
|
|
96
|
+
target.abstractCounters.clear();
|
|
97
|
+
for (const [key, values] of source.abstractCounters) target.abstractCounters.set(key, copyOf(values));
|
|
98
|
+
target.seenLevels.clear();
|
|
99
|
+
for (const level of source.seenLevels) target.seenLevels.add(level);
|
|
100
|
+
target.restartedNumIds = new Set(source.restartedNumIds);
|
|
101
|
+
target.previousList = { ...source.previousList ?? {
|
|
102
|
+
abstractNumId: null,
|
|
103
|
+
fromStyle: false,
|
|
104
|
+
numId: null
|
|
105
|
+
} };
|
|
106
|
+
if (source.lastAdvancedNumId === void 0) delete target.lastAdvancedNumId;
|
|
107
|
+
else target.lastAdvancedNumId = source.lastAdvancedNumId;
|
|
108
|
+
};
|
|
109
|
+
export { convertsWithOtherNodes, freezeKeptBlock, freezesKeptBlocks, restoreListCounterState, sameCheckpoint, sameListCounterState, takeCheckpoint };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { closestHtmlElement, findHtmlElement, htmlQueryAll, queryHtmlElement } from "../../utils/domGuards.js";
|
|
2
|
+
import { PAINTED_RANGE_SELECTOR, PAINTED_START_SELECTOR, hasPaintedRange, hasPaintedStart, readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
|
|
2
3
|
import { descendantTextNodes, logicalTextOffset, measurePaintedSpanRange, paintedTextOffset, textBoundaryAt, totalTextLength } from "./textStreamDom.js";
|
|
3
4
|
// src/layout-bridge/dom/clickToPositionDom.ts
|
|
4
5
|
/**
|
|
@@ -24,18 +25,18 @@ function clickToPositionDom(container, clientX, clientY, zoom = 1) {
|
|
|
24
25
|
const elements = document.elementsFromPoint(clientX, clientY);
|
|
25
26
|
const pageEl = findHtmlElement(elements, (el) => el.classList.contains("layout-page"));
|
|
26
27
|
if (!pageEl) return null;
|
|
27
|
-
const spanEl = findHtmlElement(elements, (el) => el.tagName === "SPAN" && el
|
|
28
|
+
const spanEl = findHtmlElement(elements, (el) => el.tagName === "SPAN" && hasPaintedRange(el));
|
|
28
29
|
if (spanEl) return findPositionInSpan(spanEl, clientX, clientY);
|
|
29
30
|
const emptyRun = findHtmlElement(elements, (el) => el.classList.contains("layout-empty-run"));
|
|
30
31
|
if (emptyRun) {
|
|
31
32
|
const paragraph = closestHtmlElement(emptyRun, ".layout-paragraph");
|
|
32
|
-
if (paragraph && paragraph
|
|
33
|
+
if (paragraph && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
33
34
|
}
|
|
34
|
-
const paragraphEl = findHtmlElement(elements, (el) => el.classList.contains("layout-paragraph") && el
|
|
35
|
-
if (paragraphEl && paragraphEl
|
|
35
|
+
const paragraphEl = findHtmlElement(elements, (el) => el.classList.contains("layout-paragraph") && hasPaintedStart(el));
|
|
36
|
+
if (paragraphEl && hasPaintedStart(paragraphEl)) {
|
|
36
37
|
const nearestPos = findNearestSpanInElement(paragraphEl, clientX, clientY);
|
|
37
38
|
if (nearestPos !== null) return nearestPos;
|
|
38
|
-
return
|
|
39
|
+
return readPaintedStart(paragraphEl) ?? NaN;
|
|
39
40
|
}
|
|
40
41
|
const cellEl = findHtmlElement(elements, (el) => el.classList.contains("layout-table-cell"));
|
|
41
42
|
if (cellEl) return findNearestSpanInElement(cellEl, clientX, clientY);
|
|
@@ -52,8 +53,8 @@ function clickToPositionDom(container, clientX, clientY, zoom = 1) {
|
|
|
52
53
|
* caret API resolved to a sibling text node at the same y).
|
|
53
54
|
*/
|
|
54
55
|
function findPositionInSpan(spanEl, clientX, clientY) {
|
|
55
|
-
const pmStart =
|
|
56
|
-
const pmEnd =
|
|
56
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
57
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
57
58
|
if (spanEl.classList.contains("layout-run-tab")) {
|
|
58
59
|
const rect = spanEl.getBoundingClientRect();
|
|
59
60
|
return clientX < (rect.left + rect.right) / 2 ? pmStart : pmEnd;
|
|
@@ -132,9 +133,9 @@ function caretOffsetFromPoint(ownerDoc, textNodes, clientX, clientY) {
|
|
|
132
133
|
function findNearestSpanInElement(element, clientX, clientY) {
|
|
133
134
|
const emptyRun = queryHtmlElement(element, ".layout-empty-run");
|
|
134
135
|
if (emptyRun) {
|
|
135
|
-
if (emptyRun
|
|
136
|
+
if (hasPaintedStart(emptyRun)) return readPaintedStart(emptyRun) ?? NaN;
|
|
136
137
|
const paragraph = closestHtmlElement(emptyRun, ".layout-paragraph");
|
|
137
|
-
if (paragraph && paragraph
|
|
138
|
+
if (paragraph && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
138
139
|
}
|
|
139
140
|
const lines = htmlQueryAll(element, ".layout-line");
|
|
140
141
|
let closestLine = null;
|
|
@@ -149,15 +150,15 @@ function findNearestSpanInElement(element, clientX, clientY) {
|
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
152
|
if (!closestLine) {
|
|
152
|
-
const paragraph = queryHtmlElement(element,
|
|
153
|
-
if (paragraph
|
|
154
|
-
if (element
|
|
153
|
+
const paragraph = queryHtmlElement(element, `.layout-paragraph${PAINTED_START_SELECTOR}`);
|
|
154
|
+
if (paragraph !== null && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
155
|
+
if (hasPaintedStart(element)) return readPaintedStart(element) ?? NaN;
|
|
155
156
|
return null;
|
|
156
157
|
}
|
|
157
|
-
const lineSpans = htmlQueryAll(closestLine,
|
|
158
|
+
const lineSpans = htmlQueryAll(closestLine, `span${PAINTED_RANGE_SELECTOR}`);
|
|
158
159
|
if (lineSpans.length === 0) {
|
|
159
160
|
const paragraph = closestHtmlElement(closestLine, ".layout-paragraph");
|
|
160
|
-
if (paragraph
|
|
161
|
+
if (paragraph !== null && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
161
162
|
return null;
|
|
162
163
|
}
|
|
163
164
|
let closestSpan = null;
|
|
@@ -172,17 +173,17 @@ function findNearestSpanInElement(element, clientX, clientY) {
|
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
if (!closestSpan) return null;
|
|
175
|
-
if (clientX < closestSpan.getBoundingClientRect().left) return
|
|
176
|
-
return
|
|
176
|
+
if (clientX < closestSpan.getBoundingClientRect().left) return readPaintedStart(closestSpan) ?? NaN;
|
|
177
|
+
return readPaintedEnd(closestSpan) ?? NaN;
|
|
177
178
|
}
|
|
178
179
|
/**
|
|
179
180
|
* Find the nearest text span when click is not directly on text.
|
|
180
181
|
* This handles clicks in margins, between lines, etc.
|
|
181
182
|
*/
|
|
182
183
|
function findNearestSpan(_container, pageEl, clientX, clientY, _zoom) {
|
|
183
|
-
if (htmlQueryAll(pageEl,
|
|
184
|
+
if (htmlQueryAll(pageEl, `.layout-page-content span[data-pm-start][data-pm-end]`).length === 0) {
|
|
184
185
|
const firstP = htmlQueryAll(pageEl, ".layout-page-content .layout-paragraph").at(0);
|
|
185
|
-
if (firstP) return
|
|
186
|
+
if (firstP) return readPaintedStart(firstP) || 0;
|
|
186
187
|
return null;
|
|
187
188
|
}
|
|
188
189
|
const lines = htmlQueryAll(pageEl, ".layout-page-content .layout-line");
|
|
@@ -198,10 +199,10 @@ function findNearestSpan(_container, pageEl, clientX, clientY, _zoom) {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
if (!closestLine) return null;
|
|
201
|
-
const lineSpans = htmlQueryAll(closestLine,
|
|
202
|
+
const lineSpans = htmlQueryAll(closestLine, `span${PAINTED_RANGE_SELECTOR}`);
|
|
202
203
|
if (lineSpans.length === 0) {
|
|
203
204
|
const paragraph = closestHtmlElement(closestLine, ".layout-paragraph");
|
|
204
|
-
if (paragraph
|
|
205
|
+
if (paragraph !== null && hasPaintedStart(paragraph)) return readPaintedStart(paragraph) ?? NaN;
|
|
205
206
|
return null;
|
|
206
207
|
}
|
|
207
208
|
let closestSpan = null;
|
|
@@ -216,12 +217,12 @@ function findNearestSpan(_container, pageEl, clientX, clientY, _zoom) {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
if (!closestSpan) return null;
|
|
219
|
-
if (clientX < closestSpan.getBoundingClientRect().left) return
|
|
220
|
-
return
|
|
220
|
+
if (clientX < closestSpan.getBoundingClientRect().left) return readPaintedStart(closestSpan) ?? NaN;
|
|
221
|
+
return readPaintedEnd(closestSpan) ?? NaN;
|
|
221
222
|
}
|
|
222
223
|
function getSelectionRectsFromDom(container, from, to, overlayRect) {
|
|
223
224
|
const rects = [];
|
|
224
|
-
const spans = htmlQueryAll(container,
|
|
225
|
+
const spans = htmlQueryAll(container, `.layout-page-content span${PAINTED_RANGE_SELECTOR}`);
|
|
225
226
|
for (const spanEl of spans) {
|
|
226
227
|
const measurement = measurePaintedSpanRange(spanEl, from, to);
|
|
227
228
|
if (measurement.type === "outside") continue;
|
|
@@ -255,8 +256,8 @@ function getCollapsedLineEdgeCaretGeometry(spanEl, pmPos) {
|
|
|
255
256
|
const line = closestHtmlElement(spanEl, ".layout-line");
|
|
256
257
|
const anchorRect = sibling?.getBoundingClientRect() ?? line?.getBoundingClientRect() ?? spanRect;
|
|
257
258
|
const lineRect = line?.getBoundingClientRect();
|
|
258
|
-
const pmStart =
|
|
259
|
-
const pmEnd =
|
|
259
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
260
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
260
261
|
const storedSpaceAdvance = Number(spanEl.dataset["collapsedSpaceAdvance"]);
|
|
261
262
|
const lineScale = line && line.offsetWidth > 0 && lineRect ? lineRect.width / line.offsetWidth : 1;
|
|
262
263
|
const trailingSpaceCount = isTrailing && pmPos !== void 0 && Number.isFinite(pmStart) && Number.isFinite(pmEnd) ? Math.max(0, Math.min(pmPos, pmEnd) - pmStart) : 0;
|
|
@@ -275,8 +276,8 @@ function getCollapsedLineEdgeCaretGeometry(spanEl, pmPos) {
|
|
|
275
276
|
*/
|
|
276
277
|
function findCollapsedLineEdgeCaretTarget(spans, pmPos) {
|
|
277
278
|
for (const span of spans) {
|
|
278
|
-
const pmStart =
|
|
279
|
-
const pmEnd =
|
|
279
|
+
const pmStart = readPaintedStart(span) ?? NaN;
|
|
280
|
+
const pmEnd = readPaintedEnd(span) ?? NaN;
|
|
280
281
|
if (pmPos < pmStart || pmPos > pmEnd) continue;
|
|
281
282
|
const geometry = getCollapsedLineEdgeCaretGeometry(span, pmPos);
|
|
282
283
|
if (geometry) return {
|
|
@@ -292,7 +293,7 @@ const getPaintedSpanCaretGeometry = (span, pmPos) => {
|
|
|
292
293
|
const spanRect = span.getBoundingClientRect();
|
|
293
294
|
const lineHeight = closestHtmlElement(span, ".layout-line")?.getBoundingClientRect().height || spanRect.height || 16;
|
|
294
295
|
if (span.classList.contains("layout-run-tab")) return {
|
|
295
|
-
left: pmPos >=
|
|
296
|
+
left: pmPos >= (readPaintedEnd(span) ?? NaN) ? spanRect.right : spanRect.left,
|
|
296
297
|
top: spanRect.top,
|
|
297
298
|
height: lineHeight
|
|
298
299
|
};
|
|
@@ -302,10 +303,10 @@ const getPaintedSpanCaretGeometry = (span, pmPos) => {
|
|
|
302
303
|
top: spanRect.top,
|
|
303
304
|
height: lineHeight
|
|
304
305
|
};
|
|
305
|
-
const pmStart =
|
|
306
|
+
const pmStart = readPaintedStart(span) ?? NaN;
|
|
306
307
|
const charIndex = paintedTextOffset({
|
|
307
308
|
pmStart,
|
|
308
|
-
pmEnd:
|
|
309
|
+
pmEnd: readPaintedEnd(span) ?? NaN,
|
|
309
310
|
pmPosition: pmPos,
|
|
310
311
|
textLength: totalTextLength(textNodes)
|
|
311
312
|
});
|
|
@@ -334,12 +335,12 @@ const getPaintedSpanCaretGeometry = (span, pmPos) => {
|
|
|
334
335
|
function findParagraphGapCaretTarget(container, pmPos) {
|
|
335
336
|
let best;
|
|
336
337
|
for (const paragraph of htmlQueryAll(container, ".layout-page-content .layout-paragraph")) {
|
|
337
|
-
const paragraphStart =
|
|
338
|
-
const paragraphEnd =
|
|
338
|
+
const paragraphStart = readPaintedStart(paragraph) ?? NaN;
|
|
339
|
+
const paragraphEnd = readPaintedEnd(paragraph) ?? NaN;
|
|
339
340
|
if (!(pmPos > paragraphStart && pmPos < paragraphEnd)) continue;
|
|
340
|
-
for (const span of htmlQueryAll(paragraph,
|
|
341
|
-
const spanStart =
|
|
342
|
-
const spanEnd =
|
|
341
|
+
for (const span of htmlQueryAll(paragraph, `span${PAINTED_RANGE_SELECTOR}`)) {
|
|
342
|
+
const spanStart = readPaintedStart(span) ?? NaN;
|
|
343
|
+
const spanEnd = readPaintedEnd(span) ?? NaN;
|
|
343
344
|
if (!Number.isFinite(spanStart) || !Number.isFinite(spanEnd)) continue;
|
|
344
345
|
const boundaryPos = pmPos < spanStart ? spanStart : spanEnd;
|
|
345
346
|
const distance = Math.abs(boundaryPos - pmPos);
|
|
@@ -357,7 +358,7 @@ function findParagraphGapCaretTarget(container, pmPos) {
|
|
|
357
358
|
};
|
|
358
359
|
}
|
|
359
360
|
function getCaretPositionFromDom(container, pmPos, overlayRect) {
|
|
360
|
-
const spans = htmlQueryAll(container,
|
|
361
|
+
const spans = htmlQueryAll(container, `.layout-page-content span${PAINTED_RANGE_SELECTOR}`);
|
|
361
362
|
const collapsedTarget = findCollapsedLineEdgeCaretTarget(spans, pmPos);
|
|
362
363
|
if (collapsedTarget) {
|
|
363
364
|
const pageEl = closestHtmlElement(collapsedTarget.span, ".layout-page");
|
|
@@ -370,8 +371,8 @@ function getCaretPositionFromDom(container, pmPos, overlayRect) {
|
|
|
370
371
|
};
|
|
371
372
|
}
|
|
372
373
|
for (const spanEl of spans) {
|
|
373
|
-
const pmStart =
|
|
374
|
-
const pmEnd =
|
|
374
|
+
const pmStart = readPaintedStart(spanEl) ?? NaN;
|
|
375
|
+
const pmEnd = readPaintedEnd(spanEl) ?? NaN;
|
|
375
376
|
if (spanEl.classList.contains("layout-run-tab")) {
|
|
376
377
|
if (pmPos >= pmStart && pmPos < pmEnd) {
|
|
377
378
|
const spanRect = spanEl.getBoundingClientRect();
|
|
@@ -440,8 +441,8 @@ function getCaretPositionFromDom(container, pmPos, overlayRect) {
|
|
|
440
441
|
}
|
|
441
442
|
const paragraphs = htmlQueryAll(container, ".layout-paragraph");
|
|
442
443
|
for (const pEl of paragraphs) {
|
|
443
|
-
const pStart =
|
|
444
|
-
const pEnd =
|
|
444
|
+
const pStart = readPaintedStart(pEl) ?? NaN;
|
|
445
|
+
const pEnd = readPaintedEnd(pEl) ?? NaN;
|
|
445
446
|
if (pmPos >= pStart && pmPos <= pEnd) {
|
|
446
447
|
const targetEl = pEl.querySelector(".layout-empty-run") || pEl;
|
|
447
448
|
const rect = targetEl.getBoundingClientRect();
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { PAINTED_RANGE_SELECTOR, PAINTED_START_SELECTOR, paintedStartSelector } from "../../utils/paintedPositions.js";
|
|
1
2
|
// src/layout-bridge/dom/findBodyPmSpans.ts
|
|
2
3
|
const BODY_SCOPE = ".layout-page-content";
|
|
3
4
|
function findBodyPmSpans(container) {
|
|
4
|
-
return Array.from(container.querySelectorAll(`${BODY_SCOPE} span
|
|
5
|
+
return Array.from(container.querySelectorAll(`${BODY_SCOPE} span${PAINTED_RANGE_SELECTOR}`));
|
|
5
6
|
}
|
|
6
7
|
function findBodyEmptyRuns(container) {
|
|
7
8
|
return Array.from(container.querySelectorAll(`${BODY_SCOPE} .layout-empty-run`));
|
|
8
9
|
}
|
|
9
10
|
function findBodyPmAnchors(container) {
|
|
10
|
-
return Array.from(container.querySelectorAll(`${BODY_SCOPE}
|
|
11
|
+
return Array.from(container.querySelectorAll(`${BODY_SCOPE} ${PAINTED_START_SELECTOR}`));
|
|
11
12
|
}
|
|
12
13
|
function findBodyPmAnchor(container, pmStart) {
|
|
13
14
|
if (!Number.isFinite(pmStart)) return null;
|
|
14
|
-
return container.querySelector(`${BODY_SCOPE}
|
|
15
|
+
return container.querySelector(`${BODY_SCOPE} ${paintedStartSelector(pmStart)}`);
|
|
15
16
|
}
|
|
16
17
|
export { findBodyEmptyRuns, findBodyPmAnchor, findBodyPmAnchors, findBodyPmSpans };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PAINTED_RANGE_SELECTOR, PAINTED_START_SELECTOR, hasPaintedRange, paintedStartSelector, readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
|
|
1
2
|
import { findPositionInSpan } from "./clickToPositionDom.js";
|
|
2
3
|
// src/layout-bridge/dom/findHfPmSpans.ts
|
|
3
4
|
/**
|
|
@@ -26,14 +27,14 @@ function querySlotAnchors(container, kind, rId, selector) {
|
|
|
26
27
|
return uniqueElements([...querySlotDescendants(container, kind, rId, selector), ...Array.from(container.querySelectorAll(`${associatedSlotSelector(kind, rId)}${selector}`))]);
|
|
27
28
|
}
|
|
28
29
|
function findHfPmSpans(container, kind, rId) {
|
|
29
|
-
return querySlotDescendants(container, kind, rId,
|
|
30
|
+
return querySlotDescendants(container, kind, rId, `span${PAINTED_RANGE_SELECTOR}`);
|
|
30
31
|
}
|
|
31
32
|
function findHfPmAnchors(container, kind, rId) {
|
|
32
|
-
return querySlotAnchors(container, kind, rId,
|
|
33
|
+
return querySlotAnchors(container, kind, rId, PAINTED_START_SELECTOR);
|
|
33
34
|
}
|
|
34
35
|
function findHfPmAnchor(container, kind, rId, pmStart) {
|
|
35
36
|
if (!Number.isFinite(pmStart)) return null;
|
|
36
|
-
return container.querySelector(`${slotSelector(kind, rId)}
|
|
37
|
+
return container.querySelector(`${slotSelector(kind, rId)} ${paintedStartSelector(pmStart)}`) ?? container.querySelector(`${associatedSlotSelector(kind, rId)} ${paintedStartSelector(pmStart)}`) ?? container.querySelector(`${associatedSlotSelector(kind, rId)}${paintedStartSelector(pmStart)}`);
|
|
37
38
|
}
|
|
38
39
|
function findHfCaretSpan(container, kind, rId, pos) {
|
|
39
40
|
if (!Number.isFinite(pos)) return null;
|
|
@@ -45,11 +46,9 @@ function findHfCaretSpan(container, kind, rId, pos) {
|
|
|
45
46
|
const spans = findHfPmSpans(container, kind, rId);
|
|
46
47
|
let best = null;
|
|
47
48
|
for (const span of spans) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
const start = Number.parseInt(startStr, 10);
|
|
52
|
-
const end = Number.parseInt(endStr, 10);
|
|
49
|
+
const start = readPaintedStart(span);
|
|
50
|
+
const end = readPaintedEnd(span);
|
|
51
|
+
if (start === void 0 || end === void 0) continue;
|
|
53
52
|
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
54
53
|
if (pos === end) best = {
|
|
55
54
|
element: span,
|
|
@@ -83,7 +82,7 @@ function clickToPositionInHfSlot(container, kind, rId, clientX, clientY) {
|
|
|
83
82
|
if (!(el instanceof HTMLElement)) continue;
|
|
84
83
|
const slot = findHfSlotForTarget(el);
|
|
85
84
|
if (!slot || slot.kind !== kind || slot.rId !== rId) continue;
|
|
86
|
-
if (el.tagName === "SPAN" && el
|
|
85
|
+
if (el.tagName === "SPAN" && hasPaintedRange(el)) return findPositionInSpan(el, clientX, clientY);
|
|
87
86
|
}
|
|
88
87
|
return findNearestSpanInHfSlots(container, kind, rId, clientX, clientY);
|
|
89
88
|
}
|
|
@@ -114,12 +113,8 @@ function findNearestSpanInHfSlots(container, kind, rId, clientX, clientY) {
|
|
|
114
113
|
}
|
|
115
114
|
if (!bestSpan) return null;
|
|
116
115
|
if (bestInside) return findPositionInSpan(bestSpan, clientX, clientY);
|
|
117
|
-
if (clientX < bestSpan.getBoundingClientRect().left)
|
|
118
|
-
|
|
119
|
-
return v ? Number(v) : null;
|
|
120
|
-
}
|
|
121
|
-
const v = bestSpan.dataset["pmEnd"];
|
|
122
|
-
return v ? Number(v) : null;
|
|
116
|
+
if (clientX < bestSpan.getBoundingClientRect().left) return readPaintedStart(bestSpan) ?? null;
|
|
117
|
+
return readPaintedEnd(bestSpan) ?? null;
|
|
123
118
|
}
|
|
124
119
|
function findHfSlotForTarget(target) {
|
|
125
120
|
if (!target) return null;
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The class of the box hosts put the hidden editor's host in: a tiny clipping
|
|
3
|
+
* box off-screen, which the browser may scroll to reveal the native caret.
|
|
4
|
+
*/
|
|
5
|
+
export declare const HIDDEN_EDITOR_WRAPPER_CLASS = "paged-editor__hidden-pm-wrapper";
|
|
1
6
|
type ImeCaretHost = {
|
|
2
7
|
style: {
|
|
3
8
|
transform: string;
|
|
4
9
|
};
|
|
10
|
+
readonly parentElement?: {
|
|
11
|
+
closest: (selectors: string) => unknown;
|
|
12
|
+
} | null;
|
|
5
13
|
};
|
|
6
14
|
type ImeCaretEditorView = {
|
|
7
15
|
readonly composing: boolean;
|
|
@@ -1,6 +1,62 @@
|
|
|
1
|
+
import { scrollClipBoxToOrigin } from "../../paged-layout/editorScrollRoot.js";
|
|
1
2
|
// src/layout-bridge/dom/imeCaretAnchor.ts
|
|
3
|
+
/**
|
|
4
|
+
* The class of the box hosts put the hidden editor's host in: a tiny clipping
|
|
5
|
+
* box off-screen, which the browser may scroll to reveal the native caret.
|
|
6
|
+
*/
|
|
7
|
+
const HIDDEN_EDITOR_WRAPPER_CLASS = "paged-editor__hidden-pm-wrapper";
|
|
8
|
+
const isScrollingWrapper = (value) => typeof value === "object" && value !== null && "scrollLeft" in value && "scrollTop" in value && "addEventListener" in value;
|
|
9
|
+
const toOrigin = (wrapper) => scrollClipBoxToOrigin(wrapper);
|
|
10
|
+
const heldWrappers = /* @__PURE__ */ new WeakSet();
|
|
11
|
+
/**
|
|
12
|
+
* Keep the wrapper around the host scrolled to its origin. The translation
|
|
13
|
+
* moves the native caret outside the clipping wrapper, so the browser scrolls
|
|
14
|
+
* the wrapper to reveal it, by any amount, whenever it reveals the caret; the
|
|
15
|
+
* translation is measured with the wrapper at its origin and is only right
|
|
16
|
+
* there. So the wrapper goes back to its origin before every measurement, and
|
|
17
|
+
* after every scroll of it, which leaves the caret where the last measurement
|
|
18
|
+
* put it.
|
|
19
|
+
*/
|
|
20
|
+
const holdWrapperAtOrigin = (hiddenHost) => {
|
|
21
|
+
const wrapper = hiddenHost.parentElement?.closest(`.${HIDDEN_EDITOR_WRAPPER_CLASS}`);
|
|
22
|
+
if (!isScrollingWrapper(wrapper)) return;
|
|
23
|
+
toOrigin(wrapper);
|
|
24
|
+
if (heldWrappers.has(wrapper)) return;
|
|
25
|
+
heldWrappers.add(wrapper);
|
|
26
|
+
wrapper.addEventListener("scroll", () => toOrigin(wrapper), { passive: true });
|
|
27
|
+
};
|
|
28
|
+
/** A translation this module wrote, as the browser or a test reads it back. */
|
|
29
|
+
const ANCHOR_TRANSLATION = /^translate3d\((-?\d+(?:\.\d+)?)px, (-?\d+(?:\.\d+)?)px, 0(?:px)?\)$/u;
|
|
30
|
+
/**
|
|
31
|
+
* The offset the host carries now: none without a transform, the translation
|
|
32
|
+
* for one this module wrote, null for any other transform.
|
|
33
|
+
*/
|
|
34
|
+
const hostOffset = (hiddenHost) => {
|
|
35
|
+
const transform = hiddenHost.style.transform;
|
|
36
|
+
if (transform === "") return {
|
|
37
|
+
dx: 0,
|
|
38
|
+
dy: 0
|
|
39
|
+
};
|
|
40
|
+
const match = ANCHOR_TRANSLATION.exec(transform);
|
|
41
|
+
if (!match) return null;
|
|
42
|
+
return {
|
|
43
|
+
dx: Number(match[1]),
|
|
44
|
+
dy: Number(match[2])
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Give the host an offset, writing only when it changes. A reset keeps a zero
|
|
49
|
+
* translation rather than removing the transform: the host holds the whole
|
|
50
|
+
* hidden document, and adding or removing its transform makes the browser
|
|
51
|
+
* rebuild paint properties for every node under it.
|
|
52
|
+
*/
|
|
53
|
+
const placeHost = (hiddenHost, dx, dy) => {
|
|
54
|
+
const current = hostOffset(hiddenHost);
|
|
55
|
+
if (current && current.dx === dx && current.dy === dy) return;
|
|
56
|
+
hiddenHost.style.transform = `translate3d(${dx}px, ${dy}px, 0)`;
|
|
57
|
+
};
|
|
2
58
|
const resetHostTransform = (hiddenHost) => {
|
|
3
|
-
if (hiddenHost) hiddenHost
|
|
59
|
+
if (hiddenHost) placeHost(hiddenHost, 0, 0);
|
|
4
60
|
};
|
|
5
61
|
const getNativeSelectionCaret = (editorView) => {
|
|
6
62
|
const editorDom = editorView.dom;
|
|
@@ -25,6 +81,7 @@ const getNativeSelectionCaret = (editorView) => {
|
|
|
25
81
|
*/
|
|
26
82
|
const syncImeCaretAnchor = ({ hiddenHost, editorView, visibleCaret }) => {
|
|
27
83
|
if (!hiddenHost) return false;
|
|
84
|
+
holdWrapperAtOrigin(hiddenHost);
|
|
28
85
|
if (!editorView) {
|
|
29
86
|
resetHostTransform(hiddenHost);
|
|
30
87
|
return false;
|
|
@@ -35,24 +92,31 @@ const syncImeCaretAnchor = ({ hiddenHost, editorView, visibleCaret }) => {
|
|
|
35
92
|
return false;
|
|
36
93
|
}
|
|
37
94
|
const previousTransform = hiddenHost.style.transform;
|
|
38
|
-
|
|
95
|
+
let offset = hostOffset(hiddenHost);
|
|
96
|
+
if (!offset) {
|
|
97
|
+
hiddenHost.style.transform = "";
|
|
98
|
+
offset = {
|
|
99
|
+
dx: 0,
|
|
100
|
+
dy: 0
|
|
101
|
+
};
|
|
102
|
+
}
|
|
39
103
|
let hiddenCaret;
|
|
40
104
|
try {
|
|
41
105
|
hiddenCaret = getNativeSelectionCaret(editorView) ?? editorView.coordsAtPos(editorView.state.selection.head);
|
|
42
106
|
} catch {
|
|
43
|
-
hiddenHost.style.transform = previousTransform;
|
|
107
|
+
if (hiddenHost.style.transform !== previousTransform) hiddenHost.style.transform = previousTransform;
|
|
44
108
|
return false;
|
|
45
109
|
}
|
|
46
110
|
if (!Number.isFinite(hiddenCaret.left) || !Number.isFinite(hiddenCaret.top) || !Number.isFinite(visibleCaret.left) || !Number.isFinite(visibleCaret.top)) {
|
|
47
111
|
resetHostTransform(hiddenHost);
|
|
48
112
|
return false;
|
|
49
113
|
}
|
|
50
|
-
const dx = Math.round(visibleCaret.left - hiddenCaret.left);
|
|
51
|
-
const dy = Math.round(visibleCaret.top - hiddenCaret.top);
|
|
52
|
-
hiddenHost
|
|
114
|
+
const dx = Math.round(visibleCaret.left - (hiddenCaret.left - offset.dx));
|
|
115
|
+
const dy = Math.round(visibleCaret.top - (hiddenCaret.top - offset.dy));
|
|
116
|
+
placeHost(hiddenHost, dx, dy);
|
|
53
117
|
return true;
|
|
54
118
|
};
|
|
55
119
|
const resetImeCaretAnchor = (hiddenHost) => {
|
|
56
120
|
resetHostTransform(hiddenHost);
|
|
57
121
|
};
|
|
58
|
-
export { resetImeCaretAnchor, syncImeCaretAnchor };
|
|
122
|
+
export { HIDDEN_EDITOR_WRAPPER_CLASS, resetImeCaretAnchor, syncImeCaretAnchor };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readPaintedEnd, readPaintedStart } from "../../utils/paintedPositions.js";
|
|
1
2
|
// src/layout-bridge/dom/textStreamDom.ts
|
|
2
3
|
const TEXT_NODE_TYPE = 3;
|
|
3
4
|
const isTextNode = (node) => node.nodeType === TEXT_NODE_TYPE;
|
|
@@ -58,8 +59,8 @@ const createTextStreamRange = (element, startOffset, endOffset) => {
|
|
|
58
59
|
};
|
|
59
60
|
/** Measure the intersecting portion of one painted position span. */
|
|
60
61
|
const measurePaintedSpanRange = (element, from, to) => {
|
|
61
|
-
const pmStart =
|
|
62
|
-
const pmEnd =
|
|
62
|
+
const pmStart = readPaintedStart(element) ?? NaN;
|
|
63
|
+
const pmEnd = readPaintedEnd(element) ?? NaN;
|
|
63
64
|
if (!Number.isFinite(pmStart) || !Number.isFinite(pmEnd) || pmEnd <= from || pmStart >= to) return { type: "outside" };
|
|
64
65
|
if (element.classList.contains("layout-run-tab")) return {
|
|
65
66
|
type: "element",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BlockId, FlowBlock } from "../../layout-engine/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Each block's index by id, the first block's where ids repeat. A pass that
|
|
4
|
+
* looks up the block of every fragment builds it once instead of searching
|
|
5
|
+
* the blocks for each fragment.
|
|
6
|
+
*/
|
|
7
|
+
export declare const indexBlocksById: (blocks: readonly FlowBlock[]) => ReadonlyMap<BlockId, number>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/layout-bridge/engine/blockIndex.ts
|
|
2
|
+
/**
|
|
3
|
+
* Each block's index by id, the first block's where ids repeat. A pass that
|
|
4
|
+
* looks up the block of every fragment builds it once instead of searching
|
|
5
|
+
* the blocks for each fragment.
|
|
6
|
+
*/
|
|
7
|
+
const indexBlocksById = (blocks) => {
|
|
8
|
+
const indices = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const [index, block] of blocks.entries()) if (!indices.has(block.id)) indices.set(block.id, index);
|
|
10
|
+
return indices;
|
|
11
|
+
};
|
|
12
|
+
export { indexBlocksById };
|
|
@@ -3,6 +3,7 @@ import { getTableCellContentWidth } from "../../layout-engine/measure/tableCellF
|
|
|
3
3
|
import { buildTableCellGrid, buildTableCellPlacements, getTableCellSpacingInsetsY } from "../../layout-engine/measure/tableCellGrid.js";
|
|
4
4
|
import { getHeaderRowsHeight } from "../../layout-engine/tableLayout.js";
|
|
5
5
|
import { resolveTableCellPadding } from "../../layout-engine/types.js";
|
|
6
|
+
import { indexBlocksById } from "./blockIndex.js";
|
|
6
7
|
// src/layout-bridge/engine/hitTest.ts
|
|
7
8
|
/**
|
|
8
9
|
* Hit Testing Utilities
|
|
@@ -78,12 +79,6 @@ function getPageIndexAtY(layout, y) {
|
|
|
78
79
|
})?.pageIndex ?? null;
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
|
-
* Find a block by its ID in the blocks array.
|
|
82
|
-
*/
|
|
83
|
-
function findBlockIndexById(blocks, blockId) {
|
|
84
|
-
return blocks.findIndex((block) => block.id === blockId);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
82
|
* Calculate the actual height of a paragraph fragment from its lines.
|
|
88
83
|
*/
|
|
89
84
|
function calculateParagraphFragmentHeight(fragment, measure) {
|
|
@@ -107,8 +102,9 @@ function hitTestFragment(pageHit, blocks, measures, pagePoint) {
|
|
|
107
102
|
if (Math.abs(dy) > .5) return dy;
|
|
108
103
|
return a.x - b.x;
|
|
109
104
|
});
|
|
105
|
+
const blockIndices = indexBlocksById(blocks);
|
|
110
106
|
for (const fragment of sortedFragments) {
|
|
111
|
-
const blockIndex =
|
|
107
|
+
const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
|
|
112
108
|
if (blockIndex === -1) continue;
|
|
113
109
|
const block = blocks[blockIndex];
|
|
114
110
|
const measure = measures[blockIndex];
|
|
@@ -137,9 +133,10 @@ function hitTestFragment(pageHit, blocks, measures, pagePoint) {
|
|
|
137
133
|
* Hit-test to find image fragments (they may overlap other content).
|
|
138
134
|
*/
|
|
139
135
|
function hitTestImageFragment(pageHit, blocks, measures, pagePoint) {
|
|
136
|
+
const blockIndices = indexBlocksById(blocks);
|
|
140
137
|
for (const fragment of pageHit.page.fragments) {
|
|
141
138
|
if (fragment.kind !== "image") continue;
|
|
142
|
-
const blockIndex =
|
|
139
|
+
const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
|
|
143
140
|
if (blockIndex === -1) continue;
|
|
144
141
|
const block = blocks[blockIndex];
|
|
145
142
|
const measure = measures[blockIndex];
|
|
@@ -167,13 +164,14 @@ function hitTestImageFragment(pageHit, blocks, measures, pagePoint) {
|
|
|
167
164
|
* @returns TableCellHit if a table cell was found, null otherwise.
|
|
168
165
|
*/
|
|
169
166
|
function hitTestTableCell(pageHit, blocks, measures, pagePoint) {
|
|
167
|
+
const blockIndices = indexBlocksById(blocks);
|
|
170
168
|
for (const fragment of pageHit.page.fragments) {
|
|
171
169
|
if (fragment.kind !== "table") continue;
|
|
172
170
|
const tableFragment = fragment;
|
|
173
171
|
const withinX = pagePoint.x >= tableFragment.x && pagePoint.x <= tableFragment.x + tableFragment.width;
|
|
174
172
|
const withinY = pagePoint.y >= tableFragment.y && pagePoint.y <= tableFragment.y + tableFragment.height;
|
|
175
173
|
if (!withinX || !withinY) continue;
|
|
176
|
-
const blockIndex =
|
|
174
|
+
const blockIndex = blockIndices.get(tableFragment.blockId) ?? -1;
|
|
177
175
|
if (blockIndex === -1) continue;
|
|
178
176
|
const block = blocks[blockIndex];
|
|
179
177
|
const measure = measures[blockIndex];
|
|
@@ -363,8 +361,9 @@ function isPointInContentArea(_layout, pageHit, pagePoint) {
|
|
|
363
361
|
function findNearestFragment(pageHit, blocks, measures, pagePoint) {
|
|
364
362
|
let nearestHit = null;
|
|
365
363
|
let nearestDistance = Infinity;
|
|
364
|
+
const blockIndices = indexBlocksById(blocks);
|
|
366
365
|
for (const fragment of pageHit.page.fragments) {
|
|
367
|
-
const blockIndex =
|
|
366
|
+
const blockIndex = blockIndices.get(fragment.blockId) ?? -1;
|
|
368
367
|
if (blockIndex === -1) continue;
|
|
369
368
|
const block = blocks[blockIndex];
|
|
370
369
|
const measure = measures[blockIndex];
|