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

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-Y5Q3KpNr.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-C4xgIIbF.es.js → PdfViewer-ag_ZFG_a.es.js} +1 -1
  3. package/dist/chunks/{index-BY-3Vl72.cjs → index-CWNzyoyI.cjs} +4 -6
  4. package/dist/chunks/{index-s9GUR_Gc.es.js → index-Dymes5hN.es.js} +4 -6
  5. package/dist/chunks/{index-BqPa6D4q-8U4x8RP6.es.js → index-XnRj2biz-CWqMvtJZ.es.js} +1 -1
  6. package/dist/chunks/{index-BqPa6D4q-Dulj8zfc.cjs → index-XnRj2biz-DiLIwrZX.cjs} +1 -1
  7. package/dist/chunks/{super-editor.es-CT28vUbx.es.js → super-editor.es-BBUBeVVw.es.js} +950 -202
  8. package/dist/chunks/{super-editor.es-BM-ulSRj.cjs → super-editor.es-DwEkOdPH.cjs} +950 -202
  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-CFpzAUl1.js} +49 -9
  17. package/dist/super-editor/chunks/{docx-zipper-B2VXuf8h.js → docx-zipper-B4U-khNy.js} +1 -1
  18. package/dist/super-editor/chunks/{editor-B4Q_tNET.js → editor-CUCVDSiG.js} +894 -196
  19. package/dist/super-editor/chunks/{index-BqPa6D4q.js → index-XnRj2biz.js} +1 -1
  20. package/dist/super-editor/chunks/{toolbar-BD-lDCLr.js → toolbar-DXUz-ZeU.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 +953 -207
  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-CFpzAUl1.js";
16
+ import { D as DocxZipper } from "./docx-zipper-B4U-khNy.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.20";
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-XnRj2biz.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.20");
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 };
@@ -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
  }
@@ -30059,6 +30396,94 @@ function getCellPadding(cellIdx, blockRow) {
30059
30396
  function getCellTotalLines(cell) {
30060
30397
  return getCellLines(cell).length;
30061
30398
  }
30399
+ function mergePmRange(target, range) {
30400
+ if (typeof range.pmStart === "number") {
30401
+ target.pmStart = target.pmStart == null ? range.pmStart : Math.min(target.pmStart, range.pmStart);
30402
+ }
30403
+ if (typeof range.pmEnd === "number") {
30404
+ target.pmEnd = target.pmEnd == null ? range.pmEnd : Math.max(target.pmEnd, range.pmEnd);
30405
+ }
30406
+ }
30407
+ function computeCellPmRange(cell, cellMeasure, fromLine, toLine) {
30408
+ const range = {};
30409
+ if (!cell || !cellMeasure) return range;
30410
+ const cellBlocks = cell.blocks ?? (cell.paragraph ? [cell.paragraph] : []);
30411
+ const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
30412
+ const maxBlocks = Math.min(cellBlocks.length, blockMeasures.length);
30413
+ let cumulativeLineCount = 0;
30414
+ for (let i = 0; i < maxBlocks; i++) {
30415
+ const block = cellBlocks[i];
30416
+ const blockMeasure = blockMeasures[i];
30417
+ if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
30418
+ const paraMeasure = blockMeasure;
30419
+ const lines = paraMeasure.lines;
30420
+ const blockLineCount = lines?.length ?? 0;
30421
+ const blockStartGlobal = cumulativeLineCount;
30422
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
30423
+ const localFrom = Math.max(fromLine, blockStartGlobal) - blockStartGlobal;
30424
+ const localTo = Math.min(toLine, blockEndGlobal) - blockStartGlobal;
30425
+ if (lines && lines.length > 0 && localFrom < localTo) {
30426
+ mergePmRange(range, computeFragmentPmRange(block, lines, localFrom, localTo));
30427
+ } else {
30428
+ mergePmRange(range, extractBlockPmRange(block));
30429
+ }
30430
+ cumulativeLineCount += blockLineCount;
30431
+ continue;
30432
+ }
30433
+ mergePmRange(range, extractBlockPmRange(block));
30434
+ }
30435
+ return range;
30436
+ }
30437
+ function computeTableFragmentPmRange(block, measure, fromRow, toRow, partialRow) {
30438
+ const range = {};
30439
+ for (let rowIndex = fromRow; rowIndex < toRow; rowIndex++) {
30440
+ const row = block.rows[rowIndex];
30441
+ const rowMeasure = measure.rows[rowIndex];
30442
+ if (!row || !rowMeasure) continue;
30443
+ const isPartial = partialRow?.rowIndex === rowIndex;
30444
+ const cellCount = Math.min(row.cells.length, rowMeasure.cells.length);
30445
+ for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
30446
+ const cell = row.cells[cellIndex];
30447
+ const cellMeasure = rowMeasure.cells[cellIndex];
30448
+ if (!cell || !cellMeasure) continue;
30449
+ const totalLines = getCellTotalLines(cellMeasure);
30450
+ let fromLine = 0;
30451
+ let toLine = totalLines;
30452
+ if (isPartial) {
30453
+ const hasValidFromLineByCell = partialRow?.fromLineByCell && cellIndex < partialRow.fromLineByCell.length;
30454
+ const hasValidToLineByCell = partialRow?.toLineByCell && cellIndex < partialRow.toLineByCell.length;
30455
+ if (hasValidFromLineByCell) {
30456
+ const rawFrom = partialRow.fromLineByCell[cellIndex];
30457
+ if (typeof rawFrom === "number" && rawFrom >= 0) {
30458
+ fromLine = rawFrom;
30459
+ }
30460
+ }
30461
+ if (hasValidToLineByCell) {
30462
+ const rawTo = partialRow.toLineByCell[cellIndex];
30463
+ if (typeof rawTo === "number") {
30464
+ toLine = rawTo === -1 ? totalLines : rawTo;
30465
+ }
30466
+ }
30467
+ }
30468
+ fromLine = Math.max(0, Math.min(fromLine, totalLines));
30469
+ toLine = Math.max(0, Math.min(toLine, totalLines));
30470
+ if (toLine < fromLine) {
30471
+ toLine = fromLine;
30472
+ }
30473
+ mergePmRange(range, computeCellPmRange(cell, cellMeasure, fromLine, toLine));
30474
+ }
30475
+ }
30476
+ return range;
30477
+ }
30478
+ function applyTableFragmentPmRange(fragment, block, measure) {
30479
+ const range = computeTableFragmentPmRange(block, measure, fragment.fromRow, fragment.toRow, fragment.partialRow);
30480
+ if (range.pmStart != null) {
30481
+ fragment.pmStart = range.pmStart;
30482
+ }
30483
+ if (range.pmEnd != null) {
30484
+ fragment.pmEnd = range.pmEnd;
30485
+ }
30486
+ }
30062
30487
  function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
30063
30488
  const row = measure.rows[rowIndex];
30064
30489
  if (!row) {
@@ -30203,6 +30628,7 @@ function layoutMonolithicTable(context) {
30203
30628
  height,
30204
30629
  metadata
30205
30630
  };
30631
+ applyTableFragmentPmRange(fragment, context.block, context.measure);
30206
30632
  state.page.fragments.push(fragment);
30207
30633
  state.cursorY += height;
30208
30634
  }
@@ -30281,6 +30707,7 @@ function layoutTableBlock({
30281
30707
  height,
30282
30708
  metadata
30283
30709
  };
30710
+ applyTableFragmentPmRange(fragment, block, measure);
30284
30711
  state.page.fragments.push(fragment);
30285
30712
  state.cursorY += height;
30286
30713
  return;
@@ -30344,6 +30771,7 @@ function layoutTableBlock({
30344
30771
  partialRow: continuationPartialRow,
30345
30772
  metadata: generateFragmentMetadata(measure)
30346
30773
  };
30774
+ applyTableFragmentPmRange(fragment2, block, measure);
30347
30775
  state.page.fragments.push(fragment2);
30348
30776
  state.cursorY += fragmentHeight2;
30349
30777
  }
@@ -30388,6 +30816,7 @@ function layoutTableBlock({
30388
30816
  partialRow: forcedPartialRow,
30389
30817
  metadata: generateFragmentMetadata(measure)
30390
30818
  };
30819
+ applyTableFragmentPmRange(fragment2, block, measure);
30391
30820
  state.page.fragments.push(fragment2);
30392
30821
  state.cursorY += fragmentHeight2;
30393
30822
  pendingPartialRow = forcedPartialRow;
@@ -30423,6 +30852,7 @@ function layoutTableBlock({
30423
30852
  partialRow: partialRow || void 0,
30424
30853
  metadata: generateFragmentMetadata(measure)
30425
30854
  };
30855
+ applyTableFragmentPmRange(fragment, block, measure);
30426
30856
  state.page.fragments.push(fragment);
30427
30857
  state.cursorY += fragmentHeight;
30428
30858
  if (partialRow && !partialRow.isLastPart) {
@@ -30440,7 +30870,7 @@ function createAnchoredTableFragment(block, measure, x, y) {
30440
30870
  columnBoundaries: generateColumnBoundaries(measure),
30441
30871
  coordinateSystem: "fragment"
30442
30872
  };
30443
- return {
30873
+ const fragment = {
30444
30874
  kind: "table",
30445
30875
  blockId: block.id,
30446
30876
  fromRow: 0,
@@ -30451,6 +30881,8 @@ function createAnchoredTableFragment(block, measure, x, y) {
30451
30881
  height: measure.totalHeight ?? 0,
30452
30882
  metadata
30453
30883
  };
30884
+ applyTableFragmentPmRange(fragment, block, measure);
30885
+ return fragment;
30454
30886
  }
30455
30887
  function isPageRelativeAnchor(block) {
30456
30888
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -30872,8 +31304,8 @@ function layoutDocument(blocks, measures, options = {}) {
30872
31304
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
30873
31305
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
30874
31306
  };
30875
- const contentWidth = pageSize.w - (margins.left + margins.right);
30876
- if (contentWidth <= 0) {
31307
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
31308
+ if (baseContentWidth <= 0) {
30877
31309
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
30878
31310
  }
30879
31311
  const validateContentHeight = (height) => {
@@ -30903,8 +31335,12 @@ function layoutDocument(blocks, measures, options = {}) {
30903
31335
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
30904
31336
  let activeTopMargin = effectiveTopMargin;
30905
31337
  let activeBottomMargin = effectiveBottomMargin;
31338
+ let activeLeftMargin = margins.left;
31339
+ let activeRightMargin = margins.right;
30906
31340
  let pendingTopMargin = null;
30907
31341
  let pendingBottomMargin = null;
31342
+ let pendingLeftMargin = null;
31343
+ let pendingRightMargin = null;
30908
31344
  let activeHeaderDistance = margins.header ?? margins.top;
30909
31345
  let pendingHeaderDistance = null;
30910
31346
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -30917,10 +31353,11 @@ function layoutDocument(blocks, measures, options = {}) {
30917
31353
  let pendingOrientation = null;
30918
31354
  let activeVAlign = null;
30919
31355
  let pendingVAlign = null;
31356
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
30920
31357
  const floatManager = createFloatingObjectManager(
30921
- normalizeColumns(activeColumns, contentWidth),
30922
- { left: margins.left, right: margins.right },
30923
- pageSize.w
31358
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
31359
+ { left: activeLeftMargin, right: activeRightMargin },
31360
+ activePageSize.w
30924
31361
  );
30925
31362
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks);
30926
31363
  const scheduleSectionBreakCompat = (block, state, baseMargins) => {
@@ -30937,22 +31374,38 @@ function layoutDocument(blocks, measures, options = {}) {
30937
31374
  next.activeOrientation = block.orientation;
30938
31375
  next.pendingOrientation = null;
30939
31376
  }
31377
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
31378
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
31379
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
31380
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
30940
31381
  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;
31382
+ next.activeHeaderDistance = headerDistance2;
31383
+ next.pendingHeaderDistance = headerDistance2;
30947
31384
  }
30948
31385
  if (block.margins?.footer !== void 0) {
30949
- const footerDistance2 = Math.max(0, block.margins.footer);
30950
31386
  next.activeFooterDistance = footerDistance2;
30951
31387
  next.pendingFooterDistance = footerDistance2;
31388
+ }
31389
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
31390
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
31391
+ next.activeTopMargin = Math.max(sectionTop, requiredTop);
31392
+ next.pendingTopMargin = next.activeTopMargin;
31393
+ }
31394
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
30952
31395
  const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
30953
- next.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
31396
+ next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
30954
31397
  next.pendingBottomMargin = next.activeBottomMargin;
30955
31398
  }
31399
+ if (block.margins?.left !== void 0) {
31400
+ const leftMargin = Math.max(0, block.margins.left);
31401
+ next.activeLeftMargin = leftMargin;
31402
+ next.pendingLeftMargin = leftMargin;
31403
+ }
31404
+ if (block.margins?.right !== void 0) {
31405
+ const rightMargin = Math.max(0, block.margins.right);
31406
+ next.activeRightMargin = rightMargin;
31407
+ next.pendingRightMargin = rightMargin;
31408
+ }
30956
31409
  if (block.columns) {
30957
31410
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
30958
31411
  next.pendingColumns = null;
@@ -30981,27 +31434,35 @@ function layoutDocument(blocks, measures, options = {}) {
30981
31434
  const headerPx = block.margins?.header;
30982
31435
  const footerPx = block.margins?.footer;
30983
31436
  const topPx = block.margins?.top;
31437
+ const bottomPx = block.margins?.bottom;
31438
+ const leftPx = block.margins?.left;
31439
+ const rightPx = block.margins?.right;
30984
31440
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
30985
31441
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
31442
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
31443
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
30986
31444
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
30987
31445
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
30988
31446
  next.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
30989
31447
  next.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
30990
31448
  if (typeof headerPx === "number" || typeof topPx === "number") {
30991
- const sectionTop = topPx ?? baseMargins.top;
31449
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
30992
31450
  const sectionHeader = next.pendingHeaderDistance;
30993
31451
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
30994
31452
  next.pendingTopMargin = Math.max(sectionTop, requiredTop);
30995
31453
  } else {
30996
31454
  next.pendingTopMargin = nextTop;
30997
31455
  }
30998
- if (typeof footerPx === "number") {
31456
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
30999
31457
  const sectionFooter = next.pendingFooterDistance;
31458
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
31000
31459
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
31001
- next.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
31460
+ next.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
31002
31461
  } else {
31003
31462
  next.pendingBottomMargin = nextBottom;
31004
31463
  }
31464
+ next.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
31465
+ next.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
31005
31466
  if (block.pageSize) next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
31006
31467
  if (block.orientation) next.pendingOrientation = block.orientation;
31007
31468
  const sectionType = block.type ?? "continuous";
@@ -31086,7 +31547,7 @@ function layoutDocument(blocks, measures, options = {}) {
31086
31547
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
31087
31548
  let pendingSectionIndex = null;
31088
31549
  const paginator = createPaginator({
31089
- margins: { left: margins.left, right: margins.right },
31550
+ margins: paginatorMargins,
31090
31551
  getActiveTopMargin: () => activeTopMargin,
31091
31552
  getActiveBottomMargin: () => activeBottomMargin,
31092
31553
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -31101,8 +31562,12 @@ function layoutDocument(blocks, measures, options = {}) {
31101
31562
  const applied = applyPendingToActive({
31102
31563
  activeTopMargin,
31103
31564
  activeBottomMargin,
31565
+ activeLeftMargin,
31566
+ activeRightMargin,
31104
31567
  pendingTopMargin,
31105
31568
  pendingBottomMargin,
31569
+ pendingLeftMargin,
31570
+ pendingRightMargin,
31106
31571
  activeHeaderDistance,
31107
31572
  activeFooterDistance,
31108
31573
  pendingHeaderDistance,
@@ -31117,8 +31582,12 @@ function layoutDocument(blocks, measures, options = {}) {
31117
31582
  });
31118
31583
  activeTopMargin = applied.activeTopMargin;
31119
31584
  activeBottomMargin = applied.activeBottomMargin;
31585
+ activeLeftMargin = applied.activeLeftMargin;
31586
+ activeRightMargin = applied.activeRightMargin;
31120
31587
  pendingTopMargin = applied.pendingTopMargin;
31121
31588
  pendingBottomMargin = applied.pendingBottomMargin;
31589
+ pendingLeftMargin = applied.pendingLeftMargin;
31590
+ pendingRightMargin = applied.pendingRightMargin;
31122
31591
  activeHeaderDistance = applied.activeHeaderDistance;
31123
31592
  activeFooterDistance = applied.activeFooterDistance;
31124
31593
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -31130,6 +31599,14 @@ function layoutDocument(blocks, measures, options = {}) {
31130
31599
  activeOrientation = applied.activeOrientation;
31131
31600
  pendingOrientation = applied.pendingOrientation;
31132
31601
  cachedColumnsState.state = null;
31602
+ paginatorMargins.left = activeLeftMargin;
31603
+ paginatorMargins.right = activeRightMargin;
31604
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31605
+ floatManager.setLayoutContext(
31606
+ normalizeColumns(activeColumns, contentWidth),
31607
+ { left: activeLeftMargin, right: activeRightMargin },
31608
+ activePageSize.w
31609
+ );
31133
31610
  if (pendingNumbering) {
31134
31611
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
31135
31612
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -31174,7 +31651,7 @@ function layoutDocument(blocks, measures, options = {}) {
31174
31651
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
31175
31652
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
31176
31653
  const getCurrentColumns = () => {
31177
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
31654
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31178
31655
  const state = states[states.length - 1] ?? null;
31179
31656
  const colsConfig = state ? getActiveColumnsForState(state) : activeColumns;
31180
31657
  const constraintIndex = state ? state.activeConstraintIndex : -1;
@@ -31207,6 +31684,12 @@ function layoutDocument(blocks, measures, options = {}) {
31207
31684
  layoutLog(` Current page: ${state.page.number}, cursorY: ${state.cursorY}`);
31208
31685
  activeColumns = newColumns;
31209
31686
  cachedColumnsState.state = null;
31687
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31688
+ floatManager.setLayoutContext(
31689
+ normalizeColumns(activeColumns, contentWidth),
31690
+ { left: activeLeftMargin, right: activeRightMargin },
31691
+ activePageSize.w
31692
+ );
31210
31693
  };
31211
31694
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
31212
31695
  const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
@@ -31238,10 +31721,10 @@ function layoutDocument(blocks, measures, options = {}) {
31238
31721
  if (alignV === "top") {
31239
31722
  anchorY = offsetV;
31240
31723
  } else if (alignV === "bottom") {
31241
- const pageHeight = contentBottom + margins.bottom;
31724
+ const pageHeight = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin);
31242
31725
  anchorY = pageHeight - imageHeight + offsetV;
31243
31726
  } else if (alignV === "center") {
31244
- const pageHeight = contentBottom + margins.bottom;
31727
+ const pageHeight = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin);
31245
31728
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
31246
31729
  } else {
31247
31730
  anchorY = offsetV;
@@ -31252,11 +31735,11 @@ function layoutDocument(blocks, measures, options = {}) {
31252
31735
  const anchorX = entry.block.anchor ? computeAnchorX(
31253
31736
  entry.block.anchor,
31254
31737
  state.columnIndex,
31255
- normalizeColumns(activeColumns, contentWidth),
31738
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
31256
31739
  entry.measure.width,
31257
- { left: margins.left, right: margins.right },
31740
+ { left: activeLeftMargin, right: activeRightMargin },
31258
31741
  activePageSize.w
31259
- ) : margins.left;
31742
+ ) : activeLeftMargin;
31260
31743
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
31261
31744
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state.page.number });
31262
31745
  }
@@ -31294,8 +31777,12 @@ function layoutDocument(blocks, measures, options = {}) {
31294
31777
  const sectionState = {
31295
31778
  activeTopMargin,
31296
31779
  activeBottomMargin,
31780
+ activeLeftMargin,
31781
+ activeRightMargin,
31297
31782
  pendingTopMargin,
31298
31783
  pendingBottomMargin,
31784
+ pendingLeftMargin,
31785
+ pendingRightMargin,
31299
31786
  activeHeaderDistance,
31300
31787
  activeFooterDistance,
31301
31788
  pendingHeaderDistance,
@@ -31329,8 +31816,12 @@ function layoutDocument(blocks, measures, options = {}) {
31329
31816
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
31330
31817
  activeTopMargin = updatedState.activeTopMargin;
31331
31818
  activeBottomMargin = updatedState.activeBottomMargin;
31819
+ activeLeftMargin = updatedState.activeLeftMargin;
31820
+ activeRightMargin = updatedState.activeRightMargin;
31332
31821
  pendingTopMargin = updatedState.pendingTopMargin;
31333
31822
  pendingBottomMargin = updatedState.pendingBottomMargin;
31823
+ pendingLeftMargin = updatedState.pendingLeftMargin;
31824
+ pendingRightMargin = updatedState.pendingRightMargin;
31334
31825
  activeHeaderDistance = updatedState.activeHeaderDistance;
31335
31826
  activeFooterDistance = updatedState.activeFooterDistance;
31336
31827
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -31468,8 +31959,8 @@ function layoutDocument(blocks, measures, options = {}) {
31468
31959
  pageMargins: {
31469
31960
  top: activeTopMargin,
31470
31961
  bottom: activeBottomMargin,
31471
- left: margins.left,
31472
- right: margins.right
31962
+ left: activeLeftMargin,
31963
+ right: activeRightMargin
31473
31964
  },
31474
31965
  columns: getCurrentColumns(),
31475
31966
  placedAnchoredIds
@@ -31491,9 +31982,9 @@ function layoutDocument(blocks, measures, options = {}) {
31491
31982
  const cols = getCurrentColumns();
31492
31983
  let maxWidth;
31493
31984
  if (relativeFrom === "page") {
31494
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
31985
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
31495
31986
  } else if (relativeFrom === "margin") {
31496
- maxWidth = activePageSize.w - margins.left - margins.right;
31987
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31497
31988
  } else {
31498
31989
  maxWidth = cols.width;
31499
31990
  }
@@ -31653,6 +32144,9 @@ function layoutHeaderFooter(blocks, measures, constraints) {
31653
32144
  if (!Number.isFinite(height) || height <= 0) {
31654
32145
  throw new Error("layoutHeaderFooter: height must be positive");
31655
32146
  }
32147
+ const maxBehindDocOverflow = Math.max(192, height * 4);
32148
+ const minBehindDocY = -maxBehindDocOverflow;
32149
+ const maxBehindDocY = height + maxBehindDocOverflow;
31656
32150
  const marginLeft = constraints.margins?.left ?? 0;
31657
32151
  const transformedBlocks = marginLeft > 0 ? blocks.map((block) => {
31658
32152
  const hasPageRelativeAnchor = (block.kind === "image" || block.kind === "drawing") && block.anchor?.hRelativeFrom === "page" && block.anchor.offsetH != null;
@@ -31683,6 +32177,18 @@ function layoutHeaderFooter(blocks, measures, constraints) {
31683
32177
  if (idx == null) continue;
31684
32178
  const block = blocks[idx];
31685
32179
  const measure = measures[idx];
32180
+ const isAnchoredFragment = (fragment.kind === "image" || fragment.kind === "drawing") && fragment.isAnchored === true;
32181
+ if (isAnchoredFragment) {
32182
+ if (block.kind !== "image" && block.kind !== "drawing") {
32183
+ throw new Error(
32184
+ `Type mismatch: fragment kind is ${fragment.kind} but block kind is ${block.kind} for block ${block.id}`
32185
+ );
32186
+ }
32187
+ const anchoredBlock = block;
32188
+ if (anchoredBlock.anchor?.behindDoc && (fragment.y < minBehindDocY || fragment.y > maxBehindDocY)) {
32189
+ continue;
32190
+ }
32191
+ }
31686
32192
  if (fragment.y < minY) minY = fragment.y;
31687
32193
  let bottom2 = fragment.y;
31688
32194
  if (fragment.kind === "para" && measure?.kind === "paragraph") {
@@ -32680,11 +33186,11 @@ function findWordBoundaries(blocks, pos) {
32680
33186
  if (text.length === 0) return null;
32681
33187
  const clampedPos = Math.max(0, Math.min(localPos, text.length));
32682
33188
  let wordStart = clampedPos;
32683
- while (wordStart > 0 && isWordChar(text[wordStart - 1])) {
33189
+ while (wordStart > 0 && isWordChar$2(text[wordStart - 1])) {
32684
33190
  wordStart--;
32685
33191
  }
32686
33192
  let wordEnd = clampedPos;
32687
- while (wordEnd < text.length && isWordChar(text[wordEnd])) {
33193
+ while (wordEnd < text.length && isWordChar$2(text[wordEnd])) {
32688
33194
  wordEnd++;
32689
33195
  }
32690
33196
  if (wordStart === wordEnd) {
@@ -32747,7 +33253,7 @@ function findBlockAtPosition(blocks, pos) {
32747
33253
  }
32748
33254
  return null;
32749
33255
  }
32750
- function isWordChar(char) {
33256
+ function isWordChar$2(char) {
32751
33257
  return /[\p{L}\p{N}_]/u.test(char);
32752
33258
  }
32753
33259
  function isWhitespace(char) {
@@ -32782,6 +33288,29 @@ function fontString(run) {
32782
33288
  function runText(run) {
32783
33289
  return "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
32784
33290
  }
33291
+ const isWordChar$1 = (char) => {
33292
+ if (!char) return false;
33293
+ const code = char.charCodeAt(0);
33294
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
33295
+ };
33296
+ const capitalizeText$1 = (text, fullText, startOffset) => {
33297
+ if (!text) return text;
33298
+ const hasFullText = typeof startOffset === "number" && fullText != null;
33299
+ let result = "";
33300
+ for (let i = 0; i < text.length; i += 1) {
33301
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
33302
+ const ch = text[i];
33303
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
33304
+ }
33305
+ return result;
33306
+ };
33307
+ const applyTextTransform$1 = (text, transform, fullText, startOffset) => {
33308
+ if (!text || !transform || transform === "none") return text;
33309
+ if (transform === "uppercase") return text.toUpperCase();
33310
+ if (transform === "lowercase") return text.toLowerCase();
33311
+ if (transform === "capitalize") return capitalizeText$1(text, fullText, startOffset);
33312
+ return text;
33313
+ };
32785
33314
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
32786
33315
  const TWIPS_PER_INCH$4 = 1440;
32787
33316
  const PX_PER_INCH$3 = 96;
@@ -32790,6 +33319,13 @@ const TAB_EPSILON$1 = 0.1;
32790
33319
  const WIDTH_FUDGE_PX = 0.5;
32791
33320
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
32792
33321
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
33322
+ const markerFontString = (run) => {
33323
+ const size2 = run?.fontSize ?? 16;
33324
+ const family = run?.fontFamily ?? "Arial";
33325
+ const italic = run?.italic ? "italic " : "";
33326
+ const bold = run?.bold ? "bold " : "";
33327
+ return `${italic}${bold}${size2}px ${family}`.trim();
33328
+ };
32793
33329
  const buildTabStopsPx$1 = (indent, tabs, tabIntervalTwips) => {
32794
33330
  const paragraphIndentTwips = {
32795
33331
  left: pxToTwips$1(Math.max(0, indent?.left ?? 0)),
@@ -32820,7 +33356,9 @@ const getNextTabStopPx$1 = (currentX, tabStops, startIndex) => {
32820
33356
  };
32821
33357
  function measureRunSliceWidth(run, fromChar, toChar) {
32822
33358
  const context = getCtx();
32823
- const text = runText(run).slice(fromChar, toChar);
33359
+ const fullText = runText(run);
33360
+ const transform = isTextRun$2(run) ? run.textTransform : void 0;
33361
+ const text = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
32824
33362
  if (!context) {
32825
33363
  const textRun = isTextRun$2(run) ? run : null;
32826
33364
  const size2 = textRun?.fontSize ?? 16;
@@ -32866,8 +33404,21 @@ function remeasureParagraph(block, maxWidth, firstLineIndent = 0) {
32866
33404
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
32867
33405
  const markerTextStartX = wordLayout?.marker?.textStartX;
32868
33406
  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);
33407
+ const resolvedTextStartPx = resolveListTextStartPx(
33408
+ wordLayout,
33409
+ indentLeft,
33410
+ indentFirstLine,
33411
+ indentHanging,
33412
+ (markerText, marker) => {
33413
+ const context = getCtx();
33414
+ if (!context) return 0;
33415
+ context.font = markerFontString(marker.run);
33416
+ return context.measureText(markerText).width;
33417
+ }
33418
+ );
33419
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
33420
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
33421
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
32871
33422
  const tabStops = buildTabStopsPx$1(indent, attrs?.tabs, attrs?.tabIntervalTwips);
32872
33423
  let currentRun = 0;
32873
33424
  let currentChar = 0;
@@ -33407,7 +33958,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33407
33958
  if (dirty.deletedBlockIds.length > 0) {
33408
33959
  measureCache.invalidate(dirty.deletedBlockIds);
33409
33960
  }
33410
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
33961
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
33411
33962
  if (measurementWidth <= 0 || measurementHeight <= 0) {
33412
33963
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
33413
33964
  }
@@ -33676,7 +34227,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33676
34227
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
33677
34228
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
33678
34229
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
33679
- function resolveMeasurementConstraints(options) {
34230
+ function resolveMeasurementConstraints(options, blocks) {
33680
34231
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
33681
34232
  const margins = {
33682
34233
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -33684,23 +34235,41 @@ function resolveMeasurementConstraints(options) {
33684
34235
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
33685
34236
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
33686
34237
  };
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) {
34238
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
34239
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
34240
+ const computeColumnWidth = (contentWidth, columns) => {
34241
+ if (!columns || columns.count <= 1) return contentWidth;
33691
34242
  const gap = Math.max(0, columns.gap ?? 0);
33692
34243
  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
34244
+ return (contentWidth - totalGap) / columns.count;
34245
+ };
34246
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
34247
+ let measurementHeight = baseContentHeight;
34248
+ if (blocks && blocks.length > 0) {
34249
+ for (const block of blocks) {
34250
+ if (block.kind !== "sectionBreak") continue;
34251
+ const sectionPageSize = block.pageSize ?? pageSize;
34252
+ const sectionMargins = {
34253
+ top: normalizeMargin(block.margins?.top, margins.top),
34254
+ right: normalizeMargin(block.margins?.right, margins.right),
34255
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
34256
+ left: normalizeMargin(block.margins?.left, margins.left)
33698
34257
  };
34258
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
34259
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
34260
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
34261
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
34262
+ if (columnWidth > measurementWidth) {
34263
+ measurementWidth = columnWidth;
34264
+ }
34265
+ if (contentHeight > measurementHeight) {
34266
+ measurementHeight = contentHeight;
34267
+ }
33699
34268
  }
33700
34269
  }
33701
34270
  return {
33702
- measurementWidth: contentWidth,
33703
- measurementHeight: contentHeight
34271
+ measurementWidth,
34272
+ measurementHeight
33704
34273
  };
33705
34274
  }
33706
34275
  const serializeHeaderFooterResults = (kind, batch) => {
@@ -36159,14 +36728,15 @@ function getAtomNodeTypes(schema) {
36159
36728
  if (!schema) return [];
36160
36729
  const types = [];
36161
36730
  try {
36162
- schema.nodes.forEach((nodeType, name) => {
36731
+ for (const name in schema.nodes) {
36163
36732
  if (name === "text") {
36164
- return;
36733
+ continue;
36165
36734
  }
36166
- if (nodeType.isAtom || nodeType.isLeaf) {
36735
+ const nodeType = schema.nodes[name];
36736
+ if (nodeType && (nodeType.isAtom || nodeType.isLeaf)) {
36167
36737
  types.push(name);
36168
36738
  }
36169
- });
36739
+ }
36170
36740
  } catch {
36171
36741
  return [];
36172
36742
  }
@@ -37569,6 +38139,7 @@ function shouldRequirePageBoundary(current, next) {
37569
38139
  function hasIntrinsicBoundarySignals(_) {
37570
38140
  return false;
37571
38141
  }
38142
+ const DEFAULT_HEADER_FOOTER_MARGIN_PX = 0;
37572
38143
  function shouldIgnoreSectionBreak(paragraph, index2, total, hasBodySectPr) {
37573
38144
  const paragraphAttrs = paragraph.attrs ?? {};
37574
38145
  const paragraphProperties = paragraphAttrs?.paragraphProperties;
@@ -37609,14 +38180,15 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
37609
38180
  const sectionData = extractSectionData(item.node);
37610
38181
  if (!sectionData) return;
37611
38182
  const sectPr = getSectPrFromNode(item.node);
38183
+ const hasAnyMargin = sectionData.headerPx != null || sectionData.footerPx != null || sectionData.topPx != null || sectionData.rightPx != null || sectionData.bottomPx != null || sectionData.leftPx != null;
37612
38184
  const range = {
37613
38185
  sectionIndex: idx,
37614
38186
  startParagraphIndex: currentStart,
37615
38187
  endParagraphIndex: item.index,
37616
38188
  sectPr,
37617
- margins: sectionData.headerPx != null || sectionData.footerPx != null ? {
37618
- header: sectionData.headerPx ?? 0,
37619
- footer: sectionData.footerPx ?? 0,
38189
+ margins: hasAnyMargin ? {
38190
+ header: sectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
38191
+ footer: sectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
37620
38192
  top: sectionData.topPx,
37621
38193
  right: sectionData.rightPx,
37622
38194
  bottom: sectionData.bottomPx,
@@ -37658,14 +38230,15 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
37658
38230
  };
37659
38231
  const bodySectionData = extractSectionData(tempNode);
37660
38232
  if (!bodySectionData) return null;
38233
+ const hasAnyMargin = bodySectionData.headerPx != null || bodySectionData.footerPx != null || bodySectionData.topPx != null || bodySectionData.rightPx != null || bodySectionData.bottomPx != null || bodySectionData.leftPx != null;
37661
38234
  return {
37662
38235
  sectionIndex,
37663
38236
  startParagraphIndex: currentStart,
37664
38237
  endParagraphIndex: totalParagraphs - 1,
37665
38238
  sectPr: bodySectPr,
37666
- margins: bodySectionData.headerPx != null || bodySectionData.footerPx != null ? {
37667
- header: bodySectionData.headerPx ?? 0,
37668
- footer: bodySectionData.footerPx ?? 0,
38239
+ margins: hasAnyMargin ? {
38240
+ header: bodySectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
38241
+ footer: bodySectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
37669
38242
  top: bodySectionData.topPx,
37670
38243
  right: bodySectionData.rightPx,
37671
38244
  bottom: bodySectionData.bottomPx,
@@ -38649,11 +39222,27 @@ const collectTrackedChangeFromMarks = (marks) => {
38649
39222
  }, void 0);
38650
39223
  };
38651
39224
  const normalizeUnderlineStyle = (value) => {
38652
- if (value === "none") {
38653
- return void 0;
39225
+ if (value === void 0 || value === null) {
39226
+ return "single";
38654
39227
  }
38655
- if (value === "double" || value === "dotted" || value === "dashed" || value === "wavy") {
38656
- return value;
39228
+ if (typeof value === "boolean") {
39229
+ return value ? "single" : void 0;
39230
+ }
39231
+ if (typeof value === "number") {
39232
+ return value === 0 ? void 0 : "single";
39233
+ }
39234
+ if (typeof value === "string") {
39235
+ const normalized = value.trim().toLowerCase();
39236
+ if (!normalized) {
39237
+ return "single";
39238
+ }
39239
+ if (normalized === "none" || normalized === "0" || normalized === "false" || normalized === "off") {
39240
+ return void 0;
39241
+ }
39242
+ if (normalized === "double" || normalized === "dotted" || normalized === "dashed" || normalized === "wavy") {
39243
+ return normalized;
39244
+ }
39245
+ return "single";
38657
39246
  }
38658
39247
  return "single";
38659
39248
  };
@@ -38805,13 +39394,16 @@ const applyMarksToRun = (run, marks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG,
38805
39394
  break;
38806
39395
  }
38807
39396
  case "underline": {
38808
- const style = normalizeUnderlineStyle(mark.attrs?.underlineType);
39397
+ const underlineValue = mark.attrs?.underlineType ?? mark.attrs?.value ?? mark.attrs?.underline ?? mark.attrs?.style;
39398
+ const style = normalizeUnderlineStyle(underlineValue);
38809
39399
  if (style) {
38810
39400
  const underlineColor = resolveColorFromAttributes(mark.attrs ?? {}, themeColors);
38811
39401
  run.underline = {
38812
39402
  style,
38813
39403
  color: underlineColor ?? run.underline?.color
38814
39404
  };
39405
+ } else if (underlineValue !== void 0 && underlineValue !== null) {
39406
+ delete run.underline;
38815
39407
  }
38816
39408
  break;
38817
39409
  }
@@ -39747,8 +40339,8 @@ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
39747
40339
  }
39748
40340
  return void 0;
39749
40341
  }
39750
- const DEFAULT_LIST_HANGING_PX$1 = 18;
39751
- const LIST_MARKER_GAP$1 = 8;
40342
+ const DEFAULT_LIST_HANGING_PX = 18;
40343
+ const LIST_MARKER_GAP = 8;
39752
40344
  const DEFAULT_BULLET_GLYPH = "•";
39753
40345
  const DEFAULT_DECIMAL_PATTERN = "%1.";
39754
40346
  const ASCII_UPPERCASE_A = 65;
@@ -40159,7 +40751,7 @@ function computeWordParagraphLayout(input) {
40159
40751
  let markerBoxWidthPx;
40160
40752
  let markerX;
40161
40753
  if (hasFirstLineIndent) {
40162
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
40754
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
40163
40755
  markerX = indentLeftPx + (firstLinePx ?? 0);
40164
40756
  layout.textStartPx = markerX + markerBoxWidthPx;
40165
40757
  layout.hangingPx = 0;
@@ -40259,12 +40851,12 @@ const resolveMarkerBoxWidth = (hangingPxRaw, glyphWidthPx) => {
40259
40851
  let markerBox = Math.max(hangingPxRaw || 0, 0);
40260
40852
  if (markerBox <= 0) {
40261
40853
  if (glyphWidthPx != null && glyphWidthPx > 0) {
40262
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
40854
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
40263
40855
  } else {
40264
- markerBox = DEFAULT_LIST_HANGING_PX$1;
40856
+ markerBox = DEFAULT_LIST_HANGING_PX;
40265
40857
  }
40266
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
40267
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
40858
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
40859
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
40268
40860
  }
40269
40861
  return markerBox;
40270
40862
  };
@@ -40284,7 +40876,7 @@ const buildMarkerLayout = ({
40284
40876
  textStartX: textStartPx,
40285
40877
  baselineOffsetPx: markerRun.baselineShift ?? 0,
40286
40878
  // Gutter is the small gap between marker and text, not the full marker box width
40287
- gutterWidthPx: LIST_MARKER_GAP$1,
40879
+ gutterWidthPx: LIST_MARKER_GAP,
40288
40880
  justification: numbering.lvlJc ?? "left",
40289
40881
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
40290
40882
  run: markerRun,
@@ -40374,7 +40966,10 @@ const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
40374
40966
  tabStops: cloneIfObject(resolvedExtended.tabStops),
40375
40967
  keepLines: resolvedExtended.keepLines,
40376
40968
  keepNext: resolvedExtended.keepNext,
40377
- numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties)
40969
+ numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties),
40970
+ // Extract contextualSpacing from style resolution - this is a sibling to spacing in OOXML,
40971
+ // not nested within it. When true, suppresses spacing between paragraphs of the same style.
40972
+ contextualSpacing: resolvedExtended.contextualSpacing
40378
40973
  };
40379
40974
  return hydrated;
40380
40975
  };
@@ -40976,6 +41571,31 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
40976
41571
  return null;
40977
41572
  }
40978
41573
  };
41574
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
41575
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
41576
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
41577
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
41578
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
41579
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
41580
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
41581
+ wordLayout.firstLineIndentMode = false;
41582
+ }
41583
+ if (wordLayout.firstLineIndentMode === true) {
41584
+ if (isFiniteNumber(wordLayout.textStartPx)) {
41585
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
41586
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
41587
+ }
41588
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
41589
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
41590
+ }
41591
+ } else {
41592
+ wordLayout.textStartPx = indentLeft;
41593
+ if (wordLayout.marker) {
41594
+ wordLayout.marker.textStartX = indentLeft;
41595
+ }
41596
+ }
41597
+ return wordLayout;
41598
+ };
40979
41599
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
40980
41600
  const attrs = para.attrs ?? {};
40981
41601
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -41084,7 +41704,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41084
41704
  paragraphAttrs.spacing.afterAutospacing = normalizedSpacing.afterAutospacing;
41085
41705
  }
41086
41706
  }
41087
- const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing");
41707
+ const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing") ?? hydrated?.contextualSpacing;
41088
41708
  if (contextualSpacingValue != null) {
41089
41709
  paragraphAttrs.contextualSpacing = isTruthy(contextualSpacingValue);
41090
41710
  }
@@ -41298,8 +41918,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41298
41918
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
41299
41919
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
41300
41920
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
41301
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
41302
- if (firstLinePx > 0) {
41921
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
41922
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
41923
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
41924
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
41925
+ if (firstLinePx > 0 && !hangingPx) {
41303
41926
  wordLayout = {
41304
41927
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
41305
41928
  firstLineIndentMode: true,
@@ -41307,10 +41930,13 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41307
41930
  };
41308
41931
  }
41309
41932
  }
41310
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
41933
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
41311
41934
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
41312
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
41313
- if (firstLinePx > 0) {
41935
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
41936
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
41937
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
41938
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
41939
+ if (firstLinePx > 0 && !hangingPx) {
41314
41940
  wordLayout = {
41315
41941
  ...wordLayout,
41316
41942
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -41330,6 +41956,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41330
41956
  wordLayout.marker.suffix = listRendering.suffix;
41331
41957
  }
41332
41958
  }
41959
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
41333
41960
  paragraphAttrs.wordLayout = wordLayout;
41334
41961
  }
41335
41962
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -45563,11 +46190,6 @@ function initHeaderFooterRegistry({
45563
46190
  cleanups
45564
46191
  };
45565
46192
  }
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
46193
  function calculateRotatedBounds(input) {
45572
46194
  const width = Math.max(0, input.width);
45573
46195
  const height = Math.max(0, input.height);
@@ -45737,7 +46359,7 @@ function measureText(text, font, ctx2, _fontFamily, _letterSpacing) {
45737
46359
  return Math.max(advanceWidth, paintedWidth);
45738
46360
  }
45739
46361
  const MIN_SINGLE_LINE_PX = 12 * 96 / 72;
45740
- const LINE_HEIGHT_SAFETY_MARGIN_PX = 1;
46362
+ const WORD_SINGLE_LINE_SPACING_MULTIPLIER = 1.15;
45741
46363
  function calculateTypographyMetrics(fontSize, spacing, fontInfo) {
45742
46364
  let ascent;
45743
46365
  let descent;
@@ -45750,7 +46372,7 @@ function calculateTypographyMetrics(fontSize, spacing, fontInfo) {
45750
46372
  ascent = roundValue(fontSize * 0.8);
45751
46373
  descent = roundValue(fontSize * 0.2);
45752
46374
  }
45753
- const baseLineHeight = Math.max(ascent + descent + LINE_HEIGHT_SAFETY_MARGIN_PX, MIN_SINGLE_LINE_PX);
46375
+ const baseLineHeight = Math.max(fontSize * WORD_SINGLE_LINE_SPACING_MULTIPLIER, ascent + descent, MIN_SINGLE_LINE_PX);
45754
46376
  const lineHeight = roundValue(resolveLineHeight(spacing, baseLineHeight));
45755
46377
  return {
45756
46378
  ascent,
@@ -45831,8 +46453,25 @@ async function measureParagraphBlock(block, maxWidth) {
45831
46453
  const rawTextStartPx = wordLayout?.textStartPx;
45832
46454
  const markerTextStartX = wordLayout?.marker?.textStartX;
45833
46455
  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);
46456
+ const resolvedTextStartPx = resolveListTextStartPx(
46457
+ wordLayout,
46458
+ indentLeft,
46459
+ firstLine,
46460
+ hanging,
46461
+ (markerText, marker) => {
46462
+ const markerRun = {
46463
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
46464
+ fontSize: marker.run?.fontSize ?? 16,
46465
+ bold: marker.run?.bold ?? false,
46466
+ italic: marker.run?.italic ?? false
46467
+ };
46468
+ const { font: markerFont } = buildFontString(markerRun);
46469
+ return measureText(markerText, markerFont, ctx2);
46470
+ }
46471
+ );
46472
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
46473
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
46474
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
45836
46475
  } else {
45837
46476
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
45838
46477
  }
@@ -45919,7 +46558,7 @@ async function measureParagraphBlock(block, maxWidth) {
45919
46558
  pendingTabAlignment = null;
45920
46559
  return startX;
45921
46560
  };
45922
- const alignSegmentAtTab = (segmentText, font, runContext) => {
46561
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
45923
46562
  if (!pendingTabAlignment || !currentLine) return void 0;
45924
46563
  const { val } = pendingTabAlignment;
45925
46564
  let segmentWidth = 0;
@@ -45928,11 +46567,11 @@ async function measureParagraphBlock(block, maxWidth) {
45928
46567
  const idx = segmentText.indexOf(decimalSeparator);
45929
46568
  if (idx >= 0) {
45930
46569
  const beforeText = segmentText.slice(0, idx);
45931
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
46570
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
45932
46571
  }
45933
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
46572
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
45934
46573
  } else if (val === "end" || val === "center") {
45935
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
46574
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
45936
46575
  }
45937
46576
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
45938
46577
  };
@@ -45984,8 +46623,8 @@ async function measureParagraphBlock(block, maxWidth) {
45984
46623
  const { font } = buildFontString(
45985
46624
  lastRun
45986
46625
  );
45987
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
45988
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
46626
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
46627
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
45989
46628
  const delta = Math.max(0, fullWidth - keptWidth);
45990
46629
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
45991
46630
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -46196,7 +46835,8 @@ async function measureParagraphBlock(block, maxWidth) {
46196
46835
  continue;
46197
46836
  }
46198
46837
  if (isFieldAnnotationRun(run)) {
46199
- const displayText = run.displayLabel || "";
46838
+ const rawDisplayText = run.displayLabel || "";
46839
+ const displayText = applyTextTransform(rawDisplayText, run);
46200
46840
  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
46841
  const annotationFontFamily = run.fontFamily || "Arial, sans-serif";
46202
46842
  const fontWeight = run.bold ? "bold" : "normal";
@@ -46299,7 +46939,7 @@ async function measureParagraphBlock(block, maxWidth) {
46299
46939
  const spacesLength = segment.length;
46300
46940
  const spacesStartChar = charPosInRun;
46301
46941
  const spacesEndChar = charPosInRun + spacesLength;
46302
- const spacesWidth = measureRunWidth(segment, font, ctx2, run);
46942
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run, spacesStartChar);
46303
46943
  if (!currentLine) {
46304
46944
  currentLine = {
46305
46945
  fromRun: runIndex,
@@ -46363,7 +47003,7 @@ async function measureParagraphBlock(block, maxWidth) {
46363
47003
  }
46364
47004
  let segmentStartX;
46365
47005
  if (currentLine && pendingTabAlignment) {
46366
- segmentStartX = alignSegmentAtTab(segment, font, run);
47006
+ segmentStartX = alignSegmentAtTab(segment, font, run, charPosInRun);
46367
47007
  if (segmentStartX == null) {
46368
47008
  segmentStartX = currentLine.width;
46369
47009
  }
@@ -46373,7 +47013,7 @@ async function measureParagraphBlock(block, maxWidth) {
46373
47013
  if (word2 === "") {
46374
47014
  const spaceStartChar = charPosInRun;
46375
47015
  const spaceEndChar = charPosInRun + 1;
46376
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run);
47016
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run, spaceStartChar);
46377
47017
  if (!currentLine) {
46378
47018
  currentLine = {
46379
47019
  fromRun: runIndex,
@@ -46424,12 +47064,12 @@ async function measureParagraphBlock(block, maxWidth) {
46424
47064
  charPosInRun = spaceEndChar;
46425
47065
  continue;
46426
47066
  }
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
47067
  const wordStartChar = charPosInRun;
47068
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run, wordStartChar);
47069
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
46432
47070
  const wordEndNoSpace = charPosInRun + word2.length;
47071
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run, wordEndNoSpace) : 0;
47072
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
46433
47073
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
46434
47074
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
46435
47075
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -46448,7 +47088,7 @@ async function measureParagraphBlock(block, maxWidth) {
46448
47088
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
46449
47089
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
46450
47090
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
46451
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run);
47091
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run, wordStartChar);
46452
47092
  let chunkCharOffset = wordStartChar;
46453
47093
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
46454
47094
  const chunk = chunks[chunkIndex];
@@ -46550,6 +47190,10 @@ async function measureParagraphBlock(block, maxWidth) {
46550
47190
  currentLine.width = roundValue(currentLine.width + spaceWidth + ls);
46551
47191
  charPosInRun = wordEndWithSpace;
46552
47192
  currentLine.spaceCount += 1;
47193
+ if (currentLine.segments?.[0]) {
47194
+ currentLine.segments[0].toChar = wordEndWithSpace;
47195
+ currentLine.segments[0].width += spaceWidth;
47196
+ }
46553
47197
  } else {
46554
47198
  charPosInRun = wordEndWithSpace;
46555
47199
  }
@@ -46572,7 +47216,7 @@ async function measureParagraphBlock(block, maxWidth) {
46572
47216
  if (candidateSpaces > 0) {
46573
47217
  const overflow = totalWidthWithWord - availableWidth;
46574
47218
  if (overflow > 0) {
46575
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run) || Math.max(1, boundarySpacing);
47219
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run, wordEndNoSpace) || Math.max(1, boundarySpacing);
46576
47220
  const perSpaceCompression = overflow / candidateSpaces;
46577
47221
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
46578
47222
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -46612,6 +47256,10 @@ async function measureParagraphBlock(block, maxWidth) {
46612
47256
  currentLine.width = roundValue(currentLine.width + spaceWidth + (run.letterSpacing ?? 0));
46613
47257
  charPosInRun = wordEndWithSpace;
46614
47258
  currentLine.spaceCount += 1;
47259
+ if (currentLine.segments?.[0]) {
47260
+ currentLine.segments[0].toChar = wordEndWithSpace;
47261
+ currentLine.segments[0].width += spaceWidth;
47262
+ }
46615
47263
  } else {
46616
47264
  charPosInRun = wordEndWithSpace;
46617
47265
  }
@@ -46747,8 +47395,8 @@ async function measureParagraphBlock(block, maxWidth) {
46747
47395
  const { font: markerFont } = buildFontString(markerRun);
46748
47396
  const markerText = wordLayout.marker.markerText ?? "";
46749
47397
  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);
47398
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
47399
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
46752
47400
  markerInfo = {
46753
47401
  markerWidth: markerBoxWidth,
46754
47402
  markerTextWidth: glyphWidth,
@@ -47092,7 +47740,7 @@ async function measureListBlock(block, constraints) {
47092
47740
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
47093
47741
  indentLeft = resolveIndentLeft(item);
47094
47742
  const indentHanging = resolveIndentHanging(item);
47095
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
47743
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
47096
47744
  }
47097
47745
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
47098
47746
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -47118,16 +47766,46 @@ const getPrimaryRun = (paragraph) => {
47118
47766
  fontSize: 16
47119
47767
  };
47120
47768
  };
47121
- const measureRunWidth = (text, font, ctx2, run) => {
47769
+ const isWordChar = (char) => {
47770
+ if (!char) return false;
47771
+ const code = char.charCodeAt(0);
47772
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
47773
+ };
47774
+ const capitalizeText = (text, fullText, startOffset) => {
47775
+ if (!text) return text;
47776
+ const hasFullText = typeof startOffset === "number" && fullText != null;
47777
+ let result = "";
47778
+ for (let i = 0; i < text.length; i += 1) {
47779
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
47780
+ const ch = text[i];
47781
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
47782
+ }
47783
+ return result;
47784
+ };
47785
+ const applyTextTransform = (text, run, startOffset) => {
47786
+ const transform = "textTransform" in run ? run.textTransform : void 0;
47787
+ if (!text || !transform || transform === "none") return text;
47788
+ if (transform === "uppercase") return text.toUpperCase();
47789
+ if (transform === "lowercase") return text.toLowerCase();
47790
+ if (transform === "capitalize") {
47791
+ const fullText = "text" in run && typeof run.text === "string" ? run.text : text;
47792
+ return capitalizeText(text, fullText, startOffset);
47793
+ }
47794
+ return text;
47795
+ };
47796
+ const measureRunWidth = (text, font, ctx2, run, startOffset) => {
47122
47797
  const letterSpacing = run.kind === "text" || run.kind === void 0 ? run.letterSpacing || 0 : 0;
47123
- const width = getMeasuredTextWidth(text, font, letterSpacing, ctx2);
47798
+ const displayText = applyTextTransform(text, run, startOffset);
47799
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
47124
47800
  return roundValue(width);
47125
47801
  };
47126
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run) => {
47802
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run, startOffset) => {
47127
47803
  const chunks = [];
47804
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
47128
47805
  if (maxWidth <= 0) {
47129
- for (const char of word2) {
47130
- const charWidth = measureRunWidth(char, font, ctx2, run);
47806
+ for (let i = 0; i < word2.length; i++) {
47807
+ const char = word2[i];
47808
+ const charWidth = measureRunWidth(char, font, ctx2, run, baseOffset + i);
47131
47809
  chunks.push({ text: char, width: charWidth });
47132
47810
  }
47133
47811
  return chunks;
@@ -47137,11 +47815,11 @@ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run) => {
47137
47815
  for (let i = 0; i < word2.length; i++) {
47138
47816
  const char = word2[i];
47139
47817
  const testChunk = currentChunk + char;
47140
- const testWidth = measureRunWidth(testChunk, font, ctx2, run);
47818
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run, baseOffset);
47141
47819
  if (testWidth > maxWidth && currentChunk.length > 0) {
47142
47820
  chunks.push({ text: currentChunk, width: currentWidth });
47143
47821
  currentChunk = char;
47144
- currentWidth = measureRunWidth(char, font, ctx2, run);
47822
+ currentWidth = measureRunWidth(char, font, ctx2, run, baseOffset + i);
47145
47823
  } else {
47146
47824
  currentChunk = testChunk;
47147
47825
  currentWidth = testWidth;
@@ -47195,12 +47873,13 @@ const measureDropCap = (ctx2, descriptor, spacing) => {
47195
47873
  italic: run.italic
47196
47874
  });
47197
47875
  ctx2.font = font;
47198
- const metrics = ctx2.measureText(run.text);
47876
+ const displayText = applyTextTransform(run.text, run);
47877
+ const metrics = ctx2.measureText(displayText);
47199
47878
  const advanceWidth = metrics.width;
47200
47879
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
47201
47880
  const textWidth = Math.max(advanceWidth, paintedWidth);
47202
47881
  const width = roundValue(textWidth + DROP_CAP_PADDING_PX);
47203
- const baseLineHeight = resolveLineHeight(spacing, run.fontSize * 1.2);
47882
+ const baseLineHeight = resolveLineHeight(spacing, run.fontSize * WORD_SINGLE_LINE_SPACING_MULTIPLIER);
47204
47883
  const height = roundValue(baseLineHeight * lines);
47205
47884
  return {
47206
47885
  width,
@@ -47221,7 +47900,7 @@ const resolveIndentHanging = (item) => {
47221
47900
  if (indentHanging > 0) {
47222
47901
  return indentHanging;
47223
47902
  }
47224
- return DEFAULT_LIST_HANGING_PX;
47903
+ return DEFAULT_LIST_HANGING_PX$1;
47225
47904
  };
47226
47905
  const buildTabStopsPx = (indent, tabs, tabIntervalTwips) => {
47227
47906
  const paragraphIndentTwips = {
@@ -47443,6 +48122,9 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
47443
48122
  if (event.button !== 0) {
47444
48123
  return;
47445
48124
  }
48125
+ if (event.ctrlKey && navigator.platform.includes("Mac")) {
48126
+ return;
48127
+ }
47446
48128
  __privateSet(this, _pendingMarginClick, null);
47447
48129
  const target = event.target;
47448
48130
  if (target?.closest?.(".superdoc-ruler-handle") != null) {
@@ -47939,6 +48621,10 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
47939
48621
  __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
47940
48622
  return;
47941
48623
  }
48624
+ if (__privateGet(this, _documentMode) === "viewing") {
48625
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
48626
+ return;
48627
+ }
47942
48628
  const region = __privateMethod(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, normalized.x, normalized.y);
47943
48629
  if (!region) {
47944
48630
  __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
@@ -48167,6 +48853,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
48167
48853
  __privateSet(this, _visibleHost, options.element);
48168
48854
  __privateGet(this, _visibleHost).innerHTML = "";
48169
48855
  __privateGet(this, _visibleHost).classList.add("presentation-editor");
48856
+ __privateMethod(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
48170
48857
  if (!__privateGet(this, _visibleHost).hasAttribute("tabindex")) {
48171
48858
  __privateGet(this, _visibleHost).tabIndex = 0;
48172
48859
  }
@@ -48662,6 +49349,7 @@ const _PresentationEditor = class _PresentationEditor extends EventEmitter {
48662
49349
  }
48663
49350
  __privateSet(this, _documentMode, mode);
48664
49351
  __privateGet(this, _editor3).setDocumentMode(mode);
49352
+ __privateMethod(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
48665
49353
  __privateMethod(this, _PresentationEditor_instances, syncHiddenEditorA11yAttributes_fn).call(this);
48666
49354
  const trackedChangesChanged = __privateMethod(this, _PresentationEditor_instances, syncTrackedChangesPreferences_fn).call(this);
48667
49355
  if (trackedChangesChanged) {
@@ -49601,6 +50289,10 @@ wrapHiddenEditorFocus_fn = function() {
49601
50289
  }
49602
50290
  };
49603
50291
  };
50292
+ syncDocumentModeClass_fn = function() {
50293
+ if (!__privateGet(this, _visibleHost)) return;
50294
+ __privateGet(this, _visibleHost).classList.toggle("presentation-editor--viewing", __privateGet(this, _documentMode) === "viewing");
50295
+ };
49604
50296
  /**
49605
50297
  * Collect all comment and tracked change positions from the PM document.
49606
50298
  *
@@ -50505,7 +51197,7 @@ rerender_fn = async function() {
50505
51197
  const atomNodeTypes = getAtomNodeTypes(__privateGet(this, _editor3)?.schema ?? null);
50506
51198
  const positionMap = __privateGet(this, _editor3)?.state?.doc && docJson ? buildPositionMapFromPmDoc(__privateGet(this, _editor3).state.doc, docJson) : null;
50507
51199
  const result = toFlowBlocks(docJson, {
50508
- mediaFiles: __privateGet(this, _options).mediaFiles,
51200
+ mediaFiles: __privateGet(this, _editor3)?.storage?.image?.media,
50509
51201
  emitSectionBreaks: true,
50510
51202
  sectionMetadata,
50511
51203
  trackedChangesMode: __privateGet(this, _trackedChangesMode),
@@ -51709,6 +52401,10 @@ renderCellSelectionOverlay_fn = function(selection, layout) {
51709
52401
  });
51710
52402
  };
51711
52403
  renderHoverRegion_fn = function(region) {
52404
+ if (__privateGet(this, _documentMode) === "viewing") {
52405
+ __privateMethod(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
52406
+ return;
52407
+ }
51712
52408
  if (!__privateGet(this, _hoverOverlay) || !__privateGet(this, _hoverTooltip)) return;
51713
52409
  const coords = __privateMethod(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, region.pageIndex, region.localX, region.localY);
51714
52410
  if (!coords) {
@@ -53368,6 +54064,8 @@ const SlashMenu = Extension.create({
53368
54064
  const cbRect = containingBlock.getBoundingClientRect();
53369
54065
  left2 -= cbRect.left;
53370
54066
  top2 -= cbRect.top;
54067
+ left2 += containingBlock.scrollLeft || 0;
54068
+ top2 += containingBlock.scrollTop || 0;
53371
54069
  } catch (error) {
53372
54070
  console.warn("SlashMenu: Failed to adjust for containing block", error);
53373
54071
  }
@@ -69372,7 +70070,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
69372
70070
  document.addEventListener("mousedown", globalMousedownHandler);
69373
70071
  scrollHandler = () => {
69374
70072
  if (currentWrapper && resizeContainer) {
69375
- updateHandlePositions(currentWrapper.firstElementChild);
70073
+ updateHandlePositions(currentWrapper);
69376
70074
  }
69377
70075
  };
69378
70076
  window.addEventListener("scroll", scrollHandler, true);
@@ -69434,7 +70132,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
69434
70132
  }
69435
70133
  applyStyleIsolationClass(resizeContainer);
69436
70134
  document.body.appendChild(resizeContainer);
69437
- updateHandlePositions(wrapper.firstElementChild);
70135
+ updateHandlePositions(wrapper);
69438
70136
  }
69439
70137
  function hideResizeHandles() {
69440
70138
  if (resizeContainer?.parentNode) {