@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,257 @@
|
|
|
1
|
+
//#region src/utils/headerFooter.ts
|
|
2
|
+
const EMPTY_RESOLUTION = {
|
|
3
|
+
headerContent: null,
|
|
4
|
+
footerContent: null,
|
|
5
|
+
firstPageHeaderContent: null,
|
|
6
|
+
firstPageFooterContent: null,
|
|
7
|
+
hasTitlePg: false,
|
|
8
|
+
activeHeaderRId: null,
|
|
9
|
+
activeFooterRId: null,
|
|
10
|
+
activeFirstHeaderRId: null,
|
|
11
|
+
activeFirstFooterRId: null
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the header/footer content (and the active relationship ids) for a
|
|
15
|
+
* parsed package. Returns the empty resolution when no package is loaded.
|
|
16
|
+
*/
|
|
17
|
+
const resolveHeaderFooterContent = (pkg) => {
|
|
18
|
+
if (!pkg) return EMPTY_RESOLUTION;
|
|
19
|
+
const finalProps = pkg.document.finalSectionProperties;
|
|
20
|
+
const sections = pkg.document.sections;
|
|
21
|
+
const headers = pkg.headers;
|
|
22
|
+
const footers = pkg.footers;
|
|
23
|
+
const allSectionProps = [];
|
|
24
|
+
if (sections) for (const s of sections) allSectionProps.push(s.properties);
|
|
25
|
+
else if (finalProps) allSectionProps.push(finalProps);
|
|
26
|
+
let header = null;
|
|
27
|
+
let footer = null;
|
|
28
|
+
let firstHeader = null;
|
|
29
|
+
let firstFooter = null;
|
|
30
|
+
let titlePg = false;
|
|
31
|
+
let resolvedHeaderRId = null;
|
|
32
|
+
let resolvedFooterRId = null;
|
|
33
|
+
let resolvedFirstHeaderRId = null;
|
|
34
|
+
let resolvedFirstFooterRId = null;
|
|
35
|
+
if (headers) {
|
|
36
|
+
let primaryHeaderFromTitleSection = null;
|
|
37
|
+
let primaryHeaderRId = null;
|
|
38
|
+
let lastHeader = null;
|
|
39
|
+
let lastHeaderRId = null;
|
|
40
|
+
for (const sp of allSectionProps) {
|
|
41
|
+
if (!sp.headerReferences) continue;
|
|
42
|
+
const defaultRef = sp.headerReferences.find((r) => r.type === "default");
|
|
43
|
+
if (!defaultRef?.rId) continue;
|
|
44
|
+
const candidate = headers.get(defaultRef.rId);
|
|
45
|
+
if (!candidate) continue;
|
|
46
|
+
lastHeader = candidate;
|
|
47
|
+
lastHeaderRId = defaultRef.rId;
|
|
48
|
+
if (sp.titlePg === true && sp.headerReferences.some((r) => r.type === "first") && !primaryHeaderFromTitleSection) {
|
|
49
|
+
primaryHeaderFromTitleSection = candidate;
|
|
50
|
+
primaryHeaderRId = defaultRef.rId;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
header = primaryHeaderFromTitleSection ?? lastHeader ?? header;
|
|
54
|
+
resolvedHeaderRId = primaryHeaderRId ?? lastHeaderRId;
|
|
55
|
+
}
|
|
56
|
+
if (footers) {
|
|
57
|
+
let primaryFooterFromTitleSection = null;
|
|
58
|
+
let primaryFooterRId = null;
|
|
59
|
+
let lastFooter = null;
|
|
60
|
+
let lastFooterRId = null;
|
|
61
|
+
for (const sp of allSectionProps) {
|
|
62
|
+
if (!sp.footerReferences) continue;
|
|
63
|
+
const defaultRef = sp.footerReferences.find((r) => r.type === "default");
|
|
64
|
+
if (!defaultRef?.rId) continue;
|
|
65
|
+
const candidate = footers.get(defaultRef.rId);
|
|
66
|
+
if (!candidate) continue;
|
|
67
|
+
lastFooter = candidate;
|
|
68
|
+
lastFooterRId = defaultRef.rId;
|
|
69
|
+
if (sp.titlePg === true && sp.footerReferences.some((r) => r.type === "first") && !primaryFooterFromTitleSection) {
|
|
70
|
+
primaryFooterFromTitleSection = candidate;
|
|
71
|
+
primaryFooterRId = defaultRef.rId;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
footer = primaryFooterFromTitleSection ?? lastFooter ?? footer;
|
|
75
|
+
resolvedFooterRId = primaryFooterRId ?? lastFooterRId;
|
|
76
|
+
}
|
|
77
|
+
for (const sp of allSectionProps) if (sp.titlePg) {
|
|
78
|
+
titlePg = true;
|
|
79
|
+
if (headers && sp.headerReferences) {
|
|
80
|
+
const firstRef = sp.headerReferences.find((r) => r.type === "first");
|
|
81
|
+
if (firstRef?.rId) {
|
|
82
|
+
firstHeader = headers.get(firstRef.rId) ?? null;
|
|
83
|
+
resolvedFirstHeaderRId = firstRef.rId;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (footers && sp.footerReferences) {
|
|
87
|
+
const firstRef = sp.footerReferences.find((r) => r.type === "first");
|
|
88
|
+
if (firstRef?.rId) {
|
|
89
|
+
firstFooter = footers.get(firstRef.rId) ?? null;
|
|
90
|
+
resolvedFirstFooterRId = firstRef.rId;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
if (!titlePg && headers) {
|
|
96
|
+
const firstRef = (finalProps?.headerReferences)?.find((r) => r.type === "first");
|
|
97
|
+
if (firstRef?.rId) {
|
|
98
|
+
firstHeader = headers.get(firstRef.rId) ?? null;
|
|
99
|
+
resolvedFirstHeaderRId = firstRef.rId;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!titlePg && footers) {
|
|
103
|
+
const firstRef = (finalProps?.footerReferences)?.find((r) => r.type === "first");
|
|
104
|
+
if (firstRef?.rId) {
|
|
105
|
+
firstFooter = footers.get(firstRef.rId) ?? null;
|
|
106
|
+
resolvedFirstFooterRId = firstRef.rId;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!titlePg) {
|
|
110
|
+
if (!header && firstHeader) {
|
|
111
|
+
header = firstHeader;
|
|
112
|
+
resolvedHeaderRId = resolvedFirstHeaderRId;
|
|
113
|
+
}
|
|
114
|
+
if (!footer && firstFooter) {
|
|
115
|
+
footer = firstFooter;
|
|
116
|
+
resolvedFooterRId = resolvedFirstFooterRId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
headerContent: header,
|
|
121
|
+
footerContent: footer,
|
|
122
|
+
firstPageHeaderContent: firstHeader,
|
|
123
|
+
firstPageFooterContent: firstFooter,
|
|
124
|
+
hasTitlePg: titlePg,
|
|
125
|
+
activeHeaderRId: resolvedHeaderRId,
|
|
126
|
+
activeFooterRId: resolvedFooterRId,
|
|
127
|
+
activeFirstHeaderRId: resolvedFirstHeaderRId,
|
|
128
|
+
activeFirstFooterRId: resolvedFirstFooterRId
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The section properties that drive the rendered chrome, with `titlePg` merged
|
|
133
|
+
* in when title-page mode was inferred from header/footer references.
|
|
134
|
+
*/
|
|
135
|
+
const resolveEffectiveSectionProperties = (documentBody, hasTitlePg) => {
|
|
136
|
+
const base = (documentBody?.sections?.find((section) => section.content.length > 0))?.properties ?? documentBody?.finalSectionProperties;
|
|
137
|
+
if (!hasTitlePg || base?.titlePg) return base;
|
|
138
|
+
return base ? {
|
|
139
|
+
...base,
|
|
140
|
+
titlePg: true
|
|
141
|
+
} : base;
|
|
142
|
+
};
|
|
143
|
+
/** Pick the relationship id for the slot a save/remove targets. */
|
|
144
|
+
const pickActiveHeaderFooterRId = (resolution, position, isFirstPage) => {
|
|
145
|
+
if (isFirstPage) return position === "header" ? resolution.activeFirstHeaderRId : resolution.activeFirstFooterRId;
|
|
146
|
+
return position === "header" ? resolution.activeHeaderRId : resolution.activeFooterRId;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Build a Document with a fresh empty header/footer for the given slot, wired
|
|
150
|
+
* into `finalSectionProperties` via a new reference. Returns null when the
|
|
151
|
+
* document has no final section properties to attach the reference to.
|
|
152
|
+
*/
|
|
153
|
+
const createEmptyHeaderFooter = (document, position, isFirstPage) => {
|
|
154
|
+
const pkg = document.package;
|
|
155
|
+
const sectionProps = pkg.document.finalSectionProperties;
|
|
156
|
+
if (!sectionProps) return null;
|
|
157
|
+
const hdrFtrType = isFirstPage ? "first" : "default";
|
|
158
|
+
const rId = `rId_new_${position}_${hdrFtrType}`;
|
|
159
|
+
const emptyHf = {
|
|
160
|
+
type: position,
|
|
161
|
+
hdrFtrType,
|
|
162
|
+
content: [{
|
|
163
|
+
type: "paragraph",
|
|
164
|
+
content: []
|
|
165
|
+
}]
|
|
166
|
+
};
|
|
167
|
+
const mapKey = position === "header" ? "headers" : "footers";
|
|
168
|
+
const newMap = new Map(pkg[mapKey]);
|
|
169
|
+
newMap.set(rId, emptyHf);
|
|
170
|
+
const refKey = position === "header" ? "headerReferences" : "footerReferences";
|
|
171
|
+
const existingRefs = sectionProps[refKey] ?? [];
|
|
172
|
+
const newRef = {
|
|
173
|
+
type: hdrFtrType,
|
|
174
|
+
rId
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
...document,
|
|
178
|
+
package: {
|
|
179
|
+
...pkg,
|
|
180
|
+
[mapKey]: newMap,
|
|
181
|
+
document: {
|
|
182
|
+
...pkg.document,
|
|
183
|
+
finalSectionProperties: {
|
|
184
|
+
...sectionProps,
|
|
185
|
+
[refKey]: [...existingRefs, newRef]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Serialise edited header/footer content into a new Document. A brand-new
|
|
193
|
+
* HeaderFooter inside a brand-new Map keeps every earlier history entry's
|
|
194
|
+
* Document untouched so undo can step back to the pre-edit state. Returns null
|
|
195
|
+
* when the target header/footer cannot be found.
|
|
196
|
+
*/
|
|
197
|
+
const saveHeaderFooterContent = ({ document, position, isFirstPage, activeRId, blocks }) => {
|
|
198
|
+
const pkg = document.package;
|
|
199
|
+
const mapKey = position === "header" ? "headers" : "footers";
|
|
200
|
+
const map = pkg[mapKey];
|
|
201
|
+
const existing = map?.get(activeRId);
|
|
202
|
+
if (!map || !existing) return null;
|
|
203
|
+
const updated = {
|
|
204
|
+
...existing,
|
|
205
|
+
type: position,
|
|
206
|
+
hdrFtrType: isFirstPage ? "first" : "default",
|
|
207
|
+
content: blocks
|
|
208
|
+
};
|
|
209
|
+
const newMap = new Map(map);
|
|
210
|
+
newMap.set(activeRId, updated);
|
|
211
|
+
return {
|
|
212
|
+
...document,
|
|
213
|
+
package: {
|
|
214
|
+
...pkg,
|
|
215
|
+
[mapKey]: newMap
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Remove a header/footer and drop its reference from every section that points
|
|
221
|
+
* at it, returning the new Document.
|
|
222
|
+
*/
|
|
223
|
+
const removeHeaderFooter = ({ document, position, activeRId }) => {
|
|
224
|
+
const pkg = document.package;
|
|
225
|
+
const refKey = position === "header" ? "headerReferences" : "footerReferences";
|
|
226
|
+
const mapKey = position === "header" ? "headers" : "footers";
|
|
227
|
+
const newMap = new Map(pkg[mapKey]);
|
|
228
|
+
newMap.delete(activeRId);
|
|
229
|
+
const stripRef = (sp) => {
|
|
230
|
+
const refs = sp[refKey];
|
|
231
|
+
if (!refs?.some((r) => r.rId === activeRId)) return sp;
|
|
232
|
+
return {
|
|
233
|
+
...sp,
|
|
234
|
+
[refKey]: refs.filter((r) => r.rId !== activeRId)
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
const oldDoc = pkg.document;
|
|
238
|
+
const newSections = oldDoc.sections?.map((s) => ({
|
|
239
|
+
...s,
|
|
240
|
+
properties: stripRef(s.properties)
|
|
241
|
+
}));
|
|
242
|
+
const newFinalProps = oldDoc.finalSectionProperties ? stripRef(oldDoc.finalSectionProperties) : oldDoc.finalSectionProperties;
|
|
243
|
+
return {
|
|
244
|
+
...document,
|
|
245
|
+
package: {
|
|
246
|
+
...pkg,
|
|
247
|
+
[mapKey]: newMap,
|
|
248
|
+
document: {
|
|
249
|
+
...oldDoc,
|
|
250
|
+
...newSections !== void 0 ? { sections: newSections } : {},
|
|
251
|
+
...newFinalProps !== void 0 ? { finalSectionProperties: newFinalProps } : {}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
//#endregion
|
|
257
|
+
export { createEmptyHeaderFooter, pickActiveHeaderFooterRId, removeHeaderFooter, resolveEffectiveSectionProperties, resolveHeaderFooterContent, saveHeaderFooterContent };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Node } from "prosemirror-model";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/headingCollector.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Information about a heading found in the document.
|
|
6
|
+
*/
|
|
7
|
+
type HeadingInfo = {
|
|
8
|
+
/** The text content of the heading */text: string; /** Outline level (0 = Heading 1, 1 = Heading 2, etc.) */
|
|
9
|
+
level: number; /** ProseMirror document position of the paragraph node */
|
|
10
|
+
pmPos: number; /** 1-indexed page number, filled in by the editor once layout is known. */
|
|
11
|
+
pageNumber?: number | null;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Collect all headings from a ProseMirror document.
|
|
15
|
+
*
|
|
16
|
+
* Detection logic:
|
|
17
|
+
* 1. Check `outlineLevel` attr (set by OOXML parsing or style resolution)
|
|
18
|
+
* 2. Fallback to `styleId` matching /^[Hh]eading(\d)$/
|
|
19
|
+
*/
|
|
20
|
+
declare function collectHeadings(doc: Node): HeadingInfo[];
|
|
21
|
+
//#endregion
|
|
22
|
+
export { HeadingInfo, collectHeadings };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/utils/headingCollector.ts
|
|
2
|
+
/**
|
|
3
|
+
* Collect all headings from a ProseMirror document.
|
|
4
|
+
*
|
|
5
|
+
* Detection logic:
|
|
6
|
+
* 1. Check `outlineLevel` attr (set by OOXML parsing or style resolution)
|
|
7
|
+
* 2. Fallback to `styleId` matching /^[Hh]eading(\d)$/
|
|
8
|
+
*/
|
|
9
|
+
function collectHeadings(doc) {
|
|
10
|
+
const headings = [];
|
|
11
|
+
doc.descendants((node, pos) => {
|
|
12
|
+
if (node.type.name === "paragraph") {
|
|
13
|
+
const level = node.attrs["outlineLevel"];
|
|
14
|
+
const styleId = node.attrs["styleId"];
|
|
15
|
+
let effectiveLevel = level;
|
|
16
|
+
if (effectiveLevel === null && styleId) {
|
|
17
|
+
const match = /^[Hh]eading(?<level>\d)$/u.exec(styleId);
|
|
18
|
+
if (match) effectiveLevel = Number.parseInt(match.groups["level"], 10) - 1;
|
|
19
|
+
}
|
|
20
|
+
if (effectiveLevel !== null && effectiveLevel >= 0 && effectiveLevel <= 8) {
|
|
21
|
+
let text = "";
|
|
22
|
+
node.forEach((child) => {
|
|
23
|
+
if (child.isText) text += child.text || "";
|
|
24
|
+
});
|
|
25
|
+
if (text.trim()) headings.push({
|
|
26
|
+
text: text.trim(),
|
|
27
|
+
level: effectiveLevel,
|
|
28
|
+
pmPos: pos
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return headings;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { collectHeadings };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/utils/hexId.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Lifted from
|
|
4
|
+
* https://github.com/eigenpal/docx-editor/blob/main/packages/core/src/utils/hexId.ts
|
|
5
|
+
* (Apache-2.0). Keep the bound and the comments in sync upstream.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Strictest OOXML `ST_LongHexNumber` upper bound (exclusive) across the
|
|
9
|
+
* fields this helper feeds: `w14:paraId` / `w14:textId` / comment
|
|
10
|
+
* `paraId` (`< 0x80000000`) and `w16cid:commentId/@durableId`
|
|
11
|
+
* (`< 0x7FFFFFFF`). Generated ids must stay strictly below this value
|
|
12
|
+
* to survive both Word ("Document Recovery — Table Properties") and
|
|
13
|
+
* strict OOXML validators.
|
|
14
|
+
*/
|
|
15
|
+
declare const MAX_HEX_ID_EXCLUSIVE = 2147483647;
|
|
16
|
+
/**
|
|
17
|
+
* Random 8-char uppercase hex id, matching Microsoft's `w14:paraId`
|
|
18
|
+
* extension format (also reused for comment `paraId` / `durableId`).
|
|
19
|
+
*
|
|
20
|
+
* Range is `[0, MAX_HEX_ID_EXCLUSIVE)` = `[0, 0x7FFFFFFE]`.
|
|
21
|
+
*
|
|
22
|
+
* Uses `Math.random()` rather than `crypto.randomUUID()` so the
|
|
23
|
+
* generator works in non-secure contexts (file://, web workers).
|
|
24
|
+
*/
|
|
25
|
+
declare const generateHexId: () => string;
|
|
26
|
+
/**
|
|
27
|
+
* Deterministic 8-char uppercase hex id (FNV-1a over `seed`), `< 0x7FFFFFFF`.
|
|
28
|
+
* Re-deriving from the same seed mints the same id, so content/position-derived
|
|
29
|
+
* ids (block paraIds, comment thread keys) are stable across saves.
|
|
30
|
+
*/
|
|
31
|
+
declare const deterministicHexId: (seed: string) => string;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { MAX_HEX_ID_EXCLUSIVE, deterministicHexId, generateHexId };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/utils/hexId.ts
|
|
2
|
+
/**
|
|
3
|
+
* Lifted from
|
|
4
|
+
* https://github.com/eigenpal/docx-editor/blob/main/packages/core/src/utils/hexId.ts
|
|
5
|
+
* (Apache-2.0). Keep the bound and the comments in sync upstream.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Strictest OOXML `ST_LongHexNumber` upper bound (exclusive) across the
|
|
9
|
+
* fields this helper feeds: `w14:paraId` / `w14:textId` / comment
|
|
10
|
+
* `paraId` (`< 0x80000000`) and `w16cid:commentId/@durableId`
|
|
11
|
+
* (`< 0x7FFFFFFF`). Generated ids must stay strictly below this value
|
|
12
|
+
* to survive both Word ("Document Recovery — Table Properties") and
|
|
13
|
+
* strict OOXML validators.
|
|
14
|
+
*/
|
|
15
|
+
const MAX_HEX_ID_EXCLUSIVE = 2147483647;
|
|
16
|
+
/**
|
|
17
|
+
* Random 8-char uppercase hex id, matching Microsoft's `w14:paraId`
|
|
18
|
+
* extension format (also reused for comment `paraId` / `durableId`).
|
|
19
|
+
*
|
|
20
|
+
* Range is `[0, MAX_HEX_ID_EXCLUSIVE)` = `[0, 0x7FFFFFFE]`.
|
|
21
|
+
*
|
|
22
|
+
* Uses `Math.random()` rather than `crypto.randomUUID()` so the
|
|
23
|
+
* generator works in non-secure contexts (file://, web workers).
|
|
24
|
+
*/
|
|
25
|
+
const generateHexId = () => Math.floor(Math.random() * MAX_HEX_ID_EXCLUSIVE).toString(16).toUpperCase().padStart(8, "0");
|
|
26
|
+
/**
|
|
27
|
+
* Deterministic 8-char uppercase hex id (FNV-1a over `seed`), `< 0x7FFFFFFF`.
|
|
28
|
+
* Re-deriving from the same seed mints the same id, so content/position-derived
|
|
29
|
+
* ids (block paraIds, comment thread keys) are stable across saves.
|
|
30
|
+
*/
|
|
31
|
+
const deterministicHexId = (seed) => {
|
|
32
|
+
let hash = 2166136261;
|
|
33
|
+
for (const character of seed) hash = Math.imul(hash ^ (character.codePointAt(0) ?? 0), 16777619) >>> 0;
|
|
34
|
+
return (hash % MAX_HEX_ID_EXCLUSIVE).toString(16).toUpperCase().padStart(8, "0");
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { MAX_HEX_ID_EXCLUSIVE, deterministicHexId, generateHexId };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/utils/imageValidation.ts
|
|
2
|
+
const MAX_INSERTED_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
3
|
+
const ALLOWED_IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
4
|
+
"image/png",
|
|
5
|
+
"image/jpeg",
|
|
6
|
+
"image/gif",
|
|
7
|
+
"image/bmp",
|
|
8
|
+
"image/webp",
|
|
9
|
+
"image/tiff"
|
|
10
|
+
]);
|
|
11
|
+
function isAllowedImageMimeType(mimeType) {
|
|
12
|
+
return ALLOWED_IMAGE_MIME_TYPES.has(mimeType);
|
|
13
|
+
}
|
|
14
|
+
async function isSafeImageFile(file) {
|
|
15
|
+
if (file.size <= 0 || file.size > MAX_INSERTED_IMAGE_BYTES) return false;
|
|
16
|
+
if (!isAllowedImageMimeType(file.type)) return false;
|
|
17
|
+
return matchesImageSignature(new Uint8Array(await file.slice(0, 12).arrayBuffer()), file.type);
|
|
18
|
+
}
|
|
19
|
+
function matchesImageSignature(bytes, mimeType) {
|
|
20
|
+
switch (mimeType) {
|
|
21
|
+
case "image/png": return bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71;
|
|
22
|
+
case "image/jpeg": return bytes[0] === 255 && bytes[1] === 216;
|
|
23
|
+
case "image/gif": return bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 56;
|
|
24
|
+
case "image/bmp": return bytes[0] === 66 && bytes[1] === 77;
|
|
25
|
+
case "image/webp": return bytes[0] === 82 && bytes[1] === 73 && bytes[2] === 70 && bytes[3] === 70 && bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80;
|
|
26
|
+
case "image/tiff": return bytes[0] === 73 && bytes[1] === 73 && (bytes[2] === 42 || bytes[2] === 43) && bytes[3] === 0 || bytes[0] === 77 && bytes[1] === 77 && bytes[2] === 0 && (bytes[3] === 42 || bytes[3] === 43);
|
|
27
|
+
default: return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { isAllowedImageMimeType, isSafeImageFile };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/paragraphFormattingMerge.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Merge paragraph properties for OOXML style cascade resolution.
|
|
6
|
+
*
|
|
7
|
+
* The source is the higher-priority layer. Most `w:pPr` properties replace an
|
|
8
|
+
* inherited value when present; nested child containers merge by child field;
|
|
9
|
+
* tabs replace as a complete ordered collection; paragraph mark `w:rPr` uses
|
|
10
|
+
* the run-formatting merge rules.
|
|
11
|
+
*/
|
|
12
|
+
declare function mergeParagraphFormatting(target: document_d_exports.ParagraphFormatting | undefined, source: document_d_exports.ParagraphFormatting | undefined): document_d_exports.ParagraphFormatting | undefined;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { mergeParagraphFormatting };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { mergeTextFormatting } from "./textFormattingMerge.js";
|
|
2
|
+
//#region src/utils/paragraphFormattingMerge.ts
|
|
3
|
+
const PARAGRAPH_REPLACE_KEYS = [
|
|
4
|
+
"alignment",
|
|
5
|
+
"bidi",
|
|
6
|
+
"spaceBefore",
|
|
7
|
+
"spaceAfter",
|
|
8
|
+
"lineSpacing",
|
|
9
|
+
"lineSpacingRule",
|
|
10
|
+
"beforeAutospacing",
|
|
11
|
+
"afterAutospacing",
|
|
12
|
+
"spacingExplicit",
|
|
13
|
+
"indentLeft",
|
|
14
|
+
"indentRight",
|
|
15
|
+
"indentFirstLine",
|
|
16
|
+
"hangingIndent",
|
|
17
|
+
"shading",
|
|
18
|
+
"keepNext",
|
|
19
|
+
"keepLines",
|
|
20
|
+
"widowControl",
|
|
21
|
+
"pageBreakBefore",
|
|
22
|
+
"contextualSpacing",
|
|
23
|
+
"outlineLevel",
|
|
24
|
+
"styleId",
|
|
25
|
+
"suppressLineNumbers",
|
|
26
|
+
"suppressAutoHyphens",
|
|
27
|
+
"runInWithNext"
|
|
28
|
+
];
|
|
29
|
+
const copyDefinedParagraphProperty = (target, source, key) => {
|
|
30
|
+
const value = source[key];
|
|
31
|
+
if (value !== void 0) target[key] = value;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Merge paragraph properties for OOXML style cascade resolution.
|
|
35
|
+
*
|
|
36
|
+
* The source is the higher-priority layer. Most `w:pPr` properties replace an
|
|
37
|
+
* inherited value when present; nested child containers merge by child field;
|
|
38
|
+
* tabs replace as a complete ordered collection; paragraph mark `w:rPr` uses
|
|
39
|
+
* the run-formatting merge rules.
|
|
40
|
+
*/
|
|
41
|
+
function mergeParagraphFormatting(target, source) {
|
|
42
|
+
if (!source) return target;
|
|
43
|
+
if (!target) {
|
|
44
|
+
const result = { ...source };
|
|
45
|
+
if (source.tabs !== void 0) result.tabs = [...source.tabs];
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
const result = { ...target };
|
|
49
|
+
for (const key of PARAGRAPH_REPLACE_KEYS) copyDefinedParagraphProperty(result, source, key);
|
|
50
|
+
const mergedRunProperties = mergeTextFormatting(result.runProperties, source.runProperties);
|
|
51
|
+
if (mergedRunProperties) result.runProperties = mergedRunProperties;
|
|
52
|
+
if (source.borders !== void 0) result.borders = {
|
|
53
|
+
...result.borders,
|
|
54
|
+
...source.borders
|
|
55
|
+
};
|
|
56
|
+
if (source.numPr !== void 0) result.numPr = {
|
|
57
|
+
...result.numPr,
|
|
58
|
+
...source.numPr
|
|
59
|
+
};
|
|
60
|
+
if (source.frame !== void 0) result.frame = {
|
|
61
|
+
...result.frame,
|
|
62
|
+
...source.frame
|
|
63
|
+
};
|
|
64
|
+
if (source.tabs !== void 0) result.tabs = [...source.tabs];
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { mergeParagraphFormatting };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/replaceText.d.ts
|
|
4
|
+
type ReplaceRange = {
|
|
5
|
+
start: {
|
|
6
|
+
paragraphIndex: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
};
|
|
9
|
+
end: {
|
|
10
|
+
paragraphIndex: number;
|
|
11
|
+
offset: number;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** Replace text within a range in the document. Returns a new document. */
|
|
15
|
+
declare function replaceTextInDocument(doc: document_d_exports.Document, range: ReplaceRange, text: string, formatting?: document_d_exports.TextFormatting): document_d_exports.Document;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { replaceTextInDocument };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
//#region src/utils/replaceText.ts
|
|
2
|
+
/** Replace text within a range in the document. Returns a new document. */
|
|
3
|
+
function replaceTextInDocument(doc, range, text, formatting) {
|
|
4
|
+
const newDoc = structuredClone(doc);
|
|
5
|
+
const body = newDoc.package.document;
|
|
6
|
+
const { start, end } = range;
|
|
7
|
+
if (start.paragraphIndex === end.paragraphIndex) {
|
|
8
|
+
const paragraph = getParagraphByIndex(body, start.paragraphIndex);
|
|
9
|
+
if (!paragraph) return newDoc;
|
|
10
|
+
paragraph.content = deleteTextInParagraph(paragraph, start.offset, end.offset);
|
|
11
|
+
paragraph.content = insertTextAtOffset(paragraph, start.offset, text, formatting);
|
|
12
|
+
} else {
|
|
13
|
+
const startParagraph = getParagraphByIndex(body, start.paragraphIndex);
|
|
14
|
+
if (!startParagraph) return newDoc;
|
|
15
|
+
const startText = getParagraphText(startParagraph);
|
|
16
|
+
startParagraph.content = deleteTextInParagraph(startParagraph, start.offset, startText.length);
|
|
17
|
+
startParagraph.content = insertTextAtOffset(startParagraph, start.offset, text, formatting);
|
|
18
|
+
const paragraphsToRemove = [];
|
|
19
|
+
for (let i = start.paragraphIndex + 1; i <= end.paragraphIndex; i++) paragraphsToRemove.push(getTopLevelParagraphBlockIndex(body, i));
|
|
20
|
+
for (let i = paragraphsToRemove.length - 1; i >= 0; i--) {
|
|
21
|
+
const idx = paragraphsToRemove[i];
|
|
22
|
+
if (idx !== -1) body.content.splice(idx, 1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return newDoc;
|
|
26
|
+
}
|
|
27
|
+
function getTopLevelParagraphBlockIndex(body, paragraphIndex) {
|
|
28
|
+
let pIdx = 0;
|
|
29
|
+
for (let i = 0; i < body.content.length; i++) if (body.content[i].type === "paragraph") {
|
|
30
|
+
if (pIdx === paragraphIndex) return i;
|
|
31
|
+
pIdx++;
|
|
32
|
+
}
|
|
33
|
+
return -1;
|
|
34
|
+
}
|
|
35
|
+
function getParagraphByIndex(body, paragraphIndex) {
|
|
36
|
+
let currentIndex = 0;
|
|
37
|
+
const walkBlocks = (blocks) => {
|
|
38
|
+
for (const block of blocks) {
|
|
39
|
+
if (block.type === "paragraph") {
|
|
40
|
+
if (currentIndex === paragraphIndex) return block;
|
|
41
|
+
currentIndex++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (block.type === "table") {
|
|
45
|
+
for (const row of block.rows) for (const cell of row.cells) {
|
|
46
|
+
const found = walkBlocks(cell.content);
|
|
47
|
+
if (found !== null) return found;
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const found = walkBlocks(block.content);
|
|
52
|
+
if (found !== null) return found;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
return walkBlocks(body.content);
|
|
57
|
+
}
|
|
58
|
+
function getParagraphText(paragraph) {
|
|
59
|
+
let text = "";
|
|
60
|
+
for (const item of paragraph.content) if (item.type === "run") {
|
|
61
|
+
for (const c of item.content) if (c.type === "text") text += c.text;
|
|
62
|
+
} else if (item.type === "hyperlink") for (const child of item.children) {
|
|
63
|
+
if (child.type !== "run") continue;
|
|
64
|
+
for (const c of child.content) if (c.type === "text") text += c.text;
|
|
65
|
+
}
|
|
66
|
+
return text;
|
|
67
|
+
}
|
|
68
|
+
function deleteTextInParagraph(paragraph, startOffset, endOffset) {
|
|
69
|
+
const result = [];
|
|
70
|
+
let currentOffset = 0;
|
|
71
|
+
for (const item of paragraph.content) if (item.type === "run") {
|
|
72
|
+
const newContent = [];
|
|
73
|
+
for (const content of item.content) if (content.type === "text") {
|
|
74
|
+
const textStart = currentOffset;
|
|
75
|
+
const textEnd = currentOffset + content.text.length;
|
|
76
|
+
if (textEnd <= startOffset || textStart >= endOffset) newContent.push(content);
|
|
77
|
+
else {
|
|
78
|
+
let newText = "";
|
|
79
|
+
if (textStart < startOffset) newText += content.text.slice(0, startOffset - textStart);
|
|
80
|
+
if (textEnd > endOffset) newText += content.text.slice(endOffset - textStart);
|
|
81
|
+
if (newText) newContent.push({
|
|
82
|
+
...content,
|
|
83
|
+
text: newText
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
currentOffset = textEnd;
|
|
87
|
+
} else newContent.push(content);
|
|
88
|
+
if (newContent.length > 0) result.push({
|
|
89
|
+
...item,
|
|
90
|
+
content: newContent
|
|
91
|
+
});
|
|
92
|
+
} else result.push(item);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
function insertTextAtOffset(paragraph, offset, text, formatting) {
|
|
96
|
+
if (!text) return paragraph.content;
|
|
97
|
+
let currentOffset = 0;
|
|
98
|
+
for (const item of paragraph.content) if (item.type === "run") for (let ci = 0; ci < item.content.length; ci++) {
|
|
99
|
+
const content = item.content[ci];
|
|
100
|
+
if (content.type === "text") {
|
|
101
|
+
const textStart = currentOffset;
|
|
102
|
+
const textEnd = currentOffset + content.text.length;
|
|
103
|
+
if (offset >= textStart && offset <= textEnd) {
|
|
104
|
+
const relOffset = offset - textStart;
|
|
105
|
+
if (formatting) {
|
|
106
|
+
const before = content.text.slice(0, relOffset);
|
|
107
|
+
const after = content.text.slice(relOffset);
|
|
108
|
+
const newContent = [];
|
|
109
|
+
if (before) newContent.push({
|
|
110
|
+
type: "text",
|
|
111
|
+
text: before
|
|
112
|
+
});
|
|
113
|
+
const newRun = {
|
|
114
|
+
type: "text",
|
|
115
|
+
text
|
|
116
|
+
};
|
|
117
|
+
item.content.splice(ci, 1, ...newContent);
|
|
118
|
+
const insertRun = {
|
|
119
|
+
type: "run",
|
|
120
|
+
content: [newRun],
|
|
121
|
+
formatting
|
|
122
|
+
};
|
|
123
|
+
const afterItems = [];
|
|
124
|
+
if (after) afterItems.push({
|
|
125
|
+
type: "text",
|
|
126
|
+
text: after
|
|
127
|
+
});
|
|
128
|
+
const remaining = item.content.splice(ci + newContent.length);
|
|
129
|
+
const afterRun = {
|
|
130
|
+
type: "run",
|
|
131
|
+
content: [...remaining, ...afterItems],
|
|
132
|
+
...item.formatting !== void 0 ? { formatting: item.formatting } : {}
|
|
133
|
+
};
|
|
134
|
+
const idx = paragraph.content.indexOf(item);
|
|
135
|
+
paragraph.content.splice(idx + 1, 0, insertRun);
|
|
136
|
+
if (afterItems.length > 0 || remaining.length > 0) paragraph.content.splice(idx + 2, 0, afterRun);
|
|
137
|
+
return paragraph.content;
|
|
138
|
+
}
|
|
139
|
+
content.text = content.text.slice(0, relOffset) + text + content.text.slice(relOffset);
|
|
140
|
+
return paragraph.content;
|
|
141
|
+
}
|
|
142
|
+
currentOffset = textEnd;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const lastRun = paragraph.content.findLast((item) => item.type === "run");
|
|
146
|
+
if (lastRun) lastRun.content.push({
|
|
147
|
+
type: "text",
|
|
148
|
+
text
|
|
149
|
+
});
|
|
150
|
+
else paragraph.content.push({
|
|
151
|
+
type: "run",
|
|
152
|
+
content: [{
|
|
153
|
+
type: "text",
|
|
154
|
+
text
|
|
155
|
+
}],
|
|
156
|
+
formatting: formatting ?? {}
|
|
157
|
+
});
|
|
158
|
+
return paragraph.content;
|
|
159
|
+
}
|
|
160
|
+
//#endregion
|
|
161
|
+
export { replaceTextInDocument };
|