@stll/folio-core 0.46.0 → 0.47.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/dist/ai-edits/apply.js +26 -24
- package/dist/ai-edits/headless.js +1 -1
- package/dist/ai-edits/read.d.ts +1 -0
- package/dist/ai-edits/read.js +1 -0
- package/dist/ai-edits/snapshot.js +32 -27
- package/dist/ai-edits/table-cell-mutations.js +15 -7
- package/dist/ai-edits/table-geometry.js +21 -18
- package/dist/ai-edits/table-template.js +2 -2
- package/dist/compare/content-alignment.js +108 -12
- package/dist/compare/content-types.d.ts +8 -2
- package/dist/compare/content.js +2 -11
- package/dist/compare/plan.js +7 -4
- package/dist/compare/section-boundary-properties.js +1 -2
- package/dist/content-controls/checkboxDisplay.d.ts +8 -2
- package/dist/content-controls/checkboxDisplay.js +11 -5
- package/dist/content-controls/mutateContentControls.js +41 -42
- package/dist/controller/layoutPipeline.js +8 -3
- package/dist/display-list/build/buildDisplayList.js +7 -7
- package/dist/display-list/build/imagePrimitives.d.ts +4 -4
- package/dist/display-list/build/imagePrimitives.js +38 -20
- package/dist/display-list/build/pageBorderPrimitives.js +2 -1
- package/dist/display-list/build/paragraphPrimitives.js +93 -13
- package/dist/display-list/build/previewPrimitives.d.ts +10 -0
- package/dist/display-list/build/previewPrimitives.js +89 -0
- package/dist/display-list/build/strokes.d.ts +177 -8
- package/dist/display-list/build/strokes.js +167 -47
- package/dist/display-list/build/tablePrimitives.js +4 -2
- package/dist/display-list/build/textBoxPrimitives.js +6 -4
- package/dist/display-list/build/textDecorations.d.ts +15 -1
- package/dist/display-list/build/textDecorations.js +15 -1
- package/dist/display-list/dom/renderDisplayListToDom.js +1 -19
- package/dist/display-list/primitives.d.ts +13 -2
- package/dist/display-list/primitives.js +36 -1
- package/dist/document-operations.js +2 -1
- package/dist/docx/attributeRemainder.d.ts +34 -1
- package/dist/docx/attributeRemainder.js +49 -3
- package/dist/docx/blockContentParser.d.ts +2 -0
- package/dist/docx/blockContentParser.js +39 -67
- package/dist/docx/blockPlainText.js +3 -1
- package/dist/docx/borderParser.js +26 -11
- package/dist/docx/builtInStyles.d.ts +8 -16
- package/dist/docx/builtInStyles.js +54 -17
- package/dist/docx/commentAnchorIndex.js +1 -1
- package/dist/docx/commentParser.js +3 -3
- package/dist/docx/commentRangeIntegrity.js +1 -1
- package/dist/docx/commentRangeJoin.js +1 -1
- package/dist/docx/commentReferenceNormalization.js +3 -2
- package/dist/docx/commentReplyMarkers.js +1 -1
- package/dist/docx/compatibility.js +56 -42
- package/dist/docx/containerChildren.d.ts +110 -13
- package/dist/docx/containerChildren.gen.d.ts +16 -1
- package/dist/docx/containerChildren.gen.js +18 -1
- package/dist/docx/containerChildren.js +63 -13
- package/dist/docx/diagramPreview.d.ts +14 -2
- package/dist/docx/diagramPreview.js +81 -169
- package/dist/docx/documentParser.js +4 -1
- package/dist/docx/drawingAnchor.d.ts +87 -0
- package/dist/docx/drawingAnchor.js +201 -0
- package/dist/docx/drawingUtils.d.ts +43 -38
- package/dist/docx/drawingUtils.js +205 -118
- package/dist/docx/fontTableParser.js +102 -41
- package/dist/docx/footnoteParser.js +10 -6
- package/dist/docx/groupDrawingParser.js +4 -3
- package/dist/docx/headerFooterReferenceNormalization.js +1 -1
- package/dist/docx/hyperlinkParser.d.ts +45 -7
- package/dist/docx/hyperlinkParser.js +126 -57
- package/dist/docx/imageParser.js +127 -107
- package/dist/docx/index.d.ts +2 -1
- package/dist/docx/index.js +2 -1
- package/dist/docx/inlineContentRemovals.d.ts +28 -0
- package/dist/docx/inlineContentRemovals.js +46 -0
- package/dist/docx/inlineWrapperContent.d.ts +84 -3
- package/dist/docx/inlineWrapperContent.js +85 -4
- package/dist/docx/inlineWrapperParser.d.ts +11 -0
- package/dist/docx/inlineWrapperParser.js +60 -0
- package/dist/docx/nonVisualDrawingProps.d.ts +5 -13
- package/dist/docx/normalizeBaseDirection.js +4 -2
- package/dist/docx/numberingParser.d.ts +25 -2
- package/dist/docx/numberingParser.js +264 -361
- package/dist/docx/numberingReference.d.ts +9 -16
- package/dist/docx/numberingReference.js +17 -16
- package/dist/docx/numberingReferenceNormalization.js +7 -7
- package/dist/docx/ooxmlCounterFormatter.d.ts +1 -1
- package/dist/docx/ooxmlCounterFormatter.js +4 -1
- package/dist/docx/paraIdAttribute.d.ts +91 -1
- package/dist/docx/paraIdAttribute.js +79 -1
- package/dist/docx/paragraphParser.d.ts +9 -24
- package/dist/docx/paragraphParser.js +212 -396
- package/dist/docx/paragraphProperties.d.ts +23 -0
- package/dist/docx/paragraphProperties.js +279 -0
- package/dist/docx/paragraphPropertySource.js +2 -0
- package/dist/docx/paragraphTextBoxEnrichment.d.ts +2 -1
- package/dist/docx/paragraphTextBoxEnrichment.js +14 -7
- package/dist/docx/paragraphTraversal.d.ts +14 -10
- package/dist/docx/paragraphTraversal.js +47 -49
- package/dist/docx/parseWarningMessage.js +3 -0
- package/dist/docx/parserEnums.d.ts +6 -8
- package/dist/docx/parserEnums.js +4 -6
- package/dist/docx/preservedRunContent.js +16 -6
- package/dist/docx/previewBudget.d.ts +44 -23
- package/dist/docx/previewBudget.js +61 -30
- package/dist/docx/propertyElementAttributes.d.ts +178 -0
- package/dist/docx/propertyElementAttributes.js +114 -0
- package/dist/docx/renderedPageBreakNormalization.js +2 -2
- package/dist/docx/rezip.d.ts +28 -2
- package/dist/docx/rezip.js +78 -9
- package/dist/docx/runConsolidator.d.ts +42 -2
- package/dist/docx/runConsolidator.js +60 -6
- package/dist/docx/runParser.d.ts +54 -18
- package/dist/docx/runParser.js +379 -295
- package/dist/docx/runPayload.d.ts +5 -0
- package/dist/docx/runPayload.js +4 -0
- package/dist/docx/sdtProperties.d.ts +39 -5
- package/dist/docx/sdtProperties.js +205 -84
- package/dist/docx/sdtPropertiesPatch.d.ts +5 -9
- package/dist/docx/sdtPropertiesPatch.js +68 -112
- package/dist/docx/sectionParser.d.ts +1 -2
- package/dist/docx/sectionParser.js +236 -240
- package/dist/docx/selectiveSave.js +3 -2
- package/dist/docx/selectiveXmlPatch.d.ts +21 -2
- package/dist/docx/selectiveXmlPatch.js +195 -99
- package/dist/docx/serializer/blockSdtSerializer.js +2 -96
- package/dist/docx/serializer/borderSerializer.d.ts +5 -5
- package/dist/docx/serializer/borderSerializer.js +10 -8
- package/dist/docx/serializer/documentSerializer.js +3 -0
- package/dist/docx/serializer/fontTableSerializer.js +31 -3
- package/dist/docx/serializer/headerFooterSerializer.js +3 -0
- package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
- package/dist/docx/serializer/markupRangeAttributes.js +9 -1
- package/dist/docx/serializer/noteSerializer.js +3 -0
- package/dist/docx/serializer/numberingSerializer.d.ts +1 -6
- package/dist/docx/serializer/numberingSerializer.js +81 -79
- package/dist/docx/serializer/paragraphSerializer.d.ts +1 -9
- package/dist/docx/serializer/paragraphSerializer.js +88 -188
- package/dist/docx/serializer/runSerializer.d.ts +1 -5
- package/dist/docx/serializer/runSerializer.js +109 -59
- package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
- package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +34 -45
- package/dist/docx/serializer/settingsSerializer.js +6 -4
- package/dist/docx/serializer/stylesSerializer.js +8 -11
- package/dist/docx/serializer/tableSerializer.js +268 -100
- package/dist/docx/serializer/textFormattingSerializer.d.ts +28 -4
- package/dist/docx/serializer/textFormattingSerializer.js +111 -101
- package/dist/docx/serializer/xmlUtils.d.ts +1 -1
- package/dist/docx/serializer/xmlUtils.js +1 -1
- package/dist/docx/server/createBilingualDocument.js +18 -16
- package/dist/docx/server/migrateYjsAttrSchema.js +3 -3
- package/dist/docx/settingsParser.js +7 -4
- package/dist/docx/shadingParser.d.ts +2 -1
- package/dist/docx/shadingParser.js +43 -7
- package/dist/docx/shapeParser.js +8 -3
- package/dist/docx/strictNames.d.ts +11 -0
- package/dist/docx/strictNames.gen.d.ts +45 -0
- package/dist/docx/strictNames.gen.js +50 -0
- package/dist/docx/strictNames.js +43 -0
- package/dist/docx/strictValueEncodings.gen.js +133 -131
- package/dist/docx/styleParser.js +17 -349
- package/dist/docx/tableParser.d.ts +10 -1
- package/dist/docx/tableParser.js +505 -181
- package/dist/docx/textBoxParser.d.ts +3 -1
- package/dist/docx/textBoxParser.js +18 -8
- package/dist/docx/themeColorAttribute.d.ts +13 -0
- package/dist/docx/themeColorAttribute.js +24 -0
- package/dist/docx/trackedMoveRangeNormalization.js +2 -1
- package/dist/docx/vmlImageParser.d.ts +13 -4
- package/dist/docx/vmlImageParser.js +74 -31
- package/dist/docx/vmlPreview.js +2 -2
- package/dist/docx/wrapPolygon.d.ts +30 -0
- package/dist/docx/wrapPolygon.js +70 -0
- package/dist/docx/xmlParser.d.ts +14 -1
- package/dist/docx/xmlParser.js +18 -2
- package/dist/fonts/embeddedFonts.js +3 -3
- package/dist/headless-layout.js +2 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +68 -0
- package/dist/i18n/messages/catalogs.gen.js +102 -34
- package/dist/i18n/messages/messages.gen.d.ts +4 -0
- package/dist/internal/headlessRevisionResolution.js +9 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +3 -1
- package/dist/internal/paragraphFormattingSerialization.d.ts +20 -9
- package/dist/internal/paragraphFormattingSerialization.js +118 -83
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +2 -0
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +17 -12
- package/dist/layout-bridge/convert/toFlowBlocks.js +177 -101
- package/dist/layout-engine/index.d.ts +2 -2
- package/dist/layout-engine/index.js +53 -17
- package/dist/layout-engine/measure/measureBlocks.d.ts +3 -0
- package/dist/layout-engine/measure/measureBlocks.js +6 -10
- package/dist/layout-engine/measure/tableCellGrid.js +2 -1
- package/dist/layout-engine/measure/tableFragmentBorderGeometry.js +2 -1
- package/dist/layout-engine/measure/tableInlinePlacement.js +2 -5
- package/dist/layout-engine/paragraphSequence.js +3 -2
- package/dist/layout-engine/renderedBreakReconciliation.js +2 -1
- package/dist/layout-engine/section-breaks.d.ts +49 -2
- package/dist/layout-engine/section-breaks.js +55 -4
- package/dist/layout-engine/types.d.ts +47 -17
- package/dist/layout-engine/types.js +16 -1
- package/dist/layout-painter/borderStroke.d.ts +18 -4
- package/dist/layout-painter/renderPage.js +6 -4
- package/dist/layout-painter/renderParagraph.d.ts +2 -1
- package/dist/layout-painter/renderParagraph.js +13 -26
- package/dist/layout-painter/renderTable.d.ts +4 -1
- package/dist/layout-painter/renderTable.js +22 -22
- package/dist/layout-painter/renderTextBox.js +5 -3
- package/dist/markdown/renderBlock.js +3 -1
- package/dist/markdown/renderRuns.js +7 -2
- package/dist/markdown/renderTable.js +2 -1
- package/dist/model.d.ts +3 -3
- package/dist/model.js +2 -2
- package/dist/paged-layout/sectionBlockWidths.d.ts +3 -0
- package/dist/paged-layout/sectionBlockWidths.js +26 -4
- package/dist/prosemirror/attrs/index.d.ts +22 -4
- package/dist/prosemirror/attrs/index.js +498 -60
- package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +9 -1
- package/dist/prosemirror/bookmarkBoundaryAttrs.js +22 -3
- package/dist/prosemirror/commands/comments.js +68 -53
- package/dist/prosemirror/commands/contentControls.js +24 -19
- package/dist/prosemirror/commands/image.d.ts +1 -1
- package/dist/prosemirror/commands/image.js +4 -1
- package/dist/prosemirror/commands/paragraph.d.ts +2 -1
- package/dist/prosemirror/commands/propertyChangeScope.d.ts +12 -4
- package/dist/prosemirror/commands/propertyChangeScope.js +22 -4
- package/dist/prosemirror/commands/sectionBreak.d.ts +33 -1
- package/dist/prosemirror/commands/sectionBreak.js +187 -11
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +18 -2
- package/dist/prosemirror/conversion/fromProseDoc.js +330 -183
- package/dist/prosemirror/conversion/index.d.ts +2 -2
- package/dist/prosemirror/conversion/preservedSinkCarriers.d.ts +39 -0
- package/dist/prosemirror/conversion/preservedSinkCarriers.js +19 -0
- package/dist/prosemirror/conversion/runShadingMark.js +14 -1
- package/dist/prosemirror/conversion/sdtAttrs.d.ts +10 -1
- package/dist/prosemirror/conversion/sdtAttrs.js +19 -5
- package/dist/prosemirror/conversion/toProseDoc.js +371 -141
- package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
- package/dist/prosemirror/emptyRangeAnchor.js +158 -0
- package/dist/prosemirror/extensions/StarterKit.js +8 -2
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +19 -15
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
- package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +4 -3
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.d.ts +3 -3
- package/dist/prosemirror/extensions/features/PasteCleanupExtension.js +5 -5
- package/dist/prosemirror/extensions/features/pasteCleanup.d.ts +3 -1
- package/dist/prosemirror/extensions/features/pasteCleanup.js +56 -2
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +5 -4
- package/dist/prosemirror/extensions/markRegistry.d.ts +26 -2
- package/dist/prosemirror/extensions/markRegistry.js +73 -10
- package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +17 -3
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.d.ts +26 -0
- package/dist/prosemirror/extensions/marks/RunIdentityExtension.js +134 -0
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -1
- package/dist/prosemirror/extensions/marks/UnderlineExtension.js +12 -18
- package/dist/prosemirror/extensions/marks/markUtils.js +2 -1
- package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.d.ts +29 -0
- package/dist/prosemirror/extensions/nodes/BlockBookmarkBoundaryExtension.js +46 -0
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.d.ts +4 -3
- package/dist/prosemirror/extensions/nodes/BlockSdtExtension.js +18 -13
- package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +28 -53
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +10 -0
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +8 -1
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +43 -0
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.d.ts +13 -0
- package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +65 -0
- package/dist/prosemirror/extensions/nodes/SdtExtension.d.ts +3 -1
- package/dist/prosemirror/extensions/nodes/SdtExtension.js +22 -16
- package/dist/prosemirror/extensions/nodes/ShapeExtension.js +4 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +141 -123
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +4 -0
- package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.d.ts +23 -0
- package/dist/prosemirror/extensions/nodes/bookmarkBoundaryDom.js +57 -0
- package/dist/prosemirror/extensions/types.d.ts +12 -3
- package/dist/prosemirror/index.d.ts +4 -2
- package/dist/prosemirror/index.js +2 -1
- package/dist/prosemirror/inlineWrapperStack.js +20 -3
- package/dist/prosemirror/listMarker.d.ts +2 -2
- package/dist/prosemirror/listMarker.js +7 -8
- package/dist/prosemirror/listRenderingAttrs.js +11 -1
- package/dist/prosemirror/listState.d.ts +62 -0
- package/dist/prosemirror/listState.js +49 -0
- package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +13 -0
- package/dist/prosemirror/moveRangeBoundaryAttrs.js +114 -0
- package/dist/prosemirror/numberedRefFields.js +4 -4
- package/dist/prosemirror/numberingAttr.d.ts +55 -0
- package/dist/prosemirror/numberingAttr.js +74 -0
- package/dist/prosemirror/outlineLevelAttr.d.ts +29 -0
- package/dist/prosemirror/outlineLevelAttr.js +42 -0
- package/dist/prosemirror/paragraphFormattingProvenance.d.ts +9 -0
- package/dist/prosemirror/paragraphFormattingProvenance.js +4 -1
- package/dist/prosemirror/plugins/selectionTracker.d.ts +3 -6
- package/dist/prosemirror/plugins/selectionTracker.js +3 -10
- package/dist/prosemirror/rangeAnchorAttrs.d.ts +14 -0
- package/dist/prosemirror/rangeAnchorAttrs.js +101 -0
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +24 -6
- package/dist/prosemirror/revisionCarriers.d.ts +86 -2
- package/dist/prosemirror/revisionCarriers.js +86 -60
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -0
- package/dist/prosemirror/runFormattingInlineCarriers.js +2 -0
- package/dist/prosemirror/runIdentity.d.ts +28 -0
- package/dist/prosemirror/runIdentity.js +36 -0
- package/dist/prosemirror/runStyleFormatting.js +1 -1
- package/dist/prosemirror/schema/index.d.ts +2 -2
- package/dist/prosemirror/schema/marks.d.ts +23 -4
- package/dist/prosemirror/schema/nodes.d.ts +220 -24
- package/dist/prosemirror/sectionCarrier.d.ts +37 -0
- package/dist/prosemirror/sectionCarrier.js +40 -0
- package/dist/prosemirror/selectionState.d.ts +3 -0
- package/dist/prosemirror/selectionState.js +4 -1
- package/dist/prosemirror/styles/resolvedStyleAttrs.d.ts +5 -4
- package/dist/prosemirror/styles/resolvedStyleAttrs.js +15 -13
- package/dist/prosemirror/tableResize.js +5 -6
- package/dist/prosemirror/trackedRunInlineAtoms.d.ts +2 -0
- package/dist/prosemirror/trackedRunInlineAtoms.js +2 -0
- package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
- package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
- package/dist/prosemirror/validation.js +17 -6
- package/dist/prosemirror/yjsDocumentMetadata.d.ts +2 -2
- package/dist/prosemirror/yjsDocumentMetadata.js +428 -7
- package/dist/prosemirror/zeroWidthAnchors.js +4 -0
- package/dist/style-sets/extract.js +4 -4
- package/dist/style-sets/stellaStyle.js +36 -23
- package/dist/types/colors.d.ts +2 -2
- package/dist/types/content.d.ts +2 -2
- package/dist/types/documentEnumValues.d.ts +53 -26
- package/dist/types/documentEnumValues.js +72 -174
- package/dist/types/formatting.d.ts +2 -2
- package/dist/types/index.d.ts +9 -2
- package/dist/utils/borderCss.d.ts +246 -0
- package/dist/utils/borderCss.js +325 -0
- package/dist/utils/colorResolver.d.ts +4 -3
- package/dist/utils/colorResolver.js +45 -76
- package/dist/utils/createDocument.js +24 -6
- package/dist/utils/findReplace.js +52 -10
- package/dist/utils/formatToStyle.d.ts +84 -2
- package/dist/utils/formatToStyle.js +133 -52
- package/dist/utils/headingCollector.js +3 -2
- package/dist/utils/mergeDocumentContent.js +5 -3
- package/dist/utils/paragraphFormattingMerge.js +27 -6
- package/dist/utils/replaceText.js +1 -1
- package/dist/utils/tableOperations.d.ts +5 -3
- package/dist/utils/tableOperations.js +14 -1
- package/dist/utils/tablePlacement.d.ts +7 -0
- package/dist/utils/tablePlacement.js +14 -0
- package/dist/utils/textDirectionFlow.d.ts +15 -0
- package/dist/utils/textDirectionFlow.js +38 -0
- package/dist/utils/textFormattingMerge.js +16 -4
- package/package.json +10 -10
- package/dist/ai-edits/__fixtures__/paragraphs.d.ts +0 -17
- package/dist/ai-edits/__fixtures__/paragraphs.js +0 -33
- package/dist/compare/__fixtures__/body-sequence.d.ts +0 -119
- package/dist/compare/__fixtures__/body-sequence.js +0 -225
- package/dist/compare/__fixtures__/nested-table.d.ts +0 -16
- package/dist/compare/__fixtures__/nested-table.js +0 -50
- package/dist/compare/__fixtures__/numbered-list.d.ts +0 -34
- package/dist/compare/__fixtures__/numbered-list.js +0 -85
- package/dist/docx/bookmarkPlacement.d.ts +0 -9
- package/dist/docx/bookmarkPlacement.js +0 -52
- package/dist/fonts/embeddedFontTable.d.ts +0 -45
- package/dist/fonts/embeddedFontTable.js +0 -80
- package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.d.ts +0 -13
- package/dist/prosemirror/extensions/marks/PageBreakRunOwnerExtension.js +0 -39
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { isValidHexColor } from "../../utils/colorResolver.js";
|
|
2
2
|
import { normalizeImageLuminancePercent } from "../../utils/imageLuminance.js";
|
|
3
3
|
import { serializePreservedAttributes } from "../attributeRemainder.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveEffectExtents, resolveWrapDistances, serializeAnchorAttributes, serializeEffectExtent, serializeInlineAttributes, serializeSimplePos, serializeWrapDistances } from "../drawingAnchor.js";
|
|
5
5
|
import { fieldStateAttributes } from "../fieldState.js";
|
|
6
6
|
import { serializeGraphicFrameLocks } from "../graphicFrameLocks.js";
|
|
7
7
|
import { DECORATIVE_EXTENSION_URI, DECORATIVE_NAMESPACE } from "../imageParser.js";
|
|
8
8
|
import { canReplayEditableImageRawXml } from "../imageRawXml.js";
|
|
9
9
|
import { serializeNonVisualDrawingNames } from "../nonVisualDrawingProps.js";
|
|
10
|
+
import { runHoldsPayload } from "../runPayload.js";
|
|
11
|
+
import { requiredWrapPolygon, serializeWrapPolygon } from "../wrapPolygon.js";
|
|
10
12
|
import { serializeParagraph } from "./paragraphSerializer.js";
|
|
11
13
|
import { serializeTable } from "./tableSerializer.js";
|
|
12
14
|
import { serializeTextFormatting } from "./textFormattingSerializer.js";
|
|
@@ -14,6 +16,7 @@ import { getSingularRunPropertyChange, serializeTrackedChangeAttributes } from "
|
|
|
14
16
|
import { intAttr } from "./xmlUtils.js";
|
|
15
17
|
import { panic } from "better-result";
|
|
16
18
|
import { escapeXmlAttribute, escapeXmlText, requiresXmlSpacePreserve } from "@stll/docx-core";
|
|
19
|
+
import { SCHEME_COLOR_VALUE_BY_THEME_COLOR, knownThemeColor, presetLineDashToken } from "@stll/docx-core/model";
|
|
17
20
|
//#region src/docx/serializer/runSerializer.ts
|
|
18
21
|
/**
|
|
19
22
|
* Run Serializer - Serialize runs to OOXML XML
|
|
@@ -44,21 +47,13 @@ function getUniqueId(id) {
|
|
|
44
47
|
if (id !== void 0 && id !== "" && id !== 0) return String(id);
|
|
45
48
|
return String(nextAutoId++);
|
|
46
49
|
}
|
|
47
|
-
function extractRPrInner(rPrXml) {
|
|
48
|
-
if (!rPrXml.startsWith("<w:rPr>") || !rPrXml.endsWith("</w:rPr>")) return "";
|
|
49
|
-
return rPrXml.slice(7, -8);
|
|
50
|
-
}
|
|
51
50
|
function serializeRunPropertyChange(change) {
|
|
52
51
|
const previousRPrXml = serializeTextFormatting(change.previousFormatting) || "<w:rPr/>";
|
|
53
52
|
return `<w:rPrChange ${serializeTrackedChangeAttributes(change.info)}>${previousRPrXml}</w:rPrChange>`;
|
|
54
53
|
}
|
|
55
54
|
function serializeRunProperties(formatting, propertyChanges) {
|
|
56
|
-
const currentRPrXml = serializeTextFormatting(formatting);
|
|
57
|
-
const currentInner = currentRPrXml ? extractRPrInner(currentRPrXml) : "";
|
|
58
55
|
const propertyChange = getSingularRunPropertyChange(propertyChanges);
|
|
59
|
-
|
|
60
|
-
if (!combined) return "";
|
|
61
|
-
return `<w:rPr>${combined}</w:rPr>`;
|
|
56
|
+
return serializeTextFormatting(formatting, propertyChange ? [["rPrChange", serializeRunPropertyChange(propertyChange)]] : []);
|
|
62
57
|
}
|
|
63
58
|
/**
|
|
64
59
|
* Serialize text content (w:t)
|
|
@@ -130,8 +125,10 @@ function serializeNoBreakHyphen(_content) {
|
|
|
130
125
|
function serializeDrawingColor(color) {
|
|
131
126
|
if (!color) return "";
|
|
132
127
|
if (color.rgb && isValidHexColor(color.rgb)) return `<a:srgbClr val="${escapeXmlAttribute(color.rgb.replace("#", ""))}"/>`;
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
const themeColor = color.themeColor && knownThemeColor(color.themeColor);
|
|
129
|
+
const schemeColor = themeColor ? SCHEME_COLOR_VALUE_BY_THEME_COLOR[themeColor] : null;
|
|
130
|
+
if (schemeColor !== null) {
|
|
131
|
+
let clr = `<a:schemeClr val="${schemeColor}"`;
|
|
135
132
|
if (color.themeTint) clr += `><a:tint val="${escapeXmlAttribute(color.themeTint)}"/></a:schemeClr>`;
|
|
136
133
|
else if (color.themeShade) clr += `><a:shade val="${escapeXmlAttribute(color.themeShade)}"/></a:schemeClr>`;
|
|
137
134
|
else clr += `/>`;
|
|
@@ -171,7 +168,7 @@ function serializeOutline(outline) {
|
|
|
171
168
|
if (outline.cap) attrs.push(`cap="${serializeLineCap(outline.cap)}"`);
|
|
172
169
|
const parts = [];
|
|
173
170
|
if (outline.color) parts.push(`<a:solidFill>${serializeDrawingColor(outline.color)}</a:solidFill>`);
|
|
174
|
-
if (outline.
|
|
171
|
+
if (outline.dash) parts.push(`<a:prstDash val="${escapeXmlAttribute(presetLineDashToken(outline.dash))}"/>`);
|
|
175
172
|
if (outline.join === "bevel") parts.push("<a:bevel/>");
|
|
176
173
|
else if (outline.join === "round") parts.push("<a:round/>");
|
|
177
174
|
else if (outline.join === "miter") parts.push("<a:miter/>");
|
|
@@ -195,14 +192,60 @@ function serializePosition(pos) {
|
|
|
195
192
|
parts.push("</wp:positionV>");
|
|
196
193
|
return parts.join("");
|
|
197
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* The insets each `EG_WrapType` member's own type declares.
|
|
197
|
+
*
|
|
198
|
+
* Total over the wrap kinds, so a kind added to the model has to say which of
|
|
199
|
+
* the four its element may carry. A key this map does not list cannot be
|
|
200
|
+
* written on that element without failing the schema, whatever the drawing's
|
|
201
|
+
* slots hold.
|
|
202
|
+
*/
|
|
203
|
+
const WRAP_CHILD_DISTANCE_KEYS = {
|
|
204
|
+
square: [
|
|
205
|
+
"distT",
|
|
206
|
+
"distB",
|
|
207
|
+
"distL",
|
|
208
|
+
"distR"
|
|
209
|
+
],
|
|
210
|
+
tight: ["distL", "distR"],
|
|
211
|
+
through: ["distL", "distR"],
|
|
212
|
+
topAndBottom: ["distT", "distB"],
|
|
213
|
+
behind: [],
|
|
214
|
+
inFront: [],
|
|
215
|
+
inline: []
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Which `EG_WrapType` members declare a `wp:effectExtent` of their own.
|
|
219
|
+
*
|
|
220
|
+
* Total over the wrap kinds for {@link WRAP_CHILD_DISTANCE_KEYS}'s reason: a
|
|
221
|
+
* kind added to the model has to say whether its element may carry one, and
|
|
222
|
+
* writing it where the type does not declare it fails the schema.
|
|
223
|
+
*/
|
|
224
|
+
const WRAP_CHILD_DECLARES_EFFECT_EXTENT = {
|
|
225
|
+
square: true,
|
|
226
|
+
tight: false,
|
|
227
|
+
through: false,
|
|
228
|
+
topAndBottom: true,
|
|
229
|
+
behind: false,
|
|
230
|
+
inFront: false,
|
|
231
|
+
inline: false
|
|
232
|
+
};
|
|
198
233
|
/** Serialize wrap type to wp:wrap* element */
|
|
199
|
-
function serializeWrap(wrap) {
|
|
234
|
+
function serializeWrap(wrap, effectExtent) {
|
|
200
235
|
const wrapText = wrap.wrapText ? ` wrapText="${wrap.wrapText}"` : " wrapText=\"bothSides\"";
|
|
236
|
+
const authored = resolveWrapDistances(wrap).wrapChild;
|
|
237
|
+
const distances = {};
|
|
238
|
+
for (const key of WRAP_CHILD_DISTANCE_KEYS[wrap.type]) {
|
|
239
|
+
const value = authored[key];
|
|
240
|
+
if (value !== void 0) distances[key] = value;
|
|
241
|
+
}
|
|
242
|
+
const dist = serializeWrapDistances(distances);
|
|
243
|
+
const extent = effectExtent !== void 0 && WRAP_CHILD_DECLARES_EFFECT_EXTENT[wrap.type] ? serializeEffectExtent(effectExtent) : "";
|
|
201
244
|
switch (wrap.type) {
|
|
202
|
-
case "square": return `<wp:wrapSquare${wrapText}/>`;
|
|
203
|
-
case "tight": return `<wp:wrapTight${wrapText}
|
|
204
|
-
case "through": return `<wp:wrapThrough${wrapText}
|
|
205
|
-
case "topAndBottom": return
|
|
245
|
+
case "square": return extent ? `<wp:wrapSquare${wrapText}${dist}>${extent}</wp:wrapSquare>` : `<wp:wrapSquare${wrapText}${dist}/>`;
|
|
246
|
+
case "tight": return `<wp:wrapTight${wrapText}${dist}>${serializeWrapPolygon(requiredWrapPolygon(wrap.polygon))}</wp:wrapTight>`;
|
|
247
|
+
case "through": return `<wp:wrapThrough${wrapText}${dist}>${serializeWrapPolygon(requiredWrapPolygon(wrap.polygon))}</wp:wrapThrough>`;
|
|
248
|
+
case "topAndBottom": return extent ? `<wp:wrapTopAndBottom${dist}>${extent}</wp:wrapTopAndBottom>` : `<wp:wrapTopAndBottom${dist}/>`;
|
|
206
249
|
case "behind":
|
|
207
250
|
case "inFront": return "<wp:wrapNone/>";
|
|
208
251
|
case "inline": return "<wp:wrapNone/>";
|
|
@@ -231,7 +274,10 @@ function serializePicGraphic(image, imageRId, sharedId) {
|
|
|
231
274
|
const cy = image.size.height;
|
|
232
275
|
const rId = escapeXmlAttribute(imageRId);
|
|
233
276
|
const id = sharedId;
|
|
234
|
-
const
|
|
277
|
+
const picNames = serializeNonVisualDrawingNames({
|
|
278
|
+
...image.pictureNames,
|
|
279
|
+
name: image.pictureNames?.name ?? image.filename ?? `image${id}`
|
|
280
|
+
});
|
|
235
281
|
const xfrmAttrs = serializeTransformAttrs(image.transform);
|
|
236
282
|
const cropAttrs = [];
|
|
237
283
|
if (image.crop?.left) cropAttrs.push(`l="${Math.round(image.crop.left * 1e5)}"`);
|
|
@@ -249,7 +295,7 @@ function serializePicGraphic(image, imageRId, sharedId) {
|
|
|
249
295
|
"<a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">",
|
|
250
296
|
"<pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">",
|
|
251
297
|
"<pic:nvPicPr>",
|
|
252
|
-
`<pic:cNvPr id="${id}"
|
|
298
|
+
`<pic:cNvPr id="${id}"${picNames}/>`,
|
|
253
299
|
"<pic:cNvPicPr/>",
|
|
254
300
|
"</pic:nvPicPr>",
|
|
255
301
|
"<pic:blipFill>",
|
|
@@ -271,18 +317,6 @@ function serializePicGraphic(image, imageRId, sharedId) {
|
|
|
271
317
|
].join("");
|
|
272
318
|
}
|
|
273
319
|
/**
|
|
274
|
-
* Serialize only authored wrap-distance attributes. OOXML defaults omitted
|
|
275
|
-
* values to zero, but preserving absence keeps untouched models stable.
|
|
276
|
-
*/
|
|
277
|
-
function serializeWrapDistanceAttrs(wrap) {
|
|
278
|
-
const attrs = [];
|
|
279
|
-
if (wrap?.distT !== void 0) attrs.push(`distT="${intAttr(wrap.distT)}"`);
|
|
280
|
-
if (wrap?.distB !== void 0) attrs.push(`distB="${intAttr(wrap.distB)}"`);
|
|
281
|
-
if (wrap?.distL !== void 0) attrs.push(`distL="${intAttr(wrap.distL)}"`);
|
|
282
|
-
if (wrap?.distR !== void 0) attrs.push(`distR="${intAttr(wrap.distR)}"`);
|
|
283
|
-
return attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
320
|
* Serialize the `wp:docPr` extension list.
|
|
287
321
|
*
|
|
288
322
|
* The decorative flag is the one extension folio models; every other `a:ext`
|
|
@@ -296,6 +330,23 @@ function serializeDocPrExtensions(image) {
|
|
|
296
330
|
return entries ? `<a:extLst>${entries}</a:extLst>` : "";
|
|
297
331
|
}
|
|
298
332
|
/**
|
|
333
|
+
* Serialize `wp:docPr`'s two link children, in the order the schema declares.
|
|
334
|
+
*
|
|
335
|
+
* The click element is replayed from the source while the model still names the
|
|
336
|
+
* target it named, which keeps `tooltip`, `tgtFrame`, `history` and the rest of
|
|
337
|
+
* `CT_Hyperlink` that the model has no field for. A link the editor retargeted
|
|
338
|
+
* no longer agrees with those bytes, so it is rebuilt from the target instead —
|
|
339
|
+
* the alternative is writing a tooltip that points somewhere else. The hover
|
|
340
|
+
* element has no modelled half to disagree with it, so it always replays.
|
|
341
|
+
*/
|
|
342
|
+
function serializeDocPrLinks(image) {
|
|
343
|
+
const hover = image.hlinkHoverXml ?? "";
|
|
344
|
+
const source = image.hlinkClickSource;
|
|
345
|
+
if (source !== void 0 && source.rId === image.hlinkRId) return `${source.xml}${hover}`;
|
|
346
|
+
if (image.hlinkRId === void 0) return hover;
|
|
347
|
+
return `<a:hlinkClick r:id="${escapeXmlAttribute(image.hlinkRId)}"/>${hover}`;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
299
350
|
* Serialize drawing/image content (w:drawing) to full DrawingML XML
|
|
300
351
|
*/
|
|
301
352
|
function serializeDrawingContent(content) {
|
|
@@ -303,19 +354,15 @@ function serializeDrawingContent(content) {
|
|
|
303
354
|
const isFloating = image.wrap.type !== "inline";
|
|
304
355
|
const cx = image.size.width;
|
|
305
356
|
const cy = image.size.height;
|
|
306
|
-
const
|
|
307
|
-
const
|
|
308
|
-
const effT = image.padding?.top ?? 0;
|
|
309
|
-
const effR = image.padding?.right ?? 0;
|
|
310
|
-
const effB = image.padding?.bottom ?? 0;
|
|
311
|
-
const effectExtentEl = `<wp:effectExtent l="${intAttr(effL)}" t="${intAttr(effT)}" r="${intAttr(effR)}" b="${intAttr(effB)}"/>`;
|
|
357
|
+
const effectExtents = resolveEffectExtents(image.wrap, image.padding);
|
|
358
|
+
const effectExtentEl = serializeEffectExtent(effectExtents.drawing);
|
|
312
359
|
const docPrId = getUniqueId(image.id);
|
|
313
360
|
const docPrNames = serializeNonVisualDrawingNames({
|
|
314
361
|
...image.docPrName !== void 0 ? { name: image.docPrName } : {},
|
|
315
362
|
...image.alt !== void 0 ? { alt: image.alt } : {},
|
|
316
363
|
...image.title !== void 0 ? { title: image.title } : {}
|
|
317
364
|
});
|
|
318
|
-
const hlinkClick =
|
|
365
|
+
const hlinkClick = serializeDocPrLinks(image);
|
|
319
366
|
const docPrAttrs = `id="${docPrId}"${docPrNames}${image.hidden === void 0 ? "" : ` hidden="${image.hidden ? "1" : "0"}"`}`;
|
|
320
367
|
const docPrChildren = `${hlinkClick}${serializeDocPrExtensions(image)}`;
|
|
321
368
|
const docPr = docPrChildren ? `<wp:docPr ${docPrAttrs}>${docPrChildren}</wp:docPr>` : `<wp:docPr ${docPrAttrs}/>`;
|
|
@@ -323,7 +370,7 @@ function serializeDrawingContent(content) {
|
|
|
323
370
|
const graphic = image.rId === void 0 ? "" : serializePicGraphic(image, image.rId, docPrId);
|
|
324
371
|
if (!isFloating) return [
|
|
325
372
|
"<w:drawing>",
|
|
326
|
-
`<wp:inline${
|
|
373
|
+
`<wp:inline${serializeInlineAttributes(image.wrap)}>`,
|
|
327
374
|
`<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
|
|
328
375
|
effectExtentEl,
|
|
329
376
|
docPr,
|
|
@@ -332,13 +379,16 @@ function serializeDrawingContent(content) {
|
|
|
332
379
|
"</wp:inline>",
|
|
333
380
|
"</w:drawing>"
|
|
334
381
|
].join("");
|
|
335
|
-
const behindDoc = image.wrap.type === "behind" ? "1" : "0";
|
|
336
382
|
const position = image.position ? serializePosition(image.position) : "<wp:positionH relativeFrom=\"column\"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom=\"paragraph\"><wp:posOffset>0</wp:posOffset></wp:positionV>";
|
|
337
|
-
const wrap = serializeWrap(image.wrap);
|
|
383
|
+
const wrap = serializeWrap(image.wrap, effectExtents.wrapChild);
|
|
338
384
|
return [
|
|
339
385
|
"<w:drawing>",
|
|
340
|
-
`<wp:anchor${
|
|
341
|
-
|
|
386
|
+
`<wp:anchor${serializeAnchorAttributes({
|
|
387
|
+
anchor: image.anchor,
|
|
388
|
+
wrap: image.wrap,
|
|
389
|
+
behindDoc: image.wrap.type === "behind"
|
|
390
|
+
})}>`,
|
|
391
|
+
serializeSimplePos(image.anchor),
|
|
342
392
|
position,
|
|
343
393
|
`<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
|
|
344
394
|
effectExtentEl,
|
|
@@ -377,13 +427,13 @@ function serializeShapeContent(content) {
|
|
|
377
427
|
const cy = shape.size.height;
|
|
378
428
|
const isTextBox = shape.shapeType === "textBox";
|
|
379
429
|
const isFloating = shape.wrap && shape.wrap.type !== "inline";
|
|
380
|
-
const wrapDistances = serializeWrapDistanceAttrs(shape.wrap);
|
|
381
430
|
const docPrId = getUniqueId(shape.id);
|
|
382
431
|
const docPrNames = serializeNonVisualDrawingNames({
|
|
383
432
|
...shape.name !== void 0 ? { name: shape.name } : {},
|
|
384
433
|
...shape.alt !== void 0 ? { alt: shape.alt } : {},
|
|
385
434
|
...shape.title !== void 0 ? { title: shape.title } : {}
|
|
386
435
|
});
|
|
436
|
+
const shapeNames = shape.shapeNames === void 0 ? "" : `<wps:cNvPr id="${docPrId}"${serializeNonVisualDrawingNames(shape.shapeNames)}/>`;
|
|
387
437
|
const spPr = [
|
|
388
438
|
"<wps:spPr>",
|
|
389
439
|
`<a:xfrm${serializeTransformAttrs(shape.transform)}>`,
|
|
@@ -428,6 +478,7 @@ function serializeShapeContent(content) {
|
|
|
428
478
|
"<a:graphicData uri=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\">",
|
|
429
479
|
[
|
|
430
480
|
"<wps:wsp>",
|
|
481
|
+
shapeNames,
|
|
431
482
|
`<wps:cNvSpPr${isTextBox ? " txBox=\"1\"" : ""}/>`,
|
|
432
483
|
spPr,
|
|
433
484
|
textBody === "" ? "<wps:bodyPr/>" : textBody,
|
|
@@ -436,28 +487,32 @@ function serializeShapeContent(content) {
|
|
|
436
487
|
"</a:graphicData>",
|
|
437
488
|
"</a:graphic>"
|
|
438
489
|
].join("");
|
|
490
|
+
const shapeEffectExtents = resolveEffectExtents(shape.wrap, shape.wrap?.effectExtentSlots?.drawing);
|
|
439
491
|
if (!isFloating) return [
|
|
440
492
|
"<w:drawing>",
|
|
441
|
-
`<wp:inline${
|
|
493
|
+
`<wp:inline${serializeInlineAttributes(shape.wrap)}>`,
|
|
442
494
|
`<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
|
|
443
|
-
|
|
495
|
+
serializeEffectExtent(shapeEffectExtents.drawing),
|
|
444
496
|
`<wp:docPr id="${docPrId}"${docPrNames}/>`,
|
|
445
497
|
"<wp:cNvGraphicFramePr/>",
|
|
446
498
|
graphic,
|
|
447
499
|
"</wp:inline>",
|
|
448
500
|
"</w:drawing>"
|
|
449
501
|
].join("");
|
|
450
|
-
const behindDoc = shape.wrap?.type === "behind" ? "1" : "0";
|
|
451
502
|
const position = shape.position ? serializePosition(shape.position) : "<wp:positionH relativeFrom=\"column\"><wp:posOffset>0</wp:posOffset></wp:positionH><wp:positionV relativeFrom=\"paragraph\"><wp:posOffset>0</wp:posOffset></wp:positionV>";
|
|
452
503
|
if (!shape.wrap) panic("Floating shape must have a wrap property");
|
|
453
|
-
const wrap = serializeWrap(shape.wrap);
|
|
504
|
+
const wrap = serializeWrap(shape.wrap, shapeEffectExtents.wrapChild);
|
|
454
505
|
return [
|
|
455
506
|
"<w:drawing>",
|
|
456
|
-
`<wp:anchor${
|
|
457
|
-
|
|
507
|
+
`<wp:anchor${serializeAnchorAttributes({
|
|
508
|
+
anchor: shape.anchor,
|
|
509
|
+
wrap: shape.wrap,
|
|
510
|
+
behindDoc: shape.wrap.type === "behind"
|
|
511
|
+
})}>`,
|
|
512
|
+
serializeSimplePos(shape.anchor),
|
|
458
513
|
position,
|
|
459
514
|
`<wp:extent cx="${intAttr(cx)}" cy="${intAttr(cy)}"/>`,
|
|
460
|
-
|
|
515
|
+
serializeEffectExtent(shapeEffectExtents.drawing),
|
|
461
516
|
wrap,
|
|
462
517
|
`<wp:docPr id="${docPrId}"${docPrNames}/>`,
|
|
463
518
|
"<wp:cNvGraphicFramePr/>",
|
|
@@ -497,6 +552,7 @@ function serializeRunContent(content) {
|
|
|
497
552
|
* @returns XML string for the run
|
|
498
553
|
*/
|
|
499
554
|
function serializeRun(run) {
|
|
555
|
+
if (!runHoldsPayload(run)) return "";
|
|
500
556
|
const parts = [];
|
|
501
557
|
const rPrXml = serializeRunProperties(run.formatting, run.propertyChanges);
|
|
502
558
|
if (rPrXml) parts.push(rPrXml);
|
|
@@ -517,12 +573,6 @@ function serializeRuns(runs) {
|
|
|
517
573
|
return runs.map(serializeRun).join("");
|
|
518
574
|
}
|
|
519
575
|
/**
|
|
520
|
-
* Check if a run has any content
|
|
521
|
-
*/
|
|
522
|
-
function hasRunContent(run) {
|
|
523
|
-
return run.content.length > 0;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
576
|
* Check if a run has formatting
|
|
527
577
|
*/
|
|
528
578
|
function hasRunFormatting(run) {
|
|
@@ -580,4 +630,4 @@ function createTabRun(formatting) {
|
|
|
580
630
|
};
|
|
581
631
|
}
|
|
582
632
|
//#endregion
|
|
583
|
-
export { createBreakRun, createEmptyRun, createTabRun, createTextRun, getRunPlainText,
|
|
633
|
+
export { createBreakRun, createEmptyRun, createTabRun, createTextRun, getRunPlainText, hasRunFormatting, resetAutoIdCounter, serializeRun, serializeRuns };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { document_d_exports } from "../../types/document.js";
|
|
2
|
+
//#region src/docx/serializer/sdtPropertiesSerializer.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* `<w:sdtPr>` from the model: the modelled children, the preserved ones, in
|
|
5
|
+
* schema order.
|
|
6
|
+
*
|
|
7
|
+
* An empty property set is written as an empty element rather than left out.
|
|
8
|
+
* `<w:sdtPr/>` and no `w:sdtPr` at all are different documents — the first is
|
|
9
|
+
* a richText control that states nothing, the second is markup the schema does
|
|
10
|
+
* not admit under `w:sdt` — and folio used to write the second for both.
|
|
11
|
+
*/
|
|
12
|
+
declare const serializeSdtProperties: (props: document_d_exports.SdtProperties) => string;
|
|
13
|
+
/**
|
|
14
|
+
* `w:sdtEndPr`, replayed when the parse captured it and written from the
|
|
15
|
+
* record otherwise.
|
|
16
|
+
*
|
|
17
|
+
* The record's presence is the element's: `<w:sdtEndPr/>` with no `w:rPr` is
|
|
18
|
+
* what Word writes for most controls and differs from a missing element.
|
|
19
|
+
*/
|
|
20
|
+
declare const serializeSdtEndProperties: (properties: document_d_exports.SdtProperties) => string;
|
|
21
|
+
/** `w:sdtPr` followed by `w:sdtEndPr`, in schema order. */
|
|
22
|
+
declare const serializeSdtPropertyElements: (properties: document_d_exports.SdtProperties) => string;
|
|
23
|
+
/** The one writer of an SDT wrapper at every content-model level. */
|
|
24
|
+
declare const serializeSdtWrapper: (properties: document_d_exports.SdtProperties, contentXml: string) => string;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { serializeSdtEndProperties, serializeSdtProperties, serializeSdtPropertyElements, serializeSdtWrapper };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { statesControlKind } from "../sdtProperties.js";
|
|
2
|
+
import { withModelledControlState } from "../sdtPropertiesPatch.js";
|
|
3
|
+
import { serializeTextFormatting } from "./textFormattingSerializer.js";
|
|
4
|
+
import { isSingleWellFormedElement } from "./xmlUtils.js";
|
|
5
|
+
import { escapeXmlAttribute, serializeOnOffElement } from "@stll/docx-core";
|
|
6
|
+
import { assertSafePreservedMarkup, serializeSequenceChildren } from "@stll/docx-core/schema";
|
|
7
|
+
//#region src/docx/serializer/sdtPropertiesSerializer.ts
|
|
8
|
+
/**
|
|
9
|
+
* The one writer of `<w:sdtPr>`.
|
|
10
|
+
*
|
|
11
|
+
* Every content control — block, inline, row and cell — writes its property
|
|
12
|
+
* set here. There used to be three producers: a fallback projection on the
|
|
13
|
+
* block path, a second one on the inline path, and a regex pass over the
|
|
14
|
+
* source's captured bytes that patched an interactive change back into them.
|
|
15
|
+
* The three agreed on nothing in particular, and the patching pass existed
|
|
16
|
+
* only because the replay was the serialization source.
|
|
17
|
+
*
|
|
18
|
+
* It is not any more. `parseSdtProperties` puts every child folio does not
|
|
19
|
+
* model into `SdtProperties.preserved` at its `CT_SdtPr` ordinal, so the model
|
|
20
|
+
* holds the whole element and the writer merges its two halves back in schema
|
|
21
|
+
* order — which `CT_SdtPr` demands, and Word repairs a file that disregards.
|
|
22
|
+
*/
|
|
23
|
+
const listElement = (name, props) => {
|
|
24
|
+
return `<w:${name}${props.dropdownLastValue === void 0 ? "" : ` w:lastValue="${escapeXmlAttribute(props.dropdownLastValue)}"`}>${(props.listItems ?? []).map((item) => `<w:listItem w:displayText="${escapeXmlAttribute(item.displayText)}" w:value="${escapeXmlAttribute(item.value)}"/>`).join("")}</w:${name}>`;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The kind marker for a control that carries none of its own.
|
|
28
|
+
*
|
|
29
|
+
* Only reached for a control built in code rather than parsed: a parsed one
|
|
30
|
+
* keeps the element its author wrote, in the sink, glyph elements and all.
|
|
31
|
+
* `richText` is the format's default and `unknown` is folio's word for a kind
|
|
32
|
+
* it could not read, so neither writes a marker — a bare `w:sdtPr` already
|
|
33
|
+
* means richText.
|
|
34
|
+
*
|
|
35
|
+
* A checkbox has no declared kind element at all: `w14:checkbox` is an
|
|
36
|
+
* extension the Transitional content model does not know, so it is filed
|
|
37
|
+
* under the slot the kind choice occupies, which is where Word writes it.
|
|
38
|
+
*/
|
|
39
|
+
const synthesizedKind = (props) => {
|
|
40
|
+
switch (props.sdtType) {
|
|
41
|
+
case "plainText": return ["text", "<w:text/>"];
|
|
42
|
+
case "date": return ["date", `<w:date${props.dateValueISO ? ` w:fullDate="${escapeXmlAttribute(props.dateValueISO)}"` : ""}>${props.dateFormat ? `<w:dateFormat w:val="${escapeXmlAttribute(props.dateFormat)}"/>` : ""}</w:date>`];
|
|
43
|
+
case "dropdown": return ["dropDownList", listElement("dropDownList", props)];
|
|
44
|
+
case "comboBox": return ["comboBox", listElement("comboBox", props)];
|
|
45
|
+
case "checkbox": return ["equation", `<w14:checkbox><w14:checked w14:val="${props.checked ? "1" : "0"}"/></w14:checkbox>`];
|
|
46
|
+
case "picture": return ["picture", "<w:picture/>"];
|
|
47
|
+
case "buildingBlockGallery": return ["docPartObj", "<w:docPartObj/>"];
|
|
48
|
+
case "group": return ["group", "<w:group/>"];
|
|
49
|
+
case "richText":
|
|
50
|
+
case "unknown": return ["richText", ""];
|
|
51
|
+
default: return props.sdtType;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* `<w:sdtPr>` from the model: the modelled children, the preserved ones, in
|
|
56
|
+
* schema order.
|
|
57
|
+
*
|
|
58
|
+
* An empty property set is written as an empty element rather than left out.
|
|
59
|
+
* `<w:sdtPr/>` and no `w:sdtPr` at all are different documents — the first is
|
|
60
|
+
* a richText control that states nothing, the second is markup the schema does
|
|
61
|
+
* not admit under `w:sdt` — and folio used to write the second for both.
|
|
62
|
+
*/
|
|
63
|
+
const serializeSdtProperties = (props) => {
|
|
64
|
+
assertSafePreservedMarkup(props.preserved);
|
|
65
|
+
const modelled = [];
|
|
66
|
+
if (props.alias !== void 0) modelled.push(["alias", `<w:alias w:val="${escapeXmlAttribute(props.alias)}"/>`]);
|
|
67
|
+
if (props.tag !== void 0) modelled.push(["tag", `<w:tag w:val="${escapeXmlAttribute(props.tag)}"/>`]);
|
|
68
|
+
if (props.id !== void 0) modelled.push(["id", `<w:id w:val="${props.id}"/>`]);
|
|
69
|
+
if (props.lock !== void 0) modelled.push(["lock", `<w:lock w:val="${props.lock}"/>`]);
|
|
70
|
+
if (props.placeholder !== void 0) modelled.push(["placeholder", `<w:placeholder><w:docPart w:val="${escapeXmlAttribute(props.placeholder)}"/></w:placeholder>`]);
|
|
71
|
+
if (props.showingPlaceholder !== void 0) modelled.push(["showingPlcHdr", serializeOnOffElement(props.showingPlaceholder, "showingPlcHdr")]);
|
|
72
|
+
const captured = props.preserved?.children ?? [];
|
|
73
|
+
let statedKind = false;
|
|
74
|
+
const preserved = captured.map((child) => {
|
|
75
|
+
if (!statesControlKind(child.xml)) return child;
|
|
76
|
+
statedKind = true;
|
|
77
|
+
return {
|
|
78
|
+
index: child.index,
|
|
79
|
+
xml: withModelledControlState(child.xml, props)
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
if (!statedKind) modelled.push(synthesizedKind(props));
|
|
83
|
+
const body = serializeSequenceChildren({
|
|
84
|
+
container: "content-control-properties",
|
|
85
|
+
modelled,
|
|
86
|
+
preserved: props.preserved === void 0 ? void 0 : { children: preserved }
|
|
87
|
+
}).join("");
|
|
88
|
+
return body.length === 0 ? "<w:sdtPr/>" : `<w:sdtPr>${body}</w:sdtPr>`;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* `w:sdtEndPr`, replayed when the parse captured it and written from the
|
|
92
|
+
* record otherwise.
|
|
93
|
+
*
|
|
94
|
+
* The record's presence is the element's: `<w:sdtEndPr/>` with no `w:rPr` is
|
|
95
|
+
* what Word writes for most controls and differs from a missing element.
|
|
96
|
+
*/
|
|
97
|
+
const serializeSdtEndProperties = (properties) => {
|
|
98
|
+
if (properties.rawEndPropertiesXml && isSingleWellFormedElement(properties.rawEndPropertiesXml, "sdtEndPr")) return properties.rawEndPropertiesXml;
|
|
99
|
+
const endProperties = properties.endProperties;
|
|
100
|
+
if (endProperties === void 0) return "";
|
|
101
|
+
const runProperties = serializeTextFormatting(endProperties.runProperties);
|
|
102
|
+
return runProperties.length > 0 ? `<w:sdtEndPr>${runProperties}</w:sdtEndPr>` : "<w:sdtEndPr/>";
|
|
103
|
+
};
|
|
104
|
+
/** `w:sdtPr` followed by `w:sdtEndPr`, in schema order. */
|
|
105
|
+
const serializeSdtPropertyElements = (properties) => `${serializeSdtProperties(properties)}${serializeSdtEndProperties(properties)}`;
|
|
106
|
+
/** The one writer of an SDT wrapper at every content-model level. */
|
|
107
|
+
const serializeSdtWrapper = (properties, contentXml) => {
|
|
108
|
+
return `<w:sdt>${serializeSdtPropertyElements(properties)}${properties.rawSdtChildrenBeforeContent ?? ""}<w:sdtContent>${contentXml}</w:sdtContent>${properties.rawSdtChildrenAfterContent ?? ""}</w:sdt>`;
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
export { serializeSdtEndProperties, serializeSdtProperties, serializeSdtPropertyElements, serializeSdtWrapper };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { serializePreservedAttributes } from "../attributeRemainder.js";
|
|
2
|
-
import { getUnserializedSectionPropertyChildNames } from "../sectionParser.js";
|
|
3
2
|
import { serializeSectionReferenceHistory } from "../sectionReferenceHistory.js";
|
|
4
3
|
import { serializeBorder } from "./borderSerializer.js";
|
|
5
4
|
import { serializeTrackedChangeAttributes } from "./trackedChangeAttributes.js";
|
|
6
5
|
import { intAttr } from "./xmlUtils.js";
|
|
7
|
-
import { escapeXmlAttribute } from "@stll/docx-core";
|
|
6
|
+
import { escapeXmlAttribute, serializeOnOffElement } from "@stll/docx-core";
|
|
7
|
+
import { themeColorToken } from "@stll/docx-core/model";
|
|
8
|
+
import { serializeSequenceChildren } from "@stll/docx-core/schema";
|
|
8
9
|
//#region src/docx/serializer/sectionPropertiesSerializer.ts
|
|
9
10
|
const serializeHeaderReference = (ref) => `<w:headerReference w:type="${ref.type}" r:id="${escapeXmlAttribute(ref.rId)}"/>`;
|
|
10
11
|
const serializeFooterReference = (ref) => `<w:footerReference w:type="${ref.type}" r:id="${escapeXmlAttribute(ref.rId)}"/>`;
|
|
@@ -77,7 +78,7 @@ function serializeLineNumbers(props) {
|
|
|
77
78
|
if (ln.start !== void 0) attrs.push(`w:start="${intAttr(ln.start)}"`);
|
|
78
79
|
if (ln.distance !== void 0) attrs.push(`w:distance="${intAttr(ln.distance)}"`);
|
|
79
80
|
if (ln.restart) attrs.push(`w:restart="${ln.restart}"`);
|
|
80
|
-
return attrs.length > 0 ? `<w:lnNumType ${attrs.join(" ")}/>` : "";
|
|
81
|
+
return attrs.length > 0 ? `<w:lnNumType ${attrs.join(" ")}/>` : "<w:lnNumType/>";
|
|
81
82
|
}
|
|
82
83
|
function serializePageNumbering(props) {
|
|
83
84
|
if (!props.pageNumbering) return "";
|
|
@@ -106,7 +107,6 @@ function serializePageBorders(props) {
|
|
|
106
107
|
const xml = serializeBorder(pb[key], elementName);
|
|
107
108
|
if (xml) borderElements.push(xml);
|
|
108
109
|
}
|
|
109
|
-
if (borderElements.length === 0 && attrs.length === 0) return "";
|
|
110
110
|
const attrsStr = attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
|
|
111
111
|
if (borderElements.length === 0) return `<w:pgBorders${attrsStr}/>`;
|
|
112
112
|
return `<w:pgBorders${attrsStr}>${borderElements.join("")}</w:pgBorders>`;
|
|
@@ -117,7 +117,8 @@ function serializeBackground(props) {
|
|
|
117
117
|
const { background } = props;
|
|
118
118
|
if (background.color?.auto) attrs.push("w:color=\"auto\"");
|
|
119
119
|
else if (background.color?.rgb) attrs.push(`w:color="${escapeXmlAttribute(background.color.rgb)}"`);
|
|
120
|
-
|
|
120
|
+
const backgroundThemeColor = background.themeColor ?? background.color?.themeColor;
|
|
121
|
+
if (backgroundThemeColor !== void 0) attrs.push(`w:themeColor="${escapeXmlAttribute(themeColorToken(backgroundThemeColor))}"`);
|
|
121
122
|
if (background.themeTint ?? background.color?.themeTint) attrs.push(`w:themeTint="${escapeXmlAttribute(background.themeTint ?? background.color?.themeTint ?? "")}"`);
|
|
122
123
|
if (background.themeShade ?? background.color?.themeShade) attrs.push(`w:themeShade="${escapeXmlAttribute(background.themeShade ?? background.color?.themeShade ?? "")}"`);
|
|
123
124
|
return attrs.length > 0 ? `<w:background ${attrs.join(" ")}/>` : "";
|
|
@@ -131,10 +132,6 @@ function serializeDocGrid(props) {
|
|
|
131
132
|
if (dg.charSpace !== void 0) attrs.push(`w:charSpace="${intAttr(dg.charSpace)}"`);
|
|
132
133
|
return attrs.length > 0 ? `<w:docGrid ${attrs.join(" ")}/>` : "<w:docGrid/>";
|
|
133
134
|
}
|
|
134
|
-
function serializeOnOffElement(value, name) {
|
|
135
|
-
if (value === void 0) return "";
|
|
136
|
-
return value ? `<w:${name}/>` : `<w:${name} w:val="0"/>`;
|
|
137
|
-
}
|
|
138
135
|
function serializeSectionPropertyChange(change) {
|
|
139
136
|
const { headerReferences: _headers, footerReferences: _footers, ...previous } = change.previousProperties ?? {};
|
|
140
137
|
const previousSectPrXml = serializeSectionProperties(previous) || "<w:sectPr/>";
|
|
@@ -143,42 +140,34 @@ function serializeSectionPropertyChange(change) {
|
|
|
143
140
|
}
|
|
144
141
|
function serializeSectionProperties(props) {
|
|
145
142
|
if (!props) return "";
|
|
146
|
-
const parts =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
serializeOnOffElement(props.formProtection, "formProt"),
|
|
175
|
-
serializeOnOffElement(props.noEndnote, "noEndnote"),
|
|
176
|
-
serializeOnOffElement(props.rtlGutter, "rtlGutter")
|
|
177
|
-
]) if (xml) parts.push(xml);
|
|
178
|
-
if (props.printerSettingsRelationshipId) parts.push(`<w:printerSettings r:id="${escapeXmlAttribute(props.printerSettingsRelationshipId)}"/>`);
|
|
179
|
-
for (const change of props.propertyChanges ?? []) parts.push(serializeSectionPropertyChange(change));
|
|
180
|
-
const unserializedChildNames = getUnserializedSectionPropertyChildNames(props);
|
|
181
|
-
if (unserializedChildNames && unserializedChildNames.length > 0) return "";
|
|
143
|
+
const parts = serializeSequenceChildren({
|
|
144
|
+
container: "section-properties",
|
|
145
|
+
modelled: [
|
|
146
|
+
["headerReference", (props.headerReferences ?? []).map(serializeHeaderReference).join("")],
|
|
147
|
+
["footerReference", (props.footerReferences ?? []).map(serializeFooterReference).join("")],
|
|
148
|
+
["footnotePr", serializeFootnoteProperties(props.footnotePr) + serializeFootnoteColumns(props)],
|
|
149
|
+
["endnotePr", serializeEndnoteProperties(props.endnotePr)],
|
|
150
|
+
["type", props.sectionStart ? `<w:type w:val="${props.sectionStart}"/>` : ""],
|
|
151
|
+
["pgSz", serializePageSize(props)],
|
|
152
|
+
["pgMar", serializePageMargins(props)],
|
|
153
|
+
["paperSrc", serializePaperSource(props)],
|
|
154
|
+
["pgBorders", serializePageBorders(props) + serializeBackground(props)],
|
|
155
|
+
["lnNumType", serializeLineNumbers(props)],
|
|
156
|
+
["pgNumType", serializePageNumbering(props)],
|
|
157
|
+
["cols", serializeColumns(props)],
|
|
158
|
+
["formProt", serializeOnOffElement(props.formProtection, "formProt")],
|
|
159
|
+
["vAlign", props.verticalAlign ? `<w:vAlign w:val="${props.verticalAlign}"/>` : ""],
|
|
160
|
+
["noEndnote", serializeOnOffElement(props.noEndnote, "noEndnote")],
|
|
161
|
+
["titlePg", serializeOnOffElement(props.titlePg, "titlePg")],
|
|
162
|
+
["textDirection", props.textDirection ? `<w:textDirection w:val="${props.textDirection}"/>` : ""],
|
|
163
|
+
["bidi", serializeOnOffElement(props.bidi, "bidi")],
|
|
164
|
+
["rtlGutter", serializeOnOffElement(props.rtlGutter, "rtlGutter")],
|
|
165
|
+
["docGrid", serializeDocGrid(props)],
|
|
166
|
+
["printerSettings", props.printerSettingsRelationshipId ? `<w:printerSettings r:id="${escapeXmlAttribute(props.printerSettingsRelationshipId)}"/>` : ""],
|
|
167
|
+
["sectPrChange", (props.propertyChanges ?? []).map(serializeSectionPropertyChange).join("")]
|
|
168
|
+
],
|
|
169
|
+
preserved: props.preserved
|
|
170
|
+
});
|
|
182
171
|
const attributes = serializePreservedAttributes([], props.preservedAttributes);
|
|
183
172
|
const startTag = attributes.length > 0 ? `<w:sectPr ${attributes.join(" ")}` : "<w:sectPr";
|
|
184
173
|
if (parts.length > 0) return `${startTag}>${parts.join("")}</w:sectPr>`;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { serializePartElement } from "./partNamespaces.js";
|
|
2
2
|
import { intAttr } from "./xmlUtils.js";
|
|
3
|
-
import { escapeXmlAttribute } from "@stll/docx-core";
|
|
3
|
+
import { escapeXmlAttribute, serializeOnOffElement } from "@stll/docx-core";
|
|
4
4
|
//#region src/docx/serializer/settingsSerializer.ts
|
|
5
5
|
const serializeSettingsXml = (settings) => {
|
|
6
|
-
const parts = [
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const parts = [
|
|
7
|
+
`<w:defaultTabStop w:val="${intAttr(settings.defaultTabStop)}"/>`,
|
|
8
|
+
serializeOnOffElement(settings.evenAndOddHeaders, "evenAndOddHeaders"),
|
|
9
|
+
serializeOnOffElement(settings.updateFields, "updateFields")
|
|
10
|
+
];
|
|
9
11
|
if (settings.themeFontLang) {
|
|
10
12
|
const attrs = [];
|
|
11
13
|
if (settings.themeFontLang.eastAsia) attrs.push(`w:eastAsia="${escapeXmlAttribute(settings.themeFontLang.eastAsia)}"`);
|