@stll/folio-core 0.0.1-placeholder.0 → 0.1.1
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/LICENSE +202 -0
- package/NOTICE.md +29 -0
- package/README.md +41 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/ai-edits/apply.d.ts +35 -0
- package/dist/ai-edits/apply.js +683 -0
- package/dist/ai-edits/clean-text.d.ts +28 -0
- package/dist/ai-edits/clean-text.js +23 -0
- package/dist/ai-edits/headless.d.ts +225 -0
- package/dist/ai-edits/headless.js +513 -0
- package/dist/ai-edits/index.d.ts +6 -0
- package/dist/ai-edits/index.js +5 -0
- package/dist/ai-edits/inline-emphasis.d.ts +38 -0
- package/dist/ai-edits/inline-emphasis.js +78 -0
- package/dist/ai-edits/snapshot.d.ts +9 -0
- package/dist/ai-edits/snapshot.js +195 -0
- package/dist/ai-edits/types.d.ts +156 -0
- package/dist/ai-edits/types.js +0 -0
- package/dist/ai-edits/word-diff.d.ts +20 -0
- package/dist/ai-edits/word-diff.js +77 -0
- package/dist/ai-suggestions/apply.d.ts +17 -0
- package/dist/ai-suggestions/apply.js +64 -0
- package/dist/ai-suggestions/conflict.d.ts +22 -0
- package/dist/ai-suggestions/conflict.js +67 -0
- package/dist/ai-suggestions/text-positions.d.ts +21 -0
- package/dist/ai-suggestions/text-positions.js +48 -0
- package/dist/ai-suggestions/types.d.ts +199 -0
- package/dist/ai-suggestions/types.js +59 -0
- package/dist/content-controls/errors.d.ts +52 -0
- package/dist/content-controls/errors.js +36 -0
- package/dist/content-controls/findContentControls.d.ts +55 -0
- package/dist/content-controls/findContentControls.js +75 -0
- package/dist/content-controls/index.d.ts +4 -0
- package/dist/content-controls/index.js +4 -0
- package/dist/content-controls/mutateContentControls.d.ts +51 -0
- package/dist/content-controls/mutateContentControls.js +377 -0
- package/dist/controller/folioEditor.d.ts +21 -0
- package/dist/controller/folioEditor.js +29 -0
- package/dist/controller/folioEditorEvents.d.ts +23 -0
- package/dist/controller/folioEditorEvents.js +24 -0
- package/dist/controller/hiddenEditorApi.d.ts +35 -0
- package/dist/controller/hiddenEditorApi.js +112 -0
- package/dist/controller/hiddenEditorManager.d.ts +93 -0
- package/dist/controller/hiddenEditorManager.js +308 -0
- package/dist/controller/layoutPipeline.d.ts +63 -0
- package/dist/controller/layoutPipeline.js +406 -0
- package/dist/controller/layoutScheduler.d.ts +41 -0
- package/dist/controller/layoutScheduler.js +59 -0
- package/dist/controller/layoutSession.d.ts +24 -0
- package/dist/controller/layoutSession.js +13 -0
- package/dist/docx/blockContentParser.d.ts +13 -0
- package/dist/docx/blockContentParser.js +289 -0
- package/dist/docx/bookmarkParser.d.ts +178 -0
- package/dist/docx/bookmarkParser.js +246 -0
- package/dist/docx/bookmarkPlacement.d.ts +10 -0
- package/dist/docx/bookmarkPlacement.js +50 -0
- package/dist/docx/bulletMarkers.d.ts +4 -0
- package/dist/docx/bulletMarkers.js +42 -0
- package/dist/docx/commentParser.d.ts +34 -0
- package/dist/docx/commentParser.js +127 -0
- package/dist/docx/commentReferenceNormalization.d.ts +25 -0
- package/dist/docx/commentReferenceNormalization.js +97 -0
- package/dist/docx/commentReplyMarkers.d.ts +20 -0
- package/dist/docx/commentReplyMarkers.js +123 -0
- package/dist/docx/compatibility.d.ts +12 -0
- package/dist/docx/compatibility.js +77 -0
- package/dist/docx/documentParser.d.ts +65 -0
- package/dist/docx/documentParser.js +209 -0
- package/dist/docx/drawingUtils.d.ts +56 -0
- package/dist/docx/drawingUtils.js +305 -0
- package/dist/docx/fieldParser.d.ts +228 -0
- package/dist/docx/fieldParser.js +559 -0
- package/dist/docx/footnoteParser.d.ts +109 -0
- package/dist/docx/footnoteParser.js +270 -0
- package/dist/docx/headerFooterParser.d.ts +119 -0
- package/dist/docx/headerFooterParser.js +266 -0
- package/dist/docx/headerFooterRefParser.d.ts +22 -0
- package/dist/docx/headerFooterRefParser.js +52 -0
- package/dist/docx/headerFooterReferenceNormalization.d.ts +19 -0
- package/dist/docx/headerFooterReferenceNormalization.js +64 -0
- package/dist/docx/hyperlinkParser.d.ts +108 -0
- package/dist/docx/hyperlinkParser.js +230 -0
- package/dist/docx/imageParser.d.ts +93 -0
- package/dist/docx/imageParser.js +522 -0
- package/dist/docx/mathToMathml.d.ts +15 -0
- package/dist/docx/mathToMathml.js +357 -0
- package/dist/docx/modelValidation.d.ts +13 -0
- package/dist/docx/modelValidation.js +21 -0
- package/dist/docx/normalizeBaseDirection.d.ts +12 -0
- package/dist/docx/normalizeBaseDirection.js +81 -0
- package/dist/docx/notePropertiesParser.d.ts +16 -0
- package/dist/docx/notePropertiesParser.js +99 -0
- package/dist/docx/numberingParser.d.ts +86 -0
- package/dist/docx/numberingParser.js +735 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +25 -0
- package/dist/docx/numberingReferenceNormalization.js +22 -0
- package/dist/docx/paragraphParser.d.ts +86 -0
- package/dist/docx/paragraphParser.js +1132 -0
- package/dist/docx/paragraphTraversal.d.ts +19 -0
- package/dist/docx/paragraphTraversal.js +76 -0
- package/dist/docx/parser.d.ts +67 -0
- package/dist/docx/parser.js +391 -0
- package/dist/docx/parserEnums.d.ts +45 -0
- package/dist/docx/parserEnums.js +70 -0
- package/dist/docx/relsParser.d.ts +160 -0
- package/dist/docx/relsParser.js +235 -0
- package/dist/docx/replyToComment.d.ts +29 -0
- package/dist/docx/replyToComment.js +73 -0
- package/dist/docx/rezip.d.ts +166 -0
- package/dist/docx/rezip.js +1194 -0
- package/dist/docx/runConsolidator.d.ts +57 -0
- package/dist/docx/runConsolidator.js +224 -0
- package/dist/docx/runParser.d.ts +78 -0
- package/dist/docx/runParser.js +661 -0
- package/dist/docx/sdtProperties.d.ts +15 -0
- package/dist/docx/sdtProperties.js +290 -0
- package/dist/docx/sdtPropertiesPatch.d.ts +16 -0
- package/dist/docx/sdtPropertiesPatch.js +144 -0
- package/dist/docx/sectionParser.d.ts +95 -0
- package/dist/docx/sectionParser.js +534 -0
- package/dist/docx/selectiveSave.d.ts +25 -0
- package/dist/docx/selectiveSave.js +247 -0
- package/dist/docx/selectiveSaveFlags.d.ts +33 -0
- package/dist/docx/selectiveSaveFlags.js +11 -0
- package/dist/docx/selectiveSaveTripwire.d.ts +33 -0
- package/dist/docx/selectiveSaveTripwire.js +79 -0
- package/dist/docx/selectiveXmlPatch.d.ts +103 -0
- package/dist/docx/selectiveXmlPatch.js +493 -0
- package/dist/docx/serializer/blockSdtSerializer.d.ts +6 -0
- package/dist/docx/serializer/blockSdtSerializer.js +88 -0
- package/dist/docx/serializer/borderSerializer.d.ts +25 -0
- package/dist/docx/serializer/borderSerializer.js +44 -0
- package/dist/docx/serializer/commentSerializer.d.ts +31 -0
- package/dist/docx/serializer/commentSerializer.js +184 -0
- package/dist/docx/serializer/documentSerializer.d.ts +65 -0
- package/dist/docx/serializer/documentSerializer.js +199 -0
- package/dist/docx/serializer/headerFooterSerializer.d.ts +12 -0
- package/dist/docx/serializer/headerFooterSerializer.js +84 -0
- package/dist/docx/serializer/noteSerializer.d.ts +19 -0
- package/dist/docx/serializer/noteSerializer.js +70 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +12 -0
- package/dist/docx/serializer/numberingSerializer.js +93 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +48 -0
- package/dist/docx/serializer/paragraphSerializer.js +559 -0
- package/dist/docx/serializer/runSerializer.d.ts +56 -0
- package/dist/docx/serializer/runSerializer.js +621 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.d.ts +6 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +187 -0
- package/dist/docx/serializer/tableSerializer.d.ts +79 -0
- package/dist/docx/serializer/tableSerializer.js +422 -0
- package/dist/docx/serializer/xmlUtils.d.ts +20 -0
- package/dist/docx/serializer/xmlUtils.js +25 -0
- package/dist/docx/settingsParser.d.ts +8 -0
- package/dist/docx/settingsParser.js +36 -0
- package/dist/docx/shapeParser.d.ts +20 -0
- package/dist/docx/shapeParser.js +272 -0
- package/dist/docx/styleParser.d.ts +50 -0
- package/dist/docx/styleParser.js +905 -0
- package/dist/docx/tableParser.d.ts +202 -0
- package/dist/docx/tableParser.js +811 -0
- package/dist/docx/textBoxParser.d.ts +117 -0
- package/dist/docx/textBoxParser.js +262 -0
- package/dist/docx/themeParser.d.ts +77 -0
- package/dist/docx/themeParser.js +330 -0
- package/dist/docx/trackedMoveRangeNormalization.d.ts +22 -0
- package/dist/docx/trackedMoveRangeNormalization.js +100 -0
- package/dist/docx/unzip.d.ts +118 -0
- package/dist/docx/unzip.js +383 -0
- package/dist/docx/vmlImageParser.d.ts +16 -0
- package/dist/docx/vmlImageParser.js +100 -0
- package/dist/docx/watermarkParser.d.ts +45 -0
- package/dist/docx/watermarkParser.js +348 -0
- package/dist/docx/wrapTypes.d.ts +29 -0
- package/dist/docx/wrapTypes.js +48 -0
- package/dist/docx/xmlParser.d.ts +297 -0
- package/dist/docx/xmlParser.js +527 -0
- package/dist/fields/bookmarkPages.d.ts +13 -0
- package/dist/fields/bookmarkPages.js +66 -0
- package/dist/fields/bookmarkText.d.ts +16 -0
- package/dist/fields/bookmarkText.js +61 -0
- package/dist/fields/evaluateField.d.ts +23 -0
- package/dist/fields/evaluateField.js +77 -0
- package/dist/fields/fieldContext.d.ts +21 -0
- package/dist/fields/fieldContext.js +0 -0
- package/dist/fields/resolveFieldValues.d.ts +44 -0
- package/dist/fields/resolveFieldValues.js +204 -0
- package/dist/fields/sectionPageCounts.d.ts +11 -0
- package/dist/fields/sectionPageCounts.js +16 -0
- package/dist/fields/seqValues.d.ts +14 -0
- package/dist/fields/seqValues.js +36 -0
- package/dist/fonts/embeddedFontTable.d.ts +42 -0
- package/dist/fonts/embeddedFontTable.js +80 -0
- package/dist/fonts/embeddedFonts.d.ts +46 -0
- package/dist/fonts/embeddedFonts.js +112 -0
- package/dist/fonts/fontDeobfuscation.d.ts +30 -0
- package/dist/fonts/fontDeobfuscation.js +57 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +23 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +57 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +316 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +74 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +432 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +36 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.js +176 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +65 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +1309 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +17 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.js +36 -0
- package/dist/layout-bridge/dom/clickToPositionDom.d.ts +66 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +304 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.d.ts +7 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.js +17 -0
- package/dist/layout-bridge/dom/findHfPmSpans.d.ts +62 -0
- package/dist/layout-bridge/dom/findHfPmSpans.js +197 -0
- package/dist/layout-bridge/engine/clickToPosition.d.ts +66 -0
- package/dist/layout-bridge/engine/clickToPosition.js +403 -0
- package/dist/layout-bridge/engine/hitTest.d.ts +135 -0
- package/dist/layout-bridge/engine/hitTest.js +375 -0
- package/dist/layout-bridge/engine/measuring/index.d.ts +10 -0
- package/dist/layout-bridge/engine/measuring/index.js +9 -0
- package/dist/layout-bridge/engine/selectionRects.d.ts +59 -0
- package/dist/layout-bridge/engine/selectionRects.js +485 -0
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +7 -0
- package/dist/layout-bridge/engine/tableWidthUtils.js +25 -0
- package/dist/layout-engine/index.d.ts +44 -0
- package/dist/layout-engine/index.js +691 -0
- package/dist/layout-engine/keep-together.d.ts +43 -0
- package/dist/layout-engine/keep-together.js +98 -0
- package/dist/layout-engine/layoutInstrumentation.d.ts +50 -0
- package/dist/layout-engine/layoutInstrumentation.js +43 -0
- package/dist/layout-engine/lineFlow.d.ts +8 -0
- package/dist/layout-engine/lineFlow.js +17 -0
- package/dist/layout-engine/measure/cache.d.ts +93 -0
- package/dist/layout-engine/measure/cache.js +245 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.d.ts +20 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.js +29 -0
- package/dist/layout-engine/measure/featureFlags.d.ts +44 -0
- package/dist/layout-engine/measure/featureFlags.js +19 -0
- package/dist/layout-engine/measure/floatingZones.d.ts +89 -0
- package/dist/layout-engine/measure/floatingZones.js +152 -0
- package/dist/layout-engine/measure/font-metrics.worker.d.ts +17 -0
- package/dist/layout-engine/measure/font-metrics.worker.js +104 -0
- package/dist/layout-engine/measure/index.d.ts +9 -0
- package/dist/layout-engine/measure/index.js +8 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +40 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +76 -0
- package/dist/layout-engine/measure/measureBlocks.d.ts +25 -0
- package/dist/layout-engine/measure/measureBlocks.js +450 -0
- package/dist/layout-engine/measure/measureContainer.d.ts +24 -0
- package/dist/layout-engine/measure/measureContainer.js +280 -0
- package/dist/layout-engine/measure/measureHelpers.d.ts +82 -0
- package/dist/layout-engine/measure/measureHelpers.js +156 -0
- package/dist/layout-engine/measure/measureParagraph.d.ts +61 -0
- package/dist/layout-engine/measure/measureParagraph.js +724 -0
- package/dist/layout-engine/measure/measureProvider.d.ts +23 -0
- package/dist/layout-engine/measure/measureProvider.js +35 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +61 -0
- package/dist/layout-engine/measure/measureTypes.js +0 -0
- package/dist/layout-engine/measure/measureWorker.d.ts +54 -0
- package/dist/layout-engine/measure/measureWorker.js +249 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +88 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.js +20 -0
- package/dist/layout-engine/measure/tableCellFloating.d.ts +26 -0
- package/dist/layout-engine/measure/tableCellFloating.js +99 -0
- package/dist/layout-engine/paginator.d.ts +84 -0
- package/dist/layout-engine/paginator.js +348 -0
- package/dist/layout-engine/paragraphFragmentRange.d.ts +9 -0
- package/dist/layout-engine/paragraphFragmentRange.js +40 -0
- package/dist/layout-engine/section-breaks.d.ts +78 -0
- package/dist/layout-engine/section-breaks.js +182 -0
- package/dist/layout-engine/tableRowBreak.d.ts +23 -0
- package/dist/layout-engine/tableRowBreak.js +147 -0
- package/dist/layout-engine/textBoxFlow.d.ts +50 -0
- package/dist/layout-engine/textBoxFlow.js +160 -0
- package/dist/layout-engine/types.d.ts +1031 -0
- package/dist/layout-engine/types.js +100 -0
- package/dist/layout-painter/documentColors.d.ts +4 -0
- package/dist/layout-painter/documentColors.js +40 -0
- package/dist/layout-painter/index.d.ts +110 -0
- package/dist/layout-painter/index.js +182 -0
- package/dist/layout-painter/registry/modules/image.d.ts +6 -0
- package/dist/layout-painter/registry/modules/image.js +17 -0
- package/dist/layout-painter/registry/modules/paragraph.d.ts +6 -0
- package/dist/layout-painter/registry/modules/paragraph.js +18 -0
- package/dist/layout-painter/registry/modules/table.d.ts +6 -0
- package/dist/layout-painter/registry/modules/table.js +16 -0
- package/dist/layout-painter/registry/modules/textBox.d.ts +6 -0
- package/dist/layout-painter/registry/modules/textBox.js +13 -0
- package/dist/layout-painter/registry/modules.d.ts +6 -0
- package/dist/layout-painter/registry/modules.js +26 -0
- package/dist/layout-painter/registry/registry.d.ts +24 -0
- package/dist/layout-painter/registry/registry.js +53 -0
- package/dist/layout-painter/registry/types.d.ts +61 -0
- package/dist/layout-painter/registry/types.js +0 -0
- package/dist/layout-painter/renderFragment.d.ts +32 -0
- package/dist/layout-painter/renderFragment.js +114 -0
- package/dist/layout-painter/renderImage.d.ts +88 -0
- package/dist/layout-painter/renderImage.js +130 -0
- package/dist/layout-painter/renderPage.d.ts +264 -0
- package/dist/layout-painter/renderPage.js +1795 -0
- package/dist/layout-painter/renderParagraph.d.ts +93 -0
- package/dist/layout-painter/renderParagraph.js +1300 -0
- package/dist/layout-painter/renderTable.d.ts +36 -0
- package/dist/layout-painter/renderTable.js +432 -0
- package/dist/layout-painter/renderTextBox.d.ts +22 -0
- package/dist/layout-painter/renderTextBox.js +67 -0
- package/dist/layout-painter/renderUtils.d.ts +42 -0
- package/dist/layout-painter/renderUtils.js +30 -0
- package/dist/layout-painter/renderWatermark.d.ts +16 -0
- package/dist/layout-painter/renderWatermark.js +61 -0
- package/dist/layout-painter/sdtBoundary.d.ts +6 -0
- package/dist/layout-painter/sdtBoundary.js +28 -0
- package/dist/managers/ContextMenuManager.d.ts +28 -0
- package/dist/managers/ContextMenuManager.js +48 -0
- package/dist/managers/DocumentLoaderManager.d.ts +47 -0
- package/dist/managers/DocumentLoaderManager.js +69 -0
- package/dist/managers/EditorModeManager.d.ts +28 -0
- package/dist/managers/EditorModeManager.js +50 -0
- package/dist/managers/ErrorManager.d.ts +26 -0
- package/dist/managers/ErrorManager.js +85 -0
- package/dist/managers/FindReplaceManager.d.ts +54 -0
- package/dist/managers/FindReplaceManager.js +104 -0
- package/dist/managers/HistoryManager.d.ts +92 -0
- package/dist/managers/HistoryManager.js +193 -0
- package/dist/managers/Subscribable.d.ts +34 -0
- package/dist/managers/Subscribable.js +46 -0
- package/dist/managers/TableSelectionManager.d.ts +74 -0
- package/dist/managers/TableSelectionManager.js +225 -0
- package/dist/managers/editorShortcuts.d.ts +42 -0
- package/dist/managers/editorShortcuts.js +60 -0
- package/dist/managers/types.d.ts +41 -0
- package/dist/managers/types.js +0 -0
- package/dist/markdown/annotations.d.ts +14 -0
- package/dist/markdown/annotations.js +42 -0
- package/dist/markdown/escape.d.ts +36 -0
- package/dist/markdown/escape.js +59 -0
- package/dist/markdown/fromMarkdown.d.ts +11 -0
- package/dist/markdown/fromMarkdown.js +223 -0
- package/dist/markdown/headings.d.ts +13 -0
- package/dist/markdown/headings.js +20 -0
- package/dist/markdown/images.d.ts +13 -0
- package/dist/markdown/images.js +63 -0
- package/dist/markdown/index.d.ts +18 -0
- package/dist/markdown/index.js +33 -0
- package/dist/markdown/internals.d.ts +15 -0
- package/dist/markdown/internals.js +35 -0
- package/dist/markdown/renderBlock.d.ts +7 -0
- package/dist/markdown/renderBlock.js +68 -0
- package/dist/markdown/renderParagraph.d.ts +11 -0
- package/dist/markdown/renderParagraph.js +64 -0
- package/dist/markdown/renderRuns.d.ts +11 -0
- package/dist/markdown/renderRuns.js +265 -0
- package/dist/markdown/renderTable.d.ts +8 -0
- package/dist/markdown/renderTable.js +229 -0
- package/dist/markdown/trailers.d.ts +13 -0
- package/dist/markdown/trailers.js +54 -0
- package/dist/markdown/types.d.ts +118 -0
- package/dist/markdown/types.js +0 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +4 -0
- package/dist/paged-layout/LayoutSelectionGate.d.ts +80 -0
- package/dist/paged-layout/LayoutSelectionGate.js +131 -0
- package/dist/paged-layout/headerFooterMargins.d.ts +73 -0
- package/dist/paged-layout/headerFooterMargins.js +120 -0
- package/dist/paged-layout/hiddenEditorScroll.d.ts +4 -0
- package/dist/paged-layout/hiddenEditorScroll.js +4 -0
- package/dist/paged-layout/incrementalMeasure.d.ts +33 -0
- package/dist/paged-layout/incrementalMeasure.js +56 -0
- package/dist/paged-layout/rangeProjection.d.ts +51 -0
- package/dist/paged-layout/rangeProjection.js +153 -0
- package/dist/paged-layout/readOnlyEditAttempt.d.ts +5 -0
- package/dist/paged-layout/readOnlyEditAttempt.js +22 -0
- package/dist/paged-layout/scrollNavigation.d.ts +23 -0
- package/dist/paged-layout/scrollNavigation.js +31 -0
- package/dist/paged-layout/scrollPageInfo.d.ts +41 -0
- package/dist/paged-layout/scrollPageInfo.js +34 -0
- package/dist/paged-layout/scrollToPmPosition.d.ts +17 -0
- package/dist/paged-layout/scrollToPmPosition.js +95 -0
- package/dist/paged-layout/sectionBlockWidths.d.ts +35 -0
- package/dist/paged-layout/sectionBlockWidths.js +52 -0
- package/dist/paged-layout/sectionGeometry.d.ts +21 -0
- package/dist/paged-layout/sectionGeometry.js +36 -0
- package/dist/paged-layout/selectionViewportRect.d.ts +29 -0
- package/dist/paged-layout/selectionViewportRect.js +55 -0
- package/dist/paged-layout/tableColumnResize.d.ts +19 -0
- package/dist/paged-layout/tableColumnResize.js +28 -0
- package/dist/paged-layout/tableInsertButtonGeometry.d.ts +15 -0
- package/dist/paged-layout/tableInsertButtonGeometry.js +15 -0
- package/dist/paged-layout/transactionDirtyRange.d.ts +7 -0
- package/dist/paged-layout/transactionDirtyRange.js +27 -0
- package/dist/paged-layout/zoomScrollAnchor.d.ts +40 -0
- package/dist/paged-layout/zoomScrollAnchor.js +25 -0
- package/dist/prosemirror/attrs/index.d.ts +80 -0
- package/dist/prosemirror/attrs/index.js +1218 -0
- package/dist/prosemirror/autospacingBase.d.ts +11 -0
- package/dist/prosemirror/autospacingBase.js +16 -0
- package/dist/prosemirror/commands/comments.d.ts +93 -0
- package/dist/prosemirror/commands/comments.js +435 -0
- package/dist/prosemirror/commands/contentControls.d.ts +45 -0
- package/dist/prosemirror/commands/contentControls.js +294 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +15 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.js +19 -0
- package/dist/prosemirror/commands/formatPainter.d.ts +31 -0
- package/dist/prosemirror/commands/formatPainter.js +130 -0
- package/dist/prosemirror/commands/formatting.d.ts +32 -0
- package/dist/prosemirror/commands/formatting.js +45 -0
- package/dist/prosemirror/commands/hyperlink.d.ts +31 -0
- package/dist/prosemirror/commands/hyperlink.js +79 -0
- package/dist/prosemirror/commands/image.d.ts +59 -0
- package/dist/prosemirror/commands/image.js +219 -0
- package/dist/prosemirror/commands/index.d.ts +13 -0
- package/dist/prosemirror/commands/index.js +13 -0
- package/dist/prosemirror/commands/pageBreak.d.ts +10 -0
- package/dist/prosemirror/commands/pageBreak.js +47 -0
- package/dist/prosemirror/commands/paragraph.d.ts +39 -0
- package/dist/prosemirror/commands/paragraph.js +64 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +39 -0
- package/dist/prosemirror/commands/pastePlainText.js +67 -0
- package/dist/prosemirror/commands/table.d.ts +83 -0
- package/dist/prosemirror/commands/table.js +105 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +27 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +1550 -0
- package/dist/prosemirror/conversion/index.d.ts +4 -0
- package/dist/prosemirror/conversion/index.js +4 -0
- package/dist/prosemirror/conversion/runShadingMark.d.ts +16 -0
- package/dist/prosemirror/conversion/runShadingMark.js +39 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +39 -0
- package/dist/prosemirror/conversion/toProseDoc.js +1404 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +43 -0
- package/dist/prosemirror/extensions/ExtensionManager.js +86 -0
- package/dist/prosemirror/extensions/StarterKit.d.ts +16 -0
- package/dist/prosemirror/extensions/StarterKit.js +132 -0
- package/dist/prosemirror/extensions/core/DocExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +12 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.js +28 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +25 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +619 -0
- package/dist/prosemirror/extensions/core/TextExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/TextExtension.js +12 -0
- package/dist/prosemirror/extensions/create.d.ts +17 -0
- package/dist/prosemirror/extensions/create.js +129 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +106 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +172 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +38 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.js +21 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.js +20 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +44 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +19 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.js +24 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +15 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +66 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +91 -0
- package/dist/prosemirror/extensions/features/ListExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +340 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +60 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +35 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +188 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +34 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.js +145 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.js +17 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.d.ts +31 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.js +27 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +31 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.js +159 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.js +41 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +64 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +55 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +92 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.js +115 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +146 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.js +34 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.js +21 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +75 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +33 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +50 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +31 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.js +134 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +22 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +113 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.js +60 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +34 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +233 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +122 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +87 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +38 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.js +18 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +132 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.js +56 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +20 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.js +107 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +30 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +502 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.js +27 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +1972 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +150 -0
- package/dist/prosemirror/extensions/types.d.ts +101 -0
- package/dist/prosemirror/extensions/types.js +10 -0
- package/dist/prosemirror/findReplaceSelection.d.ts +23 -0
- package/dist/prosemirror/findReplaceSelection.js +86 -0
- package/dist/prosemirror/index.d.ts +25 -0
- package/dist/prosemirror/index.js +23 -0
- package/dist/prosemirror/insertOperations.d.ts +12 -0
- package/dist/prosemirror/insertOperations.js +19 -0
- package/dist/prosemirror/paragraphDirection.d.ts +42 -0
- package/dist/prosemirror/paragraphDirection.js +33 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +40 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.js +90 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +42 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +135 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +60 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.js +120 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +123 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +283 -0
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +56 -0
- package/dist/prosemirror/plugins/contentControlWidgets.js +192 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +37 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.js +55 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +18 -0
- package/dist/prosemirror/plugins/documentStyles.js +46 -0
- package/dist/prosemirror/plugins/index.d.ts +3 -0
- package/dist/prosemirror/plugins/index.js +3 -0
- package/dist/prosemirror/plugins/pmTextScan.d.ts +19 -0
- package/dist/prosemirror/plugins/pmTextScan.js +39 -0
- package/dist/prosemirror/plugins/selectionTracker.d.ts +43 -0
- package/dist/prosemirror/plugins/selectionTracker.js +179 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +70 -0
- package/dist/prosemirror/plugins/suggestionMode.js +489 -0
- package/dist/prosemirror/plugins/templateDirectives.d.ts +25 -0
- package/dist/prosemirror/plugins/templateDirectives.js +67 -0
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +49 -0
- package/dist/prosemirror/plugins/templatePreviewValues.js +117 -0
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +57 -0
- package/dist/prosemirror/plugins/templateSlashMenu.js +184 -0
- package/dist/prosemirror/schema/index.d.ts +15 -0
- package/dist/prosemirror/schema/index.js +20 -0
- package/dist/prosemirror/schema/marks.d.ts +118 -0
- package/dist/prosemirror/schema/marks.js +0 -0
- package/dist/prosemirror/schema/nodes.d.ts +389 -0
- package/dist/prosemirror/schema/nodes.js +0 -0
- package/dist/prosemirror/selectionState.d.ts +23 -0
- package/dist/prosemirror/selectionState.js +111 -0
- package/dist/prosemirror/styles/index.d.ts +2 -0
- package/dist/prosemirror/styles/index.js +2 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +32 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +108 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +94 -0
- package/dist/prosemirror/styles/styleResolver.js +200 -0
- package/dist/prosemirror/utils/findParagraphByParaId.d.ts +26 -0
- package/dist/prosemirror/utils/findParagraphByParaId.js +37 -0
- package/dist/prosemirror/utils/tabCalculator.d.ts +110 -0
- package/dist/prosemirror/utils/tabCalculator.js +137 -0
- package/dist/prosemirror/validation.d.ts +20 -0
- package/dist/prosemirror/validation.js +177 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +6 -0
- package/dist/style-engine/index.d.ts +3 -0
- package/dist/style-engine/index.js +2 -0
- package/dist/style-engine/styleEngine.d.ts +67 -0
- package/dist/style-engine/styleEngine.js +70 -0
- package/dist/types/block-id.d.ts +66 -0
- package/dist/types/block-id.js +73 -0
- package/dist/types/colors.d.ts +2 -0
- package/dist/types/colors.js +0 -0
- package/dist/types/content.d.ts +2 -0
- package/dist/types/content.js +0 -0
- package/dist/types/document.d.ts +7 -0
- package/dist/types/document.js +0 -0
- package/dist/types/documentEnumValues.d.ts +89 -0
- package/dist/types/documentEnumValues.js +693 -0
- package/dist/types/formatting.d.ts +2 -0
- package/dist/types/formatting.js +0 -0
- package/dist/types/index.d.ts +107 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/authorColors.d.ts +16 -0
- package/dist/utils/authorColors.js +30 -0
- package/dist/utils/baseDirection.d.ts +23 -0
- package/dist/utils/baseDirection.js +34 -0
- package/dist/utils/clipboard.d.ts +126 -0
- package/dist/utils/clipboard.js +622 -0
- package/dist/utils/colorResolver.d.ts +158 -0
- package/dist/utils/colorResolver.js +557 -0
- package/dist/utils/createDocument.d.ts +50 -0
- package/dist/utils/createDocument.js +262 -0
- package/dist/utils/documentLoaderBehavior.d.ts +22 -0
- package/dist/utils/documentLoaderBehavior.js +14 -0
- package/dist/utils/docxInput.d.ts +22 -0
- package/dist/utils/docxInput.js +16 -0
- package/dist/utils/domGuards.d.ts +59 -0
- package/dist/utils/domGuards.js +82 -0
- package/dist/utils/fontFamilyMerge.d.ts +7 -0
- package/dist/utils/fontFamilyMerge.js +31 -0
- package/dist/utils/fontLoader.d.ts +50 -0
- package/dist/utils/fontLoader.js +177 -0
- package/dist/utils/fontResolver.d.ts +61 -0
- package/dist/utils/fontResolver.js +651 -0
- package/dist/utils/fontWeights.d.ts +4 -0
- package/dist/utils/fontWeights.js +4 -0
- package/dist/utils/formatToStyle.d.ts +103 -0
- package/dist/utils/formatToStyle.js +289 -0
- package/dist/utils/headerFooter.d.ts +74 -0
- package/dist/utils/headerFooter.js +257 -0
- package/dist/utils/headingCollector.d.ts +22 -0
- package/dist/utils/headingCollector.js +36 -0
- package/dist/utils/hexId.d.ts +33 -0
- package/dist/utils/hexId.js +37 -0
- package/dist/utils/imageValidation.d.ts +5 -0
- package/dist/utils/imageValidation.js +31 -0
- package/dist/utils/paragraphFormattingMerge.d.ts +14 -0
- package/dist/utils/paragraphFormattingMerge.js +68 -0
- package/dist/utils/replaceText.d.ts +17 -0
- package/dist/utils/replaceText.js +161 -0
- package/dist/utils/rotationBoundingBox.d.ts +12 -0
- package/dist/utils/rotationBoundingBox.js +36 -0
- package/dist/utils/scriptSegments.d.ts +36 -0
- package/dist/utils/scriptSegments.js +52 -0
- package/dist/utils/tableOperations.d.ts +87 -0
- package/dist/utils/tableOperations.js +259 -0
- package/dist/utils/textFormattingMerge.d.ts +6 -0
- package/dist/utils/textFormattingMerge.js +31 -0
- package/dist/utils/tiffConverter.d.ts +18 -0
- package/dist/utils/tiffConverter.js +83 -0
- package/dist/utils/units.d.ts +99 -0
- package/dist/utils/units.js +139 -0
- package/dist/utils/urlSecurity.d.ts +7 -0
- package/dist/utils/urlSecurity.js +65 -0
- package/dist/watermark/index.d.ts +39 -0
- package/dist/watermark/index.js +149 -0
- package/package.json +122 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { findPositionInSpan } from "./clickToPositionDom.js";
|
|
2
|
+
//#region src/layout-bridge/dom/findHfPmSpans.ts
|
|
3
|
+
/**
|
|
4
|
+
* Slot-scoped sibling of `findBodyPmSpans` — locates `data-pm-start` markers
|
|
5
|
+
* inside a single painted header/footer slot. The pointer pipeline uses these
|
|
6
|
+
* to translate a click coordinate inside `.layout-page-header[data-rid="…"]`
|
|
7
|
+
* (or footer) to a PM position on the matching hidden HF EditorView.
|
|
8
|
+
*
|
|
9
|
+
* Slot identity is the part-relationship id (`rId`) emitted by the painter on
|
|
10
|
+
* the HF DOM node — never the `(hdrFtrType, kind)` tuple (two sections that
|
|
11
|
+
* share a header by rId share both the painted spans and the EditorView).
|
|
12
|
+
*/
|
|
13
|
+
function slotSelector(kind, rId) {
|
|
14
|
+
return kind === "header" ? `.layout-page-header[data-rid="${rId}"]` : `.layout-page-footer[data-rid="${rId}"]`;
|
|
15
|
+
}
|
|
16
|
+
function associatedSlotSelector(kind, rId) {
|
|
17
|
+
return `[data-hf-slot-kind="${kind}"][data-hf-rid="${rId}"]`;
|
|
18
|
+
}
|
|
19
|
+
function uniqueElements(elements) {
|
|
20
|
+
return Array.from(new Set(elements));
|
|
21
|
+
}
|
|
22
|
+
function querySlotDescendants(container, kind, rId, selector) {
|
|
23
|
+
return uniqueElements([...Array.from(container.querySelectorAll(`${slotSelector(kind, rId)} ${selector}`)), ...Array.from(container.querySelectorAll(`${associatedSlotSelector(kind, rId)} ${selector}`))]);
|
|
24
|
+
}
|
|
25
|
+
function querySlotAnchors(container, kind, rId, selector) {
|
|
26
|
+
return uniqueElements([...querySlotDescendants(container, kind, rId, selector), ...Array.from(container.querySelectorAll(`${associatedSlotSelector(kind, rId)}${selector}`))]);
|
|
27
|
+
}
|
|
28
|
+
function findHfPmSpans(container, kind, rId) {
|
|
29
|
+
return querySlotDescendants(container, kind, rId, "span[data-pm-start][data-pm-end]");
|
|
30
|
+
}
|
|
31
|
+
function findHfPmAnchors(container, kind, rId) {
|
|
32
|
+
return querySlotAnchors(container, kind, rId, "[data-pm-start]");
|
|
33
|
+
}
|
|
34
|
+
function findHfPmAnchor(container, kind, rId, pmStart) {
|
|
35
|
+
if (!Number.isFinite(pmStart)) return null;
|
|
36
|
+
return container.querySelector(`${slotSelector(kind, rId)} [data-pm-start="${String(pmStart)}"]`) ?? container.querySelector(`${associatedSlotSelector(kind, rId)} [data-pm-start="${String(pmStart)}"]`) ?? container.querySelector(`${associatedSlotSelector(kind, rId)}[data-pm-start="${String(pmStart)}"]`);
|
|
37
|
+
}
|
|
38
|
+
function findHfCaretSpan(container, kind, rId, pos) {
|
|
39
|
+
if (!Number.isFinite(pos)) return null;
|
|
40
|
+
const exact = findHfPmAnchor(container, kind, rId, pos);
|
|
41
|
+
if (exact) return {
|
|
42
|
+
element: exact,
|
|
43
|
+
edge: "left"
|
|
44
|
+
};
|
|
45
|
+
const spans = findHfPmSpans(container, kind, rId);
|
|
46
|
+
let best = null;
|
|
47
|
+
for (const span of spans) {
|
|
48
|
+
const startStr = span.dataset["pmStart"];
|
|
49
|
+
const endStr = span.dataset["pmEnd"];
|
|
50
|
+
if (startStr === void 0 || endStr === void 0) continue;
|
|
51
|
+
const start = Number.parseInt(startStr, 10);
|
|
52
|
+
const end = Number.parseInt(endStr, 10);
|
|
53
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) continue;
|
|
54
|
+
if (pos === end) best = {
|
|
55
|
+
element: span,
|
|
56
|
+
edge: "right"
|
|
57
|
+
};
|
|
58
|
+
else if (pos > start && pos < end && !best) best = {
|
|
59
|
+
element: span,
|
|
60
|
+
edge: "left"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return best;
|
|
64
|
+
}
|
|
65
|
+
function hasCloset(value) {
|
|
66
|
+
return typeof value === "object" && value !== null && typeof value.closest === "function";
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Slot-scoped click-to-position mapper. `clickToPositionDom`'s fallback
|
|
70
|
+
* (`findNearestSpan`) is hardcoded to `.layout-page-content` — body — so when
|
|
71
|
+
* the user clicks HF whitespace (right of the text, between lines, etc.),
|
|
72
|
+
* the body fallback can return a body PM position that the HF dispatch then
|
|
73
|
+
* applies to the HF EditorView (clamped) and the caret leaps to an
|
|
74
|
+
* unrelated HF doc position (Codex #487 P2: 21:02 review).
|
|
75
|
+
*
|
|
76
|
+
* Scope everything to the slot element: try the exact-span lookup via
|
|
77
|
+
* `document.elementsFromPoint` filtered to descendants of `slot`; fall back
|
|
78
|
+
* to nearest-span-in-line + start/end edge math within the same slot.
|
|
79
|
+
*/
|
|
80
|
+
function clickToPositionInHfSlot(container, kind, rId, clientX, clientY) {
|
|
81
|
+
const elements = (container instanceof Element ? container.ownerDocument : document).elementsFromPoint(clientX, clientY);
|
|
82
|
+
for (const el of elements) {
|
|
83
|
+
if (!(el instanceof HTMLElement)) continue;
|
|
84
|
+
const slot = findHfSlotForTarget(el);
|
|
85
|
+
if (!slot || slot.kind !== kind || slot.rId !== rId) continue;
|
|
86
|
+
if (el.tagName === "SPAN" && el.dataset["pmStart"] !== void 0 && el.dataset["pmEnd"] !== void 0) return findPositionInSpan(el, clientX, clientY);
|
|
87
|
+
}
|
|
88
|
+
return findNearestSpanInHfSlots(container, kind, rId, clientX, clientY);
|
|
89
|
+
}
|
|
90
|
+
function computeColDist(inside, rect, clientX) {
|
|
91
|
+
if (inside) return 0;
|
|
92
|
+
if (clientX < rect.left) return rect.left - clientX;
|
|
93
|
+
return clientX - rect.right;
|
|
94
|
+
}
|
|
95
|
+
function findNearestSpanInHfSlots(container, kind, rId, clientX, clientY) {
|
|
96
|
+
const spans = findHfPmSpans(container, kind, rId);
|
|
97
|
+
if (spans.length === 0) return null;
|
|
98
|
+
let bestSpan = null;
|
|
99
|
+
let bestRowDist = Number.POSITIVE_INFINITY;
|
|
100
|
+
let bestColDist = Number.POSITIVE_INFINITY;
|
|
101
|
+
let bestInside = false;
|
|
102
|
+
for (const span of spans) {
|
|
103
|
+
const rect = span.getBoundingClientRect();
|
|
104
|
+
const centerY = (rect.top + rect.bottom) / 2;
|
|
105
|
+
const rowDist = Math.abs(clientY - centerY);
|
|
106
|
+
const inside = clientX >= rect.left && clientX <= rect.right;
|
|
107
|
+
const colDist = computeColDist(inside, rect, clientX);
|
|
108
|
+
if (rowDist < bestRowDist || rowDist === bestRowDist && (inside && !bestInside || inside === bestInside && colDist < bestColDist)) {
|
|
109
|
+
bestRowDist = rowDist;
|
|
110
|
+
bestColDist = colDist;
|
|
111
|
+
bestInside = inside;
|
|
112
|
+
bestSpan = span;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!bestSpan) return null;
|
|
116
|
+
if (bestInside) return findPositionInSpan(bestSpan, clientX, clientY);
|
|
117
|
+
if (clientX < bestSpan.getBoundingClientRect().left) {
|
|
118
|
+
const v = bestSpan.dataset["pmStart"];
|
|
119
|
+
return v ? Number(v) : null;
|
|
120
|
+
}
|
|
121
|
+
const v = bestSpan.dataset["pmEnd"];
|
|
122
|
+
return v ? Number(v) : null;
|
|
123
|
+
}
|
|
124
|
+
function findHfSlotForTarget(target) {
|
|
125
|
+
if (!target) return null;
|
|
126
|
+
if (!hasCloset(target)) {
|
|
127
|
+
const owner = target.parentElement;
|
|
128
|
+
if (!owner) return null;
|
|
129
|
+
return findHfSlotForTarget(owner);
|
|
130
|
+
}
|
|
131
|
+
const header = target.closest(".layout-page-header[data-rid]");
|
|
132
|
+
if (header) {
|
|
133
|
+
const rId = header.dataset["rid"];
|
|
134
|
+
if (rId) return {
|
|
135
|
+
kind: "header",
|
|
136
|
+
rId,
|
|
137
|
+
element: header
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const footer = target.closest(".layout-page-footer[data-rid]");
|
|
141
|
+
if (footer) {
|
|
142
|
+
const rId = footer.dataset["rid"];
|
|
143
|
+
if (rId) return {
|
|
144
|
+
kind: "footer",
|
|
145
|
+
rId,
|
|
146
|
+
element: footer
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
const associated = target.closest("[data-hf-slot-kind][data-hf-rid]");
|
|
150
|
+
if (associated) {
|
|
151
|
+
const kind = associated.dataset["hfSlotKind"];
|
|
152
|
+
const rId = associated.dataset["hfRid"];
|
|
153
|
+
if ((kind === "header" || kind === "footer") && rId) return {
|
|
154
|
+
kind,
|
|
155
|
+
rId,
|
|
156
|
+
element: associated
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Resolve only the header/footer KIND of the slot under `target`, whether or
|
|
163
|
+
* not it has an assigned rId yet. `findHfSlotForTarget` matches only a slot
|
|
164
|
+
* that already carries a `data-rid` (an existing HF part); but the painter also
|
|
165
|
+
* renders an EMPTY `.layout-page-header` / `.layout-page-footer` box — the
|
|
166
|
+
* hover-hint and double-click-to-add target — that has no rId. Entering edit
|
|
167
|
+
* mode to *create* a header needs only the kind (the handler mints the part),
|
|
168
|
+
* so this looser resolver matches that empty box too.
|
|
169
|
+
*/
|
|
170
|
+
function findHfSlotKindForTarget(target) {
|
|
171
|
+
if (!target) return null;
|
|
172
|
+
if (!hasCloset(target)) {
|
|
173
|
+
const owner = target.parentElement;
|
|
174
|
+
return owner ? findHfSlotKindForTarget(owner) : null;
|
|
175
|
+
}
|
|
176
|
+
const header = target.closest(".layout-page-header");
|
|
177
|
+
if (header) return {
|
|
178
|
+
kind: "header",
|
|
179
|
+
element: header
|
|
180
|
+
};
|
|
181
|
+
const footer = target.closest(".layout-page-footer");
|
|
182
|
+
if (footer) return {
|
|
183
|
+
kind: "footer",
|
|
184
|
+
element: footer
|
|
185
|
+
};
|
|
186
|
+
const associated = target.closest("[data-hf-slot-kind]");
|
|
187
|
+
if (associated) {
|
|
188
|
+
const kind = associated.dataset["hfSlotKind"];
|
|
189
|
+
if (kind === "header" || kind === "footer") return {
|
|
190
|
+
kind,
|
|
191
|
+
element: associated
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
export { clickToPositionInHfSlot, findHfCaretSpan, findHfPmAnchor, findHfPmAnchors, findHfPmSpans, findHfSlotForTarget, findHfSlotKindForTarget };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ParagraphBlock, ParagraphMeasure } from "../../layout-engine/types.js";
|
|
2
|
+
import { FragmentHit, TableCellHit } from "./hitTest.js";
|
|
3
|
+
|
|
4
|
+
//#region src/layout-bridge/engine/clickToPosition.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Result of click-to-position mapping.
|
|
7
|
+
*/
|
|
8
|
+
type PositionResult = {
|
|
9
|
+
/** ProseMirror document position. */pmPosition: number; /** Character offset within the line (for debugging). */
|
|
10
|
+
charOffset: number; /** Line index within the paragraph. */
|
|
11
|
+
lineIndex: number;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A click in the second half of an astral glyph can resolve to the UTF-16
|
|
15
|
+
* offset between its surrogate pair (`measureRun` emits a 0-width entry for the
|
|
16
|
+
* trailing surrogate). Nudge such an offset forward to the code-point boundary
|
|
17
|
+
* so ProseMirror never receives — or edits inside — a half-pair position.
|
|
18
|
+
*/
|
|
19
|
+
declare function snapPastTrailingSurrogate(text: string, offset: number): number;
|
|
20
|
+
/**
|
|
21
|
+
* Map a click within a paragraph fragment to a PM position.
|
|
22
|
+
*
|
|
23
|
+
* @param fragmentHit - The fragment hit result from hitTestFragment.
|
|
24
|
+
* @returns Position result, or null if mapping fails.
|
|
25
|
+
*/
|
|
26
|
+
declare function clickToPositionInParagraph(fragmentHit: FragmentHit): PositionResult | null;
|
|
27
|
+
/**
|
|
28
|
+
* Map a click within a table cell to a PM position.
|
|
29
|
+
*
|
|
30
|
+
* @param tableCellHit - The table cell hit result from hitTestTableCell.
|
|
31
|
+
* @returns PM position, or null if mapping fails.
|
|
32
|
+
*/
|
|
33
|
+
declare function clickToPositionInTableCell(tableCellHit: TableCellHit): number | null;
|
|
34
|
+
/**
|
|
35
|
+
* Main entry point: Map a click to a PM position.
|
|
36
|
+
*
|
|
37
|
+
* This function takes the result of hit testing and returns the PM position.
|
|
38
|
+
*
|
|
39
|
+
* @param fragmentHit - Fragment hit from hitTestFragment.
|
|
40
|
+
* @param tableCellHit - Optional table cell hit from hitTestTableCell.
|
|
41
|
+
* @returns PM position, or null if mapping fails.
|
|
42
|
+
*/
|
|
43
|
+
declare function clickToPosition(fragmentHit: FragmentHit | null, tableCellHit?: TableCellHit | null): number | null;
|
|
44
|
+
/**
|
|
45
|
+
* Map a PM position to X coordinates within a line (for caret positioning).
|
|
46
|
+
*
|
|
47
|
+
* @param block - The paragraph block.
|
|
48
|
+
* @param measure - The paragraph measure.
|
|
49
|
+
* @param pmPosition - The PM position to map.
|
|
50
|
+
* @param fragmentWidth - Width of the fragment.
|
|
51
|
+
* @returns X coordinate relative to fragment start, or null if not found.
|
|
52
|
+
*/
|
|
53
|
+
declare function positionToX(block: ParagraphBlock, measure: ParagraphMeasure, pmPosition: number, _fragmentWidth: number): {
|
|
54
|
+
x: number;
|
|
55
|
+
lineIndex: number;
|
|
56
|
+
} | null;
|
|
57
|
+
/**
|
|
58
|
+
* Get the bounding rect for a PM position (for caret rendering).
|
|
59
|
+
*/
|
|
60
|
+
declare function getPositionRect(block: ParagraphBlock, measure: ParagraphMeasure, pmPosition: number, fragmentX: number, fragmentY: number, fragmentWidth: number, fromLine: number): {
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
height: number;
|
|
64
|
+
} | null;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { PositionResult, clickToPosition, clickToPositionInParagraph, clickToPositionInTableCell, getPositionRect, positionToX, snapPastTrailingSurrogate };
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { measureRun } from "../../layout-engine/measure/measureProvider.js";
|
|
2
|
+
import { buildRunFontStyle, findCharacterAtX } from "../../layout-engine/measure/measureHelpers.js";
|
|
3
|
+
import { inlineImageBoundingBox } from "../../utils/rotationBoundingBox.js";
|
|
4
|
+
import { measuredLineAdvance, measuredLineContentOffset } from "../../layout-engine/lineFlow.js";
|
|
5
|
+
//#region src/layout-bridge/engine/clickToPosition.ts
|
|
6
|
+
/**
|
|
7
|
+
* Click-to-Position Mapping
|
|
8
|
+
*
|
|
9
|
+
* Maps click coordinates within a layout to ProseMirror document positions.
|
|
10
|
+
* Uses geometry-based calculation with canvas text measurement for accuracy.
|
|
11
|
+
*
|
|
12
|
+
* The main entry point `clickToPosition` takes fragment hit data and local
|
|
13
|
+
* coordinates and returns the PM position at the click point.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Extract FontStyle from a run for measurement.
|
|
17
|
+
*/
|
|
18
|
+
function runToFontStyle(run) {
|
|
19
|
+
return buildRunFontStyle(run, "Arial", 12);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A click in the second half of an astral glyph can resolve to the UTF-16
|
|
23
|
+
* offset between its surrogate pair (`measureRun` emits a 0-width entry for the
|
|
24
|
+
* trailing surrogate). Nudge such an offset forward to the code-point boundary
|
|
25
|
+
* so ProseMirror never receives — or edits inside — a half-pair position.
|
|
26
|
+
*/
|
|
27
|
+
function snapPastTrailingSurrogate(text, offset) {
|
|
28
|
+
const codeUnit = offset < text.length ? text.codePointAt(offset) : void 0;
|
|
29
|
+
if (codeUnit !== void 0 && codeUnit >= 56320 && codeUnit <= 57343) return offset + 1;
|
|
30
|
+
return offset;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Slice the runs that are part of a specific line.
|
|
34
|
+
* Returns only the text portions that belong to the line.
|
|
35
|
+
*/
|
|
36
|
+
function sliceRunsForLine(block, line) {
|
|
37
|
+
const result = [];
|
|
38
|
+
for (let runIndex = line.fromRun; runIndex <= line.toRun && runIndex < block.runs.length; runIndex++) {
|
|
39
|
+
const run = block.runs[runIndex];
|
|
40
|
+
if (!run) continue;
|
|
41
|
+
if (run.kind === "tab" || run.kind === "image" || run.kind === "lineBreak") {
|
|
42
|
+
result.push(run);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (run.kind === "text") {
|
|
46
|
+
const text = run.text;
|
|
47
|
+
const isFirstRun = runIndex === line.fromRun;
|
|
48
|
+
const isLastRun = runIndex === line.toRun;
|
|
49
|
+
if (isFirstRun || isLastRun) {
|
|
50
|
+
const start = isFirstRun ? line.fromChar : 0;
|
|
51
|
+
const end = isLastRun ? line.toChar : text.length;
|
|
52
|
+
const slice = text.slice(start, end);
|
|
53
|
+
if (slice.length > 0) result.push({
|
|
54
|
+
...run,
|
|
55
|
+
text: slice
|
|
56
|
+
});
|
|
57
|
+
} else result.push(run);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Calculate the PM position range for a line.
|
|
64
|
+
*/
|
|
65
|
+
function computeLinePmRange(block, line) {
|
|
66
|
+
let pmStart;
|
|
67
|
+
let pmEnd;
|
|
68
|
+
const blockPmStart = block.pmStart ?? 0;
|
|
69
|
+
let charOffset = 0;
|
|
70
|
+
for (let runIndex = 0; runIndex < block.runs.length && runIndex <= line.toRun; runIndex++) {
|
|
71
|
+
const run = block.runs[runIndex];
|
|
72
|
+
if (!run) continue;
|
|
73
|
+
if (runIndex < line.fromRun) {
|
|
74
|
+
if (run.kind === "text") charOffset += run.text.length;
|
|
75
|
+
else if (run.kind === "tab" || run.kind === "lineBreak") charOffset += 1;
|
|
76
|
+
else if (run.kind === "image") charOffset += 1;
|
|
77
|
+
} else if (runIndex === line.fromRun) {
|
|
78
|
+
charOffset += line.fromChar;
|
|
79
|
+
pmStart = blockPmStart + charOffset;
|
|
80
|
+
if (run.kind === "text") charOffset = line.fromChar;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (pmStart !== void 0) {
|
|
84
|
+
let lineLength = 0;
|
|
85
|
+
for (let runIndex = line.fromRun; runIndex <= line.toRun && runIndex < block.runs.length; runIndex++) {
|
|
86
|
+
const run = block.runs[runIndex];
|
|
87
|
+
if (!run) continue;
|
|
88
|
+
if (run.kind === "text") {
|
|
89
|
+
const text = run.text;
|
|
90
|
+
const start = runIndex === line.fromRun ? line.fromChar : 0;
|
|
91
|
+
const end = runIndex === line.toRun ? line.toChar : text.length;
|
|
92
|
+
lineLength += end - start;
|
|
93
|
+
} else if (run.kind === "tab" || run.kind === "lineBreak") lineLength += 1;
|
|
94
|
+
else if (run.kind === "image") lineLength += 1;
|
|
95
|
+
}
|
|
96
|
+
pmEnd = pmStart + lineLength;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
pmStart,
|
|
100
|
+
pmEnd
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Find which line contains a Y coordinate within a fragment.
|
|
105
|
+
*
|
|
106
|
+
* @param measure - The paragraph measure with lines.
|
|
107
|
+
* @param localY - Y coordinate relative to fragment top.
|
|
108
|
+
* @param fromLine - First line index in the fragment.
|
|
109
|
+
* @param toLine - Last line index (exclusive) in the fragment.
|
|
110
|
+
* @returns Line index, or null if not found.
|
|
111
|
+
*/
|
|
112
|
+
function findLineAtY(measure, localY, fromLine, toLine) {
|
|
113
|
+
let y = 0;
|
|
114
|
+
for (let lineIndex = fromLine; lineIndex < toLine && lineIndex < measure.lines.length; lineIndex++) {
|
|
115
|
+
const line = measure.lines[lineIndex];
|
|
116
|
+
const lineAdvance = measuredLineAdvance(line);
|
|
117
|
+
if (localY >= y && localY < y + lineAdvance) return lineIndex;
|
|
118
|
+
y += lineAdvance;
|
|
119
|
+
}
|
|
120
|
+
if (toLine > fromLine) return Math.min(toLine - 1, measure.lines.length - 1);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Find the character position at an X coordinate within a line.
|
|
125
|
+
*
|
|
126
|
+
* Uses canvas text measurement for pixel-perfect accuracy.
|
|
127
|
+
*
|
|
128
|
+
* @param block - The paragraph block.
|
|
129
|
+
* @param line - The measured line.
|
|
130
|
+
* @param x - X coordinate relative to the line's start position.
|
|
131
|
+
* @param availableWidth - Available width for alignment calculations.
|
|
132
|
+
* @returns Character offset and PM position.
|
|
133
|
+
*/
|
|
134
|
+
function findCharacterInLine(block, line, x, availableWidth) {
|
|
135
|
+
const { pmStart, pmEnd } = computeLinePmRange(block, line);
|
|
136
|
+
if (pmStart === void 0 || pmEnd === void 0) return {
|
|
137
|
+
charOffset: 0,
|
|
138
|
+
pmPosition: block.pmStart ?? 0
|
|
139
|
+
};
|
|
140
|
+
const alignment = block.attrs?.alignment ?? "left";
|
|
141
|
+
let alignmentOffset = 0;
|
|
142
|
+
if (alignment === "center") alignmentOffset = Math.max(0, (availableWidth - line.width) / 2);
|
|
143
|
+
else if (alignment === "right") alignmentOffset = Math.max(0, availableWidth - line.width);
|
|
144
|
+
const adjustedX = Math.max(0, x - alignmentOffset);
|
|
145
|
+
if (adjustedX <= 0) return {
|
|
146
|
+
charOffset: 0,
|
|
147
|
+
pmPosition: pmStart
|
|
148
|
+
};
|
|
149
|
+
const runs = sliceRunsForLine(block, line);
|
|
150
|
+
if (runs.length === 0) return {
|
|
151
|
+
charOffset: 0,
|
|
152
|
+
pmPosition: pmStart
|
|
153
|
+
};
|
|
154
|
+
let currentX = 0;
|
|
155
|
+
let currentCharOffset = 0;
|
|
156
|
+
for (const run of runs) {
|
|
157
|
+
if (run.kind === "tab") {
|
|
158
|
+
const tabWidth = run.width ?? 48;
|
|
159
|
+
const runEndX = currentX + tabWidth;
|
|
160
|
+
if (adjustedX <= runEndX) {
|
|
161
|
+
if (adjustedX < currentX + tabWidth / 2) return {
|
|
162
|
+
charOffset: currentCharOffset,
|
|
163
|
+
pmPosition: pmStart + currentCharOffset
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
charOffset: currentCharOffset + 1,
|
|
167
|
+
pmPosition: pmStart + currentCharOffset + 1
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
currentX = runEndX;
|
|
171
|
+
currentCharOffset += 1;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (run.kind === "image") {
|
|
175
|
+
const imageWidth = inlineImageBoundingBox(run).width;
|
|
176
|
+
const runEndX = currentX + imageWidth;
|
|
177
|
+
if (adjustedX <= runEndX) {
|
|
178
|
+
if (adjustedX < currentX + imageWidth / 2) return {
|
|
179
|
+
charOffset: currentCharOffset,
|
|
180
|
+
pmPosition: pmStart + currentCharOffset
|
|
181
|
+
};
|
|
182
|
+
return {
|
|
183
|
+
charOffset: currentCharOffset + 1,
|
|
184
|
+
pmPosition: pmStart + currentCharOffset + 1
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
currentX = runEndX;
|
|
188
|
+
currentCharOffset += 1;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (run.kind === "lineBreak") {
|
|
192
|
+
if (adjustedX >= currentX) return {
|
|
193
|
+
charOffset: currentCharOffset,
|
|
194
|
+
pmPosition: pmStart + currentCharOffset
|
|
195
|
+
};
|
|
196
|
+
currentCharOffset += 1;
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (run.kind === "text") {
|
|
200
|
+
const text = run.text;
|
|
201
|
+
if (text.length === 0) continue;
|
|
202
|
+
const measurement = measureRun(text, runToFontStyle(run));
|
|
203
|
+
const runEndX = currentX + measurement.width;
|
|
204
|
+
if (adjustedX <= runEndX) {
|
|
205
|
+
const charInRun = snapPastTrailingSurrogate(text, findCharacterAtX(adjustedX - currentX, measurement.charWidths));
|
|
206
|
+
const charOffset = currentCharOffset + charInRun;
|
|
207
|
+
return {
|
|
208
|
+
charOffset,
|
|
209
|
+
pmPosition: pmStart + charOffset
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
currentX = runEndX;
|
|
213
|
+
currentCharOffset += text.length;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
charOffset: pmEnd - pmStart,
|
|
218
|
+
pmPosition: pmEnd
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Map a click within a paragraph fragment to a PM position.
|
|
223
|
+
*
|
|
224
|
+
* @param fragmentHit - The fragment hit result from hitTestFragment.
|
|
225
|
+
* @returns Position result, or null if mapping fails.
|
|
226
|
+
*/
|
|
227
|
+
function clickToPositionInParagraph(fragmentHit) {
|
|
228
|
+
const { fragment, block, measure, localX, localY } = fragmentHit;
|
|
229
|
+
if (fragment.kind !== "paragraph") return null;
|
|
230
|
+
if (block.kind !== "paragraph") return null;
|
|
231
|
+
if (measure.kind !== "paragraph") return null;
|
|
232
|
+
const paragraphFragment = fragment;
|
|
233
|
+
const paragraphBlock = block;
|
|
234
|
+
const paragraphMeasure = measure;
|
|
235
|
+
const lineIndex = findLineAtY(paragraphMeasure, localY, paragraphFragment.fromLine, paragraphFragment.toLine);
|
|
236
|
+
if (lineIndex === null) return null;
|
|
237
|
+
const line = paragraphMeasure.lines[lineIndex];
|
|
238
|
+
if (!line) return null;
|
|
239
|
+
const indent = paragraphBlock.attrs?.indent;
|
|
240
|
+
const indentLeft = indent?.left ?? 0;
|
|
241
|
+
const indentRight = indent?.right ?? 0;
|
|
242
|
+
const availableWidth = Math.max(0, fragment.width - indentLeft - indentRight);
|
|
243
|
+
const { charOffset, pmPosition } = findCharacterInLine(paragraphBlock, line, localX - indentLeft, availableWidth);
|
|
244
|
+
return {
|
|
245
|
+
pmPosition,
|
|
246
|
+
charOffset,
|
|
247
|
+
lineIndex
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Map a click within a table cell to a PM position.
|
|
252
|
+
*
|
|
253
|
+
* @param tableCellHit - The table cell hit result from hitTestTableCell.
|
|
254
|
+
* @returns PM position, or null if mapping fails.
|
|
255
|
+
*/
|
|
256
|
+
function clickToPositionInTableCell(tableCellHit) {
|
|
257
|
+
const { cellBlock, cellMeasure, cellLocalX, cellLocalY } = tableCellHit;
|
|
258
|
+
if (!cellBlock || !cellMeasure) return null;
|
|
259
|
+
return clickToPositionInParagraph({
|
|
260
|
+
fragment: {
|
|
261
|
+
kind: "paragraph",
|
|
262
|
+
blockId: cellBlock.id,
|
|
263
|
+
x: 0,
|
|
264
|
+
y: 0,
|
|
265
|
+
width: getMaxLineWidth(cellMeasure.lines, 100),
|
|
266
|
+
fromLine: 0,
|
|
267
|
+
toLine: cellMeasure.lines.length,
|
|
268
|
+
height: cellMeasure.totalHeight
|
|
269
|
+
},
|
|
270
|
+
block: cellBlock,
|
|
271
|
+
measure: cellMeasure,
|
|
272
|
+
pageIndex: tableCellHit.pageIndex,
|
|
273
|
+
localX: cellLocalX,
|
|
274
|
+
localY: cellLocalY
|
|
275
|
+
})?.pmPosition ?? null;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Main entry point: Map a click to a PM position.
|
|
279
|
+
*
|
|
280
|
+
* This function takes the result of hit testing and returns the PM position.
|
|
281
|
+
*
|
|
282
|
+
* @param fragmentHit - Fragment hit from hitTestFragment.
|
|
283
|
+
* @param tableCellHit - Optional table cell hit from hitTestTableCell.
|
|
284
|
+
* @returns PM position, or null if mapping fails.
|
|
285
|
+
*/
|
|
286
|
+
function clickToPosition(fragmentHit, tableCellHit) {
|
|
287
|
+
if (tableCellHit) return clickToPositionInTableCell(tableCellHit);
|
|
288
|
+
if (!fragmentHit) return null;
|
|
289
|
+
const { fragment } = fragmentHit;
|
|
290
|
+
if (fragment.kind === "paragraph") return clickToPositionInParagraph(fragmentHit)?.pmPosition ?? null;
|
|
291
|
+
if (fragment.kind === "image") return fragment.pmStart ?? null;
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Map a PM position to X coordinates within a line (for caret positioning).
|
|
296
|
+
*
|
|
297
|
+
* @param block - The paragraph block.
|
|
298
|
+
* @param measure - The paragraph measure.
|
|
299
|
+
* @param pmPosition - The PM position to map.
|
|
300
|
+
* @param fragmentWidth - Width of the fragment.
|
|
301
|
+
* @returns X coordinate relative to fragment start, or null if not found.
|
|
302
|
+
*/
|
|
303
|
+
function positionToX(block, measure, pmPosition, _fragmentWidth) {
|
|
304
|
+
const blockPmStart = block.pmStart ?? 0;
|
|
305
|
+
const blockPmEnd = block.pmEnd ?? blockPmStart;
|
|
306
|
+
if (pmPosition < blockPmStart || pmPosition > blockPmEnd) return null;
|
|
307
|
+
const positionOffset = pmPosition - blockPmStart;
|
|
308
|
+
for (let lineIndex = 0; lineIndex < measure.lines.length; lineIndex++) {
|
|
309
|
+
const line = measure.lines[lineIndex];
|
|
310
|
+
const { pmStart: linePmStart, pmEnd: linePmEnd } = computeLinePmRange(block, line);
|
|
311
|
+
if (linePmStart === void 0 || linePmEnd === void 0) continue;
|
|
312
|
+
const lineStartOffset = linePmStart - blockPmStart;
|
|
313
|
+
const lineEndOffset = linePmEnd - blockPmStart;
|
|
314
|
+
if (positionOffset >= lineStartOffset && positionOffset <= lineEndOffset) {
|
|
315
|
+
const offsetInLine = positionOffset - lineStartOffset;
|
|
316
|
+
const runs = sliceRunsForLine(block, line);
|
|
317
|
+
let x = 0;
|
|
318
|
+
let charsProcessed = 0;
|
|
319
|
+
for (const run of runs) if (run.kind === "tab") {
|
|
320
|
+
if (offsetInLine <= charsProcessed + 1) {
|
|
321
|
+
if (offsetInLine <= charsProcessed) return {
|
|
322
|
+
x,
|
|
323
|
+
lineIndex
|
|
324
|
+
};
|
|
325
|
+
return {
|
|
326
|
+
x: x + (run.width ?? 48),
|
|
327
|
+
lineIndex
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
x += run.width ?? 48;
|
|
331
|
+
charsProcessed += 1;
|
|
332
|
+
} else if (run.kind === "image") {
|
|
333
|
+
if (offsetInLine <= charsProcessed + 1) {
|
|
334
|
+
if (offsetInLine <= charsProcessed) return {
|
|
335
|
+
x,
|
|
336
|
+
lineIndex
|
|
337
|
+
};
|
|
338
|
+
return {
|
|
339
|
+
x: x + run.width,
|
|
340
|
+
lineIndex
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
x += run.width;
|
|
344
|
+
charsProcessed += 1;
|
|
345
|
+
} else if (run.kind === "lineBreak") {
|
|
346
|
+
if (offsetInLine <= charsProcessed) return {
|
|
347
|
+
x,
|
|
348
|
+
lineIndex
|
|
349
|
+
};
|
|
350
|
+
charsProcessed += 1;
|
|
351
|
+
} else if (run.kind === "text") {
|
|
352
|
+
const text = run.text;
|
|
353
|
+
if (offsetInLine <= charsProcessed + text.length) {
|
|
354
|
+
const charInRun = offsetInLine - charsProcessed;
|
|
355
|
+
const style = runToFontStyle(run);
|
|
356
|
+
const measurement = measureRun(text.slice(0, charInRun), style);
|
|
357
|
+
return {
|
|
358
|
+
x: x + measurement.width,
|
|
359
|
+
lineIndex
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const measurement = measureRun(text, runToFontStyle(run));
|
|
363
|
+
x += measurement.width;
|
|
364
|
+
charsProcessed += text.length;
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
x,
|
|
368
|
+
lineIndex
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
const getMaxLineWidth = (lines, fallback) => {
|
|
375
|
+
let maxWidth = fallback;
|
|
376
|
+
for (const line of lines) maxWidth = Math.max(maxWidth, line.width);
|
|
377
|
+
return maxWidth;
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Get the bounding rect for a PM position (for caret rendering).
|
|
381
|
+
*/
|
|
382
|
+
function getPositionRect(block, measure, pmPosition, fragmentX, fragmentY, fragmentWidth, fromLine) {
|
|
383
|
+
const result = positionToX(block, measure, pmPosition, fragmentWidth);
|
|
384
|
+
if (!result) return null;
|
|
385
|
+
const alignment = block.attrs?.alignment ?? "left";
|
|
386
|
+
const indent = block.attrs?.indent;
|
|
387
|
+
const indentLeft = indent?.left ?? 0;
|
|
388
|
+
const indentRight = indent?.right ?? 0;
|
|
389
|
+
const availableWidth = Math.max(0, fragmentWidth - indentLeft - indentRight);
|
|
390
|
+
const line = measure.lines[result.lineIndex];
|
|
391
|
+
if (!line) return null;
|
|
392
|
+
let alignmentOffset = 0;
|
|
393
|
+
if (alignment === "center") alignmentOffset = Math.max(0, (availableWidth - line.width) / 2);
|
|
394
|
+
else if (alignment === "right") alignmentOffset = Math.max(0, availableWidth - line.width);
|
|
395
|
+
const lineY = measuredLineContentOffset(measure.lines, fromLine, result.lineIndex);
|
|
396
|
+
return {
|
|
397
|
+
x: fragmentX + indentLeft + alignmentOffset + result.x,
|
|
398
|
+
y: fragmentY + lineY,
|
|
399
|
+
height: line.lineHeight
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
//#endregion
|
|
403
|
+
export { clickToPosition, clickToPositionInParagraph, clickToPositionInTableCell, getPositionRect, positionToX, snapPastTrailingSurrogate };
|