@stll/folio-core 0.45.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 +85 -43
- package/dist/ai-edits/headless.js +2 -2
- 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/compare.js +2 -5
- 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/scenario.js +2 -5
- package/dist/compare/section-boundary-properties.js +1 -2
- package/dist/compare/types.d.ts +9 -1
- package/dist/compare/types.js +12 -1
- package/dist/compat/eigenpal.d.ts +2 -1
- package/dist/compat/eigenpal.js +2 -1
- package/dist/content-controls/checkboxDisplay.d.ts +17 -0
- package/dist/content-controls/checkboxDisplay.js +46 -0
- package/dist/content-controls/findContentControls.js +3 -1
- package/dist/content-controls/mutateContentControls.js +57 -43
- package/dist/controller/contentControlWidgetController.d.ts +1 -0
- package/dist/controller/contentControlWidgetController.js +3 -0
- package/dist/controller/hiddenEditorApi.js +3 -1
- package/dist/controller/hiddenEditorManager.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.js +6 -3
- package/dist/controller/layoutPipeline.js +8 -3
- package/dist/display-list/build/buildDisplayList.js +20 -1
- package/dist/display-list/build/imagePrimitives.d.ts +4 -4
- package/dist/display-list/build/imagePrimitives.js +38 -18
- package/dist/display-list/build/pageBorderPrimitives.js +2 -1
- package/dist/display-list/build/paragraphPrimitives.js +113 -14
- 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 +11 -21
- package/dist/display-list/primitives.d.ts +13 -2
- package/dist/display-list/primitives.js +36 -1
- package/dist/display-list/types.d.ts +17 -0
- package/dist/document-operations.js +2 -1
- package/dist/docx/attributeRemainder.d.ts +76 -0
- package/dist/docx/attributeRemainder.js +111 -0
- package/dist/docx/blockContentParser.d.ts +3 -1
- package/dist/docx/blockContentParser.js +102 -106
- package/dist/docx/blockPlainText.d.ts +3 -4
- package/dist/docx/blockPlainText.js +3 -0
- 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.d.ts +30 -0
- package/dist/docx/commentAnchorIndex.js +50 -0
- package/dist/docx/commentParser.d.ts +1 -1
- package/dist/docx/commentParser.js +56 -39
- package/dist/docx/commentRangeIntegrity.d.ts +16 -1
- package/dist/docx/commentRangeIntegrity.js +42 -1
- package/dist/docx/commentRangeJoin.d.ts +9 -0
- package/dist/docx/commentRangeJoin.js +33 -0
- package/dist/docx/commentReferenceCompletion.d.ts +9 -0
- package/dist/docx/commentReferenceCompletion.js +47 -0
- package/dist/docx/commentReferenceNormalization.js +3 -1
- package/dist/docx/commentReplyMarkers.js +11 -19
- package/dist/docx/compatibility.js +56 -41
- package/dist/docx/containerChildren.d.ts +208 -0
- package/dist/docx/containerChildren.gen.d.ts +43 -0
- package/dist/docx/containerChildren.gen.js +263 -0
- package/dist/docx/containerChildren.js +153 -0
- package/dist/docx/diagramPreview.d.ts +14 -2
- package/dist/docx/diagramPreview.js +81 -169
- package/dist/docx/documentParser.d.ts +1 -1
- package/dist/docx/documentParser.js +7 -4
- 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/ensureParaIds.js +17 -7
- package/dist/docx/fieldParser.d.ts +1 -1
- package/dist/docx/fieldParser.js +4 -4
- package/dist/docx/fieldState.d.ts +26 -0
- package/dist/docx/fieldState.js +53 -0
- package/dist/docx/fontTableParser.js +102 -41
- package/dist/docx/footnoteParser.d.ts +1 -1
- package/dist/docx/footnoteParser.js +10 -6
- package/dist/docx/graphicFrameLocks.d.ts +16 -4
- package/dist/docx/graphicFrameLocks.js +19 -6
- package/dist/docx/groupDrawingParser.js +4 -3
- package/dist/docx/headerFooterParser.js +1 -1
- package/dist/docx/headerFooterReferenceNormalization.js +1 -0
- package/dist/docx/hyperlinkParser.d.ts +66 -9
- package/dist/docx/hyperlinkParser.js +153 -26
- package/dist/docx/imageParser.js +160 -115
- 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 +166 -0
- package/dist/docx/inlineWrapperContent.js +165 -0
- 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 +12 -1
- 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 +111 -0
- package/dist/docx/paraIdAttribute.js +142 -0
- package/dist/docx/paragraphParser.d.ts +10 -25
- package/dist/docx/paragraphParser.js +421 -496
- package/dist/docx/paragraphProperties.d.ts +23 -0
- package/dist/docx/paragraphProperties.js +279 -0
- package/dist/docx/paragraphPropertySource.js +7 -1
- package/dist/docx/paragraphTextBoxEnrichment.d.ts +3 -2
- package/dist/docx/paragraphTextBoxEnrichment.js +20 -59
- package/dist/docx/paragraphTraversal.d.ts +14 -10
- package/dist/docx/paragraphTraversal.js +53 -52
- package/dist/docx/parseWarningMessage.js +5 -1
- package/dist/docx/parserEnums.d.ts +6 -8
- package/dist/docx/parserEnums.js +4 -6
- package/dist/docx/preservedRunContent.d.ts +32 -0
- package/dist/docx/preservedRunContent.js +96 -0
- 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 +4 -6
- package/dist/docx/rezip.d.ts +28 -2
- package/dist/docx/rezip.js +152 -27
- package/dist/docx/runConsolidator.d.ts +42 -2
- package/dist/docx/runConsolidator.js +60 -6
- package/dist/docx/runParser.d.ts +55 -19
- package/dist/docx/runParser.js +394 -306
- 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 +241 -238
- package/dist/docx/selectiveSave.js +3 -2
- package/dist/docx/selectiveXmlPatch.d.ts +66 -3
- package/dist/docx/selectiveXmlPatch.js +276 -133
- package/dist/docx/serializer/blockSdtSerializer.js +2 -96
- package/dist/docx/serializer/borderSerializer.d.ts +5 -5
- package/dist/docx/serializer/borderSerializer.js +12 -10
- package/dist/docx/serializer/commentSerializer.js +5 -7
- package/dist/docx/serializer/documentSerializer.js +11 -11
- package/dist/docx/serializer/fontTableSerializer.js +31 -3
- package/dist/docx/serializer/headerFooterSerializer.js +10 -9
- package/dist/docx/serializer/markupRangeAttributes.d.ts +9 -1
- package/dist/docx/serializer/markupRangeAttributes.js +9 -1
- package/dist/docx/serializer/noteSerializer.js +11 -8
- 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 +156 -236
- package/dist/docx/serializer/runSerializer.d.ts +1 -5
- package/dist/docx/serializer/runSerializer.js +134 -75
- package/dist/docx/serializer/sdtPropertiesSerializer.d.ts +26 -0
- package/dist/docx/serializer/sdtPropertiesSerializer.js +111 -0
- package/dist/docx/serializer/sectionPropertiesSerializer.js +42 -49
- package/dist/docx/serializer/settingsSerializer.js +6 -4
- package/dist/docx/serializer/stylesSerializer.js +8 -11
- package/dist/docx/serializer/tableSerializer.js +283 -105
- 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 +20 -16
- package/dist/docx/server/materializeYjsDocx.d.ts +1 -1
- package/dist/docx/server/materializeYjsDocx.js +9 -1
- package/dist/docx/server/migrateYjsAttrSchema.d.ts +55 -0
- package/dist/docx/server/migrateYjsAttrSchema.js +95 -0
- 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 +13 -8
- 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 +11 -2
- package/dist/docx/tableParser.js +665 -220
- package/dist/docx/textBoxParser.d.ts +28 -3
- package/dist/docx/textBoxParser.js +69 -9
- 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/unzip.js +5 -4
- package/dist/docx/vmlImageParser.d.ts +30 -5
- package/dist/docx/vmlImageParser.js +91 -32
- 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/xmlEncoding.d.ts +5 -0
- package/dist/docx/xmlEncoding.js +12 -0
- package/dist/docx/xmlParser.d.ts +23 -1
- package/dist/docx/xmlParser.js +31 -2
- package/dist/fonts/embeddedFonts.js +3 -3
- package/dist/headless-layout.js +12 -1
- 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/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/headlessRevisionResolution.js +9 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +7 -2
- 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 +267 -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/tableCellFloating.d.ts +2 -0
- package/dist/layout-engine/measure/tableCellFloating.js +2 -0
- 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 +69 -17
- package/dist/layout-engine/types.js +16 -1
- package/dist/layout-painter/borderStroke.d.ts +18 -4
- package/dist/layout-painter/renderImage.d.ts +5 -1
- package/dist/layout-painter/renderImage.js +10 -3
- package/dist/layout-painter/renderPage.d.ts +2 -0
- package/dist/layout-painter/renderPage.js +10 -4
- package/dist/layout-painter/renderParagraph.d.ts +14 -1
- package/dist/layout-painter/renderParagraph.js +34 -28
- 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/managers/autoSaveCodec.d.ts +9 -1
- package/dist/managers/autoSaveCodec.js +12 -4
- package/dist/markdown/renderBlock.js +3 -0
- package/dist/markdown/renderRuns.d.ts +1 -1
- package/dist/markdown/renderRuns.js +34 -6
- package/dist/markdown/renderTable.js +24 -6
- package/dist/markdown/trailers.js +4 -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/pdf/images.js +142 -6
- package/dist/prosemirror/attrs/index.d.ts +34 -5
- package/dist/prosemirror/attrs/index.js +639 -48
- package/dist/prosemirror/authoredTransformAttrs.d.ts +28 -0
- package/dist/prosemirror/authoredTransformAttrs.js +64 -0
- 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 +33 -20
- package/dist/prosemirror/commands/image.d.ts +10 -3
- package/dist/prosemirror/commands/image.js +46 -29
- package/dist/prosemirror/commands/pageBreak.js +1 -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/commentReferenceAttrs.d.ts +8 -0
- package/dist/prosemirror/commentReferenceAttrs.js +33 -0
- package/dist/prosemirror/commentReferenceIntegrity.d.ts +47 -0
- package/dist/prosemirror/commentReferenceIntegrity.js +43 -0
- package/dist/prosemirror/conversion/fromProseDoc.d.ts +17 -12
- package/dist/prosemirror/conversion/fromProseDoc.js +553 -207
- 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.d.ts +7 -9
- package/dist/prosemirror/conversion/toProseDoc.js +801 -411
- package/dist/prosemirror/emptyRangeAnchor.d.ts +53 -0
- package/dist/prosemirror/emptyRangeAnchor.js +158 -0
- package/dist/prosemirror/extensions/StarterKit.js +14 -58
- package/dist/prosemirror/extensions/core/DocExtension.js +1 -1
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +21 -16
- package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +48 -29
- package/dist/prosemirror/extensions/features/EmptyParagraphFormatExtension.js +3 -1
- package/dist/prosemirror/extensions/features/ImagePasteExtension.js +5 -3
- package/dist/prosemirror/extensions/features/ListExtension.js +43 -24
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +1 -0
- 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 +65 -0
- package/dist/prosemirror/extensions/markRegistry.js +138 -0
- package/dist/prosemirror/extensions/marks/InlineWrapperExtension.d.ts +18 -0
- package/dist/prosemirror/extensions/marks/InlineWrapperExtension.js +77 -0
- 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.d.ts +2 -1
- package/dist/prosemirror/extensions/marks/markUtils.js +49 -5
- 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.d.ts +11 -0
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +97 -0
- package/dist/prosemirror/extensions/nodes/FieldExtension.js +9 -7
- package/dist/prosemirror/extensions/nodes/ImageExtension.js +24 -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/PreservedBlockExtension.d.ts +32 -0
- package/dist/prosemirror/extensions/nodes/PreservedBlockExtension.js +67 -0
- package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.d.ts +16 -0
- package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +60 -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 +7 -0
- package/dist/prosemirror/extensions/nodes/TableExtension.js +142 -123
- package/dist/prosemirror/extensions/nodes/TextBoxExtension.js +9 -1
- 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.d.ts +39 -0
- package/dist/prosemirror/inlineWrapperStack.js +92 -0
- 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/pageBreakRunProjection.d.ts +17 -7
- package/dist/prosemirror/pageBreakRunProjection.js +19 -9
- 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 +59 -0
- package/dist/prosemirror/replacedAnnotations.js +183 -0
- package/dist/prosemirror/revisionCarriers.d.ts +86 -2
- package/dist/prosemirror/revisionCarriers.js +86 -60
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +5 -1
- package/dist/prosemirror/runFormattingInlineCarriers.js +7 -1
- 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 +3 -3
- package/dist/prosemirror/schema/marks.d.ts +47 -4
- package/dist/prosemirror/schema/nodes.d.ts +309 -26
- package/dist/prosemirror/schema/nodes.js +16 -1
- 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 +4 -0
- package/dist/prosemirror/trackedRunInlineAtoms.js +4 -0
- package/dist/prosemirror/utils/extractTrackedChanges.d.ts +10 -11
- package/dist/prosemirror/utils/extractTrackedChanges.js +109 -92
- package/dist/prosemirror/validation.js +31 -6
- package/dist/prosemirror/yjsDocumentMetadata.d.ts +73 -0
- package/dist/prosemirror/yjsDocumentMetadata.js +592 -0
- package/dist/prosemirror/zeroWidthAnchors.js +6 -0
- package/dist/render-dom/commentAnchorAttributes.d.ts +37 -0
- package/dist/render-dom/commentAnchorAttributes.js +54 -0
- package/dist/server.d.ts +3 -1
- package/dist/server.js +3 -1
- 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/clipboard.d.ts +9 -1
- package/dist/utils/clipboard.js +27 -1
- 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/imageLuminance.d.ts +15 -0
- package/dist/utils/imageLuminance.js +32 -0
- package/dist/utils/mergeDocumentContent.js +12 -20
- package/dist/utils/paragraphFormattingMerge.js +27 -6
- package/dist/utils/replaceText.js +1 -0
- 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/blockRangeMarkers.d.ts +0 -36
- package/dist/docx/blockRangeMarkers.js +0 -59
- package/dist/docx/bookmarkPlacement.d.ts +0 -9
- package/dist/docx/bookmarkPlacement.js +0 -50
- 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
- package/dist/prosemirror/yjsParagraphSourceContract.d.ts +0 -9
- package/dist/prosemirror/yjsParagraphSourceContract.js +0 -26
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { TRANSITIONAL_NAMESPACE_BY_STRICT_URI } from "./strictValueEncodings.gen.js";
|
|
2
|
+
import { captureVerbatimXml } from "./verbatimCapture.js";
|
|
3
|
+
import { WORDPROCESSINGML_NAMESPACE_URIS, getChildElements, getLocalName, getNamespaceUri } from "./xmlParser.js";
|
|
4
|
+
import { SEQUENCE_CHILDREN } from "@stll/docx-core/schema";
|
|
5
|
+
//#region src/docx/containerChildren.ts
|
|
6
|
+
/** Keep this child's markup verbatim, in place. */
|
|
7
|
+
const CAPTURE = "capture";
|
|
8
|
+
/**
|
|
9
|
+
* What a handler answers with: nothing when it took a typed value, and
|
|
10
|
+
* {@link CAPTURE} when it took none, so the child's bytes are kept instead.
|
|
11
|
+
*
|
|
12
|
+
* `<w:tblLayout/>` states no layout and `<w:jc w:val="end"/>` states a value a
|
|
13
|
+
* reader's enumeration does not admit. Both used to fall off the end of the
|
|
14
|
+
* walk, and neither can be decided by name: a map keyed by name cannot list
|
|
15
|
+
* the values a reader will refuse, only the names it has never heard of.
|
|
16
|
+
*/
|
|
17
|
+
const keptUnless = (taken) => taken ? void 0 : CAPTURE;
|
|
18
|
+
const OWNED_ELSEWHERE = "owned-elsewhere";
|
|
19
|
+
const CLAIMS = /* @__PURE__ */ new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Every owner a handler map has claimed so far.
|
|
22
|
+
*
|
|
23
|
+
* A claim is registered when `ownedElsewhere` is called, so a module that is
|
|
24
|
+
* never imported contributes none. The checks that read this therefore load
|
|
25
|
+
* the claiming modules first, by scanning the sources for the call rather than
|
|
26
|
+
* by keeping a list beside them.
|
|
27
|
+
*/
|
|
28
|
+
const ownedElsewhereClaims = () => [...CLAIMS.values()];
|
|
29
|
+
/** State that another reader takes this child, and who. */
|
|
30
|
+
const ownedElsewhere = (claim) => {
|
|
31
|
+
CLAIMS.set(`${claim.container}/${claim.child}#${claim.reader}`, claim);
|
|
32
|
+
return {
|
|
33
|
+
disposition: OWNED_ELSEWHERE,
|
|
34
|
+
...claim
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* This child goes with the wrapper folio does not keep.
|
|
39
|
+
*
|
|
40
|
+
* `w:smartTagPr` is the case: folio unwraps `w:smartTag` and splices its
|
|
41
|
+
* content into the paragraph, so the properties describing the wrapper have
|
|
42
|
+
* nothing left to describe and capturing them would put a `w:smartTagPr`
|
|
43
|
+
* where the schema does not admit one. The drop is stated here and recorded
|
|
44
|
+
* in `specifications/container-contract/contract.json`, which is the whole
|
|
45
|
+
* difference between this and a `default` that says nothing.
|
|
46
|
+
*/
|
|
47
|
+
const DROPPED_WITH_ITS_WRAPPER = "dropped-with-its-wrapper";
|
|
48
|
+
/**
|
|
49
|
+
* The Transitional spelling of a namespace, so one disposition covers both.
|
|
50
|
+
*
|
|
51
|
+
* ISO Strict writes the same content model under its own URIs: maths is
|
|
52
|
+
* `purl.oclc.org/ooxml/officeDocument/math` rather than
|
|
53
|
+
* `schemas.openxmlformats.org/officeDocument/2006/math`. A namespace-keyed
|
|
54
|
+
* disposition written in Transitional would otherwise send a Strict
|
|
55
|
+
* document's maths to the sink, which models it as bytes instead of an
|
|
56
|
+
* equation. The pairs come from the generated table rather than a second list
|
|
57
|
+
* here, so a namespace cannot be paired in one place and forgotten in the
|
|
58
|
+
* other.
|
|
59
|
+
*/
|
|
60
|
+
const transitionalNamespaceOf = (namespace) => TRANSITIONAL_NAMESPACE_BY_STRICT_URI.get(namespace) ?? namespace;
|
|
61
|
+
/**
|
|
62
|
+
* Walk a container's children, handing each to its handler and the rest to the
|
|
63
|
+
* sink.
|
|
64
|
+
*
|
|
65
|
+
* @returns the container's unmodelled markup, or `undefined` when it held
|
|
66
|
+
* none — an empty record is never written, so a fully modelled container
|
|
67
|
+
* stays byte-identical in the model.
|
|
68
|
+
*/
|
|
69
|
+
const dispatchChildren = ({ element, handlers, capturePosition, undeclared, undeclaredNamespaces }) => {
|
|
70
|
+
const children = [];
|
|
71
|
+
const capture = (child) => {
|
|
72
|
+
children.push({
|
|
73
|
+
index: capturePosition(child),
|
|
74
|
+
xml: captureVerbatimXml(child)
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
const declared = new Map(Object.entries(handlers));
|
|
78
|
+
const byName = new Map(Object.entries(undeclared ?? {}));
|
|
79
|
+
const byNamespace = new Map(Object.entries(undeclaredNamespaces ?? {}));
|
|
80
|
+
for (const child of getChildElements(element)) {
|
|
81
|
+
const localName = getLocalName(child.name);
|
|
82
|
+
const namespace = getNamespaceUri(child);
|
|
83
|
+
const disposition = namespace === void 0 || WORDPROCESSINGML_NAMESPACE_URIS.has(namespace) ? declared.get(localName) ?? byName.get(localName) : byName.get(localName) ?? byNamespace.get(transitionalNamespaceOf(namespace));
|
|
84
|
+
if (disposition === void 0 || disposition === "capture") {
|
|
85
|
+
capture(child);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (typeof disposition !== "function") continue;
|
|
89
|
+
if (disposition(child) === "capture") capture(child);
|
|
90
|
+
}
|
|
91
|
+
return children.length === 0 ? void 0 : { children };
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Put a container's modelled children back with its preserved ones between
|
|
95
|
+
* them, in source position.
|
|
96
|
+
*
|
|
97
|
+
* Where the content model demands schema order the caller has already put its
|
|
98
|
+
* modelled children in that order; the sink's `index` then places each capture
|
|
99
|
+
* between the same two siblings it sat between when it was read.
|
|
100
|
+
*
|
|
101
|
+
* @param wrap turns one capture's markup into whatever the caller's list holds
|
|
102
|
+
*/
|
|
103
|
+
const withPreservedChildren = (modelled, preserved, wrap) => {
|
|
104
|
+
const captures = preserved?.children;
|
|
105
|
+
if (captures === void 0 || captures.length === 0) return [...modelled];
|
|
106
|
+
const byIndex = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const child of captures) {
|
|
108
|
+
const { index, xml } = child;
|
|
109
|
+
const slot = Math.min(Math.max(index, 0), modelled.length);
|
|
110
|
+
const bucket = byIndex.get(slot);
|
|
111
|
+
if (bucket) {
|
|
112
|
+
bucket.push(wrap(xml, child));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
byIndex.set(slot, [wrap(xml, child)]);
|
|
116
|
+
}
|
|
117
|
+
const items = [];
|
|
118
|
+
for (const [index, item] of modelled.entries()) items.push(...byIndex.get(index) ?? [], item);
|
|
119
|
+
items.push(...byIndex.get(modelled.length) ?? []);
|
|
120
|
+
return items;
|
|
121
|
+
};
|
|
122
|
+
/** {@link withPreservedChildren} for a caller that already holds markup. */
|
|
123
|
+
const serializeWithPreservedChildren = (modelled, preserved) => withPreservedChildren(modelled, preserved, (xml) => xml).join("");
|
|
124
|
+
/**
|
|
125
|
+
* Where each child sits in a container whose content model is one flat sequence.
|
|
126
|
+
*
|
|
127
|
+
* A property set is that container: `CT_TblPr` and `CT_SectPr` are sequences
|
|
128
|
+
* of optional singletons, so a child's position is a property of its name and
|
|
129
|
+
* the generated list is the order. That is what the sink records for them,
|
|
130
|
+
* rather than a count of modelled siblings: the count is a mirror of whichever
|
|
131
|
+
* properties folio models today, and it moves under the capture the moment one
|
|
132
|
+
* more of them is modelled.
|
|
133
|
+
*
|
|
134
|
+
* An undeclared child — a foreign namespace, an `mc:` construct, a name a
|
|
135
|
+
* later revision of the format adds — has no place in the sequence, so it
|
|
136
|
+
* takes the place of the last declared child before it and comes back beside
|
|
137
|
+
* the same neighbour. One before every declared child takes position `-1`,
|
|
138
|
+
* ahead of the sequence's first slot.
|
|
139
|
+
*/
|
|
140
|
+
const sequencePositions = (container, element) => {
|
|
141
|
+
const declared = SEQUENCE_CHILDREN[container];
|
|
142
|
+
const positions = /* @__PURE__ */ new Map();
|
|
143
|
+
let previous = -1;
|
|
144
|
+
for (const child of getChildElements(element)) {
|
|
145
|
+
const namespace = getNamespaceUri(child);
|
|
146
|
+
const at = namespace === void 0 || WORDPROCESSINGML_NAMESPACE_URIS.has(namespace) ? declared.indexOf(getLocalName(child.name)) : -1;
|
|
147
|
+
if (at !== -1) previous = at;
|
|
148
|
+
positions.set(child, at === -1 ? previous : at);
|
|
149
|
+
}
|
|
150
|
+
return (child) => positions.get(child) ?? -1;
|
|
151
|
+
};
|
|
152
|
+
//#endregion
|
|
153
|
+
export { CAPTURE, DROPPED_WITH_ITS_WRAPPER, dispatchChildren, keptUnless, ownedElsewhere, ownedElsewhereClaims, sequencePositions, serializeWithPreservedChildren, transitionalNamespaceOf, withPreservedChildren };
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { XmlElement } from "./xmlParser.js";
|
|
3
3
|
//#region src/docx/diagramPreview.d.ts
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* How many `dsp:sp` a preview describes at most.
|
|
6
|
+
*
|
|
7
|
+
* The bound is on the description rather than on any picture built from it:
|
|
8
|
+
* the shapes are what a backend draws, and a drawing with ten thousand of them
|
|
9
|
+
* is a drawing folio summarises rather than reproduces.
|
|
10
|
+
*/
|
|
11
|
+
declare const MAX_PREVIEW_SHAPES = 128;
|
|
12
|
+
/**
|
|
13
|
+
* Describe a diagram drawing, without drawing it.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately simple and bounded; it is never an editable diagram projection.
|
|
16
|
+
*/
|
|
5
17
|
declare const parseDiagramPreview: (drawing: XmlElement, rels: document_d_exports.RelationshipMap | undefined, media: Map<string, document_d_exports.MediaFile> | undefined) => document_d_exports.Image | null;
|
|
6
18
|
//#endregion
|
|
7
|
-
export { parseDiagramPreview };
|
|
19
|
+
export { MAX_PREVIEW_SHAPES, parseDiagramPreview };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { bytesToDataUrl } from "../utils/base64.js";
|
|
2
|
-
import { PREVIEW_KINDS } from "./previewBudget.js";
|
|
3
1
|
import { resolveRelationshipIdOfType, resolveRelativePath } from "./relsParser.js";
|
|
4
2
|
import { OFFICE_RELATIONSHIP_NAMESPACE_URIS, findChildByNamespaceUri, getAttribute, getAttributeByNamespaceUri, getLocalName, parseNumericAttribute, parseXmlDocument } from "./xmlParser.js";
|
|
5
3
|
//#region src/docx/diagramPreview.ts
|
|
4
|
+
/**
|
|
5
|
+
* How many `dsp:sp` a preview describes at most.
|
|
6
|
+
*
|
|
7
|
+
* The bound is on the description rather than on any picture built from it:
|
|
8
|
+
* the shapes are what a backend draws, and a drawing with ten thousand of them
|
|
9
|
+
* is a drawing folio summarises rather than reproduces.
|
|
10
|
+
*/
|
|
6
11
|
const MAX_PREVIEW_SHAPES = 128;
|
|
7
|
-
const MAX_PREVIEW_PIXELS = 144e4;
|
|
8
|
-
const MAX_PREVIEW_PAINT_PIXELS = MAX_PREVIEW_PIXELS * 4;
|
|
9
12
|
const DRAWINGML_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/main", "http://purl.oclc.org/ooxml/drawingml/main"]);
|
|
10
13
|
const DIAGRAM_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/diagram", "http://purl.oclc.org/ooxml/drawingml/diagram"]);
|
|
11
14
|
const DIAGRAM_DRAWING_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.microsoft.com/office/drawing/2008/diagram"]);
|
|
@@ -13,140 +16,6 @@ const DIAGRAM_DATA_RELATIONSHIP_TYPE = "http://schemas.openxmlformats.org/office
|
|
|
13
16
|
const DIAGRAM_DRAWING_RELATIONSHIP_TYPE = "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing";
|
|
14
17
|
const DOCUMENT_PART_PATH = "word/document.xml";
|
|
15
18
|
const WORD_DRAWING_NAMESPACE_URIS = /* @__PURE__ */ new Set(["http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing"]);
|
|
16
|
-
/**
|
|
17
|
-
* The preview is a megapixel raster, so both checksums run over megabytes.
|
|
18
|
-
* `for (const byte of bytes)` drives the array iterator protocol once per
|
|
19
|
-
* byte, which profiles as the dominant cost of parsing a SmartArt document;
|
|
20
|
-
* indexed loops and a table-driven CRC produce the same numbers without it.
|
|
21
|
-
*/
|
|
22
|
-
const CRC32_TABLE = (() => {
|
|
23
|
-
const table = /* @__PURE__ */ new Uint32Array(256);
|
|
24
|
-
for (let index = 0; index < 256; index += 1) {
|
|
25
|
-
let value = index;
|
|
26
|
-
for (let bit = 0; bit < 8; bit += 1) value = value >>> 1 ^ (value & 1 ? 3988292384 : 0);
|
|
27
|
-
table[index] = value >>> 0;
|
|
28
|
-
}
|
|
29
|
-
return table;
|
|
30
|
-
})();
|
|
31
|
-
const crc32 = (bytes) => {
|
|
32
|
-
let crc = 4294967295;
|
|
33
|
-
for (let index = 0; index < bytes.length; index += 1) crc = crc >>> 8 ^ CRC32_TABLE[(crc ^ bytes[index]) & 255];
|
|
34
|
-
return (crc ^ 4294967295) >>> 0;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* `a` and `b` stay below 2^31 for 5552 iterations from any legal state, so the
|
|
38
|
-
* modulo runs per block rather than per byte.
|
|
39
|
-
*/
|
|
40
|
-
const ADLER32_BLOCK = 5552;
|
|
41
|
-
const adler32 = (bytes) => {
|
|
42
|
-
let a = 1;
|
|
43
|
-
let b = 0;
|
|
44
|
-
let index = 0;
|
|
45
|
-
while (index < bytes.length) {
|
|
46
|
-
const end = Math.min(index + ADLER32_BLOCK, bytes.length);
|
|
47
|
-
for (; index < end; index += 1) {
|
|
48
|
-
a += bytes[index];
|
|
49
|
-
b += a;
|
|
50
|
-
}
|
|
51
|
-
a %= 65521;
|
|
52
|
-
b %= 65521;
|
|
53
|
-
}
|
|
54
|
-
return b << 16 | a;
|
|
55
|
-
};
|
|
56
|
-
const pngChunk = (type, data) => {
|
|
57
|
-
const name = new TextEncoder().encode(type);
|
|
58
|
-
const output = new Uint8Array(12 + data.length);
|
|
59
|
-
const view = new DataView(output.buffer);
|
|
60
|
-
view.setUint32(0, data.length);
|
|
61
|
-
output.set(name, 4);
|
|
62
|
-
output.set(data, 8);
|
|
63
|
-
view.setUint32(8 + data.length, crc32(output.subarray(4, 8 + data.length)));
|
|
64
|
-
return output;
|
|
65
|
-
};
|
|
66
|
-
const previewPng = (width, height, shapes) => {
|
|
67
|
-
const scale = Math.min(1, Math.sqrt(MAX_PREVIEW_PIXELS / (width * height)));
|
|
68
|
-
const w = Math.max(1, Math.round(width * scale));
|
|
69
|
-
const h = Math.max(1, Math.round(height * scale));
|
|
70
|
-
const pixels = new Uint8Array((w * 4 + 1) * h);
|
|
71
|
-
for (let y = 0; y < h; y += 1) {
|
|
72
|
-
const row = y * (w * 4 + 1);
|
|
73
|
-
pixels[row] = 0;
|
|
74
|
-
for (let x = 0; x < w; x += 1) {
|
|
75
|
-
const index = row + 1 + x * 4;
|
|
76
|
-
pixels[index] = 238;
|
|
77
|
-
pixels[index + 1] = 242;
|
|
78
|
-
pixels[index + 2] = 247;
|
|
79
|
-
pixels[index + 3] = 255;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
let paintedPixels = 0;
|
|
83
|
-
for (const shape of shapes) {
|
|
84
|
-
const sx = Math.max(0, Math.round(shape.x / width * w));
|
|
85
|
-
const sy = Math.max(0, Math.round(shape.y / height * h));
|
|
86
|
-
const ex = Math.min(w, Math.round((shape.x + shape.width) / width * w));
|
|
87
|
-
const ey = Math.min(h, Math.round((shape.y + shape.height) / height * h));
|
|
88
|
-
const red = Number.parseInt(shape.color.slice(0, 2), 16) || 232;
|
|
89
|
-
const green = Number.parseInt(shape.color.slice(2, 4), 16) || 238;
|
|
90
|
-
const blue = Number.parseInt(shape.color.slice(4, 6), 16) || 247;
|
|
91
|
-
const shapePixels = Math.max(0, ex - sx) * Math.max(0, ey - sy);
|
|
92
|
-
if (paintedPixels + shapePixels > MAX_PREVIEW_PAINT_PIXELS) break;
|
|
93
|
-
paintedPixels += shapePixels;
|
|
94
|
-
for (let y = sy; y < ey; y += 1) {
|
|
95
|
-
const row = y * (w * 4 + 1);
|
|
96
|
-
for (let x = sx; x < ex; x += 1) {
|
|
97
|
-
const index = row + 1 + x * 4;
|
|
98
|
-
pixels[index] = red;
|
|
99
|
-
pixels[index + 1] = green;
|
|
100
|
-
pixels[index + 2] = blue;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const compressed = new Uint8Array(2 + pixels.length + Math.ceil(pixels.length / 65535) * 5 + 4);
|
|
105
|
-
compressed[0] = 120;
|
|
106
|
-
compressed[1] = 1;
|
|
107
|
-
let cursor = 2;
|
|
108
|
-
for (let offset = 0; offset < pixels.length;) {
|
|
109
|
-
const length = Math.min(65535, pixels.length - offset);
|
|
110
|
-
compressed[cursor++] = offset + length === pixels.length ? 1 : 0;
|
|
111
|
-
compressed[cursor++] = length & 255;
|
|
112
|
-
compressed[cursor++] = length >>> 8;
|
|
113
|
-
compressed[cursor++] = ~length & 255;
|
|
114
|
-
compressed[cursor++] = ~length >>> 8 & 255;
|
|
115
|
-
compressed.set(pixels.subarray(offset, offset + length), cursor);
|
|
116
|
-
cursor += length;
|
|
117
|
-
offset += length;
|
|
118
|
-
}
|
|
119
|
-
new DataView(compressed.buffer).setUint32(cursor, adler32(pixels));
|
|
120
|
-
const output = compressed;
|
|
121
|
-
const signature = new Uint8Array([
|
|
122
|
-
137,
|
|
123
|
-
80,
|
|
124
|
-
78,
|
|
125
|
-
71,
|
|
126
|
-
13,
|
|
127
|
-
10,
|
|
128
|
-
26,
|
|
129
|
-
10
|
|
130
|
-
]);
|
|
131
|
-
const header = /* @__PURE__ */ new Uint8Array(13);
|
|
132
|
-
new DataView(header.buffer).setUint32(0, w);
|
|
133
|
-
new DataView(header.buffer).setUint32(4, h);
|
|
134
|
-
header[8] = 8;
|
|
135
|
-
header[9] = 6;
|
|
136
|
-
const chunks = [
|
|
137
|
-
signature,
|
|
138
|
-
pngChunk("IHDR", header),
|
|
139
|
-
pngChunk("IDAT", output),
|
|
140
|
-
pngChunk("IEND", /* @__PURE__ */ new Uint8Array())
|
|
141
|
-
];
|
|
142
|
-
const png = new Uint8Array(chunks.reduce((total, chunk) => total + chunk.length, 0));
|
|
143
|
-
let position = 0;
|
|
144
|
-
for (const chunk of chunks) {
|
|
145
|
-
png.set(chunk, position);
|
|
146
|
-
position += chunk.length;
|
|
147
|
-
}
|
|
148
|
-
return png;
|
|
149
|
-
};
|
|
150
19
|
const extent = (drawing) => {
|
|
151
20
|
const value = findChildByNamespaceUri(findChildByNamespaceUri(drawing, WORD_DRAWING_NAMESPACE_URIS, "inline") ?? findChildByNamespaceUri(drawing, WORD_DRAWING_NAMESPACE_URIS, "anchor"), WORD_DRAWING_NAMESPACE_URIS, "extent");
|
|
152
21
|
return {
|
|
@@ -155,11 +24,47 @@ const extent = (drawing) => {
|
|
|
155
24
|
};
|
|
156
25
|
};
|
|
157
26
|
/** Parse the part a relationship of the given type names, by that relationship's id. */
|
|
158
|
-
const partByRelationshipId = ({ rels, media, rId, type }) => {
|
|
27
|
+
const partByRelationshipId = ({ rels, media, rId, type, cache }) => {
|
|
159
28
|
const resolved = resolveRelationshipIdOfType(rels, rId ?? void 0, type);
|
|
160
29
|
if (resolved.status !== "resolved" || !resolved.relationship.target) return null;
|
|
161
|
-
const
|
|
162
|
-
|
|
30
|
+
const path = resolveRelativePath(DOCUMENT_PART_PATH, resolved.relationship.target);
|
|
31
|
+
const cached = cache.get(path);
|
|
32
|
+
if (cached !== void 0) return cached;
|
|
33
|
+
const file = media.get(path);
|
|
34
|
+
const parsed = file?.data ? parseXmlDocument(new TextDecoder().decode(file.data)) : null;
|
|
35
|
+
cache.set(path, parsed);
|
|
36
|
+
return parsed;
|
|
37
|
+
};
|
|
38
|
+
const matchesNamespace = (element, namespaceUris, localName) => element.namespaceUri !== void 0 && namespaceUris.has(element.namespaceUri) && getLocalName(element.name ?? "") === localName;
|
|
39
|
+
/**
|
|
40
|
+
* Descendants in document order, stopping once `limit` of them are found.
|
|
41
|
+
*
|
|
42
|
+
* The walk used to collect every match and slice afterwards, so a drawing with
|
|
43
|
+
* ten thousand shapes built a ten-thousand-element array to keep a hundred and
|
|
44
|
+
* twenty-eight of them. The bound belongs in the walk, not after it.
|
|
45
|
+
*/
|
|
46
|
+
const descendantsByNamespace = (root, namespaceUris, localName, limit) => {
|
|
47
|
+
const result = [];
|
|
48
|
+
const visit = (element) => {
|
|
49
|
+
if (matchesNamespace(element, namespaceUris, localName)) {
|
|
50
|
+
result.push(element);
|
|
51
|
+
return result.length < limit;
|
|
52
|
+
}
|
|
53
|
+
for (const child of element.elements ?? []) if (child.type === "element" && !visit(child)) return false;
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
56
|
+
visit(root);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
/** The first match in document order, without walking the rest of the subtree. */
|
|
60
|
+
const firstDescendantByNamespace = (root, namespaceUris, localName) => {
|
|
61
|
+
if (matchesNamespace(root, namespaceUris, localName)) return root;
|
|
62
|
+
for (const child of root.elements ?? []) {
|
|
63
|
+
if (child.type !== "element") continue;
|
|
64
|
+
const found = firstDescendantByNamespace(child, namespaceUris, localName);
|
|
65
|
+
if (found) return found;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
163
68
|
};
|
|
164
69
|
/**
|
|
165
70
|
* The drawing cache this diagram points at, reached through its own ids.
|
|
@@ -170,25 +75,27 @@ const partByRelationshipId = ({ rels, media, rId, type }) => {
|
|
|
170
75
|
* more than one, which is why the scan refused outright on a second match:
|
|
171
76
|
* both diagrams in a two-diagram document then got no preview at all.
|
|
172
77
|
*/
|
|
173
|
-
const cachedDiagramShapes = (graphicData, rels, media) => {
|
|
78
|
+
const cachedDiagramShapes = (graphicData, rels, media, cache) => {
|
|
174
79
|
const relIds = findChildByNamespaceUri(graphicData, DIAGRAM_NAMESPACE_URIS, "relIds");
|
|
175
80
|
const data = partByRelationshipId({
|
|
176
81
|
rels,
|
|
177
82
|
media,
|
|
83
|
+
cache,
|
|
178
84
|
rId: getAttributeByNamespaceUri(relIds, OFFICE_RELATIONSHIP_NAMESPACE_URIS, "dm"),
|
|
179
85
|
type: DIAGRAM_DATA_RELATIONSHIP_TYPE
|
|
180
86
|
});
|
|
181
87
|
if (!data) return [];
|
|
182
|
-
const dataModelExt =
|
|
88
|
+
const dataModelExt = firstDescendantByNamespace(data, DIAGRAM_DRAWING_NAMESPACE_URIS, "dataModelExt");
|
|
183
89
|
const root = partByRelationshipId({
|
|
184
90
|
rels,
|
|
185
91
|
media,
|
|
92
|
+
cache,
|
|
186
93
|
rId: getAttribute(dataModelExt, null, "relId"),
|
|
187
94
|
type: DIAGRAM_DRAWING_RELATIONSHIP_TYPE
|
|
188
95
|
});
|
|
189
96
|
if (!root) return [];
|
|
190
97
|
const shapes = [];
|
|
191
|
-
for (const shape of descendantsByNamespace(root, DIAGRAM_DRAWING_NAMESPACE_URIS, "sp"
|
|
98
|
+
for (const shape of descendantsByNamespace(root, DIAGRAM_DRAWING_NAMESPACE_URIS, "sp", 128)) {
|
|
192
99
|
const properties = findChildByNamespaceUri(shape, DIAGRAM_DRAWING_NAMESPACE_URIS, "spPr");
|
|
193
100
|
const transform = findChildByNamespaceUri(properties, DRAWINGML_NAMESPACE_URIS, "xfrm");
|
|
194
101
|
const offset = findChildByNamespaceUri(transform, DRAWINGML_NAMESPACE_URIS, "off");
|
|
@@ -207,27 +114,28 @@ const cachedDiagramShapes = (graphicData, rels, media) => {
|
|
|
207
114
|
}
|
|
208
115
|
return shapes;
|
|
209
116
|
};
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (found) return found;
|
|
227
|
-
}
|
|
228
|
-
return null;
|
|
117
|
+
/**
|
|
118
|
+
* The part cache, keyed by the package's own media map.
|
|
119
|
+
*
|
|
120
|
+
* The cache has to be per package: a global one would answer one document's
|
|
121
|
+
* `word/diagrams/data1.xml` with another's. Keying it on the media map gets
|
|
122
|
+
* that lifetime for free and without threading a reader through every drawing
|
|
123
|
+
* call site, and a weak key means the cache dies with the package rather than
|
|
124
|
+
* retaining its parts.
|
|
125
|
+
*/
|
|
126
|
+
const PART_CACHES = /* @__PURE__ */ new WeakMap();
|
|
127
|
+
const partCacheFor = (media) => {
|
|
128
|
+
const existing = PART_CACHES.get(media);
|
|
129
|
+
if (existing) return existing;
|
|
130
|
+
const created = /* @__PURE__ */ new Map();
|
|
131
|
+
PART_CACHES.set(media, created);
|
|
132
|
+
return created;
|
|
229
133
|
};
|
|
230
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* Describe a diagram drawing, without drawing it.
|
|
136
|
+
*
|
|
137
|
+
* Deliberately simple and bounded; it is never an editable diagram projection.
|
|
138
|
+
*/
|
|
231
139
|
const parseDiagramPreview = (drawing, rels, media) => {
|
|
232
140
|
if (!rels || !media) return null;
|
|
233
141
|
const graphicData = firstDescendantByNamespace(drawing, DRAWINGML_NAMESPACE_URIS, "graphicData");
|
|
@@ -236,10 +144,14 @@ const parseDiagramPreview = (drawing, rels, media) => {
|
|
|
236
144
|
if (width <= 0 || height <= 0) return null;
|
|
237
145
|
return {
|
|
238
146
|
type: "image",
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
147
|
+
preview: {
|
|
148
|
+
kind: "diagram",
|
|
149
|
+
extent: {
|
|
150
|
+
width,
|
|
151
|
+
height
|
|
152
|
+
},
|
|
153
|
+
shapes: cachedDiagramShapes(graphicData, rels, media, partCacheFor(media))
|
|
154
|
+
},
|
|
243
155
|
size: {
|
|
244
156
|
width,
|
|
245
157
|
height
|
|
@@ -248,4 +160,4 @@ const parseDiagramPreview = (drawing, rels, media) => {
|
|
|
248
160
|
};
|
|
249
161
|
};
|
|
250
162
|
//#endregion
|
|
251
|
-
export { parseDiagramPreview };
|
|
163
|
+
export { MAX_PREVIEW_SHAPES, parseDiagramPreview };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { NumberingMap } from "./numberingParser.js";
|
|
3
|
-
import { StyleMap } from "./styleParser.js";
|
|
4
3
|
import { ParseContext } from "./parseContext.js";
|
|
4
|
+
import { StyleMap } from "./styleParser.js";
|
|
5
5
|
//#region src/docx/documentParser.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Extract template variables from text
|
|
@@ -49,7 +49,7 @@ function extractTableVariables(table) {
|
|
|
49
49
|
for (const row of table.rows) for (const cell of row.cells) for (const cellContent of cell.content) if (cellContent.type === "paragraph") {
|
|
50
50
|
const vars = extractTemplateVariables(getParagraphText(cellContent));
|
|
51
51
|
for (const v of vars) if (!variables.includes(v)) variables.push(v);
|
|
52
|
-
} else {
|
|
52
|
+
} else if (cellContent.type === "table") {
|
|
53
53
|
const nestedVars = extractTableVariables(cellContent);
|
|
54
54
|
for (const v of nestedVars) if (!variables.includes(v)) variables.push(v);
|
|
55
55
|
}
|
|
@@ -127,7 +127,10 @@ function parseDocumentBody(xml, styles = null, theme = null, numbering = null, r
|
|
|
127
127
|
if (!documentEl) return result;
|
|
128
128
|
const bodyEl = findChild(documentEl, "w", "body");
|
|
129
129
|
if (!bodyEl) return result;
|
|
130
|
-
result.content = parseBlockContent(bodyEl, styles, theme, numbering, rels, media, {
|
|
130
|
+
result.content = parseBlockContent(bodyEl, styles, theme, numbering, rels, media, {
|
|
131
|
+
rootXmlns: collectXmlnsDeclarations(documentEl),
|
|
132
|
+
context
|
|
133
|
+
});
|
|
131
134
|
const finalSectPr = findChild(bodyEl, "w", "sectPr");
|
|
132
135
|
if (finalSectPr) result.finalSectionProperties = parseSectionProperties(finalSectPr, context);
|
|
133
136
|
canonicalizeLeadingBodySectionProperties(bodyEl, result);
|
|
@@ -149,7 +152,7 @@ function getAllParagraphs(body) {
|
|
|
149
152
|
function getTableParagraphs(table) {
|
|
150
153
|
const paragraphs = [];
|
|
151
154
|
for (const row of table.rows) for (const cell of row.cells) for (const content of cell.content) if (content.type === "paragraph") paragraphs.push(content);
|
|
152
|
-
else paragraphs.push(...getTableParagraphs(content));
|
|
155
|
+
else if (content.type === "table") paragraphs.push(...getTableParagraphs(content));
|
|
153
156
|
return paragraphs;
|
|
154
157
|
}
|
|
155
158
|
/**
|
|
@@ -193,7 +196,7 @@ function getTableText(table) {
|
|
|
193
196
|
for (const cell of row.cells) {
|
|
194
197
|
const cellTexts = [];
|
|
195
198
|
for (const content of cell.content) if (content.type === "paragraph") cellTexts.push(getParagraphText(content));
|
|
196
|
-
else cellTexts.push(getTableText(content));
|
|
199
|
+
else if (content.type === "table") cellTexts.push(getTableText(content));
|
|
197
200
|
rowTexts.push(cellTexts.join("\n"));
|
|
198
201
|
}
|
|
199
202
|
lines.push(rowTexts.join(" "));
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { XmlElement } from "./xmlParser.js";
|
|
3
|
+
//#region src/docx/drawingAnchor.d.ts
|
|
4
|
+
/** WordprocessingDrawing, Transitional and Strict (ECMA-376 Parts 1 and 4). */
|
|
5
|
+
declare const WORDPROCESSING_DRAWING_NAMESPACE_URIS: ReadonlySet<string>;
|
|
6
|
+
/** The anchor fields that are a single `ST_OnOff`-style attribute. */
|
|
7
|
+
type DrawingAnchorFlag = { [Key in keyof document_d_exports.DrawingAnchor]-?: NonNullable<document_d_exports.DrawingAnchor[Key]> extends boolean ? Key : never; }[keyof document_d_exports.DrawingAnchor];
|
|
8
|
+
/** Every boolean the anchor models, from the total map above. */
|
|
9
|
+
declare const DRAWING_ANCHOR_FLAG_KEYS: DrawingAnchorFlag[];
|
|
10
|
+
/**
|
|
11
|
+
* Read `CT_Anchor`'s own attributes and its `wp:simplePos` offsets.
|
|
12
|
+
*
|
|
13
|
+
* Undefined when the element states none of them: an anchor whose every
|
|
14
|
+
* attribute is the spec default holds nothing the model needs to remember, and
|
|
15
|
+
* recording an empty record would make a rebuild write values the source did
|
|
16
|
+
* not.
|
|
17
|
+
*/
|
|
18
|
+
declare const parseDrawingAnchor: (anchorEl: XmlElement) => document_d_exports.DrawingAnchor | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The insets to write on each of the two elements that can carry them.
|
|
21
|
+
*
|
|
22
|
+
* A drawing whose slots say where its insets were authored gets each one back
|
|
23
|
+
* on that element, which is the only way the wrap child's own set survives a
|
|
24
|
+
* rebuild. A drawing with no slots, or one an editor command has moved an inset
|
|
25
|
+
* on, states the value in force on the drawing: that is where OOXML reads an
|
|
26
|
+
* inset from when the wrap child states none, so the effective value is right
|
|
27
|
+
* either way, and inventing a wrap-child inset from a moved value would not be.
|
|
28
|
+
*/
|
|
29
|
+
declare const resolveWrapDistances: (wrap: document_d_exports.ImageWrap | undefined) => {
|
|
30
|
+
drawing: document_d_exports.WrapDistances;
|
|
31
|
+
wrapChild: document_d_exports.WrapDistances;
|
|
32
|
+
};
|
|
33
|
+
type ResolvedEffectExtents = {
|
|
34
|
+
/** `wp:inline` or `wp:anchor`; undefined writes the all-zero reservation. */
|
|
35
|
+
drawing: document_d_exports.ImagePadding | undefined;
|
|
36
|
+
/** `wp:wrapSquare` or `wp:wrapTopAndBottom`, which write nothing when undefined. */
|
|
37
|
+
wrapChild: document_d_exports.ImagePadding | undefined;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The `wp:effectExtent` to write on each of the two elements that carry one.
|
|
41
|
+
*
|
|
42
|
+
* {@link resolveWrapDistances}'s rule, one element over: a drawing whose slots
|
|
43
|
+
* say where the reservations were authored gets each one back on that element,
|
|
44
|
+
* which is the only way the wrap child's own survives a rebuild. Once the
|
|
45
|
+
* drawing's reservation has been resized the two no longer describe the same
|
|
46
|
+
* object, so the rebuild states the value in force on the drawing and lets
|
|
47
|
+
* OOXML's own default apply to the wrap — keeping a wrap reservation computed
|
|
48
|
+
* against the old size would flow text around a shape that is no longer there.
|
|
49
|
+
*
|
|
50
|
+
* `effective` is the reservation the model holds for the drawing itself:
|
|
51
|
+
* `Image.padding`. A shape and a text box have no such field — the rebuild has
|
|
52
|
+
* always written zeros — so they pass the drawing slot back and nothing can
|
|
53
|
+
* have moved a value the model cannot hold.
|
|
54
|
+
*/
|
|
55
|
+
declare const resolveEffectExtents: (wrap: document_d_exports.ImageWrap | undefined, effective: document_d_exports.ImagePadding | undefined) => ResolvedEffectExtents;
|
|
56
|
+
/** `wp:effectExtent`, whose four sides `CT_EffectExtent` all requires. */
|
|
57
|
+
declare const serializeEffectExtent: (extent: document_d_exports.ImagePadding | undefined) => string;
|
|
58
|
+
/** The inset attributes an element states, in schema order, or nothing. */
|
|
59
|
+
declare const serializeWrapDistances: (distances: document_d_exports.WrapDistances) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Only the wrap insets `wp:inline` or `wp:anchor` itself carries. OOXML
|
|
62
|
+
* defaults an omitted one to zero, so writing all four would put a value on
|
|
63
|
+
* every drawing that never had one.
|
|
64
|
+
*/
|
|
65
|
+
declare const serializeWrapDistanceAttributes: (wrap: document_d_exports.ImageWrap | undefined) => string;
|
|
66
|
+
/** `wp:inline` carries the wrap insets and nothing else of `CT_Anchor`'s set. */
|
|
67
|
+
declare const serializeInlineAttributes: (wrap: document_d_exports.ImageWrap | undefined) => string;
|
|
68
|
+
type AnchorAttributesOptions = {
|
|
69
|
+
anchor: document_d_exports.DrawingAnchor | undefined;
|
|
70
|
+
wrap: document_d_exports.ImageWrap | undefined;
|
|
71
|
+
/** `@behindDoc`, which the wrap type decides rather than the anchor record. */
|
|
72
|
+
behindDoc: boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Every attribute `CT_Anchor` declares of its own, in schema order.
|
|
76
|
+
*
|
|
77
|
+
* The walk is over {@link DRAWING_ANCHOR_FLAG_KEYS} rather than a hand-written list, so
|
|
78
|
+
* a flag added to the model cannot be written by the parser and forgotten here.
|
|
79
|
+
*/
|
|
80
|
+
declare const serializeAnchorAttributes: ({ anchor, wrap, behindDoc }: AnchorAttributesOptions) => string;
|
|
81
|
+
/**
|
|
82
|
+
* `wp:simplePos`, which `CT_Anchor` requires whether or not `@simplePos` says to
|
|
83
|
+
* use it, so an anchor that authored no offsets still writes the origin.
|
|
84
|
+
*/
|
|
85
|
+
declare const serializeSimplePos: (anchor: document_d_exports.DrawingAnchor | undefined) => string;
|
|
86
|
+
//#endregion
|
|
87
|
+
export { AnchorAttributesOptions, DRAWING_ANCHOR_FLAG_KEYS, ResolvedEffectExtents, WORDPROCESSING_DRAWING_NAMESPACE_URIS, parseDrawingAnchor, resolveEffectExtents, resolveWrapDistances, serializeAnchorAttributes, serializeEffectExtent, serializeInlineAttributes, serializeSimplePos, serializeWrapDistanceAttributes, serializeWrapDistances };
|