@stll/folio-core 0.0.1-placeholder.0 → 0.1.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/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 +58 -0
- package/dist/types/block-id.js +61 -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,195 @@
|
|
|
1
|
+
import { deriveBlockId } from "../types/block-id.js";
|
|
2
|
+
import { buildCleanBlockText } from "./clean-text.js";
|
|
3
|
+
//#region src/ai-edits/snapshot.ts
|
|
4
|
+
const normalizeFolioAIBlockText = (text) => text.replace(/\s+/gu, " ").trim();
|
|
5
|
+
const hashFolioAIBlockText = (text) => {
|
|
6
|
+
let hash = 5381;
|
|
7
|
+
for (const character of text) hash = (hash * 33 + (character.codePointAt(0) ?? 0)) % 2147483647;
|
|
8
|
+
return `h${hash.toString(36)}`;
|
|
9
|
+
};
|
|
10
|
+
const createFolioAIEditSnapshot = (doc) => {
|
|
11
|
+
const draftBlocks = [];
|
|
12
|
+
const hashCounts = /* @__PURE__ */ new Map();
|
|
13
|
+
const usedBlockIds = /* @__PURE__ */ new Set();
|
|
14
|
+
let blockIndex = 0;
|
|
15
|
+
doc.descendants((node, pos) => {
|
|
16
|
+
if (!node.isTextblock) return;
|
|
17
|
+
const { text } = buildCleanBlockText(node, pos);
|
|
18
|
+
const normalizedText = normalizeFolioAIBlockText(text);
|
|
19
|
+
if (normalizedText.length === 0) return;
|
|
20
|
+
const textHash = hashFolioAIBlockText(normalizedText);
|
|
21
|
+
hashCounts.set(textHash, (hashCounts.get(textHash) ?? 0) + 1);
|
|
22
|
+
blockIndex++;
|
|
23
|
+
const paraIdAttr = node.attrs["paraId"];
|
|
24
|
+
const id = deriveBlockId({
|
|
25
|
+
paraId: typeof paraIdAttr === "string" && paraIdAttr.length > 0 ? paraIdAttr : null,
|
|
26
|
+
index: blockIndex,
|
|
27
|
+
taken: usedBlockIds
|
|
28
|
+
});
|
|
29
|
+
usedBlockIds.add(id);
|
|
30
|
+
const kind = getBlockKind(node);
|
|
31
|
+
const displayLabel = getDisplayLabel(node);
|
|
32
|
+
const styleId = getStyleId(node);
|
|
33
|
+
const previewRuns = getPreviewRuns(node);
|
|
34
|
+
draftBlocks.push({
|
|
35
|
+
block: {
|
|
36
|
+
id,
|
|
37
|
+
kind,
|
|
38
|
+
text,
|
|
39
|
+
...displayLabel !== void 0 && { displayLabel },
|
|
40
|
+
...styleId !== void 0 && { styleId },
|
|
41
|
+
...previewRuns !== void 0 && { previewRuns }
|
|
42
|
+
},
|
|
43
|
+
anchor: {
|
|
44
|
+
id,
|
|
45
|
+
from: pos,
|
|
46
|
+
to: pos + node.nodeSize,
|
|
47
|
+
text,
|
|
48
|
+
normalizedText,
|
|
49
|
+
textHash
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
const blocks = [];
|
|
54
|
+
const anchors = {};
|
|
55
|
+
for (const draft of draftBlocks) {
|
|
56
|
+
blocks.push(draft.block);
|
|
57
|
+
anchors[draft.block.id] = {
|
|
58
|
+
...draft.anchor,
|
|
59
|
+
hashOccurrenceCount: hashCounts.get(draft.anchor.textHash) ?? 0
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
blocks,
|
|
64
|
+
anchors
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const getBlockKind = (node) => {
|
|
68
|
+
const listMarker = node.attrs["listMarker"];
|
|
69
|
+
const numPr = node.attrs["numPr"];
|
|
70
|
+
if (typeof listMarker === "string" && listMarker.trim().length > 0 || numPr !== void 0 && numPr !== null) return "listItem";
|
|
71
|
+
const outlineLevel = node.attrs["outlineLevel"];
|
|
72
|
+
if (typeof outlineLevel === "number" && outlineLevel >= 0) return "heading";
|
|
73
|
+
return "paragraph";
|
|
74
|
+
};
|
|
75
|
+
const getDisplayLabel = (node) => {
|
|
76
|
+
const listMarker = node.attrs["listMarker"];
|
|
77
|
+
if (typeof listMarker === "string" && listMarker.trim().length > 0) return listMarker.trim();
|
|
78
|
+
const styleId = node.attrs["styleId"];
|
|
79
|
+
if (typeof styleId === "string" && /^heading/iu.test(styleId)) return styleId;
|
|
80
|
+
};
|
|
81
|
+
const getStyleId = (node) => {
|
|
82
|
+
const styleId = node.attrs["styleId"];
|
|
83
|
+
return typeof styleId === "string" && styleId.length > 0 ? styleId : void 0;
|
|
84
|
+
};
|
|
85
|
+
const DELETION_MARK = "deletion";
|
|
86
|
+
const getPreviewRuns = (node) => {
|
|
87
|
+
const runs = [];
|
|
88
|
+
const defaultStyle = getDefaultPreviewRunStyle(node);
|
|
89
|
+
node.descendants((child) => {
|
|
90
|
+
if (!child.isText || child.text === void 0) return true;
|
|
91
|
+
if (child.marks.some((mark) => mark.type.name === DELETION_MARK)) return false;
|
|
92
|
+
const style = getPreviewRunStyle(child.marks, defaultStyle);
|
|
93
|
+
const previous = runs.at(-1);
|
|
94
|
+
if (previous && samePreviewRunStyle(previous, style)) {
|
|
95
|
+
previous.text += child.text;
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
runs.push({
|
|
99
|
+
text: child.text,
|
|
100
|
+
...style
|
|
101
|
+
});
|
|
102
|
+
return false;
|
|
103
|
+
});
|
|
104
|
+
if (runs.every(isUnstyledPreviewRun)) return;
|
|
105
|
+
return runs;
|
|
106
|
+
};
|
|
107
|
+
const getDefaultPreviewRunStyle = (node) => {
|
|
108
|
+
const formatting = node.attrs["defaultTextFormatting"];
|
|
109
|
+
if (typeof formatting !== "object" || formatting === null) return {};
|
|
110
|
+
return {
|
|
111
|
+
...getBooleanTextFormatting(formatting),
|
|
112
|
+
...getFontSizeTextFormatting(formatting),
|
|
113
|
+
...getFontFamilyTextFormatting(formatting),
|
|
114
|
+
...getColorTextFormatting(formatting)
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const getPreviewRunStyle = (marks, defaultStyle) => {
|
|
118
|
+
const style = { ...defaultStyle };
|
|
119
|
+
for (const mark of marks) switch (mark.type.name) {
|
|
120
|
+
case "bold":
|
|
121
|
+
style.bold = true;
|
|
122
|
+
break;
|
|
123
|
+
case "italic":
|
|
124
|
+
style.italic = true;
|
|
125
|
+
break;
|
|
126
|
+
case "underline":
|
|
127
|
+
if (isUnderlineEnabled(mark.attrs["style"])) style.underline = true;
|
|
128
|
+
break;
|
|
129
|
+
case "strike":
|
|
130
|
+
style.strike = true;
|
|
131
|
+
break;
|
|
132
|
+
case "fontSize": {
|
|
133
|
+
const size = Number(mark.attrs["size"]);
|
|
134
|
+
if (Number.isFinite(size) && size > 0) style.fontSizePt = size / 2;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "fontFamily": {
|
|
138
|
+
const fontFamily = getFontFamilyFromAttrs(mark.attrs);
|
|
139
|
+
if (fontFamily !== void 0) style.fontFamily = fontFamily;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case "textColor": {
|
|
143
|
+
const color = getColorFromAttrs(mark.attrs);
|
|
144
|
+
if (color !== void 0) style.color = color;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
default: break;
|
|
148
|
+
}
|
|
149
|
+
return style;
|
|
150
|
+
};
|
|
151
|
+
const getBooleanTextFormatting = (formatting) => ({
|
|
152
|
+
...Reflect.get(formatting, "bold") === true && { bold: true },
|
|
153
|
+
...Reflect.get(formatting, "italic") === true && { italic: true },
|
|
154
|
+
...isUnderlineEnabled(Reflect.get(formatting, "underline")) && { underline: true },
|
|
155
|
+
...Reflect.get(formatting, "strike") === true && { strike: true }
|
|
156
|
+
});
|
|
157
|
+
const isUnderlineEnabled = (underline) => {
|
|
158
|
+
if (underline === void 0 || underline === null || underline === false) return false;
|
|
159
|
+
if (underline === true) return true;
|
|
160
|
+
if (typeof underline === "string") return underline !== "none";
|
|
161
|
+
if (typeof underline !== "object") return false;
|
|
162
|
+
return Reflect.get(underline, "style") !== "none";
|
|
163
|
+
};
|
|
164
|
+
const getFontSizeTextFormatting = (formatting) => {
|
|
165
|
+
const fontSize = Number(Reflect.get(formatting, "fontSize"));
|
|
166
|
+
if (!Number.isFinite(fontSize) || fontSize <= 0) return {};
|
|
167
|
+
return { fontSizePt: fontSize / 2 };
|
|
168
|
+
};
|
|
169
|
+
const getFontFamilyTextFormatting = (formatting) => {
|
|
170
|
+
const fontFamilyValue = Reflect.get(formatting, "fontFamily");
|
|
171
|
+
if (typeof fontFamilyValue !== "object" || fontFamilyValue === null) return {};
|
|
172
|
+
const fontFamily = getFontFamilyFromAttrs(fontFamilyValue);
|
|
173
|
+
return fontFamily === void 0 ? {} : { fontFamily };
|
|
174
|
+
};
|
|
175
|
+
const getColorTextFormatting = (formatting) => {
|
|
176
|
+
const colorValue = Reflect.get(formatting, "color");
|
|
177
|
+
if (typeof colorValue !== "object" || colorValue === null) return {};
|
|
178
|
+
const color = getColorFromAttrs(colorValue);
|
|
179
|
+
return color === void 0 ? {} : { color };
|
|
180
|
+
};
|
|
181
|
+
const getFontFamilyFromAttrs = (attrs) => {
|
|
182
|
+
const ascii = Reflect.get(attrs, "ascii");
|
|
183
|
+
if (typeof ascii === "string" && ascii.length > 0) return ascii;
|
|
184
|
+
const hAnsi = Reflect.get(attrs, "hAnsi");
|
|
185
|
+
if (typeof hAnsi === "string" && hAnsi.length > 0) return hAnsi;
|
|
186
|
+
};
|
|
187
|
+
const getColorFromAttrs = (attrs) => {
|
|
188
|
+
const rgb = Reflect.get(attrs, "rgb") ?? Reflect.get(attrs, "val");
|
|
189
|
+
if (typeof rgb !== "string" || !/^[0-9a-fA-F]{6}$/u.test(rgb)) return;
|
|
190
|
+
return `#${rgb}`;
|
|
191
|
+
};
|
|
192
|
+
const samePreviewRunStyle = (run, style) => run.bold === style.bold && run.italic === style.italic && run.underline === style.underline && run.strike === style.strike && run.fontFamily === style.fontFamily && run.fontSizePt === style.fontSizePt && run.color === style.color;
|
|
193
|
+
const isUnstyledPreviewRun = ({ bold, italic, underline, strike, fontFamily, fontSizePt, color }) => bold === void 0 && italic === void 0 && underline === void 0 && strike === void 0 && fontFamily === void 0 && fontSizePt === void 0 && color === void 0;
|
|
194
|
+
//#endregion
|
|
195
|
+
export { createFolioAIEditSnapshot, hashFolioAIBlockText, normalizeFolioAIBlockText };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
//#region src/ai-edits/types.d.ts
|
|
2
|
+
type FolioAIBlockKind = "heading" | "listItem" | "paragraph";
|
|
3
|
+
type FolioAIBlockPreviewRun = {
|
|
4
|
+
text: string;
|
|
5
|
+
bold?: boolean;
|
|
6
|
+
italic?: boolean;
|
|
7
|
+
underline?: boolean;
|
|
8
|
+
strike?: boolean;
|
|
9
|
+
fontFamily?: string;
|
|
10
|
+
fontSizePt?: number;
|
|
11
|
+
color?: string;
|
|
12
|
+
};
|
|
13
|
+
type FolioAIBlock = {
|
|
14
|
+
id: string;
|
|
15
|
+
kind: FolioAIBlockKind;
|
|
16
|
+
text: string;
|
|
17
|
+
displayLabel?: string;
|
|
18
|
+
styleId?: string;
|
|
19
|
+
previewRuns?: FolioAIBlockPreviewRun[];
|
|
20
|
+
};
|
|
21
|
+
type FolioAIEditSnapshot = {
|
|
22
|
+
blocks: FolioAIBlock[];
|
|
23
|
+
anchors: Record<string, FolioAIBlockAnchor>;
|
|
24
|
+
};
|
|
25
|
+
type FolioAIBlockAnchor = {
|
|
26
|
+
id: string;
|
|
27
|
+
from: number;
|
|
28
|
+
to: number;
|
|
29
|
+
text: string;
|
|
30
|
+
normalizedText: string;
|
|
31
|
+
textHash: string;
|
|
32
|
+
hashOccurrenceCount: number;
|
|
33
|
+
};
|
|
34
|
+
type FolioAIComment = {
|
|
35
|
+
text: string;
|
|
36
|
+
};
|
|
37
|
+
type FolioAIEditSeverity = "low" | "medium" | "high";
|
|
38
|
+
/**
|
|
39
|
+
* Optional review metadata attached to an AI-authored operation.
|
|
40
|
+
* Set by the model when performing a structured review (e.g.
|
|
41
|
+
* `severity: "high"`, `area: "Penalty"`); absent for direct edits.
|
|
42
|
+
* Both fields are independent — either or both may be set.
|
|
43
|
+
*/
|
|
44
|
+
type FolioAIEditReviewMeta = {
|
|
45
|
+
severity?: FolioAIEditSeverity;
|
|
46
|
+
area?: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* A party in an `insertSignatureTable` op. Mirrors the
|
|
50
|
+
* `signatureTable` helper in `docx-core/legal-source/compile.ts`:
|
|
51
|
+
* name is rendered bold; `signatory` and `title` are optional
|
|
52
|
+
* lines under the signature rule (title in italics).
|
|
53
|
+
*/
|
|
54
|
+
type FolioAISignatureParty = {
|
|
55
|
+
name: string;
|
|
56
|
+
signatory?: string;
|
|
57
|
+
title?: string;
|
|
58
|
+
};
|
|
59
|
+
type FolioAIEditOperation = FolioAIEditReviewMeta & ({
|
|
60
|
+
id: string;
|
|
61
|
+
type: "replaceInBlock";
|
|
62
|
+
blockId: string;
|
|
63
|
+
find: string;
|
|
64
|
+
replace: string;
|
|
65
|
+
comment?: FolioAIComment;
|
|
66
|
+
} | {
|
|
67
|
+
id: string;
|
|
68
|
+
type: "insertAfterBlock" | "insertBeforeBlock";
|
|
69
|
+
blockId: string;
|
|
70
|
+
text: string;
|
|
71
|
+
inheritFormatting?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* When true, mark the inserted paragraph with
|
|
74
|
+
* `pageBreakBefore` so the layout engine starts it on a
|
|
75
|
+
* new page. Use for explicit page-break inserts.
|
|
76
|
+
*/
|
|
77
|
+
pageBreakBefore?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Override the paragraph `styleId` attr of the inserted
|
|
80
|
+
* block (e.g. `ClauseHeading1`). When omitted the inserted
|
|
81
|
+
* block inherits the source block's styleId via
|
|
82
|
+
* `inheritFormatting`.
|
|
83
|
+
*/
|
|
84
|
+
styleId?: string;
|
|
85
|
+
comment?: FolioAIComment;
|
|
86
|
+
} | {
|
|
87
|
+
id: string;
|
|
88
|
+
type: "replaceBlock";
|
|
89
|
+
blockId: string;
|
|
90
|
+
text: string;
|
|
91
|
+
preserveFormatting?: boolean;
|
|
92
|
+
styleId?: string;
|
|
93
|
+
comment?: FolioAIComment;
|
|
94
|
+
} | {
|
|
95
|
+
id: string;
|
|
96
|
+
type: "deleteBlock";
|
|
97
|
+
blockId: string;
|
|
98
|
+
comment?: FolioAIComment;
|
|
99
|
+
} | {
|
|
100
|
+
id: string;
|
|
101
|
+
type: "commentOnBlock";
|
|
102
|
+
blockId: string;
|
|
103
|
+
quote?: string;
|
|
104
|
+
comment: FolioAIComment;
|
|
105
|
+
} | {
|
|
106
|
+
id: string;
|
|
107
|
+
type: "insertSignatureTable";
|
|
108
|
+
blockId: string;
|
|
109
|
+
/**
|
|
110
|
+
* Position the table after the anchor block (default) or
|
|
111
|
+
* before it. Always inserts as a sibling at the document
|
|
112
|
+
* level — no nested-table support.
|
|
113
|
+
*/
|
|
114
|
+
position?: "after" | "before";
|
|
115
|
+
parties: FolioAISignatureParty[];
|
|
116
|
+
comment?: FolioAIComment;
|
|
117
|
+
});
|
|
118
|
+
type FolioAIEditApplyMode = "direct" | "tracked-changes";
|
|
119
|
+
type FolioAIEditSkipReason = "missingBlock" | "changedBlock" | "ambiguousFind" | "missingFind" | "unsupportedBlock" | "emptyOperation"
|
|
120
|
+
/**
|
|
121
|
+
* The operation would not change the document — find equals
|
|
122
|
+
* replace, or replaceBlock's `text` matches the live block.
|
|
123
|
+
* Filtered out so the reviewer doesn't see "X → X" cards.
|
|
124
|
+
*/
|
|
125
|
+
| "noopOperation";
|
|
126
|
+
type FolioAIEditAppliedOperation = {
|
|
127
|
+
id: string;
|
|
128
|
+
commentId?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Primary tracked-change revision id (only set when applied in
|
|
131
|
+
* `tracked-changes` mode and the operation produced at least one
|
|
132
|
+
* insertion/deletion mark). Stable identifier suitable for
|
|
133
|
+
* scroll-to and visual reference.
|
|
134
|
+
*/
|
|
135
|
+
revisionId?: number;
|
|
136
|
+
/**
|
|
137
|
+
* Every revision id this operation produced. A replace allocates
|
|
138
|
+
* separate ids for the deletion and the insertion sides because
|
|
139
|
+
* fromProseDoc serialises a single id carrying both as a Word
|
|
140
|
+
* "moveTo/moveFrom" pair, not an ins/del — so the two sides must
|
|
141
|
+
* be distinct ids in the doc but conceptually one operation here.
|
|
142
|
+
* Use this list when you need to accept or reject every mark
|
|
143
|
+
* belonging to this op.
|
|
144
|
+
*/
|
|
145
|
+
revisionIds?: readonly number[];
|
|
146
|
+
};
|
|
147
|
+
type FolioAIEditSkippedOperation = {
|
|
148
|
+
id: string;
|
|
149
|
+
reason: FolioAIEditSkipReason;
|
|
150
|
+
};
|
|
151
|
+
type FolioAIEditApplyResult = {
|
|
152
|
+
applied: FolioAIEditAppliedOperation[];
|
|
153
|
+
skipped: FolioAIEditSkippedOperation[];
|
|
154
|
+
};
|
|
155
|
+
//#endregion
|
|
156
|
+
export { FolioAIBlock, FolioAIBlockAnchor, FolioAIBlockKind, FolioAIBlockPreviewRun, FolioAIComment, FolioAIEditAppliedOperation, FolioAIEditApplyMode, FolioAIEditApplyResult, FolioAIEditOperation, FolioAIEditReviewMeta, FolioAIEditSeverity, FolioAIEditSkipReason, FolioAIEditSkippedOperation, FolioAIEditSnapshot, FolioAISignatureParty };
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/ai-edits/word-diff.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Word-level diff between two strings. Tokenises on whitespace
|
|
4
|
+
* boundaries (preserving the whitespace as part of each token), runs
|
|
5
|
+
* an LCS, and returns a left-to-right ordered list of segments where
|
|
6
|
+
* shared runs render as `equal`, removed runs as `del`, and added
|
|
7
|
+
* runs as `ins`. Used by both the panel (to render minimal-change
|
|
8
|
+
* redlines) and the apply engine (so tracked changes only mark the
|
|
9
|
+
* divergent tokens, not the whole replaced span).
|
|
10
|
+
*
|
|
11
|
+
* O(n*m) on token counts; if a single replacement ever holds more
|
|
12
|
+
* than a few hundred tokens, swap for a streaming diff.
|
|
13
|
+
*/
|
|
14
|
+
type WordDiffSegment = {
|
|
15
|
+
type: "equal" | "del" | "ins";
|
|
16
|
+
text: string;
|
|
17
|
+
};
|
|
18
|
+
declare const diffWordSegments: (before: string, after: string) => WordDiffSegment[];
|
|
19
|
+
//#endregion
|
|
20
|
+
export { WordDiffSegment, diffWordSegments };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
//#region src/ai-edits/word-diff.ts
|
|
2
|
+
const tokenize = (s) => s.match(/\s+|\S+/gu) ?? [];
|
|
3
|
+
const diffWordSegments = (before, after) => {
|
|
4
|
+
const a = tokenize(before);
|
|
5
|
+
const b = tokenize(after);
|
|
6
|
+
if (a.length === 0 && b.length === 0) return [];
|
|
7
|
+
const m = a.length;
|
|
8
|
+
const n = b.length;
|
|
9
|
+
const dp = Array.from({ length: m + 1 }, () => Array.from({ length: n + 1 }, () => 0));
|
|
10
|
+
for (let i = 0; i < m; i++) for (let j = 0; j < n; j++) {
|
|
11
|
+
const row = dp[i + 1];
|
|
12
|
+
const prevRow = dp[i];
|
|
13
|
+
if (!row || !prevRow) continue;
|
|
14
|
+
const prev = prevRow[j] ?? 0;
|
|
15
|
+
const left = row[j] ?? 0;
|
|
16
|
+
const top = prevRow[j + 1] ?? 0;
|
|
17
|
+
row[j + 1] = a[i] === b[j] ? prev + 1 : Math.max(left, top);
|
|
18
|
+
}
|
|
19
|
+
const segments = [];
|
|
20
|
+
const push = (type, text) => {
|
|
21
|
+
if (text.length === 0) return;
|
|
22
|
+
const last = segments.at(-1);
|
|
23
|
+
if (last && last.type === type) {
|
|
24
|
+
last.text += text;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
segments.push({
|
|
28
|
+
type,
|
|
29
|
+
text
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
let i = m;
|
|
33
|
+
let j = n;
|
|
34
|
+
const reverse = [];
|
|
35
|
+
while (i > 0 && j > 0) {
|
|
36
|
+
if (a[i - 1] === b[j - 1]) {
|
|
37
|
+
reverse.push({
|
|
38
|
+
type: "equal",
|
|
39
|
+
text: a[i - 1] ?? ""
|
|
40
|
+
});
|
|
41
|
+
i--;
|
|
42
|
+
j--;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if ((dp[i - 1]?.[j] ?? 0) > (dp[i]?.[j - 1] ?? 0)) {
|
|
46
|
+
reverse.push({
|
|
47
|
+
type: "del",
|
|
48
|
+
text: a[i - 1] ?? ""
|
|
49
|
+
});
|
|
50
|
+
i--;
|
|
51
|
+
} else {
|
|
52
|
+
reverse.push({
|
|
53
|
+
type: "ins",
|
|
54
|
+
text: b[j - 1] ?? ""
|
|
55
|
+
});
|
|
56
|
+
j--;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
while (i > 0) {
|
|
60
|
+
reverse.push({
|
|
61
|
+
type: "del",
|
|
62
|
+
text: a[i - 1] ?? ""
|
|
63
|
+
});
|
|
64
|
+
i--;
|
|
65
|
+
}
|
|
66
|
+
while (j > 0) {
|
|
67
|
+
reverse.push({
|
|
68
|
+
type: "ins",
|
|
69
|
+
text: b[j - 1] ?? ""
|
|
70
|
+
});
|
|
71
|
+
j--;
|
|
72
|
+
}
|
|
73
|
+
for (const seg of reverse.toReversed()) push(seg.type, seg.text);
|
|
74
|
+
return segments;
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
export { diffWordSegments };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AISuggestion, AISuggestionApplyMode } from "./types.js";
|
|
2
|
+
import { EditorView } from "prosemirror-view";
|
|
3
|
+
|
|
4
|
+
//#region src/ai-suggestions/apply.d.ts
|
|
5
|
+
type ApplyResult = {
|
|
6
|
+
applied: string[];
|
|
7
|
+
stale: string[];
|
|
8
|
+
};
|
|
9
|
+
type ApplyOptions = {
|
|
10
|
+
view: EditorView;
|
|
11
|
+
suggestions: AISuggestion[];
|
|
12
|
+
mode: AISuggestionApplyMode;
|
|
13
|
+
author: string;
|
|
14
|
+
};
|
|
15
|
+
declare function applySuggestions(options: ApplyOptions): ApplyResult;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ApplyResult, applySuggestions };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { resolveSuggestionAnchor } from "./conflict.js";
|
|
2
|
+
//#region src/ai-suggestions/apply.ts
|
|
3
|
+
function applySuggestions(options) {
|
|
4
|
+
const { view, suggestions, mode, author } = options;
|
|
5
|
+
const applied = [];
|
|
6
|
+
const stale = [];
|
|
7
|
+
if (suggestions.length === 0) return {
|
|
8
|
+
applied,
|
|
9
|
+
stale
|
|
10
|
+
};
|
|
11
|
+
const resolved = [];
|
|
12
|
+
for (const suggestion of suggestions) {
|
|
13
|
+
const anchor = resolveSuggestionAnchor(view.state.doc, suggestion);
|
|
14
|
+
if (!anchor) {
|
|
15
|
+
stale.push(suggestion.id);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
resolved.push({
|
|
19
|
+
suggestion,
|
|
20
|
+
from: anchor.from,
|
|
21
|
+
to: anchor.to
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (resolved.length === 0) return {
|
|
25
|
+
applied,
|
|
26
|
+
stale
|
|
27
|
+
};
|
|
28
|
+
resolved.sort((a, b) => b.from - a.from);
|
|
29
|
+
const tr = view.state.tr;
|
|
30
|
+
if (mode === "direct") for (const { suggestion, from, to } of resolved) {
|
|
31
|
+
tr.insertText(suggestion.suggestedText, from, to);
|
|
32
|
+
applied.push(suggestion.id);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const insertionType = view.state.schema.marks["insertion"];
|
|
36
|
+
const deletionType = view.state.schema.marks["deletion"];
|
|
37
|
+
if (!insertionType || !deletionType) return {
|
|
38
|
+
applied,
|
|
39
|
+
stale: [...stale, ...resolved.map((r) => r.suggestion.id)]
|
|
40
|
+
};
|
|
41
|
+
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
42
|
+
let revisionSeed = Date.now();
|
|
43
|
+
for (const { suggestion, from, to } of resolved) {
|
|
44
|
+
const attrs = {
|
|
45
|
+
revisionId: revisionSeed++,
|
|
46
|
+
author,
|
|
47
|
+
date
|
|
48
|
+
};
|
|
49
|
+
if (suggestion.suggestedText.length > 0) {
|
|
50
|
+
tr.insertText(suggestion.suggestedText, to, to);
|
|
51
|
+
tr.addMark(to, to + suggestion.suggestedText.length, insertionType.create(attrs));
|
|
52
|
+
}
|
|
53
|
+
if (to > from) tr.addMark(from, to, deletionType.create(attrs));
|
|
54
|
+
applied.push(suggestion.id);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (tr.docChanged) view.dispatch(tr);
|
|
58
|
+
return {
|
|
59
|
+
applied,
|
|
60
|
+
stale
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { applySuggestions };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AISuggestion } from "./types.js";
|
|
2
|
+
import { Node } from "prosemirror-model";
|
|
3
|
+
|
|
4
|
+
//#region src/ai-suggestions/conflict.d.ts
|
|
5
|
+
type ResolvedAnchor = {
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the current PM range of a suggestion's original text.
|
|
11
|
+
*
|
|
12
|
+
* Strategy:
|
|
13
|
+
* 1. If the recorded range still contains the originalText verbatim, use it.
|
|
14
|
+
* 2. Otherwise, search a bounded window of the document for a unique
|
|
15
|
+
* match of `contextBefore + originalText + contextAfter`.
|
|
16
|
+
* 3. If the match is missing or ambiguous, return null — the caller
|
|
17
|
+
* treats null as a stale suggestion.
|
|
18
|
+
*/
|
|
19
|
+
declare function resolveSuggestionAnchor(doc: Node, suggestion: AISuggestion): ResolvedAnchor | null;
|
|
20
|
+
declare function isSuggestionStale(doc: Node, suggestion: AISuggestion): boolean;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ResolvedAnchor, isSuggestionStale, resolveSuggestionAnchor };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { buildPositionalText } from "./text-positions.js";
|
|
2
|
+
//#region src/ai-suggestions/conflict.ts
|
|
3
|
+
const ANCHOR_SEARCH_WINDOW_PM = 2e3;
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the current PM range of a suggestion's original text.
|
|
6
|
+
*
|
|
7
|
+
* Strategy:
|
|
8
|
+
* 1. If the recorded range still contains the originalText verbatim, use it.
|
|
9
|
+
* 2. Otherwise, search a bounded window of the document for a unique
|
|
10
|
+
* match of `contextBefore + originalText + contextAfter`.
|
|
11
|
+
* 3. If the match is missing or ambiguous, return null — the caller
|
|
12
|
+
* treats null as a stale suggestion.
|
|
13
|
+
*/
|
|
14
|
+
function resolveSuggestionAnchor(doc, suggestion) {
|
|
15
|
+
const docSize = doc.content.size;
|
|
16
|
+
const { from, to } = suggestion.range;
|
|
17
|
+
if (from >= 0 && to <= docSize && to - from === suggestion.originalText.length) {
|
|
18
|
+
if (doc.textBetween(from, to, "\n", "\n") === suggestion.originalText) return {
|
|
19
|
+
from,
|
|
20
|
+
to
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const positional = buildPositionalText(doc, Math.max(0, from - ANCHOR_SEARCH_WINDOW_PM), Math.min(docSize, to + ANCHOR_SEARCH_WINDOW_PM));
|
|
24
|
+
const needles = [
|
|
25
|
+
{
|
|
26
|
+
needle: suggestion.contextBefore + suggestion.originalText + suggestion.contextAfter,
|
|
27
|
+
prefix: suggestion.contextBefore.length
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
needle: suggestion.originalText + suggestion.contextAfter,
|
|
31
|
+
prefix: 0
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
needle: suggestion.contextBefore + suggestion.originalText,
|
|
35
|
+
prefix: suggestion.contextBefore.length
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
needle: suggestion.originalText,
|
|
39
|
+
prefix: 0
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
for (const { needle, prefix } of needles) {
|
|
43
|
+
if (needle.length === 0) continue;
|
|
44
|
+
const firstHit = positional.text.indexOf(needle);
|
|
45
|
+
if (firstHit === -1) continue;
|
|
46
|
+
if (positional.text.indexOf(needle, firstHit + 1) !== -1) continue;
|
|
47
|
+
const originalTextStart = firstHit + prefix;
|
|
48
|
+
const originalTextEnd = originalTextStart + suggestion.originalText.length;
|
|
49
|
+
if (suggestion.originalText.length === 0) {
|
|
50
|
+
const point = positional.pmPositionAt(originalTextStart);
|
|
51
|
+
return {
|
|
52
|
+
from: point,
|
|
53
|
+
to: point
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
from: positional.pmPositionAt(originalTextStart),
|
|
58
|
+
to: positional.pmPositionAt(originalTextEnd - 1) + 1
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
function isSuggestionStale(doc, suggestion) {
|
|
64
|
+
return resolveSuggestionAnchor(doc, suggestion) === null;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { isSuggestionStale, resolveSuggestionAnchor };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
|
|
3
|
+
//#region src/ai-suggestions/text-positions.d.ts
|
|
4
|
+
type PositionalText = {
|
|
5
|
+
/** Concatenated text content, with `\n` between block nodes. */text: string;
|
|
6
|
+
/**
|
|
7
|
+
* For each character at index `i` in `text`, returns the PM position
|
|
8
|
+
* of that character (i.e., the position just before it). Block
|
|
9
|
+
* separator characters map to the position immediately after the
|
|
10
|
+
* preceding block.
|
|
11
|
+
*/
|
|
12
|
+
pmPositionAt: (textIndex: number) => number;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Walk a slice of the document, returning its text plus a position
|
|
16
|
+
* lookup. The walk skips past block boundaries, inserting a
|
|
17
|
+
* separator character so consumers can identify line breaks.
|
|
18
|
+
*/
|
|
19
|
+
declare function buildPositionalText(doc: Node, from?: number, to?: number): PositionalText;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { PositionalText, buildPositionalText };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
//#region src/ai-suggestions/text-positions.ts
|
|
2
|
+
const BLOCK_SEPARATOR = "\n";
|
|
3
|
+
/**
|
|
4
|
+
* Walk a slice of the document, returning its text plus a position
|
|
5
|
+
* lookup. The walk skips past block boundaries, inserting a
|
|
6
|
+
* separator character so consumers can identify line breaks.
|
|
7
|
+
*/
|
|
8
|
+
function buildPositionalText(doc, from = 0, to = doc.content.size) {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
const offsets = [];
|
|
11
|
+
let textLength = 0;
|
|
12
|
+
let lastBlockEnd = null;
|
|
13
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
14
|
+
if (node.isText) {
|
|
15
|
+
const text = node.text ?? "";
|
|
16
|
+
const startInNode = Math.max(from, pos);
|
|
17
|
+
const endInNode = Math.min(to, pos + node.nodeSize);
|
|
18
|
+
if (endInNode <= startInNode) return false;
|
|
19
|
+
const sliceStart = startInNode - pos;
|
|
20
|
+
const sliceEnd = endInNode - pos;
|
|
21
|
+
const slice = text.slice(sliceStart, sliceEnd);
|
|
22
|
+
if (slice.length === 0) return false;
|
|
23
|
+
chunks.push(slice);
|
|
24
|
+
for (let i = 0; i < slice.length; i++) offsets.push(startInNode + i);
|
|
25
|
+
textLength += slice.length;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (node.isBlock) {
|
|
29
|
+
if (lastBlockEnd !== null && textLength > 0) {
|
|
30
|
+
chunks.push(BLOCK_SEPARATOR);
|
|
31
|
+
offsets.push(lastBlockEnd);
|
|
32
|
+
textLength += 1;
|
|
33
|
+
}
|
|
34
|
+
lastBlockEnd = pos + node.nodeSize - 1;
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
text: chunks.join(""),
|
|
40
|
+
pmPositionAt: (textIndex) => {
|
|
41
|
+
if (textIndex < 0) return offsets[0] ?? from;
|
|
42
|
+
if (textIndex >= offsets.length) return (offsets.at(-1) ?? from) + 1;
|
|
43
|
+
return offsets[textIndex] ?? from;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
export { buildPositionalText };
|