@harbour-enterprises/superdoc 2.0.0-next.2 → 2.0.0-next.21

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.
Files changed (34) hide show
  1. package/dist/chunks/{PdfViewer-CWO98Qls.cjs → PdfViewer-B4os0dhm.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-C4xgIIbF.es.js → PdfViewer-CvJZenVo.es.js} +1 -1
  3. package/dist/chunks/{index-BqPa6D4q-Dulj8zfc.cjs → index--w_Fk0WX-Bd420t19.cjs} +1 -1
  4. package/dist/chunks/{index-BqPa6D4q-8U4x8RP6.es.js → index--w_Fk0WX-D_kNY98j.es.js} +1 -1
  5. package/dist/chunks/{index-BY-3Vl72.cjs → index-BaspZNUO.cjs} +4 -6
  6. package/dist/chunks/{index-s9GUR_Gc.es.js → index-bocgaXi5.es.js} +4 -6
  7. package/dist/chunks/{super-editor.es-CT28vUbx.es.js → super-editor.es-CHiYj0m5.es.js} +1050 -245
  8. package/dist/chunks/{super-editor.es-BM-ulSRj.cjs → super-editor.es-KouCN1a9.cjs} +1050 -245
  9. package/dist/packages/superdoc/src/core/SuperDoc.d.ts +3 -3
  10. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  11. package/dist/packages/superdoc/src/core/types/index.d.ts +173 -0
  12. package/dist/packages/superdoc/src/core/types/index.d.ts.map +1 -1
  13. package/dist/packages/superdoc/src/stores/comments-store.d.ts.map +1 -1
  14. package/dist/style.css +14 -6
  15. package/dist/super-editor/ai-writer.es.js +2 -2
  16. package/dist/super-editor/chunks/{converter-CDlAWcRu.js → converter-De_h0rq-.js} +49 -9
  17. package/dist/super-editor/chunks/{docx-zipper-B2VXuf8h.js → docx-zipper-CKQFze2s.js} +1 -1
  18. package/dist/super-editor/chunks/{editor-B4Q_tNET.js → editor-BJljVUQD.js} +994 -239
  19. package/dist/super-editor/chunks/{index-BqPa6D4q.js → index--w_Fk0WX.js} +1 -1
  20. package/dist/super-editor/chunks/{toolbar-BD-lDCLr.js → toolbar-Br3J_GSc.js} +2 -2
  21. package/dist/super-editor/converter.es.js +1 -1
  22. package/dist/super-editor/docx-zipper.es.js +2 -2
  23. package/dist/super-editor/editor.es.js +3 -3
  24. package/dist/super-editor/file-zipper.es.js +1 -1
  25. package/dist/super-editor/style.css +14 -6
  26. package/dist/super-editor/super-editor.es.js +19 -9
  27. package/dist/super-editor/toolbar.es.js +2 -2
  28. package/dist/super-editor.cjs +1 -1
  29. package/dist/super-editor.es.js +1 -1
  30. package/dist/superdoc.cjs +2 -2
  31. package/dist/superdoc.es.js +2 -2
  32. package/dist/superdoc.umd.js +1053 -250
  33. package/dist/superdoc.umd.js.map +1 -1
  34. package/package.json +1 -1
@@ -9,11 +9,11 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
- var _a, _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, dispatchWithFallback_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, getPluginKeyName_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _currentEpoch, _mapsByFromEpoch, _maxEpochsToKeep, _EpochPositionMapper_instances, pruneByCurrentEpoch_fn, _entries, _windowRoot, _getPainterHost, _onRebuild, _observer, _rebuildScheduled, _rebuildRafId, _docEpoch, _layoutEpoch, _layoutUpdating, _pending, _scheduled, _rafHandle, _scheduler, _SelectionSyncCoordinator_instances, isSafeToRender_fn, maybeSchedule_fn, cancelScheduledRender_fn, _windowRoot2, _layoutSurfaces, _getTargetDom, _isEditable, _onTargetChanged, _listeners, _currentTarget, _destroyed, _useWindowFallback, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, shouldSkipSurface_fn, isInLayoutSurface_fn, getListenerTargets_fn, isPlainCharacterKey_fn, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _selectionOverlay, _activeEditorHost, _activeDecorationContainer, _activeRegion, _borderLine, _dimmingOverlay, _EditorOverlayManager_instances, findDecorationContainer_fn, ensureEditorHost_fn, positionEditorHost_fn, hideDimmingOverlay_fn, showHeaderFooterBorder_fn, hideHeaderFooterBorder_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay2, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _pageGeometryHelper, _dragHandlerCleanup, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionSync, _remoteCursorUpdateScheduled, _epochMapper, _layoutEpoch2, _domPositionIndex, _domIndexObserverManager, _debugLastPointer, _debugLastHit, _pendingMarginClick, _rafHandle2, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _multiSectionIdentifier, _headerLayoutResults, _footerLayoutResults, _headerLayoutsByRId, _footerLayoutsByRId, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _overlayManager, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _a11ySelectionAnnounceTimeout, _a11yLastAnnouncedSelectionKey, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _dragAnchor, _dragAnchorPageIndex, _isDragging, _dragExtensionMode, _dragLastPointer, _dragLastRawHit, _dragUsedPageNotMountedFallback, _cellAnchor, _cellDragMode, _remoteCursorState, _remoteCursorElements, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _scrollTimeout, _lastRemoteCursorRenderTime, _remoteCursorThrottleTimeout, _PresentationEditor_instances, wrapHiddenEditorFocus_fn, collectCommentPositions_fn, updateSelectionDebugHud_fn, computePendingMarginClick_fn, aggregateLayoutBounds_fn, rebuildDomPositionIndex_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, updateLocalAwarenessCursor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, setupPointerHandlers_fn, setupDragHandlers_fn, focusEditorAfterImageSelection_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, getCellPosFromTableHit_fn, getTablePosFromHit_fn, shouldUseCellSelection_fn, setCellAnchor_fn, clearCellAnchor_fn, hitTestTable_fn, selectWordAt_fn, selectParagraphAt_fn, calculateExtendedSelection_fn, _handlePointerMove, _handlePointerLeave, _handleVisibleHostFocusIn, _handlePointerUp, _handleDragOver, _handleDrop, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, layoutPerRIdHeaderFooters_fn, updateDecorationProviders_fn, createDecorationProvider_fn, findHeaderFooterPageForPageNumber_fn, computeDecorationBox_fn, computeExpectedSectionType_fn, rebuildHeaderFooterRegions_fn, hitTestHeaderFooterRegion_fn, pointInRegion_fn, activateHeaderFooterRegion_fn, enterHeaderFooterMode_fn, exitHeaderFooterMode_fn, getActiveDomTarget_fn, emitHeaderFooterModeChanged_fn, emitHeaderFooterEditingContext_fn, updateAwarenessSession_fn, updateModeBanner_fn, announce_fn, syncHiddenEditorA11yAttributes_fn, scheduleA11ySelectionAnnouncement_fn, announceSelectionNow_fn, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, createDefaultHeaderFooter_fn, getPageElement_fn, isSelectionAwareVirtualizationEnabled_fn, updateSelectionVirtualizationPins_fn, finalizeDragSelectionWithDom_fn, scrollPageIntoView_fn, waitForPageMount_fn, getEffectivePageGap_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderCellSelectionOverlay_fn, renderHoverRegion_fn, clearHoverRegion_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, applyZoom_fn, getPageOffsetX_fn, convertPageLocalToOverlayCoords_fn, computeSelectionRectsFromDom_fn, computeDomCaretPageLocal_fn, normalizeClientPoint_fn, computeCaretLayoutRectGeometry_fn, computeCaretLayoutRect_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, checkShouldUpdate_fn, updateHTMLAttributes_fn, updateDOMStyles_fn, resolveNeighborParagraphProperties_fn, updateListStyles_fn, initList_fn, checkIsList_fn, createMarker_fn, createSeparator_fn, calculateTabSeparatorStyle_fn, calculateMarkerStyle_fn, removeList_fn, getParagraphContext_fn, scheduleAnimation_fn, cancelScheduledAnimation_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn, _VectorShapeView_instances, ensureParentPositioned_fn, _ShapeGroupView_instances, ensureParentPositioned_fn2;
12
+ var _a, _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, dispatchWithFallback_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, getPluginKeyName_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _currentEpoch, _mapsByFromEpoch, _maxEpochsToKeep, _EpochPositionMapper_instances, pruneByCurrentEpoch_fn, _entries, _windowRoot, _getPainterHost, _onRebuild, _observer, _rebuildScheduled, _rebuildRafId, _docEpoch, _layoutEpoch, _layoutUpdating, _pending, _scheduled, _rafHandle, _scheduler, _SelectionSyncCoordinator_instances, isSafeToRender_fn, maybeSchedule_fn, cancelScheduledRender_fn, _windowRoot2, _layoutSurfaces, _getTargetDom, _isEditable, _onTargetChanged, _listeners, _currentTarget, _destroyed, _useWindowFallback, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, shouldSkipSurface_fn, isInLayoutSurface_fn, getListenerTargets_fn, isPlainCharacterKey_fn, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _selectionOverlay, _activeEditorHost, _activeDecorationContainer, _activeRegion, _borderLine, _dimmingOverlay, _EditorOverlayManager_instances, findDecorationContainer_fn, ensureEditorHost_fn, positionEditorHost_fn, hideDimmingOverlay_fn, showHeaderFooterBorder_fn, hideHeaderFooterBorder_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay2, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _pageGeometryHelper, _dragHandlerCleanup, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionSync, _remoteCursorUpdateScheduled, _epochMapper, _layoutEpoch2, _domPositionIndex, _domIndexObserverManager, _debugLastPointer, _debugLastHit, _pendingMarginClick, _rafHandle2, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _multiSectionIdentifier, _headerLayoutResults, _footerLayoutResults, _headerLayoutsByRId, _footerLayoutsByRId, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _overlayManager, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _a11ySelectionAnnounceTimeout, _a11yLastAnnouncedSelectionKey, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _dragAnchor, _dragAnchorPageIndex, _isDragging, _dragExtensionMode, _dragLastPointer, _dragLastRawHit, _dragUsedPageNotMountedFallback, _cellAnchor, _cellDragMode, _remoteCursorState, _remoteCursorElements, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _scrollTimeout, _lastRemoteCursorRenderTime, _remoteCursorThrottleTimeout, _PresentationEditor_instances, wrapHiddenEditorFocus_fn, syncDocumentModeClass_fn, collectCommentPositions_fn, updateSelectionDebugHud_fn, computePendingMarginClick_fn, aggregateLayoutBounds_fn, rebuildDomPositionIndex_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, updateLocalAwarenessCursor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, setupPointerHandlers_fn, setupDragHandlers_fn, focusEditorAfterImageSelection_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, getCellPosFromTableHit_fn, getTablePosFromHit_fn, shouldUseCellSelection_fn, setCellAnchor_fn, clearCellAnchor_fn, hitTestTable_fn, selectWordAt_fn, selectParagraphAt_fn, calculateExtendedSelection_fn, _handlePointerMove, _handlePointerLeave, _handleVisibleHostFocusIn, _handlePointerUp, _handleDragOver, _handleDrop, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, layoutPerRIdHeaderFooters_fn, updateDecorationProviders_fn, createDecorationProvider_fn, findHeaderFooterPageForPageNumber_fn, computeDecorationBox_fn, computeExpectedSectionType_fn, rebuildHeaderFooterRegions_fn, hitTestHeaderFooterRegion_fn, pointInRegion_fn, activateHeaderFooterRegion_fn, enterHeaderFooterMode_fn, exitHeaderFooterMode_fn, getActiveDomTarget_fn, emitHeaderFooterModeChanged_fn, emitHeaderFooterEditingContext_fn, updateAwarenessSession_fn, updateModeBanner_fn, announce_fn, syncHiddenEditorA11yAttributes_fn, scheduleA11ySelectionAnnouncement_fn, announceSelectionNow_fn, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, createDefaultHeaderFooter_fn, getPageElement_fn, isSelectionAwareVirtualizationEnabled_fn, updateSelectionVirtualizationPins_fn, finalizeDragSelectionWithDom_fn, scrollPageIntoView_fn, waitForPageMount_fn, getEffectivePageGap_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderCellSelectionOverlay_fn, renderHoverRegion_fn, clearHoverRegion_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, applyZoom_fn, getPageOffsetX_fn, convertPageLocalToOverlayCoords_fn, computeSelectionRectsFromDom_fn, computeDomCaretPageLocal_fn, normalizeClientPoint_fn, computeCaretLayoutRectGeometry_fn, computeCaretLayoutRect_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, checkShouldUpdate_fn, updateHTMLAttributes_fn, updateDOMStyles_fn, resolveNeighborParagraphProperties_fn, updateListStyles_fn, initList_fn, checkIsList_fn, createMarker_fn, createSeparator_fn, calculateTabSeparatorStyle_fn, calculateMarkerStyle_fn, removeList_fn, getParagraphContext_fn, scheduleAnimation_fn, cancelScheduledAnimation_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn, _VectorShapeView_instances, ensureParentPositioned_fn, _ShapeGroupView_instances, ensureParentPositioned_fn2;
13
13
  import * as Y from "yjs";
14
14
  import { UndoManager, Item as Item$1, ContentType, Text as Text$1, XmlElement, encodeStateAsUpdate } from "yjs";
15
- import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$2, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as htmlHandler, E as ReplaceStep, G as twipsToInches, H as inchesToTwips, I as ptToTwips, J as getResolvedParagraphProperties, K as linesToTwips, L as changeListLevel, O as findParentNode, Q as isList, U as updateNumberingProperties, V as ListHelpers, W as isMacOS, X as isIOS, Y as getSchemaTypeByName, Z as inputRulesPlugin, _ as TrackDeleteMarkName$1, $ as TrackInsertMarkName$1, a0 as v4, a1 as TrackFormatMarkName$1, a2 as comments_module_events, a3 as findMark, a4 as objectIncludes, a5 as AddMarkStep, a6 as RemoveMarkStep, a7 as twipsToLines, a8 as pixelsToTwips, a9 as helpers, aa as posToDOMRect, ab as CommandService, ac as SuperConverter, ad as createDocument, ae as createDocFromMarkdown, af as createDocFromHTML, ag as EditorState, ah as isActive, ai as unflattenListsInHtml, aj as SelectionRange, ak as Transform, al as resolveParagraphProperties, am as _getReferencedTableStyles, an as parseSizeUnit, ao as minMax, ap as updateDOMAttributes, aq as findChildren$5, ar as generateRandomSigned32BitIntStrId, as as decodeRPrFromMarks, at as calculateResolvedParagraphProperties, au as resolveRunProperties, av as encodeCSSFromPPr, aw as twipsToPixels$2, ax as encodeCSSFromRPr, ay as generateOrderedListIndex, az as docxNumberingHelpers, aA as InputRule, aB as convertSizeToCSS, aC as findParentNodeClosestToPos, aD as isInTable$1, aE as generateDocxRandomId, aF as insertNewRelationship, aG as inchesToPixels, aH as kebabCase, aI as getUnderlineCssString } from "./converter-CDlAWcRu.js";
16
- import { D as DocxZipper } from "./docx-zipper-B2VXuf8h.js";
15
+ import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$2, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as htmlHandler, E as ReplaceStep, G as twipsToInches, H as inchesToTwips, I as ptToTwips, J as getResolvedParagraphProperties, K as linesToTwips, L as changeListLevel, O as findParentNode, Q as isList, U as updateNumberingProperties, V as ListHelpers, W as isMacOS, X as isIOS, Y as getSchemaTypeByName, Z as inputRulesPlugin, _ as TrackDeleteMarkName$1, $ as TrackInsertMarkName$1, a0 as v4, a1 as TrackFormatMarkName$1, a2 as comments_module_events, a3 as objectIncludes, a4 as AddMarkStep, a5 as RemoveMarkStep, a6 as findMark, a7 as twipsToLines, a8 as pixelsToTwips, a9 as helpers, aa as posToDOMRect, ab as CommandService, ac as SuperConverter, ad as createDocument, ae as createDocFromMarkdown, af as createDocFromHTML, ag as EditorState, ah as isActive, ai as unflattenListsInHtml, aj as SelectionRange, ak as Transform, al as resolveParagraphProperties, am as _getReferencedTableStyles, an as parseSizeUnit, ao as minMax, ap as updateDOMAttributes, aq as findChildren$5, ar as generateRandomSigned32BitIntStrId, as as decodeRPrFromMarks, at as calculateResolvedParagraphProperties, au as resolveRunProperties, av as encodeCSSFromPPr, aw as twipsToPixels$2, ax as encodeCSSFromRPr, ay as generateOrderedListIndex, az as docxNumberingHelpers, aA as InputRule, aB as convertSizeToCSS, aC as findParentNodeClosestToPos, aD as isInTable$1, aE as generateDocxRandomId, aF as insertNewRelationship, aG as inchesToPixels, aH as kebabCase, aI as getUnderlineCssString } from "./converter-De_h0rq-.js";
16
+ import { D as DocxZipper } from "./docx-zipper-CKQFze2s.js";
17
17
  import { ref, computed, createElementBlock, openBlock, withModifiers, Fragment as Fragment$1, renderList, normalizeClass, createCommentVNode, toDisplayString, createElementVNode, createApp } from "vue";
18
18
  var GOOD_LEAF_SIZE = 200;
19
19
  var RopeSequence = function RopeSequence2() {
@@ -11859,6 +11859,9 @@ const findMarkPosition = (doc2, pos, markName) => {
11859
11859
  return null;
11860
11860
  }
11861
11861
  const actualMark = start2.node.marks.find((mark) => mark.type.name === markName);
11862
+ if (!actualMark) {
11863
+ return null;
11864
+ }
11862
11865
  let startIndex = $pos.index();
11863
11866
  let startPos = $pos.start() + start2.offset;
11864
11867
  while (startIndex > 0 && actualMark.isInSet(parent.child(startIndex - 1).marks)) {
@@ -12148,6 +12151,70 @@ const getCommentPositionsById = (commentId, doc2) => {
12148
12151
  });
12149
12152
  return positions;
12150
12153
  };
12154
+ const getCommentMarkSegmentsById = (commentId, doc2) => {
12155
+ const segments = [];
12156
+ doc2.descendants((node, pos) => {
12157
+ if (!node.isInline) return;
12158
+ const commentMark = node.marks?.find(
12159
+ (mark) => mark.type.name === CommentMarkName$1 && mark.attrs?.commentId === commentId
12160
+ );
12161
+ if (!commentMark) return;
12162
+ segments.push({
12163
+ from: pos,
12164
+ to: pos + node.nodeSize,
12165
+ attrs: commentMark.attrs || {}
12166
+ });
12167
+ });
12168
+ return segments;
12169
+ };
12170
+ const getCommentMarkRangesById = (commentId, doc2) => {
12171
+ const segments = getCommentMarkSegmentsById(commentId, doc2);
12172
+ if (!segments.length) return { segments, ranges: [] };
12173
+ const ranges = [];
12174
+ let active = null;
12175
+ segments.forEach((seg) => {
12176
+ if (!active) {
12177
+ active = {
12178
+ from: seg.from,
12179
+ to: seg.to,
12180
+ internal: !!seg.attrs?.internal
12181
+ };
12182
+ return;
12183
+ }
12184
+ if (seg.from <= active.to) {
12185
+ active.to = Math.max(active.to, seg.to);
12186
+ return;
12187
+ }
12188
+ ranges.push(active);
12189
+ active = {
12190
+ from: seg.from,
12191
+ to: seg.to,
12192
+ internal: !!seg.attrs?.internal
12193
+ };
12194
+ });
12195
+ if (active) ranges.push(active);
12196
+ return { segments, ranges };
12197
+ };
12198
+ const resolveCommentById = ({ commentId, state, tr, dispatch }) => {
12199
+ const { schema } = state;
12200
+ const markType = schema.marks?.[CommentMarkName$1];
12201
+ if (!markType) return false;
12202
+ const { segments, ranges } = getCommentMarkRangesById(commentId, state.doc);
12203
+ if (!segments.length) return false;
12204
+ segments.forEach(({ from: from2, to, attrs }) => {
12205
+ tr.removeMark(from2, to, markType.create(attrs));
12206
+ });
12207
+ const startType = schema.nodes?.commentRangeStart;
12208
+ const endType = schema.nodes?.commentRangeEnd;
12209
+ if (startType && endType) {
12210
+ ranges.slice().sort((a, b) => b.from - a.from).forEach(({ from: from2, to, internal }) => {
12211
+ tr.insert(to, endType.create({ "w:id": commentId }));
12212
+ tr.insert(from2, startType.create({ "w:id": commentId, internal }));
12213
+ });
12214
+ }
12215
+ dispatch(tr);
12216
+ return true;
12217
+ };
12151
12218
  const prepareCommentsForExport = (doc2, tr, schema, comments = []) => {
12152
12219
  const commentMap = /* @__PURE__ */ new Map();
12153
12220
  comments.forEach((c) => {
@@ -12254,6 +12321,7 @@ const getPreparedComment = (attrs) => {
12254
12321
  const prepareCommentsForImport = (doc2, tr, schema, converter) => {
12255
12322
  const toMark = [];
12256
12323
  const toDelete = [];
12324
+ const toUpdate = [];
12257
12325
  doc2.descendants((node, pos) => {
12258
12326
  const { type } = node;
12259
12327
  const commentNodes = ["commentRangeStart", "commentRangeEnd", "commentReference"];
@@ -12262,8 +12330,9 @@ const prepareCommentsForImport = (doc2, tr, schema, converter) => {
12262
12330
  converter,
12263
12331
  importedId: node.attrs["w:id"]
12264
12332
  });
12333
+ const isDone = !!matchingImportedComment?.isDone;
12265
12334
  if (type.name === "commentRangeStart") {
12266
- if (!matchingImportedComment?.isDone) {
12335
+ if (!isDone) {
12267
12336
  toMark.push({
12268
12337
  commentId: resolvedCommentId,
12269
12338
  importedId,
@@ -12277,8 +12346,29 @@ const prepareCommentsForImport = (doc2, tr, schema, converter) => {
12277
12346
  commentId: resolvedCommentId,
12278
12347
  importedId
12279
12348
  });
12280
- toDelete.push({ start: pos, end: pos + 1 });
12349
+ if (isDone) {
12350
+ toUpdate.push({
12351
+ pos,
12352
+ attrs: {
12353
+ ...node.attrs,
12354
+ "w:id": resolvedCommentId,
12355
+ internal
12356
+ }
12357
+ });
12358
+ } else {
12359
+ toDelete.push({ start: pos, end: pos + 1 });
12360
+ }
12281
12361
  } else if (type.name === "commentRangeEnd") {
12362
+ if (isDone) {
12363
+ toUpdate.push({
12364
+ pos,
12365
+ attrs: {
12366
+ ...node.attrs,
12367
+ "w:id": resolvedCommentId
12368
+ }
12369
+ });
12370
+ return;
12371
+ }
12282
12372
  const itemToMark = toMark.find((p) => p.importedId === importedId);
12283
12373
  if (!itemToMark) return;
12284
12374
  const { start: start2 } = itemToMark;
@@ -12293,6 +12383,11 @@ const prepareCommentsForImport = (doc2, tr, schema, converter) => {
12293
12383
  toDelete.push({ start: pos, end: pos + 1 });
12294
12384
  }
12295
12385
  });
12386
+ if (typeof tr.setNodeMarkup === "function") {
12387
+ toUpdate.sort((a, b) => b.pos - a.pos).forEach(({ pos, attrs }) => {
12388
+ tr.setNodeMarkup(pos, void 0, attrs);
12389
+ });
12390
+ }
12296
12391
  toDelete.sort((a, b) => b.start - a.start).forEach(({ start: start2, end: end2 }) => {
12297
12392
  tr.delete(start2, end2);
12298
12393
  });
@@ -12486,7 +12581,7 @@ const CommentsPlugin = Extension.create({
12486
12581
  },
12487
12582
  resolveComment: ({ commentId }) => ({ tr, dispatch, state }) => {
12488
12583
  tr.setMeta(CommentsPluginKey, { event: "update" });
12489
- removeCommentsById({ commentId, state, tr, dispatch });
12584
+ return resolveCommentById({ commentId, state, tr, dispatch });
12490
12585
  },
12491
12586
  setCursorById: (id) => ({ state, editor }) => {
12492
12587
  const { from: from2 } = findRangeById(state.doc, id) || {};
@@ -12919,47 +13014,58 @@ function findRangeById(doc2, id) {
12919
13014
  return from2 !== null && to !== null ? { from: from2, to } : null;
12920
13015
  }
12921
13016
  const replaceStep = ({ state, tr, step, newTr, map: map2, user, date, originalStep, originalStepIndex }) => {
12922
- const deletionMarkSchema = state.schema.marks[TrackDeleteMarkName$1];
12923
- const deletionMark = findMark(state, deletionMarkSchema, false);
12924
- const positionTo = deletionMark ? deletionMark.to : step.to;
12925
- const newStep = new ReplaceStep(
12926
- positionTo,
12927
- // We insert all the same steps, but with "from"/"to" both set to "to" in order not to delete content. Mapped as needed.
12928
- positionTo,
12929
- step.slice,
12930
- step.structure
12931
- );
12932
- const invertStep = originalStep.invert(tr.docs[originalStepIndex]).map(map2);
12933
- map2.appendMap(invertStep.getMap());
12934
- const meta = {};
12935
- if (newStep) {
12936
- const trTemp = state.apply(newTr).tr;
12937
- if (trTemp.maybeStep(newStep).failed) {
12938
- return;
12939
- }
12940
- const mappedNewStepTo = newStep.getMap().map(newStep.to);
12941
- const insertedMark = markInsertion({
12942
- tr: trTemp,
12943
- from: newStep.from,
12944
- to: mappedNewStepTo,
12945
- user,
12946
- date
12947
- });
12948
- const condensedStep = new ReplaceStep(newStep.from, newStep.to, trTemp.doc.slice(newStep.from, mappedNewStepTo));
12949
- newTr.step(condensedStep);
12950
- const mirrorIndex = map2.maps.length - 1;
12951
- map2.appendMap(condensedStep.getMap(), mirrorIndex);
12952
- if (newStep.from !== mappedNewStepTo) {
12953
- meta.insertedMark = insertedMark;
12954
- meta.step = condensedStep;
13017
+ const trTemp = state.apply(newTr).tr;
13018
+ let positionTo = step.to;
13019
+ const probePos = Math.max(step.from, step.to - 1);
13020
+ const deletionSpan = findMarkPosition(trTemp.doc, probePos, TrackDeleteMarkName$1);
13021
+ if (deletionSpan && deletionSpan.to > positionTo) {
13022
+ positionTo = deletionSpan.to;
13023
+ }
13024
+ const tryInsert = (slice2) => {
13025
+ const insertionStep = new ReplaceStep(positionTo, positionTo, slice2, false);
13026
+ if (trTemp.maybeStep(insertionStep).failed) return null;
13027
+ return {
13028
+ insertedFrom: insertionStep.from,
13029
+ insertedTo: insertionStep.getMap().map(insertionStep.to, 1)
13030
+ };
13031
+ };
13032
+ const insertion = tryInsert(step.slice) || tryInsert(Slice.maxOpen(step.slice.content, true));
13033
+ if (!insertion) {
13034
+ if (!newTr.maybeStep(step).failed) {
13035
+ map2.appendMap(step.getMap());
12955
13036
  }
12956
- if (!newTr.selection.eq(trTemp.selection)) {
12957
- newTr.setSelection(trTemp.selection);
13037
+ return;
13038
+ }
13039
+ const meta = {};
13040
+ const insertedMark = markInsertion({
13041
+ tr: trTemp,
13042
+ from: insertion.insertedFrom,
13043
+ to: insertion.insertedTo,
13044
+ user,
13045
+ date
13046
+ });
13047
+ const trackedInsertedSlice = trTemp.doc.slice(insertion.insertedFrom, insertion.insertedTo);
13048
+ const condensedStep = new ReplaceStep(positionTo, positionTo, trackedInsertedSlice, false);
13049
+ if (newTr.maybeStep(condensedStep).failed) {
13050
+ if (!newTr.maybeStep(step).failed) {
13051
+ map2.appendMap(step.getMap());
12958
13052
  }
13053
+ return;
13054
+ }
13055
+ const invertStep = originalStep.invert(tr.docs[originalStepIndex]).map(map2);
13056
+ map2.appendMap(invertStep.getMap());
13057
+ const mirrorIndex = map2.maps.length - 1;
13058
+ map2.appendMap(condensedStep.getMap(), mirrorIndex);
13059
+ if (insertion.insertedFrom !== insertion.insertedTo) {
13060
+ meta.insertedMark = insertedMark;
13061
+ meta.step = condensedStep;
13062
+ }
13063
+ if (!newTr.selection.eq(trTemp.selection)) {
13064
+ newTr.setSelection(trTemp.selection);
12959
13065
  }
12960
13066
  if (step.from !== step.to) {
12961
13067
  const {
12962
- deletionMark: deletionMark2,
13068
+ deletionMark,
12963
13069
  deletionMap,
12964
13070
  nodes: deletionNodes
12965
13071
  } = markDeletion({
@@ -12971,7 +13077,7 @@ const replaceStep = ({ state, tr, step, newTr, map: map2, user, date, originalSt
12971
13077
  id: meta.insertedMark?.attrs?.id
12972
13078
  });
12973
13079
  meta.deletionNodes = deletionNodes;
12974
- meta.deletionMark = deletionMark2;
13080
+ meta.deletionMark = deletionMark;
12975
13081
  map2.appendMapping(deletionMap);
12976
13082
  }
12977
13083
  newTr.setMeta(TrackChangesBasePluginKey, meta);
@@ -14815,7 +14921,7 @@ const isHeadless = (editor) => {
14815
14921
  const shouldSkipNodeView = (editor) => {
14816
14922
  return isHeadless(editor);
14817
14923
  };
14818
- const summaryVersion = "2.0.0-next.2";
14924
+ const summaryVersion = "2.0.0-next.21";
14819
14925
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
14820
14926
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
14821
14927
  function mapAttributes(attrs) {
@@ -15607,7 +15713,7 @@ const _Editor = class _Editor extends EventEmitter {
15607
15713
  { default: remarkStringify },
15608
15714
  { default: remarkGfm }
15609
15715
  ] = await Promise.all([
15610
- import("./index-BqPa6D4q.js"),
15716
+ import("./index--w_Fk0WX.js"),
15611
15717
  import("./index-DRCvimau.js"),
15612
15718
  import("./index-C_x_N6Uh.js"),
15613
15719
  import("./index-D_sWOSiG.js"),
@@ -15812,7 +15918,7 @@ const _Editor = class _Editor extends EventEmitter {
15812
15918
  * Process collaboration migrations
15813
15919
  */
15814
15920
  processCollaborationMigrations() {
15815
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.2");
15921
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.21");
15816
15922
  if (!this.options.ydoc) return;
15817
15923
  const metaMap = this.options.ydoc.getMap("meta");
15818
15924
  let docVersion = metaMap.get("version");
@@ -21464,6 +21570,24 @@ const SDT_CONTAINER_STYLES = `
21464
21570
  display: block;
21465
21571
  }
21466
21572
 
21573
+ /* Viewing mode: remove structured content affordances */
21574
+ .presentation-editor--viewing .superdoc-structured-content-block,
21575
+ .presentation-editor--viewing .superdoc-structured-content-inline {
21576
+ background: none;
21577
+ border: none;
21578
+ padding: 0;
21579
+ }
21580
+
21581
+ .presentation-editor--viewing .superdoc-structured-content-inline:hover {
21582
+ background: none;
21583
+ border: none;
21584
+ }
21585
+
21586
+ .presentation-editor--viewing .superdoc-structured-content__label,
21587
+ .presentation-editor--viewing .superdoc-structured-content-inline__label {
21588
+ display: none !important;
21589
+ }
21590
+
21467
21591
  /* Print mode: hide visual styling for SDT containers */
21468
21592
  @media print {
21469
21593
  .superdoc-document-section,
@@ -23152,7 +23276,7 @@ function isMinimalWordLayout(value) {
23152
23276
  return true;
23153
23277
  }
23154
23278
  const LIST_MARKER_GAP$2 = 8;
23155
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
23279
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
23156
23280
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
23157
23281
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
23158
23282
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -24079,6 +24203,7 @@ const _DomPainter = class _DomPainter {
24079
24203
  const block = lookup.block;
24080
24204
  const measure = lookup.measure;
24081
24205
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
24206
+ const alignment = block.attrs?.alignment;
24082
24207
  const fragmentEl = this.doc.createElement("div");
24083
24208
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
24084
24209
  const isTocEntry = block.attrs?.isTocEntry;
@@ -24157,7 +24282,7 @@ const _DomPainter = class _DomPainter {
24157
24282
  const textStart = paraIndentLeft + firstLine;
24158
24283
  tabWidth = textStart - currentPos;
24159
24284
  if (tabWidth <= 0) {
24160
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
24285
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
24161
24286
  } else if (tabWidth < LIST_MARKER_GAP$2) {
24162
24287
  tabWidth = LIST_MARKER_GAP$2;
24163
24288
  }
@@ -24184,6 +24309,21 @@ const _DomPainter = class _DomPainter {
24184
24309
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
24185
24310
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
24186
24311
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
24312
+ if (alignment === "justify" || alignment === "both") {
24313
+ console.log(
24314
+ "[justify-debug][painter-firstline-available]",
24315
+ JSON.stringify({
24316
+ blockId: block.id,
24317
+ fragmentWidth: fragment.width,
24318
+ markerTabWidth: listFirstLineMarkerTabWidth,
24319
+ paraIndentRight,
24320
+ availableWidthOverride,
24321
+ lineMaxWidth: line.maxWidth ?? null,
24322
+ lineWidth: line.width,
24323
+ lineNaturalWidth: line.naturalWidth ?? null
24324
+ })
24325
+ );
24326
+ }
24187
24327
  }
24188
24328
  const isLastLineOfFragment = index2 === lines.length - 1;
24189
24329
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -24309,7 +24449,7 @@ const _DomPainter = class _DomPainter {
24309
24449
  const textStart = paraIndentLeft + firstLine;
24310
24450
  tabWidth = textStart - currentPos;
24311
24451
  if (tabWidth <= 0) {
24312
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
24452
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
24313
24453
  } else if (tabWidth < LIST_MARKER_GAP$2) {
24314
24454
  tabWidth = LIST_MARKER_GAP$2;
24315
24455
  }
@@ -25843,6 +25983,23 @@ const _DomPainter = class _DomPainter {
25843
25983
  if (spacingPerSpace !== 0) {
25844
25984
  el.style.wordSpacing = `${spacingPerSpace}px`;
25845
25985
  }
25986
+ if (justifyShouldApply && spacingPerSpace < 0) {
25987
+ console.log(
25988
+ "[justify-debug][painter-wordspacing-negative]",
25989
+ JSON.stringify({
25990
+ blockId: block.id,
25991
+ lineIndex: lineIndex ?? null,
25992
+ alignment: alignment ?? null,
25993
+ availableWidth,
25994
+ lineWidth,
25995
+ lineMaxWidth: line.maxWidth ?? null,
25996
+ lineNaturalWidth: line.naturalWidth ?? null,
25997
+ spaceCount,
25998
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
25999
+ skipJustify: Boolean(skipJustify)
26000
+ })
26001
+ );
26002
+ }
25846
26003
  if (hasExplicitPositioning && line.segments) {
25847
26004
  const paraIndent = block.attrs?.indent;
25848
26005
  const indentLeft = paraIndent?.left ?? 0;
@@ -28036,6 +28193,28 @@ let measurementCtx = null;
28036
28193
  const TAB_CHAR_LENGTH = 1;
28037
28194
  const SPACE_CHARS = SPACE_CHARS$1;
28038
28195
  const isTabRun$1 = (run) => run?.kind === "tab";
28196
+ const isWordChar$3 = (char) => {
28197
+ if (!char) return false;
28198
+ const code = char.charCodeAt(0);
28199
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
28200
+ };
28201
+ const capitalizeText$2 = (text) => {
28202
+ if (!text) return text;
28203
+ let result = "";
28204
+ for (let i = 0; i < text.length; i += 1) {
28205
+ const prevChar = i > 0 ? text[i - 1] : "";
28206
+ const ch = text[i];
28207
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
28208
+ }
28209
+ return result;
28210
+ };
28211
+ const applyTextTransform$2 = (text, transform) => {
28212
+ if (!text || !transform || transform === "none") return text;
28213
+ if (transform === "uppercase") return text.toUpperCase();
28214
+ if (transform === "lowercase") return text.toLowerCase();
28215
+ if (transform === "capitalize") return capitalizeText$2(text);
28216
+ return text;
28217
+ };
28039
28218
  function getMeasurementContext() {
28040
28219
  if (measurementCtx) return measurementCtx;
28041
28220
  if (typeof document === "undefined") {
@@ -28211,17 +28390,19 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
28211
28390
  }
28212
28391
  const text = "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
28213
28392
  const runLength = text.length;
28393
+ const transform = isTabRun$1(run) || "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? void 0 : run.textTransform;
28394
+ const displayText = applyTextTransform$2(text, transform);
28214
28395
  if (currentCharOffset + runLength >= charOffset) {
28215
28396
  const offsetInRun = charOffset - currentCharOffset;
28216
28397
  ctx2.font = getRunFontString(run);
28217
- const textUpToTarget = text.slice(0, offsetInRun);
28398
+ const textUpToTarget = displayText.slice(0, offsetInRun);
28218
28399
  const measured2 = ctx2.measureText(textUpToTarget);
28219
28400
  const spacingWidth = computeLetterSpacingWidth(run, offsetInRun, runLength);
28220
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
28401
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text.slice(0, offsetInRun)) : 0;
28221
28402
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
28222
28403
  }
28223
28404
  ctx2.font = getRunFontString(run);
28224
- const measured = ctx2.measureText(text);
28405
+ const measured = ctx2.measureText(displayText);
28225
28406
  const runLetterSpacing = computeLetterSpacingWidth(run, runLength, runLength);
28226
28407
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text) : 0;
28227
28408
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -28260,8 +28441,10 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
28260
28441
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
28261
28442
  }
28262
28443
  const text = run.text ?? "";
28263
- const segmentText = text.slice(segment.fromChar, segment.toChar);
28264
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
28444
+ const transform = "textTransform" in run ? run.textTransform : void 0;
28445
+ const displayText = applyTextTransform$2(text, transform);
28446
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
28447
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
28265
28448
  ctx2.font = getRunFontString(run);
28266
28449
  const measured = ctx2.measureText(textUpToTarget);
28267
28450
  const spacingWidth = computeLetterSpacingWidth(run, offsetInSegment, segmentChars);
@@ -28357,12 +28540,14 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
28357
28540
  }
28358
28541
  const text = "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
28359
28542
  const runLength = text.length;
28543
+ const transform = isTabRun$1(run) || "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? void 0 : run.textTransform;
28544
+ const displayText = applyTextTransform$2(text, transform);
28360
28545
  if (runLength === 0) continue;
28361
28546
  ctx2.font = getRunFontString(run);
28362
28547
  for (let i = 0; i <= runLength; i++) {
28363
- const textUpToChar = text.slice(0, i);
28548
+ const textUpToChar = displayText.slice(0, i);
28364
28549
  const measured2 = ctx2.measureText(textUpToChar);
28365
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
28550
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text.slice(0, i)) : 0;
28366
28551
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run, i, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
28367
28552
  if (charX >= safeX) {
28368
28553
  if (i === 0) {
@@ -28372,7 +28557,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
28372
28557
  pmPosition: pmPosition3
28373
28558
  };
28374
28559
  }
28375
- const prevText = text.slice(0, i - 1);
28560
+ const prevText = displayText.slice(0, i - 1);
28376
28561
  const prevMeasured = ctx2.measureText(prevText);
28377
28562
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run, i - 1, runLength);
28378
28563
  const distToPrev = Math.abs(safeX - prevX);
@@ -28385,7 +28570,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
28385
28570
  };
28386
28571
  }
28387
28572
  }
28388
- const measured = ctx2.measureText(text);
28573
+ const measured = ctx2.measureText(displayText);
28389
28574
  const runLetterSpacing = computeLetterSpacingWidth(run, runLength, runLength);
28390
28575
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
28391
28576
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -28816,6 +29001,83 @@ function findCharIndexAtX(textNode, container, targetX) {
28816
29001
  }
28817
29002
  return index2;
28818
29003
  }
29004
+ const LIST_MARKER_GAP$1 = 8;
29005
+ const MIN_MARKER_GUTTER = 24;
29006
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
29007
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
29008
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
29009
+ const SPACE_SUFFIX_GAP_PX = 4;
29010
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
29011
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
29012
+ const marker = wordLayout?.marker;
29013
+ if (!marker) {
29014
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
29015
+ return textStartPx;
29016
+ }
29017
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
29018
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
29019
+ if (markerTextWidth == null && marker.markerText) {
29020
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
29021
+ }
29022
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth !== void 0 && markerTextWidth < 0) {
29023
+ markerTextWidth = markerBoxWidth;
29024
+ }
29025
+ const finalMarkerTextWidth = Math.max(0, markerTextWidth ?? 0);
29026
+ let markerStartPos;
29027
+ if (wordLayout?.firstLineIndentMode === true && typeof marker.markerX === "number" && Number.isFinite(marker.markerX)) {
29028
+ markerStartPos = marker.markerX;
29029
+ } else {
29030
+ markerStartPos = indentLeft - hanging + firstLine;
29031
+ }
29032
+ if (!Number.isFinite(markerStartPos)) {
29033
+ markerStartPos = 0;
29034
+ }
29035
+ const currentPos = markerStartPos + finalMarkerTextWidth;
29036
+ const suffix = marker.suffix ?? "tab";
29037
+ if (suffix === "space") {
29038
+ return markerStartPos + finalMarkerTextWidth + SPACE_SUFFIX_GAP_PX;
29039
+ }
29040
+ if (suffix === "nothing") {
29041
+ return markerStartPos + finalMarkerTextWidth;
29042
+ }
29043
+ const markerJustification = marker.justification ?? "left";
29044
+ if (markerJustification !== "left") {
29045
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
29046
+ return markerStartPos + finalMarkerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
29047
+ }
29048
+ if (wordLayout?.firstLineIndentMode === true) {
29049
+ let targetTabStop;
29050
+ if (Array.isArray(wordLayout.tabsPx)) {
29051
+ for (const tab of wordLayout.tabsPx) {
29052
+ if (typeof tab === "number" && tab > currentPos) {
29053
+ targetTabStop = tab;
29054
+ break;
29055
+ }
29056
+ }
29057
+ }
29058
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
29059
+ let tabWidth2;
29060
+ if (targetTabStop !== void 0) {
29061
+ tabWidth2 = targetTabStop - currentPos;
29062
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
29063
+ tabWidth2 = textStartTarget - currentPos;
29064
+ } else {
29065
+ tabWidth2 = LIST_MARKER_GAP$1;
29066
+ }
29067
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
29068
+ tabWidth2 = LIST_MARKER_GAP$1;
29069
+ }
29070
+ return markerStartPos + finalMarkerTextWidth + tabWidth2;
29071
+ }
29072
+ const textStart = indentLeft + firstLine;
29073
+ let tabWidth = textStart - currentPos;
29074
+ if (tabWidth <= 0) {
29075
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
29076
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
29077
+ tabWidth = LIST_MARKER_GAP$1;
29078
+ }
29079
+ return markerStartPos + finalMarkerTextWidth + tabWidth;
29080
+ }
28819
29081
  function getWordLayoutConfig(block) {
28820
29082
  if (!block || block.kind !== "paragraph") {
28821
29083
  return void 0;
@@ -28848,9 +29110,16 @@ function calculateTextStartIndent(params2) {
28848
29110
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
28849
29111
  let indentAdjust = paraIndentLeft;
28850
29112
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
29113
+ const resolvedTextStart = resolveListTextStartPx(
29114
+ wordLayout,
29115
+ paraIndentLeft,
29116
+ Math.max(firstLineIndent, 0),
29117
+ Math.max(hangingIndent, 0),
29118
+ () => markerWidth
29119
+ // Use provided markerWidth since we don't have canvas access here
29120
+ );
28851
29121
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
28852
- const markerTextStartX = wordLayout?.marker?.textStartX;
28853
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
29122
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
28854
29123
  } else if (isFirstLine && !isListItem2) {
28855
29124
  indentAdjust += firstLineOffset;
28856
29125
  }
@@ -29006,7 +29275,10 @@ function getHeaderFooterTypeForSection(pageNumber, sectionIndex, identifier, opt
29006
29275
  }
29007
29276
  function createFloatingObjectManager(columns, margins, pageWidth) {
29008
29277
  const zones = [];
29009
- const marginLeft = Math.max(0, margins?.left ?? 0);
29278
+ let currentColumns = columns;
29279
+ let currentMargins = margins;
29280
+ let currentPageWidth = pageWidth;
29281
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
29010
29282
  return {
29011
29283
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
29012
29284
  if (!drawingBlock.anchor?.isAnchored) {
@@ -29019,7 +29291,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29019
29291
  }
29020
29292
  const objectWidth = measure.width ?? 0;
29021
29293
  const objectHeight = measure.height ?? 0;
29022
- const x = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
29294
+ const x = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
29023
29295
  const y = anchorY + (anchor.offsetV ?? 0);
29024
29296
  const zone = {
29025
29297
  imageBlockId: drawingBlock.id,
@@ -29053,7 +29325,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29053
29325
  }
29054
29326
  const tableWidth = measure.totalWidth ?? 0;
29055
29327
  const tableHeight = measure.totalHeight ?? 0;
29056
- const x = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
29328
+ const x = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
29057
29329
  const y = anchorY + (anchor.offsetV ?? 0);
29058
29330
  const zone = {
29059
29331
  imageBlockId: tableBlock.id,
@@ -29101,7 +29373,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29101
29373
  }
29102
29374
  const leftFloats = [];
29103
29375
  const rightFloats = [];
29104
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
29376
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
29105
29377
  const columnCenter = columnOrigin + baseWidth / 2;
29106
29378
  for (const zone of wrappingZones) {
29107
29379
  if (zone.wrapMode === "left") {
@@ -29140,6 +29412,22 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29140
29412
  },
29141
29413
  clear() {
29142
29414
  zones.length = 0;
29415
+ },
29416
+ /**
29417
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
29418
+ * This method should be called when the layout configuration changes (e.g., section breaks,
29419
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
29420
+ * correctly relative to the new layout boundaries.
29421
+ *
29422
+ * @param nextColumns - Column layout configuration (width, gap, count)
29423
+ * @param nextMargins - Optional page margins (left, right) in pixels
29424
+ * @param nextPageWidth - Optional total page width in pixels
29425
+ */
29426
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
29427
+ currentColumns = nextColumns;
29428
+ currentMargins = nextMargins;
29429
+ currentPageWidth = nextPageWidth;
29430
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
29143
29431
  }
29144
29432
  };
29145
29433
  }
@@ -29239,7 +29527,14 @@ function computeNextSectionPropsAtBreak(blocks) {
29239
29527
  const props = {};
29240
29528
  if (source.kind !== "sectionBreak") return props;
29241
29529
  if (source.margins) {
29242
- props.margins = { header: source.margins.header, footer: source.margins.footer };
29530
+ props.margins = {
29531
+ header: source.margins.header,
29532
+ footer: source.margins.footer,
29533
+ top: source.margins.top,
29534
+ right: source.margins.right,
29535
+ bottom: source.margins.bottom,
29536
+ left: source.margins.left
29537
+ };
29243
29538
  }
29244
29539
  if (source.pageSize) {
29245
29540
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -29270,13 +29565,13 @@ function scheduleSectionBreak(block, state, baseMargins, maxHeaderContentHeight
29270
29565
  if (maxHeaderContentHeight > 0) {
29271
29566
  return Math.max(baseTop, headerDistance + maxHeaderContentHeight);
29272
29567
  }
29273
- return Math.max(baseTop, headerDistance);
29568
+ return baseTop;
29274
29569
  };
29275
29570
  const calcRequiredBottomMargin = (footerDistance, baseBottom) => {
29276
29571
  if (maxFooterContentHeight > 0) {
29277
29572
  return Math.max(baseBottom, footerDistance + maxFooterContentHeight);
29278
29573
  }
29279
- return Math.max(baseBottom, footerDistance);
29574
+ return baseBottom;
29280
29575
  };
29281
29576
  if (block.attrs?.isFirstSection && !next.hasAnyPages) {
29282
29577
  if (block.pageSize) {
@@ -29287,20 +29582,36 @@ function scheduleSectionBreak(block, state, baseMargins, maxHeaderContentHeight
29287
29582
  next.activeOrientation = block.orientation;
29288
29583
  next.pendingOrientation = null;
29289
29584
  }
29585
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
29586
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
29587
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
29588
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
29290
29589
  if (block.margins?.header !== void 0) {
29291
- const headerDistance = Math.max(0, block.margins.header);
29292
29590
  next.activeHeaderDistance = headerDistance;
29293
29591
  next.pendingHeaderDistance = headerDistance;
29294
- next.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
29295
- next.pendingTopMargin = next.activeTopMargin;
29296
29592
  }
29297
29593
  if (block.margins?.footer !== void 0) {
29298
- const footerDistance = Math.max(0, block.margins.footer);
29299
29594
  next.activeFooterDistance = footerDistance;
29300
29595
  next.pendingFooterDistance = footerDistance;
29301
- next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
29596
+ }
29597
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
29598
+ next.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
29599
+ next.pendingTopMargin = next.activeTopMargin;
29600
+ }
29601
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
29602
+ next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
29302
29603
  next.pendingBottomMargin = next.activeBottomMargin;
29303
29604
  }
29605
+ if (block.margins?.left !== void 0) {
29606
+ const leftMargin = Math.max(0, block.margins.left);
29607
+ next.activeLeftMargin = leftMargin;
29608
+ next.pendingLeftMargin = leftMargin;
29609
+ }
29610
+ if (block.margins?.right !== void 0) {
29611
+ const rightMargin = Math.max(0, block.margins.right);
29612
+ next.activeRightMargin = rightMargin;
29613
+ next.pendingRightMargin = rightMargin;
29614
+ }
29304
29615
  if (block.columns) {
29305
29616
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
29306
29617
  next.pendingColumns = null;
@@ -29309,26 +29620,42 @@ function scheduleSectionBreak(block, state, baseMargins, maxHeaderContentHeight
29309
29620
  }
29310
29621
  const headerPx = block.margins?.header;
29311
29622
  const footerPx = block.margins?.footer;
29623
+ const topPx = block.margins?.top;
29624
+ const bottomPx = block.margins?.bottom;
29312
29625
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
29313
29626
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
29627
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
29628
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
29314
29629
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
29315
29630
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
29316
- if (typeof headerPx === "number") {
29317
- const newHeaderDist = Math.max(0, headerPx);
29631
+ if (typeof headerPx === "number" || typeof topPx === "number") {
29632
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
29633
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
29318
29634
  next.pendingHeaderDistance = newHeaderDist;
29319
- next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
29635
+ next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
29320
29636
  } else {
29321
29637
  next.pendingTopMargin = nextTop;
29322
29638
  next.pendingHeaderDistance = nextHeader;
29323
29639
  }
29324
- if (typeof footerPx === "number") {
29325
- const newFooterDist = Math.max(0, footerPx);
29640
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
29641
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
29642
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
29326
29643
  next.pendingFooterDistance = newFooterDist;
29327
- next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
29644
+ next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
29328
29645
  } else {
29329
29646
  next.pendingBottomMargin = nextBottom;
29330
29647
  next.pendingFooterDistance = nextFooter;
29331
29648
  }
29649
+ if (typeof block.margins?.left === "number") {
29650
+ next.pendingLeftMargin = Math.max(0, block.margins.left);
29651
+ } else {
29652
+ next.pendingLeftMargin = nextLeft;
29653
+ }
29654
+ if (typeof block.margins?.right === "number") {
29655
+ next.pendingRightMargin = Math.max(0, block.margins.right);
29656
+ } else {
29657
+ next.pendingRightMargin = nextRight;
29658
+ }
29332
29659
  if (block.pageSize) {
29333
29660
  next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
29334
29661
  }
@@ -29388,6 +29715,12 @@ function applyPendingToActive(state) {
29388
29715
  if (next.pendingBottomMargin != null) {
29389
29716
  next.activeBottomMargin = next.pendingBottomMargin;
29390
29717
  }
29718
+ if (next.pendingLeftMargin != null) {
29719
+ next.activeLeftMargin = next.pendingLeftMargin;
29720
+ }
29721
+ if (next.pendingRightMargin != null) {
29722
+ next.activeRightMargin = next.pendingRightMargin;
29723
+ }
29391
29724
  if (next.pendingHeaderDistance != null) {
29392
29725
  next.activeHeaderDistance = next.pendingHeaderDistance;
29393
29726
  }
@@ -29405,6 +29738,8 @@ function applyPendingToActive(state) {
29405
29738
  }
29406
29739
  next.pendingTopMargin = null;
29407
29740
  next.pendingBottomMargin = null;
29741
+ next.pendingLeftMargin = null;
29742
+ next.pendingRightMargin = null;
29408
29743
  next.pendingHeaderDistance = null;
29409
29744
  next.pendingFooterDistance = null;
29410
29745
  next.pendingPageSize = null;
@@ -29633,7 +29968,8 @@ function layoutParagraphBlock(ctx2, anchors) {
29633
29968
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
29634
29969
  const firstLineIndent = calculateFirstLineIndent(block, measure);
29635
29970
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
29636
- lines = normalizeLines(newMeasure);
29971
+ const newLines = normalizeLines(newMeasure);
29972
+ lines = newLines;
29637
29973
  didRemeasureForColumnWidth = true;
29638
29974
  }
29639
29975
  let fromLine = 0;
@@ -29715,7 +30051,8 @@ function layoutParagraphBlock(ctx2, anchors) {
29715
30051
  if (narrowestRemeasureWidth < remeasureWidth) {
29716
30052
  const firstLineIndent = calculateFirstLineIndent(block, measure);
29717
30053
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
29718
- lines = normalizeLines(newMeasure);
30054
+ const newLines = normalizeLines(newMeasure);
30055
+ lines = newLines;
29719
30056
  didRemeasureForFloats = true;
29720
30057
  }
29721
30058
  }
@@ -29735,6 +30072,11 @@ function layoutParagraphBlock(ctx2, anchors) {
29735
30072
  const prevTrailing = state.trailingSpacing ?? 0;
29736
30073
  const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
29737
30074
  if (state.cursorY + neededSpacingBefore > state.contentBottom) {
30075
+ if (state.cursorY <= state.topMargin) {
30076
+ state.trailingSpacing = 0;
30077
+ appliedSpacingBefore = true;
30078
+ break;
30079
+ }
29738
30080
  state = advanceColumn(state);
29739
30081
  if (state.trailingSpacing == null) state.trailingSpacing = 0;
29740
30082
  continue;
@@ -30059,6 +30401,94 @@ function getCellPadding(cellIdx, blockRow) {
30059
30401
  function getCellTotalLines(cell) {
30060
30402
  return getCellLines(cell).length;
30061
30403
  }
30404
+ function mergePmRange(target, range) {
30405
+ if (typeof range.pmStart === "number") {
30406
+ target.pmStart = target.pmStart == null ? range.pmStart : Math.min(target.pmStart, range.pmStart);
30407
+ }
30408
+ if (typeof range.pmEnd === "number") {
30409
+ target.pmEnd = target.pmEnd == null ? range.pmEnd : Math.max(target.pmEnd, range.pmEnd);
30410
+ }
30411
+ }
30412
+ function computeCellPmRange(cell, cellMeasure, fromLine, toLine) {
30413
+ const range = {};
30414
+ if (!cell || !cellMeasure) return range;
30415
+ const cellBlocks = cell.blocks ?? (cell.paragraph ? [cell.paragraph] : []);
30416
+ const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
30417
+ const maxBlocks = Math.min(cellBlocks.length, blockMeasures.length);
30418
+ let cumulativeLineCount = 0;
30419
+ for (let i = 0; i < maxBlocks; i++) {
30420
+ const block = cellBlocks[i];
30421
+ const blockMeasure = blockMeasures[i];
30422
+ if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
30423
+ const paraMeasure = blockMeasure;
30424
+ const lines = paraMeasure.lines;
30425
+ const blockLineCount = lines?.length ?? 0;
30426
+ const blockStartGlobal = cumulativeLineCount;
30427
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
30428
+ const localFrom = Math.max(fromLine, blockStartGlobal) - blockStartGlobal;
30429
+ const localTo = Math.min(toLine, blockEndGlobal) - blockStartGlobal;
30430
+ if (lines && lines.length > 0 && localFrom < localTo) {
30431
+ mergePmRange(range, computeFragmentPmRange(block, lines, localFrom, localTo));
30432
+ } else {
30433
+ mergePmRange(range, extractBlockPmRange(block));
30434
+ }
30435
+ cumulativeLineCount += blockLineCount;
30436
+ continue;
30437
+ }
30438
+ mergePmRange(range, extractBlockPmRange(block));
30439
+ }
30440
+ return range;
30441
+ }
30442
+ function computeTableFragmentPmRange(block, measure, fromRow, toRow, partialRow) {
30443
+ const range = {};
30444
+ for (let rowIndex = fromRow; rowIndex < toRow; rowIndex++) {
30445
+ const row = block.rows[rowIndex];
30446
+ const rowMeasure = measure.rows[rowIndex];
30447
+ if (!row || !rowMeasure) continue;
30448
+ const isPartial = partialRow?.rowIndex === rowIndex;
30449
+ const cellCount = Math.min(row.cells.length, rowMeasure.cells.length);
30450
+ for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
30451
+ const cell = row.cells[cellIndex];
30452
+ const cellMeasure = rowMeasure.cells[cellIndex];
30453
+ if (!cell || !cellMeasure) continue;
30454
+ const totalLines = getCellTotalLines(cellMeasure);
30455
+ let fromLine = 0;
30456
+ let toLine = totalLines;
30457
+ if (isPartial) {
30458
+ const hasValidFromLineByCell = partialRow?.fromLineByCell && cellIndex < partialRow.fromLineByCell.length;
30459
+ const hasValidToLineByCell = partialRow?.toLineByCell && cellIndex < partialRow.toLineByCell.length;
30460
+ if (hasValidFromLineByCell) {
30461
+ const rawFrom = partialRow.fromLineByCell[cellIndex];
30462
+ if (typeof rawFrom === "number" && rawFrom >= 0) {
30463
+ fromLine = rawFrom;
30464
+ }
30465
+ }
30466
+ if (hasValidToLineByCell) {
30467
+ const rawTo = partialRow.toLineByCell[cellIndex];
30468
+ if (typeof rawTo === "number") {
30469
+ toLine = rawTo === -1 ? totalLines : rawTo;
30470
+ }
30471
+ }
30472
+ }
30473
+ fromLine = Math.max(0, Math.min(fromLine, totalLines));
30474
+ toLine = Math.max(0, Math.min(toLine, totalLines));
30475
+ if (toLine < fromLine) {
30476
+ toLine = fromLine;
30477
+ }
30478
+ mergePmRange(range, computeCellPmRange(cell, cellMeasure, fromLine, toLine));
30479
+ }
30480
+ }
30481
+ return range;
30482
+ }
30483
+ function applyTableFragmentPmRange(fragment, block, measure) {
30484
+ const range = computeTableFragmentPmRange(block, measure, fragment.fromRow, fragment.toRow, fragment.partialRow);
30485
+ if (range.pmStart != null) {
30486
+ fragment.pmStart = range.pmStart;
30487
+ }
30488
+ if (range.pmEnd != null) {
30489
+ fragment.pmEnd = range.pmEnd;
30490
+ }
30491
+ }
30062
30492
  function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
30063
30493
  const row = measure.rows[rowIndex];
30064
30494
  if (!row) {
@@ -30203,6 +30633,7 @@ function layoutMonolithicTable(context) {
30203
30633
  height,
30204
30634
  metadata
30205
30635
  };
30636
+ applyTableFragmentPmRange(fragment, context.block, context.measure);
30206
30637
  state.page.fragments.push(fragment);
30207
30638
  state.cursorY += height;
30208
30639
  }
@@ -30281,6 +30712,7 @@ function layoutTableBlock({
30281
30712
  height,
30282
30713
  metadata
30283
30714
  };
30715
+ applyTableFragmentPmRange(fragment, block, measure);
30284
30716
  state.page.fragments.push(fragment);
30285
30717
  state.cursorY += height;
30286
30718
  return;
@@ -30344,6 +30776,7 @@ function layoutTableBlock({
30344
30776
  partialRow: continuationPartialRow,
30345
30777
  metadata: generateFragmentMetadata(measure)
30346
30778
  };
30779
+ applyTableFragmentPmRange(fragment2, block, measure);
30347
30780
  state.page.fragments.push(fragment2);
30348
30781
  state.cursorY += fragmentHeight2;
30349
30782
  }
@@ -30388,6 +30821,7 @@ function layoutTableBlock({
30388
30821
  partialRow: forcedPartialRow,
30389
30822
  metadata: generateFragmentMetadata(measure)
30390
30823
  };
30824
+ applyTableFragmentPmRange(fragment2, block, measure);
30391
30825
  state.page.fragments.push(fragment2);
30392
30826
  state.cursorY += fragmentHeight2;
30393
30827
  pendingPartialRow = forcedPartialRow;
@@ -30423,6 +30857,7 @@ function layoutTableBlock({
30423
30857
  partialRow: partialRow || void 0,
30424
30858
  metadata: generateFragmentMetadata(measure)
30425
30859
  };
30860
+ applyTableFragmentPmRange(fragment, block, measure);
30426
30861
  state.page.fragments.push(fragment);
30427
30862
  state.cursorY += fragmentHeight;
30428
30863
  if (partialRow && !partialRow.isLastPart) {
@@ -30440,7 +30875,7 @@ function createAnchoredTableFragment(block, measure, x, y) {
30440
30875
  columnBoundaries: generateColumnBoundaries(measure),
30441
30876
  coordinateSystem: "fragment"
30442
30877
  };
30443
- return {
30878
+ const fragment = {
30444
30879
  kind: "table",
30445
30880
  blockId: block.id,
30446
30881
  fromRow: 0,
@@ -30451,6 +30886,8 @@ function createAnchoredTableFragment(block, measure, x, y) {
30451
30886
  height: measure.totalHeight ?? 0,
30452
30887
  metadata
30453
30888
  };
30889
+ applyTableFragmentPmRange(fragment, block, measure);
30890
+ return fragment;
30454
30891
  }
30455
30892
  function isPageRelativeAnchor(block) {
30456
30893
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -30872,8 +31309,8 @@ function layoutDocument(blocks, measures, options = {}) {
30872
31309
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
30873
31310
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
30874
31311
  };
30875
- const contentWidth = pageSize.w - (margins.left + margins.right);
30876
- if (contentWidth <= 0) {
31312
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
31313
+ if (baseContentWidth <= 0) {
30877
31314
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
30878
31315
  }
30879
31316
  const validateContentHeight = (height) => {
@@ -30903,8 +31340,12 @@ function layoutDocument(blocks, measures, options = {}) {
30903
31340
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
30904
31341
  let activeTopMargin = effectiveTopMargin;
30905
31342
  let activeBottomMargin = effectiveBottomMargin;
31343
+ let activeLeftMargin = margins.left;
31344
+ let activeRightMargin = margins.right;
30906
31345
  let pendingTopMargin = null;
30907
31346
  let pendingBottomMargin = null;
31347
+ let pendingLeftMargin = null;
31348
+ let pendingRightMargin = null;
30908
31349
  let activeHeaderDistance = margins.header ?? margins.top;
30909
31350
  let pendingHeaderDistance = null;
30910
31351
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -30917,10 +31358,11 @@ function layoutDocument(blocks, measures, options = {}) {
30917
31358
  let pendingOrientation = null;
30918
31359
  let activeVAlign = null;
30919
31360
  let pendingVAlign = null;
31361
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
30920
31362
  const floatManager = createFloatingObjectManager(
30921
- normalizeColumns(activeColumns, contentWidth),
30922
- { left: margins.left, right: margins.right },
30923
- pageSize.w
31363
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
31364
+ { left: activeLeftMargin, right: activeRightMargin },
31365
+ activePageSize.w
30924
31366
  );
30925
31367
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks);
30926
31368
  const scheduleSectionBreakCompat = (block, state, baseMargins) => {
@@ -30937,22 +31379,38 @@ function layoutDocument(blocks, measures, options = {}) {
30937
31379
  next.activeOrientation = block.orientation;
30938
31380
  next.pendingOrientation = null;
30939
31381
  }
31382
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
31383
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
31384
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
31385
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
30940
31386
  if (block.margins?.header !== void 0) {
30941
- const headerDist = Math.max(0, block.margins.header);
30942
- next.activeHeaderDistance = headerDist;
30943
- next.pendingHeaderDistance = headerDist;
30944
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
30945
- next.activeTopMargin = Math.max(baseMargins.top, requiredTop);
30946
- next.pendingTopMargin = next.activeTopMargin;
31387
+ next.activeHeaderDistance = headerDistance2;
31388
+ next.pendingHeaderDistance = headerDistance2;
30947
31389
  }
30948
31390
  if (block.margins?.footer !== void 0) {
30949
- const footerDistance2 = Math.max(0, block.margins.footer);
30950
31391
  next.activeFooterDistance = footerDistance2;
30951
31392
  next.pendingFooterDistance = footerDistance2;
30952
- const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
30953
- next.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
31393
+ }
31394
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
31395
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : 0;
31396
+ next.activeTopMargin = Math.max(sectionTop, requiredTop);
31397
+ next.pendingTopMargin = next.activeTopMargin;
31398
+ }
31399
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
31400
+ const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : 0;
31401
+ next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
30954
31402
  next.pendingBottomMargin = next.activeBottomMargin;
30955
31403
  }
31404
+ if (block.margins?.left !== void 0) {
31405
+ const leftMargin = Math.max(0, block.margins.left);
31406
+ next.activeLeftMargin = leftMargin;
31407
+ next.pendingLeftMargin = leftMargin;
31408
+ }
31409
+ if (block.margins?.right !== void 0) {
31410
+ const rightMargin = Math.max(0, block.margins.right);
31411
+ next.activeRightMargin = rightMargin;
31412
+ next.pendingRightMargin = rightMargin;
31413
+ }
30956
31414
  if (block.columns) {
30957
31415
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
30958
31416
  next.pendingColumns = null;
@@ -30981,27 +31439,35 @@ function layoutDocument(blocks, measures, options = {}) {
30981
31439
  const headerPx = block.margins?.header;
30982
31440
  const footerPx = block.margins?.footer;
30983
31441
  const topPx = block.margins?.top;
31442
+ const bottomPx = block.margins?.bottom;
31443
+ const leftPx = block.margins?.left;
31444
+ const rightPx = block.margins?.right;
30984
31445
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
30985
31446
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
31447
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
31448
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
30986
31449
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
30987
31450
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
30988
31451
  next.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
30989
31452
  next.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
30990
31453
  if (typeof headerPx === "number" || typeof topPx === "number") {
30991
- const sectionTop = topPx ?? baseMargins.top;
31454
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
30992
31455
  const sectionHeader = next.pendingHeaderDistance;
30993
31456
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
30994
31457
  next.pendingTopMargin = Math.max(sectionTop, requiredTop);
30995
31458
  } else {
30996
31459
  next.pendingTopMargin = nextTop;
30997
31460
  }
30998
- if (typeof footerPx === "number") {
31461
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
30999
31462
  const sectionFooter = next.pendingFooterDistance;
31463
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
31000
31464
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
31001
- next.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
31465
+ next.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
31002
31466
  } else {
31003
31467
  next.pendingBottomMargin = nextBottom;
31004
31468
  }
31469
+ next.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
31470
+ next.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
31005
31471
  if (block.pageSize) next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
31006
31472
  if (block.orientation) next.pendingOrientation = block.orientation;
31007
31473
  const sectionType = block.type ?? "continuous";
@@ -31086,7 +31552,7 @@ function layoutDocument(blocks, measures, options = {}) {
31086
31552
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
31087
31553
  let pendingSectionIndex = null;
31088
31554
  const paginator = createPaginator({
31089
- margins: { left: margins.left, right: margins.right },
31555
+ margins: paginatorMargins,
31090
31556
  getActiveTopMargin: () => activeTopMargin,
31091
31557
  getActiveBottomMargin: () => activeBottomMargin,
31092
31558
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -31101,8 +31567,12 @@ function layoutDocument(blocks, measures, options = {}) {
31101
31567
  const applied = applyPendingToActive({
31102
31568
  activeTopMargin,
31103
31569
  activeBottomMargin,
31570
+ activeLeftMargin,
31571
+ activeRightMargin,
31104
31572
  pendingTopMargin,
31105
31573
  pendingBottomMargin,
31574
+ pendingLeftMargin,
31575
+ pendingRightMargin,
31106
31576
  activeHeaderDistance,
31107
31577
  activeFooterDistance,
31108
31578
  pendingHeaderDistance,
@@ -31117,8 +31587,12 @@ function layoutDocument(blocks, measures, options = {}) {
31117
31587
  });
31118
31588
  activeTopMargin = applied.activeTopMargin;
31119
31589
  activeBottomMargin = applied.activeBottomMargin;
31590
+ activeLeftMargin = applied.activeLeftMargin;
31591
+ activeRightMargin = applied.activeRightMargin;
31120
31592
  pendingTopMargin = applied.pendingTopMargin;
31121
31593
  pendingBottomMargin = applied.pendingBottomMargin;
31594
+ pendingLeftMargin = applied.pendingLeftMargin;
31595
+ pendingRightMargin = applied.pendingRightMargin;
31122
31596
  activeHeaderDistance = applied.activeHeaderDistance;
31123
31597
  activeFooterDistance = applied.activeFooterDistance;
31124
31598
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -31130,6 +31604,14 @@ function layoutDocument(blocks, measures, options = {}) {
31130
31604
  activeOrientation = applied.activeOrientation;
31131
31605
  pendingOrientation = applied.pendingOrientation;
31132
31606
  cachedColumnsState.state = null;
31607
+ paginatorMargins.left = activeLeftMargin;
31608
+ paginatorMargins.right = activeRightMargin;
31609
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31610
+ floatManager.setLayoutContext(
31611
+ normalizeColumns(activeColumns, contentWidth),
31612
+ { left: activeLeftMargin, right: activeRightMargin },
31613
+ activePageSize.w
31614
+ );
31133
31615
  if (pendingNumbering) {
31134
31616
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
31135
31617
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -31174,7 +31656,7 @@ function layoutDocument(blocks, measures, options = {}) {
31174
31656
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
31175
31657
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
31176
31658
  const getCurrentColumns = () => {
31177
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
31659
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31178
31660
  const state = states[states.length - 1] ?? null;
31179
31661
  const colsConfig = state ? getActiveColumnsForState(state) : activeColumns;
31180
31662
  const constraintIndex = state ? state.activeConstraintIndex : -1;
@@ -31207,6 +31689,12 @@ function layoutDocument(blocks, measures, options = {}) {
31207
31689
  layoutLog(` Current page: ${state.page.number}, cursorY: ${state.cursorY}`);
31208
31690
  activeColumns = newColumns;
31209
31691
  cachedColumnsState.state = null;
31692
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31693
+ floatManager.setLayoutContext(
31694
+ normalizeColumns(activeColumns, contentWidth),
31695
+ { left: activeLeftMargin, right: activeRightMargin },
31696
+ activePageSize.w
31697
+ );
31210
31698
  };
31211
31699
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
31212
31700
  const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
@@ -31238,10 +31726,10 @@ function layoutDocument(blocks, measures, options = {}) {
31238
31726
  if (alignV === "top") {
31239
31727
  anchorY = offsetV;
31240
31728
  } else if (alignV === "bottom") {
31241
- const pageHeight = contentBottom + margins.bottom;
31729
+ const pageHeight = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin);
31242
31730
  anchorY = pageHeight - imageHeight + offsetV;
31243
31731
  } else if (alignV === "center") {
31244
- const pageHeight = contentBottom + margins.bottom;
31732
+ const pageHeight = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin);
31245
31733
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
31246
31734
  } else {
31247
31735
  anchorY = offsetV;
@@ -31252,11 +31740,11 @@ function layoutDocument(blocks, measures, options = {}) {
31252
31740
  const anchorX = entry.block.anchor ? computeAnchorX(
31253
31741
  entry.block.anchor,
31254
31742
  state.columnIndex,
31255
- normalizeColumns(activeColumns, contentWidth),
31743
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
31256
31744
  entry.measure.width,
31257
- { left: margins.left, right: margins.right },
31745
+ { left: activeLeftMargin, right: activeRightMargin },
31258
31746
  activePageSize.w
31259
- ) : margins.left;
31747
+ ) : activeLeftMargin;
31260
31748
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
31261
31749
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state.page.number });
31262
31750
  }
@@ -31294,8 +31782,12 @@ function layoutDocument(blocks, measures, options = {}) {
31294
31782
  const sectionState = {
31295
31783
  activeTopMargin,
31296
31784
  activeBottomMargin,
31785
+ activeLeftMargin,
31786
+ activeRightMargin,
31297
31787
  pendingTopMargin,
31298
31788
  pendingBottomMargin,
31789
+ pendingLeftMargin,
31790
+ pendingRightMargin,
31299
31791
  activeHeaderDistance,
31300
31792
  activeFooterDistance,
31301
31793
  pendingHeaderDistance,
@@ -31329,8 +31821,12 @@ function layoutDocument(blocks, measures, options = {}) {
31329
31821
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
31330
31822
  activeTopMargin = updatedState.activeTopMargin;
31331
31823
  activeBottomMargin = updatedState.activeBottomMargin;
31824
+ activeLeftMargin = updatedState.activeLeftMargin;
31825
+ activeRightMargin = updatedState.activeRightMargin;
31332
31826
  pendingTopMargin = updatedState.pendingTopMargin;
31333
31827
  pendingBottomMargin = updatedState.pendingBottomMargin;
31828
+ pendingLeftMargin = updatedState.pendingLeftMargin;
31829
+ pendingRightMargin = updatedState.pendingRightMargin;
31334
31830
  activeHeaderDistance = updatedState.activeHeaderDistance;
31335
31831
  activeFooterDistance = updatedState.activeFooterDistance;
31336
31832
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -31468,8 +31964,8 @@ function layoutDocument(blocks, measures, options = {}) {
31468
31964
  pageMargins: {
31469
31965
  top: activeTopMargin,
31470
31966
  bottom: activeBottomMargin,
31471
- left: margins.left,
31472
- right: margins.right
31967
+ left: activeLeftMargin,
31968
+ right: activeRightMargin
31473
31969
  },
31474
31970
  columns: getCurrentColumns(),
31475
31971
  placedAnchoredIds
@@ -31491,9 +31987,9 @@ function layoutDocument(blocks, measures, options = {}) {
31491
31987
  const cols = getCurrentColumns();
31492
31988
  let maxWidth;
31493
31989
  if (relativeFrom === "page") {
31494
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
31990
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
31495
31991
  } else if (relativeFrom === "margin") {
31496
- maxWidth = activePageSize.w - margins.left - margins.right;
31992
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31497
31993
  } else {
31498
31994
  maxWidth = cols.width;
31499
31995
  }
@@ -31651,8 +32147,11 @@ function layoutHeaderFooter(blocks, measures, constraints) {
31651
32147
  throw new Error("layoutHeaderFooter: width must be positive");
31652
32148
  }
31653
32149
  if (!Number.isFinite(height) || height <= 0) {
31654
- throw new Error("layoutHeaderFooter: height must be positive");
32150
+ return { pages: [], height: 0 };
31655
32151
  }
32152
+ const maxBehindDocOverflow = Math.max(192, height * 4);
32153
+ const minBehindDocY = -maxBehindDocOverflow;
32154
+ const maxBehindDocY = height + maxBehindDocOverflow;
31656
32155
  const marginLeft = constraints.margins?.left ?? 0;
31657
32156
  const transformedBlocks = marginLeft > 0 ? blocks.map((block) => {
31658
32157
  const hasPageRelativeAnchor = (block.kind === "image" || block.kind === "drawing") && block.anchor?.hRelativeFrom === "page" && block.anchor.offsetH != null;
@@ -31683,6 +32182,18 @@ function layoutHeaderFooter(blocks, measures, constraints) {
31683
32182
  if (idx == null) continue;
31684
32183
  const block = blocks[idx];
31685
32184
  const measure = measures[idx];
32185
+ const isAnchoredFragment = (fragment.kind === "image" || fragment.kind === "drawing") && fragment.isAnchored === true;
32186
+ if (isAnchoredFragment) {
32187
+ if (block.kind !== "image" && block.kind !== "drawing") {
32188
+ throw new Error(
32189
+ `Type mismatch: fragment kind is ${fragment.kind} but block kind is ${block.kind} for block ${block.id}`
32190
+ );
32191
+ }
32192
+ const anchoredBlock = block;
32193
+ if (anchoredBlock.anchor?.behindDoc && (fragment.y < minBehindDocY || fragment.y > maxBehindDocY)) {
32194
+ continue;
32195
+ }
32196
+ }
31686
32197
  if (fragment.y < minY) minY = fragment.y;
31687
32198
  let bottom2 = fragment.y;
31688
32199
  if (fragment.kind === "para" && measure?.kind === "paragraph") {
@@ -32680,11 +33191,11 @@ function findWordBoundaries(blocks, pos) {
32680
33191
  if (text.length === 0) return null;
32681
33192
  const clampedPos = Math.max(0, Math.min(localPos, text.length));
32682
33193
  let wordStart = clampedPos;
32683
- while (wordStart > 0 && isWordChar(text[wordStart - 1])) {
33194
+ while (wordStart > 0 && isWordChar$2(text[wordStart - 1])) {
32684
33195
  wordStart--;
32685
33196
  }
32686
33197
  let wordEnd = clampedPos;
32687
- while (wordEnd < text.length && isWordChar(text[wordEnd])) {
33198
+ while (wordEnd < text.length && isWordChar$2(text[wordEnd])) {
32688
33199
  wordEnd++;
32689
33200
  }
32690
33201
  if (wordStart === wordEnd) {
@@ -32747,7 +33258,7 @@ function findBlockAtPosition(blocks, pos) {
32747
33258
  }
32748
33259
  return null;
32749
33260
  }
32750
- function isWordChar(char) {
33261
+ function isWordChar$2(char) {
32751
33262
  return /[\p{L}\p{N}_]/u.test(char);
32752
33263
  }
32753
33264
  function isWhitespace(char) {
@@ -32782,6 +33293,29 @@ function fontString(run) {
32782
33293
  function runText(run) {
32783
33294
  return "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
32784
33295
  }
33296
+ const isWordChar$1 = (char) => {
33297
+ if (!char) return false;
33298
+ const code = char.charCodeAt(0);
33299
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
33300
+ };
33301
+ const capitalizeText$1 = (text, fullText, startOffset) => {
33302
+ if (!text) return text;
33303
+ const hasFullText = typeof startOffset === "number" && fullText != null;
33304
+ let result = "";
33305
+ for (let i = 0; i < text.length; i += 1) {
33306
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
33307
+ const ch = text[i];
33308
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
33309
+ }
33310
+ return result;
33311
+ };
33312
+ const applyTextTransform$1 = (text, transform, fullText, startOffset) => {
33313
+ if (!text || !transform || transform === "none") return text;
33314
+ if (transform === "uppercase") return text.toUpperCase();
33315
+ if (transform === "lowercase") return text.toLowerCase();
33316
+ if (transform === "capitalize") return capitalizeText$1(text, fullText, startOffset);
33317
+ return text;
33318
+ };
32785
33319
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
32786
33320
  const TWIPS_PER_INCH$4 = 1440;
32787
33321
  const PX_PER_INCH$3 = 96;
@@ -32790,6 +33324,13 @@ const TAB_EPSILON$1 = 0.1;
32790
33324
  const WIDTH_FUDGE_PX = 0.5;
32791
33325
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
32792
33326
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
33327
+ const markerFontString = (run) => {
33328
+ const size2 = run?.fontSize ?? 16;
33329
+ const family = run?.fontFamily ?? "Arial";
33330
+ const italic = run?.italic ? "italic " : "";
33331
+ const bold = run?.bold ? "bold " : "";
33332
+ return `${italic}${bold}${size2}px ${family}`.trim();
33333
+ };
32793
33334
  const buildTabStopsPx$1 = (indent, tabs, tabIntervalTwips) => {
32794
33335
  const paragraphIndentTwips = {
32795
33336
  left: pxToTwips$1(Math.max(0, indent?.left ?? 0)),
@@ -32820,7 +33361,9 @@ const getNextTabStopPx$1 = (currentX, tabStops, startIndex) => {
32820
33361
  };
32821
33362
  function measureRunSliceWidth(run, fromChar, toChar) {
32822
33363
  const context = getCtx();
32823
- const text = runText(run).slice(fromChar, toChar);
33364
+ const fullText = runText(run);
33365
+ const transform = isTextRun$2(run) ? run.textTransform : void 0;
33366
+ const text = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
32824
33367
  if (!context) {
32825
33368
  const textRun = isTextRun$2(run) ? run : null;
32826
33369
  const size2 = textRun?.fontSize ?? 16;
@@ -32866,8 +33409,21 @@ function remeasureParagraph(block, maxWidth, firstLineIndent = 0) {
32866
33409
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
32867
33410
  const markerTextStartX = wordLayout?.marker?.textStartX;
32868
33411
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
32869
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
32870
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
33412
+ const resolvedTextStartPx = resolveListTextStartPx(
33413
+ wordLayout,
33414
+ indentLeft,
33415
+ indentFirstLine,
33416
+ indentHanging,
33417
+ (markerText, marker) => {
33418
+ const context = getCtx();
33419
+ if (!context) return 0;
33420
+ context.font = markerFontString(marker.run);
33421
+ return context.measureText(markerText).width;
33422
+ }
33423
+ );
33424
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
33425
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
33426
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
32871
33427
  const tabStops = buildTabStopsPx$1(indent, attrs?.tabs, attrs?.tabIntervalTwips);
32872
33428
  let currentRun = 0;
32873
33429
  let currentChar = 0;
@@ -33407,7 +33963,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33407
33963
  if (dirty.deletedBlockIds.length > 0) {
33408
33964
  measureCache.invalidate(dirty.deletedBlockIds);
33409
33965
  }
33410
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
33966
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
33411
33967
  if (measurementWidth <= 0 || measurementHeight <= 0) {
33412
33968
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
33413
33969
  }
@@ -33437,7 +33993,9 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33437
33993
  `[Perf] 4.1 Measure all blocks: ${(measureEnd - measureStart).toFixed(2)}ms (${cacheMisses} measured, ${cacheHits} cached)`
33438
33994
  );
33439
33995
  let headerContentHeights;
33440
- if (headerFooter?.constraints && headerFooter.headerBlocks) {
33996
+ const hasHeaderBlocks = headerFooter?.headerBlocks && Object.keys(headerFooter.headerBlocks).length > 0;
33997
+ const hasHeaderBlocksByRId = headerFooter?.headerBlocksByRId && headerFooter.headerBlocksByRId.size > 0;
33998
+ if (headerFooter?.constraints && (hasHeaderBlocks || hasHeaderBlocksByRId)) {
33441
33999
  const hfPreStart = performance.now();
33442
34000
  const measureFn = headerFooter.measure ?? measureBlock2;
33443
34001
  invalidateHeaderFooterCache(
@@ -33449,25 +34007,45 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33449
34007
  options.sectionMetadata
33450
34008
  );
33451
34009
  const HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
33452
- const preHeaderLayouts = await layoutHeaderFooterWithCache(
33453
- headerFooter.headerBlocks,
33454
- headerFooter.constraints,
33455
- measureFn,
33456
- headerMeasureCache,
33457
- HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
33458
- void 0
33459
- // No page resolver needed for height calculation
33460
- );
33461
34010
  const isValidHeaderType = (key2) => {
33462
34011
  return ["default", "first", "even", "odd"].includes(key2);
33463
34012
  };
33464
34013
  headerContentHeights = {};
33465
- for (const [type, value] of Object.entries(preHeaderLayouts)) {
33466
- if (!isValidHeaderType(type)) continue;
33467
- if (value?.layout && typeof value.layout.height === "number") {
33468
- const height = value.layout.height;
33469
- if (Number.isFinite(height) && height >= 0) {
33470
- headerContentHeights[type] = height;
34014
+ if (hasHeaderBlocks && headerFooter.headerBlocks) {
34015
+ const preHeaderLayouts = await layoutHeaderFooterWithCache(
34016
+ headerFooter.headerBlocks,
34017
+ headerFooter.constraints,
34018
+ measureFn,
34019
+ headerMeasureCache,
34020
+ HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
34021
+ void 0
34022
+ // No page resolver needed for height calculation
34023
+ );
34024
+ for (const [type, value] of Object.entries(preHeaderLayouts)) {
34025
+ if (!isValidHeaderType(type)) continue;
34026
+ if (value?.layout && typeof value.layout.height === "number") {
34027
+ const height = value.layout.height;
34028
+ if (Number.isFinite(height) && height >= 0) {
34029
+ headerContentHeights[type] = height;
34030
+ }
34031
+ }
34032
+ }
34033
+ }
34034
+ if (hasHeaderBlocksByRId && headerFooter.headerBlocksByRId) {
34035
+ for (const [_rId, blocks] of headerFooter.headerBlocksByRId) {
34036
+ if (!blocks || blocks.length === 0) continue;
34037
+ const measureConstraints = {
34038
+ maxWidth: headerFooter.constraints.width,
34039
+ maxHeight: headerFooter.constraints.height
34040
+ };
34041
+ const measures2 = await Promise.all(blocks.map((block) => measureFn(block, measureConstraints)));
34042
+ const layout2 = layoutHeaderFooter(blocks, measures2, {
34043
+ width: headerFooter.constraints.width,
34044
+ height: headerFooter.constraints.height
34045
+ });
34046
+ if (layout2.height > 0) {
34047
+ const currentDefault = headerContentHeights.default ?? 0;
34048
+ headerContentHeights.default = Math.max(currentDefault, layout2.height);
33471
34049
  }
33472
34050
  }
33473
34051
  }
@@ -33475,10 +34053,12 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33475
34053
  perfLog(`[Perf] 4.1.5 Pre-layout headers for height: ${(hfPreEnd - hfPreStart).toFixed(2)}ms`);
33476
34054
  }
33477
34055
  let footerContentHeights;
33478
- if (headerFooter?.constraints && headerFooter.footerBlocks) {
34056
+ const hasFooterBlocks = headerFooter?.footerBlocks && Object.keys(headerFooter.footerBlocks).length > 0;
34057
+ const hasFooterBlocksByRId = headerFooter?.footerBlocksByRId && headerFooter.footerBlocksByRId.size > 0;
34058
+ if (headerFooter?.constraints && (hasFooterBlocks || hasFooterBlocksByRId)) {
33479
34059
  const footerPreStart = performance.now();
33480
34060
  const measureFn = headerFooter.measure ?? measureBlock2;
33481
- if (!headerFooter.headerBlocks) {
34061
+ if (!hasHeaderBlocks && !hasHeaderBlocksByRId) {
33482
34062
  invalidateHeaderFooterCache(
33483
34063
  headerMeasureCache,
33484
34064
  headerFooterCacheState,
@@ -33489,26 +34069,46 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33489
34069
  );
33490
34070
  }
33491
34071
  const FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
34072
+ const isValidFooterType = (key2) => {
34073
+ return ["default", "first", "even", "odd"].includes(key2);
34074
+ };
34075
+ footerContentHeights = {};
33492
34076
  try {
33493
- const preFooterLayouts = await layoutHeaderFooterWithCache(
33494
- headerFooter.footerBlocks,
33495
- headerFooter.constraints,
33496
- measureFn,
33497
- headerMeasureCache,
33498
- FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
33499
- void 0
33500
- // No page resolver needed for height calculation
33501
- );
33502
- const isValidFooterType = (key2) => {
33503
- return ["default", "first", "even", "odd"].includes(key2);
33504
- };
33505
- footerContentHeights = {};
33506
- for (const [type, value] of Object.entries(preFooterLayouts)) {
33507
- if (!isValidFooterType(type)) continue;
33508
- if (value?.layout && typeof value.layout.height === "number") {
33509
- const height = value.layout.height;
33510
- if (Number.isFinite(height) && height >= 0) {
33511
- footerContentHeights[type] = height;
34077
+ if (hasFooterBlocks && headerFooter.footerBlocks) {
34078
+ const preFooterLayouts = await layoutHeaderFooterWithCache(
34079
+ headerFooter.footerBlocks,
34080
+ headerFooter.constraints,
34081
+ measureFn,
34082
+ headerMeasureCache,
34083
+ FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
34084
+ void 0
34085
+ // No page resolver needed for height calculation
34086
+ );
34087
+ for (const [type, value] of Object.entries(preFooterLayouts)) {
34088
+ if (!isValidFooterType(type)) continue;
34089
+ if (value?.layout && typeof value.layout.height === "number") {
34090
+ const height = value.layout.height;
34091
+ if (Number.isFinite(height) && height >= 0) {
34092
+ footerContentHeights[type] = height;
34093
+ }
34094
+ }
34095
+ }
34096
+ }
34097
+ if (hasFooterBlocksByRId && headerFooter.footerBlocksByRId) {
34098
+ for (const [_rId, blocks] of headerFooter.footerBlocksByRId) {
34099
+ if (!blocks || blocks.length === 0) continue;
34100
+ const measureConstraints = {
34101
+ maxWidth: headerFooter.constraints.width,
34102
+ maxHeight: headerFooter.constraints.height
34103
+ };
34104
+ const measures2 = await Promise.all(blocks.map((block) => measureFn(block, measureConstraints)));
34105
+ const layout2 = layoutHeaderFooter(blocks, measures2, {
34106
+ width: headerFooter.constraints.width,
34107
+ height: headerFooter.constraints.height
34108
+ });
34109
+ if (layout2.height > 0) {
34110
+ const currentDefault = footerContentHeights.default ?? 0;
34111
+ footerContentHeights.default = Math.max(currentDefault, layout2.height);
33512
34112
  }
33513
34113
  }
33514
34114
  }
@@ -33676,7 +34276,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33676
34276
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
33677
34277
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
33678
34278
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
33679
- function resolveMeasurementConstraints(options) {
34279
+ function resolveMeasurementConstraints(options, blocks) {
33680
34280
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
33681
34281
  const margins = {
33682
34282
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -33684,23 +34284,41 @@ function resolveMeasurementConstraints(options) {
33684
34284
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
33685
34285
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
33686
34286
  };
33687
- const contentWidth = pageSize.w - (margins.left + margins.right);
33688
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
33689
- const columns = options.columns;
33690
- if (columns && columns.count > 1) {
34287
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
34288
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
34289
+ const computeColumnWidth = (contentWidth, columns) => {
34290
+ if (!columns || columns.count <= 1) return contentWidth;
33691
34291
  const gap = Math.max(0, columns.gap ?? 0);
33692
34292
  const totalGap = gap * (columns.count - 1);
33693
- const columnWidth = (contentWidth - totalGap) / columns.count;
33694
- if (columnWidth > 0) {
33695
- return {
33696
- measurementWidth: columnWidth,
33697
- measurementHeight: contentHeight
34293
+ return (contentWidth - totalGap) / columns.count;
34294
+ };
34295
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
34296
+ let measurementHeight = baseContentHeight;
34297
+ if (blocks && blocks.length > 0) {
34298
+ for (const block of blocks) {
34299
+ if (block.kind !== "sectionBreak") continue;
34300
+ const sectionPageSize = block.pageSize ?? pageSize;
34301
+ const sectionMargins = {
34302
+ top: normalizeMargin(block.margins?.top, margins.top),
34303
+ right: normalizeMargin(block.margins?.right, margins.right),
34304
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
34305
+ left: normalizeMargin(block.margins?.left, margins.left)
33698
34306
  };
34307
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
34308
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
34309
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
34310
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
34311
+ if (columnWidth > measurementWidth) {
34312
+ measurementWidth = columnWidth;
34313
+ }
34314
+ if (contentHeight > measurementHeight) {
34315
+ measurementHeight = contentHeight;
34316
+ }
33699
34317
  }
33700
34318
  }
33701
34319
  return {
33702
- measurementWidth: contentWidth,
33703
- measurementHeight: contentHeight
34320
+ measurementWidth,
34321
+ measurementHeight
33704
34322
  };
33705
34323
  }
33706
34324
  const serializeHeaderFooterResults = (kind, batch) => {
@@ -36159,14 +36777,15 @@ function getAtomNodeTypes(schema) {
36159
36777
  if (!schema) return [];
36160
36778
  const types = [];
36161
36779
  try {
36162
- schema.nodes.forEach((nodeType, name) => {
36780
+ for (const name in schema.nodes) {
36163
36781
  if (name === "text") {
36164
- return;
36782
+ continue;
36165
36783
  }
36166
- if (nodeType.isAtom || nodeType.isLeaf) {
36784
+ const nodeType = schema.nodes[name];
36785
+ if (nodeType && (nodeType.isAtom || nodeType.isLeaf)) {
36167
36786
  types.push(name);
36168
36787
  }
36169
- });
36788
+ }
36170
36789
  } catch {
36171
36790
  return [];
36172
36791
  }
@@ -37569,6 +38188,7 @@ function shouldRequirePageBoundary(current, next) {
37569
38188
  function hasIntrinsicBoundarySignals(_) {
37570
38189
  return false;
37571
38190
  }
38191
+ const DEFAULT_HEADER_FOOTER_MARGIN_PX = 0;
37572
38192
  function shouldIgnoreSectionBreak(paragraph, index2, total, hasBodySectPr) {
37573
38193
  const paragraphAttrs = paragraph.attrs ?? {};
37574
38194
  const paragraphProperties = paragraphAttrs?.paragraphProperties;
@@ -37609,14 +38229,15 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
37609
38229
  const sectionData = extractSectionData(item.node);
37610
38230
  if (!sectionData) return;
37611
38231
  const sectPr = getSectPrFromNode(item.node);
38232
+ const hasAnyMargin = sectionData.headerPx != null || sectionData.footerPx != null || sectionData.topPx != null || sectionData.rightPx != null || sectionData.bottomPx != null || sectionData.leftPx != null;
37612
38233
  const range = {
37613
38234
  sectionIndex: idx,
37614
38235
  startParagraphIndex: currentStart,
37615
38236
  endParagraphIndex: item.index,
37616
38237
  sectPr,
37617
- margins: sectionData.headerPx != null || sectionData.footerPx != null ? {
37618
- header: sectionData.headerPx ?? 0,
37619
- footer: sectionData.footerPx ?? 0,
38238
+ margins: hasAnyMargin ? {
38239
+ header: sectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
38240
+ footer: sectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
37620
38241
  top: sectionData.topPx,
37621
38242
  right: sectionData.rightPx,
37622
38243
  bottom: sectionData.bottomPx,
@@ -37658,14 +38279,15 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
37658
38279
  };
37659
38280
  const bodySectionData = extractSectionData(tempNode);
37660
38281
  if (!bodySectionData) return null;
38282
+ const hasAnyMargin = bodySectionData.headerPx != null || bodySectionData.footerPx != null || bodySectionData.topPx != null || bodySectionData.rightPx != null || bodySectionData.bottomPx != null || bodySectionData.leftPx != null;
37661
38283
  return {
37662
38284
  sectionIndex,
37663
38285
  startParagraphIndex: currentStart,
37664
38286
  endParagraphIndex: totalParagraphs - 1,
37665
38287
  sectPr: bodySectPr,
37666
- margins: bodySectionData.headerPx != null || bodySectionData.footerPx != null ? {
37667
- header: bodySectionData.headerPx ?? 0,
37668
- footer: bodySectionData.footerPx ?? 0,
38288
+ margins: hasAnyMargin ? {
38289
+ header: bodySectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
38290
+ footer: bodySectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
37669
38291
  top: bodySectionData.topPx,
37670
38292
  right: bodySectionData.rightPx,
37671
38293
  bottom: bodySectionData.bottomPx,
@@ -38649,11 +39271,27 @@ const collectTrackedChangeFromMarks = (marks) => {
38649
39271
  }, void 0);
38650
39272
  };
38651
39273
  const normalizeUnderlineStyle = (value) => {
38652
- if (value === "none") {
38653
- return void 0;
39274
+ if (value === void 0 || value === null) {
39275
+ return "single";
38654
39276
  }
38655
- if (value === "double" || value === "dotted" || value === "dashed" || value === "wavy") {
38656
- return value;
39277
+ if (typeof value === "boolean") {
39278
+ return value ? "single" : void 0;
39279
+ }
39280
+ if (typeof value === "number") {
39281
+ return value === 0 ? void 0 : "single";
39282
+ }
39283
+ if (typeof value === "string") {
39284
+ const normalized = value.trim().toLowerCase();
39285
+ if (!normalized) {
39286
+ return "single";
39287
+ }
39288
+ if (normalized === "none" || normalized === "0" || normalized === "false" || normalized === "off") {
39289
+ return void 0;
39290
+ }
39291
+ if (normalized === "double" || normalized === "dotted" || normalized === "dashed" || normalized === "wavy") {
39292
+ return normalized;
39293
+ }
39294
+ return "single";
38657
39295
  }
38658
39296
  return "single";
38659
39297
  };
@@ -38805,13 +39443,16 @@ const applyMarksToRun = (run, marks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG,
38805
39443
  break;
38806
39444
  }
38807
39445
  case "underline": {
38808
- const style = normalizeUnderlineStyle(mark.attrs?.underlineType);
39446
+ const underlineValue = mark.attrs?.underlineType ?? mark.attrs?.value ?? mark.attrs?.underline ?? mark.attrs?.style;
39447
+ const style = normalizeUnderlineStyle(underlineValue);
38809
39448
  if (style) {
38810
39449
  const underlineColor = resolveColorFromAttributes(mark.attrs ?? {}, themeColors);
38811
39450
  run.underline = {
38812
39451
  style,
38813
39452
  color: underlineColor ?? run.underline?.color
38814
39453
  };
39454
+ } else if (underlineValue !== void 0 && underlineValue !== null) {
39455
+ delete run.underline;
38815
39456
  }
38816
39457
  break;
38817
39458
  }
@@ -39747,8 +40388,8 @@ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
39747
40388
  }
39748
40389
  return void 0;
39749
40390
  }
39750
- const DEFAULT_LIST_HANGING_PX$1 = 18;
39751
- const LIST_MARKER_GAP$1 = 8;
40391
+ const DEFAULT_LIST_HANGING_PX = 18;
40392
+ const LIST_MARKER_GAP = 8;
39752
40393
  const DEFAULT_BULLET_GLYPH = "•";
39753
40394
  const DEFAULT_DECIMAL_PATTERN = "%1.";
39754
40395
  const ASCII_UPPERCASE_A = 65;
@@ -40159,7 +40800,7 @@ function computeWordParagraphLayout(input) {
40159
40800
  let markerBoxWidthPx;
40160
40801
  let markerX;
40161
40802
  if (hasFirstLineIndent) {
40162
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
40803
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
40163
40804
  markerX = indentLeftPx + (firstLinePx ?? 0);
40164
40805
  layout.textStartPx = markerX + markerBoxWidthPx;
40165
40806
  layout.hangingPx = 0;
@@ -40259,12 +40900,12 @@ const resolveMarkerBoxWidth = (hangingPxRaw, glyphWidthPx) => {
40259
40900
  let markerBox = Math.max(hangingPxRaw || 0, 0);
40260
40901
  if (markerBox <= 0) {
40261
40902
  if (glyphWidthPx != null && glyphWidthPx > 0) {
40262
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
40903
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
40263
40904
  } else {
40264
- markerBox = DEFAULT_LIST_HANGING_PX$1;
40905
+ markerBox = DEFAULT_LIST_HANGING_PX;
40265
40906
  }
40266
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
40267
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
40907
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
40908
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
40268
40909
  }
40269
40910
  return markerBox;
40270
40911
  };
@@ -40284,7 +40925,7 @@ const buildMarkerLayout = ({
40284
40925
  textStartX: textStartPx,
40285
40926
  baselineOffsetPx: markerRun.baselineShift ?? 0,
40286
40927
  // Gutter is the small gap between marker and text, not the full marker box width
40287
- gutterWidthPx: LIST_MARKER_GAP$1,
40928
+ gutterWidthPx: LIST_MARKER_GAP,
40288
40929
  justification: numbering.lvlJc ?? "left",
40289
40930
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
40290
40931
  run: markerRun,
@@ -40374,7 +41015,10 @@ const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
40374
41015
  tabStops: cloneIfObject(resolvedExtended.tabStops),
40375
41016
  keepLines: resolvedExtended.keepLines,
40376
41017
  keepNext: resolvedExtended.keepNext,
40377
- numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties)
41018
+ numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties),
41019
+ // Extract contextualSpacing from style resolution - this is a sibling to spacing in OOXML,
41020
+ // not nested within it. When true, suppresses spacing between paragraphs of the same style.
41021
+ contextualSpacing: resolvedExtended.contextualSpacing
40378
41022
  };
40379
41023
  return hydrated;
40380
41024
  };
@@ -40976,6 +41620,31 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
40976
41620
  return null;
40977
41621
  }
40978
41622
  };
41623
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
41624
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
41625
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
41626
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
41627
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
41628
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
41629
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
41630
+ wordLayout.firstLineIndentMode = false;
41631
+ }
41632
+ if (wordLayout.firstLineIndentMode === true) {
41633
+ if (isFiniteNumber(wordLayout.textStartPx)) {
41634
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
41635
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
41636
+ }
41637
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
41638
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
41639
+ }
41640
+ } else {
41641
+ wordLayout.textStartPx = indentLeft;
41642
+ if (wordLayout.marker) {
41643
+ wordLayout.marker.textStartX = indentLeft;
41644
+ }
41645
+ }
41646
+ return wordLayout;
41647
+ };
40979
41648
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
40980
41649
  const attrs = para.attrs ?? {};
40981
41650
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -41084,7 +41753,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41084
41753
  paragraphAttrs.spacing.afterAutospacing = normalizedSpacing.afterAutospacing;
41085
41754
  }
41086
41755
  }
41087
- const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing");
41756
+ const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing") ?? hydrated?.contextualSpacing;
41088
41757
  if (contextualSpacingValue != null) {
41089
41758
  paragraphAttrs.contextualSpacing = isTruthy(contextualSpacingValue);
41090
41759
  }
@@ -41298,8 +41967,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41298
41967
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
41299
41968
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
41300
41969
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
41301
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
41302
- if (firstLinePx > 0) {
41970
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
41971
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
41972
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
41973
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
41974
+ if (firstLinePx > 0 && !hangingPx) {
41303
41975
  wordLayout = {
41304
41976
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
41305
41977
  firstLineIndentMode: true,
@@ -41307,10 +41979,13 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41307
41979
  };
41308
41980
  }
41309
41981
  }
41310
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
41982
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
41311
41983
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
41312
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
41313
- if (firstLinePx > 0) {
41984
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
41985
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
41986
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
41987
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
41988
+ if (firstLinePx > 0 && !hangingPx) {
41314
41989
  wordLayout = {
41315
41990
  ...wordLayout,
41316
41991
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -41330,6 +42005,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41330
42005
  wordLayout.marker.suffix = listRendering.suffix;
41331
42006
  }
41332
42007
  }
42008
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
41333
42009
  paragraphAttrs.wordLayout = wordLayout;
41334
42010
  }
41335
42011
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -45563,11 +46239,6 @@ function initHeaderFooterRegistry({
45563
46239
  cleanups
45564
46240
  };
45565
46241
  }
45566
- const LIST_MARKER_GAP = 8;
45567
- const MIN_MARKER_GUTTER = 24;
45568
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
45569
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
45570
- const DEFAULT_LIST_HANGING_PX = 18;
45571
46242
  function calculateRotatedBounds(input) {
45572
46243
  const width = Math.max(0, input.width);
45573
46244
  const height = Math.max(0, input.height);
@@ -45737,7 +46408,7 @@ function measureText(text, font, ctx2, _fontFamily, _letterSpacing) {
45737
46408
  return Math.max(advanceWidth, paintedWidth);
45738
46409
  }
45739
46410
  const MIN_SINGLE_LINE_PX = 12 * 96 / 72;
45740
- const LINE_HEIGHT_SAFETY_MARGIN_PX = 1;
46411
+ const WORD_SINGLE_LINE_SPACING_MULTIPLIER = 1.15;
45741
46412
  function calculateTypographyMetrics(fontSize, spacing, fontInfo) {
45742
46413
  let ascent;
45743
46414
  let descent;
@@ -45750,7 +46421,7 @@ function calculateTypographyMetrics(fontSize, spacing, fontInfo) {
45750
46421
  ascent = roundValue(fontSize * 0.8);
45751
46422
  descent = roundValue(fontSize * 0.2);
45752
46423
  }
45753
- const baseLineHeight = Math.max(ascent + descent + LINE_HEIGHT_SAFETY_MARGIN_PX, MIN_SINGLE_LINE_PX);
46424
+ const baseLineHeight = Math.max(fontSize * WORD_SINGLE_LINE_SPACING_MULTIPLIER, ascent + descent, MIN_SINGLE_LINE_PX);
45754
46425
  const lineHeight = roundValue(resolveLineHeight(spacing, baseLineHeight));
45755
46426
  return {
45756
46427
  ascent,
@@ -45831,8 +46502,25 @@ async function measureParagraphBlock(block, maxWidth) {
45831
46502
  const rawTextStartPx = wordLayout?.textStartPx;
45832
46503
  const markerTextStartX = wordLayout?.marker?.textStartX;
45833
46504
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
45834
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
45835
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
46505
+ const resolvedTextStartPx = resolveListTextStartPx(
46506
+ wordLayout,
46507
+ indentLeft,
46508
+ firstLine,
46509
+ hanging,
46510
+ (markerText, marker) => {
46511
+ const markerRun = {
46512
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
46513
+ fontSize: marker.run?.fontSize ?? 16,
46514
+ bold: marker.run?.bold ?? false,
46515
+ italic: marker.run?.italic ?? false
46516
+ };
46517
+ const { font: markerFont } = buildFontString(markerRun);
46518
+ return measureText(markerText, markerFont, ctx2);
46519
+ }
46520
+ );
46521
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
46522
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
46523
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
45836
46524
  } else {
45837
46525
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
45838
46526
  }
@@ -45919,7 +46607,7 @@ async function measureParagraphBlock(block, maxWidth) {
45919
46607
  pendingTabAlignment = null;
45920
46608
  return startX;
45921
46609
  };
45922
- const alignSegmentAtTab = (segmentText, font, runContext) => {
46610
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
45923
46611
  if (!pendingTabAlignment || !currentLine) return void 0;
45924
46612
  const { val } = pendingTabAlignment;
45925
46613
  let segmentWidth = 0;
@@ -45928,11 +46616,11 @@ async function measureParagraphBlock(block, maxWidth) {
45928
46616
  const idx = segmentText.indexOf(decimalSeparator);
45929
46617
  if (idx >= 0) {
45930
46618
  const beforeText = segmentText.slice(0, idx);
45931
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
46619
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
45932
46620
  }
45933
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
46621
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
45934
46622
  } else if (val === "end" || val === "center") {
45935
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
46623
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
45936
46624
  }
45937
46625
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
45938
46626
  };
@@ -45984,8 +46672,8 @@ async function measureParagraphBlock(block, maxWidth) {
45984
46672
  const { font } = buildFontString(
45985
46673
  lastRun
45986
46674
  );
45987
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
45988
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
46675
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
46676
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
45989
46677
  const delta = Math.max(0, fullWidth - keptWidth);
45990
46678
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
45991
46679
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -46196,7 +46884,8 @@ async function measureParagraphBlock(block, maxWidth) {
46196
46884
  continue;
46197
46885
  }
46198
46886
  if (isFieldAnnotationRun(run)) {
46199
- const displayText = run.displayLabel || "";
46887
+ const rawDisplayText = run.displayLabel || "";
46888
+ const displayText = applyTextTransform(rawDisplayText, run);
46200
46889
  const annotationFontSize = typeof run.fontSize === "number" ? run.fontSize : typeof run.fontSize === "string" ? parseFloat(run.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
46201
46890
  const annotationFontFamily = run.fontFamily || "Arial, sans-serif";
46202
46891
  const fontWeight = run.bold ? "bold" : "normal";
@@ -46299,7 +46988,7 @@ async function measureParagraphBlock(block, maxWidth) {
46299
46988
  const spacesLength = segment.length;
46300
46989
  const spacesStartChar = charPosInRun;
46301
46990
  const spacesEndChar = charPosInRun + spacesLength;
46302
- const spacesWidth = measureRunWidth(segment, font, ctx2, run);
46991
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run, spacesStartChar);
46303
46992
  if (!currentLine) {
46304
46993
  currentLine = {
46305
46994
  fromRun: runIndex,
@@ -46363,7 +47052,7 @@ async function measureParagraphBlock(block, maxWidth) {
46363
47052
  }
46364
47053
  let segmentStartX;
46365
47054
  if (currentLine && pendingTabAlignment) {
46366
- segmentStartX = alignSegmentAtTab(segment, font, run);
47055
+ segmentStartX = alignSegmentAtTab(segment, font, run, charPosInRun);
46367
47056
  if (segmentStartX == null) {
46368
47057
  segmentStartX = currentLine.width;
46369
47058
  }
@@ -46373,7 +47062,7 @@ async function measureParagraphBlock(block, maxWidth) {
46373
47062
  if (word2 === "") {
46374
47063
  const spaceStartChar = charPosInRun;
46375
47064
  const spaceEndChar = charPosInRun + 1;
46376
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run);
47065
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run, spaceStartChar);
46377
47066
  if (!currentLine) {
46378
47067
  currentLine = {
46379
47068
  fromRun: runIndex,
@@ -46424,12 +47113,12 @@ async function measureParagraphBlock(block, maxWidth) {
46424
47113
  charPosInRun = spaceEndChar;
46425
47114
  continue;
46426
47115
  }
46427
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run);
46428
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
46429
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run) : 0;
46430
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
46431
47116
  const wordStartChar = charPosInRun;
47117
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run, wordStartChar);
47118
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
46432
47119
  const wordEndNoSpace = charPosInRun + word2.length;
47120
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run, wordEndNoSpace) : 0;
47121
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
46433
47122
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
46434
47123
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
46435
47124
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -46448,7 +47137,7 @@ async function measureParagraphBlock(block, maxWidth) {
46448
47137
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
46449
47138
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
46450
47139
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
46451
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run);
47140
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run, wordStartChar);
46452
47141
  let chunkCharOffset = wordStartChar;
46453
47142
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
46454
47143
  const chunk = chunks[chunkIndex];
@@ -46550,6 +47239,10 @@ async function measureParagraphBlock(block, maxWidth) {
46550
47239
  currentLine.width = roundValue(currentLine.width + spaceWidth + ls);
46551
47240
  charPosInRun = wordEndWithSpace;
46552
47241
  currentLine.spaceCount += 1;
47242
+ if (currentLine.segments?.[0]) {
47243
+ currentLine.segments[0].toChar = wordEndWithSpace;
47244
+ currentLine.segments[0].width += spaceWidth;
47245
+ }
46553
47246
  } else {
46554
47247
  charPosInRun = wordEndWithSpace;
46555
47248
  }
@@ -46572,7 +47265,7 @@ async function measureParagraphBlock(block, maxWidth) {
46572
47265
  if (candidateSpaces > 0) {
46573
47266
  const overflow = totalWidthWithWord - availableWidth;
46574
47267
  if (overflow > 0) {
46575
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run) || Math.max(1, boundarySpacing);
47268
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run, wordEndNoSpace) || Math.max(1, boundarySpacing);
46576
47269
  const perSpaceCompression = overflow / candidateSpaces;
46577
47270
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
46578
47271
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -46612,6 +47305,10 @@ async function measureParagraphBlock(block, maxWidth) {
46612
47305
  currentLine.width = roundValue(currentLine.width + spaceWidth + (run.letterSpacing ?? 0));
46613
47306
  charPosInRun = wordEndWithSpace;
46614
47307
  currentLine.spaceCount += 1;
47308
+ if (currentLine.segments?.[0]) {
47309
+ currentLine.segments[0].toChar = wordEndWithSpace;
47310
+ currentLine.segments[0].width += spaceWidth;
47311
+ }
46615
47312
  } else {
46616
47313
  charPosInRun = wordEndWithSpace;
46617
47314
  }
@@ -46747,8 +47444,8 @@ async function measureParagraphBlock(block, maxWidth) {
46747
47444
  const { font: markerFont } = buildFontString(markerRun);
46748
47445
  const markerText = wordLayout.marker.markerText ?? "";
46749
47446
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
46750
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
46751
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
47447
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
47448
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
46752
47449
  markerInfo = {
46753
47450
  markerWidth: markerBoxWidth,
46754
47451
  markerTextWidth: glyphWidth,
@@ -47092,7 +47789,7 @@ async function measureListBlock(block, constraints) {
47092
47789
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
47093
47790
  indentLeft = resolveIndentLeft(item);
47094
47791
  const indentHanging = resolveIndentHanging(item);
47095
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
47792
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
47096
47793
  }
47097
47794
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
47098
47795
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -47118,16 +47815,46 @@ const getPrimaryRun = (paragraph) => {
47118
47815
  fontSize: 16
47119
47816
  };
47120
47817
  };
47121
- const measureRunWidth = (text, font, ctx2, run) => {
47818
+ const isWordChar = (char) => {
47819
+ if (!char) return false;
47820
+ const code = char.charCodeAt(0);
47821
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
47822
+ };
47823
+ const capitalizeText = (text, fullText, startOffset) => {
47824
+ if (!text) return text;
47825
+ const hasFullText = typeof startOffset === "number" && fullText != null;
47826
+ let result = "";
47827
+ for (let i = 0; i < text.length; i += 1) {
47828
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
47829
+ const ch = text[i];
47830
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
47831
+ }
47832
+ return result;
47833
+ };
47834
+ const applyTextTransform = (text, run, startOffset) => {
47835
+ const transform = "textTransform" in run ? run.textTransform : void 0;
47836
+ if (!text || !transform || transform === "none") return text;
47837
+ if (transform === "uppercase") return text.toUpperCase();
47838
+ if (transform === "lowercase") return text.toLowerCase();
47839
+ if (transform === "capitalize") {
47840
+ const fullText = "text" in run && typeof run.text === "string" ? run.text : text;
47841
+ return capitalizeText(text, fullText, startOffset);
47842
+ }
47843
+ return text;
47844
+ };
47845
+ const measureRunWidth = (text, font, ctx2, run, startOffset) => {
47122
47846
  const letterSpacing = run.kind === "text" || run.kind === void 0 ? run.letterSpacing || 0 : 0;
47123
- const width = getMeasuredTextWidth(text, font, letterSpacing, ctx2);
47847
+ const displayText = applyTextTransform(text, run, startOffset);
47848
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
47124
47849
  return roundValue(width);
47125
47850
  };
47126
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run) => {
47851
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run, startOffset) => {
47127
47852
  const chunks = [];
47853
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
47128
47854
  if (maxWidth <= 0) {
47129
- for (const char of word2) {
47130
- const charWidth = measureRunWidth(char, font, ctx2, run);
47855
+ for (let i = 0; i < word2.length; i++) {
47856
+ const char = word2[i];
47857
+ const charWidth = measureRunWidth(char, font, ctx2, run, baseOffset + i);
47131
47858
  chunks.push({ text: char, width: charWidth });
47132
47859
  }
47133
47860
  return chunks;
@@ -47137,11 +47864,11 @@ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run) => {
47137
47864
  for (let i = 0; i < word2.length; i++) {
47138
47865
  const char = word2[i];
47139
47866
  const testChunk = currentChunk + char;
47140
- const testWidth = measureRunWidth(testChunk, font, ctx2, run);
47867
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run, baseOffset);
47141
47868
  if (testWidth > maxWidth && currentChunk.length > 0) {
47142
47869
  chunks.push({ text: currentChunk, width: currentWidth });
47143
47870
  currentChunk = char;
47144
- currentWidth = measureRunWidth(char, font, ctx2, run);
47871
+ currentWidth = measureRunWidth(char, font, ctx2, run, baseOffset + i);
47145
47872
  } else {
47146
47873
  currentChunk = testChunk;
47147
47874
  currentWidth = testWidth;
@@ -47195,12 +47922,13 @@ const measureDropCap = (ctx2, descriptor, spacing) => {
47195
47922
  italic: run.italic
47196
47923
  });
47197
47924
  ctx2.font = font;
47198
- const metrics = ctx2.measureText(run.text);
47925
+ const displayText = applyTextTransform(run.text, run);
47926
+ const metrics = ctx2.measureText(displayText);
47199
47927
  const advanceWidth = metrics.width;
47200
47928
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
47201
47929
  const textWidth = Math.max(advanceWidth, paintedWidth);
47202
47930
  const width = roundValue(textWidth + DROP_CAP_PADDING_PX);
47203
- const baseLineHeight = resolveLineHeight(spacing, run.fontSize * 1.2);
47931
+ const baseLineHeight = resolveLineHeight(spacing, run.fontSize * WORD_SINGLE_LINE_SPACING_MULTIPLIER);
47204
47932
  const height = roundValue(baseLineHeight * lines);
47205
47933
  return {
47206
47934
  width,
@@ -47221,7 +47949,7 @@ const resolveIndentHanging = (item) => {
47221
47949
  if (indentHanging > 0) {
47222
47950
  return indentHanging;
47223
47951
  }
47224
- return DEFAULT_LIST_HANGING_PX;
47952
+ return DEFAULT_LIST_HANGING_PX$1;
47225
47953
  };
47226
47954
  const buildTabStopsPx = (indent, tabs, tabIntervalTwips) => {
47227
47955
  const paragraphIndentTwips = {
@@ -47443,6 +48171,9 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
47443
48171
  if (event.button !== 0) {
47444
48172
  return;
47445
48173
  }
48174
+ if (event.ctrlKey && navigator.platform.includes("Mac")) {
48175
+ return;
48176
+ }
47446
48177
  __privateSet(this, _pendingMarginClick, null);
47447
48178
  const target = event.target;
47448
48179
  if (target?.closest?.(".superdoc-ruler-handle") != null) {
@@ -47939,6 +48670,10 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
47939
48670
  __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
47940
48671
  return;
47941
48672
  }
48673
+ if (__privateGet(this, _documentMode) === "viewing") {
48674
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
48675
+ return;
48676
+ }
47942
48677
  const region = __privateMethod(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, normalized.x, normalized.y);
47943
48678
  if (!region) {
47944
48679
  __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
@@ -48167,6 +48902,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
48167
48902
  __privateSet(this, _visibleHost, options.element);
48168
48903
  __privateGet(this, _visibleHost).innerHTML = "";
48169
48904
  __privateGet(this, _visibleHost).classList.add("presentation-editor");
48905
+ __privateMethod(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
48170
48906
  if (!__privateGet(this, _visibleHost).hasAttribute("tabindex")) {
48171
48907
  __privateGet(this, _visibleHost).tabIndex = 0;
48172
48908
  }
@@ -48662,6 +49398,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
48662
49398
  }
48663
49399
  __privateSet(this, _documentMode, mode);
48664
49400
  __privateGet(this, _editor3).setDocumentMode(mode);
49401
+ __privateMethod(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
48665
49402
  __privateMethod(this, _PresentationEditor_instances, syncHiddenEditorA11yAttributes_fn).call(this);
48666
49403
  const trackedChangesChanged = __privateMethod(this, _PresentationEditor_instances, syncTrackedChangesPreferences_fn).call(this);
48667
49404
  if (trackedChangesChanged) {
@@ -49601,6 +50338,10 @@ wrapHiddenEditorFocus_fn = function() {
49601
50338
  }
49602
50339
  };
49603
50340
  };
50341
+ syncDocumentModeClass_fn = function() {
50342
+ if (!__privateGet(this, _visibleHost)) return;
50343
+ __privateGet(this, _visibleHost).classList.toggle("presentation-editor--viewing", __privateGet(this, _documentMode) === "viewing");
50344
+ };
49604
50345
  /**
49605
50346
  * Collect all comment and tracked change positions from the PM document.
49606
50347
  *
@@ -50505,7 +51246,7 @@ rerender_fn = async function() {
50505
51246
  const atomNodeTypes = getAtomNodeTypes(__privateGet(this, _editor3)?.schema ?? null);
50506
51247
  const positionMap = __privateGet(this, _editor3)?.state?.doc && docJson ? buildPositionMapFromPmDoc(__privateGet(this, _editor3).state.doc, docJson) : null;
50507
51248
  const result = toFlowBlocks(docJson, {
50508
- mediaFiles: __privateGet(this, _options).mediaFiles,
51249
+ mediaFiles: __privateGet(this, _editor3)?.storage?.image?.media,
50509
51250
  emitSectionBreaks: true,
50510
51251
  sectionMetadata,
50511
51252
  trackedChangesMode: __privateGet(this, _trackedChangesMode),
@@ -50862,7 +51603,14 @@ computeHeaderFooterConstraints_fn = function() {
50862
51603
  const footerMargin = margins.footer ?? 0;
50863
51604
  const headerContentSpace = Math.max(marginTop - headerMargin, 0);
50864
51605
  const footerContentSpace = Math.max(marginBottom - footerMargin, 0);
50865
- const height = Math.max(headerContentSpace, footerContentSpace, 1);
51606
+ const height = Math.max(
51607
+ headerContentSpace,
51608
+ footerContentSpace,
51609
+ headerMargin,
51610
+ footerMargin,
51611
+ marginTop,
51612
+ marginBottom
51613
+ );
50866
51614
  return {
50867
51615
  width: measurementWidth,
50868
51616
  height,
@@ -51030,7 +51778,8 @@ computeDecorationBox_fn = function(kind, pageMargins, pageHeight) {
51030
51778
  const headerMargin = margins.header ?? 0;
51031
51779
  const topMargin = margins.top ?? DEFAULT_MARGINS.top ?? 0;
51032
51780
  const height = Math.max(topMargin - headerMargin, 1);
51033
- return { x: left2, width, height, offset: headerMargin };
51781
+ const offset2 = headerMargin;
51782
+ return { x: left2, width, height, offset: offset2 };
51034
51783
  } else {
51035
51784
  const footerMargin = margins.footer ?? 0;
51036
51785
  const bottomMargin = margins.bottom ?? DEFAULT_MARGINS.bottom ?? 0;
@@ -51709,6 +52458,10 @@ renderCellSelectionOverlay_fn = function(selection, layout) {
51709
52458
  });
51710
52459
  };
51711
52460
  renderHoverRegion_fn = function(region) {
52461
+ if (__privateGet(this, _documentMode) === "viewing") {
52462
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
52463
+ return;
52464
+ }
51712
52465
  if (!__privateGet(this, _hoverOverlay) || !__privateGet(this, _hoverTooltip)) return;
51713
52466
  const coords = __privateMethod(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, region.pageIndex, region.localX, region.localY);
51714
52467
  if (!coords) {
@@ -53368,6 +54121,8 @@ const SlashMenu = Extension.create({
53368
54121
  const cbRect = containingBlock.getBoundingClientRect();
53369
54122
  left2 -= cbRect.left;
53370
54123
  top2 -= cbRect.top;
54124
+ left2 += containingBlock.scrollLeft || 0;
54125
+ top2 += containingBlock.scrollTop || 0;
53371
54126
  } catch (error) {
53372
54127
  console.warn("SlashMenu: Failed to adjust for containing block", error);
53373
54128
  }
@@ -69372,7 +70127,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
69372
70127
  document.addEventListener("mousedown", globalMousedownHandler);
69373
70128
  scrollHandler = () => {
69374
70129
  if (currentWrapper && resizeContainer) {
69375
- updateHandlePositions(currentWrapper.firstElementChild);
70130
+ updateHandlePositions(currentWrapper);
69376
70131
  }
69377
70132
  };
69378
70133
  window.addEventListener("scroll", scrollHandler, true);
@@ -69434,7 +70189,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
69434
70189
  }
69435
70190
  applyStyleIsolationClass(resizeContainer);
69436
70191
  document.body.appendChild(resizeContainer);
69437
- updateHandlePositions(wrapper.firstElementChild);
70192
+ updateHandlePositions(wrapper);
69438
70193
  }
69439
70194
  function hideResizeHandles() {
69440
70195
  if (resizeContainer?.parentNode) {