@stll/folio-core 0.0.1-placeholder.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE.md +29 -0
- package/README.md +41 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/ai-edits/apply.d.ts +35 -0
- package/dist/ai-edits/apply.js +683 -0
- package/dist/ai-edits/clean-text.d.ts +28 -0
- package/dist/ai-edits/clean-text.js +23 -0
- package/dist/ai-edits/headless.d.ts +225 -0
- package/dist/ai-edits/headless.js +513 -0
- package/dist/ai-edits/index.d.ts +6 -0
- package/dist/ai-edits/index.js +5 -0
- package/dist/ai-edits/inline-emphasis.d.ts +38 -0
- package/dist/ai-edits/inline-emphasis.js +78 -0
- package/dist/ai-edits/snapshot.d.ts +9 -0
- package/dist/ai-edits/snapshot.js +195 -0
- package/dist/ai-edits/types.d.ts +156 -0
- package/dist/ai-edits/types.js +0 -0
- package/dist/ai-edits/word-diff.d.ts +20 -0
- package/dist/ai-edits/word-diff.js +77 -0
- package/dist/ai-suggestions/apply.d.ts +17 -0
- package/dist/ai-suggestions/apply.js +64 -0
- package/dist/ai-suggestions/conflict.d.ts +22 -0
- package/dist/ai-suggestions/conflict.js +67 -0
- package/dist/ai-suggestions/text-positions.d.ts +21 -0
- package/dist/ai-suggestions/text-positions.js +48 -0
- package/dist/ai-suggestions/types.d.ts +199 -0
- package/dist/ai-suggestions/types.js +59 -0
- package/dist/content-controls/errors.d.ts +52 -0
- package/dist/content-controls/errors.js +36 -0
- package/dist/content-controls/findContentControls.d.ts +55 -0
- package/dist/content-controls/findContentControls.js +75 -0
- package/dist/content-controls/index.d.ts +4 -0
- package/dist/content-controls/index.js +4 -0
- package/dist/content-controls/mutateContentControls.d.ts +51 -0
- package/dist/content-controls/mutateContentControls.js +377 -0
- package/dist/controller/folioEditor.d.ts +21 -0
- package/dist/controller/folioEditor.js +29 -0
- package/dist/controller/folioEditorEvents.d.ts +23 -0
- package/dist/controller/folioEditorEvents.js +24 -0
- package/dist/controller/hiddenEditorApi.d.ts +35 -0
- package/dist/controller/hiddenEditorApi.js +112 -0
- package/dist/controller/hiddenEditorManager.d.ts +93 -0
- package/dist/controller/hiddenEditorManager.js +308 -0
- package/dist/controller/layoutPipeline.d.ts +63 -0
- package/dist/controller/layoutPipeline.js +406 -0
- package/dist/controller/layoutScheduler.d.ts +41 -0
- package/dist/controller/layoutScheduler.js +59 -0
- package/dist/controller/layoutSession.d.ts +24 -0
- package/dist/controller/layoutSession.js +13 -0
- package/dist/docx/blockContentParser.d.ts +13 -0
- package/dist/docx/blockContentParser.js +289 -0
- package/dist/docx/bookmarkParser.d.ts +178 -0
- package/dist/docx/bookmarkParser.js +246 -0
- package/dist/docx/bookmarkPlacement.d.ts +10 -0
- package/dist/docx/bookmarkPlacement.js +50 -0
- package/dist/docx/bulletMarkers.d.ts +4 -0
- package/dist/docx/bulletMarkers.js +42 -0
- package/dist/docx/commentParser.d.ts +34 -0
- package/dist/docx/commentParser.js +127 -0
- package/dist/docx/commentReferenceNormalization.d.ts +25 -0
- package/dist/docx/commentReferenceNormalization.js +97 -0
- package/dist/docx/commentReplyMarkers.d.ts +20 -0
- package/dist/docx/commentReplyMarkers.js +123 -0
- package/dist/docx/compatibility.d.ts +12 -0
- package/dist/docx/compatibility.js +77 -0
- package/dist/docx/documentParser.d.ts +65 -0
- package/dist/docx/documentParser.js +209 -0
- package/dist/docx/drawingUtils.d.ts +56 -0
- package/dist/docx/drawingUtils.js +305 -0
- package/dist/docx/fieldParser.d.ts +228 -0
- package/dist/docx/fieldParser.js +559 -0
- package/dist/docx/footnoteParser.d.ts +109 -0
- package/dist/docx/footnoteParser.js +270 -0
- package/dist/docx/headerFooterParser.d.ts +119 -0
- package/dist/docx/headerFooterParser.js +266 -0
- package/dist/docx/headerFooterRefParser.d.ts +22 -0
- package/dist/docx/headerFooterRefParser.js +52 -0
- package/dist/docx/headerFooterReferenceNormalization.d.ts +19 -0
- package/dist/docx/headerFooterReferenceNormalization.js +64 -0
- package/dist/docx/hyperlinkParser.d.ts +108 -0
- package/dist/docx/hyperlinkParser.js +230 -0
- package/dist/docx/imageParser.d.ts +93 -0
- package/dist/docx/imageParser.js +522 -0
- package/dist/docx/mathToMathml.d.ts +15 -0
- package/dist/docx/mathToMathml.js +357 -0
- package/dist/docx/modelValidation.d.ts +13 -0
- package/dist/docx/modelValidation.js +21 -0
- package/dist/docx/normalizeBaseDirection.d.ts +12 -0
- package/dist/docx/normalizeBaseDirection.js +81 -0
- package/dist/docx/notePropertiesParser.d.ts +16 -0
- package/dist/docx/notePropertiesParser.js +99 -0
- package/dist/docx/numberingParser.d.ts +86 -0
- package/dist/docx/numberingParser.js +735 -0
- package/dist/docx/numberingReferenceNormalization.d.ts +25 -0
- package/dist/docx/numberingReferenceNormalization.js +22 -0
- package/dist/docx/paragraphParser.d.ts +86 -0
- package/dist/docx/paragraphParser.js +1132 -0
- package/dist/docx/paragraphTraversal.d.ts +19 -0
- package/dist/docx/paragraphTraversal.js +76 -0
- package/dist/docx/parser.d.ts +67 -0
- package/dist/docx/parser.js +391 -0
- package/dist/docx/parserEnums.d.ts +45 -0
- package/dist/docx/parserEnums.js +70 -0
- package/dist/docx/relsParser.d.ts +160 -0
- package/dist/docx/relsParser.js +235 -0
- package/dist/docx/replyToComment.d.ts +29 -0
- package/dist/docx/replyToComment.js +73 -0
- package/dist/docx/rezip.d.ts +166 -0
- package/dist/docx/rezip.js +1194 -0
- package/dist/docx/runConsolidator.d.ts +57 -0
- package/dist/docx/runConsolidator.js +224 -0
- package/dist/docx/runParser.d.ts +78 -0
- package/dist/docx/runParser.js +661 -0
- package/dist/docx/sdtProperties.d.ts +15 -0
- package/dist/docx/sdtProperties.js +290 -0
- package/dist/docx/sdtPropertiesPatch.d.ts +16 -0
- package/dist/docx/sdtPropertiesPatch.js +144 -0
- package/dist/docx/sectionParser.d.ts +95 -0
- package/dist/docx/sectionParser.js +534 -0
- package/dist/docx/selectiveSave.d.ts +25 -0
- package/dist/docx/selectiveSave.js +247 -0
- package/dist/docx/selectiveSaveFlags.d.ts +33 -0
- package/dist/docx/selectiveSaveFlags.js +11 -0
- package/dist/docx/selectiveSaveTripwire.d.ts +33 -0
- package/dist/docx/selectiveSaveTripwire.js +79 -0
- package/dist/docx/selectiveXmlPatch.d.ts +103 -0
- package/dist/docx/selectiveXmlPatch.js +493 -0
- package/dist/docx/serializer/blockSdtSerializer.d.ts +6 -0
- package/dist/docx/serializer/blockSdtSerializer.js +88 -0
- package/dist/docx/serializer/borderSerializer.d.ts +25 -0
- package/dist/docx/serializer/borderSerializer.js +44 -0
- package/dist/docx/serializer/commentSerializer.d.ts +31 -0
- package/dist/docx/serializer/commentSerializer.js +184 -0
- package/dist/docx/serializer/documentSerializer.d.ts +65 -0
- package/dist/docx/serializer/documentSerializer.js +199 -0
- package/dist/docx/serializer/headerFooterSerializer.d.ts +12 -0
- package/dist/docx/serializer/headerFooterSerializer.js +84 -0
- package/dist/docx/serializer/noteSerializer.d.ts +19 -0
- package/dist/docx/serializer/noteSerializer.js +70 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +12 -0
- package/dist/docx/serializer/numberingSerializer.js +93 -0
- package/dist/docx/serializer/paragraphSerializer.d.ts +48 -0
- package/dist/docx/serializer/paragraphSerializer.js +559 -0
- package/dist/docx/serializer/runSerializer.d.ts +56 -0
- package/dist/docx/serializer/runSerializer.js +621 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.d.ts +6 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +187 -0
- package/dist/docx/serializer/tableSerializer.d.ts +79 -0
- package/dist/docx/serializer/tableSerializer.js +422 -0
- package/dist/docx/serializer/xmlUtils.d.ts +20 -0
- package/dist/docx/serializer/xmlUtils.js +25 -0
- package/dist/docx/settingsParser.d.ts +8 -0
- package/dist/docx/settingsParser.js +36 -0
- package/dist/docx/shapeParser.d.ts +20 -0
- package/dist/docx/shapeParser.js +272 -0
- package/dist/docx/styleParser.d.ts +50 -0
- package/dist/docx/styleParser.js +905 -0
- package/dist/docx/tableParser.d.ts +202 -0
- package/dist/docx/tableParser.js +811 -0
- package/dist/docx/textBoxParser.d.ts +117 -0
- package/dist/docx/textBoxParser.js +262 -0
- package/dist/docx/themeParser.d.ts +77 -0
- package/dist/docx/themeParser.js +330 -0
- package/dist/docx/trackedMoveRangeNormalization.d.ts +22 -0
- package/dist/docx/trackedMoveRangeNormalization.js +100 -0
- package/dist/docx/unzip.d.ts +118 -0
- package/dist/docx/unzip.js +383 -0
- package/dist/docx/vmlImageParser.d.ts +16 -0
- package/dist/docx/vmlImageParser.js +100 -0
- package/dist/docx/watermarkParser.d.ts +45 -0
- package/dist/docx/watermarkParser.js +348 -0
- package/dist/docx/wrapTypes.d.ts +29 -0
- package/dist/docx/wrapTypes.js +48 -0
- package/dist/docx/xmlParser.d.ts +297 -0
- package/dist/docx/xmlParser.js +527 -0
- package/dist/fields/bookmarkPages.d.ts +13 -0
- package/dist/fields/bookmarkPages.js +66 -0
- package/dist/fields/bookmarkText.d.ts +16 -0
- package/dist/fields/bookmarkText.js +61 -0
- package/dist/fields/evaluateField.d.ts +23 -0
- package/dist/fields/evaluateField.js +77 -0
- package/dist/fields/fieldContext.d.ts +21 -0
- package/dist/fields/fieldContext.js +0 -0
- package/dist/fields/resolveFieldValues.d.ts +44 -0
- package/dist/fields/resolveFieldValues.js +204 -0
- package/dist/fields/sectionPageCounts.d.ts +11 -0
- package/dist/fields/sectionPageCounts.js +16 -0
- package/dist/fields/seqValues.d.ts +14 -0
- package/dist/fields/seqValues.js +36 -0
- package/dist/fonts/embeddedFontTable.d.ts +42 -0
- package/dist/fonts/embeddedFontTable.js +80 -0
- package/dist/fonts/embeddedFonts.d.ts +46 -0
- package/dist/fonts/embeddedFonts.js +112 -0
- package/dist/fonts/fontDeobfuscation.d.ts +30 -0
- package/dist/fonts/fontDeobfuscation.js +57 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +23 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +57 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +316 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +74 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +432 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.d.ts +36 -0
- package/dist/layout-bridge/convert/templatePreviewFlow.js +176 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +65 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +1309 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.d.ts +17 -0
- package/dist/layout-bridge/convert/wrapEditorViewAsSurface.js +36 -0
- package/dist/layout-bridge/dom/clickToPositionDom.d.ts +66 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +304 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.d.ts +7 -0
- package/dist/layout-bridge/dom/findBodyPmSpans.js +17 -0
- package/dist/layout-bridge/dom/findHfPmSpans.d.ts +62 -0
- package/dist/layout-bridge/dom/findHfPmSpans.js +197 -0
- package/dist/layout-bridge/engine/clickToPosition.d.ts +66 -0
- package/dist/layout-bridge/engine/clickToPosition.js +403 -0
- package/dist/layout-bridge/engine/hitTest.d.ts +135 -0
- package/dist/layout-bridge/engine/hitTest.js +375 -0
- package/dist/layout-bridge/engine/measuring/index.d.ts +10 -0
- package/dist/layout-bridge/engine/measuring/index.js +9 -0
- package/dist/layout-bridge/engine/selectionRects.d.ts +59 -0
- package/dist/layout-bridge/engine/selectionRects.js +485 -0
- package/dist/layout-bridge/engine/tableWidthUtils.d.ts +7 -0
- package/dist/layout-bridge/engine/tableWidthUtils.js +25 -0
- package/dist/layout-engine/index.d.ts +44 -0
- package/dist/layout-engine/index.js +691 -0
- package/dist/layout-engine/keep-together.d.ts +43 -0
- package/dist/layout-engine/keep-together.js +98 -0
- package/dist/layout-engine/layoutInstrumentation.d.ts +50 -0
- package/dist/layout-engine/layoutInstrumentation.js +43 -0
- package/dist/layout-engine/lineFlow.d.ts +8 -0
- package/dist/layout-engine/lineFlow.js +17 -0
- package/dist/layout-engine/measure/cache.d.ts +93 -0
- package/dist/layout-engine/measure/cache.js +245 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.d.ts +20 -0
- package/dist/layout-engine/measure/clampFloatingWrapMargins.js +29 -0
- package/dist/layout-engine/measure/featureFlags.d.ts +44 -0
- package/dist/layout-engine/measure/featureFlags.js +19 -0
- package/dist/layout-engine/measure/floatingZones.d.ts +89 -0
- package/dist/layout-engine/measure/floatingZones.js +152 -0
- package/dist/layout-engine/measure/font-metrics.worker.d.ts +17 -0
- package/dist/layout-engine/measure/font-metrics.worker.js +104 -0
- package/dist/layout-engine/measure/index.d.ts +9 -0
- package/dist/layout-engine/measure/index.js +8 -0
- package/dist/layout-engine/measure/listMarkerWidth.d.ts +40 -0
- package/dist/layout-engine/measure/listMarkerWidth.js +76 -0
- package/dist/layout-engine/measure/measureBlocks.d.ts +25 -0
- package/dist/layout-engine/measure/measureBlocks.js +450 -0
- package/dist/layout-engine/measure/measureContainer.d.ts +24 -0
- package/dist/layout-engine/measure/measureContainer.js +280 -0
- package/dist/layout-engine/measure/measureHelpers.d.ts +82 -0
- package/dist/layout-engine/measure/measureHelpers.js +156 -0
- package/dist/layout-engine/measure/measureParagraph.d.ts +61 -0
- package/dist/layout-engine/measure/measureParagraph.js +724 -0
- package/dist/layout-engine/measure/measureProvider.d.ts +23 -0
- package/dist/layout-engine/measure/measureProvider.js +35 -0
- package/dist/layout-engine/measure/measureTypes.d.ts +61 -0
- package/dist/layout-engine/measure/measureTypes.js +0 -0
- package/dist/layout-engine/measure/measureWorker.d.ts +54 -0
- package/dist/layout-engine/measure/measureWorker.js +249 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.d.ts +88 -0
- package/dist/layout-engine/measure/measureWorkerProtocol.js +20 -0
- package/dist/layout-engine/measure/tableCellFloating.d.ts +26 -0
- package/dist/layout-engine/measure/tableCellFloating.js +99 -0
- package/dist/layout-engine/paginator.d.ts +84 -0
- package/dist/layout-engine/paginator.js +348 -0
- package/dist/layout-engine/paragraphFragmentRange.d.ts +9 -0
- package/dist/layout-engine/paragraphFragmentRange.js +40 -0
- package/dist/layout-engine/section-breaks.d.ts +78 -0
- package/dist/layout-engine/section-breaks.js +182 -0
- package/dist/layout-engine/tableRowBreak.d.ts +23 -0
- package/dist/layout-engine/tableRowBreak.js +147 -0
- package/dist/layout-engine/textBoxFlow.d.ts +50 -0
- package/dist/layout-engine/textBoxFlow.js +160 -0
- package/dist/layout-engine/types.d.ts +1031 -0
- package/dist/layout-engine/types.js +100 -0
- package/dist/layout-painter/documentColors.d.ts +4 -0
- package/dist/layout-painter/documentColors.js +40 -0
- package/dist/layout-painter/index.d.ts +110 -0
- package/dist/layout-painter/index.js +182 -0
- package/dist/layout-painter/registry/modules/image.d.ts +6 -0
- package/dist/layout-painter/registry/modules/image.js +17 -0
- package/dist/layout-painter/registry/modules/paragraph.d.ts +6 -0
- package/dist/layout-painter/registry/modules/paragraph.js +18 -0
- package/dist/layout-painter/registry/modules/table.d.ts +6 -0
- package/dist/layout-painter/registry/modules/table.js +16 -0
- package/dist/layout-painter/registry/modules/textBox.d.ts +6 -0
- package/dist/layout-painter/registry/modules/textBox.js +13 -0
- package/dist/layout-painter/registry/modules.d.ts +6 -0
- package/dist/layout-painter/registry/modules.js +26 -0
- package/dist/layout-painter/registry/registry.d.ts +24 -0
- package/dist/layout-painter/registry/registry.js +53 -0
- package/dist/layout-painter/registry/types.d.ts +61 -0
- package/dist/layout-painter/registry/types.js +0 -0
- package/dist/layout-painter/renderFragment.d.ts +32 -0
- package/dist/layout-painter/renderFragment.js +114 -0
- package/dist/layout-painter/renderImage.d.ts +88 -0
- package/dist/layout-painter/renderImage.js +130 -0
- package/dist/layout-painter/renderPage.d.ts +264 -0
- package/dist/layout-painter/renderPage.js +1795 -0
- package/dist/layout-painter/renderParagraph.d.ts +93 -0
- package/dist/layout-painter/renderParagraph.js +1300 -0
- package/dist/layout-painter/renderTable.d.ts +36 -0
- package/dist/layout-painter/renderTable.js +432 -0
- package/dist/layout-painter/renderTextBox.d.ts +22 -0
- package/dist/layout-painter/renderTextBox.js +67 -0
- package/dist/layout-painter/renderUtils.d.ts +42 -0
- package/dist/layout-painter/renderUtils.js +30 -0
- package/dist/layout-painter/renderWatermark.d.ts +16 -0
- package/dist/layout-painter/renderWatermark.js +61 -0
- package/dist/layout-painter/sdtBoundary.d.ts +6 -0
- package/dist/layout-painter/sdtBoundary.js +28 -0
- package/dist/managers/ContextMenuManager.d.ts +28 -0
- package/dist/managers/ContextMenuManager.js +48 -0
- package/dist/managers/DocumentLoaderManager.d.ts +47 -0
- package/dist/managers/DocumentLoaderManager.js +69 -0
- package/dist/managers/EditorModeManager.d.ts +28 -0
- package/dist/managers/EditorModeManager.js +50 -0
- package/dist/managers/ErrorManager.d.ts +26 -0
- package/dist/managers/ErrorManager.js +85 -0
- package/dist/managers/FindReplaceManager.d.ts +54 -0
- package/dist/managers/FindReplaceManager.js +104 -0
- package/dist/managers/HistoryManager.d.ts +92 -0
- package/dist/managers/HistoryManager.js +193 -0
- package/dist/managers/Subscribable.d.ts +34 -0
- package/dist/managers/Subscribable.js +46 -0
- package/dist/managers/TableSelectionManager.d.ts +74 -0
- package/dist/managers/TableSelectionManager.js +225 -0
- package/dist/managers/editorShortcuts.d.ts +42 -0
- package/dist/managers/editorShortcuts.js +60 -0
- package/dist/managers/types.d.ts +41 -0
- package/dist/managers/types.js +0 -0
- package/dist/markdown/annotations.d.ts +14 -0
- package/dist/markdown/annotations.js +42 -0
- package/dist/markdown/escape.d.ts +36 -0
- package/dist/markdown/escape.js +59 -0
- package/dist/markdown/fromMarkdown.d.ts +11 -0
- package/dist/markdown/fromMarkdown.js +223 -0
- package/dist/markdown/headings.d.ts +13 -0
- package/dist/markdown/headings.js +20 -0
- package/dist/markdown/images.d.ts +13 -0
- package/dist/markdown/images.js +63 -0
- package/dist/markdown/index.d.ts +18 -0
- package/dist/markdown/index.js +33 -0
- package/dist/markdown/internals.d.ts +15 -0
- package/dist/markdown/internals.js +35 -0
- package/dist/markdown/renderBlock.d.ts +7 -0
- package/dist/markdown/renderBlock.js +68 -0
- package/dist/markdown/renderParagraph.d.ts +11 -0
- package/dist/markdown/renderParagraph.js +64 -0
- package/dist/markdown/renderRuns.d.ts +11 -0
- package/dist/markdown/renderRuns.js +265 -0
- package/dist/markdown/renderTable.d.ts +8 -0
- package/dist/markdown/renderTable.js +229 -0
- package/dist/markdown/trailers.d.ts +13 -0
- package/dist/markdown/trailers.js +54 -0
- package/dist/markdown/types.d.ts +118 -0
- package/dist/markdown/types.js +0 -0
- package/dist/model.d.ts +13 -0
- package/dist/model.js +4 -0
- package/dist/paged-layout/LayoutSelectionGate.d.ts +80 -0
- package/dist/paged-layout/LayoutSelectionGate.js +131 -0
- package/dist/paged-layout/headerFooterMargins.d.ts +73 -0
- package/dist/paged-layout/headerFooterMargins.js +120 -0
- package/dist/paged-layout/hiddenEditorScroll.d.ts +4 -0
- package/dist/paged-layout/hiddenEditorScroll.js +4 -0
- package/dist/paged-layout/incrementalMeasure.d.ts +33 -0
- package/dist/paged-layout/incrementalMeasure.js +56 -0
- package/dist/paged-layout/rangeProjection.d.ts +51 -0
- package/dist/paged-layout/rangeProjection.js +153 -0
- package/dist/paged-layout/readOnlyEditAttempt.d.ts +5 -0
- package/dist/paged-layout/readOnlyEditAttempt.js +22 -0
- package/dist/paged-layout/scrollNavigation.d.ts +23 -0
- package/dist/paged-layout/scrollNavigation.js +31 -0
- package/dist/paged-layout/scrollPageInfo.d.ts +41 -0
- package/dist/paged-layout/scrollPageInfo.js +34 -0
- package/dist/paged-layout/scrollToPmPosition.d.ts +17 -0
- package/dist/paged-layout/scrollToPmPosition.js +95 -0
- package/dist/paged-layout/sectionBlockWidths.d.ts +35 -0
- package/dist/paged-layout/sectionBlockWidths.js +52 -0
- package/dist/paged-layout/sectionGeometry.d.ts +21 -0
- package/dist/paged-layout/sectionGeometry.js +36 -0
- package/dist/paged-layout/selectionViewportRect.d.ts +29 -0
- package/dist/paged-layout/selectionViewportRect.js +55 -0
- package/dist/paged-layout/tableColumnResize.d.ts +19 -0
- package/dist/paged-layout/tableColumnResize.js +28 -0
- package/dist/paged-layout/tableInsertButtonGeometry.d.ts +15 -0
- package/dist/paged-layout/tableInsertButtonGeometry.js +15 -0
- package/dist/paged-layout/transactionDirtyRange.d.ts +7 -0
- package/dist/paged-layout/transactionDirtyRange.js +27 -0
- package/dist/paged-layout/zoomScrollAnchor.d.ts +40 -0
- package/dist/paged-layout/zoomScrollAnchor.js +25 -0
- package/dist/prosemirror/attrs/index.d.ts +80 -0
- package/dist/prosemirror/attrs/index.js +1218 -0
- package/dist/prosemirror/autospacingBase.d.ts +11 -0
- package/dist/prosemirror/autospacingBase.js +16 -0
- package/dist/prosemirror/commands/comments.d.ts +93 -0
- package/dist/prosemirror/commands/comments.js +435 -0
- package/dist/prosemirror/commands/contentControls.d.ts +45 -0
- package/dist/prosemirror/commands/contentControls.js +294 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.d.ts +15 -0
- package/dist/prosemirror/commands/contentControlsBlockFill.js +19 -0
- package/dist/prosemirror/commands/formatPainter.d.ts +31 -0
- package/dist/prosemirror/commands/formatPainter.js +130 -0
- package/dist/prosemirror/commands/formatting.d.ts +32 -0
- package/dist/prosemirror/commands/formatting.js +45 -0
- package/dist/prosemirror/commands/hyperlink.d.ts +31 -0
- package/dist/prosemirror/commands/hyperlink.js +79 -0
- package/dist/prosemirror/commands/image.d.ts +59 -0
- package/dist/prosemirror/commands/image.js +219 -0
- package/dist/prosemirror/commands/index.d.ts +13 -0
- package/dist/prosemirror/commands/index.js +13 -0
- package/dist/prosemirror/commands/pageBreak.d.ts +10 -0
- package/dist/prosemirror/commands/pageBreak.js +47 -0
- package/dist/prosemirror/commands/paragraph.d.ts +39 -0
- package/dist/prosemirror/commands/paragraph.js +64 -0
- package/dist/prosemirror/commands/pastePlainText.d.ts +39 -0
- package/dist/prosemirror/commands/pastePlainText.js +67 -0
- package/dist/prosemirror/commands/table.d.ts +83 -0
- package/dist/prosemirror/commands/table.js +105 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +27 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +1550 -0
- package/dist/prosemirror/conversion/index.d.ts +4 -0
- package/dist/prosemirror/conversion/index.js +4 -0
- package/dist/prosemirror/conversion/runShadingMark.d.ts +16 -0
- package/dist/prosemirror/conversion/runShadingMark.js +39 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +39 -0
- package/dist/prosemirror/conversion/toProseDoc.js +1404 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +43 -0
- package/dist/prosemirror/extensions/ExtensionManager.js +86 -0
- package/dist/prosemirror/extensions/StarterKit.d.ts +16 -0
- package/dist/prosemirror/extensions/StarterKit.js +132 -0
- package/dist/prosemirror/extensions/core/DocExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/DocExtension.js +12 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/core/HistoryExtension.js +28 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +25 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +619 -0
- package/dist/prosemirror/extensions/core/TextExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/core/TextExtension.js +12 -0
- package/dist/prosemirror/extensions/create.d.ts +17 -0
- package/dist/prosemirror/extensions/create.js +129 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +106 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +172 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +38 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/features/ContentControlWidgetsExtension.js +21 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/DropCursorExtension.js +20 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.d.ts +8 -0
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +44 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.d.ts +19 -0
- package/dist/prosemirror/extensions/features/GapCursorExtension.js +24 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.d.ts +15 -0
- package/dist/prosemirror/extensions/features/ImageDragExtension.js +66 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +91 -0
- package/dist/prosemirror/extensions/features/ListExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/features/ListExtension.js +340 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +60 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +35 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +188 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +34 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.d.ts +20 -0
- package/dist/prosemirror/extensions/features/PasteStyleInlinerExtension.js +145 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/features/SelectionTrackerExtension.js +17 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.d.ts +31 -0
- package/dist/prosemirror/extensions/features/bidiShortcutController.js +27 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +31 -0
- package/dist/prosemirror/extensions/features/pasteCleanup.js +159 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/AllCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/BoldExtension.js +41 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.d.ts +14 -0
- package/dist/prosemirror/extensions/marks/CharacterSpacingExtension.js +64 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/CharacterStyleExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/marks/CommentExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontFamilyExtension.js +55 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/FontSizeExtension.js +47 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/FootnoteRefExtension.js +92 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.d.ts +23 -0
- package/dist/prosemirror/extensions/marks/HiddenTextExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.d.ts +10 -0
- package/dist/prosemirror/extensions/marks/HighlightExtension.js +115 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +146 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/ItalicExtension.js +34 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RtlExtension.js +21 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/marks/RunFormattingOverrideExtension.js +75 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/RunShadingExtension.js +38 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SmallCapsExtension.js +24 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/StrikeExtension.js +33 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SubscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/SuperscriptExtension.js +25 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +50 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/marks/TextEffectExtension.js +35 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.d.ts +31 -0
- package/dist/prosemirror/extensions/marks/TextEffectsExtensions.js +134 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.d.ts +22 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +113 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/marks/UnderlineExtension.js +60 -0
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +34 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +233 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +122 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +87 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HardBreakExtension.js +38 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/HorizontalRuleExtension.js +18 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +132 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/nodes/MathExtension.js +56 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/PageBreakExtension.js +20 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +12 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.js +107 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.d.ts +30 -0
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +502 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.d.ts +9 -0
- package/dist/prosemirror/extensions/nodes/TabExtension.js +27 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +1972 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.d.ts +34 -0
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +150 -0
- package/dist/prosemirror/extensions/types.d.ts +101 -0
- package/dist/prosemirror/extensions/types.js +10 -0
- package/dist/prosemirror/findReplaceSelection.d.ts +23 -0
- package/dist/prosemirror/findReplaceSelection.js +86 -0
- package/dist/prosemirror/index.d.ts +25 -0
- package/dist/prosemirror/index.js +23 -0
- package/dist/prosemirror/insertOperations.d.ts +12 -0
- package/dist/prosemirror/insertOperations.js +19 -0
- package/dist/prosemirror/paragraphDirection.d.ts +42 -0
- package/dist/prosemirror/paragraphDirection.js +33 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.d.ts +40 -0
- package/dist/prosemirror/plugins/aiCitationDecorations.js +90 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.d.ts +42 -0
- package/dist/prosemirror/plugins/aiSuggestionDecorations.js +135 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.d.ts +60 -0
- package/dist/prosemirror/plugins/anonymizationDecorations.js +120 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.d.ts +123 -0
- package/dist/prosemirror/plugins/autocompleteSuggestion.js +283 -0
- package/dist/prosemirror/plugins/contentControlWidgets.d.ts +56 -0
- package/dist/prosemirror/plugins/contentControlWidgets.js +192 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +37 -0
- package/dist/prosemirror/plugins/createDocScanPlugin.js +55 -0
- package/dist/prosemirror/plugins/documentStyles.d.ts +18 -0
- package/dist/prosemirror/plugins/documentStyles.js +46 -0
- package/dist/prosemirror/plugins/index.d.ts +3 -0
- package/dist/prosemirror/plugins/index.js +3 -0
- package/dist/prosemirror/plugins/pmTextScan.d.ts +19 -0
- package/dist/prosemirror/plugins/pmTextScan.js +39 -0
- package/dist/prosemirror/plugins/selectionTracker.d.ts +43 -0
- package/dist/prosemirror/plugins/selectionTracker.js +179 -0
- package/dist/prosemirror/plugins/suggestionMode.d.ts +70 -0
- package/dist/prosemirror/plugins/suggestionMode.js +489 -0
- package/dist/prosemirror/plugins/templateDirectives.d.ts +25 -0
- package/dist/prosemirror/plugins/templateDirectives.js +67 -0
- package/dist/prosemirror/plugins/templatePreviewValues.d.ts +49 -0
- package/dist/prosemirror/plugins/templatePreviewValues.js +117 -0
- package/dist/prosemirror/plugins/templateSlashMenu.d.ts +57 -0
- package/dist/prosemirror/plugins/templateSlashMenu.js +184 -0
- package/dist/prosemirror/schema/index.d.ts +15 -0
- package/dist/prosemirror/schema/index.js +20 -0
- package/dist/prosemirror/schema/marks.d.ts +118 -0
- package/dist/prosemirror/schema/marks.js +0 -0
- package/dist/prosemirror/schema/nodes.d.ts +389 -0
- package/dist/prosemirror/schema/nodes.js +0 -0
- package/dist/prosemirror/selectionState.d.ts +23 -0
- package/dist/prosemirror/selectionState.js +111 -0
- package/dist/prosemirror/styles/index.d.ts +2 -0
- package/dist/prosemirror/styles/index.js +2 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +32 -0
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +108 -0
- package/dist/prosemirror/styles/styleResolver.d.ts +94 -0
- package/dist/prosemirror/styles/styleResolver.js +200 -0
- package/dist/prosemirror/utils/findParagraphByParaId.d.ts +26 -0
- package/dist/prosemirror/utils/findParagraphByParaId.js +37 -0
- package/dist/prosemirror/utils/tabCalculator.d.ts +110 -0
- package/dist/prosemirror/utils/tabCalculator.js +137 -0
- package/dist/prosemirror/validation.d.ts +20 -0
- package/dist/prosemirror/validation.js +177 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +6 -0
- package/dist/style-engine/index.d.ts +3 -0
- package/dist/style-engine/index.js +2 -0
- package/dist/style-engine/styleEngine.d.ts +67 -0
- package/dist/style-engine/styleEngine.js +70 -0
- package/dist/types/block-id.d.ts +58 -0
- package/dist/types/block-id.js +61 -0
- package/dist/types/colors.d.ts +2 -0
- package/dist/types/colors.js +0 -0
- package/dist/types/content.d.ts +2 -0
- package/dist/types/content.js +0 -0
- package/dist/types/document.d.ts +7 -0
- package/dist/types/document.js +0 -0
- package/dist/types/documentEnumValues.d.ts +89 -0
- package/dist/types/documentEnumValues.js +693 -0
- package/dist/types/formatting.d.ts +2 -0
- package/dist/types/formatting.js +0 -0
- package/dist/types/index.d.ts +107 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/authorColors.d.ts +16 -0
- package/dist/utils/authorColors.js +30 -0
- package/dist/utils/baseDirection.d.ts +23 -0
- package/dist/utils/baseDirection.js +34 -0
- package/dist/utils/clipboard.d.ts +126 -0
- package/dist/utils/clipboard.js +622 -0
- package/dist/utils/colorResolver.d.ts +158 -0
- package/dist/utils/colorResolver.js +557 -0
- package/dist/utils/createDocument.d.ts +50 -0
- package/dist/utils/createDocument.js +262 -0
- package/dist/utils/documentLoaderBehavior.d.ts +22 -0
- package/dist/utils/documentLoaderBehavior.js +14 -0
- package/dist/utils/docxInput.d.ts +22 -0
- package/dist/utils/docxInput.js +16 -0
- package/dist/utils/domGuards.d.ts +59 -0
- package/dist/utils/domGuards.js +82 -0
- package/dist/utils/fontFamilyMerge.d.ts +7 -0
- package/dist/utils/fontFamilyMerge.js +31 -0
- package/dist/utils/fontLoader.d.ts +50 -0
- package/dist/utils/fontLoader.js +177 -0
- package/dist/utils/fontResolver.d.ts +61 -0
- package/dist/utils/fontResolver.js +651 -0
- package/dist/utils/fontWeights.d.ts +4 -0
- package/dist/utils/fontWeights.js +4 -0
- package/dist/utils/formatToStyle.d.ts +103 -0
- package/dist/utils/formatToStyle.js +289 -0
- package/dist/utils/headerFooter.d.ts +74 -0
- package/dist/utils/headerFooter.js +257 -0
- package/dist/utils/headingCollector.d.ts +22 -0
- package/dist/utils/headingCollector.js +36 -0
- package/dist/utils/hexId.d.ts +33 -0
- package/dist/utils/hexId.js +37 -0
- package/dist/utils/imageValidation.d.ts +5 -0
- package/dist/utils/imageValidation.js +31 -0
- package/dist/utils/paragraphFormattingMerge.d.ts +14 -0
- package/dist/utils/paragraphFormattingMerge.js +68 -0
- package/dist/utils/replaceText.d.ts +17 -0
- package/dist/utils/replaceText.js +161 -0
- package/dist/utils/rotationBoundingBox.d.ts +12 -0
- package/dist/utils/rotationBoundingBox.js +36 -0
- package/dist/utils/scriptSegments.d.ts +36 -0
- package/dist/utils/scriptSegments.js +52 -0
- package/dist/utils/tableOperations.d.ts +87 -0
- package/dist/utils/tableOperations.js +259 -0
- package/dist/utils/textFormattingMerge.d.ts +6 -0
- package/dist/utils/textFormattingMerge.js +31 -0
- package/dist/utils/tiffConverter.d.ts +18 -0
- package/dist/utils/tiffConverter.js +83 -0
- package/dist/utils/units.d.ts +99 -0
- package/dist/utils/units.js +139 -0
- package/dist/utils/urlSecurity.d.ts +7 -0
- package/dist/utils/urlSecurity.js +65 -0
- package/dist/watermark/index.d.ts +39 -0
- package/dist/watermark/index.js +149 -0
- package/package.json +122 -2
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
import { getFontMetrics, measureRun, measureTextWidth } from "./measureProvider.js";
|
|
2
|
+
import "../../utils/fontResolver.js";
|
|
3
|
+
import { buildRunFontStyle, ptToPx } from "./measureHelpers.js";
|
|
4
|
+
import { calculateTabWidth, pixelsToTwips } from "../../prosemirror/utils/tabCalculator.js";
|
|
5
|
+
import { inlineImageBoundingBox } from "../../utils/rotationBoundingBox.js";
|
|
6
|
+
import { measuredLineAdvance } from "../lineFlow.js";
|
|
7
|
+
import { isFloatingImageRun } from "../types.js";
|
|
8
|
+
import { clampFloatingWrapMargins } from "./clampFloatingWrapMargins.js";
|
|
9
|
+
import { getFloatingAvailableWidth, getFloatingMargins } from "./floatingZones.js";
|
|
10
|
+
import { getListMarkerInlineWidth } from "./listMarkerWidth.js";
|
|
11
|
+
//#region src/layout-engine/measure/measureParagraph.ts
|
|
12
|
+
/**
|
|
13
|
+
* Paragraph measurement module
|
|
14
|
+
*
|
|
15
|
+
* Measures paragraph blocks and computes line breaking.
|
|
16
|
+
* Converts runs into measured lines with typography metrics.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_FONT_SIZE = 11;
|
|
19
|
+
const DEFAULT_FONT_FAMILY = "Calibri";
|
|
20
|
+
const DEFAULT_LINE_HEIGHT_MULTIPLIER = 1;
|
|
21
|
+
const WIDTH_TOLERANCE = .5;
|
|
22
|
+
/**
|
|
23
|
+
* Find the longest prefix of `text` that fits within `maxWidth` pixels.
|
|
24
|
+
* Returns the number of characters that fit (at least 1 if `forceMin` is true).
|
|
25
|
+
*/
|
|
26
|
+
function findMaxFittingLength(text, style, maxWidth, forceMin = false) {
|
|
27
|
+
let lo = 1;
|
|
28
|
+
let hi = text.length;
|
|
29
|
+
let best = 0;
|
|
30
|
+
while (lo <= hi) {
|
|
31
|
+
const mid = Math.floor((lo + hi) / 2);
|
|
32
|
+
if (measureTextWidth(text.slice(0, mid), style) <= maxWidth) {
|
|
33
|
+
best = mid;
|
|
34
|
+
lo = mid + 1;
|
|
35
|
+
} else hi = mid - 1;
|
|
36
|
+
}
|
|
37
|
+
return forceMin && best === 0 ? 1 : best;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Extract FontStyle from a run that carries RunFormatting (text, tab, or
|
|
41
|
+
* field). All three share the same formatting shape, so they measure the
|
|
42
|
+
* same way; widening the parameter keeps tab-following measurement
|
|
43
|
+
* (FieldRun page numbers, etc.) consistent with TextRun handling.
|
|
44
|
+
*/
|
|
45
|
+
function runToFontStyle(run) {
|
|
46
|
+
return buildRunFontStyle(run, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Calculate typography metrics from font size and spacing settings
|
|
50
|
+
*
|
|
51
|
+
* @param fontSize - Font size in points
|
|
52
|
+
* @param spacing - Paragraph spacing settings
|
|
53
|
+
* @param metrics - Pre-calculated font metrics (in pixels)
|
|
54
|
+
*/
|
|
55
|
+
function calculateTypographyMetrics(fontSize, spacing, metrics) {
|
|
56
|
+
const fontSizePx = ptToPx(fontSize);
|
|
57
|
+
const ascent = metrics?.ascent ?? fontSizePx * .8;
|
|
58
|
+
const descent = metrics?.descent ?? fontSizePx * .2;
|
|
59
|
+
const singleLineBase = fontSizePx * (metrics?.singleLineRatio ?? 1.15);
|
|
60
|
+
let lineHeight;
|
|
61
|
+
if (spacing?.lineRule === "exact" && spacing.line !== void 0) lineHeight = spacing.line;
|
|
62
|
+
else if (spacing?.lineRule === "atLeast" && spacing.line !== void 0) {
|
|
63
|
+
const defaultHeight = singleLineBase * DEFAULT_LINE_HEIGHT_MULTIPLIER;
|
|
64
|
+
lineHeight = Math.max(spacing.line, defaultHeight);
|
|
65
|
+
} else if (spacing?.line !== void 0 && spacing.lineUnit === "multiplier") lineHeight = singleLineBase * spacing.line;
|
|
66
|
+
else if (spacing?.line !== void 0 && spacing.lineUnit === "px") lineHeight = spacing.line;
|
|
67
|
+
else lineHeight = singleLineBase * DEFAULT_LINE_HEIGHT_MULTIPLIER;
|
|
68
|
+
return {
|
|
69
|
+
ascent,
|
|
70
|
+
descent,
|
|
71
|
+
lineHeight
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Word's "single line spacing" floor (≈ 1.15×) applied to empty paragraphs
|
|
76
|
+
* with `auto`/`atLeast` line rules. Without this, narrow-metric fonts
|
|
77
|
+
* (Arial Narrow, OS/2 ratio ≈ 1.117) collapse empty rows visibly tighter
|
|
78
|
+
* than Word renders them. See eigenpal #391/#394.
|
|
79
|
+
*/
|
|
80
|
+
const WORD_SINGLE_LINE_FLOOR = 1.15;
|
|
81
|
+
/**
|
|
82
|
+
* Calculate metrics for an empty paragraph.
|
|
83
|
+
*
|
|
84
|
+
* Word renders an empty paragraph as a single readable line — its line
|
|
85
|
+
* height never collapses below 1.15 × font size, even when the doc
|
|
86
|
+
* explicitly writes `<w:line w:val="240"/>` (1.0×). The floor is scoped to
|
|
87
|
+
* `auto`/`atLeast` line rules; `exact` means exact (per OOXML §17.3.1.33)
|
|
88
|
+
* and stays untouched.
|
|
89
|
+
*/
|
|
90
|
+
function calculateEmptyParagraphMetrics(fontSize, spacing, fontFamily) {
|
|
91
|
+
const result = calculateTypographyMetrics(fontSize, spacing, getFontMetrics({
|
|
92
|
+
fontSize,
|
|
93
|
+
fontFamily: fontFamily ?? DEFAULT_FONT_FAMILY
|
|
94
|
+
}));
|
|
95
|
+
const lineRule = spacing?.lineRule ?? "auto";
|
|
96
|
+
if (lineRule === "auto" || lineRule === "atLeast") {
|
|
97
|
+
const floor = ptToPx(fontSize) * WORD_SINGLE_LINE_FLOOR;
|
|
98
|
+
if (result.lineHeight < floor) return {
|
|
99
|
+
...result,
|
|
100
|
+
lineHeight: floor
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if a run is a text run
|
|
107
|
+
*/
|
|
108
|
+
function isTextRun(run) {
|
|
109
|
+
return run.kind === "text";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if a run is a tab run
|
|
113
|
+
*/
|
|
114
|
+
function isTabRun(run) {
|
|
115
|
+
return run.kind === "tab";
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a run is an image run
|
|
119
|
+
*/
|
|
120
|
+
function isImageRun(run) {
|
|
121
|
+
return run.kind === "image";
|
|
122
|
+
}
|
|
123
|
+
function parseRotationDegrees(transform) {
|
|
124
|
+
if (!transform) return 0;
|
|
125
|
+
const match = /rotate\(\s*(?<degrees>[-\d.]+)\s*deg\s*\)/u.exec(transform);
|
|
126
|
+
if (!match) return 0;
|
|
127
|
+
const raw = Number.parseFloat(match.groups["degrees"]);
|
|
128
|
+
if (!Number.isFinite(raw)) return 0;
|
|
129
|
+
return (raw % 360 + 360) % 360;
|
|
130
|
+
}
|
|
131
|
+
function rotatedBlockImageHeight(run) {
|
|
132
|
+
const deg = parseRotationDegrees(run.transform);
|
|
133
|
+
if (deg === 0 || deg === 180) return run.height;
|
|
134
|
+
if (deg === 90 || deg === 270) return run.width;
|
|
135
|
+
const rad = deg * Math.PI / 180;
|
|
136
|
+
const sinA = Math.abs(Math.sin(rad));
|
|
137
|
+
const cosA = Math.abs(Math.cos(rad));
|
|
138
|
+
return run.width * sinA + run.height * cosA;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if a run is a line break run
|
|
142
|
+
*/
|
|
143
|
+
function isLineBreakRun(run) {
|
|
144
|
+
return run.kind === "lineBreak";
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Check if a run is a field run
|
|
148
|
+
*/
|
|
149
|
+
function isFieldRun(run) {
|
|
150
|
+
return run.kind === "field";
|
|
151
|
+
}
|
|
152
|
+
/** Text a field run is measured at: its resolved value when known (so the
|
|
153
|
+
* measurer agrees with the painter), else the cached fallback. */
|
|
154
|
+
function fieldMeasureText(run, fieldValues) {
|
|
155
|
+
return (run.pmStart === void 0 ? void 0 : fieldValues?.get(run.pmStart)) ?? (run.fallback || "1");
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Check if a run is a math equation run
|
|
159
|
+
*/
|
|
160
|
+
function isMathRun(run) {
|
|
161
|
+
return run.kind === "math";
|
|
162
|
+
}
|
|
163
|
+
function isStackedMathLocalName(localName) {
|
|
164
|
+
switch (localName) {
|
|
165
|
+
case "bar":
|
|
166
|
+
case "d":
|
|
167
|
+
case "eqArr":
|
|
168
|
+
case "f":
|
|
169
|
+
case "groupChr":
|
|
170
|
+
case "limLow":
|
|
171
|
+
case "limUpp":
|
|
172
|
+
case "m":
|
|
173
|
+
case "nary":
|
|
174
|
+
case "rad":
|
|
175
|
+
case "sPre":
|
|
176
|
+
case "sSubSup": return true;
|
|
177
|
+
default: return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function hasStackedMathLayout(run) {
|
|
181
|
+
if (run.display === "block") return true;
|
|
182
|
+
for (const match of run.ommlXml.matchAll(/<(?<tag>[A-Za-z_][\w.-]*(?::[A-Za-z_][\w.-]*)?)(?:\s|\/|>)/gu)) {
|
|
183
|
+
const tagName = match.groups?.["tag"];
|
|
184
|
+
if (!tagName) continue;
|
|
185
|
+
const colonIndex = tagName.indexOf(":");
|
|
186
|
+
if (isStackedMathLocalName(colonIndex === -1 ? tagName : tagName.slice(colonIndex + 1))) return true;
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
function estimateMathFootprintPx(run) {
|
|
191
|
+
return ptToPx(run.fontSize ?? DEFAULT_FONT_SIZE) * (hasStackedMathLayout(run) ? 2.4 : 1.25);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Check if text run is empty (only whitespace or no text)
|
|
195
|
+
*/
|
|
196
|
+
function isEmptyTextRun(run) {
|
|
197
|
+
return !run.text || run.text.replace(/\u00a0/gu, " ").trim().length === 0;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Sum the inline pixel widths of runs after a tab, up to (but not including)
|
|
201
|
+
* the next tab or line break. Measured per-run so widths reserved match what
|
|
202
|
+
* the painter draws even when trailing runs use different fonts/sizes.
|
|
203
|
+
*
|
|
204
|
+
* Floating/anchored images are skipped — the painter lifts them out of the
|
|
205
|
+
* paragraph flow (see `isFloatingImageRun`) and `measureFollowingContentWidth`
|
|
206
|
+
* in the painter already excludes them, so counting their width here would
|
|
207
|
+
* desync measurer and painter on tab advance for paragraphs with a tab
|
|
208
|
+
* preceding a floating image.
|
|
209
|
+
*/
|
|
210
|
+
function measureInlineWidthAfterTab(runs, tabIndex, fieldValues) {
|
|
211
|
+
let width = 0;
|
|
212
|
+
for (let i = tabIndex + 1; i < runs.length; i++) {
|
|
213
|
+
const next = runs[i];
|
|
214
|
+
if (!next || isTabRun(next) || isLineBreakRun(next)) break;
|
|
215
|
+
if (isTextRun(next)) width += measureTextWidth(next.text || "", runToFontStyle(next));
|
|
216
|
+
else if (isFieldRun(next)) width += measureTextWidth(fieldMeasureText(next, fieldValues), runToFontStyle(next));
|
|
217
|
+
else if (isImageRun(next) && !isFloatingImageRun(next)) width += next.width || 0;
|
|
218
|
+
else if (isMathRun(next)) width += measureTextWidth(next.plainText || "[equation]", runToFontStyle(next));
|
|
219
|
+
}
|
|
220
|
+
return width;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Width of the inline content preceding the first `.` in the runs that follow
|
|
224
|
+
* a tab, used to anchor `decimal` tab stops. Mirrors `getTextAfterTab` +
|
|
225
|
+
* decimal-prefix measurement in the painter (`renderParagraph.ts`) so the
|
|
226
|
+
* measurer and painter agree on tab advance for decimal stops.
|
|
227
|
+
*
|
|
228
|
+
* Returns 0 when no decimal separator appears before the next tab / line
|
|
229
|
+
* break — `calculateTabWidth` treats that as "no anchor adjustment".
|
|
230
|
+
*/
|
|
231
|
+
function measureDecimalPrefixWidthAfterTab(runs, tabIndex, fieldValues) {
|
|
232
|
+
let text = "";
|
|
233
|
+
let firstRun;
|
|
234
|
+
for (let i = tabIndex + 1; i < runs.length; i++) {
|
|
235
|
+
const next = runs[i];
|
|
236
|
+
if (!next || isTabRun(next) || isLineBreakRun(next)) break;
|
|
237
|
+
if (isTextRun(next)) {
|
|
238
|
+
text += next.text || "";
|
|
239
|
+
firstRun ??= next;
|
|
240
|
+
} else if (isFieldRun(next)) {
|
|
241
|
+
text += fieldMeasureText(next, fieldValues);
|
|
242
|
+
firstRun ??= next;
|
|
243
|
+
} else if (isMathRun(next)) {
|
|
244
|
+
text += next.plainText || "[equation]";
|
|
245
|
+
firstRun ??= next;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const decimalIndex = text.indexOf(".");
|
|
249
|
+
if (decimalIndex === -1 || !firstRun) return 0;
|
|
250
|
+
return measureTextWidth(text.slice(0, decimalIndex), runToFontStyle(firstRun));
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Find word break points in text
|
|
254
|
+
* Returns array of indices where words end (after space/punctuation)
|
|
255
|
+
*/
|
|
256
|
+
function findWordBreaks(text) {
|
|
257
|
+
const breaks = [];
|
|
258
|
+
for (let i = 0; i < text.length; i++) {
|
|
259
|
+
const char = text[i];
|
|
260
|
+
if (char === " " || char === "-" || char === " ") breaks.push(i + 1);
|
|
261
|
+
}
|
|
262
|
+
return breaks;
|
|
263
|
+
}
|
|
264
|
+
function isBreakChar(char) {
|
|
265
|
+
return char === " " || char === "-" || char === " ";
|
|
266
|
+
}
|
|
267
|
+
function isSpaceOrTab(char) {
|
|
268
|
+
return char === " " || char === " ";
|
|
269
|
+
}
|
|
270
|
+
function trimTrailingSpacesAndTabs(text) {
|
|
271
|
+
let end = text.length;
|
|
272
|
+
while (end > 0) {
|
|
273
|
+
const char = text[end - 1];
|
|
274
|
+
if (char !== " " && char !== " ") break;
|
|
275
|
+
end--;
|
|
276
|
+
}
|
|
277
|
+
return text.slice(0, end);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Width of the unbreakable text glued to the end of each run.
|
|
281
|
+
* A run boundary is not itself a wrap opportunity: adjacent note markers and
|
|
282
|
+
* format-only word splits must wrap as one cluster.
|
|
283
|
+
*/
|
|
284
|
+
function computeTrailingGlueWidths(runs) {
|
|
285
|
+
const widths = Array.from({ length: runs.length }, () => 0);
|
|
286
|
+
for (let index = runs.length - 1; index >= 0; index--) {
|
|
287
|
+
const nextRun = runs[index + 1];
|
|
288
|
+
if (!nextRun || !isTextRun(nextRun)) continue;
|
|
289
|
+
const text = nextRun.text;
|
|
290
|
+
if (!text) {
|
|
291
|
+
widths[index] = widths[index + 1] ?? 0;
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
if (isSpaceOrTab(text[0])) continue;
|
|
295
|
+
const style = runToFontStyle(nextRun);
|
|
296
|
+
const breaks = findWordBreaks(text);
|
|
297
|
+
if (breaks.length === 0) {
|
|
298
|
+
widths[index] = measureTextWidth(text, style) + (widths[index + 1] ?? 0);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const firstBreak = breaks[0];
|
|
302
|
+
if (firstBreak === void 0) continue;
|
|
303
|
+
widths[index] = measureTextWidth(trimTrailingSpacesAndTabs(text.slice(0, firstBreak)), style);
|
|
304
|
+
}
|
|
305
|
+
return widths;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Minimum horizontal room a line must offer before we treat it as usable for
|
|
309
|
+
* body text. Below this threshold the line is bumped past obstructing floats
|
|
310
|
+
* via `findClearLineY` instead of being rendered into the unusable sliver.
|
|
311
|
+
* Without this guard, a near-full-width float (e.g. floating table) produces
|
|
312
|
+
* a ~2px segment that collapses every wrap line to one glyph per row.
|
|
313
|
+
*/
|
|
314
|
+
const MIN_WRAP_SEGMENT_WIDTH = 24;
|
|
315
|
+
/**
|
|
316
|
+
* Find the next vertical position at or below `startY` where the available
|
|
317
|
+
* text width is at least `minWidth`. Used to skip lines past stacked floats
|
|
318
|
+
* when there is no horizontal room for meaningful text at the current Y.
|
|
319
|
+
*
|
|
320
|
+
* Returns `startY` if the current position already has enough room, otherwise
|
|
321
|
+
* the lowest `bottomY` of any zone currently obstructing the line. The caller
|
|
322
|
+
* is expected to re-query margins at the returned Y.
|
|
323
|
+
*
|
|
324
|
+
* Coordinates are absolute (i.e., already include any paragraphYOffset).
|
|
325
|
+
*/
|
|
326
|
+
function findClearLineY(startY, lineHeight, zones, contentWidth, minWidth) {
|
|
327
|
+
if (!zones || zones.length === 0) return startY;
|
|
328
|
+
let y = startY;
|
|
329
|
+
for (let i = 0; i < zones.length + 2; i++) {
|
|
330
|
+
const margins = getFloatingMargins(y, lineHeight, zones, 0);
|
|
331
|
+
if (Math.max(0, getFloatingAvailableWidth(margins, contentWidth)) >= minWidth) return y;
|
|
332
|
+
const lineBottom = y + lineHeight;
|
|
333
|
+
let nextY = Number.POSITIVE_INFINITY;
|
|
334
|
+
for (const zone of zones) {
|
|
335
|
+
if (lineBottom <= zone.topY || y >= zone.bottomY) continue;
|
|
336
|
+
if (zone.bottomY > y && zone.bottomY < nextY) nextY = zone.bottomY;
|
|
337
|
+
}
|
|
338
|
+
if (!Number.isFinite(nextY) || nextY <= y) return y;
|
|
339
|
+
y = nextY;
|
|
340
|
+
}
|
|
341
|
+
return y;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Measure a paragraph block and compute line breaks
|
|
345
|
+
*
|
|
346
|
+
* @param block - The paragraph block to measure
|
|
347
|
+
* @param maxWidth - Maximum available width for the paragraph
|
|
348
|
+
* @param options - Optional measurement options (floating zones, Y offset)
|
|
349
|
+
* @returns ParagraphMeasure with lines and total height
|
|
350
|
+
*/
|
|
351
|
+
function measureParagraph(block, maxWidth, options) {
|
|
352
|
+
const runs = block.runs;
|
|
353
|
+
const attrs = block.attrs;
|
|
354
|
+
const spacing = attrs?.spacing;
|
|
355
|
+
const floatingZones = options?.floatingZones;
|
|
356
|
+
const paragraphYOffset = options?.paragraphYOffset ?? 0;
|
|
357
|
+
const indent = attrs?.indent;
|
|
358
|
+
const indentLeft = indent?.left ?? 0;
|
|
359
|
+
const indentRight = indent?.right ?? 0;
|
|
360
|
+
const firstLineOffset = (indent?.firstLine ?? 0) - (indent?.hanging ?? 0);
|
|
361
|
+
const bodyContentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
|
|
362
|
+
let baseFirstLineWidth = Math.max(1, bodyContentWidth - firstLineOffset);
|
|
363
|
+
const markerInlineWidth = getListMarkerInlineWidth(block);
|
|
364
|
+
if (markerInlineWidth > 0) baseFirstLineWidth = Math.max(1, baseFirstLineWidth - markerInlineWidth);
|
|
365
|
+
let cumulativeHeight = 0;
|
|
366
|
+
let pendingFloatSkip = 0;
|
|
367
|
+
/**
|
|
368
|
+
* If floats leave no usable horizontal room at `cumulativeHeight`, advance
|
|
369
|
+
* past them by mutating cumulativeHeight + pendingFloatSkip.
|
|
370
|
+
*/
|
|
371
|
+
const skipObstructingFloats = (lineHeight, lineMaxWidth) => {
|
|
372
|
+
if (!floatingZones || floatingZones.length === 0) return;
|
|
373
|
+
const absoluteY = paragraphYOffset + cumulativeHeight;
|
|
374
|
+
const skip = findClearLineY(absoluteY, lineHeight, floatingZones, lineMaxWidth, 24) - absoluteY;
|
|
375
|
+
if (skip > 0) {
|
|
376
|
+
cumulativeHeight += skip;
|
|
377
|
+
pendingFloatSkip += skip;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const estimatedFirstLineHeight = ptToPx(DEFAULT_FONT_SIZE) * DEFAULT_LINE_HEIGHT_MULTIPLIER;
|
|
381
|
+
skipObstructingFloats(estimatedFirstLineHeight, baseFirstLineWidth);
|
|
382
|
+
const firstLineFloatingMargins = getFloatingMargins(cumulativeHeight, estimatedFirstLineHeight, floatingZones, paragraphYOffset);
|
|
383
|
+
const firstLineWidth = Math.max(1, getFloatingAvailableWidth(firstLineFloatingMargins, baseFirstLineWidth));
|
|
384
|
+
const lines = [];
|
|
385
|
+
if (runs.length === 0) {
|
|
386
|
+
if (attrs?.suppressEmptyParagraphHeight) {
|
|
387
|
+
lines.push({
|
|
388
|
+
fromRun: 0,
|
|
389
|
+
fromChar: 0,
|
|
390
|
+
toRun: 0,
|
|
391
|
+
toChar: 0,
|
|
392
|
+
width: 0,
|
|
393
|
+
ascent: 0,
|
|
394
|
+
descent: 0,
|
|
395
|
+
lineHeight: 0
|
|
396
|
+
});
|
|
397
|
+
return {
|
|
398
|
+
kind: "paragraph",
|
|
399
|
+
lines,
|
|
400
|
+
totalHeight: 0
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const emptyMetrics = calculateEmptyParagraphMetrics(attrs?.defaultFontSize ?? DEFAULT_FONT_SIZE, spacing, attrs?.defaultFontFamily ?? DEFAULT_FONT_FAMILY);
|
|
404
|
+
lines.push({
|
|
405
|
+
fromRun: 0,
|
|
406
|
+
fromChar: 0,
|
|
407
|
+
toRun: 0,
|
|
408
|
+
toChar: 0,
|
|
409
|
+
width: 0,
|
|
410
|
+
...emptyMetrics
|
|
411
|
+
});
|
|
412
|
+
let totalHeight = emptyMetrics.lineHeight;
|
|
413
|
+
if (spacing?.before) totalHeight += spacing.before;
|
|
414
|
+
if (spacing?.after) totalHeight += spacing.after;
|
|
415
|
+
return {
|
|
416
|
+
kind: "paragraph",
|
|
417
|
+
lines,
|
|
418
|
+
totalHeight
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
if (runs.length === 1 && isTextRun(runs[0]) && isEmptyTextRun(runs[0])) {
|
|
422
|
+
const run = runs[0];
|
|
423
|
+
const emptyMetrics = calculateEmptyParagraphMetrics(run.fontSize ?? attrs?.defaultFontSize ?? DEFAULT_FONT_SIZE, spacing, run.fontFamily ?? attrs?.defaultFontFamily ?? DEFAULT_FONT_FAMILY);
|
|
424
|
+
lines.push({
|
|
425
|
+
fromRun: 0,
|
|
426
|
+
fromChar: 0,
|
|
427
|
+
toRun: 0,
|
|
428
|
+
toChar: 0,
|
|
429
|
+
width: 0,
|
|
430
|
+
...emptyMetrics
|
|
431
|
+
});
|
|
432
|
+
let totalHeight = emptyMetrics.lineHeight;
|
|
433
|
+
if (spacing?.before) totalHeight += spacing.before;
|
|
434
|
+
if (spacing?.after) totalHeight += spacing.after;
|
|
435
|
+
return {
|
|
436
|
+
kind: "paragraph",
|
|
437
|
+
lines,
|
|
438
|
+
totalHeight
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
const trailingGlueWidths = computeTrailingGlueWidths(runs);
|
|
442
|
+
let currentLine = {
|
|
443
|
+
fromRun: 0,
|
|
444
|
+
fromChar: 0,
|
|
445
|
+
toRun: 0,
|
|
446
|
+
toChar: 0,
|
|
447
|
+
width: 0,
|
|
448
|
+
maxFontSize: DEFAULT_FONT_SIZE,
|
|
449
|
+
maxFontMetrics: null,
|
|
450
|
+
maxImageHeightPx: 0,
|
|
451
|
+
maxMathHeightPx: 0,
|
|
452
|
+
availableWidth: firstLineWidth,
|
|
453
|
+
leftOffset: firstLineFloatingMargins.leftMargin,
|
|
454
|
+
rightOffset: firstLineFloatingMargins.rightMargin,
|
|
455
|
+
...firstLineFloatingMargins.segments?.length ? { segmentZones: firstLineFloatingMargins.segments } : {}
|
|
456
|
+
};
|
|
457
|
+
const calculateLineTypography = (line) => {
|
|
458
|
+
const finalTypography = { ...calculateTypographyMetrics(line.maxFontSize, spacing, line.maxFontMetrics) };
|
|
459
|
+
const inlineObjectHeight = Math.max(line.maxImageHeightPx, line.maxMathHeightPx);
|
|
460
|
+
if (inlineObjectHeight > finalTypography.lineHeight) {
|
|
461
|
+
const objectHeight = inlineObjectHeight;
|
|
462
|
+
const buffer = finalTypography.descent;
|
|
463
|
+
if (line.fromRun === line.toRun) {
|
|
464
|
+
finalTypography.lineHeight = objectHeight + buffer * 2;
|
|
465
|
+
finalTypography.ascent = objectHeight + buffer;
|
|
466
|
+
} else {
|
|
467
|
+
finalTypography.lineHeight = objectHeight + buffer;
|
|
468
|
+
finalTypography.ascent = objectHeight;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return finalTypography;
|
|
472
|
+
};
|
|
473
|
+
const getPostWrapAvailableWidth = () => {
|
|
474
|
+
if (!floatingZones || floatingZones.length === 0) return bodyContentWidth;
|
|
475
|
+
const lineTypography = calculateLineTypography(currentLine);
|
|
476
|
+
let nextCumulativeHeight = cumulativeHeight + lineTypography.lineHeight;
|
|
477
|
+
const estimatedLineHeight = ptToPx(DEFAULT_FONT_SIZE) * DEFAULT_LINE_HEIGHT_MULTIPLIER;
|
|
478
|
+
const absoluteY = paragraphYOffset + nextCumulativeHeight;
|
|
479
|
+
const skip = findClearLineY(absoluteY, estimatedLineHeight, floatingZones, bodyContentWidth, 24) - absoluteY;
|
|
480
|
+
if (skip > 0) nextCumulativeHeight += skip;
|
|
481
|
+
const floatingMargins = getFloatingMargins(nextCumulativeHeight, estimatedLineHeight, floatingZones, paragraphYOffset);
|
|
482
|
+
return Math.max(1, getFloatingAvailableWidth(floatingMargins, bodyContentWidth));
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Finalize and push the current line to the lines array
|
|
486
|
+
*/
|
|
487
|
+
const finalizeLine = () => {
|
|
488
|
+
const finalTypography = calculateLineTypography(currentLine);
|
|
489
|
+
const line = {
|
|
490
|
+
fromRun: currentLine.fromRun,
|
|
491
|
+
fromChar: currentLine.fromChar,
|
|
492
|
+
toRun: currentLine.toRun,
|
|
493
|
+
toChar: currentLine.toChar,
|
|
494
|
+
width: currentLine.width,
|
|
495
|
+
...finalTypography
|
|
496
|
+
};
|
|
497
|
+
if (currentLine.leftOffset > 0) line.leftOffset = currentLine.leftOffset;
|
|
498
|
+
if (currentLine.rightOffset > 0) line.rightOffset = currentLine.rightOffset;
|
|
499
|
+
if (pendingFloatSkip > 0) {
|
|
500
|
+
line.floatSkipBefore = pendingFloatSkip;
|
|
501
|
+
pendingFloatSkip = 0;
|
|
502
|
+
}
|
|
503
|
+
lines.push(line);
|
|
504
|
+
cumulativeHeight += finalTypography.lineHeight;
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* Start a new line after the current one
|
|
508
|
+
*/
|
|
509
|
+
const startNewLine = (runIndex, charIndex) => {
|
|
510
|
+
finalizeLine();
|
|
511
|
+
const estimatedLineHeight = ptToPx(DEFAULT_FONT_SIZE) * DEFAULT_LINE_HEIGHT_MULTIPLIER;
|
|
512
|
+
skipObstructingFloats(estimatedLineHeight, bodyContentWidth);
|
|
513
|
+
const floatingMargins = getFloatingMargins(cumulativeHeight, estimatedLineHeight, floatingZones, paragraphYOffset);
|
|
514
|
+
currentLine = {
|
|
515
|
+
fromRun: runIndex,
|
|
516
|
+
fromChar: charIndex,
|
|
517
|
+
toRun: runIndex,
|
|
518
|
+
toChar: charIndex,
|
|
519
|
+
width: 0,
|
|
520
|
+
maxFontSize: DEFAULT_FONT_SIZE,
|
|
521
|
+
maxFontMetrics: null,
|
|
522
|
+
maxImageHeightPx: 0,
|
|
523
|
+
maxMathHeightPx: 0,
|
|
524
|
+
availableWidth: Math.max(1, getFloatingAvailableWidth(floatingMargins, bodyContentWidth)),
|
|
525
|
+
leftOffset: floatingMargins.leftMargin,
|
|
526
|
+
rightOffset: floatingMargins.rightMargin,
|
|
527
|
+
...floatingMargins.segments?.length ? { segmentZones: floatingMargins.segments } : {}
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* Update max font tracking for the current line
|
|
532
|
+
*/
|
|
533
|
+
const updateMaxFont = (style) => {
|
|
534
|
+
const fontSize = style.fontSize ?? DEFAULT_FONT_SIZE;
|
|
535
|
+
if (!currentLine.maxFontMetrics || fontSize > currentLine.maxFontSize) {
|
|
536
|
+
currentLine.maxFontSize = fontSize;
|
|
537
|
+
currentLine.maxFontMetrics = getFontMetrics(style);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
for (let runIndex = 0; runIndex < runs.length; runIndex++) {
|
|
541
|
+
const run = runs[runIndex];
|
|
542
|
+
if (isLineBreakRun(run)) {
|
|
543
|
+
currentLine.toRun = runIndex;
|
|
544
|
+
currentLine.toChar = 0;
|
|
545
|
+
startNewLine(runIndex + 1, 0);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (isTabRun(run)) {
|
|
549
|
+
const style = runToFontStyle(run);
|
|
550
|
+
updateMaxFont(style);
|
|
551
|
+
const followingWidth = measureInlineWidthAfterTab(runs, runIndex, options?.fieldValues);
|
|
552
|
+
const decimalPrefixWidth = measureDecimalPrefixWidthAfterTab(runs, runIndex, options?.fieldValues);
|
|
553
|
+
const lineX = currentLine.width + currentLine.leftOffset;
|
|
554
|
+
const tabWidth = calculateTabWidth(indentLeft + (lines.length === 0 ? firstLineOffset + markerInlineWidth : 0) + lineX, {
|
|
555
|
+
...attrs?.tabs !== void 0 ? { explicitStops: attrs.tabs } : {},
|
|
556
|
+
leftIndent: pixelsToTwips(indentLeft)
|
|
557
|
+
}, {
|
|
558
|
+
followingWidth,
|
|
559
|
+
decimalPrefixWidth
|
|
560
|
+
}).width;
|
|
561
|
+
if (currentLine.width + tabWidth > currentLine.availableWidth + WIDTH_TOLERANCE) {
|
|
562
|
+
startNewLine(runIndex, 0);
|
|
563
|
+
updateMaxFont(style);
|
|
564
|
+
}
|
|
565
|
+
currentLine.width += tabWidth;
|
|
566
|
+
currentLine.toRun = runIndex;
|
|
567
|
+
currentLine.toChar = 1;
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
if (isImageRun(run)) {
|
|
571
|
+
const wrapType = run.wrapType;
|
|
572
|
+
if (run.displayMode === "float" || wrapType === "square" || wrapType === "tight" || wrapType === "through" || wrapType === "behind" || wrapType === "inFront") {
|
|
573
|
+
currentLine.toRun = runIndex;
|
|
574
|
+
currentLine.toChar = 1;
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (wrapType === "topAndBottom" || run.displayMode === "block") {
|
|
578
|
+
if (currentLine.width > 0) startNewLine(runIndex, 0);
|
|
579
|
+
const imageHeight = rotatedBlockImageHeight(run);
|
|
580
|
+
const distTop = run.distTop ?? 6;
|
|
581
|
+
const distBottom = run.distBottom ?? 6;
|
|
582
|
+
currentLine.toRun = runIndex;
|
|
583
|
+
currentLine.toChar = 1;
|
|
584
|
+
currentLine.maxImageHeightPx = imageHeight + distTop + distBottom;
|
|
585
|
+
startNewLine(runIndex + 1, 0);
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const inlineBbox = inlineImageBoundingBox(run);
|
|
589
|
+
const imageWidth = inlineBbox.width;
|
|
590
|
+
const imageHeight = inlineBbox.height;
|
|
591
|
+
if (currentLine.width > 0 && currentLine.width + imageWidth > currentLine.availableWidth + WIDTH_TOLERANCE) startNewLine(runIndex, 0);
|
|
592
|
+
const imageFootprintPx = imageHeight + (run.distTop ?? 0) + (run.distBottom ?? 0);
|
|
593
|
+
if (imageFootprintPx > currentLine.maxImageHeightPx) currentLine.maxImageHeightPx = imageFootprintPx;
|
|
594
|
+
currentLine.width += imageWidth;
|
|
595
|
+
currentLine.toRun = runIndex;
|
|
596
|
+
currentLine.toChar = 1;
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
if (isFieldRun(run)) {
|
|
600
|
+
const fallback = fieldMeasureText(run, options?.fieldValues);
|
|
601
|
+
const style = buildRunFontStyle(run, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE);
|
|
602
|
+
updateMaxFont(style);
|
|
603
|
+
const fieldWidth = measureTextWidth(fallback, style);
|
|
604
|
+
if (currentLine.width > 0 && currentLine.width + fieldWidth > currentLine.availableWidth + WIDTH_TOLERANCE) {
|
|
605
|
+
startNewLine(runIndex, 0);
|
|
606
|
+
updateMaxFont(style);
|
|
607
|
+
}
|
|
608
|
+
currentLine.width += fieldWidth;
|
|
609
|
+
currentLine.toRun = runIndex;
|
|
610
|
+
currentLine.toChar = 1;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
if (isMathRun(run)) {
|
|
614
|
+
const style = {
|
|
615
|
+
fontFamily: run.fontFamily ?? "Cambria Math",
|
|
616
|
+
fontSize: run.fontSize ?? DEFAULT_FONT_SIZE,
|
|
617
|
+
...run.bold !== void 0 ? { bold: run.bold } : {},
|
|
618
|
+
...run.italic !== void 0 ? { italic: run.italic } : {}
|
|
619
|
+
};
|
|
620
|
+
updateMaxFont(style);
|
|
621
|
+
const mathWidth = measureTextWidth(run.plainText || "[equation]", style);
|
|
622
|
+
const mathFootprintPx = estimateMathFootprintPx(run);
|
|
623
|
+
if (currentLine.width > 0 && currentLine.width + mathWidth > currentLine.availableWidth + WIDTH_TOLERANCE) {
|
|
624
|
+
startNewLine(runIndex, 0);
|
|
625
|
+
updateMaxFont(style);
|
|
626
|
+
}
|
|
627
|
+
if (mathFootprintPx > currentLine.maxMathHeightPx) currentLine.maxMathHeightPx = mathFootprintPx;
|
|
628
|
+
currentLine.width += mathWidth;
|
|
629
|
+
currentLine.toRun = runIndex;
|
|
630
|
+
currentLine.toChar = 1;
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
if (isTextRun(run)) {
|
|
634
|
+
const textRun = run;
|
|
635
|
+
const text = textRun.text;
|
|
636
|
+
const style = runToFontStyle(textRun);
|
|
637
|
+
updateMaxFont(style);
|
|
638
|
+
if (!text || text.length === 0) {
|
|
639
|
+
currentLine.toRun = runIndex;
|
|
640
|
+
currentLine.toChar = 0;
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const wordBreaks = findWordBreaks(text);
|
|
644
|
+
let charIndex = 0;
|
|
645
|
+
while (charIndex < text.length) {
|
|
646
|
+
let nextBreak = text.length;
|
|
647
|
+
for (const breakPoint of wordBreaks) if (breakPoint > charIndex) {
|
|
648
|
+
nextBreak = breakPoint;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
const word = text.slice(charIndex, nextBreak);
|
|
652
|
+
const wordWidth = measureTextWidth(word, style);
|
|
653
|
+
if (wordWidth > currentLine.availableWidth + WIDTH_TOLERANCE) {
|
|
654
|
+
let chunkStart = 0;
|
|
655
|
+
while (chunkStart < word.length) {
|
|
656
|
+
const spaceLeft = currentLine.availableWidth - currentLine.width + WIDTH_TOLERANCE;
|
|
657
|
+
let bestEnd = findMaxFittingLength(word.slice(chunkStart), style, spaceLeft);
|
|
658
|
+
if (bestEnd === 0) {
|
|
659
|
+
if (currentLine.width > 0) {
|
|
660
|
+
startNewLine(runIndex, charIndex + chunkStart);
|
|
661
|
+
updateMaxFont(style);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
bestEnd = 1;
|
|
665
|
+
}
|
|
666
|
+
const chunkEnd = chunkStart + bestEnd;
|
|
667
|
+
const chunkWidth = measureTextWidth(word.slice(chunkStart, chunkEnd), style);
|
|
668
|
+
currentLine.width += chunkWidth;
|
|
669
|
+
currentLine.toRun = runIndex;
|
|
670
|
+
currentLine.toChar = charIndex + chunkEnd;
|
|
671
|
+
chunkStart = chunkEnd;
|
|
672
|
+
if (chunkStart < word.length) {
|
|
673
|
+
startNewLine(runIndex, charIndex + chunkStart);
|
|
674
|
+
updateMaxFont(style);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
charIndex = nextBreak;
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
const rawGlueWidth = nextBreak === text.length && word.length > 0 && !isBreakChar(word[word.length - 1]) ? trailingGlueWidths[runIndex] ?? 0 : 0;
|
|
681
|
+
const glueWidth = rawGlueWidth > 0 && wordWidth + rawGlueWidth <= getPostWrapAvailableWidth() + WIDTH_TOLERANCE ? rawGlueWidth : 0;
|
|
682
|
+
if (currentLine.width > 0 && currentLine.width + wordWidth + glueWidth > currentLine.availableWidth + WIDTH_TOLERANCE) {
|
|
683
|
+
startNewLine(runIndex, charIndex);
|
|
684
|
+
updateMaxFont(style);
|
|
685
|
+
}
|
|
686
|
+
currentLine.width += wordWidth;
|
|
687
|
+
currentLine.toRun = runIndex;
|
|
688
|
+
currentLine.toChar = nextBreak;
|
|
689
|
+
charIndex = nextBreak;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
finalizeLine();
|
|
694
|
+
let totalWithSpacing = lines.reduce((sum, line) => sum + measuredLineAdvance(line), 0);
|
|
695
|
+
if (spacing?.before) totalWithSpacing += spacing.before;
|
|
696
|
+
if (spacing?.after) totalWithSpacing += spacing.after;
|
|
697
|
+
return {
|
|
698
|
+
kind: "paragraph",
|
|
699
|
+
lines,
|
|
700
|
+
totalHeight: totalWithSpacing
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Measure multiple paragraph blocks
|
|
705
|
+
*
|
|
706
|
+
* @param blocks - Array of paragraph blocks to measure
|
|
707
|
+
* @param maxWidth - Maximum available width
|
|
708
|
+
* @returns Array of ParagraphMeasure results
|
|
709
|
+
*/
|
|
710
|
+
function measureParagraphs(blocks, maxWidth) {
|
|
711
|
+
return blocks.map((block) => measureParagraph(block, maxWidth));
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Get per-character widths for a text run (for click positioning)
|
|
715
|
+
*
|
|
716
|
+
* @param run - The text run to measure
|
|
717
|
+
* @returns Array of character widths
|
|
718
|
+
*/
|
|
719
|
+
function getRunCharWidths(run) {
|
|
720
|
+
const style = runToFontStyle(run);
|
|
721
|
+
return measureRun(run.text, style).charWidths;
|
|
722
|
+
}
|
|
723
|
+
//#endregion
|
|
724
|
+
export { MIN_WRAP_SEGMENT_WIDTH, clampFloatingWrapMargins, findClearLineY, getRunCharWidths, measureParagraph, measureParagraphs };
|