@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,1132 @@
|
|
|
1
|
+
import { elementToXml, findChild, findChildren, getAttribute, getChildElements, mergeXmlnsDeclarations, parseBooleanElement, parseNumericAttribute } from "./xmlParser.js";
|
|
2
|
+
import { parseBookmarkEnd as parseBookmarkEnd$1, parseBookmarkStart as parseBookmarkStart$1 } from "./bookmarkParser.js";
|
|
3
|
+
import { BorderStyleSchema, FrameWrapSchema, FrameXAlignSchema, FrameYAlignSchema, LineSpacingRuleSchema, ParagraphAlignmentSchema, ShadingPatternSchema, TabLeaderSchema, TabStopAlignmentSchema, ThemeColorSlotSchema, narrowEnum } from "./parserEnums.js";
|
|
4
|
+
import { parseRun, parseRunProperties } from "./runParser.js";
|
|
5
|
+
import { parseFieldType } from "./fieldParser.js";
|
|
6
|
+
import { parseHyperlink as parseHyperlink$1 } from "./hyperlinkParser.js";
|
|
7
|
+
import { consolidateParagraphContent } from "./runConsolidator.js";
|
|
8
|
+
import { parseSdtProperties } from "./sdtProperties.js";
|
|
9
|
+
import { parseSectionProperties } from "./sectionParser.js";
|
|
10
|
+
//#region src/docx/paragraphParser.ts
|
|
11
|
+
/**
|
|
12
|
+
* Extract plain text from a math element (recursive text content extraction)
|
|
13
|
+
*/
|
|
14
|
+
function extractPlainText(runs) {
|
|
15
|
+
let out = "";
|
|
16
|
+
for (const run of runs) for (const c of run.content) if (c.type === "text") out += c.text;
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
function extractMathText(el) {
|
|
20
|
+
let text = "";
|
|
21
|
+
if (el.type === "text" && typeof el.text === "string") return el.text;
|
|
22
|
+
if (el.elements) for (const child of el.elements) if ((child.name?.replace(/^.*:/u, "") ?? "") === "t" && child.elements) {
|
|
23
|
+
for (const t of child.elements) if (t.type === "text" && typeof t.text === "string") text += t.text;
|
|
24
|
+
} else text += extractMathText(child);
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parse color value from attributes
|
|
29
|
+
*/
|
|
30
|
+
function parseColorValue(rgb, themeColor, themeTint, themeShade) {
|
|
31
|
+
const color = {};
|
|
32
|
+
if (rgb && rgb !== "auto") color.rgb = rgb;
|
|
33
|
+
else if (rgb === "auto") color.auto = true;
|
|
34
|
+
const validatedThemeColor = narrowEnum(themeColor, ThemeColorSlotSchema);
|
|
35
|
+
if (validatedThemeColor) color.themeColor = validatedThemeColor;
|
|
36
|
+
if (themeTint) color.themeTint = themeTint;
|
|
37
|
+
if (themeShade) color.themeShade = themeShade;
|
|
38
|
+
return color;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse shading properties (w:shd)
|
|
42
|
+
*/
|
|
43
|
+
function parseShadingProperties(shd) {
|
|
44
|
+
if (!shd) return;
|
|
45
|
+
const props = {};
|
|
46
|
+
const color = getAttribute(shd, "w", "color");
|
|
47
|
+
if (color && color !== "auto") props.color = { rgb: color };
|
|
48
|
+
const fill = getAttribute(shd, "w", "fill");
|
|
49
|
+
if (fill && fill !== "auto") props.fill = { rgb: fill };
|
|
50
|
+
const validatedThemeFill = narrowEnum(getAttribute(shd, "w", "themeFill"), ThemeColorSlotSchema);
|
|
51
|
+
if (validatedThemeFill) {
|
|
52
|
+
props.fill = props.fill || {};
|
|
53
|
+
props.fill.themeColor = validatedThemeFill;
|
|
54
|
+
}
|
|
55
|
+
const themeFillTint = getAttribute(shd, "w", "themeFillTint");
|
|
56
|
+
if (themeFillTint && props.fill) props.fill.themeTint = themeFillTint;
|
|
57
|
+
const themeFillShade = getAttribute(shd, "w", "themeFillShade");
|
|
58
|
+
if (themeFillShade && props.fill) props.fill.themeShade = themeFillShade;
|
|
59
|
+
const pattern = narrowEnum(getAttribute(shd, "w", "val"), ShadingPatternSchema);
|
|
60
|
+
if (pattern) props.pattern = pattern;
|
|
61
|
+
return Object.keys(props).length > 0 ? props : void 0;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Parse border specification (w:top, w:bottom, w:left, w:right, etc.)
|
|
65
|
+
*/
|
|
66
|
+
function parseBorderSpec(border) {
|
|
67
|
+
if (!border) return;
|
|
68
|
+
const rawStyle = getAttribute(border, "w", "val");
|
|
69
|
+
if (!rawStyle) return;
|
|
70
|
+
const spec = { style: narrowEnum(rawStyle, BorderStyleSchema) ?? rawStyle };
|
|
71
|
+
const colorVal = getAttribute(border, "w", "color");
|
|
72
|
+
const themeColor = getAttribute(border, "w", "themeColor");
|
|
73
|
+
if (colorVal || themeColor) spec.color = parseColorValue(colorVal, themeColor, getAttribute(border, "w", "themeTint"), getAttribute(border, "w", "themeShade"));
|
|
74
|
+
const sz = parseNumericAttribute(border, "w", "sz");
|
|
75
|
+
if (sz !== void 0) spec.size = sz;
|
|
76
|
+
const space = parseNumericAttribute(border, "w", "space");
|
|
77
|
+
if (space !== void 0) spec.space = space;
|
|
78
|
+
const shadowAttr = getAttribute(border, "w", "shadow");
|
|
79
|
+
if (shadowAttr) spec.shadow = shadowAttr === "1" || shadowAttr === "true";
|
|
80
|
+
const frame = getAttribute(border, "w", "frame");
|
|
81
|
+
if (frame) spec.frame = frame === "1" || frame === "true";
|
|
82
|
+
return spec;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Parse tab stops (w:tabs)
|
|
86
|
+
*/
|
|
87
|
+
function parseTabStops(tabs) {
|
|
88
|
+
if (!tabs) return;
|
|
89
|
+
const tabElements = findChildren(tabs, "w", "tab");
|
|
90
|
+
if (tabElements.length === 0) return;
|
|
91
|
+
const result = [];
|
|
92
|
+
for (const tab of tabElements) {
|
|
93
|
+
const pos = parseNumericAttribute(tab, "w", "pos");
|
|
94
|
+
const alignment = narrowEnum(getAttribute(tab, "w", "val"), TabStopAlignmentSchema);
|
|
95
|
+
if (pos !== void 0 && alignment) {
|
|
96
|
+
const tabStop = {
|
|
97
|
+
position: pos,
|
|
98
|
+
alignment
|
|
99
|
+
};
|
|
100
|
+
const leader = narrowEnum(getAttribute(tab, "w", "leader"), TabLeaderSchema);
|
|
101
|
+
if (leader) tabStop.leader = leader;
|
|
102
|
+
result.push(tabStop);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return result.length > 0 ? result : void 0;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parse frame properties (w:framePr)
|
|
109
|
+
*/
|
|
110
|
+
function parseFrameProperties(framePr) {
|
|
111
|
+
if (!framePr) return;
|
|
112
|
+
const frame = {};
|
|
113
|
+
const w = parseNumericAttribute(framePr, "w", "w");
|
|
114
|
+
if (w !== void 0) frame.width = w;
|
|
115
|
+
const h = parseNumericAttribute(framePr, "w", "h");
|
|
116
|
+
if (h !== void 0) frame.height = h;
|
|
117
|
+
const hAnchor = getAttribute(framePr, "w", "hAnchor");
|
|
118
|
+
if (hAnchor === "text" || hAnchor === "margin" || hAnchor === "page") frame.hAnchor = hAnchor;
|
|
119
|
+
const vAnchor = getAttribute(framePr, "w", "vAnchor");
|
|
120
|
+
if (vAnchor === "text" || vAnchor === "margin" || vAnchor === "page") frame.vAnchor = vAnchor;
|
|
121
|
+
const x = parseNumericAttribute(framePr, "w", "x");
|
|
122
|
+
if (x !== void 0) frame.x = x;
|
|
123
|
+
const y = parseNumericAttribute(framePr, "w", "y");
|
|
124
|
+
if (y !== void 0) frame.y = y;
|
|
125
|
+
const xAlign = narrowEnum(getAttribute(framePr, "w", "xAlign"), FrameXAlignSchema);
|
|
126
|
+
if (xAlign) frame.xAlign = xAlign;
|
|
127
|
+
const yAlign = narrowEnum(getAttribute(framePr, "w", "yAlign"), FrameYAlignSchema);
|
|
128
|
+
if (yAlign) frame.yAlign = yAlign;
|
|
129
|
+
const wrap = narrowEnum(getAttribute(framePr, "w", "wrap"), FrameWrapSchema);
|
|
130
|
+
if (wrap) frame.wrap = wrap;
|
|
131
|
+
return Object.keys(frame).length > 0 ? frame : void 0;
|
|
132
|
+
}
|
|
133
|
+
function collectFirstParagraphPropertyChildren(pPr) {
|
|
134
|
+
const children = {};
|
|
135
|
+
for (const child of pPr.elements ?? []) {
|
|
136
|
+
if (child.type !== "element") continue;
|
|
137
|
+
switch (getLocalName(child.name)) {
|
|
138
|
+
case "bidi":
|
|
139
|
+
children.bidi ??= child;
|
|
140
|
+
break;
|
|
141
|
+
case "contextualSpacing":
|
|
142
|
+
children.contextualSpacing ??= child;
|
|
143
|
+
break;
|
|
144
|
+
case "framePr":
|
|
145
|
+
children.framePr ??= child;
|
|
146
|
+
break;
|
|
147
|
+
case "ind":
|
|
148
|
+
children.ind ??= child;
|
|
149
|
+
break;
|
|
150
|
+
case "jc":
|
|
151
|
+
children.jc ??= child;
|
|
152
|
+
break;
|
|
153
|
+
case "keepLines":
|
|
154
|
+
children.keepLines ??= child;
|
|
155
|
+
break;
|
|
156
|
+
case "keepNext":
|
|
157
|
+
children.keepNext ??= child;
|
|
158
|
+
break;
|
|
159
|
+
case "numPr":
|
|
160
|
+
children.numPr ??= child;
|
|
161
|
+
break;
|
|
162
|
+
case "outlineLvl":
|
|
163
|
+
children.outlineLvl ??= child;
|
|
164
|
+
break;
|
|
165
|
+
case "pageBreakBefore":
|
|
166
|
+
children.pageBreakBefore ??= child;
|
|
167
|
+
break;
|
|
168
|
+
case "pBdr":
|
|
169
|
+
children.pBdr ??= child;
|
|
170
|
+
break;
|
|
171
|
+
case "pStyle":
|
|
172
|
+
children.pStyle ??= child;
|
|
173
|
+
break;
|
|
174
|
+
case "rPr":
|
|
175
|
+
children.rPr ??= child;
|
|
176
|
+
break;
|
|
177
|
+
case "shd":
|
|
178
|
+
children.shd ??= child;
|
|
179
|
+
break;
|
|
180
|
+
case "spacing":
|
|
181
|
+
children.spacing ??= child;
|
|
182
|
+
break;
|
|
183
|
+
case "suppressAutoHyphens":
|
|
184
|
+
children.suppressAutoHyphens ??= child;
|
|
185
|
+
break;
|
|
186
|
+
case "suppressLineNumbers":
|
|
187
|
+
children.suppressLineNumbers ??= child;
|
|
188
|
+
break;
|
|
189
|
+
case "tabs":
|
|
190
|
+
children.tabs ??= child;
|
|
191
|
+
break;
|
|
192
|
+
case "widowControl":
|
|
193
|
+
children.widowControl ??= child;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return children;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Parse paragraph formatting properties (w:pPr)
|
|
201
|
+
*
|
|
202
|
+
* Handles ALL pPr properties:
|
|
203
|
+
* - w:jc (alignment: left, center, right, both/justify)
|
|
204
|
+
* - w:spacing (before, after, line, lineRule)
|
|
205
|
+
* - w:ind (left, right, firstLine, hanging)
|
|
206
|
+
* - w:pBdr (paragraph borders: top, bottom, left, right, between)
|
|
207
|
+
* - w:shd (paragraph shading/background)
|
|
208
|
+
* - w:tabs (tab stops with positions and types)
|
|
209
|
+
* - w:keepNext, w:keepLines, w:widowControl, w:pageBreakBefore
|
|
210
|
+
* - w:bidi (right-to-left)
|
|
211
|
+
* - w:numPr (list info)
|
|
212
|
+
* - w:pStyle (style reference)
|
|
213
|
+
* - w:outlineLvl (outline level)
|
|
214
|
+
* - w:framePr (frame properties)
|
|
215
|
+
* - w:rPr (default run properties)
|
|
216
|
+
*/
|
|
217
|
+
function parseParagraphProperties(pPr, theme, styles) {
|
|
218
|
+
if (!pPr) return;
|
|
219
|
+
const formatting = {};
|
|
220
|
+
const propertyChildren = collectFirstParagraphPropertyChildren(pPr);
|
|
221
|
+
const jc = propertyChildren.jc;
|
|
222
|
+
if (jc) {
|
|
223
|
+
const val = narrowEnum(getAttribute(jc, "w", "val"), ParagraphAlignmentSchema);
|
|
224
|
+
if (val) formatting.alignment = val;
|
|
225
|
+
}
|
|
226
|
+
const bidi = propertyChildren.bidi;
|
|
227
|
+
if (bidi) formatting.bidi = parseBooleanElement(bidi);
|
|
228
|
+
const spacing = propertyChildren.spacing;
|
|
229
|
+
if (spacing) {
|
|
230
|
+
const before = parseNumericAttribute(spacing, "w", "before");
|
|
231
|
+
if (before !== void 0) formatting.spaceBefore = before;
|
|
232
|
+
const after = parseNumericAttribute(spacing, "w", "after");
|
|
233
|
+
if (after !== void 0) formatting.spaceAfter = after;
|
|
234
|
+
const line = parseNumericAttribute(spacing, "w", "line");
|
|
235
|
+
if (line !== void 0) formatting.lineSpacing = line;
|
|
236
|
+
const spacingExplicit = {};
|
|
237
|
+
if (before !== void 0) spacingExplicit.before = true;
|
|
238
|
+
if (after !== void 0) spacingExplicit.after = true;
|
|
239
|
+
if (spacingExplicit.before || spacingExplicit.after) formatting.spacingExplicit = spacingExplicit;
|
|
240
|
+
const lineRule = narrowEnum(getAttribute(spacing, "w", "lineRule"), LineSpacingRuleSchema);
|
|
241
|
+
if (lineRule) formatting.lineSpacingRule = lineRule;
|
|
242
|
+
const beforeAuto = getAttribute(spacing, "w", "beforeAutospacing");
|
|
243
|
+
if (beforeAuto) formatting.beforeAutospacing = beforeAuto === "1" || beforeAuto === "true";
|
|
244
|
+
const afterAuto = getAttribute(spacing, "w", "afterAutospacing");
|
|
245
|
+
if (afterAuto) formatting.afterAutospacing = afterAuto === "1" || afterAuto === "true";
|
|
246
|
+
}
|
|
247
|
+
const ind = propertyChildren.ind;
|
|
248
|
+
if (ind) {
|
|
249
|
+
const left = parseNumericAttribute(ind, "w", "left");
|
|
250
|
+
if (left !== void 0) formatting.indentLeft = left;
|
|
251
|
+
const right = parseNumericAttribute(ind, "w", "right");
|
|
252
|
+
if (right !== void 0) formatting.indentRight = right;
|
|
253
|
+
const firstLine = parseNumericAttribute(ind, "w", "firstLine");
|
|
254
|
+
if (firstLine !== void 0) formatting.indentFirstLine = firstLine;
|
|
255
|
+
const hanging = parseNumericAttribute(ind, "w", "hanging");
|
|
256
|
+
if (hanging !== void 0) {
|
|
257
|
+
formatting.indentFirstLine = -hanging;
|
|
258
|
+
formatting.hangingIndent = true;
|
|
259
|
+
}
|
|
260
|
+
const start = parseNumericAttribute(ind, "w", "start");
|
|
261
|
+
if (start !== void 0 && formatting.indentLeft === void 0) formatting.indentLeft = start;
|
|
262
|
+
const end = parseNumericAttribute(ind, "w", "end");
|
|
263
|
+
if (end !== void 0 && formatting.indentRight === void 0) formatting.indentRight = end;
|
|
264
|
+
}
|
|
265
|
+
const pBdr = propertyChildren.pBdr;
|
|
266
|
+
if (pBdr) {
|
|
267
|
+
const borders = {};
|
|
268
|
+
const top = parseBorderSpec(findChild(pBdr, "w", "top"));
|
|
269
|
+
if (top) borders.top = top;
|
|
270
|
+
const bottom = parseBorderSpec(findChild(pBdr, "w", "bottom"));
|
|
271
|
+
if (bottom) borders.bottom = bottom;
|
|
272
|
+
const left = parseBorderSpec(findChild(pBdr, "w", "left"));
|
|
273
|
+
if (left) borders.left = left;
|
|
274
|
+
const right = parseBorderSpec(findChild(pBdr, "w", "right"));
|
|
275
|
+
if (right) borders.right = right;
|
|
276
|
+
const between = parseBorderSpec(findChild(pBdr, "w", "between"));
|
|
277
|
+
if (between) borders.between = between;
|
|
278
|
+
const bar = parseBorderSpec(findChild(pBdr, "w", "bar"));
|
|
279
|
+
if (bar) borders.bar = bar;
|
|
280
|
+
if (Object.keys(borders).length > 0) formatting.borders = borders;
|
|
281
|
+
}
|
|
282
|
+
const shd = propertyChildren.shd;
|
|
283
|
+
if (shd) {
|
|
284
|
+
const shadingResult = parseShadingProperties(shd);
|
|
285
|
+
if (shadingResult !== void 0) formatting.shading = shadingResult;
|
|
286
|
+
}
|
|
287
|
+
const tabs = propertyChildren.tabs;
|
|
288
|
+
if (tabs) {
|
|
289
|
+
const tabsResult = parseTabStops(tabs);
|
|
290
|
+
if (tabsResult !== void 0) formatting.tabs = tabsResult;
|
|
291
|
+
}
|
|
292
|
+
const keepNext = propertyChildren.keepNext;
|
|
293
|
+
if (keepNext) formatting.keepNext = parseBooleanElement(keepNext);
|
|
294
|
+
const keepLines = propertyChildren.keepLines;
|
|
295
|
+
if (keepLines) formatting.keepLines = parseBooleanElement(keepLines);
|
|
296
|
+
const widowControl = propertyChildren.widowControl;
|
|
297
|
+
if (widowControl) formatting.widowControl = parseBooleanElement(widowControl);
|
|
298
|
+
const pageBreakBefore = propertyChildren.pageBreakBefore;
|
|
299
|
+
if (pageBreakBefore) formatting.pageBreakBefore = parseBooleanElement(pageBreakBefore);
|
|
300
|
+
const contextualSpacing = propertyChildren.contextualSpacing;
|
|
301
|
+
if (contextualSpacing) formatting.contextualSpacing = parseBooleanElement(contextualSpacing);
|
|
302
|
+
const numPr = propertyChildren.numPr;
|
|
303
|
+
if (numPr) {
|
|
304
|
+
const numIdEl = findChild(numPr, "w", "numId");
|
|
305
|
+
const ilvlEl = findChild(numPr, "w", "ilvl");
|
|
306
|
+
if (numIdEl || ilvlEl) {
|
|
307
|
+
formatting.numPr = {};
|
|
308
|
+
if (numIdEl) {
|
|
309
|
+
const val = parseNumericAttribute(numIdEl, "w", "val");
|
|
310
|
+
if (val !== void 0) formatting.numPr.numId = val;
|
|
311
|
+
}
|
|
312
|
+
if (ilvlEl) {
|
|
313
|
+
const val = parseNumericAttribute(ilvlEl, "w", "val");
|
|
314
|
+
if (val !== void 0) formatting.numPr.ilvl = val;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const outlineLvl = propertyChildren.outlineLvl;
|
|
319
|
+
if (outlineLvl) {
|
|
320
|
+
const val = parseNumericAttribute(outlineLvl, "w", "val");
|
|
321
|
+
if (val !== void 0) formatting.outlineLevel = val;
|
|
322
|
+
}
|
|
323
|
+
const pStyle = propertyChildren.pStyle;
|
|
324
|
+
if (pStyle) {
|
|
325
|
+
const val = getAttribute(pStyle, "w", "val");
|
|
326
|
+
if (val) formatting.styleId = val;
|
|
327
|
+
}
|
|
328
|
+
const framePr = propertyChildren.framePr;
|
|
329
|
+
if (framePr) {
|
|
330
|
+
const frameResult = parseFrameProperties(framePr);
|
|
331
|
+
if (frameResult !== void 0) formatting.frame = frameResult;
|
|
332
|
+
}
|
|
333
|
+
const suppressLineNumbers = propertyChildren.suppressLineNumbers;
|
|
334
|
+
if (suppressLineNumbers) formatting.suppressLineNumbers = parseBooleanElement(suppressLineNumbers);
|
|
335
|
+
const suppressAutoHyphens = propertyChildren.suppressAutoHyphens;
|
|
336
|
+
if (suppressAutoHyphens) formatting.suppressAutoHyphens = parseBooleanElement(suppressAutoHyphens);
|
|
337
|
+
const rPr = propertyChildren.rPr;
|
|
338
|
+
if (rPr) {
|
|
339
|
+
const runPropsResult = parseRunProperties(rPr, theme, styles);
|
|
340
|
+
if (runPropsResult !== void 0) formatting.runProperties = runPropsResult;
|
|
341
|
+
const specVanish = findChild(rPr, "w", "specVanish");
|
|
342
|
+
if (specVanish && parseBooleanElement(specVanish)) formatting.runInWithNext = true;
|
|
343
|
+
}
|
|
344
|
+
return Object.keys(formatting).length > 0 ? formatting : void 0;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Get the local name of an element (without namespace prefix)
|
|
348
|
+
*/
|
|
349
|
+
function getLocalName(name) {
|
|
350
|
+
if (!name) return "";
|
|
351
|
+
const colonIndex = name.indexOf(":");
|
|
352
|
+
return colonIndex !== -1 ? name.slice(colonIndex + 1) : name;
|
|
353
|
+
}
|
|
354
|
+
function paragraphStartsWithRenderedPageBreak(node) {
|
|
355
|
+
const inlineWrappers = /* @__PURE__ */ new Set([
|
|
356
|
+
"hyperlink",
|
|
357
|
+
"smartTag",
|
|
358
|
+
"sdt",
|
|
359
|
+
"sdtContent",
|
|
360
|
+
"fldSimple",
|
|
361
|
+
"customXml",
|
|
362
|
+
"ins",
|
|
363
|
+
"del",
|
|
364
|
+
"moveFrom",
|
|
365
|
+
"moveTo"
|
|
366
|
+
]);
|
|
367
|
+
const nonContentMarkers = /* @__PURE__ */ new Set([
|
|
368
|
+
"pPr",
|
|
369
|
+
"proofErr",
|
|
370
|
+
"bookmarkStart",
|
|
371
|
+
"bookmarkEnd",
|
|
372
|
+
"commentRangeStart",
|
|
373
|
+
"commentRangeEnd",
|
|
374
|
+
"commentReference",
|
|
375
|
+
"permStart",
|
|
376
|
+
"permEnd",
|
|
377
|
+
"rsidR"
|
|
378
|
+
]);
|
|
379
|
+
const visibleRunContent = /* @__PURE__ */ new Set([
|
|
380
|
+
"t",
|
|
381
|
+
"tab",
|
|
382
|
+
"br",
|
|
383
|
+
"cr",
|
|
384
|
+
"sym",
|
|
385
|
+
"drawing",
|
|
386
|
+
"pict",
|
|
387
|
+
"object",
|
|
388
|
+
"softHyphen",
|
|
389
|
+
"noBreakHyphen",
|
|
390
|
+
"fldChar",
|
|
391
|
+
"instrText",
|
|
392
|
+
"pgNum",
|
|
393
|
+
"separator",
|
|
394
|
+
"continuationSeparator",
|
|
395
|
+
"footnoteRef",
|
|
396
|
+
"endnoteRef",
|
|
397
|
+
"footnoteReference",
|
|
398
|
+
"endnoteReference",
|
|
399
|
+
"ptab",
|
|
400
|
+
"monthShort",
|
|
401
|
+
"monthLong",
|
|
402
|
+
"yearShort",
|
|
403
|
+
"yearLong",
|
|
404
|
+
"dayShort",
|
|
405
|
+
"dayLong"
|
|
406
|
+
]);
|
|
407
|
+
let sawRenderedPageBreak = false;
|
|
408
|
+
const visit = (element) => {
|
|
409
|
+
for (const child of getChildElements(element)) {
|
|
410
|
+
const childName = getLocalName(child.name);
|
|
411
|
+
if (nonContentMarkers.has(childName)) continue;
|
|
412
|
+
if (childName === "lastRenderedPageBreak") {
|
|
413
|
+
sawRenderedPageBreak = true;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (childName === "r") {
|
|
417
|
+
for (const runChild of getChildElements(child)) {
|
|
418
|
+
const runChildName = getLocalName(runChild.name);
|
|
419
|
+
if (runChildName === "rPr") continue;
|
|
420
|
+
if (runChildName === "lastRenderedPageBreak") {
|
|
421
|
+
sawRenderedPageBreak = true;
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (runChildName === "br" && getAttribute(runChild, "w", "type") === "page") return "forced";
|
|
425
|
+
if (visibleRunContent.has(runChildName)) return "visible";
|
|
426
|
+
}
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
if (inlineWrappers.has(childName)) {
|
|
430
|
+
const result = visit(child);
|
|
431
|
+
if (result !== "continue") return result;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
return "continue";
|
|
435
|
+
}
|
|
436
|
+
return "continue";
|
|
437
|
+
};
|
|
438
|
+
const outcome = visit(node);
|
|
439
|
+
if (outcome === "forced") return true;
|
|
440
|
+
return outcome === "visible" && sawRenderedPageBreak;
|
|
441
|
+
}
|
|
442
|
+
function replaceLocalName(name, localName) {
|
|
443
|
+
if (!name) return `w:${localName}`;
|
|
444
|
+
const colonIndex = name.indexOf(":");
|
|
445
|
+
if (colonIndex === -1) return localName;
|
|
446
|
+
return `${name.slice(0, colonIndex + 1)}${localName}`;
|
|
447
|
+
}
|
|
448
|
+
function normalizeDeletionContentElement(node) {
|
|
449
|
+
if (node.type !== "element") return node;
|
|
450
|
+
const localName = getLocalName(node.name);
|
|
451
|
+
let mappedName = node.name;
|
|
452
|
+
if (localName === "delText") mappedName = replaceLocalName(node.name, "t");
|
|
453
|
+
else if (localName === "delInstrText") mappedName = replaceLocalName(node.name, "instrText");
|
|
454
|
+
const result = { ...node };
|
|
455
|
+
if (mappedName !== void 0) result.name = mappedName;
|
|
456
|
+
if (node.elements) result.elements = node.elements.map(normalizeDeletionContentElement);
|
|
457
|
+
return result;
|
|
458
|
+
}
|
|
459
|
+
function parseTrackedChangeInfo(node) {
|
|
460
|
+
const rawId = getAttribute(node, "w", "id");
|
|
461
|
+
const parsedId = rawId ? Number.parseInt(rawId, 10) : 0;
|
|
462
|
+
const rawAuthor = getAttribute(node, "w", "author");
|
|
463
|
+
const rawDate = getAttribute(node, "w", "date");
|
|
464
|
+
const author = rawAuthor?.trim() ?? "";
|
|
465
|
+
const date = rawDate?.trim() ?? "";
|
|
466
|
+
const info = {
|
|
467
|
+
id: Number.isInteger(parsedId) && parsedId >= 0 ? parsedId : 0,
|
|
468
|
+
author: author.length > 0 ? author : "Unknown"
|
|
469
|
+
};
|
|
470
|
+
if (date.length > 0) info.date = date;
|
|
471
|
+
return info;
|
|
472
|
+
}
|
|
473
|
+
function parsePropertyChangeInfo(node) {
|
|
474
|
+
const base = parseTrackedChangeInfo(node);
|
|
475
|
+
const rsid = (getAttribute(node, "w", "rsid") ?? "").trim();
|
|
476
|
+
return rsid.length > 0 ? {
|
|
477
|
+
...base,
|
|
478
|
+
rsid
|
|
479
|
+
} : base;
|
|
480
|
+
}
|
|
481
|
+
function parseParagraphPropertyChanges(pPr, theme, styles, currentFormatting) {
|
|
482
|
+
if (!pPr) return;
|
|
483
|
+
const changes = findChildren(pPr, "w", "pPrChange").map((changeElement) => {
|
|
484
|
+
const previousFormatting = parseParagraphProperties(findChild(changeElement, "w", "pPr"), theme, styles ?? void 0);
|
|
485
|
+
const change = {
|
|
486
|
+
type: "paragraphPropertyChange",
|
|
487
|
+
info: parsePropertyChangeInfo(changeElement)
|
|
488
|
+
};
|
|
489
|
+
if (previousFormatting !== void 0) change.previousFormatting = previousFormatting;
|
|
490
|
+
if (currentFormatting !== void 0) change.currentFormatting = currentFormatting;
|
|
491
|
+
return change;
|
|
492
|
+
}).filter((change) => change.previousFormatting || change.currentFormatting);
|
|
493
|
+
return changes.length > 0 ? changes : void 0;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Parse `<w:pPr><w:rPr><w:ins/>` or `<w:del/>` — the OOXML paragraph-mark
|
|
497
|
+
* tracked-change marker (ECMA-376 §17.13.5). Returns the first marker
|
|
498
|
+
* encountered, or undefined when none is present. `ins` and `del` are
|
|
499
|
+
* mutually exclusive in valid documents.
|
|
500
|
+
*/
|
|
501
|
+
function parseParagraphMarkChange(pPr) {
|
|
502
|
+
if (!pPr) return;
|
|
503
|
+
const rPr = findChild(pPr, "w", "rPr");
|
|
504
|
+
if (!rPr) return;
|
|
505
|
+
const ins = findChild(rPr, "w", "ins");
|
|
506
|
+
if (ins) return {
|
|
507
|
+
kind: "ins",
|
|
508
|
+
info: parseTrackedChangeInfo(ins)
|
|
509
|
+
};
|
|
510
|
+
const del = findChild(rPr, "w", "del");
|
|
511
|
+
if (del) return {
|
|
512
|
+
kind: "del",
|
|
513
|
+
info: parseTrackedChangeInfo(del)
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
function isTrackedChangeWrapperChild(content) {
|
|
517
|
+
return content.type === "run" || content.type === "hyperlink";
|
|
518
|
+
}
|
|
519
|
+
function isInlineSdtContent(content) {
|
|
520
|
+
return content.type === "run" || content.type === "hyperlink" || content.type === "simpleField" || content.type === "complexField" || content.type === "inlineSdt" || content.type === "mathEquation";
|
|
521
|
+
}
|
|
522
|
+
function pushTrackedChangeWrapper({ contents, type, info, content, preserveEmpty = false }) {
|
|
523
|
+
if (content.length === 0 && !preserveEmpty) return;
|
|
524
|
+
if (type === "insertion") {
|
|
525
|
+
contents.push({
|
|
526
|
+
type: "insertion",
|
|
527
|
+
info,
|
|
528
|
+
content: [...content]
|
|
529
|
+
});
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
if (type === "deletion") {
|
|
533
|
+
contents.push({
|
|
534
|
+
type: "deletion",
|
|
535
|
+
info,
|
|
536
|
+
content: [...content]
|
|
537
|
+
});
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if (type === "moveFrom") {
|
|
541
|
+
contents.push({
|
|
542
|
+
type: "moveFrom",
|
|
543
|
+
info,
|
|
544
|
+
content: [...content]
|
|
545
|
+
});
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
contents.push({
|
|
549
|
+
type: "moveTo",
|
|
550
|
+
info,
|
|
551
|
+
content: [...content]
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
function pushTrackedChangeSegments({ contents, type, info, parsedContent }) {
|
|
555
|
+
if (!parsedContent.some(isTrackedChangeWrapperChild)) {
|
|
556
|
+
pushTrackedChangeWrapper({
|
|
557
|
+
contents,
|
|
558
|
+
type,
|
|
559
|
+
info,
|
|
560
|
+
content: [],
|
|
561
|
+
preserveEmpty: true
|
|
562
|
+
});
|
|
563
|
+
contents.push(...parsedContent);
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
const segment = [];
|
|
567
|
+
for (const content of parsedContent) {
|
|
568
|
+
if (isTrackedChangeWrapperChild(content)) {
|
|
569
|
+
segment.push(content);
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
pushTrackedChangeWrapper({
|
|
573
|
+
contents,
|
|
574
|
+
type,
|
|
575
|
+
info,
|
|
576
|
+
content: segment
|
|
577
|
+
});
|
|
578
|
+
segment.length = 0;
|
|
579
|
+
contents.push(content);
|
|
580
|
+
}
|
|
581
|
+
pushTrackedChangeWrapper({
|
|
582
|
+
contents,
|
|
583
|
+
type,
|
|
584
|
+
info,
|
|
585
|
+
content: segment
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
function pushInlineSdtSegments({ contents, properties, parsedContent }) {
|
|
589
|
+
if (!parsedContent.some(isInlineSdtContent)) {
|
|
590
|
+
contents.push({
|
|
591
|
+
type: "inlineSdt",
|
|
592
|
+
properties,
|
|
593
|
+
content: []
|
|
594
|
+
});
|
|
595
|
+
contents.push(...parsedContent);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const segment = [];
|
|
599
|
+
const pushSegment = () => {
|
|
600
|
+
if (segment.length === 0) return;
|
|
601
|
+
contents.push({
|
|
602
|
+
type: "inlineSdt",
|
|
603
|
+
properties,
|
|
604
|
+
content: [...segment]
|
|
605
|
+
});
|
|
606
|
+
segment.length = 0;
|
|
607
|
+
};
|
|
608
|
+
for (const content of parsedContent) {
|
|
609
|
+
if (isInlineSdtContent(content)) {
|
|
610
|
+
segment.push(content);
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
pushSegment();
|
|
614
|
+
contents.push(content);
|
|
615
|
+
}
|
|
616
|
+
pushSegment();
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Parse hyperlink element (w:hyperlink)
|
|
620
|
+
*
|
|
621
|
+
* Delegates to hyperlinkParser module which resolves URLs via relationships.
|
|
622
|
+
*/
|
|
623
|
+
function parseHyperlink(node, rels, styles, theme, media, rootXmlns = {}) {
|
|
624
|
+
return parseHyperlink$1(node, rels, styles, theme, media, rootXmlns);
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Parse bookmark start (w:bookmarkStart)
|
|
628
|
+
* Delegates to bookmarkParser module.
|
|
629
|
+
*/
|
|
630
|
+
function parseBookmarkStart(node) {
|
|
631
|
+
return parseBookmarkStart$1(node);
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Parse bookmark end (w:bookmarkEnd)
|
|
635
|
+
* Delegates to bookmarkParser module.
|
|
636
|
+
*/
|
|
637
|
+
function parseBookmarkEnd(node) {
|
|
638
|
+
return parseBookmarkEnd$1(node);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Parse simple field (w:fldSimple)
|
|
642
|
+
*/
|
|
643
|
+
function parseSimpleField(node, styles, theme, rels, media, rootXmlns = {}) {
|
|
644
|
+
const instruction = getAttribute(node, "w", "instr") ?? "";
|
|
645
|
+
const field = {
|
|
646
|
+
type: "simpleField",
|
|
647
|
+
instruction,
|
|
648
|
+
fieldType: parseFieldType(instruction),
|
|
649
|
+
content: []
|
|
650
|
+
};
|
|
651
|
+
const fldLock = getAttribute(node, "w", "fldLock");
|
|
652
|
+
if (fldLock === "1" || fldLock === "true") field.fldLock = true;
|
|
653
|
+
const dirty = getAttribute(node, "w", "dirty");
|
|
654
|
+
if (dirty === "1" || dirty === "true") field.dirty = true;
|
|
655
|
+
const inScopeXmlns = mergeXmlnsDeclarations(rootXmlns, node);
|
|
656
|
+
const children = getChildElements(node);
|
|
657
|
+
for (const child of children) if (getLocalName(child.name) === "r") field.content.push(parseRun(child, styles, theme, rels, media, inScopeXmlns));
|
|
658
|
+
return field;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Parse all content within a paragraph
|
|
662
|
+
*
|
|
663
|
+
* Returns the parsed content and any complex fields that span multiple runs
|
|
664
|
+
*/
|
|
665
|
+
function parseParagraphContents(paraElement, styles, theme, _numbering, rels, media, trackedContext = "default", rootXmlns = {}) {
|
|
666
|
+
const contents = [];
|
|
667
|
+
const children = getChildElements(paraElement);
|
|
668
|
+
const inScopeXmlns = mergeXmlnsDeclarations(rootXmlns, paraElement);
|
|
669
|
+
let inComplexField = false;
|
|
670
|
+
let complexFieldInstr = "";
|
|
671
|
+
let complexFieldCodeRuns = [];
|
|
672
|
+
let complexFieldResultRuns = [];
|
|
673
|
+
let afterSeparator = false;
|
|
674
|
+
let complexFieldLock = false;
|
|
675
|
+
let complexFieldDirty = false;
|
|
676
|
+
let complexFieldFormatting;
|
|
677
|
+
for (const child of children) {
|
|
678
|
+
const localName = getLocalName(child.name);
|
|
679
|
+
switch (localName) {
|
|
680
|
+
case "r": {
|
|
681
|
+
const runElement = trackedContext === "deletion" ? normalizeDeletionContentElement(child) : child;
|
|
682
|
+
const run = parseRun(runElement, styles, theme, rels, media, inScopeXmlns);
|
|
683
|
+
const commentReferenceId = getCommentReferenceId(runElement);
|
|
684
|
+
let hasFieldBegin = false;
|
|
685
|
+
let hasFieldSeparate = false;
|
|
686
|
+
let hasFieldEnd = false;
|
|
687
|
+
let endOriginalValue;
|
|
688
|
+
let instrText = "";
|
|
689
|
+
for (const content of run.content) if (content.type === "fieldChar") if (content.charType === "begin") {
|
|
690
|
+
hasFieldBegin = true;
|
|
691
|
+
if (content.fldLock) complexFieldLock = true;
|
|
692
|
+
if (content.dirty) complexFieldDirty = true;
|
|
693
|
+
} else if (content.charType === "separate") hasFieldSeparate = true;
|
|
694
|
+
else {
|
|
695
|
+
hasFieldEnd = true;
|
|
696
|
+
if (content.originalValue !== void 0) endOriginalValue = content.originalValue;
|
|
697
|
+
}
|
|
698
|
+
else if (content.type === "instrText") instrText += content.text;
|
|
699
|
+
if (hasFieldBegin) {
|
|
700
|
+
if (inComplexField && afterSeparator) {
|
|
701
|
+
contents.push(...complexFieldResultRuns);
|
|
702
|
+
inComplexField = false;
|
|
703
|
+
}
|
|
704
|
+
inComplexField = true;
|
|
705
|
+
afterSeparator = false;
|
|
706
|
+
complexFieldInstr = "";
|
|
707
|
+
complexFieldCodeRuns = [];
|
|
708
|
+
complexFieldResultRuns = [];
|
|
709
|
+
complexFieldLock = false;
|
|
710
|
+
complexFieldDirty = false;
|
|
711
|
+
complexFieldFormatting = run.formatting;
|
|
712
|
+
}
|
|
713
|
+
if (inComplexField) {
|
|
714
|
+
if (instrText) complexFieldInstr += instrText;
|
|
715
|
+
if ((!complexFieldFormatting || Object.keys(complexFieldFormatting).length === 0) && run.formatting && Object.keys(run.formatting).length > 0) complexFieldFormatting = run.formatting;
|
|
716
|
+
if (hasFieldSeparate) afterSeparator = true;
|
|
717
|
+
if (afterSeparator && !hasFieldEnd) {
|
|
718
|
+
if (!hasFieldSeparate) complexFieldResultRuns.push(run);
|
|
719
|
+
} else if (!afterSeparator && !hasFieldBegin) complexFieldCodeRuns.push(run);
|
|
720
|
+
if (hasFieldEnd) {
|
|
721
|
+
let resultRuns = complexFieldResultRuns;
|
|
722
|
+
if (resultRuns.length === 0 && !afterSeparator && endOriginalValue !== void 0) resultRuns = [{
|
|
723
|
+
type: "run",
|
|
724
|
+
content: [{
|
|
725
|
+
type: "text",
|
|
726
|
+
text: endOriginalValue
|
|
727
|
+
}]
|
|
728
|
+
}];
|
|
729
|
+
const complexField = {
|
|
730
|
+
type: "complexField",
|
|
731
|
+
instruction: complexFieldInstr.trim(),
|
|
732
|
+
fieldType: parseFieldType(complexFieldInstr),
|
|
733
|
+
fieldCode: complexFieldCodeRuns,
|
|
734
|
+
fieldResult: resultRuns
|
|
735
|
+
};
|
|
736
|
+
if (complexFieldLock) complexField.fldLock = true;
|
|
737
|
+
if (complexFieldDirty) complexField.dirty = true;
|
|
738
|
+
if (complexFieldFormatting) complexField.formatting = complexFieldFormatting;
|
|
739
|
+
contents.push(complexField);
|
|
740
|
+
if (commentReferenceId !== null) contents.push({
|
|
741
|
+
type: "commentReference",
|
|
742
|
+
id: commentReferenceId
|
|
743
|
+
});
|
|
744
|
+
inComplexField = false;
|
|
745
|
+
}
|
|
746
|
+
} else if (commentReferenceId !== null) {
|
|
747
|
+
if (run.content.length > 0) contents.push(run);
|
|
748
|
+
contents.push({
|
|
749
|
+
type: "commentReference",
|
|
750
|
+
id: commentReferenceId
|
|
751
|
+
});
|
|
752
|
+
} else contents.push(run);
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
case "hyperlink":
|
|
756
|
+
contents.push(parseHyperlink(child, rels, styles, theme, media, inScopeXmlns));
|
|
757
|
+
break;
|
|
758
|
+
case "bookmarkStart":
|
|
759
|
+
contents.push(parseBookmarkStart(child));
|
|
760
|
+
break;
|
|
761
|
+
case "bookmarkEnd":
|
|
762
|
+
contents.push(parseBookmarkEnd(child));
|
|
763
|
+
break;
|
|
764
|
+
case "fldSimple":
|
|
765
|
+
contents.push(parseSimpleField(child, styles, theme, rels, media, inScopeXmlns));
|
|
766
|
+
break;
|
|
767
|
+
case "pPr": break;
|
|
768
|
+
case "proofErr":
|
|
769
|
+
case "permStart":
|
|
770
|
+
case "permEnd":
|
|
771
|
+
case "customXml": break;
|
|
772
|
+
case "sdt": {
|
|
773
|
+
const sdtPr = findChild(child, "w", "sdtPr");
|
|
774
|
+
const sdtEndPr = findChild(child, "w", "sdtEndPr");
|
|
775
|
+
const sdtContentEl = findChild(child, "w", "sdtContent");
|
|
776
|
+
if (sdtContentEl) {
|
|
777
|
+
const sdtParsed = parseParagraphContents(sdtContentEl, styles, theme, null, rels, media, trackedContext, mergeXmlnsDeclarations(inScopeXmlns, child));
|
|
778
|
+
pushInlineSdtSegments({
|
|
779
|
+
contents,
|
|
780
|
+
properties: parseSdtProperties(sdtPr, sdtEndPr),
|
|
781
|
+
parsedContent: sdtParsed
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
case "ins":
|
|
787
|
+
pushTrackedChangeSegments({
|
|
788
|
+
contents,
|
|
789
|
+
type: "insertion",
|
|
790
|
+
info: parseTrackedChangeInfo(child),
|
|
791
|
+
parsedContent: parseParagraphContents(child, styles, theme, null, rels, media, "default", inScopeXmlns)
|
|
792
|
+
});
|
|
793
|
+
break;
|
|
794
|
+
case "del":
|
|
795
|
+
pushTrackedChangeSegments({
|
|
796
|
+
contents,
|
|
797
|
+
type: "deletion",
|
|
798
|
+
info: parseTrackedChangeInfo(child),
|
|
799
|
+
parsedContent: parseParagraphContents(child, styles, theme, null, rels, media, "deletion", inScopeXmlns)
|
|
800
|
+
});
|
|
801
|
+
break;
|
|
802
|
+
case "moveFrom":
|
|
803
|
+
pushTrackedChangeSegments({
|
|
804
|
+
contents,
|
|
805
|
+
type: "moveFrom",
|
|
806
|
+
info: parseTrackedChangeInfo(child),
|
|
807
|
+
parsedContent: parseParagraphContents(child, styles, theme, null, rels, media, "deletion", inScopeXmlns)
|
|
808
|
+
});
|
|
809
|
+
break;
|
|
810
|
+
case "moveTo":
|
|
811
|
+
pushTrackedChangeSegments({
|
|
812
|
+
contents,
|
|
813
|
+
type: "moveTo",
|
|
814
|
+
info: parseTrackedChangeInfo(child),
|
|
815
|
+
parsedContent: parseParagraphContents(child, styles, theme, null, rels, media, "default", inScopeXmlns)
|
|
816
|
+
});
|
|
817
|
+
break;
|
|
818
|
+
case "smartTag": break;
|
|
819
|
+
case "moveFromRangeStart": {
|
|
820
|
+
const id = Number.parseInt(getAttribute(child, "w", "id") ?? "0", 10);
|
|
821
|
+
const name = getAttribute(child, "w", "name") ?? "";
|
|
822
|
+
contents.push({
|
|
823
|
+
type: "moveFromRangeStart",
|
|
824
|
+
id,
|
|
825
|
+
name
|
|
826
|
+
});
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
case "moveFromRangeEnd": {
|
|
830
|
+
const id = Number.parseInt(getAttribute(child, "w", "id") ?? "0", 10);
|
|
831
|
+
contents.push({
|
|
832
|
+
type: "moveFromRangeEnd",
|
|
833
|
+
id
|
|
834
|
+
});
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
case "moveToRangeStart": {
|
|
838
|
+
const id = Number.parseInt(getAttribute(child, "w", "id") ?? "0", 10);
|
|
839
|
+
const name = getAttribute(child, "w", "name") ?? "";
|
|
840
|
+
contents.push({
|
|
841
|
+
type: "moveToRangeStart",
|
|
842
|
+
id,
|
|
843
|
+
name
|
|
844
|
+
});
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
case "moveToRangeEnd": {
|
|
848
|
+
const id = Number.parseInt(getAttribute(child, "w", "id") ?? "0", 10);
|
|
849
|
+
contents.push({
|
|
850
|
+
type: "moveToRangeEnd",
|
|
851
|
+
id
|
|
852
|
+
});
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
case "commentRangeStart": {
|
|
856
|
+
const commentId = Number.parseInt(getAttribute(child, "w", "id") ?? "0", 10);
|
|
857
|
+
contents.push({
|
|
858
|
+
type: "commentRangeStart",
|
|
859
|
+
id: commentId
|
|
860
|
+
});
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
case "commentRangeEnd": {
|
|
864
|
+
const commentId = Number.parseInt(getAttribute(child, "w", "id") ?? "0", 10);
|
|
865
|
+
contents.push({
|
|
866
|
+
type: "commentRangeEnd",
|
|
867
|
+
id: commentId
|
|
868
|
+
});
|
|
869
|
+
break;
|
|
870
|
+
}
|
|
871
|
+
case "oMath":
|
|
872
|
+
case "oMathPara": {
|
|
873
|
+
const isBlock = localName === "oMathPara";
|
|
874
|
+
const ommlXml = elementToXml(child);
|
|
875
|
+
const plainText = extractMathText(child);
|
|
876
|
+
const mathEq = {
|
|
877
|
+
type: "mathEquation",
|
|
878
|
+
display: isBlock ? "block" : "inline",
|
|
879
|
+
ommlXml
|
|
880
|
+
};
|
|
881
|
+
if (plainText) mathEq.plainText = plainText;
|
|
882
|
+
contents.push(mathEq);
|
|
883
|
+
break;
|
|
884
|
+
}
|
|
885
|
+
default: break;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
if (inComplexField && afterSeparator) contents.push(...complexFieldResultRuns);
|
|
889
|
+
return contents;
|
|
890
|
+
}
|
|
891
|
+
function getCommentReferenceId(runElement) {
|
|
892
|
+
const commentReference = findChild(runElement, "w", "commentReference");
|
|
893
|
+
if (!commentReference) return null;
|
|
894
|
+
const id = Number.parseInt(getAttribute(commentReference, "w", "id") ?? "", 10);
|
|
895
|
+
return Number.isFinite(id) ? id : null;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Parse a paragraph element (w:p)
|
|
899
|
+
*
|
|
900
|
+
* @param node - The w:p XML element
|
|
901
|
+
* @param styles - Style map for resolving style references
|
|
902
|
+
* @param theme - Theme for resolving theme colors/fonts
|
|
903
|
+
* @param numbering - Numbering definitions for list info
|
|
904
|
+
* @param rels - Relationship map for resolving hyperlink URLs
|
|
905
|
+
* @param media - Media files map for image data
|
|
906
|
+
* @param options - Parsing options for context-specific body behavior
|
|
907
|
+
* @returns Parsed Paragraph object
|
|
908
|
+
*/
|
|
909
|
+
function parseParagraph(node, styles, theme, numbering, rels = null, media = null, options) {
|
|
910
|
+
const paragraph = {
|
|
911
|
+
type: "paragraph",
|
|
912
|
+
content: []
|
|
913
|
+
};
|
|
914
|
+
const paraId = getAttribute(node, "w14", "paraId") ?? getAttribute(node, "w", "paraId");
|
|
915
|
+
if (paraId) paragraph.paraId = paraId;
|
|
916
|
+
const textId = getAttribute(node, "w14", "textId") ?? getAttribute(node, "w", "textId");
|
|
917
|
+
if (textId) paragraph.textId = textId;
|
|
918
|
+
if (!options?.inHeaderFooter && paragraphStartsWithRenderedPageBreak(node)) paragraph.renderedPageBreakBefore = true;
|
|
919
|
+
const pPr = findChild(node, "w", "pPr");
|
|
920
|
+
if (pPr) {
|
|
921
|
+
const formattingResult = parseParagraphProperties(pPr, theme, styles ?? void 0);
|
|
922
|
+
if (formattingResult !== void 0) paragraph.formatting = formattingResult;
|
|
923
|
+
const propertyChangesResult = parseParagraphPropertyChanges(pPr, theme, styles, paragraph.formatting);
|
|
924
|
+
if (propertyChangesResult !== void 0) paragraph.propertyChanges = propertyChangesResult;
|
|
925
|
+
const pPrMarkResult = parseParagraphMarkChange(pPr);
|
|
926
|
+
if (pPrMarkResult !== void 0) paragraph.pPrMark = pPrMarkResult;
|
|
927
|
+
const sectPr = findChild(pPr, "w", "sectPr");
|
|
928
|
+
if (sectPr) paragraph.sectionProperties = parseSectionProperties(sectPr);
|
|
929
|
+
}
|
|
930
|
+
paragraph.content = consolidateParagraphContent(parseParagraphContents(node, styles, theme, numbering, rels, media, "default", options?.rootXmlns ?? {}));
|
|
931
|
+
let effectiveNumPr = paragraph.formatting?.numPr;
|
|
932
|
+
let numPrFromStyle = false;
|
|
933
|
+
if (!effectiveNumPr && paragraph.formatting?.styleId && styles) {
|
|
934
|
+
const style = styles.get(paragraph.formatting.styleId);
|
|
935
|
+
if (style?.pPr?.numPr) {
|
|
936
|
+
effectiveNumPr = style.pPr.numPr;
|
|
937
|
+
numPrFromStyle = true;
|
|
938
|
+
paragraph.formatting.numPr = effectiveNumPr;
|
|
939
|
+
paragraph.formatting.numPrFromStyle = effectiveNumPr;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
if (effectiveNumPr && numbering) {
|
|
943
|
+
const { numId, ilvl = 0 } = effectiveNumPr;
|
|
944
|
+
if (numId !== void 0 && numId !== 0) {
|
|
945
|
+
const level = numbering.getLevel(numId, ilvl);
|
|
946
|
+
if (level) {
|
|
947
|
+
const levelNumFmts = [];
|
|
948
|
+
for (let levelIndex = 0; levelIndex <= ilvl; levelIndex += 1) levelNumFmts.push(level.isLgl ? "decimal" : numbering.getLevel(numId, levelIndex)?.numFmt ?? "decimal");
|
|
949
|
+
const listRendering = {
|
|
950
|
+
level: ilvl,
|
|
951
|
+
numId,
|
|
952
|
+
marker: level.lvlText,
|
|
953
|
+
isBullet: level.numFmt === "bullet",
|
|
954
|
+
levelNumFmts
|
|
955
|
+
};
|
|
956
|
+
const instance = numbering.getInstance(numId);
|
|
957
|
+
const overrideForLevel = instance?.levelOverrides?.find((override) => override.ilvl === ilvl);
|
|
958
|
+
if (instance?.abstractNumId !== void 0) listRendering.abstractNumId = instance.abstractNumId;
|
|
959
|
+
if (overrideForLevel?.startOverride !== void 0) listRendering.startOverride = overrideForLevel.startOverride;
|
|
960
|
+
if (level.isLgl) listRendering.isLegal = true;
|
|
961
|
+
listRendering.numFmt = level.isLgl ? "decimal" : level.numFmt;
|
|
962
|
+
if (level.rPr?.hidden) listRendering.markerHidden = true;
|
|
963
|
+
const markerFont = level.rPr?.fontFamily?.ascii || level.rPr?.fontFamily?.hAnsi;
|
|
964
|
+
if (markerFont) listRendering.markerFontFamily = markerFont;
|
|
965
|
+
if (level.rPr?.fontSize) listRendering.markerFontSize = level.rPr.fontSize / 2;
|
|
966
|
+
if (level.rPr?.allCaps) listRendering.markerAllCaps = true;
|
|
967
|
+
if (level.suffix) listRendering.markerSuffix = level.suffix;
|
|
968
|
+
let implicitChildLevelAdvances = 0;
|
|
969
|
+
const foldedMarkerSuffix = [];
|
|
970
|
+
const filteredContent = [];
|
|
971
|
+
let dropNextTab = false;
|
|
972
|
+
const isMetadataContent = (content) => content.type === "bookmarkStart" || content.type === "bookmarkEnd" || content.type === "commentRangeStart" || content.type === "commentRangeEnd" || content.type === "commentReference";
|
|
973
|
+
for (const content of paragraph.content) {
|
|
974
|
+
if (dropNextTab && isMetadataContent(content)) {
|
|
975
|
+
filteredContent.push(content);
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
if (dropNextTab) {
|
|
979
|
+
dropNextTab = false;
|
|
980
|
+
if (content.type === "run" && content.content.length === 1 && content.content[0]?.type === "tab") continue;
|
|
981
|
+
}
|
|
982
|
+
if (content.type === "complexField") {
|
|
983
|
+
if (content.fieldType === "LISTNUM" || content.instruction.trim().toUpperCase().startsWith("LISTNUM")) {
|
|
984
|
+
implicitChildLevelAdvances += 1;
|
|
985
|
+
const cached = extractPlainText(content.fieldResult);
|
|
986
|
+
if (cached) foldedMarkerSuffix.push(cached);
|
|
987
|
+
dropNextTab = true;
|
|
988
|
+
continue;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
filteredContent.push(content);
|
|
992
|
+
}
|
|
993
|
+
if (foldedMarkerSuffix.length > 0) {
|
|
994
|
+
paragraph.content = filteredContent;
|
|
995
|
+
listRendering.marker = `${listRendering.marker}\t${foldedMarkerSuffix.join(" ")}`;
|
|
996
|
+
const nextLevel = numbering.getLevel(numId, ilvl + 1);
|
|
997
|
+
if (nextLevel?.pPr?.hangingIndent === true && nextLevel.pPr.indentFirstLine !== void 0) {
|
|
998
|
+
const hangingTwips = -nextLevel.pPr.indentFirstLine;
|
|
999
|
+
if (hangingTwips > 0) listRendering.markerSecondSlotOffsetTwips = hangingTwips;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
if (implicitChildLevelAdvances > 0) listRendering.implicitChildLevelAdvances = implicitChildLevelAdvances;
|
|
1003
|
+
paragraph.listRendering = listRendering;
|
|
1004
|
+
const chainInd = numPrFromStyle ? styleChainInd(paragraph.formatting?.styleId, styles) : {
|
|
1005
|
+
left: false,
|
|
1006
|
+
firstLine: false
|
|
1007
|
+
};
|
|
1008
|
+
if (level.pPr) {
|
|
1009
|
+
if (!paragraph.formatting) paragraph.formatting = {};
|
|
1010
|
+
const directInd = pPr ? findChild(pPr, "w", "ind") : null;
|
|
1011
|
+
const hasDirectLeft = directInd !== null && (getAttribute(directInd, "w", "left") !== null || getAttribute(directInd, "w", "start") !== null);
|
|
1012
|
+
const directFirstLine = directInd ? parseNumericAttribute(directInd, "w", "firstLine") : void 0;
|
|
1013
|
+
const directHanging = directInd ? parseNumericAttribute(directInd, "w", "hanging") : void 0;
|
|
1014
|
+
const hasDirectFirstLineOrHanging = directFirstLine !== void 0 && directFirstLine !== 0 || directHanging !== void 0 && directHanging !== 0;
|
|
1015
|
+
if (!hasDirectLeft && !chainInd.left && level.pPr.indentLeft !== void 0) paragraph.formatting.indentLeft = level.pPr.indentLeft;
|
|
1016
|
+
if (!hasDirectFirstLineOrHanging && !chainInd.firstLine) {
|
|
1017
|
+
if (level.pPr.indentFirstLine !== void 0) paragraph.formatting.indentFirstLine = level.pPr.indentFirstLine;
|
|
1018
|
+
if (level.pPr.hangingIndent !== void 0) paragraph.formatting.hangingIndent = level.pPr.hangingIndent;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return paragraph;
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Which indent groups the basedOn chain defines: `left` (w:ind left) and
|
|
1028
|
+
* `firstLine` (w:ind firstLine/hanging). Walks from the given style up the
|
|
1029
|
+
* chain; cycles are guarded. Grouping matches listAttrsFromResolvedStyle.
|
|
1030
|
+
*/
|
|
1031
|
+
function styleChainInd(styleId, styles) {
|
|
1032
|
+
const result = {
|
|
1033
|
+
left: false,
|
|
1034
|
+
firstLine: false
|
|
1035
|
+
};
|
|
1036
|
+
if (!styleId || !styles) return result;
|
|
1037
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1038
|
+
let current = styleId;
|
|
1039
|
+
while (current && !seen.has(current)) {
|
|
1040
|
+
seen.add(current);
|
|
1041
|
+
const style = styles.get(current);
|
|
1042
|
+
if (!style) break;
|
|
1043
|
+
const p = style.pPr;
|
|
1044
|
+
if (p) {
|
|
1045
|
+
result.left ||= p.indentLeft !== void 0;
|
|
1046
|
+
result.firstLine ||= p.indentFirstLine !== void 0 || p.hangingIndent !== void 0;
|
|
1047
|
+
}
|
|
1048
|
+
if (result.left && result.firstLine) break;
|
|
1049
|
+
current = style.basedOn;
|
|
1050
|
+
}
|
|
1051
|
+
return result;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Get plain text from a paragraph
|
|
1055
|
+
*
|
|
1056
|
+
* @param paragraph - Parsed Paragraph object
|
|
1057
|
+
* @returns Concatenated text content
|
|
1058
|
+
*/
|
|
1059
|
+
function getParagraphText(paragraph) {
|
|
1060
|
+
let text = "";
|
|
1061
|
+
for (const content of paragraph.content) if (content.type === "run") {
|
|
1062
|
+
for (const runContent of content.content) if (runContent.type === "text") text += runContent.text;
|
|
1063
|
+
else if (runContent.type === "tab") text += " ";
|
|
1064
|
+
else if (runContent.type === "break") if (runContent.breakType === "page") text += "\f";
|
|
1065
|
+
else text += "\n";
|
|
1066
|
+
} else if (content.type === "hyperlink") {
|
|
1067
|
+
for (const child of content.children) if (child.type === "run") {
|
|
1068
|
+
for (const runContent of child.content) if (runContent.type === "text") text += runContent.text;
|
|
1069
|
+
}
|
|
1070
|
+
} else if (content.type === "simpleField") {
|
|
1071
|
+
for (const child of content.content) if (child.type === "run") {
|
|
1072
|
+
for (const runContent of child.content) if (runContent.type === "text") text += runContent.text;
|
|
1073
|
+
}
|
|
1074
|
+
} else if (content.type === "complexField") {
|
|
1075
|
+
for (const run of content.fieldResult) for (const runContent of run.content) if (runContent.type === "text") text += runContent.text;
|
|
1076
|
+
}
|
|
1077
|
+
return text;
|
|
1078
|
+
}
|
|
1079
|
+
/**
|
|
1080
|
+
* Check if a paragraph is empty (no visible content)
|
|
1081
|
+
*
|
|
1082
|
+
* @param paragraph - Parsed Paragraph object
|
|
1083
|
+
* @returns true if paragraph has no visible content
|
|
1084
|
+
*/
|
|
1085
|
+
function isEmptyParagraph(paragraph) {
|
|
1086
|
+
return getParagraphText(paragraph).trim() === "" && !paragraph.content.some((c) => c.type === "run" && c.content.some((rc) => rc.type === "drawing" || rc.type === "shape"));
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Check if a paragraph is a list item
|
|
1090
|
+
*
|
|
1091
|
+
* @param paragraph - Parsed Paragraph object
|
|
1092
|
+
* @returns true if paragraph has numbering properties
|
|
1093
|
+
*/
|
|
1094
|
+
function isListItem(paragraph) {
|
|
1095
|
+
return paragraph.formatting?.numPr !== void 0 && paragraph.formatting.numPr.numId !== void 0 && paragraph.formatting.numPr.numId !== 0;
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Get the list level of a paragraph (0-8)
|
|
1099
|
+
*
|
|
1100
|
+
* @param paragraph - Parsed Paragraph object
|
|
1101
|
+
* @returns List level or undefined if not a list item
|
|
1102
|
+
*/
|
|
1103
|
+
function getListLevel(paragraph) {
|
|
1104
|
+
if (!isListItem(paragraph)) return;
|
|
1105
|
+
return paragraph.formatting?.numPr?.ilvl ?? 0;
|
|
1106
|
+
}
|
|
1107
|
+
/**
|
|
1108
|
+
* Check if paragraph has a specific style
|
|
1109
|
+
*
|
|
1110
|
+
* @param paragraph - Parsed Paragraph object
|
|
1111
|
+
* @param styleId - Style ID to check for
|
|
1112
|
+
* @returns true if paragraph has the specified style
|
|
1113
|
+
*/
|
|
1114
|
+
function hasStyle(paragraph, styleId) {
|
|
1115
|
+
return paragraph.formatting?.styleId === styleId;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Check if paragraph starts with a template variable {{...}}
|
|
1119
|
+
*
|
|
1120
|
+
* @param paragraph - Parsed Paragraph object
|
|
1121
|
+
* @returns The variable name or null
|
|
1122
|
+
*/
|
|
1123
|
+
function getTemplateVariable(paragraph) {
|
|
1124
|
+
const text = getParagraphText(paragraph);
|
|
1125
|
+
const start = text.indexOf("{{");
|
|
1126
|
+
if (start === -1) return null;
|
|
1127
|
+
const end = text.indexOf("}}", start + 2);
|
|
1128
|
+
if (end === -1 || end === start + 2) return null;
|
|
1129
|
+
return text.slice(start + 2, end);
|
|
1130
|
+
}
|
|
1131
|
+
//#endregion
|
|
1132
|
+
export { getListLevel, getParagraphText, getTemplateVariable, hasStyle, isEmptyParagraph, isListItem, parseParagraph, parseParagraphProperties };
|