@stll/folio-core 0.0.1-placeholder.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE.md +29 -0
- package/README.md +41 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/ai-edits/apply.d.ts +35 -0
- package/dist/ai-edits/apply.js +683 -0
- package/dist/ai-edits/clean-text.d.ts +28 -0
- package/dist/ai-edits/clean-text.js +23 -0
- package/dist/ai-edits/headless.d.ts +225 -0
- package/dist/ai-edits/headless.js +513 -0
- package/dist/ai-edits/index.d.ts +6 -0
- package/dist/ai-edits/index.js +5 -0
- package/dist/ai-edits/inline-emphasis.d.ts +38 -0
- package/dist/ai-edits/inline-emphasis.js +78 -0
- package/dist/ai-edits/snapshot.d.ts +9 -0
- package/dist/ai-edits/snapshot.js +195 -0
- package/dist/ai-edits/types.d.ts +156 -0
- package/dist/ai-edits/types.js +0 -0
- package/dist/ai-edits/word-diff.d.ts +20 -0
- package/dist/ai-edits/word-diff.js +77 -0
- package/dist/ai-suggestions/apply.d.ts +17 -0
- package/dist/ai-suggestions/apply.js +64 -0
- package/dist/ai-suggestions/conflict.d.ts +22 -0
- package/dist/ai-suggestions/conflict.js +67 -0
- package/dist/ai-suggestions/text-positions.d.ts +21 -0
- package/dist/ai-suggestions/text-positions.js +48 -0
- package/dist/ai-suggestions/types.d.ts +199 -0
- package/dist/ai-suggestions/types.js +59 -0
- package/dist/content-controls/errors.d.ts +52 -0
- package/dist/content-controls/errors.js +36 -0
- package/dist/content-controls/findContentControls.d.ts +55 -0
- package/dist/content-controls/findContentControls.js +75 -0
- package/dist/content-controls/index.d.ts +4 -0
- package/dist/content-controls/index.js +4 -0
- package/dist/content-controls/mutateContentControls.d.ts +51 -0
- package/dist/content-controls/mutateContentControls.js +377 -0
- package/dist/controller/folioEditor.d.ts +21 -0
- package/dist/controller/folioEditor.js +29 -0
- package/dist/controller/folioEditorEvents.d.ts +23 -0
- package/dist/controller/folioEditorEvents.js +24 -0
- package/dist/controller/hiddenEditorApi.d.ts +35 -0
- package/dist/controller/hiddenEditorApi.js +112 -0
- package/dist/controller/hiddenEditorManager.d.ts +93 -0
- package/dist/controller/hiddenEditorManager.js +308 -0
- package/dist/controller/layoutPipeline.d.ts +63 -0
- package/dist/controller/layoutPipeline.js +406 -0
- package/dist/controller/layoutScheduler.d.ts +41 -0
- package/dist/controller/layoutScheduler.js +59 -0
- package/dist/controller/layoutSession.d.ts +24 -0
- package/dist/controller/layoutSession.js +13 -0
- package/dist/docx/blockContentParser.d.ts +13 -0
- package/dist/docx/blockContentParser.js +289 -0
- package/dist/docx/bookmarkParser.d.ts +178 -0
- package/dist/docx/bookmarkParser.js +246 -0
- package/dist/docx/bookmarkPlacement.d.ts +10 -0
- package/dist/docx/bookmarkPlacement.js +50 -0
- package/dist/docx/bulletMarkers.d.ts +4 -0
- package/dist/docx/bulletMarkers.js +42 -0
- package/dist/docx/commentParser.d.ts +34 -0
- package/dist/docx/commentParser.js +127 -0
- package/dist/docx/commentReferenceNormalization.d.ts +25 -0
- package/dist/docx/commentReferenceNormalization.js +97 -0
- package/dist/docx/commentReplyMarkers.d.ts +20 -0
- package/dist/docx/commentReplyMarkers.js +123 -0
- package/dist/docx/compatibility.d.ts +12 -0
- package/dist/docx/compatibility.js +77 -0
- package/dist/docx/documentParser.d.ts +65 -0
- package/dist/docx/documentParser.js +209 -0
- package/dist/docx/drawingUtils.d.ts +56 -0
- package/dist/docx/drawingUtils.js +305 -0
- package/dist/docx/fieldParser.d.ts +228 -0
- package/dist/docx/fieldParser.js +559 -0
- package/dist/docx/footnoteParser.d.ts +109 -0
- package/dist/docx/footnoteParser.js +270 -0
- package/dist/docx/headerFooterParser.d.ts +119 -0
- package/dist/docx/headerFooterParser.js +266 -0
- package/dist/docx/headerFooterRefParser.d.ts +22 -0
- package/dist/docx/headerFooterRefParser.js +52 -0
- package/dist/docx/headerFooterReferenceNormalization.d.ts +19 -0
- package/dist/docx/headerFooterReferenceNormalization.js +64 -0
- package/dist/docx/hyperlinkParser.d.ts +108 -0
- package/dist/docx/hyperlinkParser.js +230 -0
- package/dist/docx/imageParser.d.ts +93 -0
- package/dist/docx/imageParser.js +522 -0
- package/dist/docx/mathToMathml.d.ts +15 -0
- package/dist/docx/mathToMathml.js +357 -0
- package/dist/docx/modelValidation.d.ts +13 -0
- package/dist/docx/modelValidation.js +21 -0
- package/dist/docx/normalizeBaseDirection.d.ts +12 -0
- package/dist/docx/normalizeBaseDirection.js +81 -0
- package/dist/docx/notePropertiesParser.d.ts +16 -0
- package/dist/docx/notePropertiesParser.js +99 -0
- package/dist/docx/numberingParser.d.ts +86 -0
- package/dist/docx/numberingParser.js +735 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +25 -0
- package/dist/docx/numberingReferenceNormalization.js +22 -0
- package/dist/docx/paragraphParser.d.ts +86 -0
- package/dist/docx/paragraphParser.js +1132 -0
- package/dist/docx/paragraphTraversal.d.ts +19 -0
- package/dist/docx/paragraphTraversal.js +76 -0
- package/dist/docx/parser.d.ts +67 -0
- package/dist/docx/parser.js +391 -0
- package/dist/docx/parserEnums.d.ts +45 -0
- package/dist/docx/parserEnums.js +70 -0
- package/dist/docx/relsParser.d.ts +160 -0
- package/dist/docx/relsParser.js +235 -0
- package/dist/docx/replyToComment.d.ts +29 -0
- package/dist/docx/replyToComment.js +73 -0
- package/dist/docx/rezip.d.ts +166 -0
- package/dist/docx/rezip.js +1194 -0
- package/dist/docx/runConsolidator.d.ts +57 -0
- package/dist/docx/runConsolidator.js +224 -0
- package/dist/docx/runParser.d.ts +78 -0
- package/dist/docx/runParser.js +661 -0
- package/dist/docx/sdtProperties.d.ts +15 -0
- package/dist/docx/sdtProperties.js +290 -0
- package/dist/docx/sdtPropertiesPatch.d.ts +16 -0
- package/dist/docx/sdtPropertiesPatch.js +144 -0
- package/dist/docx/sectionParser.d.ts +95 -0
- package/dist/docx/sectionParser.js +534 -0
- package/dist/docx/selectiveSave.d.ts +25 -0
- package/dist/docx/selectiveSave.js +247 -0
- package/dist/docx/selectiveSaveFlags.d.ts +33 -0
- package/dist/docx/selectiveSaveFlags.js +11 -0
- package/dist/docx/selectiveSaveTripwire.d.ts +33 -0
- package/dist/docx/selectiveSaveTripwire.js +79 -0
- package/dist/docx/selectiveXmlPatch.d.ts +103 -0
- package/dist/docx/selectiveXmlPatch.js +493 -0
- package/dist/docx/serializer/blockSdtSerializer.d.ts +6 -0
- package/dist/docx/serializer/blockSdtSerializer.js +88 -0
- package/dist/docx/serializer/borderSerializer.d.ts +25 -0
- package/dist/docx/serializer/borderSerializer.js +44 -0
- package/dist/docx/serializer/commentSerializer.d.ts +31 -0
- package/dist/docx/serializer/commentSerializer.js +184 -0
- package/dist/docx/serializer/documentSerializer.d.ts +65 -0
- package/dist/docx/serializer/documentSerializer.js +199 -0
- package/dist/docx/serializer/headerFooterSerializer.d.ts +12 -0
- package/dist/docx/serializer/headerFooterSerializer.js +84 -0
- package/dist/docx/serializer/noteSerializer.d.ts +19 -0
- package/dist/docx/serializer/noteSerializer.js +70 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +12 -0
- package/dist/docx/serializer/numberingSerializer.js +93 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +48 -0
- package/dist/docx/serializer/paragraphSerializer.js +559 -0
- package/dist/docx/serializer/runSerializer.d.ts +56 -0
- package/dist/docx/serializer/runSerializer.js +621 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.d.ts +6 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +187 -0
- package/dist/docx/serializer/tableSerializer.d.ts +79 -0
- package/dist/docx/serializer/tableSerializer.js +422 -0
- package/dist/docx/serializer/xmlUtils.d.ts +20 -0
- package/dist/docx/serializer/xmlUtils.js +25 -0
- package/dist/docx/settingsParser.d.ts +8 -0
- package/dist/docx/settingsParser.js +36 -0
- package/dist/docx/shapeParser.d.ts +20 -0
- package/dist/docx/shapeParser.js +272 -0
- package/dist/docx/styleParser.d.ts +50 -0
- package/dist/docx/styleParser.js +905 -0
- package/dist/docx/tableParser.d.ts +202 -0
- package/dist/docx/tableParser.js +811 -0
- package/dist/docx/textBoxParser.d.ts +117 -0
- package/dist/docx/textBoxParser.js +262 -0
- package/dist/docx/themeParser.d.ts +77 -0
- package/dist/docx/themeParser.js +330 -0
- package/dist/docx/trackedMoveRangeNormalization.d.ts +22 -0
- package/dist/docx/trackedMoveRangeNormalization.js +100 -0
- package/dist/docx/unzip.d.ts +118 -0
- package/dist/docx/unzip.js +383 -0
- package/dist/docx/vmlImageParser.d.ts +16 -0
- package/dist/docx/vmlImageParser.js +100 -0
- package/dist/docx/watermarkParser.d.ts +45 -0
- package/dist/docx/watermarkParser.js +348 -0
- package/dist/docx/wrapTypes.d.ts +29 -0
- package/dist/docx/wrapTypes.js +48 -0
- package/dist/docx/xmlParser.d.ts +297 -0
- package/dist/docx/xmlParser.js +527 -0
- package/dist/fields/bookmarkPages.d.ts +13 -0
- package/dist/fields/bookmarkPages.js +66 -0
- package/dist/fields/bookmarkText.d.ts +16 -0
- package/dist/fields/bookmarkText.js +61 -0
- package/dist/fields/evaluateField.d.ts +23 -0
- package/dist/fields/evaluateField.js +77 -0
- package/dist/fields/fieldContext.d.ts +21 -0
- package/dist/fields/fieldContext.js +0 -0
- package/dist/fields/resolveFieldValues.d.ts +44 -0
- package/dist/fields/resolveFieldValues.js +204 -0
- package/dist/fields/sectionPageCounts.d.ts +11 -0
- package/dist/fields/sectionPageCounts.js +16 -0
- package/dist/fields/seqValues.d.ts +14 -0
- package/dist/fields/seqValues.js +36 -0
- package/dist/fonts/embeddedFontTable.d.ts +42 -0
- package/dist/fonts/embeddedFontTable.js +80 -0
- package/dist/fonts/embeddedFonts.d.ts +46 -0
- package/dist/fonts/embeddedFonts.js +112 -0
- package/dist/fonts/fontDeobfuscation.d.ts +30 -0
- package/dist/fonts/fontDeobfuscation.js +57 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +23 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +57 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +316 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +74 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +432 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +36 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.js +176 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +65 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +1309 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +17 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.js +36 -0
- package/dist/layout-bridge/dom/clickToPositionDom.d.ts +66 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +304 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.d.ts +7 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.js +17 -0
- package/dist/layout-bridge/dom/findHfPmSpans.d.ts +62 -0
- package/dist/layout-bridge/dom/findHfPmSpans.js +197 -0
- package/dist/layout-bridge/engine/clickToPosition.d.ts +66 -0
- package/dist/layout-bridge/engine/clickToPosition.js +403 -0
- package/dist/layout-bridge/engine/hitTest.d.ts +135 -0
- package/dist/layout-bridge/engine/hitTest.js +375 -0
- package/dist/layout-bridge/engine/measuring/index.d.ts +10 -0
- package/dist/layout-bridge/engine/measuring/index.js +9 -0
- package/dist/layout-bridge/engine/selectionRects.d.ts +59 -0
- package/dist/layout-bridge/engine/selectionRects.js +485 -0
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +7 -0
- package/dist/layout-bridge/engine/tableWidthUtils.js +25 -0
- package/dist/layout-engine/index.d.ts +44 -0
- package/dist/layout-engine/index.js +691 -0
- package/dist/layout-engine/keep-together.d.ts +43 -0
- package/dist/layout-engine/keep-together.js +98 -0
- package/dist/layout-engine/layoutInstrumentation.d.ts +50 -0
- package/dist/layout-engine/layoutInstrumentation.js +43 -0
- package/dist/layout-engine/lineFlow.d.ts +8 -0
- package/dist/layout-engine/lineFlow.js +17 -0
- package/dist/layout-engine/measure/cache.d.ts +93 -0
- package/dist/layout-engine/measure/cache.js +245 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.d.ts +20 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.js +29 -0
- package/dist/layout-engine/measure/featureFlags.d.ts +44 -0
- package/dist/layout-engine/measure/featureFlags.js +19 -0
- package/dist/layout-engine/measure/floatingZones.d.ts +89 -0
- package/dist/layout-engine/measure/floatingZones.js +152 -0
- package/dist/layout-engine/measure/font-metrics.worker.d.ts +17 -0
- package/dist/layout-engine/measure/font-metrics.worker.js +104 -0
- package/dist/layout-engine/measure/index.d.ts +9 -0
- package/dist/layout-engine/measure/index.js +8 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +40 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +76 -0
- package/dist/layout-engine/measure/measureBlocks.d.ts +25 -0
- package/dist/layout-engine/measure/measureBlocks.js +450 -0
- package/dist/layout-engine/measure/measureContainer.d.ts +24 -0
- package/dist/layout-engine/measure/measureContainer.js +280 -0
- package/dist/layout-engine/measure/measureHelpers.d.ts +82 -0
- package/dist/layout-engine/measure/measureHelpers.js +156 -0
- package/dist/layout-engine/measure/measureParagraph.d.ts +61 -0
- package/dist/layout-engine/measure/measureParagraph.js +724 -0
- package/dist/layout-engine/measure/measureProvider.d.ts +23 -0
- package/dist/layout-engine/measure/measureProvider.js +35 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +61 -0
- package/dist/layout-engine/measure/measureTypes.js +0 -0
- package/dist/layout-engine/measure/measureWorker.d.ts +54 -0
- package/dist/layout-engine/measure/measureWorker.js +249 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +88 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.js +20 -0
- package/dist/layout-engine/measure/tableCellFloating.d.ts +26 -0
- package/dist/layout-engine/measure/tableCellFloating.js +99 -0
- package/dist/layout-engine/paginator.d.ts +84 -0
- package/dist/layout-engine/paginator.js +348 -0
- package/dist/layout-engine/paragraphFragmentRange.d.ts +9 -0
- package/dist/layout-engine/paragraphFragmentRange.js +40 -0
- package/dist/layout-engine/section-breaks.d.ts +78 -0
- package/dist/layout-engine/section-breaks.js +182 -0
- package/dist/layout-engine/tableRowBreak.d.ts +23 -0
- package/dist/layout-engine/tableRowBreak.js +147 -0
- package/dist/layout-engine/textBoxFlow.d.ts +50 -0
- package/dist/layout-engine/textBoxFlow.js +160 -0
- package/dist/layout-engine/types.d.ts +1031 -0
- package/dist/layout-engine/types.js +100 -0
- package/dist/layout-painter/documentColors.d.ts +4 -0
- package/dist/layout-painter/documentColors.js +40 -0
- package/dist/layout-painter/index.d.ts +110 -0
- package/dist/layout-painter/index.js +182 -0
- package/dist/layout-painter/registry/modules/image.d.ts +6 -0
- package/dist/layout-painter/registry/modules/image.js +17 -0
- package/dist/layout-painter/registry/modules/paragraph.d.ts +6 -0
- package/dist/layout-painter/registry/modules/paragraph.js +18 -0
- package/dist/layout-painter/registry/modules/table.d.ts +6 -0
- package/dist/layout-painter/registry/modules/table.js +16 -0
- package/dist/layout-painter/registry/modules/textBox.d.ts +6 -0
- package/dist/layout-painter/registry/modules/textBox.js +13 -0
- package/dist/layout-painter/registry/modules.d.ts +6 -0
- package/dist/layout-painter/registry/modules.js +26 -0
- package/dist/layout-painter/registry/registry.d.ts +24 -0
- package/dist/layout-painter/registry/registry.js +53 -0
- package/dist/layout-painter/registry/types.d.ts +61 -0
- package/dist/layout-painter/registry/types.js +0 -0
- package/dist/layout-painter/renderFragment.d.ts +32 -0
- package/dist/layout-painter/renderFragment.js +114 -0
- package/dist/layout-painter/renderImage.d.ts +88 -0
- package/dist/layout-painter/renderImage.js +130 -0
- package/dist/layout-painter/renderPage.d.ts +264 -0
- package/dist/layout-painter/renderPage.js +1795 -0
- package/dist/layout-painter/renderParagraph.d.ts +93 -0
- package/dist/layout-painter/renderParagraph.js +1300 -0
- package/dist/layout-painter/renderTable.d.ts +36 -0
- package/dist/layout-painter/renderTable.js +432 -0
- package/dist/layout-painter/renderTextBox.d.ts +22 -0
- package/dist/layout-painter/renderTextBox.js +67 -0
- package/dist/layout-painter/renderUtils.d.ts +42 -0
- package/dist/layout-painter/renderUtils.js +30 -0
- package/dist/layout-painter/renderWatermark.d.ts +16 -0
- package/dist/layout-painter/renderWatermark.js +61 -0
- package/dist/layout-painter/sdtBoundary.d.ts +6 -0
- package/dist/layout-painter/sdtBoundary.js +28 -0
- package/dist/managers/ContextMenuManager.d.ts +28 -0
- package/dist/managers/ContextMenuManager.js +48 -0
- package/dist/managers/DocumentLoaderManager.d.ts +47 -0
- package/dist/managers/DocumentLoaderManager.js +69 -0
- package/dist/managers/EditorModeManager.d.ts +28 -0
- package/dist/managers/EditorModeManager.js +50 -0
- package/dist/managers/ErrorManager.d.ts +26 -0
- package/dist/managers/ErrorManager.js +85 -0
- package/dist/managers/FindReplaceManager.d.ts +54 -0
- package/dist/managers/FindReplaceManager.js +104 -0
- package/dist/managers/HistoryManager.d.ts +92 -0
- package/dist/managers/HistoryManager.js +193 -0
- package/dist/managers/Subscribable.d.ts +34 -0
- package/dist/managers/Subscribable.js +46 -0
- package/dist/managers/TableSelectionManager.d.ts +74 -0
- package/dist/managers/TableSelectionManager.js +225 -0
- package/dist/managers/editorShortcuts.d.ts +42 -0
- package/dist/managers/editorShortcuts.js +60 -0
- package/dist/managers/types.d.ts +41 -0
- package/dist/managers/types.js +0 -0
- package/dist/markdown/annotations.d.ts +14 -0
- package/dist/markdown/annotations.js +42 -0
- package/dist/markdown/escape.d.ts +36 -0
- package/dist/markdown/escape.js +59 -0
- package/dist/markdown/fromMarkdown.d.ts +11 -0
- package/dist/markdown/fromMarkdown.js +223 -0
- package/dist/markdown/headings.d.ts +13 -0
- package/dist/markdown/headings.js +20 -0
- package/dist/markdown/images.d.ts +13 -0
- package/dist/markdown/images.js +63 -0
- package/dist/markdown/index.d.ts +18 -0
- package/dist/markdown/index.js +33 -0
- package/dist/markdown/internals.d.ts +15 -0
- package/dist/markdown/internals.js +35 -0
- package/dist/markdown/renderBlock.d.ts +7 -0
- package/dist/markdown/renderBlock.js +68 -0
- package/dist/markdown/renderParagraph.d.ts +11 -0
- package/dist/markdown/renderParagraph.js +64 -0
- package/dist/markdown/renderRuns.d.ts +11 -0
- package/dist/markdown/renderRuns.js +265 -0
- package/dist/markdown/renderTable.d.ts +8 -0
- package/dist/markdown/renderTable.js +229 -0
- package/dist/markdown/trailers.d.ts +13 -0
- package/dist/markdown/trailers.js +54 -0
- package/dist/markdown/types.d.ts +118 -0
- package/dist/markdown/types.js +0 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +4 -0
- package/dist/paged-layout/LayoutSelectionGate.d.ts +80 -0
- package/dist/paged-layout/LayoutSelectionGate.js +131 -0
- package/dist/paged-layout/headerFooterMargins.d.ts +73 -0
- package/dist/paged-layout/headerFooterMargins.js +120 -0
- package/dist/paged-layout/hiddenEditorScroll.d.ts +4 -0
- package/dist/paged-layout/hiddenEditorScroll.js +4 -0
- package/dist/paged-layout/incrementalMeasure.d.ts +33 -0
- package/dist/paged-layout/incrementalMeasure.js +56 -0
- package/dist/paged-layout/rangeProjection.d.ts +51 -0
- package/dist/paged-layout/rangeProjection.js +153 -0
- package/dist/paged-layout/readOnlyEditAttempt.d.ts +5 -0
- package/dist/paged-layout/readOnlyEditAttempt.js +22 -0
- package/dist/paged-layout/scrollNavigation.d.ts +23 -0
- package/dist/paged-layout/scrollNavigation.js +31 -0
- package/dist/paged-layout/scrollPageInfo.d.ts +41 -0
- package/dist/paged-layout/scrollPageInfo.js +34 -0
- package/dist/paged-layout/scrollToPmPosition.d.ts +17 -0
- package/dist/paged-layout/scrollToPmPosition.js +95 -0
- package/dist/paged-layout/sectionBlockWidths.d.ts +35 -0
- package/dist/paged-layout/sectionBlockWidths.js +52 -0
- package/dist/paged-layout/sectionGeometry.d.ts +21 -0
- package/dist/paged-layout/sectionGeometry.js +36 -0
- package/dist/paged-layout/selectionViewportRect.d.ts +29 -0
- package/dist/paged-layout/selectionViewportRect.js +55 -0
- package/dist/paged-layout/tableColumnResize.d.ts +19 -0
- package/dist/paged-layout/tableColumnResize.js +28 -0
- package/dist/paged-layout/tableInsertButtonGeometry.d.ts +15 -0
- package/dist/paged-layout/tableInsertButtonGeometry.js +15 -0
- package/dist/paged-layout/transactionDirtyRange.d.ts +7 -0
- package/dist/paged-layout/transactionDirtyRange.js +27 -0
- package/dist/paged-layout/zoomScrollAnchor.d.ts +40 -0
- package/dist/paged-layout/zoomScrollAnchor.js +25 -0
- package/dist/prosemirror/attrs/index.d.ts +80 -0
- package/dist/prosemirror/attrs/index.js +1218 -0
- package/dist/prosemirror/autospacingBase.d.ts +11 -0
- package/dist/prosemirror/autospacingBase.js +16 -0
- package/dist/prosemirror/commands/comments.d.ts +93 -0
- package/dist/prosemirror/commands/comments.js +435 -0
- package/dist/prosemirror/commands/contentControls.d.ts +45 -0
- package/dist/prosemirror/commands/contentControls.js +294 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +15 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.js +19 -0
- package/dist/prosemirror/commands/formatPainter.d.ts +31 -0
- package/dist/prosemirror/commands/formatPainter.js +130 -0
- package/dist/prosemirror/commands/formatting.d.ts +32 -0
- package/dist/prosemirror/commands/formatting.js +45 -0
- package/dist/prosemirror/commands/hyperlink.d.ts +31 -0
- package/dist/prosemirror/commands/hyperlink.js +79 -0
- package/dist/prosemirror/commands/image.d.ts +59 -0
- package/dist/prosemirror/commands/image.js +219 -0
- package/dist/prosemirror/commands/index.d.ts +13 -0
- package/dist/prosemirror/commands/index.js +13 -0
- package/dist/prosemirror/commands/pageBreak.d.ts +10 -0
- package/dist/prosemirror/commands/pageBreak.js +47 -0
- package/dist/prosemirror/commands/paragraph.d.ts +39 -0
- package/dist/prosemirror/commands/paragraph.js +64 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +39 -0
- package/dist/prosemirror/commands/pastePlainText.js +67 -0
- package/dist/prosemirror/commands/table.d.ts +83 -0
- package/dist/prosemirror/commands/table.js +105 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +27 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +1550 -0
- package/dist/prosemirror/conversion/index.d.ts +4 -0
- package/dist/prosemirror/conversion/index.js +4 -0
- package/dist/prosemirror/conversion/runShadingMark.d.ts +16 -0
- package/dist/prosemirror/conversion/runShadingMark.js +39 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +39 -0
- package/dist/prosemirror/conversion/toProseDoc.js +1404 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +43 -0
- package/dist/prosemirror/extensions/ExtensionManager.js +86 -0
- package/dist/prosemirror/extensions/StarterKit.d.ts +16 -0
- package/dist/prosemirror/extensions/StarterKit.js +132 -0
- package/dist/prosemirror/extensions/core/DocExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +12 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.js +28 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +25 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +619 -0
- package/dist/prosemirror/extensions/core/TextExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/TextExtension.js +12 -0
- package/dist/prosemirror/extensions/create.d.ts +17 -0
- package/dist/prosemirror/extensions/create.js +129 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +106 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +172 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +38 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.js +21 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.js +20 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +44 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +19 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.js +24 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +15 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +66 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +91 -0
- package/dist/prosemirror/extensions/features/ListExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +340 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +60 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +35 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +188 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +34 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.js +145 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.js +17 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.d.ts +31 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.js +27 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +31 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.js +159 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.js +41 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +64 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +55 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +92 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.js +115 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +146 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.js +34 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.js +21 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +75 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +33 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +50 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +31 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.js +134 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +22 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +113 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.js +60 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +34 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +233 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +122 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +87 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +38 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.js +18 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +132 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.js +56 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +20 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.js +107 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +30 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +502 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.js +27 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +1972 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +150 -0
- package/dist/prosemirror/extensions/types.d.ts +101 -0
- package/dist/prosemirror/extensions/types.js +10 -0
- package/dist/prosemirror/findReplaceSelection.d.ts +23 -0
- package/dist/prosemirror/findReplaceSelection.js +86 -0
- package/dist/prosemirror/index.d.ts +25 -0
- package/dist/prosemirror/index.js +23 -0
- package/dist/prosemirror/insertOperations.d.ts +12 -0
- package/dist/prosemirror/insertOperations.js +19 -0
- package/dist/prosemirror/paragraphDirection.d.ts +42 -0
- package/dist/prosemirror/paragraphDirection.js +33 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +40 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.js +90 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +42 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +135 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +60 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.js +120 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +123 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +283 -0
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +56 -0
- package/dist/prosemirror/plugins/contentControlWidgets.js +192 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +37 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.js +55 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +18 -0
- package/dist/prosemirror/plugins/documentStyles.js +46 -0
- package/dist/prosemirror/plugins/index.d.ts +3 -0
- package/dist/prosemirror/plugins/index.js +3 -0
- package/dist/prosemirror/plugins/pmTextScan.d.ts +19 -0
- package/dist/prosemirror/plugins/pmTextScan.js +39 -0
- package/dist/prosemirror/plugins/selectionTracker.d.ts +43 -0
- package/dist/prosemirror/plugins/selectionTracker.js +179 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +70 -0
- package/dist/prosemirror/plugins/suggestionMode.js +489 -0
- package/dist/prosemirror/plugins/templateDirectives.d.ts +25 -0
- package/dist/prosemirror/plugins/templateDirectives.js +67 -0
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +49 -0
- package/dist/prosemirror/plugins/templatePreviewValues.js +117 -0
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +57 -0
- package/dist/prosemirror/plugins/templateSlashMenu.js +184 -0
- package/dist/prosemirror/schema/index.d.ts +15 -0
- package/dist/prosemirror/schema/index.js +20 -0
- package/dist/prosemirror/schema/marks.d.ts +118 -0
- package/dist/prosemirror/schema/marks.js +0 -0
- package/dist/prosemirror/schema/nodes.d.ts +389 -0
- package/dist/prosemirror/schema/nodes.js +0 -0
- package/dist/prosemirror/selectionState.d.ts +23 -0
- package/dist/prosemirror/selectionState.js +111 -0
- package/dist/prosemirror/styles/index.d.ts +2 -0
- package/dist/prosemirror/styles/index.js +2 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +32 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +108 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +94 -0
- package/dist/prosemirror/styles/styleResolver.js +200 -0
- package/dist/prosemirror/utils/findParagraphByParaId.d.ts +26 -0
- package/dist/prosemirror/utils/findParagraphByParaId.js +37 -0
- package/dist/prosemirror/utils/tabCalculator.d.ts +110 -0
- package/dist/prosemirror/utils/tabCalculator.js +137 -0
- package/dist/prosemirror/validation.d.ts +20 -0
- package/dist/prosemirror/validation.js +177 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +6 -0
- package/dist/style-engine/index.d.ts +3 -0
- package/dist/style-engine/index.js +2 -0
- package/dist/style-engine/styleEngine.d.ts +67 -0
- package/dist/style-engine/styleEngine.js +70 -0
- package/dist/types/block-id.d.ts +66 -0
- package/dist/types/block-id.js +73 -0
- package/dist/types/colors.d.ts +2 -0
- package/dist/types/colors.js +0 -0
- package/dist/types/content.d.ts +2 -0
- package/dist/types/content.js +0 -0
- package/dist/types/document.d.ts +7 -0
- package/dist/types/document.js +0 -0
- package/dist/types/documentEnumValues.d.ts +89 -0
- package/dist/types/documentEnumValues.js +693 -0
- package/dist/types/formatting.d.ts +2 -0
- package/dist/types/formatting.js +0 -0
- package/dist/types/index.d.ts +107 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/authorColors.d.ts +16 -0
- package/dist/utils/authorColors.js +30 -0
- package/dist/utils/baseDirection.d.ts +23 -0
- package/dist/utils/baseDirection.js +34 -0
- package/dist/utils/clipboard.d.ts +126 -0
- package/dist/utils/clipboard.js +622 -0
- package/dist/utils/colorResolver.d.ts +158 -0
- package/dist/utils/colorResolver.js +557 -0
- package/dist/utils/createDocument.d.ts +50 -0
- package/dist/utils/createDocument.js +262 -0
- package/dist/utils/documentLoaderBehavior.d.ts +22 -0
- package/dist/utils/documentLoaderBehavior.js +14 -0
- package/dist/utils/docxInput.d.ts +22 -0
- package/dist/utils/docxInput.js +16 -0
- package/dist/utils/domGuards.d.ts +59 -0
- package/dist/utils/domGuards.js +82 -0
- package/dist/utils/fontFamilyMerge.d.ts +7 -0
- package/dist/utils/fontFamilyMerge.js +31 -0
- package/dist/utils/fontLoader.d.ts +50 -0
- package/dist/utils/fontLoader.js +177 -0
- package/dist/utils/fontResolver.d.ts +61 -0
- package/dist/utils/fontResolver.js +651 -0
- package/dist/utils/fontWeights.d.ts +4 -0
- package/dist/utils/fontWeights.js +4 -0
- package/dist/utils/formatToStyle.d.ts +103 -0
- package/dist/utils/formatToStyle.js +289 -0
- package/dist/utils/headerFooter.d.ts +74 -0
- package/dist/utils/headerFooter.js +257 -0
- package/dist/utils/headingCollector.d.ts +22 -0
- package/dist/utils/headingCollector.js +36 -0
- package/dist/utils/hexId.d.ts +33 -0
- package/dist/utils/hexId.js +37 -0
- package/dist/utils/imageValidation.d.ts +5 -0
- package/dist/utils/imageValidation.js +31 -0
- package/dist/utils/paragraphFormattingMerge.d.ts +14 -0
- package/dist/utils/paragraphFormattingMerge.js +68 -0
- package/dist/utils/replaceText.d.ts +17 -0
- package/dist/utils/replaceText.js +161 -0
- package/dist/utils/rotationBoundingBox.d.ts +12 -0
- package/dist/utils/rotationBoundingBox.js +36 -0
- package/dist/utils/scriptSegments.d.ts +36 -0
- package/dist/utils/scriptSegments.js +52 -0
- package/dist/utils/tableOperations.d.ts +87 -0
- package/dist/utils/tableOperations.js +259 -0
- package/dist/utils/textFormattingMerge.d.ts +6 -0
- package/dist/utils/textFormattingMerge.js +31 -0
- package/dist/utils/tiffConverter.d.ts +18 -0
- package/dist/utils/tiffConverter.js +83 -0
- package/dist/utils/units.d.ts +99 -0
- package/dist/utils/units.js +139 -0
- package/dist/utils/urlSecurity.d.ts +7 -0
- package/dist/utils/urlSecurity.js +65 -0
- package/dist/watermark/index.d.ts +39 -0
- package/dist/watermark/index.js +149 -0
- package/package.json +122 -2
|
@@ -0,0 +1,1309 @@
|
|
|
1
|
+
import { NUMBER_FORMAT_VALUES } from "../../types/documentEnumValues.js";
|
|
2
|
+
import { halfPointsToPixels, halfPointsToPoints, pointsToPixels } from "../../utils/units.js";
|
|
3
|
+
import { padDecimal } from "../../docx/numberingParser.js";
|
|
4
|
+
import { DEFAULT_TEXTBOX_MARGINS } from "../../layout-engine/types.js";
|
|
5
|
+
import { resolveColor, resolveHighlightToCss } from "../../utils/colorResolver.js";
|
|
6
|
+
import { resolveShadingFill } from "../../utils/formatToStyle.js";
|
|
7
|
+
import { convertBulletToUnicode } from "../../docx/bulletMarkers.js";
|
|
8
|
+
import { directionIsRtl } from "../../prosemirror/paragraphDirection.js";
|
|
9
|
+
import { expectBlockSdtAttrs, expectCharacterSpacingMarkAttrs, expectCommentMarkAttrs, expectEmphasisMarkAttrs, expectFieldAttrs, expectFontFamilyMarkAttrs, expectFontSizeMarkAttrs, expectFootnoteRefMarkAttrs, expectHighlightMarkAttrs, expectHyperlinkMarkAttrs, expectImageAttrs, expectMathAttrs, expectParagraphAttrs, expectRunFormattingOverrideMarkAttrs, expectRunShadingMarkAttrs, expectTableAttrs, expectTableCellAttrs, expectTableRowAttrs, expectTextBoxAttrs, expectTextColorMarkAttrs, expectTextEffectMarkAttrs, expectTrackedChangeMarkAttrs, expectUnderlineMarkAttrs } from "../../prosemirror/attrs/index.js";
|
|
10
|
+
import { autospacingMatchesBase } from "../../prosemirror/autospacingBase.js";
|
|
11
|
+
import { runShadingAttrsToShading } from "../../prosemirror/conversion/runShadingMark.js";
|
|
12
|
+
import { assertValidProseMirrorDocument } from "../../prosemirror/validation.js";
|
|
13
|
+
//#region src/layout-bridge/convert/toFlowBlocks.ts
|
|
14
|
+
const DEFAULT_FONT = "Calibri";
|
|
15
|
+
const DEFAULT_TABLE_CELL_MARGIN_TWIPS = {
|
|
16
|
+
top: 0,
|
|
17
|
+
right: 108,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
left: 108
|
|
20
|
+
};
|
|
21
|
+
const DEFAULT_BLACK_TEXT_COLOR_VALUES = /* @__PURE__ */ new Set(["000000", "000"]);
|
|
22
|
+
function normalizeResolvedTextColor(color) {
|
|
23
|
+
return color.trim().toLowerCase().replace(/^#/u, "");
|
|
24
|
+
}
|
|
25
|
+
function isDefaultBlackResolvedTextColor(color) {
|
|
26
|
+
return DEFAULT_BLACK_TEXT_COLOR_VALUES.has(normalizeResolvedTextColor(color));
|
|
27
|
+
}
|
|
28
|
+
function areResolvedTextColorsEqual(left, right) {
|
|
29
|
+
return normalizeResolvedTextColor(left) === normalizeResolvedTextColor(right);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Constrain image dimensions to fit within the page content area.
|
|
33
|
+
* Scales proportionally if height exceeds pageContentHeight.
|
|
34
|
+
*/
|
|
35
|
+
function constrainImageToPage(width, height, pageContentHeight) {
|
|
36
|
+
if (!pageContentHeight || height <= pageContentHeight) return {
|
|
37
|
+
width,
|
|
38
|
+
height
|
|
39
|
+
};
|
|
40
|
+
const scale = pageContentHeight / height;
|
|
41
|
+
return {
|
|
42
|
+
width: Math.round(width * scale),
|
|
43
|
+
height: pageContentHeight
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const DEFAULT_SIZE = 11;
|
|
47
|
+
/**
|
|
48
|
+
* Convert twips to pixels (1 twip = 1/1440 inch, 1 inch = 96 CSS px).
|
|
49
|
+
* No rounding — precision prevents cumulative layout drift across paragraphs.
|
|
50
|
+
*/
|
|
51
|
+
function twipsToPixels(twips) {
|
|
52
|
+
return twips / 1440 * 96;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Generate a unique block ID.
|
|
56
|
+
*/
|
|
57
|
+
let blockIdCounter = 0;
|
|
58
|
+
function nextBlockId() {
|
|
59
|
+
return `block-${++blockIdCounter}`;
|
|
60
|
+
}
|
|
61
|
+
function formatNumberedMarker(counters, level) {
|
|
62
|
+
const parts = [];
|
|
63
|
+
for (let i = 0; i <= level; i += 1) {
|
|
64
|
+
const value = counters[i] ?? 0;
|
|
65
|
+
if (value <= 0) break;
|
|
66
|
+
parts.push(value);
|
|
67
|
+
}
|
|
68
|
+
if (parts.length === 0) return "1.";
|
|
69
|
+
return `${parts.join(".")}.`;
|
|
70
|
+
}
|
|
71
|
+
const ROMAN_PAIRS = [
|
|
72
|
+
[1e3, "M"],
|
|
73
|
+
[900, "CM"],
|
|
74
|
+
[500, "D"],
|
|
75
|
+
[400, "CD"],
|
|
76
|
+
[100, "C"],
|
|
77
|
+
[90, "XC"],
|
|
78
|
+
[50, "L"],
|
|
79
|
+
[40, "XL"],
|
|
80
|
+
[10, "X"],
|
|
81
|
+
[9, "IX"],
|
|
82
|
+
[5, "V"],
|
|
83
|
+
[4, "IV"],
|
|
84
|
+
[1, "I"]
|
|
85
|
+
];
|
|
86
|
+
function toRoman(value, upper) {
|
|
87
|
+
if (value <= 0) return "";
|
|
88
|
+
let remaining = value;
|
|
89
|
+
let output = "";
|
|
90
|
+
for (const [number, symbol] of ROMAN_PAIRS) while (remaining >= number) {
|
|
91
|
+
output += symbol;
|
|
92
|
+
remaining -= number;
|
|
93
|
+
}
|
|
94
|
+
return upper ? output : output.toLowerCase();
|
|
95
|
+
}
|
|
96
|
+
function toLetter(value, upper) {
|
|
97
|
+
if (value <= 0) return "";
|
|
98
|
+
const zeroBased = value - 1;
|
|
99
|
+
const baseCodePoint = upper ? 65 : 97;
|
|
100
|
+
return String.fromCodePoint(baseCodePoint + zeroBased % 26).repeat(Math.floor(zeroBased / 26) + 1);
|
|
101
|
+
}
|
|
102
|
+
function formatCounter(value, format) {
|
|
103
|
+
if (value <= 0) return "";
|
|
104
|
+
switch (format) {
|
|
105
|
+
case "upperRoman": return toRoman(value, true);
|
|
106
|
+
case "lowerRoman": return toRoman(value, false);
|
|
107
|
+
case "upperLetter": return toLetter(value, true);
|
|
108
|
+
case "lowerLetter": return toLetter(value, false);
|
|
109
|
+
case "decimalZero": return padDecimal(value, 2);
|
|
110
|
+
case "decimalZero3": return padDecimal(value, 3);
|
|
111
|
+
case "decimalZero4": return padDecimal(value, 4);
|
|
112
|
+
case "decimalZero5": return padDecimal(value, 5);
|
|
113
|
+
case "none": return "";
|
|
114
|
+
default: return String(value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function resolveListTemplate(template, counters, levelFormats, forceDecimal = false) {
|
|
118
|
+
return template.replace(/%(?<digit>\d)(?<punct>[.):\]])?/gu, (...args) => {
|
|
119
|
+
const { digit, punct = "" } = args.at(-1);
|
|
120
|
+
const index = Number.parseInt(digit, 10) - 1;
|
|
121
|
+
if (index < 0) return "";
|
|
122
|
+
const formatted = formatCounter(counters[index] ?? 0, forceDecimal ? "decimal" : levelFormats?.[index]);
|
|
123
|
+
return formatted ? `${formatted}${punct}` : "";
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function getLastListCounters(listCounters) {
|
|
127
|
+
let lastCounters;
|
|
128
|
+
for (const counters of listCounters.values()) lastCounters = counters;
|
|
129
|
+
return lastCounters;
|
|
130
|
+
}
|
|
131
|
+
function applyMarkerAllCaps(marker, allCaps) {
|
|
132
|
+
if (marker === null || !allCaps) return marker;
|
|
133
|
+
return marker.toLocaleUpperCase();
|
|
134
|
+
}
|
|
135
|
+
function computeListMarker(pmAttrs, listCounters, abstractCounters, seenNumIds) {
|
|
136
|
+
const numId = pmAttrs.numPr?.numId;
|
|
137
|
+
if (numId === void 0 || numId === 0) {
|
|
138
|
+
if (pmAttrs.listMarker?.includes("%") && !pmAttrs.listIsBullet) {
|
|
139
|
+
const counters = getLastListCounters(listCounters);
|
|
140
|
+
if (counters) return resolveListTemplate(pmAttrs.listMarker, counters, pmAttrs.listLevelNumFmts, pmAttrs.listIsLegal);
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (pmAttrs.listIsBullet) return convertBulletToUnicode(pmAttrs.listMarker || "");
|
|
145
|
+
const level = pmAttrs.numPr?.ilvl ?? 0;
|
|
146
|
+
const counters = listCounters.get(numId) ?? Array.from({ length: 9 }, () => 0);
|
|
147
|
+
const abstractNumId = pmAttrs.listAbstractNumId;
|
|
148
|
+
if (abstractNumId !== void 0 && level > 0) {
|
|
149
|
+
const latestAbstractCounters = abstractCounters.get(abstractNumId);
|
|
150
|
+
const missingParentCounters = counters.slice(0, level).every((value) => value === 0);
|
|
151
|
+
if (latestAbstractCounters && missingParentCounters) for (let i = 0; i < level; i += 1) counters[i] = latestAbstractCounters[i] ?? 0;
|
|
152
|
+
}
|
|
153
|
+
const seenKey = `${numId}:${level}`;
|
|
154
|
+
if (!seenNumIds.has(seenKey)) {
|
|
155
|
+
seenNumIds.add(seenKey);
|
|
156
|
+
if (pmAttrs.listStartOverride != null) counters[level] = pmAttrs.listStartOverride - 1;
|
|
157
|
+
}
|
|
158
|
+
counters[level] = (counters[level] ?? 0) + 1;
|
|
159
|
+
for (let i = level + 1; i < counters.length; i += 1) counters[i] = 0;
|
|
160
|
+
const childAdvances = pmAttrs.listImplicitChildLevelAdvances ?? 0;
|
|
161
|
+
if (childAdvances > 0 && level + 1 < counters.length) counters[level + 1] = (counters[level + 1] ?? 0) + childAdvances;
|
|
162
|
+
listCounters.set(numId, counters);
|
|
163
|
+
if (abstractNumId !== void 0) abstractCounters.set(abstractNumId, [...counters]);
|
|
164
|
+
const levelFormats = pmAttrs.listLevelNumFmts ?? (pmAttrs.listNumFmt ? [pmAttrs.listNumFmt] : void 0);
|
|
165
|
+
if (pmAttrs.listMarker && pmAttrs.listMarker.includes("%")) return resolveListTemplate(pmAttrs.listMarker, counters, levelFormats, pmAttrs.listIsLegal);
|
|
166
|
+
if (pmAttrs.listMarker) return pmAttrs.listMarker;
|
|
167
|
+
if ((levelFormats?.[level] ?? pmAttrs.listNumFmt) === "none" || pmAttrs.listMarker === "") return null;
|
|
168
|
+
return formatNumberedMarker(counters, level);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Reset the block ID counter (useful for testing).
|
|
172
|
+
*/
|
|
173
|
+
function resetBlockIdCounter() {
|
|
174
|
+
blockIdCounter = 0;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Extract run formatting from ProseMirror marks.
|
|
178
|
+
*/
|
|
179
|
+
function extractRunFormatting(marks, theme) {
|
|
180
|
+
const formatting = {};
|
|
181
|
+
let hasNoteRef = false;
|
|
182
|
+
for (const mark of marks) switch (mark.type.name) {
|
|
183
|
+
case "bold":
|
|
184
|
+
formatting.bold = true;
|
|
185
|
+
break;
|
|
186
|
+
case "italic":
|
|
187
|
+
formatting.italic = true;
|
|
188
|
+
break;
|
|
189
|
+
case "underline": {
|
|
190
|
+
const attrs = expectUnderlineMarkAttrs(mark);
|
|
191
|
+
if (attrs.style || attrs.color) {
|
|
192
|
+
const underlineObj = {};
|
|
193
|
+
if (attrs.style) underlineObj.style = attrs.style;
|
|
194
|
+
if (attrs.color) underlineObj.color = resolveColor(attrs.color, theme);
|
|
195
|
+
formatting.underline = underlineObj;
|
|
196
|
+
} else formatting.underline = true;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
case "strike":
|
|
200
|
+
formatting.strike = true;
|
|
201
|
+
break;
|
|
202
|
+
case "textColor": {
|
|
203
|
+
const attrs = expectTextColorMarkAttrs(mark);
|
|
204
|
+
if (attrs.themeColor || attrs.rgb) {
|
|
205
|
+
const colorArg = {};
|
|
206
|
+
if (attrs.rgb) colorArg.rgb = attrs.rgb;
|
|
207
|
+
if (attrs.themeColor) colorArg.themeColor = attrs.themeColor;
|
|
208
|
+
if (attrs.themeTint) colorArg.themeTint = attrs.themeTint;
|
|
209
|
+
if (attrs.themeShade) colorArg.themeShade = attrs.themeShade;
|
|
210
|
+
if (!isAutomaticTextColorValue(colorArg)) {
|
|
211
|
+
formatting.color = resolveColor(colorArg, theme);
|
|
212
|
+
formatting.textColorSource = "direct";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
case "highlight":
|
|
218
|
+
formatting.highlight = resolveHighlightToCss(expectHighlightMarkAttrs(mark).color);
|
|
219
|
+
break;
|
|
220
|
+
case "runShading": {
|
|
221
|
+
const shadingCss = resolveShadingFill(runShadingAttrsToShading(expectRunShadingMarkAttrs(mark)), theme);
|
|
222
|
+
if (shadingCss) formatting.shading = shadingCss;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
case "fontSize":
|
|
226
|
+
formatting.fontSize = expectFontSizeMarkAttrs(mark).size / 2;
|
|
227
|
+
break;
|
|
228
|
+
case "fontFamily": {
|
|
229
|
+
const attrs = expectFontFamilyMarkAttrs(mark);
|
|
230
|
+
const font = attrs.ascii || attrs.hAnsi;
|
|
231
|
+
if (font) formatting.fontFamily = font;
|
|
232
|
+
if (attrs.eastAsia) formatting.eastAsiaFontFamily = attrs.eastAsia;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "characterSpacing": {
|
|
236
|
+
const attrs = expectCharacterSpacingMarkAttrs(mark);
|
|
237
|
+
if (attrs.spacing !== void 0 && attrs.spacing !== 0) formatting.letterSpacing = twipsToPixels(attrs.spacing);
|
|
238
|
+
if (attrs.position !== void 0 && attrs.position !== 0) formatting.positionPx = halfPointsToPixels(attrs.position);
|
|
239
|
+
if (attrs.scale !== void 0 && attrs.scale !== 100) formatting.horizontalScale = attrs.scale;
|
|
240
|
+
if (attrs.kerning !== void 0 && attrs.kerning > 0) formatting.kerningMinPt = halfPointsToPoints(attrs.kerning);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case "allCaps":
|
|
244
|
+
formatting.allCaps = true;
|
|
245
|
+
break;
|
|
246
|
+
case "smallCaps":
|
|
247
|
+
formatting.smallCaps = true;
|
|
248
|
+
break;
|
|
249
|
+
case "emboss":
|
|
250
|
+
formatting.emboss = true;
|
|
251
|
+
break;
|
|
252
|
+
case "imprint":
|
|
253
|
+
formatting.imprint = true;
|
|
254
|
+
break;
|
|
255
|
+
case "hidden":
|
|
256
|
+
formatting.hidden = true;
|
|
257
|
+
break;
|
|
258
|
+
case "textShadow":
|
|
259
|
+
formatting.textShadow = true;
|
|
260
|
+
break;
|
|
261
|
+
case "textOutline":
|
|
262
|
+
formatting.textOutline = true;
|
|
263
|
+
break;
|
|
264
|
+
case "rtl":
|
|
265
|
+
formatting.rtl = true;
|
|
266
|
+
break;
|
|
267
|
+
case "textEffect":
|
|
268
|
+
formatting.textEffect = expectTextEffectMarkAttrs(mark).effect;
|
|
269
|
+
break;
|
|
270
|
+
case "runFormattingOverride":
|
|
271
|
+
applyRunFormattingOverrides(formatting, expectRunFormattingOverrideMarkAttrs(mark));
|
|
272
|
+
break;
|
|
273
|
+
case "emphasisMark":
|
|
274
|
+
formatting.emphasisMark = expectEmphasisMarkAttrs(mark).type ?? "dot";
|
|
275
|
+
break;
|
|
276
|
+
case "superscript":
|
|
277
|
+
formatting.superscript = true;
|
|
278
|
+
break;
|
|
279
|
+
case "subscript":
|
|
280
|
+
formatting.subscript = true;
|
|
281
|
+
break;
|
|
282
|
+
case "hyperlink": {
|
|
283
|
+
const attrs = expectHyperlinkMarkAttrs(mark);
|
|
284
|
+
const link = { href: attrs.href };
|
|
285
|
+
if (attrs.tooltip !== void 0) link.tooltip = attrs.tooltip;
|
|
286
|
+
formatting.hyperlink = link;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "footnoteRef": {
|
|
290
|
+
hasNoteRef = true;
|
|
291
|
+
const attrs = expectFootnoteRefMarkAttrs(mark);
|
|
292
|
+
if (attrs.vertAlign === "superscript") formatting.superscript = true;
|
|
293
|
+
const id = typeof attrs.id === "string" ? Number.parseInt(attrs.id, 10) : attrs.id;
|
|
294
|
+
if (attrs.noteType === "endnote") formatting.endnoteRefId = id;
|
|
295
|
+
else formatting.footnoteRefId = id;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case "comment": {
|
|
299
|
+
const commentId = expectCommentMarkAttrs(mark).commentId;
|
|
300
|
+
if (commentId) {
|
|
301
|
+
if (!formatting.commentIds) formatting.commentIds = [];
|
|
302
|
+
formatting.commentIds.push(commentId);
|
|
303
|
+
}
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
case "insertion": {
|
|
307
|
+
const attrs = expectTrackedChangeMarkAttrs(mark);
|
|
308
|
+
formatting.isInsertion = true;
|
|
309
|
+
formatting.changeAuthor = attrs.author;
|
|
310
|
+
if (attrs.date !== void 0) formatting.changeDate = attrs.date;
|
|
311
|
+
formatting.changeRevisionId = attrs.revisionId;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
case "deletion": {
|
|
315
|
+
const attrs = expectTrackedChangeMarkAttrs(mark);
|
|
316
|
+
formatting.isDeletion = true;
|
|
317
|
+
formatting.changeAuthor = attrs.author;
|
|
318
|
+
if (attrs.date !== void 0) formatting.changeDate = attrs.date;
|
|
319
|
+
formatting.changeRevisionId = attrs.revisionId;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
default: break;
|
|
323
|
+
}
|
|
324
|
+
if (hasNoteRef && formatting.subscript) delete formatting.superscript;
|
|
325
|
+
return formatting;
|
|
326
|
+
}
|
|
327
|
+
function isAutomaticTextColorValue(color) {
|
|
328
|
+
const rgb = color.rgb?.trim().toLowerCase();
|
|
329
|
+
return color.auto === true || rgb === "auto" || !rgb && !color.themeColor;
|
|
330
|
+
}
|
|
331
|
+
function markDefaultBlackTextColorSource(formatting, paraDefaults) {
|
|
332
|
+
if (formatting.textColorSource === "direct" || formatting.color === void 0 || paraDefaults.color === void 0 || !isDefaultBlackResolvedTextColor(formatting.color) || !areResolvedTextColorsEqual(formatting.color, paraDefaults.color)) return formatting;
|
|
333
|
+
return {
|
|
334
|
+
...formatting,
|
|
335
|
+
textColorSource: "paragraphDefault"
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function mergeRunFormatting(paraDefaults, formatting) {
|
|
339
|
+
return {
|
|
340
|
+
...paraDefaults,
|
|
341
|
+
...markDefaultBlackTextColorSource(formatting, paraDefaults)
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function applyRunFormattingOverrides(formatting, attrs) {
|
|
345
|
+
if (attrs.bold === false) formatting.bold = false;
|
|
346
|
+
if (attrs.italic === false) formatting.italic = false;
|
|
347
|
+
if (attrs.underline === "none") formatting.underline = false;
|
|
348
|
+
if (attrs.strike === false) formatting.strike = false;
|
|
349
|
+
if (attrs.allCaps === false) formatting.allCaps = false;
|
|
350
|
+
if (attrs.smallCaps === false) formatting.smallCaps = false;
|
|
351
|
+
if (attrs.emboss === false) formatting.emboss = false;
|
|
352
|
+
if (attrs.imprint === false) formatting.imprint = false;
|
|
353
|
+
if (attrs.shadow === false) formatting.textShadow = false;
|
|
354
|
+
if (attrs.outline === false) formatting.textOutline = false;
|
|
355
|
+
if (attrs.rtl === false) formatting.rtl = false;
|
|
356
|
+
}
|
|
357
|
+
function paragraphRunDefaults(pmAttrs, theme) {
|
|
358
|
+
const defaultTextFormatting = pmAttrs.defaultTextFormatting;
|
|
359
|
+
if (!defaultTextFormatting) return {};
|
|
360
|
+
const result = {};
|
|
361
|
+
const fontFamily = defaultTextFormatting.fontFamily?.ascii ?? defaultTextFormatting.fontFamily?.hAnsi;
|
|
362
|
+
if (fontFamily) result.fontFamily = fontFamily;
|
|
363
|
+
if (defaultTextFormatting.fontFamily?.eastAsia) result.eastAsiaFontFamily = defaultTextFormatting.fontFamily.eastAsia;
|
|
364
|
+
if (defaultTextFormatting.fontSize !== void 0) result.fontSize = defaultTextFormatting.fontSize / 2;
|
|
365
|
+
if (defaultTextFormatting.bold !== void 0) result.bold = defaultTextFormatting.bold;
|
|
366
|
+
if (defaultTextFormatting.italic !== void 0) result.italic = defaultTextFormatting.italic;
|
|
367
|
+
if (defaultTextFormatting.underline && defaultTextFormatting.underline.style !== "none") {
|
|
368
|
+
result.underline = { style: defaultTextFormatting.underline.style };
|
|
369
|
+
if (defaultTextFormatting.underline.color) result.underline.color = resolveColor(defaultTextFormatting.underline.color, theme);
|
|
370
|
+
}
|
|
371
|
+
if (defaultTextFormatting.strike !== void 0) result.strike = defaultTextFormatting.strike;
|
|
372
|
+
if (defaultTextFormatting.color && !isAutomaticTextColorValue(defaultTextFormatting.color)) {
|
|
373
|
+
result.color = resolveColor(defaultTextFormatting.color, theme);
|
|
374
|
+
result.textColorSource = "paragraphDefault";
|
|
375
|
+
}
|
|
376
|
+
if (defaultTextFormatting.highlight) {
|
|
377
|
+
const highlight = resolveHighlightToCss(defaultTextFormatting.highlight);
|
|
378
|
+
if (highlight) result.highlight = highlight;
|
|
379
|
+
}
|
|
380
|
+
if (defaultTextFormatting.vertAlign === "superscript") result.superscript = true;
|
|
381
|
+
if (defaultTextFormatting.vertAlign === "subscript") result.subscript = true;
|
|
382
|
+
if (defaultTextFormatting.allCaps !== void 0) result.allCaps = defaultTextFormatting.allCaps;
|
|
383
|
+
if (defaultTextFormatting.smallCaps !== void 0) result.smallCaps = defaultTextFormatting.smallCaps;
|
|
384
|
+
if (defaultTextFormatting.spacing !== void 0 && defaultTextFormatting.spacing !== 0) result.letterSpacing = twipsToPixels(defaultTextFormatting.spacing);
|
|
385
|
+
if (defaultTextFormatting.position !== void 0 && defaultTextFormatting.position !== 0) result.positionPx = halfPointsToPixels(defaultTextFormatting.position);
|
|
386
|
+
if (defaultTextFormatting.scale !== void 0 && defaultTextFormatting.scale !== 100) result.horizontalScale = defaultTextFormatting.scale;
|
|
387
|
+
if (defaultTextFormatting.kerning !== void 0 && defaultTextFormatting.kerning > 0) result.kerningMinPt = halfPointsToPoints(defaultTextFormatting.kerning);
|
|
388
|
+
if (defaultTextFormatting.emboss !== void 0) result.emboss = defaultTextFormatting.emboss;
|
|
389
|
+
if (defaultTextFormatting.imprint !== void 0) result.imprint = defaultTextFormatting.imprint;
|
|
390
|
+
if (defaultTextFormatting.shadow !== void 0) result.textShadow = defaultTextFormatting.shadow;
|
|
391
|
+
if (defaultTextFormatting.outline !== void 0) result.textOutline = defaultTextFormatting.outline;
|
|
392
|
+
if (defaultTextFormatting.emphasisMark && defaultTextFormatting.emphasisMark !== "none") result.emphasisMark = defaultTextFormatting.emphasisMark;
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Build an ImageRun from ProseMirror node attrs, applying conditional property assignment
|
|
397
|
+
* to satisfy exactOptionalPropertyTypes.
|
|
398
|
+
*/
|
|
399
|
+
function buildImageRun(attrs, constrained, pmStart, pmEnd, trackedChange) {
|
|
400
|
+
const run = {
|
|
401
|
+
kind: "image",
|
|
402
|
+
src: attrs.src,
|
|
403
|
+
width: constrained.width,
|
|
404
|
+
height: constrained.height,
|
|
405
|
+
pmStart,
|
|
406
|
+
pmEnd
|
|
407
|
+
};
|
|
408
|
+
if (attrs.alt !== void 0) run.alt = attrs.alt;
|
|
409
|
+
if (attrs.transform !== void 0) run.transform = attrs.transform;
|
|
410
|
+
if (attrs.opacity != null) run.opacity = attrs.opacity;
|
|
411
|
+
if (attrs.wrapType !== void 0) run.wrapType = attrs.wrapType;
|
|
412
|
+
if (attrs.displayMode !== void 0) run.displayMode = attrs.displayMode;
|
|
413
|
+
if (attrs.cssFloat !== void 0) run.cssFloat = attrs.cssFloat;
|
|
414
|
+
if (attrs.distTop !== void 0) run.distTop = attrs.distTop;
|
|
415
|
+
if (attrs.distBottom !== void 0) run.distBottom = attrs.distBottom;
|
|
416
|
+
if (attrs.distLeft !== void 0) run.distLeft = attrs.distLeft;
|
|
417
|
+
if (attrs.distRight !== void 0) run.distRight = attrs.distRight;
|
|
418
|
+
if (attrs.cropTop != null) run.cropTop = attrs.cropTop;
|
|
419
|
+
if (attrs.cropRight != null) run.cropRight = attrs.cropRight;
|
|
420
|
+
if (attrs.cropBottom != null) run.cropBottom = attrs.cropBottom;
|
|
421
|
+
if (attrs.cropLeft != null) run.cropLeft = attrs.cropLeft;
|
|
422
|
+
if (attrs.position !== void 0) run.position = attrs.position;
|
|
423
|
+
if (trackedChange?.isInsertion) run.isInsertion = true;
|
|
424
|
+
if (trackedChange?.isDeletion) run.isDeletion = true;
|
|
425
|
+
if (trackedChange?.changeAuthor !== void 0) run.changeAuthor = trackedChange.changeAuthor;
|
|
426
|
+
if (trackedChange?.changeDate !== void 0) run.changeDate = trackedChange.changeDate;
|
|
427
|
+
if (trackedChange?.changeRevisionId !== void 0) run.changeRevisionId = trackedChange.changeRevisionId;
|
|
428
|
+
return run;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Paragraph styleId pattern used by Word for TOC entries (TOC, TOC1, TOC2, …).
|
|
432
|
+
* Hyperlinks inside these paragraphs must render in the paragraph's own colour,
|
|
433
|
+
* not the Hyperlink character style — see {@link stripTocHyperlinkStyle}.
|
|
434
|
+
*/
|
|
435
|
+
const TOC_STYLE_ID = /^TOC\d*$/iu;
|
|
436
|
+
/**
|
|
437
|
+
* In TOC paragraphs, strip the resolved Hyperlink character-style colour and
|
|
438
|
+
* underline so the painter's link fallback doesn't fire. The PM doc keeps the
|
|
439
|
+
* original marks so copy/paste out of a TOC still carries the Hyperlink
|
|
440
|
+
* styling like Word does. Applies to both text and field runs — a TOC entry's
|
|
441
|
+
* page number is a PAGEREF field inside the entry's hyperlink.
|
|
442
|
+
*
|
|
443
|
+
* Mutates `formatting` in place; cheaper than re-cloning per run.
|
|
444
|
+
*/
|
|
445
|
+
function stripTocHyperlinkStyle(formatting) {
|
|
446
|
+
if (!formatting.hyperlink) return;
|
|
447
|
+
formatting.hyperlink = {
|
|
448
|
+
...formatting.hyperlink,
|
|
449
|
+
noDefaultStyle: true
|
|
450
|
+
};
|
|
451
|
+
delete formatting.color;
|
|
452
|
+
delete formatting.underline;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Convert a paragraph node to runs.
|
|
456
|
+
*/
|
|
457
|
+
function paragraphToRuns(node, startPos, _options) {
|
|
458
|
+
const runs = [];
|
|
459
|
+
const offset = startPos + 1;
|
|
460
|
+
const theme = _options.theme;
|
|
461
|
+
const pmAttrs = expectParagraphAttrs(node);
|
|
462
|
+
const paraDefaults = paragraphRunDefaults(pmAttrs, theme);
|
|
463
|
+
const paragraphStyleId = pmAttrs.styleId;
|
|
464
|
+
const inTocParagraph = typeof paragraphStyleId === "string" && TOC_STYLE_ID.test(paragraphStyleId);
|
|
465
|
+
function pushRunsForChild(child, childPos) {
|
|
466
|
+
if (child.isText && child.text) {
|
|
467
|
+
const formatting = extractRunFormatting(child.marks, theme);
|
|
468
|
+
if (inTocParagraph) stripTocHyperlinkStyle(formatting);
|
|
469
|
+
const run = {
|
|
470
|
+
kind: "text",
|
|
471
|
+
text: child.text,
|
|
472
|
+
...mergeRunFormatting(paraDefaults, formatting),
|
|
473
|
+
pmStart: childPos,
|
|
474
|
+
pmEnd: childPos + child.nodeSize
|
|
475
|
+
};
|
|
476
|
+
runs.push(run);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (child.type.name === "hardBreak") {
|
|
480
|
+
runs.push({
|
|
481
|
+
kind: "lineBreak",
|
|
482
|
+
pmStart: childPos,
|
|
483
|
+
pmEnd: childPos + child.nodeSize
|
|
484
|
+
});
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (child.type.name === "tab") {
|
|
488
|
+
const run = {
|
|
489
|
+
kind: "tab",
|
|
490
|
+
...mergeRunFormatting(paraDefaults, extractRunFormatting(child.marks, theme)),
|
|
491
|
+
pmStart: childPos,
|
|
492
|
+
pmEnd: childPos + child.nodeSize
|
|
493
|
+
};
|
|
494
|
+
runs.push(run);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
if (child.type.name === "image") {
|
|
498
|
+
const attrs = expectImageAttrs(child);
|
|
499
|
+
const constrained = constrainImageToPage(attrs.width || 100, attrs.height || 100, _options.pageContentHeight);
|
|
500
|
+
const trackedFmt = extractRunFormatting(child.marks, theme);
|
|
501
|
+
const run = buildImageRun(attrs, constrained, childPos, childPos + child.nodeSize, trackedFmt);
|
|
502
|
+
runs.push(run);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (child.type.name === "field") {
|
|
506
|
+
const attrs = expectFieldAttrs(child);
|
|
507
|
+
const ft = attrs.fieldType;
|
|
508
|
+
let mappedType = "OTHER";
|
|
509
|
+
if (ft === "PAGE") mappedType = "PAGE";
|
|
510
|
+
else if (ft === "NUMPAGES") mappedType = "NUMPAGES";
|
|
511
|
+
else if (ft === "DATE") mappedType = "DATE";
|
|
512
|
+
else if (ft === "TIME") mappedType = "TIME";
|
|
513
|
+
const extractedFieldFormatting = extractRunFormatting(child.marks, theme);
|
|
514
|
+
if (inTocParagraph) stripTocHyperlinkStyle(extractedFieldFormatting);
|
|
515
|
+
const fieldFormatting = markDefaultBlackTextColorSource(extractedFieldFormatting, paraDefaults);
|
|
516
|
+
const run = {
|
|
517
|
+
kind: "field",
|
|
518
|
+
fieldType: mappedType,
|
|
519
|
+
instruction: attrs.instruction,
|
|
520
|
+
fallback: attrs.displayText || "",
|
|
521
|
+
...attrs.fldLock ? { fldLock: true } : {},
|
|
522
|
+
pmStart: childPos,
|
|
523
|
+
pmEnd: childPos + child.nodeSize,
|
|
524
|
+
...fieldFormatting
|
|
525
|
+
};
|
|
526
|
+
runs.push(run);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (child.type.name === "math") {
|
|
530
|
+
const attrs = expectMathAttrs(child);
|
|
531
|
+
const plainText = attrs.plainText || "[equation]";
|
|
532
|
+
runs.push({
|
|
533
|
+
kind: "math",
|
|
534
|
+
display: attrs.display ?? "inline",
|
|
535
|
+
ommlXml: attrs.ommlXml,
|
|
536
|
+
plainText,
|
|
537
|
+
italic: true,
|
|
538
|
+
fontFamily: "Cambria Math",
|
|
539
|
+
pmStart: childPos,
|
|
540
|
+
pmEnd: childPos + child.nodeSize
|
|
541
|
+
});
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (child.type.name === "sdt") {
|
|
545
|
+
const sdtInnerOffset = childPos + 1;
|
|
546
|
+
child.forEach((sdtChild, sdtChildOffset) => {
|
|
547
|
+
pushRunsForChild(sdtChild, sdtInnerOffset + sdtChildOffset);
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
node.forEach((child, childOffset) => {
|
|
552
|
+
pushRunsForChild(child, offset + childOffset);
|
|
553
|
+
});
|
|
554
|
+
return runs;
|
|
555
|
+
}
|
|
556
|
+
function toListMarkerRevision(kind, info) {
|
|
557
|
+
const revision = { kind };
|
|
558
|
+
if (typeof info?.author === "string") revision.author = info.author;
|
|
559
|
+
if (typeof info?.date === "string") revision.date = info.date;
|
|
560
|
+
if (typeof info?.id === "number") revision.revisionId = info.id;
|
|
561
|
+
return revision;
|
|
562
|
+
}
|
|
563
|
+
function isAddedNumberingChange(change) {
|
|
564
|
+
const previousFormatting = change.previousFormatting;
|
|
565
|
+
return previousFormatting != null && Object.hasOwn(previousFormatting, "numPr") && previousFormatting["numPr"] == null;
|
|
566
|
+
}
|
|
567
|
+
function isRemovedNumberingChange(change) {
|
|
568
|
+
const previousFormatting = change.previousFormatting;
|
|
569
|
+
return previousFormatting != null && Object.hasOwn(previousFormatting, "numPr") && isListNumPr(previousFormatting["numPr"]);
|
|
570
|
+
}
|
|
571
|
+
function isChangedNumberingChange(currentNumPr, change) {
|
|
572
|
+
const previousFormatting = change.previousFormatting;
|
|
573
|
+
return previousFormatting != null && Object.hasOwn(previousFormatting, "numPr") && isListNumPr(previousFormatting["numPr"]) && !areListNumPrEqual(previousFormatting["numPr"], currentNumPr);
|
|
574
|
+
}
|
|
575
|
+
function areListNumPrEqual(left, right) {
|
|
576
|
+
return left.numId === right.numId && left.ilvl === right.ilvl;
|
|
577
|
+
}
|
|
578
|
+
function isRecord(value) {
|
|
579
|
+
return typeof value === "object" && value !== null;
|
|
580
|
+
}
|
|
581
|
+
function isListNumPr(value) {
|
|
582
|
+
if (!isRecord(value)) return false;
|
|
583
|
+
const numId = value["numId"];
|
|
584
|
+
const ilvl = value["ilvl"];
|
|
585
|
+
return (numId === void 0 || typeof numId === "number") && (ilvl === void 0 || typeof ilvl === "number");
|
|
586
|
+
}
|
|
587
|
+
function isNumberFormat(value) {
|
|
588
|
+
return NUMBER_FORMAT_VALUES.some((format) => format === value);
|
|
589
|
+
}
|
|
590
|
+
function readNumberFormats(value) {
|
|
591
|
+
if (!Array.isArray(value)) return;
|
|
592
|
+
const formats = [];
|
|
593
|
+
for (const item of value) {
|
|
594
|
+
if (!isNumberFormat(item)) return;
|
|
595
|
+
formats.push(item);
|
|
596
|
+
}
|
|
597
|
+
return formats;
|
|
598
|
+
}
|
|
599
|
+
function readListMarkerSuffix(value) {
|
|
600
|
+
if (value === "tab" || value === "space" || value === "nothing") return value;
|
|
601
|
+
}
|
|
602
|
+
function toPreviousListAttrs(previousFormatting) {
|
|
603
|
+
const attrs = {};
|
|
604
|
+
const numPr = previousFormatting["numPr"];
|
|
605
|
+
if (isListNumPr(numPr)) attrs.numPr = numPr;
|
|
606
|
+
const listIsBullet = previousFormatting["listIsBullet"];
|
|
607
|
+
if (typeof listIsBullet === "boolean") attrs.listIsBullet = listIsBullet;
|
|
608
|
+
const listIsLegal = previousFormatting["listIsLegal"];
|
|
609
|
+
if (typeof listIsLegal === "boolean") attrs.listIsLegal = listIsLegal;
|
|
610
|
+
const listMarker = previousFormatting["listMarker"];
|
|
611
|
+
if (typeof listMarker === "string") attrs.listMarker = listMarker;
|
|
612
|
+
const listNumFmt = previousFormatting["listNumFmt"];
|
|
613
|
+
if (isNumberFormat(listNumFmt)) attrs.listNumFmt = listNumFmt;
|
|
614
|
+
const listLevelNumFmts = readNumberFormats(previousFormatting["listLevelNumFmts"]);
|
|
615
|
+
if (listLevelNumFmts) attrs.listLevelNumFmts = listLevelNumFmts;
|
|
616
|
+
const listAbstractNumId = previousFormatting["listAbstractNumId"];
|
|
617
|
+
if (typeof listAbstractNumId === "number") attrs.listAbstractNumId = listAbstractNumId;
|
|
618
|
+
const listStartOverride = previousFormatting["listStartOverride"];
|
|
619
|
+
if (typeof listStartOverride === "number") attrs.listStartOverride = listStartOverride;
|
|
620
|
+
const listMarkerHidden = previousFormatting["listMarkerHidden"];
|
|
621
|
+
if (typeof listMarkerHidden === "boolean") attrs.listMarkerHidden = listMarkerHidden;
|
|
622
|
+
const listMarkerFontFamily = previousFormatting["listMarkerFontFamily"];
|
|
623
|
+
if (typeof listMarkerFontFamily === "string") attrs.listMarkerFontFamily = listMarkerFontFamily;
|
|
624
|
+
const listMarkerFontSize = previousFormatting["listMarkerFontSize"];
|
|
625
|
+
if (typeof listMarkerFontSize === "number") attrs.listMarkerFontSize = listMarkerFontSize;
|
|
626
|
+
const listMarkerSuffix = readListMarkerSuffix(previousFormatting["listMarkerSuffix"]);
|
|
627
|
+
if (listMarkerSuffix) attrs.listMarkerSuffix = listMarkerSuffix;
|
|
628
|
+
return attrs;
|
|
629
|
+
}
|
|
630
|
+
function resolveDeletedListMarker(previousListAttrs, listCounters, listAbstractCounters, listSeenNumIds) {
|
|
631
|
+
if (listCounters && previousListAttrs.numPr) {
|
|
632
|
+
const marker = computeListMarker(previousListAttrs, listCounters, listAbstractCounters ?? /* @__PURE__ */ new Map(), listSeenNumIds ?? /* @__PURE__ */ new Set());
|
|
633
|
+
if (marker) return marker;
|
|
634
|
+
}
|
|
635
|
+
if (previousListAttrs.listMarker) return previousListAttrs.listIsBullet ? convertBulletToUnicode(previousListAttrs.listMarker) : previousListAttrs.listMarker;
|
|
636
|
+
if (previousListAttrs.listIsBullet) return "•";
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
function applyDeletedListMarkerAttrs(attrs, change, listCounters, listAbstractCounters, listSeenNumIds) {
|
|
640
|
+
const previousListAttrs = toPreviousListAttrs(change.previousFormatting);
|
|
641
|
+
const marker = resolveDeletedListMarker(previousListAttrs, listCounters, listAbstractCounters, listSeenNumIds);
|
|
642
|
+
if (!marker) return;
|
|
643
|
+
attrs.listMarker = marker;
|
|
644
|
+
attrs.listMarkerRevision = toListMarkerRevision("del", change.info);
|
|
645
|
+
if (previousListAttrs.listIsBullet !== void 0) attrs.listIsBullet = previousListAttrs.listIsBullet;
|
|
646
|
+
if (previousListAttrs.listMarkerHidden !== void 0) attrs.listMarkerHidden = previousListAttrs.listMarkerHidden;
|
|
647
|
+
if (previousListAttrs.listMarkerFontFamily) attrs.listMarkerFontFamily = previousListAttrs.listMarkerFontFamily;
|
|
648
|
+
if (previousListAttrs.listMarkerFontSize) attrs.listMarkerFontSize = previousListAttrs.listMarkerFontSize;
|
|
649
|
+
if (previousListAttrs.listMarkerSuffix) attrs.listMarkerSuffix = previousListAttrs.listMarkerSuffix;
|
|
650
|
+
}
|
|
651
|
+
function convertParagraphAttrs(pmAttrs, theme, listCounters, listAbstractCounters, listSeenNumIds, defaultTabStopTwips, originalListCounters, originalListAbstractCounters, originalListSeenNumIds) {
|
|
652
|
+
const attrs = {};
|
|
653
|
+
if (pmAttrs.alignment) {
|
|
654
|
+
const align = pmAttrs.alignment;
|
|
655
|
+
if (align === "both" || align === "distribute") attrs.alignment = "justify";
|
|
656
|
+
else if (align === "left") attrs.alignment = "left";
|
|
657
|
+
else if (align === "center") attrs.alignment = "center";
|
|
658
|
+
else if (align === "right") attrs.alignment = "right";
|
|
659
|
+
}
|
|
660
|
+
const spaceBefore = pmAttrs.spaceBefore;
|
|
661
|
+
const spaceAfter = pmAttrs.spaceAfter;
|
|
662
|
+
const lineSpacing = pmAttrs.lineSpacing;
|
|
663
|
+
const autoBefore = autospacingMatchesBase(pmAttrs._autospacingBase, "before", spaceBefore);
|
|
664
|
+
const autoAfter = autospacingMatchesBase(pmAttrs._autospacingBase, "after", spaceAfter);
|
|
665
|
+
if (autoBefore || autoAfter || typeof spaceBefore === "number" || typeof spaceAfter === "number" || typeof lineSpacing === "number") {
|
|
666
|
+
attrs.spacing = {};
|
|
667
|
+
if (autoBefore) attrs.spacing.before = 14;
|
|
668
|
+
else if (typeof spaceBefore === "number") attrs.spacing.before = twipsToPixels(spaceBefore);
|
|
669
|
+
if (autoAfter) attrs.spacing.after = 14;
|
|
670
|
+
else if (typeof spaceAfter === "number") attrs.spacing.after = twipsToPixels(spaceAfter);
|
|
671
|
+
const pmSpacingExplicit = pmAttrs.spacingExplicit;
|
|
672
|
+
const explicit = {};
|
|
673
|
+
if (autoBefore || pmSpacingExplicit?.before) explicit.before = true;
|
|
674
|
+
if (autoAfter || pmSpacingExplicit?.after) explicit.after = true;
|
|
675
|
+
if (explicit.before !== void 0 || explicit.after !== void 0) attrs.spacingExplicit = explicit;
|
|
676
|
+
if (typeof lineSpacing === "number") if (pmAttrs.lineSpacingRule === "exact" || pmAttrs.lineSpacingRule === "atLeast") {
|
|
677
|
+
attrs.spacing.line = twipsToPixels(lineSpacing);
|
|
678
|
+
attrs.spacing.lineUnit = "px";
|
|
679
|
+
attrs.spacing.lineRule = pmAttrs.lineSpacingRule;
|
|
680
|
+
} else {
|
|
681
|
+
attrs.spacing.line = lineSpacing / 240;
|
|
682
|
+
attrs.spacing.lineUnit = "multiplier";
|
|
683
|
+
attrs.spacing.lineRule = "auto";
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
let indentLeft = typeof pmAttrs.indentLeft === "number" ? pmAttrs.indentLeft : void 0;
|
|
687
|
+
let indentFirstLine = typeof pmAttrs.indentFirstLine === "number" ? pmAttrs.indentFirstLine : void 0;
|
|
688
|
+
let hangingIndent = pmAttrs.hangingIndent;
|
|
689
|
+
if (pmAttrs.numPr?.numId && indentLeft === void 0) {
|
|
690
|
+
indentLeft = ((pmAttrs.numPr.ilvl ?? 0) + 1) * 720;
|
|
691
|
+
if (indentFirstLine === void 0) {
|
|
692
|
+
indentFirstLine = -360;
|
|
693
|
+
hangingIndent = true;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
if (indentLeft !== void 0 || typeof pmAttrs.indentRight === "number" || indentFirstLine !== void 0) {
|
|
697
|
+
attrs.indent = {};
|
|
698
|
+
if (indentLeft !== void 0) attrs.indent.left = twipsToPixels(indentLeft);
|
|
699
|
+
if (typeof pmAttrs.indentRight === "number") attrs.indent.right = twipsToPixels(pmAttrs.indentRight);
|
|
700
|
+
if (indentFirstLine !== void 0) if (hangingIndent) attrs.indent.hanging = Math.abs(twipsToPixels(indentFirstLine));
|
|
701
|
+
else attrs.indent.firstLine = twipsToPixels(indentFirstLine);
|
|
702
|
+
}
|
|
703
|
+
if (pmAttrs.styleId) attrs.styleId = pmAttrs.styleId;
|
|
704
|
+
if (pmAttrs.borders) {
|
|
705
|
+
const borders = pmAttrs.borders;
|
|
706
|
+
attrs.borders = {};
|
|
707
|
+
const convertBorder = (border) => border ? convertBorderSpecToLayout(border, theme) : void 0;
|
|
708
|
+
const topBorder = borders.top ? convertBorder(borders.top) : void 0;
|
|
709
|
+
if (topBorder) attrs.borders.top = topBorder;
|
|
710
|
+
const bottomBorder = borders.bottom ? convertBorder(borders.bottom) : void 0;
|
|
711
|
+
if (bottomBorder) attrs.borders.bottom = bottomBorder;
|
|
712
|
+
const leftBorder = borders.left ? convertBorder(borders.left) : void 0;
|
|
713
|
+
if (leftBorder) attrs.borders.left = leftBorder;
|
|
714
|
+
const rightBorder = borders.right ? convertBorder(borders.right) : void 0;
|
|
715
|
+
if (rightBorder) attrs.borders.right = rightBorder;
|
|
716
|
+
const betweenBorder = borders.between ? convertBorder(borders.between) : void 0;
|
|
717
|
+
if (betweenBorder) attrs.borders.between = betweenBorder;
|
|
718
|
+
const barBorder = borders.bar ? convertBorder(borders.bar) : void 0;
|
|
719
|
+
if (barBorder) attrs.borders.bar = barBorder;
|
|
720
|
+
if (!attrs.borders.top && !attrs.borders.bottom && !attrs.borders.left && !attrs.borders.right && !attrs.borders.between && !attrs.borders.bar) delete attrs.borders;
|
|
721
|
+
}
|
|
722
|
+
const shadingRgb = pmAttrs.shading?.fill?.rgb?.toUpperCase();
|
|
723
|
+
if (shadingRgb && shadingRgb !== "FFFFFF" && shadingRgb !== "FFFFFE") attrs.shading = `#${pmAttrs.shading?.fill?.rgb}`;
|
|
724
|
+
if (pmAttrs.tabs && pmAttrs.tabs.length > 0) attrs.tabs = pmAttrs.tabs.map((tab) => {
|
|
725
|
+
const tabStop = {
|
|
726
|
+
val: mapTabAlignment(tab.alignment),
|
|
727
|
+
pos: tab.position
|
|
728
|
+
};
|
|
729
|
+
if (tab.leader) tabStop.leader = tab.leader;
|
|
730
|
+
return tabStop;
|
|
731
|
+
});
|
|
732
|
+
if (pmAttrs.pageBreakBefore) attrs.pageBreakBefore = true;
|
|
733
|
+
if (pmAttrs.keepNext) attrs.keepNext = true;
|
|
734
|
+
if (pmAttrs.keepLines) attrs.keepLines = true;
|
|
735
|
+
if (pmAttrs.contextualSpacing) attrs.contextualSpacing = true;
|
|
736
|
+
if (pmAttrs.runInWithNext) attrs.runInWithNext = true;
|
|
737
|
+
if (directionIsRtl(pmAttrs.direction)) attrs.bidi = true;
|
|
738
|
+
if (pmAttrs.styleId) attrs.styleId = pmAttrs.styleId;
|
|
739
|
+
const pPrChange = pmAttrs._propertyChanges;
|
|
740
|
+
const propertyChanges = Array.isArray(pPrChange) ? pPrChange : [];
|
|
741
|
+
let changedNumberingChange;
|
|
742
|
+
if (pmAttrs.numPr) {
|
|
743
|
+
const numPr = {};
|
|
744
|
+
if (pmAttrs.numPr.numId !== void 0) numPr.numId = pmAttrs.numPr.numId;
|
|
745
|
+
if (pmAttrs.numPr.ilvl !== void 0) numPr.ilvl = pmAttrs.numPr.ilvl;
|
|
746
|
+
attrs.numPr = numPr;
|
|
747
|
+
if (pmAttrs.pPrMark?.kind === "del") attrs.listMarkerRevision = toListMarkerRevision("del", pmAttrs.pPrMark.info);
|
|
748
|
+
else if (pmAttrs.pPrMark?.kind === "ins") attrs.listMarkerRevision = toListMarkerRevision("ins", pmAttrs.pPrMark.info);
|
|
749
|
+
else {
|
|
750
|
+
const numberingAddedChange = propertyChanges.find(isAddedNumberingChange);
|
|
751
|
+
const currentNumPr = pmAttrs.numPr;
|
|
752
|
+
changedNumberingChange = propertyChanges.find((change) => isChangedNumberingChange(currentNumPr, change));
|
|
753
|
+
const numberingInsertionChange = numberingAddedChange ?? changedNumberingChange;
|
|
754
|
+
if (numberingInsertionChange) attrs.listMarkerRevision = toListMarkerRevision("ins", numberingInsertionChange.info);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
const useOriginalStream = attrs.listMarkerRevision?.kind === "del" && originalListCounters !== void 0;
|
|
758
|
+
const streamCounters = useOriginalStream ? originalListCounters : listCounters;
|
|
759
|
+
const resolvedMarker = applyMarkerAllCaps(streamCounters ? computeListMarker(pmAttrs, streamCounters, (useOriginalStream ? originalListAbstractCounters : listAbstractCounters) ?? /* @__PURE__ */ new Map(), (useOriginalStream ? originalListSeenNumIds : listSeenNumIds) ?? /* @__PURE__ */ new Set()) : null, pmAttrs.listMarkerAllCaps);
|
|
760
|
+
const numberedNumId = pmAttrs.numPr?.numId;
|
|
761
|
+
if (attrs.listMarkerRevision === void 0 && !pmAttrs.listIsBullet && originalListCounters !== void 0 && numberedNumId !== void 0 && numberedNumId !== 0) computeListMarker(pmAttrs, originalListCounters, originalListAbstractCounters ?? /* @__PURE__ */ new Map(), originalListSeenNumIds ?? /* @__PURE__ */ new Set());
|
|
762
|
+
else if (changedNumberingChange !== void 0 && originalListCounters !== void 0) {
|
|
763
|
+
const previousListAttrs = toPreviousListAttrs(changedNumberingChange.previousFormatting);
|
|
764
|
+
if (previousListAttrs.numPr && !previousListAttrs.listIsBullet) computeListMarker(previousListAttrs, originalListCounters, originalListAbstractCounters ?? /* @__PURE__ */ new Map(), originalListSeenNumIds ?? /* @__PURE__ */ new Set());
|
|
765
|
+
}
|
|
766
|
+
if (resolvedMarker !== null) attrs.listMarker = resolvedMarker;
|
|
767
|
+
else if (pmAttrs.listMarker) attrs.listMarker = pmAttrs.listIsBullet ? convertBulletToUnicode(pmAttrs.listMarker) : pmAttrs.listMarker;
|
|
768
|
+
if (pmAttrs.listIsBullet !== void 0) attrs.listIsBullet = pmAttrs.listIsBullet;
|
|
769
|
+
if (pmAttrs.listMarkerHidden) attrs.listMarkerHidden = true;
|
|
770
|
+
if (pmAttrs.listMarkerFontFamily) attrs.listMarkerFontFamily = pmAttrs.listMarkerFontFamily;
|
|
771
|
+
if (pmAttrs.listMarkerFontSize) attrs.listMarkerFontSize = pmAttrs.listMarkerFontSize;
|
|
772
|
+
if (pmAttrs.listMarkerSuffix) attrs.listMarkerSuffix = pmAttrs.listMarkerSuffix;
|
|
773
|
+
if (pmAttrs.listMarkerSecondSlotOffsetTwips !== void 0) attrs.listMarkerSecondSlotOffsetTwips = pmAttrs.listMarkerSecondSlotOffsetTwips;
|
|
774
|
+
if (!pmAttrs.numPr) {
|
|
775
|
+
const numberingRemovedChange = propertyChanges.find(isRemovedNumberingChange);
|
|
776
|
+
if (numberingRemovedChange) applyDeletedListMarkerAttrs(attrs, numberingRemovedChange, originalListCounters, originalListAbstractCounters, originalListSeenNumIds);
|
|
777
|
+
}
|
|
778
|
+
if (defaultTabStopTwips !== void 0) attrs.defaultTabStopTwips = defaultTabStopTwips;
|
|
779
|
+
const dtf = pmAttrs.defaultTextFormatting;
|
|
780
|
+
if (dtf) {
|
|
781
|
+
if (dtf.fontSize !== void 0) attrs.defaultFontSize = dtf.fontSize / 2;
|
|
782
|
+
if (dtf.fontFamily) {
|
|
783
|
+
const resolvedFamily = dtf.fontFamily.ascii || dtf.fontFamily.hAnsi;
|
|
784
|
+
if (resolvedFamily) attrs.defaultFontFamily = resolvedFamily;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return attrs;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Map document TabStopAlignment to layout engine TabAlignment
|
|
791
|
+
*/
|
|
792
|
+
function mapTabAlignment(align) {
|
|
793
|
+
switch (align) {
|
|
794
|
+
case "left": return "start";
|
|
795
|
+
case "right": return "end";
|
|
796
|
+
case "center": return "center";
|
|
797
|
+
case "decimal": return "decimal";
|
|
798
|
+
case "bar": return "bar";
|
|
799
|
+
case "clear": return "clear";
|
|
800
|
+
case "num": return "start";
|
|
801
|
+
default: return "start";
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Convert a paragraph node to a ParagraphBlock.
|
|
806
|
+
*/
|
|
807
|
+
function convertParagraph(node, startPos, options) {
|
|
808
|
+
const pmAttrs = expectParagraphAttrs(node);
|
|
809
|
+
const runs = paragraphToRuns(node, startPos, options);
|
|
810
|
+
const attrs = convertParagraphAttrs(pmAttrs, options.theme, options.listCounters, options.listAbstractCounters, options.listSeenNumIds, options.defaultTabStopTwips, options.originalListCounters, options.originalListAbstractCounters, options.originalListSeenNumIds);
|
|
811
|
+
const bookmarkNames = pmAttrs.bookmarks?.map((b) => b.name);
|
|
812
|
+
return {
|
|
813
|
+
kind: "paragraph",
|
|
814
|
+
id: nextBlockId(),
|
|
815
|
+
runs,
|
|
816
|
+
attrs,
|
|
817
|
+
...bookmarkNames && bookmarkNames.length > 0 ? { bookmarks: bookmarkNames } : {},
|
|
818
|
+
pmStart: startPos,
|
|
819
|
+
pmEnd: startPos + node.nodeSize
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Convert border width from eighths of a point to pixels.
|
|
824
|
+
* OOXML stores border widths in eighths of a point.
|
|
825
|
+
*/
|
|
826
|
+
function borderWidthToPixels(eighthsOfPoint) {
|
|
827
|
+
return Math.max(1, Math.round(eighthsOfPoint / 8 * 1.333));
|
|
828
|
+
}
|
|
829
|
+
const OOXML_TO_CSS_BORDER = {
|
|
830
|
+
single: "solid",
|
|
831
|
+
double: "double",
|
|
832
|
+
dotted: "dotted",
|
|
833
|
+
dashed: "dashed",
|
|
834
|
+
thick: "solid",
|
|
835
|
+
dashSmallGap: "dashed",
|
|
836
|
+
dotDash: "dashed",
|
|
837
|
+
dotDotDash: "dotted",
|
|
838
|
+
triple: "double",
|
|
839
|
+
wave: "solid",
|
|
840
|
+
doubleWave: "double",
|
|
841
|
+
threeDEmboss: "ridge",
|
|
842
|
+
threeDEngrave: "groove",
|
|
843
|
+
outset: "outset",
|
|
844
|
+
inset: "inset"
|
|
845
|
+
};
|
|
846
|
+
/**
|
|
847
|
+
* Convert an OOXML BorderSpec to a layout-engine BorderStyle.
|
|
848
|
+
* Shared by paragraph borders, cell borders, and header/footer borders.
|
|
849
|
+
*/
|
|
850
|
+
function convertBorderSpecToLayout(border, theme) {
|
|
851
|
+
if (!border.style || border.style === "none" || border.style === "nil") return;
|
|
852
|
+
const result = {
|
|
853
|
+
style: OOXML_TO_CSS_BORDER[border.style] || "solid",
|
|
854
|
+
width: borderWidthToPixels(border.size ?? 0),
|
|
855
|
+
color: border.color ? resolveColor(border.color, theme) : "#000000"
|
|
856
|
+
};
|
|
857
|
+
if (border.space !== void 0) result.space = pointsToPixels(border.space);
|
|
858
|
+
return result;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Extract cell borders from ProseMirror attributes.
|
|
862
|
+
* Borders are full BorderSpec objects with style/size/color.
|
|
863
|
+
*/
|
|
864
|
+
function extractCellBorders(borders, theme) {
|
|
865
|
+
if (!borders) return;
|
|
866
|
+
const result = {};
|
|
867
|
+
for (const side of [
|
|
868
|
+
"top",
|
|
869
|
+
"bottom",
|
|
870
|
+
"left",
|
|
871
|
+
"right"
|
|
872
|
+
]) {
|
|
873
|
+
const border = borders[side];
|
|
874
|
+
result[side] = (border ? convertBorderSpecToLayout(border, theme) : void 0) ?? {
|
|
875
|
+
width: 0,
|
|
876
|
+
style: "none"
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Convert a table cell node.
|
|
883
|
+
*/
|
|
884
|
+
function convertTableCell(node, startPos, options, tableCellMargins) {
|
|
885
|
+
const blocks = [];
|
|
886
|
+
let offset = startPos + 1;
|
|
887
|
+
node.forEach((child) => {
|
|
888
|
+
if (child.type.name === "paragraph") {
|
|
889
|
+
const block = convertParagraph(child, offset, options);
|
|
890
|
+
blocks.push(block);
|
|
891
|
+
} else if (child.type.name === "table") blocks.push(convertTable(child, offset, options));
|
|
892
|
+
offset += child.nodeSize;
|
|
893
|
+
});
|
|
894
|
+
const attrs = expectTableCellAttrs(node);
|
|
895
|
+
const margins = attrs.margins;
|
|
896
|
+
const resolvePaddingSide = (side, cellTwips, tableTwips) => {
|
|
897
|
+
if (cellTwips !== void 0) {
|
|
898
|
+
const px = twipsToPixels(cellTwips);
|
|
899
|
+
if (px > 0) return px;
|
|
900
|
+
}
|
|
901
|
+
if (tableTwips !== void 0) return twipsToPixels(tableTwips);
|
|
902
|
+
return twipsToPixels(DEFAULT_TABLE_CELL_MARGIN_TWIPS[side]);
|
|
903
|
+
};
|
|
904
|
+
const padding = {
|
|
905
|
+
top: resolvePaddingSide("top", margins?.top, tableCellMargins?.top),
|
|
906
|
+
right: resolvePaddingSide("right", margins?.right, tableCellMargins?.right),
|
|
907
|
+
bottom: resolvePaddingSide("bottom", margins?.bottom, tableCellMargins?.bottom),
|
|
908
|
+
left: resolvePaddingSide("left", margins?.left, tableCellMargins?.left)
|
|
909
|
+
};
|
|
910
|
+
const cell = {
|
|
911
|
+
id: nextBlockId(),
|
|
912
|
+
blocks,
|
|
913
|
+
colSpan: attrs.colspan,
|
|
914
|
+
rowSpan: attrs.rowspan,
|
|
915
|
+
padding
|
|
916
|
+
};
|
|
917
|
+
if (attrs.width) cell.width = twipsToPixels(attrs.width);
|
|
918
|
+
if (attrs.verticalAlign) cell.verticalAlign = attrs.verticalAlign;
|
|
919
|
+
if (attrs.backgroundColor) cell.background = `#${attrs.backgroundColor}`;
|
|
920
|
+
const cellBorders = extractCellBorders(attrs.borders, options.theme);
|
|
921
|
+
if (cellBorders) cell.borders = cellBorders;
|
|
922
|
+
if (attrs.noWrap) cell.noWrap = true;
|
|
923
|
+
return cell;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
926
|
+
* Convert a table row node.
|
|
927
|
+
*/
|
|
928
|
+
function convertTableRow(node, startPos, options, tableCellMargins) {
|
|
929
|
+
const cells = [];
|
|
930
|
+
let offset = startPos + 1;
|
|
931
|
+
node.forEach((child) => {
|
|
932
|
+
if (child.type.name === "tableCell" || child.type.name === "tableHeader") cells.push(convertTableCell(child, offset, options, tableCellMargins));
|
|
933
|
+
offset += child.nodeSize;
|
|
934
|
+
});
|
|
935
|
+
const attrs = expectTableRowAttrs(node);
|
|
936
|
+
const row = {
|
|
937
|
+
id: nextBlockId(),
|
|
938
|
+
cells
|
|
939
|
+
};
|
|
940
|
+
if (attrs.height) row.height = twipsToPixels(attrs.height);
|
|
941
|
+
if (attrs.heightRule) row.heightRule = attrs.heightRule;
|
|
942
|
+
if (attrs.isHeader) row.isHeader = attrs.isHeader;
|
|
943
|
+
return row;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Convert a table node to a TableBlock.
|
|
947
|
+
*/
|
|
948
|
+
function convertTable(node, startPos, options) {
|
|
949
|
+
const rows = [];
|
|
950
|
+
let offset = startPos + 1;
|
|
951
|
+
const attrs = expectTableAttrs(node);
|
|
952
|
+
const tableCellMargins = attrs.cellMargins;
|
|
953
|
+
node.forEach((child) => {
|
|
954
|
+
if (child.type.name === "tableRow") rows.push(convertTableRow(child, offset, options, tableCellMargins));
|
|
955
|
+
offset += child.nodeSize;
|
|
956
|
+
});
|
|
957
|
+
let columnWidths = attrs.columnWidths?.map(twipsToPixels);
|
|
958
|
+
const width = attrs.width;
|
|
959
|
+
const widthType = attrs.widthType;
|
|
960
|
+
if (!columnWidths && rows.length > 0) {
|
|
961
|
+
const cellWidths = rows[0].cells.map((cell) => cell.width);
|
|
962
|
+
if (cellWidths.every((w) => w !== void 0 && w > 0)) columnWidths = cellWidths;
|
|
963
|
+
}
|
|
964
|
+
const justification = attrs.justification;
|
|
965
|
+
const originalFormatting = attrs._originalFormatting;
|
|
966
|
+
const indentPx = originalFormatting?.indent?.value && originalFormatting.indent.type === "dxa" ? twipsToPixels(originalFormatting.indent.value) : void 0;
|
|
967
|
+
const floating = attrs.floating;
|
|
968
|
+
let floatingPx;
|
|
969
|
+
if (floating) {
|
|
970
|
+
const fp = {};
|
|
971
|
+
if (floating.horzAnchor) fp.horzAnchor = floating.horzAnchor;
|
|
972
|
+
if (floating.vertAnchor) fp.vertAnchor = floating.vertAnchor;
|
|
973
|
+
if (floating.tblpX !== void 0) fp.tblpX = twipsToPixels(floating.tblpX);
|
|
974
|
+
if (floating.tblpXSpec) fp.tblpXSpec = floating.tblpXSpec;
|
|
975
|
+
if (floating.tblpY !== void 0) fp.tblpY = twipsToPixels(floating.tblpY);
|
|
976
|
+
if (floating.tblpYSpec) fp.tblpYSpec = floating.tblpYSpec;
|
|
977
|
+
if (floating.topFromText !== void 0) fp.topFromText = twipsToPixels(floating.topFromText);
|
|
978
|
+
if (floating.bottomFromText !== void 0) fp.bottomFromText = twipsToPixels(floating.bottomFromText);
|
|
979
|
+
if (floating.leftFromText !== void 0) fp.leftFromText = twipsToPixels(floating.leftFromText);
|
|
980
|
+
if (floating.rightFromText !== void 0) fp.rightFromText = twipsToPixels(floating.rightFromText);
|
|
981
|
+
floatingPx = fp;
|
|
982
|
+
}
|
|
983
|
+
const tableBlock = {
|
|
984
|
+
kind: "table",
|
|
985
|
+
id: nextBlockId(),
|
|
986
|
+
rows,
|
|
987
|
+
pmStart: startPos,
|
|
988
|
+
pmEnd: startPos + node.nodeSize
|
|
989
|
+
};
|
|
990
|
+
if (columnWidths) tableBlock.columnWidths = columnWidths;
|
|
991
|
+
if (width !== void 0) tableBlock.width = width;
|
|
992
|
+
if (widthType !== void 0) tableBlock.widthType = widthType;
|
|
993
|
+
if (justification) tableBlock.justification = justification;
|
|
994
|
+
if (indentPx !== void 0) tableBlock.indent = indentPx;
|
|
995
|
+
if (floatingPx) tableBlock.floating = floatingPx;
|
|
996
|
+
if (originalFormatting?.bidi) tableBlock.bidi = true;
|
|
997
|
+
return tableBlock;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Convert an image node to an ImageBlock.
|
|
1001
|
+
*/
|
|
1002
|
+
function convertImage(node, startPos, pageContentHeight) {
|
|
1003
|
+
const attrs = expectImageAttrs(node);
|
|
1004
|
+
const wrapType = attrs.wrapType;
|
|
1005
|
+
const shouldAnchor = wrapType === "behind" || wrapType === "inFront";
|
|
1006
|
+
const constrained = constrainImageToPage(attrs.width || 100, attrs.height || 100, pageContentHeight);
|
|
1007
|
+
const imgBlock = {
|
|
1008
|
+
kind: "image",
|
|
1009
|
+
id: nextBlockId(),
|
|
1010
|
+
src: attrs.src,
|
|
1011
|
+
width: constrained.width,
|
|
1012
|
+
height: constrained.height,
|
|
1013
|
+
pmStart: startPos,
|
|
1014
|
+
pmEnd: startPos + node.nodeSize
|
|
1015
|
+
};
|
|
1016
|
+
if (attrs.alt) imgBlock.alt = attrs.alt;
|
|
1017
|
+
if (attrs.transform) imgBlock.transform = attrs.transform;
|
|
1018
|
+
if (attrs.opacity != null) imgBlock.opacity = attrs.opacity;
|
|
1019
|
+
if (shouldAnchor) {
|
|
1020
|
+
const anchor = {
|
|
1021
|
+
isAnchored: true,
|
|
1022
|
+
behindDoc: wrapType === "behind"
|
|
1023
|
+
};
|
|
1024
|
+
if (attrs.distLeft !== void 0) anchor.offsetH = attrs.distLeft;
|
|
1025
|
+
if (attrs.distTop !== void 0) anchor.offsetV = attrs.distTop;
|
|
1026
|
+
imgBlock.anchor = anchor;
|
|
1027
|
+
}
|
|
1028
|
+
if (attrs.hlinkHref) imgBlock.hlinkHref = attrs.hlinkHref;
|
|
1029
|
+
if (attrs.cropTop != null) imgBlock.cropTop = attrs.cropTop;
|
|
1030
|
+
if (attrs.cropRight != null) imgBlock.cropRight = attrs.cropRight;
|
|
1031
|
+
if (attrs.cropBottom != null) imgBlock.cropBottom = attrs.cropBottom;
|
|
1032
|
+
if (attrs.cropLeft != null) imgBlock.cropLeft = attrs.cropLeft;
|
|
1033
|
+
return imgBlock;
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Convert a textBox PM node to a TextBoxBlock.
|
|
1037
|
+
*/
|
|
1038
|
+
function convertTextBoxNode(node, startPos, opts) {
|
|
1039
|
+
const attrs = expectTextBoxAttrs(node);
|
|
1040
|
+
const contentBlocks = [];
|
|
1041
|
+
node.forEach((child, offset) => {
|
|
1042
|
+
if (child.type.name === "paragraph") {
|
|
1043
|
+
const block = convertParagraph(child, startPos + 1 + offset, opts);
|
|
1044
|
+
contentBlocks.push(block);
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
const textBox = {
|
|
1048
|
+
kind: "textBox",
|
|
1049
|
+
id: nextBlockId(),
|
|
1050
|
+
width: attrs.width ?? 200,
|
|
1051
|
+
margins: {
|
|
1052
|
+
top: attrs.marginTop ?? DEFAULT_TEXTBOX_MARGINS.top,
|
|
1053
|
+
bottom: attrs.marginBottom ?? DEFAULT_TEXTBOX_MARGINS.bottom,
|
|
1054
|
+
left: attrs.marginLeft ?? DEFAULT_TEXTBOX_MARGINS.left,
|
|
1055
|
+
right: attrs.marginRight ?? DEFAULT_TEXTBOX_MARGINS.right
|
|
1056
|
+
},
|
|
1057
|
+
content: contentBlocks,
|
|
1058
|
+
pmStart: startPos,
|
|
1059
|
+
pmEnd: startPos + node.nodeSize
|
|
1060
|
+
};
|
|
1061
|
+
if (attrs.height !== void 0) textBox.height = attrs.height;
|
|
1062
|
+
if (attrs.fillColor !== void 0) textBox.fillColor = attrs.fillColor;
|
|
1063
|
+
if (attrs.outlineWidth !== void 0) textBox.outlineWidth = attrs.outlineWidth;
|
|
1064
|
+
if (attrs.outlineColor !== void 0) textBox.outlineColor = attrs.outlineColor;
|
|
1065
|
+
if (attrs.outlineStyle !== void 0) textBox.outlineStyle = attrs.outlineStyle;
|
|
1066
|
+
if (attrs.displayMode !== void 0) textBox.displayMode = attrs.displayMode;
|
|
1067
|
+
if (attrs.cssFloat !== void 0) textBox.cssFloat = attrs.cssFloat;
|
|
1068
|
+
if (attrs.wrapType !== void 0) textBox.wrapType = attrs.wrapType;
|
|
1069
|
+
if (attrs.wrapText !== void 0) textBox.wrapText = attrs.wrapText;
|
|
1070
|
+
if (attrs.distTop !== void 0) textBox.distTop = attrs.distTop;
|
|
1071
|
+
if (attrs.distBottom !== void 0) textBox.distBottom = attrs.distBottom;
|
|
1072
|
+
if (attrs.distLeft !== void 0) textBox.distLeft = attrs.distLeft;
|
|
1073
|
+
if (attrs.distRight !== void 0) textBox.distRight = attrs.distRight;
|
|
1074
|
+
if (attrs.position !== void 0) textBox.position = attrs.position;
|
|
1075
|
+
return textBox;
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Convert a ProseMirror document to FlowBlock array.
|
|
1079
|
+
*
|
|
1080
|
+
* Walks the document tree, converting each node to the appropriate block type.
|
|
1081
|
+
* Tracks pmStart/pmEnd positions for each block for click-to-position mapping.
|
|
1082
|
+
*/
|
|
1083
|
+
function toFlowBlocks(doc, options = {}) {
|
|
1084
|
+
assertValidProseMirrorDocument(doc, "Cannot layout invalid ProseMirror document");
|
|
1085
|
+
resetBlockIdCounter();
|
|
1086
|
+
const opts = {
|
|
1087
|
+
...options,
|
|
1088
|
+
defaultFont: options.defaultFont ?? DEFAULT_FONT,
|
|
1089
|
+
defaultSize: options.defaultSize ?? DEFAULT_SIZE,
|
|
1090
|
+
listCounters: options.listCounters ?? /* @__PURE__ */ new Map(),
|
|
1091
|
+
listAbstractCounters: options.listAbstractCounters ?? /* @__PURE__ */ new Map(),
|
|
1092
|
+
listSeenNumIds: options.listSeenNumIds ?? /* @__PURE__ */ new Set(),
|
|
1093
|
+
originalListCounters: options.originalListCounters ?? /* @__PURE__ */ new Map(),
|
|
1094
|
+
originalListAbstractCounters: options.originalListAbstractCounters ?? /* @__PURE__ */ new Map(),
|
|
1095
|
+
originalListSeenNumIds: options.originalListSeenNumIds ?? /* @__PURE__ */ new Set()
|
|
1096
|
+
};
|
|
1097
|
+
const blocks = [];
|
|
1098
|
+
const offset = 0;
|
|
1099
|
+
let lastSectionMarginsTwips = {
|
|
1100
|
+
top: 1440,
|
|
1101
|
+
bottom: 1440,
|
|
1102
|
+
left: 1440,
|
|
1103
|
+
right: 1440
|
|
1104
|
+
};
|
|
1105
|
+
let sdtSeq = 0;
|
|
1106
|
+
const sdtStack = [];
|
|
1107
|
+
/**
|
|
1108
|
+
* Stamp the active SDT stack (outer→inner) onto every block produced by the
|
|
1109
|
+
* current call. ParagraphBlock/TableBlock accept `sdtGroups`; section breaks
|
|
1110
|
+
* and page breaks deliberately do not — they bracket layout, not content.
|
|
1111
|
+
*/
|
|
1112
|
+
const tagBlockWithSdtStack = (block) => {
|
|
1113
|
+
if (sdtStack.length === 0) return;
|
|
1114
|
+
if (block.kind === "paragraph" || block.kind === "table") block.sdtGroups = [...sdtStack];
|
|
1115
|
+
};
|
|
1116
|
+
const trackedPush = (block) => {
|
|
1117
|
+
tagBlockWithSdtStack(block);
|
|
1118
|
+
blocks.push(block);
|
|
1119
|
+
};
|
|
1120
|
+
const visit = (node, pos) => {
|
|
1121
|
+
switch (node.type.name) {
|
|
1122
|
+
case "blockSdt": {
|
|
1123
|
+
const attrs = expectBlockSdtAttrs(node);
|
|
1124
|
+
sdtSeq += 1;
|
|
1125
|
+
const group = {
|
|
1126
|
+
id: `sdt-${sdtSeq}`,
|
|
1127
|
+
pmPos: pos,
|
|
1128
|
+
sdtType: attrs.sdtType
|
|
1129
|
+
};
|
|
1130
|
+
if (attrs.alias) group.alias = attrs.alias;
|
|
1131
|
+
if (attrs.tag) group.tag = attrs.tag;
|
|
1132
|
+
if (typeof attrs.id === "number") group.sdtId = attrs.id;
|
|
1133
|
+
if (attrs.lock) group.lock = attrs.lock;
|
|
1134
|
+
if (attrs.showingPlaceholder) group.showingPlaceholder = true;
|
|
1135
|
+
if (typeof attrs.checked === "boolean") group.checked = attrs.checked;
|
|
1136
|
+
if (attrs.dateFormat) group.dateFormat = attrs.dateFormat;
|
|
1137
|
+
if (attrs.listItems) group.listItemsJson = attrs.listItems;
|
|
1138
|
+
sdtStack.push(group);
|
|
1139
|
+
const startIndex = blocks.length;
|
|
1140
|
+
let childOffset = pos + 1;
|
|
1141
|
+
for (let i = 0; i < node.childCount; i += 1) {
|
|
1142
|
+
const child = node.child(i);
|
|
1143
|
+
visit(child, childOffset);
|
|
1144
|
+
childOffset += child.nodeSize;
|
|
1145
|
+
}
|
|
1146
|
+
sdtStack.pop();
|
|
1147
|
+
const groupBlocks = [];
|
|
1148
|
+
for (let i = startIndex; i < blocks.length; i += 1) {
|
|
1149
|
+
const b = blocks[i];
|
|
1150
|
+
if (b && (b.kind === "paragraph" || b.kind === "table")) groupBlocks.push(b);
|
|
1151
|
+
}
|
|
1152
|
+
const ourPmPos = group.pmPos;
|
|
1153
|
+
for (let i = 0; i < groupBlocks.length; i += 1) {
|
|
1154
|
+
const b = groupBlocks[i];
|
|
1155
|
+
if (!b || !b.sdtGroups) continue;
|
|
1156
|
+
const idx = b.sdtGroups.findIndex((g) => g.pmPos === ourPmPos);
|
|
1157
|
+
if (idx === -1) continue;
|
|
1158
|
+
let position;
|
|
1159
|
+
if (groupBlocks.length === 1) position = "only";
|
|
1160
|
+
else if (i === 0) position = "first";
|
|
1161
|
+
else if (i === groupBlocks.length - 1) position = "last";
|
|
1162
|
+
else position = "middle";
|
|
1163
|
+
const next = [...b.sdtGroups];
|
|
1164
|
+
const existing = next[idx];
|
|
1165
|
+
if (!existing) continue;
|
|
1166
|
+
next[idx] = {
|
|
1167
|
+
...existing,
|
|
1168
|
+
position
|
|
1169
|
+
};
|
|
1170
|
+
b.sdtGroups = next;
|
|
1171
|
+
}
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
default: break;
|
|
1175
|
+
}
|
|
1176
|
+
switch (node.type.name) {
|
|
1177
|
+
case "paragraph": {
|
|
1178
|
+
const block = convertParagraph(node, pos, opts);
|
|
1179
|
+
const pmAttrs = expectParagraphAttrs(node);
|
|
1180
|
+
trackedPush(block);
|
|
1181
|
+
const secProps = pmAttrs._sectionProperties;
|
|
1182
|
+
if (secProps || pmAttrs.sectionBreakType) {
|
|
1183
|
+
const sectionBreak = {
|
|
1184
|
+
kind: "sectionBreak",
|
|
1185
|
+
id: nextBlockId()
|
|
1186
|
+
};
|
|
1187
|
+
const breakType = secProps?.sectionStart ?? pmAttrs.sectionBreakType;
|
|
1188
|
+
if (breakType) sectionBreak.type = breakType;
|
|
1189
|
+
if (secProps) {
|
|
1190
|
+
if (secProps.pageWidth || secProps.pageHeight) sectionBreak.pageSize = {
|
|
1191
|
+
w: twipsToPixels(secProps.pageWidth ?? 12240),
|
|
1192
|
+
h: twipsToPixels(secProps.pageHeight ?? 15840)
|
|
1193
|
+
};
|
|
1194
|
+
if (secProps.marginTop !== void 0 || secProps.marginBottom !== void 0 || secProps.marginLeft !== void 0 || secProps.marginRight !== void 0) {
|
|
1195
|
+
lastSectionMarginsTwips = {
|
|
1196
|
+
top: secProps.marginTop ?? lastSectionMarginsTwips.top,
|
|
1197
|
+
bottom: secProps.marginBottom ?? lastSectionMarginsTwips.bottom,
|
|
1198
|
+
left: secProps.marginLeft ?? lastSectionMarginsTwips.left,
|
|
1199
|
+
right: secProps.marginRight ?? lastSectionMarginsTwips.right
|
|
1200
|
+
};
|
|
1201
|
+
sectionBreak.margins = {
|
|
1202
|
+
top: twipsToPixels(lastSectionMarginsTwips.top),
|
|
1203
|
+
bottom: twipsToPixels(lastSectionMarginsTwips.bottom),
|
|
1204
|
+
left: twipsToPixels(lastSectionMarginsTwips.left),
|
|
1205
|
+
right: twipsToPixels(lastSectionMarginsTwips.right)
|
|
1206
|
+
};
|
|
1207
|
+
if (secProps.headerDistance !== void 0) sectionBreak.margins.header = twipsToPixels(secProps.headerDistance);
|
|
1208
|
+
if (secProps.footerDistance !== void 0) sectionBreak.margins.footer = twipsToPixels(secProps.footerDistance);
|
|
1209
|
+
}
|
|
1210
|
+
const colCount = secProps.columnCount ?? 1;
|
|
1211
|
+
if (colCount > 1) {
|
|
1212
|
+
const cols = {
|
|
1213
|
+
count: colCount,
|
|
1214
|
+
gap: twipsToPixels(secProps.columnSpace ?? 720),
|
|
1215
|
+
equalWidth: secProps.equalWidth ?? true
|
|
1216
|
+
};
|
|
1217
|
+
if (secProps.separator !== void 0) cols.separator = secProps.separator;
|
|
1218
|
+
sectionBreak.columns = cols;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
trackedPush(sectionBreak);
|
|
1222
|
+
}
|
|
1223
|
+
break;
|
|
1224
|
+
}
|
|
1225
|
+
case "table":
|
|
1226
|
+
trackedPush(convertTable(node, pos, opts));
|
|
1227
|
+
break;
|
|
1228
|
+
case "image":
|
|
1229
|
+
trackedPush(convertImage(node, pos, opts.pageContentHeight));
|
|
1230
|
+
break;
|
|
1231
|
+
case "textBox":
|
|
1232
|
+
trackedPush(convertTextBoxNode(node, pos, opts));
|
|
1233
|
+
break;
|
|
1234
|
+
case "horizontalRule":
|
|
1235
|
+
case "pageBreak":
|
|
1236
|
+
trackedPush({
|
|
1237
|
+
kind: "pageBreak",
|
|
1238
|
+
id: nextBlockId(),
|
|
1239
|
+
pmStart: pos,
|
|
1240
|
+
pmEnd: pos + node.nodeSize
|
|
1241
|
+
});
|
|
1242
|
+
break;
|
|
1243
|
+
default: break;
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
doc.forEach((node, nodeOffset) => {
|
|
1247
|
+
visit(node, offset + nodeOffset);
|
|
1248
|
+
});
|
|
1249
|
+
return mergeRunInParagraphs(blocks);
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Merge consecutive paragraph blocks where the first carries
|
|
1253
|
+
* `runInWithNext` (`<w:specVanish/>` on the paragraph mark).
|
|
1254
|
+
*
|
|
1255
|
+
* Word's run-in heading feature renders the next paragraph inline on
|
|
1256
|
+
* the same line, so for layout we collapse the pair into one
|
|
1257
|
+
* ParagraphBlock with combined runs. The merged block keeps the first
|
|
1258
|
+
* paragraph's attrs (heading formatting, list marker, indent) and
|
|
1259
|
+
* extends pmEnd to the second paragraph's range so click-to-position
|
|
1260
|
+
* resolution still maps both ranges back to body content.
|
|
1261
|
+
*
|
|
1262
|
+
* Chains: runInWithNext on the merged block is dropped because the
|
|
1263
|
+
* second paragraph's mark wasn't `specVanish`. If a chain of
|
|
1264
|
+
* specVanish paragraphs needs collapsing (rare in practice), the loop
|
|
1265
|
+
* naturally handles it by re-inspecting the merged block's flag (we
|
|
1266
|
+
* preserve runInWithNext only when the second paragraph itself has
|
|
1267
|
+
* specVanish).
|
|
1268
|
+
*/
|
|
1269
|
+
function sdtGroupStacksEqual(a, b) {
|
|
1270
|
+
const lenA = a?.length ?? 0;
|
|
1271
|
+
if (lenA !== (b?.length ?? 0)) return false;
|
|
1272
|
+
if (lenA === 0) return true;
|
|
1273
|
+
for (let i = 0; i < lenA; i++) if (a?.[i]?.pmPos !== b?.[i]?.pmPos) return false;
|
|
1274
|
+
return true;
|
|
1275
|
+
}
|
|
1276
|
+
function mergeRunInParagraphs(blocks) {
|
|
1277
|
+
const out = [];
|
|
1278
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
1279
|
+
let current = blocks[i];
|
|
1280
|
+
if (!current) continue;
|
|
1281
|
+
while (current.kind === "paragraph" && current.attrs?.runInWithNext && i + 1 < blocks.length) {
|
|
1282
|
+
const next = blocks[i + 1];
|
|
1283
|
+
if (!next || next.kind !== "paragraph") break;
|
|
1284
|
+
const a = current;
|
|
1285
|
+
const b = next;
|
|
1286
|
+
if (!sdtGroupStacksEqual(a.sdtGroups, b.sdtGroups)) break;
|
|
1287
|
+
const mergedAttrs = { ...a.attrs };
|
|
1288
|
+
if (b.attrs?.spacing?.after !== void 0) mergedAttrs.spacing = {
|
|
1289
|
+
...mergedAttrs.spacing,
|
|
1290
|
+
after: b.attrs.spacing.after
|
|
1291
|
+
};
|
|
1292
|
+
if (b.attrs?.runInWithNext) mergedAttrs.runInWithNext = true;
|
|
1293
|
+
else delete mergedAttrs.runInWithNext;
|
|
1294
|
+
const merged = {
|
|
1295
|
+
...a,
|
|
1296
|
+
runs: [...a.runs, ...b.runs],
|
|
1297
|
+
attrs: mergedAttrs
|
|
1298
|
+
};
|
|
1299
|
+
const mergedPmEnd = b.pmEnd ?? a.pmEnd;
|
|
1300
|
+
if (mergedPmEnd !== void 0) merged.pmEnd = mergedPmEnd;
|
|
1301
|
+
current = merged;
|
|
1302
|
+
i += 1;
|
|
1303
|
+
}
|
|
1304
|
+
out.push(current);
|
|
1305
|
+
}
|
|
1306
|
+
return out;
|
|
1307
|
+
}
|
|
1308
|
+
//#endregion
|
|
1309
|
+
export { convertBorderSpecToLayout, formatCounter, resetBlockIdCounter, resolveListTemplate, toFlowBlocks };
|