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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/chunks/{PdfViewer-CWO98Qls.cjs → PdfViewer-B4os0dhm.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-C4xgIIbF.es.js → PdfViewer-CvJZenVo.es.js} +1 -1
  3. package/dist/chunks/{index-BqPa6D4q-Dulj8zfc.cjs → index--w_Fk0WX-Bd420t19.cjs} +1 -1
  4. package/dist/chunks/{index-BqPa6D4q-8U4x8RP6.es.js → index--w_Fk0WX-D_kNY98j.es.js} +1 -1
  5. package/dist/chunks/{index-BY-3Vl72.cjs → index-BaspZNUO.cjs} +4 -6
  6. package/dist/chunks/{index-s9GUR_Gc.es.js → index-bocgaXi5.es.js} +4 -6
  7. package/dist/chunks/{super-editor.es-CT28vUbx.es.js → super-editor.es-CHiYj0m5.es.js} +1050 -245
  8. package/dist/chunks/{super-editor.es-BM-ulSRj.cjs → super-editor.es-KouCN1a9.cjs} +1050 -245
  9. package/dist/packages/superdoc/src/core/SuperDoc.d.ts +3 -3
  10. package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
  11. package/dist/packages/superdoc/src/core/types/index.d.ts +173 -0
  12. package/dist/packages/superdoc/src/core/types/index.d.ts.map +1 -1
  13. package/dist/packages/superdoc/src/stores/comments-store.d.ts.map +1 -1
  14. package/dist/style.css +14 -6
  15. package/dist/super-editor/ai-writer.es.js +2 -2
  16. package/dist/super-editor/chunks/{converter-CDlAWcRu.js → converter-De_h0rq-.js} +49 -9
  17. package/dist/super-editor/chunks/{docx-zipper-B2VXuf8h.js → docx-zipper-CKQFze2s.js} +1 -1
  18. package/dist/super-editor/chunks/{editor-B4Q_tNET.js → editor-BJljVUQD.js} +994 -239
  19. package/dist/super-editor/chunks/{index-BqPa6D4q.js → index--w_Fk0WX.js} +1 -1
  20. package/dist/super-editor/chunks/{toolbar-BD-lDCLr.js → toolbar-Br3J_GSc.js} +2 -2
  21. package/dist/super-editor/converter.es.js +1 -1
  22. package/dist/super-editor/docx-zipper.es.js +2 -2
  23. package/dist/super-editor/editor.es.js +3 -3
  24. package/dist/super-editor/file-zipper.es.js +1 -1
  25. package/dist/super-editor/style.css +14 -6
  26. package/dist/super-editor/super-editor.es.js +19 -9
  27. package/dist/super-editor/toolbar.es.js +2 -2
  28. package/dist/super-editor.cjs +1 -1
  29. package/dist/super-editor.es.js +1 -1
  30. package/dist/superdoc.cjs +2 -2
  31. package/dist/superdoc.es.js +2 -2
  32. package/dist/superdoc.umd.js +1053 -250
  33. package/dist/superdoc.umd.js.map +1 -1
  34. package/package.json +1 -1
@@ -38529,8 +38529,6 @@ const decode$7 = (params2) => {
38529
38529
  );
38530
38530
  const isInternal = parentComment?.isInternal || originalComment.isInternal;
38531
38531
  if (commentsExportType === "external" && isInternal) return;
38532
- const isResolved = !!originalComment.resolvedTime;
38533
- if (isResolved) return;
38534
38532
  if (node.type !== "commentRangeStart" && node.type !== "commentRangeEnd") {
38535
38533
  return;
38536
38534
  }
@@ -39199,11 +39197,15 @@ const encode$1 = (params2, encodedAttrs = {}) => {
39199
39197
  }
39200
39198
  if (elements.length === 1) {
39201
39199
  text = elements[0].text;
39202
- const xmlSpace = encodedAttrs.xmlSpace ?? elements[0]?.attributes?.["xml:space"];
39200
+ const docXmlSpace = params2.converter?.documentAttributes?.["xml:space"];
39201
+ const xmlSpace = encodedAttrs.xmlSpace ?? attributes?.["xml:space"] ?? elements[0]?.attributes?.["xml:space"] ?? docXmlSpace;
39203
39202
  if (xmlSpace !== "preserve" && typeof text === "string") {
39204
39203
  text = text.replace(/^[ \t\n\r]+/, "").replace(/[ \t\n\r]+$/, "");
39205
39204
  }
39206
39205
  text = text.replace(/\[\[sdspace\]\]/g, "");
39206
+ if (xmlSpace !== "preserve" && typeof text === "string" && !text.trim()) {
39207
+ return null;
39208
+ }
39207
39209
  } else if (!elements.length && encodedAttrs.xmlSpace === "preserve") {
39208
39210
  text = " ";
39209
39211
  } else return null;
@@ -42186,8 +42188,46 @@ const _SuperConverter = class _SuperConverter2 {
42186
42188
  this.declaration = this.initialJSON?.declaration;
42187
42189
  this.resolveDocumentGuid();
42188
42190
  }
42191
+ /**
42192
+ * Parses XML content into JSON format while preserving whitespace-only text runs.
42193
+ *
42194
+ * This method wraps xml-js's xml2json parser with additional preprocessing to prevent
42195
+ * the parser from dropping whitespace-only content in <w:t> and <w:delText> elements.
42196
+ * This is critical for correctly handling documents that rely on document-level
42197
+ * xml:space="preserve" rather than per-element attributes, which is common in
42198
+ * PDF-to-DOCX converted documents.
42199
+ *
42200
+ * The whitespace preservation strategy:
42201
+ * 1. Before parsing, wraps whitespace-only content with [[sdspace]] placeholders
42202
+ * 2. xml-js parser preserves the placeholder-wrapped text
42203
+ * 3. During text node processing (t-translator.js), placeholders are removed
42204
+ *
42205
+ * @param {string} xml - The XML string to parse
42206
+ * @returns {Object} The parsed JSON representation of the XML document
42207
+ *
42208
+ * @example
42209
+ * // Handles whitespace-only text runs
42210
+ * const xml = '<w:t> </w:t>';
42211
+ * const result = parseXmlToJson(xml);
42212
+ * // Result preserves the space: { elements: [{ text: '[[sdspace]] [[sdspace]]' }] }
42213
+ *
42214
+ * @example
42215
+ * // Handles elements with attributes
42216
+ * const xml = '<w:t xml:space="preserve"> text </w:t>';
42217
+ * const result = parseXmlToJson(xml);
42218
+ * // Preserves content and attributes
42219
+ *
42220
+ * @example
42221
+ * // Handles both w:t and w:delText elements
42222
+ * const xml = '<w:delText> </w:delText>';
42223
+ * const result = parseXmlToJson(xml);
42224
+ * // Preserves whitespace in deleted text
42225
+ */
42189
42226
  parseXmlToJson(xml) {
42190
- const newXml = xml.replace(/(<w:t xml:space="preserve">)(\s+)(<\/w:t>)/g, "$1[[sdspace]]$2[[sdspace]]$3");
42227
+ const newXml = xml.replace(
42228
+ /(<w:(?:t|delText)(?:\s[^>]*)?>)(\s+)(<\/w:(?:t|delText)>)/g,
42229
+ "$1[[sdspace]]$2[[sdspace]]$3"
42230
+ );
42191
42231
  return JSON.parse(xmljs.xml2json(newXml, null, 2));
42192
42232
  }
42193
42233
  /**
@@ -42410,7 +42450,7 @@ const _SuperConverter = class _SuperConverter2 {
42410
42450
  static getStoredSuperdocVersion(docx) {
42411
42451
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42412
42452
  }
42413
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.2") {
42453
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.21") {
42414
42454
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42415
42455
  }
42416
42456
  /**
@@ -45722,7 +45762,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
45722
45762
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
45723
45763
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
45724
45764
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
45725
- 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, 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;
45765
+ 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, 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;
45726
45766
  var GOOD_LEAF_SIZE = 200;
45727
45767
  var RopeSequence = function RopeSequence2() {
45728
45768
  };
@@ -57558,6 +57598,9 @@ const findMarkPosition = (doc2, pos, markName) => {
57558
57598
  return null;
57559
57599
  }
57560
57600
  const actualMark = start2.node.marks.find((mark) => mark.type.name === markName);
57601
+ if (!actualMark) {
57602
+ return null;
57603
+ }
57561
57604
  let startIndex = $pos.index();
57562
57605
  let startPos = $pos.start() + start2.offset;
57563
57606
  while (startIndex > 0 && actualMark.isInSet(parent.child(startIndex - 1).marks)) {
@@ -57847,6 +57890,70 @@ const getCommentPositionsById = (commentId, doc2) => {
57847
57890
  });
57848
57891
  return positions;
57849
57892
  };
57893
+ const getCommentMarkSegmentsById = (commentId, doc2) => {
57894
+ const segments = [];
57895
+ doc2.descendants((node, pos) => {
57896
+ if (!node.isInline) return;
57897
+ const commentMark = node.marks?.find(
57898
+ (mark) => mark.type.name === CommentMarkName$1 && mark.attrs?.commentId === commentId
57899
+ );
57900
+ if (!commentMark) return;
57901
+ segments.push({
57902
+ from: pos,
57903
+ to: pos + node.nodeSize,
57904
+ attrs: commentMark.attrs || {}
57905
+ });
57906
+ });
57907
+ return segments;
57908
+ };
57909
+ const getCommentMarkRangesById = (commentId, doc2) => {
57910
+ const segments = getCommentMarkSegmentsById(commentId, doc2);
57911
+ if (!segments.length) return { segments, ranges: [] };
57912
+ const ranges = [];
57913
+ let active = null;
57914
+ segments.forEach((seg) => {
57915
+ if (!active) {
57916
+ active = {
57917
+ from: seg.from,
57918
+ to: seg.to,
57919
+ internal: !!seg.attrs?.internal
57920
+ };
57921
+ return;
57922
+ }
57923
+ if (seg.from <= active.to) {
57924
+ active.to = Math.max(active.to, seg.to);
57925
+ return;
57926
+ }
57927
+ ranges.push(active);
57928
+ active = {
57929
+ from: seg.from,
57930
+ to: seg.to,
57931
+ internal: !!seg.attrs?.internal
57932
+ };
57933
+ });
57934
+ if (active) ranges.push(active);
57935
+ return { segments, ranges };
57936
+ };
57937
+ const resolveCommentById = ({ commentId, state: state2, tr, dispatch }) => {
57938
+ const { schema } = state2;
57939
+ const markType = schema.marks?.[CommentMarkName$1];
57940
+ if (!markType) return false;
57941
+ const { segments, ranges } = getCommentMarkRangesById(commentId, state2.doc);
57942
+ if (!segments.length) return false;
57943
+ segments.forEach(({ from: from2, to, attrs }) => {
57944
+ tr.removeMark(from2, to, markType.create(attrs));
57945
+ });
57946
+ const startType = schema.nodes?.commentRangeStart;
57947
+ const endType = schema.nodes?.commentRangeEnd;
57948
+ if (startType && endType) {
57949
+ ranges.slice().sort((a, b2) => b2.from - a.from).forEach(({ from: from2, to, internal }) => {
57950
+ tr.insert(to, endType.create({ "w:id": commentId }));
57951
+ tr.insert(from2, startType.create({ "w:id": commentId, internal }));
57952
+ });
57953
+ }
57954
+ dispatch(tr);
57955
+ return true;
57956
+ };
57850
57957
  const prepareCommentsForExport = (doc2, tr, schema, comments = []) => {
57851
57958
  const commentMap = /* @__PURE__ */ new Map();
57852
57959
  comments.forEach((c2) => {
@@ -57953,6 +58060,7 @@ const getPreparedComment = (attrs) => {
57953
58060
  const prepareCommentsForImport = (doc2, tr, schema, converter) => {
57954
58061
  const toMark = [];
57955
58062
  const toDelete = [];
58063
+ const toUpdate = [];
57956
58064
  doc2.descendants((node, pos) => {
57957
58065
  const { type: type2 } = node;
57958
58066
  const commentNodes = ["commentRangeStart", "commentRangeEnd", "commentReference"];
@@ -57961,8 +58069,9 @@ const prepareCommentsForImport = (doc2, tr, schema, converter) => {
57961
58069
  converter,
57962
58070
  importedId: node.attrs["w:id"]
57963
58071
  });
58072
+ const isDone = !!matchingImportedComment?.isDone;
57964
58073
  if (type2.name === "commentRangeStart") {
57965
- if (!matchingImportedComment?.isDone) {
58074
+ if (!isDone) {
57966
58075
  toMark.push({
57967
58076
  commentId: resolvedCommentId,
57968
58077
  importedId,
@@ -57976,8 +58085,29 @@ const prepareCommentsForImport = (doc2, tr, schema, converter) => {
57976
58085
  commentId: resolvedCommentId,
57977
58086
  importedId
57978
58087
  });
57979
- toDelete.push({ start: pos, end: pos + 1 });
58088
+ if (isDone) {
58089
+ toUpdate.push({
58090
+ pos,
58091
+ attrs: {
58092
+ ...node.attrs,
58093
+ "w:id": resolvedCommentId,
58094
+ internal
58095
+ }
58096
+ });
58097
+ } else {
58098
+ toDelete.push({ start: pos, end: pos + 1 });
58099
+ }
57980
58100
  } else if (type2.name === "commentRangeEnd") {
58101
+ if (isDone) {
58102
+ toUpdate.push({
58103
+ pos,
58104
+ attrs: {
58105
+ ...node.attrs,
58106
+ "w:id": resolvedCommentId
58107
+ }
58108
+ });
58109
+ return;
58110
+ }
57981
58111
  const itemToMark = toMark.find((p) => p.importedId === importedId);
57982
58112
  if (!itemToMark) return;
57983
58113
  const { start: start2 } = itemToMark;
@@ -57992,6 +58122,11 @@ const prepareCommentsForImport = (doc2, tr, schema, converter) => {
57992
58122
  toDelete.push({ start: pos, end: pos + 1 });
57993
58123
  }
57994
58124
  });
58125
+ if (typeof tr.setNodeMarkup === "function") {
58126
+ toUpdate.sort((a, b2) => b2.pos - a.pos).forEach(({ pos, attrs }) => {
58127
+ tr.setNodeMarkup(pos, void 0, attrs);
58128
+ });
58129
+ }
57995
58130
  toDelete.sort((a, b2) => b2.start - a.start).forEach(({ start: start2, end: end2 }) => {
57996
58131
  tr.delete(start2, end2);
57997
58132
  });
@@ -58185,7 +58320,7 @@ const CommentsPlugin = Extension.create({
58185
58320
  },
58186
58321
  resolveComment: ({ commentId }) => ({ tr, dispatch, state: state2 }) => {
58187
58322
  tr.setMeta(CommentsPluginKey, { event: "update" });
58188
- removeCommentsById({ commentId, state: state2, tr, dispatch });
58323
+ return resolveCommentById({ commentId, state: state2, tr, dispatch });
58189
58324
  },
58190
58325
  setCursorById: (id) => ({ state: state2, editor }) => {
58191
58326
  const { from: from2 } = findRangeById(state2.doc, id) || {};
@@ -58618,47 +58753,58 @@ function findRangeById(doc2, id) {
58618
58753
  return from2 !== null && to !== null ? { from: from2, to } : null;
58619
58754
  }
58620
58755
  const replaceStep = ({ state: state2, tr, step, newTr, map: map22, user, date, originalStep, originalStepIndex }) => {
58621
- const deletionMarkSchema = state2.schema.marks[TrackDeleteMarkName$1];
58622
- const deletionMark = findMark(state2, deletionMarkSchema, false);
58623
- const positionTo = deletionMark ? deletionMark.to : step.to;
58624
- const newStep = new ReplaceStep(
58625
- positionTo,
58626
- // We insert all the same steps, but with "from"/"to" both set to "to" in order not to delete content. Mapped as needed.
58627
- positionTo,
58628
- step.slice,
58629
- step.structure
58630
- );
58631
- const invertStep = originalStep.invert(tr.docs[originalStepIndex]).map(map22);
58632
- map22.appendMap(invertStep.getMap());
58633
- const meta = {};
58634
- if (newStep) {
58635
- const trTemp = state2.apply(newTr).tr;
58636
- if (trTemp.maybeStep(newStep).failed) {
58637
- return;
58638
- }
58639
- const mappedNewStepTo = newStep.getMap().map(newStep.to);
58640
- const insertedMark = markInsertion({
58641
- tr: trTemp,
58642
- from: newStep.from,
58643
- to: mappedNewStepTo,
58644
- user,
58645
- date
58646
- });
58647
- const condensedStep = new ReplaceStep(newStep.from, newStep.to, trTemp.doc.slice(newStep.from, mappedNewStepTo));
58648
- newTr.step(condensedStep);
58649
- const mirrorIndex = map22.maps.length - 1;
58650
- map22.appendMap(condensedStep.getMap(), mirrorIndex);
58651
- if (newStep.from !== mappedNewStepTo) {
58652
- meta.insertedMark = insertedMark;
58653
- meta.step = condensedStep;
58756
+ const trTemp = state2.apply(newTr).tr;
58757
+ let positionTo = step.to;
58758
+ const probePos = Math.max(step.from, step.to - 1);
58759
+ const deletionSpan = findMarkPosition(trTemp.doc, probePos, TrackDeleteMarkName$1);
58760
+ if (deletionSpan && deletionSpan.to > positionTo) {
58761
+ positionTo = deletionSpan.to;
58762
+ }
58763
+ const tryInsert = (slice2) => {
58764
+ const insertionStep = new ReplaceStep(positionTo, positionTo, slice2, false);
58765
+ if (trTemp.maybeStep(insertionStep).failed) return null;
58766
+ return {
58767
+ insertedFrom: insertionStep.from,
58768
+ insertedTo: insertionStep.getMap().map(insertionStep.to, 1)
58769
+ };
58770
+ };
58771
+ const insertion = tryInsert(step.slice) || tryInsert(Slice.maxOpen(step.slice.content, true));
58772
+ if (!insertion) {
58773
+ if (!newTr.maybeStep(step).failed) {
58774
+ map22.appendMap(step.getMap());
58654
58775
  }
58655
- if (!newTr.selection.eq(trTemp.selection)) {
58656
- newTr.setSelection(trTemp.selection);
58776
+ return;
58777
+ }
58778
+ const meta = {};
58779
+ const insertedMark = markInsertion({
58780
+ tr: trTemp,
58781
+ from: insertion.insertedFrom,
58782
+ to: insertion.insertedTo,
58783
+ user,
58784
+ date
58785
+ });
58786
+ const trackedInsertedSlice = trTemp.doc.slice(insertion.insertedFrom, insertion.insertedTo);
58787
+ const condensedStep = new ReplaceStep(positionTo, positionTo, trackedInsertedSlice, false);
58788
+ if (newTr.maybeStep(condensedStep).failed) {
58789
+ if (!newTr.maybeStep(step).failed) {
58790
+ map22.appendMap(step.getMap());
58657
58791
  }
58792
+ return;
58793
+ }
58794
+ const invertStep = originalStep.invert(tr.docs[originalStepIndex]).map(map22);
58795
+ map22.appendMap(invertStep.getMap());
58796
+ const mirrorIndex = map22.maps.length - 1;
58797
+ map22.appendMap(condensedStep.getMap(), mirrorIndex);
58798
+ if (insertion.insertedFrom !== insertion.insertedTo) {
58799
+ meta.insertedMark = insertedMark;
58800
+ meta.step = condensedStep;
58801
+ }
58802
+ if (!newTr.selection.eq(trTemp.selection)) {
58803
+ newTr.setSelection(trTemp.selection);
58658
58804
  }
58659
58805
  if (step.from !== step.to) {
58660
58806
  const {
58661
- deletionMark: deletionMark2,
58807
+ deletionMark,
58662
58808
  deletionMap,
58663
58809
  nodes: deletionNodes
58664
58810
  } = markDeletion({
@@ -58670,7 +58816,7 @@ const replaceStep = ({ state: state2, tr, step, newTr, map: map22, user, date, o
58670
58816
  id: meta.insertedMark?.attrs?.id
58671
58817
  });
58672
58818
  meta.deletionNodes = deletionNodes;
58673
- meta.deletionMark = deletionMark2;
58819
+ meta.deletionMark = deletionMark;
58674
58820
  map22.appendMapping(deletionMap);
58675
58821
  }
58676
58822
  newTr.setMeta(TrackChangesBasePluginKey, meta);
@@ -60491,7 +60637,7 @@ const isHeadless = (editor) => {
60491
60637
  const shouldSkipNodeView = (editor) => {
60492
60638
  return isHeadless(editor);
60493
60639
  };
60494
- const summaryVersion = "2.0.0-next.2";
60640
+ const summaryVersion = "2.0.0-next.21";
60495
60641
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
60496
60642
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
60497
60643
  function mapAttributes(attrs) {
@@ -61280,7 +61426,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61280
61426
  { default: remarkStringify },
61281
61427
  { default: remarkGfm }
61282
61428
  ] = await Promise.all([
61283
- import("./index-BqPa6D4q-8U4x8RP6.es.js"),
61429
+ import("./index--w_Fk0WX-D_kNY98j.es.js"),
61284
61430
  import("./index-DRCvimau-Cw339678.es.js"),
61285
61431
  import("./index-C_x_N6Uh-DJn8hIEt.es.js"),
61286
61432
  import("./index-D_sWOSiG-DE96TaT5.es.js"),
@@ -61485,7 +61631,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
61485
61631
  * Process collaboration migrations
61486
61632
  */
61487
61633
  processCollaborationMigrations() {
61488
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.2");
61634
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.21");
61489
61635
  if (!this.options.ydoc) return;
61490
61636
  const metaMap = this.options.ydoc.getMap("meta");
61491
61637
  let docVersion = metaMap.get("version");
@@ -67049,6 +67195,24 @@ const SDT_CONTAINER_STYLES = `
67049
67195
  display: block;
67050
67196
  }
67051
67197
 
67198
+ /* Viewing mode: remove structured content affordances */
67199
+ .presentation-editor--viewing .superdoc-structured-content-block,
67200
+ .presentation-editor--viewing .superdoc-structured-content-inline {
67201
+ background: none;
67202
+ border: none;
67203
+ padding: 0;
67204
+ }
67205
+
67206
+ .presentation-editor--viewing .superdoc-structured-content-inline:hover {
67207
+ background: none;
67208
+ border: none;
67209
+ }
67210
+
67211
+ .presentation-editor--viewing .superdoc-structured-content__label,
67212
+ .presentation-editor--viewing .superdoc-structured-content-inline__label {
67213
+ display: none !important;
67214
+ }
67215
+
67052
67216
  /* Print mode: hide visual styling for SDT containers */
67053
67217
  @media print {
67054
67218
  .superdoc-document-section,
@@ -68737,7 +68901,7 @@ function isMinimalWordLayout(value) {
68737
68901
  return true;
68738
68902
  }
68739
68903
  const LIST_MARKER_GAP$2 = 8;
68740
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
68904
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
68741
68905
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
68742
68906
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
68743
68907
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -69664,6 +69828,7 @@ const _DomPainter = class _DomPainter2 {
69664
69828
  const block = lookup2.block;
69665
69829
  const measure = lookup2.measure;
69666
69830
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
69831
+ const alignment2 = block.attrs?.alignment;
69667
69832
  const fragmentEl = this.doc.createElement("div");
69668
69833
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
69669
69834
  const isTocEntry = block.attrs?.isTocEntry;
@@ -69742,7 +69907,7 @@ const _DomPainter = class _DomPainter2 {
69742
69907
  const textStart = paraIndentLeft + firstLine;
69743
69908
  tabWidth = textStart - currentPos;
69744
69909
  if (tabWidth <= 0) {
69745
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
69910
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
69746
69911
  } else if (tabWidth < LIST_MARKER_GAP$2) {
69747
69912
  tabWidth = LIST_MARKER_GAP$2;
69748
69913
  }
@@ -69769,6 +69934,21 @@ const _DomPainter = class _DomPainter2 {
69769
69934
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
69770
69935
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
69771
69936
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
69937
+ if (alignment2 === "justify" || alignment2 === "both") {
69938
+ console.log(
69939
+ "[justify-debug][painter-firstline-available]",
69940
+ JSON.stringify({
69941
+ blockId: block.id,
69942
+ fragmentWidth: fragment.width,
69943
+ markerTabWidth: listFirstLineMarkerTabWidth,
69944
+ paraIndentRight,
69945
+ availableWidthOverride,
69946
+ lineMaxWidth: line.maxWidth ?? null,
69947
+ lineWidth: line.width,
69948
+ lineNaturalWidth: line.naturalWidth ?? null
69949
+ })
69950
+ );
69951
+ }
69772
69952
  }
69773
69953
  const isLastLineOfFragment = index2 === lines.length - 1;
69774
69954
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -69894,7 +70074,7 @@ const _DomPainter = class _DomPainter2 {
69894
70074
  const textStart = paraIndentLeft + firstLine;
69895
70075
  tabWidth = textStart - currentPos;
69896
70076
  if (tabWidth <= 0) {
69897
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
70077
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
69898
70078
  } else if (tabWidth < LIST_MARKER_GAP$2) {
69899
70079
  tabWidth = LIST_MARKER_GAP$2;
69900
70080
  }
@@ -71428,6 +71608,23 @@ const _DomPainter = class _DomPainter2 {
71428
71608
  if (spacingPerSpace !== 0) {
71429
71609
  el.style.wordSpacing = `${spacingPerSpace}px`;
71430
71610
  }
71611
+ if (justifyShouldApply && spacingPerSpace < 0) {
71612
+ console.log(
71613
+ "[justify-debug][painter-wordspacing-negative]",
71614
+ JSON.stringify({
71615
+ blockId: block.id,
71616
+ lineIndex: lineIndex ?? null,
71617
+ alignment: alignment2 ?? null,
71618
+ availableWidth,
71619
+ lineWidth,
71620
+ lineMaxWidth: line.maxWidth ?? null,
71621
+ lineNaturalWidth: line.naturalWidth ?? null,
71622
+ spaceCount,
71623
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
71624
+ skipJustify: Boolean(skipJustify)
71625
+ })
71626
+ );
71627
+ }
71431
71628
  if (hasExplicitPositioning && line.segments) {
71432
71629
  const paraIndent = block.attrs?.indent;
71433
71630
  const indentLeft = paraIndent?.left ?? 0;
@@ -73621,6 +73818,28 @@ let measurementCtx = null;
73621
73818
  const TAB_CHAR_LENGTH = 1;
73622
73819
  const SPACE_CHARS = SPACE_CHARS$1;
73623
73820
  const isTabRun$1 = (run2) => run2?.kind === "tab";
73821
+ const isWordChar$3 = (char) => {
73822
+ if (!char) return false;
73823
+ const code = char.charCodeAt(0);
73824
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
73825
+ };
73826
+ const capitalizeText$2 = (text) => {
73827
+ if (!text) return text;
73828
+ let result = "";
73829
+ for (let i = 0; i < text.length; i += 1) {
73830
+ const prevChar = i > 0 ? text[i - 1] : "";
73831
+ const ch = text[i];
73832
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
73833
+ }
73834
+ return result;
73835
+ };
73836
+ const applyTextTransform$2 = (text, transform) => {
73837
+ if (!text || !transform || transform === "none") return text;
73838
+ if (transform === "uppercase") return text.toUpperCase();
73839
+ if (transform === "lowercase") return text.toLowerCase();
73840
+ if (transform === "capitalize") return capitalizeText$2(text);
73841
+ return text;
73842
+ };
73624
73843
  function getMeasurementContext() {
73625
73844
  if (measurementCtx) return measurementCtx;
73626
73845
  if (typeof document === "undefined") {
@@ -73796,17 +74015,19 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
73796
74015
  }
73797
74016
  const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
73798
74017
  const runLength = text.length;
74018
+ const transform = isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? void 0 : run2.textTransform;
74019
+ const displayText = applyTextTransform$2(text, transform);
73799
74020
  if (currentCharOffset + runLength >= charOffset) {
73800
74021
  const offsetInRun = charOffset - currentCharOffset;
73801
74022
  ctx2.font = getRunFontString(run2);
73802
- const textUpToTarget = text.slice(0, offsetInRun);
74023
+ const textUpToTarget = displayText.slice(0, offsetInRun);
73803
74024
  const measured2 = ctx2.measureText(textUpToTarget);
73804
74025
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
73805
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
74026
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text.slice(0, offsetInRun)) : 0;
73806
74027
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
73807
74028
  }
73808
74029
  ctx2.font = getRunFontString(run2);
73809
- const measured = ctx2.measureText(text);
74030
+ const measured = ctx2.measureText(displayText);
73810
74031
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
73811
74032
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text) : 0;
73812
74033
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -73845,8 +74066,10 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
73845
74066
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
73846
74067
  }
73847
74068
  const text = run2.text ?? "";
73848
- const segmentText = text.slice(segment.fromChar, segment.toChar);
73849
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
74069
+ const transform = "textTransform" in run2 ? run2.textTransform : void 0;
74070
+ const displayText = applyTextTransform$2(text, transform);
74071
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
74072
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
73850
74073
  ctx2.font = getRunFontString(run2);
73851
74074
  const measured = ctx2.measureText(textUpToTarget);
73852
74075
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -73942,12 +74165,14 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73942
74165
  }
73943
74166
  const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
73944
74167
  const runLength = text.length;
74168
+ const transform = isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? void 0 : run2.textTransform;
74169
+ const displayText = applyTextTransform$2(text, transform);
73945
74170
  if (runLength === 0) continue;
73946
74171
  ctx2.font = getRunFontString(run2);
73947
74172
  for (let i = 0; i <= runLength; i++) {
73948
- const textUpToChar = text.slice(0, i);
74173
+ const textUpToChar = displayText.slice(0, i);
73949
74174
  const measured2 = ctx2.measureText(textUpToChar);
73950
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
74175
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text.slice(0, i)) : 0;
73951
74176
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
73952
74177
  if (charX >= safeX) {
73953
74178
  if (i === 0) {
@@ -73957,7 +74182,7 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73957
74182
  pmPosition: pmPosition3
73958
74183
  };
73959
74184
  }
73960
- const prevText = text.slice(0, i - 1);
74185
+ const prevText = displayText.slice(0, i - 1);
73961
74186
  const prevMeasured = ctx2.measureText(prevText);
73962
74187
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run2, i - 1, runLength);
73963
74188
  const distToPrev = Math.abs(safeX - prevX);
@@ -73970,7 +74195,7 @@ function findCharacterAtX(block, line, x2, pmStart, availableWidthOverride, alig
73970
74195
  };
73971
74196
  }
73972
74197
  }
73973
- const measured = ctx2.measureText(text);
74198
+ const measured = ctx2.measureText(displayText);
73974
74199
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
73975
74200
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
73976
74201
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -74401,6 +74626,83 @@ function findCharIndexAtX(textNode, container, targetX) {
74401
74626
  }
74402
74627
  return index2;
74403
74628
  }
74629
+ const LIST_MARKER_GAP$1 = 8;
74630
+ const MIN_MARKER_GUTTER = 24;
74631
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
74632
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
74633
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
74634
+ const SPACE_SUFFIX_GAP_PX = 4;
74635
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
74636
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
74637
+ const marker = wordLayout?.marker;
74638
+ if (!marker) {
74639
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
74640
+ return textStartPx;
74641
+ }
74642
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
74643
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
74644
+ if (markerTextWidth == null && marker.markerText) {
74645
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
74646
+ }
74647
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth !== void 0 && markerTextWidth < 0) {
74648
+ markerTextWidth = markerBoxWidth;
74649
+ }
74650
+ const finalMarkerTextWidth = Math.max(0, markerTextWidth ?? 0);
74651
+ let markerStartPos;
74652
+ if (wordLayout?.firstLineIndentMode === true && typeof marker.markerX === "number" && Number.isFinite(marker.markerX)) {
74653
+ markerStartPos = marker.markerX;
74654
+ } else {
74655
+ markerStartPos = indentLeft - hanging + firstLine;
74656
+ }
74657
+ if (!Number.isFinite(markerStartPos)) {
74658
+ markerStartPos = 0;
74659
+ }
74660
+ const currentPos = markerStartPos + finalMarkerTextWidth;
74661
+ const suffix2 = marker.suffix ?? "tab";
74662
+ if (suffix2 === "space") {
74663
+ return markerStartPos + finalMarkerTextWidth + SPACE_SUFFIX_GAP_PX;
74664
+ }
74665
+ if (suffix2 === "nothing") {
74666
+ return markerStartPos + finalMarkerTextWidth;
74667
+ }
74668
+ const markerJustification = marker.justification ?? "left";
74669
+ if (markerJustification !== "left") {
74670
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
74671
+ return markerStartPos + finalMarkerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
74672
+ }
74673
+ if (wordLayout?.firstLineIndentMode === true) {
74674
+ let targetTabStop;
74675
+ if (Array.isArray(wordLayout.tabsPx)) {
74676
+ for (const tab of wordLayout.tabsPx) {
74677
+ if (typeof tab === "number" && tab > currentPos) {
74678
+ targetTabStop = tab;
74679
+ break;
74680
+ }
74681
+ }
74682
+ }
74683
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
74684
+ let tabWidth2;
74685
+ if (targetTabStop !== void 0) {
74686
+ tabWidth2 = targetTabStop - currentPos;
74687
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
74688
+ tabWidth2 = textStartTarget - currentPos;
74689
+ } else {
74690
+ tabWidth2 = LIST_MARKER_GAP$1;
74691
+ }
74692
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
74693
+ tabWidth2 = LIST_MARKER_GAP$1;
74694
+ }
74695
+ return markerStartPos + finalMarkerTextWidth + tabWidth2;
74696
+ }
74697
+ const textStart = indentLeft + firstLine;
74698
+ let tabWidth = textStart - currentPos;
74699
+ if (tabWidth <= 0) {
74700
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
74701
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
74702
+ tabWidth = LIST_MARKER_GAP$1;
74703
+ }
74704
+ return markerStartPos + finalMarkerTextWidth + tabWidth;
74705
+ }
74404
74706
  function getWordLayoutConfig(block) {
74405
74707
  if (!block || block.kind !== "paragraph") {
74406
74708
  return void 0;
@@ -74433,9 +74735,16 @@ function calculateTextStartIndent(params2) {
74433
74735
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
74434
74736
  let indentAdjust = paraIndentLeft;
74435
74737
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
74738
+ const resolvedTextStart = resolveListTextStartPx(
74739
+ wordLayout,
74740
+ paraIndentLeft,
74741
+ Math.max(firstLineIndent, 0),
74742
+ Math.max(hangingIndent, 0),
74743
+ () => markerWidth
74744
+ // Use provided markerWidth since we don't have canvas access here
74745
+ );
74436
74746
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
74437
- const markerTextStartX = wordLayout?.marker?.textStartX;
74438
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
74747
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
74439
74748
  } else if (isFirstLine && !isListItem2) {
74440
74749
  indentAdjust += firstLineOffset;
74441
74750
  }
@@ -74591,7 +74900,10 @@ function getHeaderFooterTypeForSection(pageNumber, sectionIndex, identifier, opt
74591
74900
  }
74592
74901
  function createFloatingObjectManager(columns, margins, pageWidth) {
74593
74902
  const zones = [];
74594
- const marginLeft = Math.max(0, margins?.left ?? 0);
74903
+ let currentColumns = columns;
74904
+ let currentMargins = margins;
74905
+ let currentPageWidth = pageWidth;
74906
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
74595
74907
  return {
74596
74908
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
74597
74909
  if (!drawingBlock.anchor?.isAnchored) {
@@ -74604,7 +74916,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74604
74916
  }
74605
74917
  const objectWidth = measure.width ?? 0;
74606
74918
  const objectHeight = measure.height ?? 0;
74607
- const x2 = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
74919
+ const x2 = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
74608
74920
  const y2 = anchorY + (anchor.offsetV ?? 0);
74609
74921
  const zone = {
74610
74922
  imageBlockId: drawingBlock.id,
@@ -74638,7 +74950,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74638
74950
  }
74639
74951
  const tableWidth = measure.totalWidth ?? 0;
74640
74952
  const tableHeight = measure.totalHeight ?? 0;
74641
- const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
74953
+ const x2 = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
74642
74954
  const y2 = anchorY + (anchor.offsetV ?? 0);
74643
74955
  const zone = {
74644
74956
  imageBlockId: tableBlock.id,
@@ -74686,7 +74998,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74686
74998
  }
74687
74999
  const leftFloats = [];
74688
75000
  const rightFloats = [];
74689
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
75001
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
74690
75002
  const columnCenter = columnOrigin + baseWidth / 2;
74691
75003
  for (const zone of wrappingZones) {
74692
75004
  if (zone.wrapMode === "left") {
@@ -74725,6 +75037,22 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
74725
75037
  },
74726
75038
  clear() {
74727
75039
  zones.length = 0;
75040
+ },
75041
+ /**
75042
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
75043
+ * This method should be called when the layout configuration changes (e.g., section breaks,
75044
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
75045
+ * correctly relative to the new layout boundaries.
75046
+ *
75047
+ * @param nextColumns - Column layout configuration (width, gap, count)
75048
+ * @param nextMargins - Optional page margins (left, right) in pixels
75049
+ * @param nextPageWidth - Optional total page width in pixels
75050
+ */
75051
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
75052
+ currentColumns = nextColumns;
75053
+ currentMargins = nextMargins;
75054
+ currentPageWidth = nextPageWidth;
75055
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
74728
75056
  }
74729
75057
  };
74730
75058
  }
@@ -74824,7 +75152,14 @@ function computeNextSectionPropsAtBreak(blocks) {
74824
75152
  const props = {};
74825
75153
  if (source.kind !== "sectionBreak") return props;
74826
75154
  if (source.margins) {
74827
- props.margins = { header: source.margins.header, footer: source.margins.footer };
75155
+ props.margins = {
75156
+ header: source.margins.header,
75157
+ footer: source.margins.footer,
75158
+ top: source.margins.top,
75159
+ right: source.margins.right,
75160
+ bottom: source.margins.bottom,
75161
+ left: source.margins.left
75162
+ };
74828
75163
  }
74829
75164
  if (source.pageSize) {
74830
75165
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -74855,13 +75190,13 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74855
75190
  if (maxHeaderContentHeight > 0) {
74856
75191
  return Math.max(baseTop, headerDistance + maxHeaderContentHeight);
74857
75192
  }
74858
- return Math.max(baseTop, headerDistance);
75193
+ return baseTop;
74859
75194
  };
74860
75195
  const calcRequiredBottomMargin = (footerDistance, baseBottom) => {
74861
75196
  if (maxFooterContentHeight > 0) {
74862
75197
  return Math.max(baseBottom, footerDistance + maxFooterContentHeight);
74863
75198
  }
74864
- return Math.max(baseBottom, footerDistance);
75199
+ return baseBottom;
74865
75200
  };
74866
75201
  if (block.attrs?.isFirstSection && !next.hasAnyPages) {
74867
75202
  if (block.pageSize) {
@@ -74872,20 +75207,36 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74872
75207
  next.activeOrientation = block.orientation;
74873
75208
  next.pendingOrientation = null;
74874
75209
  }
75210
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
75211
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
75212
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
75213
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
74875
75214
  if (block.margins?.header !== void 0) {
74876
- const headerDistance = Math.max(0, block.margins.header);
74877
75215
  next.activeHeaderDistance = headerDistance;
74878
75216
  next.pendingHeaderDistance = headerDistance;
74879
- next.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
74880
- next.pendingTopMargin = next.activeTopMargin;
74881
75217
  }
74882
75218
  if (block.margins?.footer !== void 0) {
74883
- const footerDistance = Math.max(0, block.margins.footer);
74884
75219
  next.activeFooterDistance = footerDistance;
74885
75220
  next.pendingFooterDistance = footerDistance;
74886
- next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
75221
+ }
75222
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
75223
+ next.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
75224
+ next.pendingTopMargin = next.activeTopMargin;
75225
+ }
75226
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
75227
+ next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
74887
75228
  next.pendingBottomMargin = next.activeBottomMargin;
74888
75229
  }
75230
+ if (block.margins?.left !== void 0) {
75231
+ const leftMargin = Math.max(0, block.margins.left);
75232
+ next.activeLeftMargin = leftMargin;
75233
+ next.pendingLeftMargin = leftMargin;
75234
+ }
75235
+ if (block.margins?.right !== void 0) {
75236
+ const rightMargin = Math.max(0, block.margins.right);
75237
+ next.activeRightMargin = rightMargin;
75238
+ next.pendingRightMargin = rightMargin;
75239
+ }
74889
75240
  if (block.columns) {
74890
75241
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
74891
75242
  next.pendingColumns = null;
@@ -74894,26 +75245,42 @@ function scheduleSectionBreak(block, state2, baseMargins, maxHeaderContentHeight
74894
75245
  }
74895
75246
  const headerPx = block.margins?.header;
74896
75247
  const footerPx = block.margins?.footer;
75248
+ const topPx = block.margins?.top;
75249
+ const bottomPx = block.margins?.bottom;
74897
75250
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
74898
75251
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
75252
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
75253
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
74899
75254
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
74900
75255
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
74901
- if (typeof headerPx === "number") {
74902
- const newHeaderDist = Math.max(0, headerPx);
75256
+ if (typeof headerPx === "number" || typeof topPx === "number") {
75257
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
75258
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
74903
75259
  next.pendingHeaderDistance = newHeaderDist;
74904
- next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
75260
+ next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
74905
75261
  } else {
74906
75262
  next.pendingTopMargin = nextTop;
74907
75263
  next.pendingHeaderDistance = nextHeader;
74908
75264
  }
74909
- if (typeof footerPx === "number") {
74910
- const newFooterDist = Math.max(0, footerPx);
75265
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
75266
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
75267
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
74911
75268
  next.pendingFooterDistance = newFooterDist;
74912
- next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
75269
+ next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
74913
75270
  } else {
74914
75271
  next.pendingBottomMargin = nextBottom;
74915
75272
  next.pendingFooterDistance = nextFooter;
74916
75273
  }
75274
+ if (typeof block.margins?.left === "number") {
75275
+ next.pendingLeftMargin = Math.max(0, block.margins.left);
75276
+ } else {
75277
+ next.pendingLeftMargin = nextLeft;
75278
+ }
75279
+ if (typeof block.margins?.right === "number") {
75280
+ next.pendingRightMargin = Math.max(0, block.margins.right);
75281
+ } else {
75282
+ next.pendingRightMargin = nextRight;
75283
+ }
74917
75284
  if (block.pageSize) {
74918
75285
  next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
74919
75286
  }
@@ -74973,6 +75340,12 @@ function applyPendingToActive(state2) {
74973
75340
  if (next.pendingBottomMargin != null) {
74974
75341
  next.activeBottomMargin = next.pendingBottomMargin;
74975
75342
  }
75343
+ if (next.pendingLeftMargin != null) {
75344
+ next.activeLeftMargin = next.pendingLeftMargin;
75345
+ }
75346
+ if (next.pendingRightMargin != null) {
75347
+ next.activeRightMargin = next.pendingRightMargin;
75348
+ }
74976
75349
  if (next.pendingHeaderDistance != null) {
74977
75350
  next.activeHeaderDistance = next.pendingHeaderDistance;
74978
75351
  }
@@ -74990,6 +75363,8 @@ function applyPendingToActive(state2) {
74990
75363
  }
74991
75364
  next.pendingTopMargin = null;
74992
75365
  next.pendingBottomMargin = null;
75366
+ next.pendingLeftMargin = null;
75367
+ next.pendingRightMargin = null;
74993
75368
  next.pendingHeaderDistance = null;
74994
75369
  next.pendingFooterDistance = null;
74995
75370
  next.pendingPageSize = null;
@@ -75218,7 +75593,8 @@ function layoutParagraphBlock(ctx2, anchors) {
75218
75593
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
75219
75594
  const firstLineIndent = calculateFirstLineIndent(block, measure);
75220
75595
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
75221
- lines = normalizeLines(newMeasure);
75596
+ const newLines = normalizeLines(newMeasure);
75597
+ lines = newLines;
75222
75598
  didRemeasureForColumnWidth = true;
75223
75599
  }
75224
75600
  let fromLine = 0;
@@ -75300,7 +75676,8 @@ function layoutParagraphBlock(ctx2, anchors) {
75300
75676
  if (narrowestRemeasureWidth < remeasureWidth) {
75301
75677
  const firstLineIndent = calculateFirstLineIndent(block, measure);
75302
75678
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
75303
- lines = normalizeLines(newMeasure);
75679
+ const newLines = normalizeLines(newMeasure);
75680
+ lines = newLines;
75304
75681
  didRemeasureForFloats = true;
75305
75682
  }
75306
75683
  }
@@ -75320,6 +75697,11 @@ function layoutParagraphBlock(ctx2, anchors) {
75320
75697
  const prevTrailing = state2.trailingSpacing ?? 0;
75321
75698
  const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
75322
75699
  if (state2.cursorY + neededSpacingBefore > state2.contentBottom) {
75700
+ if (state2.cursorY <= state2.topMargin) {
75701
+ state2.trailingSpacing = 0;
75702
+ appliedSpacingBefore = true;
75703
+ break;
75704
+ }
75323
75705
  state2 = advanceColumn(state2);
75324
75706
  if (state2.trailingSpacing == null) state2.trailingSpacing = 0;
75325
75707
  continue;
@@ -75644,6 +76026,94 @@ function getCellPadding(cellIdx, blockRow) {
75644
76026
  function getCellTotalLines(cell) {
75645
76027
  return getCellLines(cell).length;
75646
76028
  }
76029
+ function mergePmRange(target, range2) {
76030
+ if (typeof range2.pmStart === "number") {
76031
+ target.pmStart = target.pmStart == null ? range2.pmStart : Math.min(target.pmStart, range2.pmStart);
76032
+ }
76033
+ if (typeof range2.pmEnd === "number") {
76034
+ target.pmEnd = target.pmEnd == null ? range2.pmEnd : Math.max(target.pmEnd, range2.pmEnd);
76035
+ }
76036
+ }
76037
+ function computeCellPmRange(cell, cellMeasure, fromLine, toLine) {
76038
+ const range2 = {};
76039
+ if (!cell || !cellMeasure) return range2;
76040
+ const cellBlocks = cell.blocks ?? (cell.paragraph ? [cell.paragraph] : []);
76041
+ const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
76042
+ const maxBlocks = Math.min(cellBlocks.length, blockMeasures.length);
76043
+ let cumulativeLineCount = 0;
76044
+ for (let i = 0; i < maxBlocks; i++) {
76045
+ const block = cellBlocks[i];
76046
+ const blockMeasure = blockMeasures[i];
76047
+ if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
76048
+ const paraMeasure = blockMeasure;
76049
+ const lines = paraMeasure.lines;
76050
+ const blockLineCount = lines?.length ?? 0;
76051
+ const blockStartGlobal = cumulativeLineCount;
76052
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
76053
+ const localFrom = Math.max(fromLine, blockStartGlobal) - blockStartGlobal;
76054
+ const localTo = Math.min(toLine, blockEndGlobal) - blockStartGlobal;
76055
+ if (lines && lines.length > 0 && localFrom < localTo) {
76056
+ mergePmRange(range2, computeFragmentPmRange(block, lines, localFrom, localTo));
76057
+ } else {
76058
+ mergePmRange(range2, extractBlockPmRange(block));
76059
+ }
76060
+ cumulativeLineCount += blockLineCount;
76061
+ continue;
76062
+ }
76063
+ mergePmRange(range2, extractBlockPmRange(block));
76064
+ }
76065
+ return range2;
76066
+ }
76067
+ function computeTableFragmentPmRange(block, measure, fromRow, toRow, partialRow) {
76068
+ const range2 = {};
76069
+ for (let rowIndex = fromRow; rowIndex < toRow; rowIndex++) {
76070
+ const row = block.rows[rowIndex];
76071
+ const rowMeasure = measure.rows[rowIndex];
76072
+ if (!row || !rowMeasure) continue;
76073
+ const isPartial = partialRow?.rowIndex === rowIndex;
76074
+ const cellCount = Math.min(row.cells.length, rowMeasure.cells.length);
76075
+ for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
76076
+ const cell = row.cells[cellIndex];
76077
+ const cellMeasure = rowMeasure.cells[cellIndex];
76078
+ if (!cell || !cellMeasure) continue;
76079
+ const totalLines = getCellTotalLines(cellMeasure);
76080
+ let fromLine = 0;
76081
+ let toLine = totalLines;
76082
+ if (isPartial) {
76083
+ const hasValidFromLineByCell = partialRow?.fromLineByCell && cellIndex < partialRow.fromLineByCell.length;
76084
+ const hasValidToLineByCell = partialRow?.toLineByCell && cellIndex < partialRow.toLineByCell.length;
76085
+ if (hasValidFromLineByCell) {
76086
+ const rawFrom = partialRow.fromLineByCell[cellIndex];
76087
+ if (typeof rawFrom === "number" && rawFrom >= 0) {
76088
+ fromLine = rawFrom;
76089
+ }
76090
+ }
76091
+ if (hasValidToLineByCell) {
76092
+ const rawTo = partialRow.toLineByCell[cellIndex];
76093
+ if (typeof rawTo === "number") {
76094
+ toLine = rawTo === -1 ? totalLines : rawTo;
76095
+ }
76096
+ }
76097
+ }
76098
+ fromLine = Math.max(0, Math.min(fromLine, totalLines));
76099
+ toLine = Math.max(0, Math.min(toLine, totalLines));
76100
+ if (toLine < fromLine) {
76101
+ toLine = fromLine;
76102
+ }
76103
+ mergePmRange(range2, computeCellPmRange(cell, cellMeasure, fromLine, toLine));
76104
+ }
76105
+ }
76106
+ return range2;
76107
+ }
76108
+ function applyTableFragmentPmRange(fragment, block, measure) {
76109
+ const range2 = computeTableFragmentPmRange(block, measure, fragment.fromRow, fragment.toRow, fragment.partialRow);
76110
+ if (range2.pmStart != null) {
76111
+ fragment.pmStart = range2.pmStart;
76112
+ }
76113
+ if (range2.pmEnd != null) {
76114
+ fragment.pmEnd = range2.pmEnd;
76115
+ }
76116
+ }
75647
76117
  function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
75648
76118
  const row = measure.rows[rowIndex];
75649
76119
  if (!row) {
@@ -75788,6 +76258,7 @@ function layoutMonolithicTable(context) {
75788
76258
  height,
75789
76259
  metadata
75790
76260
  };
76261
+ applyTableFragmentPmRange(fragment, context.block, context.measure);
75791
76262
  state2.page.fragments.push(fragment);
75792
76263
  state2.cursorY += height;
75793
76264
  }
@@ -75866,6 +76337,7 @@ function layoutTableBlock({
75866
76337
  height,
75867
76338
  metadata
75868
76339
  };
76340
+ applyTableFragmentPmRange(fragment, block, measure);
75869
76341
  state2.page.fragments.push(fragment);
75870
76342
  state2.cursorY += height;
75871
76343
  return;
@@ -75929,6 +76401,7 @@ function layoutTableBlock({
75929
76401
  partialRow: continuationPartialRow,
75930
76402
  metadata: generateFragmentMetadata(measure)
75931
76403
  };
76404
+ applyTableFragmentPmRange(fragment2, block, measure);
75932
76405
  state2.page.fragments.push(fragment2);
75933
76406
  state2.cursorY += fragmentHeight2;
75934
76407
  }
@@ -75973,6 +76446,7 @@ function layoutTableBlock({
75973
76446
  partialRow: forcedPartialRow,
75974
76447
  metadata: generateFragmentMetadata(measure)
75975
76448
  };
76449
+ applyTableFragmentPmRange(fragment2, block, measure);
75976
76450
  state2.page.fragments.push(fragment2);
75977
76451
  state2.cursorY += fragmentHeight2;
75978
76452
  pendingPartialRow = forcedPartialRow;
@@ -76008,6 +76482,7 @@ function layoutTableBlock({
76008
76482
  partialRow: partialRow || void 0,
76009
76483
  metadata: generateFragmentMetadata(measure)
76010
76484
  };
76485
+ applyTableFragmentPmRange(fragment, block, measure);
76011
76486
  state2.page.fragments.push(fragment);
76012
76487
  state2.cursorY += fragmentHeight;
76013
76488
  if (partialRow && !partialRow.isLastPart) {
@@ -76025,7 +76500,7 @@ function createAnchoredTableFragment(block, measure, x2, y2) {
76025
76500
  columnBoundaries: generateColumnBoundaries(measure),
76026
76501
  coordinateSystem: "fragment"
76027
76502
  };
76028
- return {
76503
+ const fragment = {
76029
76504
  kind: "table",
76030
76505
  blockId: block.id,
76031
76506
  fromRow: 0,
@@ -76036,6 +76511,8 @@ function createAnchoredTableFragment(block, measure, x2, y2) {
76036
76511
  height: measure.totalHeight ?? 0,
76037
76512
  metadata
76038
76513
  };
76514
+ applyTableFragmentPmRange(fragment, block, measure);
76515
+ return fragment;
76039
76516
  }
76040
76517
  function isPageRelativeAnchor(block) {
76041
76518
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -76457,8 +76934,8 @@ function layoutDocument(blocks, measures, options = {}) {
76457
76934
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
76458
76935
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
76459
76936
  };
76460
- const contentWidth = pageSize.w - (margins.left + margins.right);
76461
- if (contentWidth <= 0) {
76937
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
76938
+ if (baseContentWidth <= 0) {
76462
76939
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
76463
76940
  }
76464
76941
  const validateContentHeight = (height) => {
@@ -76488,8 +76965,12 @@ function layoutDocument(blocks, measures, options = {}) {
76488
76965
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
76489
76966
  let activeTopMargin = effectiveTopMargin;
76490
76967
  let activeBottomMargin = effectiveBottomMargin;
76968
+ let activeLeftMargin = margins.left;
76969
+ let activeRightMargin = margins.right;
76491
76970
  let pendingTopMargin = null;
76492
76971
  let pendingBottomMargin = null;
76972
+ let pendingLeftMargin = null;
76973
+ let pendingRightMargin = null;
76493
76974
  let activeHeaderDistance = margins.header ?? margins.top;
76494
76975
  let pendingHeaderDistance = null;
76495
76976
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -76502,10 +76983,11 @@ function layoutDocument(blocks, measures, options = {}) {
76502
76983
  let pendingOrientation = null;
76503
76984
  let activeVAlign = null;
76504
76985
  let pendingVAlign = null;
76986
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
76505
76987
  const floatManager = createFloatingObjectManager(
76506
- normalizeColumns(activeColumns, contentWidth),
76507
- { left: margins.left, right: margins.right },
76508
- pageSize.w
76988
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
76989
+ { left: activeLeftMargin, right: activeRightMargin },
76990
+ activePageSize.w
76509
76991
  );
76510
76992
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks);
76511
76993
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
@@ -76522,22 +77004,38 @@ function layoutDocument(blocks, measures, options = {}) {
76522
77004
  next.activeOrientation = block.orientation;
76523
77005
  next.pendingOrientation = null;
76524
77006
  }
77007
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
77008
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
77009
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
77010
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
76525
77011
  if (block.margins?.header !== void 0) {
76526
- const headerDist = Math.max(0, block.margins.header);
76527
- next.activeHeaderDistance = headerDist;
76528
- next.pendingHeaderDistance = headerDist;
76529
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
76530
- next.activeTopMargin = Math.max(baseMargins.top, requiredTop);
76531
- next.pendingTopMargin = next.activeTopMargin;
77012
+ next.activeHeaderDistance = headerDistance2;
77013
+ next.pendingHeaderDistance = headerDistance2;
76532
77014
  }
76533
77015
  if (block.margins?.footer !== void 0) {
76534
- const footerDistance2 = Math.max(0, block.margins.footer);
76535
77016
  next.activeFooterDistance = footerDistance2;
76536
77017
  next.pendingFooterDistance = footerDistance2;
76537
- const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
76538
- next.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
77018
+ }
77019
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
77020
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : 0;
77021
+ next.activeTopMargin = Math.max(sectionTop, requiredTop);
77022
+ next.pendingTopMargin = next.activeTopMargin;
77023
+ }
77024
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
77025
+ const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : 0;
77026
+ next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
76539
77027
  next.pendingBottomMargin = next.activeBottomMargin;
76540
77028
  }
77029
+ if (block.margins?.left !== void 0) {
77030
+ const leftMargin = Math.max(0, block.margins.left);
77031
+ next.activeLeftMargin = leftMargin;
77032
+ next.pendingLeftMargin = leftMargin;
77033
+ }
77034
+ if (block.margins?.right !== void 0) {
77035
+ const rightMargin = Math.max(0, block.margins.right);
77036
+ next.activeRightMargin = rightMargin;
77037
+ next.pendingRightMargin = rightMargin;
77038
+ }
76541
77039
  if (block.columns) {
76542
77040
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
76543
77041
  next.pendingColumns = null;
@@ -76566,27 +77064,35 @@ function layoutDocument(blocks, measures, options = {}) {
76566
77064
  const headerPx = block.margins?.header;
76567
77065
  const footerPx = block.margins?.footer;
76568
77066
  const topPx = block.margins?.top;
77067
+ const bottomPx = block.margins?.bottom;
77068
+ const leftPx = block.margins?.left;
77069
+ const rightPx = block.margins?.right;
76569
77070
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
76570
77071
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
77072
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
77073
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
76571
77074
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
76572
77075
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
76573
77076
  next.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
76574
77077
  next.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
76575
77078
  if (typeof headerPx === "number" || typeof topPx === "number") {
76576
- const sectionTop = topPx ?? baseMargins.top;
77079
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
76577
77080
  const sectionHeader = next.pendingHeaderDistance;
76578
77081
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
76579
77082
  next.pendingTopMargin = Math.max(sectionTop, requiredTop);
76580
77083
  } else {
76581
77084
  next.pendingTopMargin = nextTop;
76582
77085
  }
76583
- if (typeof footerPx === "number") {
77086
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
76584
77087
  const sectionFooter = next.pendingFooterDistance;
77088
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
76585
77089
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
76586
- next.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
77090
+ next.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
76587
77091
  } else {
76588
77092
  next.pendingBottomMargin = nextBottom;
76589
77093
  }
77094
+ next.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
77095
+ next.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
76590
77096
  if (block.pageSize) next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
76591
77097
  if (block.orientation) next.pendingOrientation = block.orientation;
76592
77098
  const sectionType = block.type ?? "continuous";
@@ -76671,7 +77177,7 @@ function layoutDocument(blocks, measures, options = {}) {
76671
77177
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
76672
77178
  let pendingSectionIndex = null;
76673
77179
  const paginator = createPaginator({
76674
- margins: { left: margins.left, right: margins.right },
77180
+ margins: paginatorMargins,
76675
77181
  getActiveTopMargin: () => activeTopMargin,
76676
77182
  getActiveBottomMargin: () => activeBottomMargin,
76677
77183
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -76686,8 +77192,12 @@ function layoutDocument(blocks, measures, options = {}) {
76686
77192
  const applied = applyPendingToActive({
76687
77193
  activeTopMargin,
76688
77194
  activeBottomMargin,
77195
+ activeLeftMargin,
77196
+ activeRightMargin,
76689
77197
  pendingTopMargin,
76690
77198
  pendingBottomMargin,
77199
+ pendingLeftMargin,
77200
+ pendingRightMargin,
76691
77201
  activeHeaderDistance,
76692
77202
  activeFooterDistance,
76693
77203
  pendingHeaderDistance,
@@ -76702,8 +77212,12 @@ function layoutDocument(blocks, measures, options = {}) {
76702
77212
  });
76703
77213
  activeTopMargin = applied.activeTopMargin;
76704
77214
  activeBottomMargin = applied.activeBottomMargin;
77215
+ activeLeftMargin = applied.activeLeftMargin;
77216
+ activeRightMargin = applied.activeRightMargin;
76705
77217
  pendingTopMargin = applied.pendingTopMargin;
76706
77218
  pendingBottomMargin = applied.pendingBottomMargin;
77219
+ pendingLeftMargin = applied.pendingLeftMargin;
77220
+ pendingRightMargin = applied.pendingRightMargin;
76707
77221
  activeHeaderDistance = applied.activeHeaderDistance;
76708
77222
  activeFooterDistance = applied.activeFooterDistance;
76709
77223
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -76715,6 +77229,14 @@ function layoutDocument(blocks, measures, options = {}) {
76715
77229
  activeOrientation = applied.activeOrientation;
76716
77230
  pendingOrientation = applied.pendingOrientation;
76717
77231
  cachedColumnsState.state = null;
77232
+ paginatorMargins.left = activeLeftMargin;
77233
+ paginatorMargins.right = activeRightMargin;
77234
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77235
+ floatManager.setLayoutContext(
77236
+ normalizeColumns(activeColumns, contentWidth),
77237
+ { left: activeLeftMargin, right: activeRightMargin },
77238
+ activePageSize.w
77239
+ );
76718
77240
  if (pendingNumbering) {
76719
77241
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
76720
77242
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -76759,7 +77281,7 @@ function layoutDocument(blocks, measures, options = {}) {
76759
77281
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
76760
77282
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
76761
77283
  const getCurrentColumns = () => {
76762
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
77284
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
76763
77285
  const state2 = states[states.length - 1] ?? null;
76764
77286
  const colsConfig = state2 ? getActiveColumnsForState(state2) : activeColumns;
76765
77287
  const constraintIndex = state2 ? state2.activeConstraintIndex : -1;
@@ -76792,6 +77314,12 @@ function layoutDocument(blocks, measures, options = {}) {
76792
77314
  layoutLog(` Current page: ${state2.page.number}, cursorY: ${state2.cursorY}`);
76793
77315
  activeColumns = newColumns;
76794
77316
  cachedColumnsState.state = null;
77317
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77318
+ floatManager.setLayoutContext(
77319
+ normalizeColumns(activeColumns, contentWidth),
77320
+ { left: activeLeftMargin, right: activeRightMargin },
77321
+ activePageSize.w
77322
+ );
76795
77323
  };
76796
77324
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
76797
77325
  const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
@@ -76823,10 +77351,10 @@ function layoutDocument(blocks, measures, options = {}) {
76823
77351
  if (alignV === "top") {
76824
77352
  anchorY = offsetV;
76825
77353
  } else if (alignV === "bottom") {
76826
- const pageHeight = contentBottom + margins.bottom;
77354
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
76827
77355
  anchorY = pageHeight - imageHeight + offsetV;
76828
77356
  } else if (alignV === "center") {
76829
- const pageHeight = contentBottom + margins.bottom;
77357
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
76830
77358
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
76831
77359
  } else {
76832
77360
  anchorY = offsetV;
@@ -76837,11 +77365,11 @@ function layoutDocument(blocks, measures, options = {}) {
76837
77365
  const anchorX = entry.block.anchor ? computeAnchorX(
76838
77366
  entry.block.anchor,
76839
77367
  state2.columnIndex,
76840
- normalizeColumns(activeColumns, contentWidth),
77368
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
76841
77369
  entry.measure.width,
76842
- { left: margins.left, right: margins.right },
77370
+ { left: activeLeftMargin, right: activeRightMargin },
76843
77371
  activePageSize.w
76844
- ) : margins.left;
77372
+ ) : activeLeftMargin;
76845
77373
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state2.columnIndex, state2.page.number);
76846
77374
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state2.page.number });
76847
77375
  }
@@ -76879,8 +77407,12 @@ function layoutDocument(blocks, measures, options = {}) {
76879
77407
  const sectionState = {
76880
77408
  activeTopMargin,
76881
77409
  activeBottomMargin,
77410
+ activeLeftMargin,
77411
+ activeRightMargin,
76882
77412
  pendingTopMargin,
76883
77413
  pendingBottomMargin,
77414
+ pendingLeftMargin,
77415
+ pendingRightMargin,
76884
77416
  activeHeaderDistance,
76885
77417
  activeFooterDistance,
76886
77418
  pendingHeaderDistance,
@@ -76914,8 +77446,12 @@ function layoutDocument(blocks, measures, options = {}) {
76914
77446
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
76915
77447
  activeTopMargin = updatedState.activeTopMargin;
76916
77448
  activeBottomMargin = updatedState.activeBottomMargin;
77449
+ activeLeftMargin = updatedState.activeLeftMargin;
77450
+ activeRightMargin = updatedState.activeRightMargin;
76917
77451
  pendingTopMargin = updatedState.pendingTopMargin;
76918
77452
  pendingBottomMargin = updatedState.pendingBottomMargin;
77453
+ pendingLeftMargin = updatedState.pendingLeftMargin;
77454
+ pendingRightMargin = updatedState.pendingRightMargin;
76919
77455
  activeHeaderDistance = updatedState.activeHeaderDistance;
76920
77456
  activeFooterDistance = updatedState.activeFooterDistance;
76921
77457
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -77053,8 +77589,8 @@ function layoutDocument(blocks, measures, options = {}) {
77053
77589
  pageMargins: {
77054
77590
  top: activeTopMargin,
77055
77591
  bottom: activeBottomMargin,
77056
- left: margins.left,
77057
- right: margins.right
77592
+ left: activeLeftMargin,
77593
+ right: activeRightMargin
77058
77594
  },
77059
77595
  columns: getCurrentColumns(),
77060
77596
  placedAnchoredIds
@@ -77076,9 +77612,9 @@ function layoutDocument(blocks, measures, options = {}) {
77076
77612
  const cols = getCurrentColumns();
77077
77613
  let maxWidth;
77078
77614
  if (relativeFrom === "page") {
77079
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
77615
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
77080
77616
  } else if (relativeFrom === "margin") {
77081
- maxWidth = activePageSize.w - margins.left - margins.right;
77617
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
77082
77618
  } else {
77083
77619
  maxWidth = cols.width;
77084
77620
  }
@@ -77236,8 +77772,11 @@ function layoutHeaderFooter(blocks, measures, constraints) {
77236
77772
  throw new Error("layoutHeaderFooter: width must be positive");
77237
77773
  }
77238
77774
  if (!Number.isFinite(height) || height <= 0) {
77239
- throw new Error("layoutHeaderFooter: height must be positive");
77775
+ return { pages: [], height: 0 };
77240
77776
  }
77777
+ const maxBehindDocOverflow = Math.max(192, height * 4);
77778
+ const minBehindDocY = -maxBehindDocOverflow;
77779
+ const maxBehindDocY = height + maxBehindDocOverflow;
77241
77780
  const marginLeft = constraints.margins?.left ?? 0;
77242
77781
  const transformedBlocks = marginLeft > 0 ? blocks.map((block) => {
77243
77782
  const hasPageRelativeAnchor = (block.kind === "image" || block.kind === "drawing") && block.anchor?.hRelativeFrom === "page" && block.anchor.offsetH != null;
@@ -77268,6 +77807,18 @@ function layoutHeaderFooter(blocks, measures, constraints) {
77268
77807
  if (idx == null) continue;
77269
77808
  const block = blocks[idx];
77270
77809
  const measure = measures[idx];
77810
+ const isAnchoredFragment = (fragment.kind === "image" || fragment.kind === "drawing") && fragment.isAnchored === true;
77811
+ if (isAnchoredFragment) {
77812
+ if (block.kind !== "image" && block.kind !== "drawing") {
77813
+ throw new Error(
77814
+ `Type mismatch: fragment kind is ${fragment.kind} but block kind is ${block.kind} for block ${block.id}`
77815
+ );
77816
+ }
77817
+ const anchoredBlock = block;
77818
+ if (anchoredBlock.anchor?.behindDoc && (fragment.y < minBehindDocY || fragment.y > maxBehindDocY)) {
77819
+ continue;
77820
+ }
77821
+ }
77271
77822
  if (fragment.y < minY) minY = fragment.y;
77272
77823
  let bottom2 = fragment.y;
77273
77824
  if (fragment.kind === "para" && measure?.kind === "paragraph") {
@@ -78265,11 +78816,11 @@ function findWordBoundaries(blocks, pos) {
78265
78816
  if (text.length === 0) return null;
78266
78817
  const clampedPos = Math.max(0, Math.min(localPos, text.length));
78267
78818
  let wordStart = clampedPos;
78268
- while (wordStart > 0 && isWordChar(text[wordStart - 1])) {
78819
+ while (wordStart > 0 && isWordChar$2(text[wordStart - 1])) {
78269
78820
  wordStart--;
78270
78821
  }
78271
78822
  let wordEnd = clampedPos;
78272
- while (wordEnd < text.length && isWordChar(text[wordEnd])) {
78823
+ while (wordEnd < text.length && isWordChar$2(text[wordEnd])) {
78273
78824
  wordEnd++;
78274
78825
  }
78275
78826
  if (wordStart === wordEnd) {
@@ -78332,7 +78883,7 @@ function findBlockAtPosition(blocks, pos) {
78332
78883
  }
78333
78884
  return null;
78334
78885
  }
78335
- function isWordChar(char) {
78886
+ function isWordChar$2(char) {
78336
78887
  return /[\p{L}\p{N}_]/u.test(char);
78337
78888
  }
78338
78889
  function isWhitespace(char) {
@@ -78367,6 +78918,29 @@ function fontString(run2) {
78367
78918
  function runText(run2) {
78368
78919
  return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
78369
78920
  }
78921
+ const isWordChar$1 = (char) => {
78922
+ if (!char) return false;
78923
+ const code = char.charCodeAt(0);
78924
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
78925
+ };
78926
+ const capitalizeText$1 = (text, fullText, startOffset) => {
78927
+ if (!text) return text;
78928
+ const hasFullText = typeof startOffset === "number" && fullText != null;
78929
+ let result = "";
78930
+ for (let i = 0; i < text.length; i += 1) {
78931
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
78932
+ const ch = text[i];
78933
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
78934
+ }
78935
+ return result;
78936
+ };
78937
+ const applyTextTransform$1 = (text, transform, fullText, startOffset) => {
78938
+ if (!text || !transform || transform === "none") return text;
78939
+ if (transform === "uppercase") return text.toUpperCase();
78940
+ if (transform === "lowercase") return text.toLowerCase();
78941
+ if (transform === "capitalize") return capitalizeText$1(text, fullText, startOffset);
78942
+ return text;
78943
+ };
78370
78944
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
78371
78945
  const TWIPS_PER_INCH$4 = 1440;
78372
78946
  const PX_PER_INCH$3 = 96;
@@ -78375,6 +78949,13 @@ const TAB_EPSILON$1 = 0.1;
78375
78949
  const WIDTH_FUDGE_PX = 0.5;
78376
78950
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
78377
78951
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
78952
+ const markerFontString = (run2) => {
78953
+ const size2 = run2?.fontSize ?? 16;
78954
+ const family = run2?.fontFamily ?? "Arial";
78955
+ const italic = run2?.italic ? "italic " : "";
78956
+ const bold = run2?.bold ? "bold " : "";
78957
+ return `${italic}${bold}${size2}px ${family}`.trim();
78958
+ };
78378
78959
  const buildTabStopsPx$1 = (indent, tabs, tabIntervalTwips) => {
78379
78960
  const paragraphIndentTwips = {
78380
78961
  left: pxToTwips$1(Math.max(0, indent?.left ?? 0)),
@@ -78405,7 +78986,9 @@ const getNextTabStopPx$1 = (currentX, tabStops, startIndex) => {
78405
78986
  };
78406
78987
  function measureRunSliceWidth(run2, fromChar, toChar) {
78407
78988
  const context = getCtx();
78408
- const text = runText(run2).slice(fromChar, toChar);
78989
+ const fullText = runText(run2);
78990
+ const transform = isTextRun$2(run2) ? run2.textTransform : void 0;
78991
+ const text = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
78409
78992
  if (!context) {
78410
78993
  const textRun = isTextRun$2(run2) ? run2 : null;
78411
78994
  const size2 = textRun?.fontSize ?? 16;
@@ -78451,8 +79034,21 @@ function remeasureParagraph(block, maxWidth, firstLineIndent = 0) {
78451
79034
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
78452
79035
  const markerTextStartX = wordLayout?.marker?.textStartX;
78453
79036
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
78454
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
78455
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
79037
+ const resolvedTextStartPx = resolveListTextStartPx(
79038
+ wordLayout,
79039
+ indentLeft,
79040
+ indentFirstLine,
79041
+ indentHanging,
79042
+ (markerText, marker) => {
79043
+ const context = getCtx();
79044
+ if (!context) return 0;
79045
+ context.font = markerFontString(marker.run);
79046
+ return context.measureText(markerText).width;
79047
+ }
79048
+ );
79049
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
79050
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
79051
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
78456
79052
  const tabStops = buildTabStopsPx$1(indent, attrs?.tabs, attrs?.tabIntervalTwips);
78457
79053
  let currentRun = 0;
78458
79054
  let currentChar = 0;
@@ -78992,7 +79588,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
78992
79588
  if (dirty.deletedBlockIds.length > 0) {
78993
79589
  measureCache.invalidate(dirty.deletedBlockIds);
78994
79590
  }
78995
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
79591
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
78996
79592
  if (measurementWidth <= 0 || measurementHeight <= 0) {
78997
79593
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
78998
79594
  }
@@ -79022,7 +79618,9 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79022
79618
  `[Perf] 4.1 Measure all blocks: ${(measureEnd - measureStart).toFixed(2)}ms (${cacheMisses} measured, ${cacheHits} cached)`
79023
79619
  );
79024
79620
  let headerContentHeights;
79025
- if (headerFooter?.constraints && headerFooter.headerBlocks) {
79621
+ const hasHeaderBlocks = headerFooter?.headerBlocks && Object.keys(headerFooter.headerBlocks).length > 0;
79622
+ const hasHeaderBlocksByRId = headerFooter?.headerBlocksByRId && headerFooter.headerBlocksByRId.size > 0;
79623
+ if (headerFooter?.constraints && (hasHeaderBlocks || hasHeaderBlocksByRId)) {
79026
79624
  const hfPreStart = performance.now();
79027
79625
  const measureFn = headerFooter.measure ?? measureBlock2;
79028
79626
  invalidateHeaderFooterCache(
@@ -79034,25 +79632,45 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79034
79632
  options.sectionMetadata
79035
79633
  );
79036
79634
  const HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
79037
- const preHeaderLayouts = await layoutHeaderFooterWithCache(
79038
- headerFooter.headerBlocks,
79039
- headerFooter.constraints,
79040
- measureFn,
79041
- headerMeasureCache,
79042
- HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79043
- void 0
79044
- // No page resolver needed for height calculation
79045
- );
79046
79635
  const isValidHeaderType = (key2) => {
79047
79636
  return ["default", "first", "even", "odd"].includes(key2);
79048
79637
  };
79049
79638
  headerContentHeights = {};
79050
- for (const [type2, value] of Object.entries(preHeaderLayouts)) {
79051
- if (!isValidHeaderType(type2)) continue;
79052
- if (value?.layout && typeof value.layout.height === "number") {
79053
- const height = value.layout.height;
79054
- if (Number.isFinite(height) && height >= 0) {
79055
- headerContentHeights[type2] = height;
79639
+ if (hasHeaderBlocks && headerFooter.headerBlocks) {
79640
+ const preHeaderLayouts = await layoutHeaderFooterWithCache(
79641
+ headerFooter.headerBlocks,
79642
+ headerFooter.constraints,
79643
+ measureFn,
79644
+ headerMeasureCache,
79645
+ HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79646
+ void 0
79647
+ // No page resolver needed for height calculation
79648
+ );
79649
+ for (const [type2, value] of Object.entries(preHeaderLayouts)) {
79650
+ if (!isValidHeaderType(type2)) continue;
79651
+ if (value?.layout && typeof value.layout.height === "number") {
79652
+ const height = value.layout.height;
79653
+ if (Number.isFinite(height) && height >= 0) {
79654
+ headerContentHeights[type2] = height;
79655
+ }
79656
+ }
79657
+ }
79658
+ }
79659
+ if (hasHeaderBlocksByRId && headerFooter.headerBlocksByRId) {
79660
+ for (const [_rId, blocks] of headerFooter.headerBlocksByRId) {
79661
+ if (!blocks || blocks.length === 0) continue;
79662
+ const measureConstraints = {
79663
+ maxWidth: headerFooter.constraints.width,
79664
+ maxHeight: headerFooter.constraints.height
79665
+ };
79666
+ const measures2 = await Promise.all(blocks.map((block) => measureFn(block, measureConstraints)));
79667
+ const layout2 = layoutHeaderFooter(blocks, measures2, {
79668
+ width: headerFooter.constraints.width,
79669
+ height: headerFooter.constraints.height
79670
+ });
79671
+ if (layout2.height > 0) {
79672
+ const currentDefault = headerContentHeights.default ?? 0;
79673
+ headerContentHeights.default = Math.max(currentDefault, layout2.height);
79056
79674
  }
79057
79675
  }
79058
79676
  }
@@ -79060,10 +79678,12 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79060
79678
  perfLog(`[Perf] 4.1.5 Pre-layout headers for height: ${(hfPreEnd - hfPreStart).toFixed(2)}ms`);
79061
79679
  }
79062
79680
  let footerContentHeights;
79063
- if (headerFooter?.constraints && headerFooter.footerBlocks) {
79681
+ const hasFooterBlocks = headerFooter?.footerBlocks && Object.keys(headerFooter.footerBlocks).length > 0;
79682
+ const hasFooterBlocksByRId = headerFooter?.footerBlocksByRId && headerFooter.footerBlocksByRId.size > 0;
79683
+ if (headerFooter?.constraints && (hasFooterBlocks || hasFooterBlocksByRId)) {
79064
79684
  const footerPreStart = performance.now();
79065
79685
  const measureFn = headerFooter.measure ?? measureBlock2;
79066
- if (!headerFooter.headerBlocks) {
79686
+ if (!hasHeaderBlocks && !hasHeaderBlocksByRId) {
79067
79687
  invalidateHeaderFooterCache(
79068
79688
  headerMeasureCache,
79069
79689
  headerFooterCacheState,
@@ -79074,26 +79694,46 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79074
79694
  );
79075
79695
  }
79076
79696
  const FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
79697
+ const isValidFooterType = (key2) => {
79698
+ return ["default", "first", "even", "odd"].includes(key2);
79699
+ };
79700
+ footerContentHeights = {};
79077
79701
  try {
79078
- const preFooterLayouts = await layoutHeaderFooterWithCache(
79079
- headerFooter.footerBlocks,
79080
- headerFooter.constraints,
79081
- measureFn,
79082
- headerMeasureCache,
79083
- FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79084
- void 0
79085
- // No page resolver needed for height calculation
79086
- );
79087
- const isValidFooterType = (key2) => {
79088
- return ["default", "first", "even", "odd"].includes(key2);
79089
- };
79090
- footerContentHeights = {};
79091
- for (const [type2, value] of Object.entries(preFooterLayouts)) {
79092
- if (!isValidFooterType(type2)) continue;
79093
- if (value?.layout && typeof value.layout.height === "number") {
79094
- const height = value.layout.height;
79095
- if (Number.isFinite(height) && height >= 0) {
79096
- footerContentHeights[type2] = height;
79702
+ if (hasFooterBlocks && headerFooter.footerBlocks) {
79703
+ const preFooterLayouts = await layoutHeaderFooterWithCache(
79704
+ headerFooter.footerBlocks,
79705
+ headerFooter.constraints,
79706
+ measureFn,
79707
+ headerMeasureCache,
79708
+ FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
79709
+ void 0
79710
+ // No page resolver needed for height calculation
79711
+ );
79712
+ for (const [type2, value] of Object.entries(preFooterLayouts)) {
79713
+ if (!isValidFooterType(type2)) continue;
79714
+ if (value?.layout && typeof value.layout.height === "number") {
79715
+ const height = value.layout.height;
79716
+ if (Number.isFinite(height) && height >= 0) {
79717
+ footerContentHeights[type2] = height;
79718
+ }
79719
+ }
79720
+ }
79721
+ }
79722
+ if (hasFooterBlocksByRId && headerFooter.footerBlocksByRId) {
79723
+ for (const [_rId, blocks] of headerFooter.footerBlocksByRId) {
79724
+ if (!blocks || blocks.length === 0) continue;
79725
+ const measureConstraints = {
79726
+ maxWidth: headerFooter.constraints.width,
79727
+ maxHeight: headerFooter.constraints.height
79728
+ };
79729
+ const measures2 = await Promise.all(blocks.map((block) => measureFn(block, measureConstraints)));
79730
+ const layout2 = layoutHeaderFooter(blocks, measures2, {
79731
+ width: headerFooter.constraints.width,
79732
+ height: headerFooter.constraints.height
79733
+ });
79734
+ if (layout2.height > 0) {
79735
+ const currentDefault = footerContentHeights.default ?? 0;
79736
+ footerContentHeights.default = Math.max(currentDefault, layout2.height);
79097
79737
  }
79098
79738
  }
79099
79739
  }
@@ -79261,7 +79901,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
79261
79901
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
79262
79902
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
79263
79903
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
79264
- function resolveMeasurementConstraints(options) {
79904
+ function resolveMeasurementConstraints(options, blocks) {
79265
79905
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
79266
79906
  const margins = {
79267
79907
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -79269,23 +79909,41 @@ function resolveMeasurementConstraints(options) {
79269
79909
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
79270
79910
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
79271
79911
  };
79272
- const contentWidth = pageSize.w - (margins.left + margins.right);
79273
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
79274
- const columns = options.columns;
79275
- if (columns && columns.count > 1) {
79912
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
79913
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
79914
+ const computeColumnWidth = (contentWidth, columns) => {
79915
+ if (!columns || columns.count <= 1) return contentWidth;
79276
79916
  const gap = Math.max(0, columns.gap ?? 0);
79277
79917
  const totalGap = gap * (columns.count - 1);
79278
- const columnWidth = (contentWidth - totalGap) / columns.count;
79279
- if (columnWidth > 0) {
79280
- return {
79281
- measurementWidth: columnWidth,
79282
- measurementHeight: contentHeight
79918
+ return (contentWidth - totalGap) / columns.count;
79919
+ };
79920
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
79921
+ let measurementHeight = baseContentHeight;
79922
+ if (blocks && blocks.length > 0) {
79923
+ for (const block of blocks) {
79924
+ if (block.kind !== "sectionBreak") continue;
79925
+ const sectionPageSize = block.pageSize ?? pageSize;
79926
+ const sectionMargins = {
79927
+ top: normalizeMargin(block.margins?.top, margins.top),
79928
+ right: normalizeMargin(block.margins?.right, margins.right),
79929
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
79930
+ left: normalizeMargin(block.margins?.left, margins.left)
79283
79931
  };
79932
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
79933
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
79934
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
79935
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
79936
+ if (columnWidth > measurementWidth) {
79937
+ measurementWidth = columnWidth;
79938
+ }
79939
+ if (contentHeight > measurementHeight) {
79940
+ measurementHeight = contentHeight;
79941
+ }
79284
79942
  }
79285
79943
  }
79286
79944
  return {
79287
- measurementWidth: contentWidth,
79288
- measurementHeight: contentHeight
79945
+ measurementWidth,
79946
+ measurementHeight
79289
79947
  };
79290
79948
  }
79291
79949
  const serializeHeaderFooterResults = (kind, batch) => {
@@ -81675,14 +82333,15 @@ function getAtomNodeTypes(schema) {
81675
82333
  if (!schema) return [];
81676
82334
  const types2 = [];
81677
82335
  try {
81678
- schema.nodes.forEach((nodeType, name) => {
82336
+ for (const name in schema.nodes) {
81679
82337
  if (name === "text") {
81680
- return;
82338
+ continue;
81681
82339
  }
81682
- if (nodeType.isAtom || nodeType.isLeaf) {
82340
+ const nodeType = schema.nodes[name];
82341
+ if (nodeType && (nodeType.isAtom || nodeType.isLeaf)) {
81683
82342
  types2.push(name);
81684
82343
  }
81685
- });
82344
+ }
81686
82345
  } catch {
81687
82346
  return [];
81688
82347
  }
@@ -83085,6 +83744,7 @@ function shouldRequirePageBoundary(current, next) {
83085
83744
  function hasIntrinsicBoundarySignals(_2) {
83086
83745
  return false;
83087
83746
  }
83747
+ const DEFAULT_HEADER_FOOTER_MARGIN_PX = 0;
83088
83748
  function shouldIgnoreSectionBreak(paragraph, index2, total, hasBodySectPr) {
83089
83749
  const paragraphAttrs = paragraph.attrs ?? {};
83090
83750
  const paragraphProperties = paragraphAttrs?.paragraphProperties;
@@ -83125,14 +83785,15 @@ function buildSectionRangesFromParagraphs(paragraphs, hasBodySectPr) {
83125
83785
  const sectionData = extractSectionData(item.node);
83126
83786
  if (!sectionData) return;
83127
83787
  const sectPr = getSectPrFromNode(item.node);
83788
+ const hasAnyMargin = sectionData.headerPx != null || sectionData.footerPx != null || sectionData.topPx != null || sectionData.rightPx != null || sectionData.bottomPx != null || sectionData.leftPx != null;
83128
83789
  const range2 = {
83129
83790
  sectionIndex: idx,
83130
83791
  startParagraphIndex: currentStart,
83131
83792
  endParagraphIndex: item.index,
83132
83793
  sectPr,
83133
- margins: sectionData.headerPx != null || sectionData.footerPx != null ? {
83134
- header: sectionData.headerPx ?? 0,
83135
- footer: sectionData.footerPx ?? 0,
83794
+ margins: hasAnyMargin ? {
83795
+ header: sectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
83796
+ footer: sectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
83136
83797
  top: sectionData.topPx,
83137
83798
  right: sectionData.rightPx,
83138
83799
  bottom: sectionData.bottomPx,
@@ -83174,14 +83835,15 @@ function createFinalSectionFromBodySectPr(bodySectPr, currentStart, totalParagra
83174
83835
  };
83175
83836
  const bodySectionData = extractSectionData(tempNode);
83176
83837
  if (!bodySectionData) return null;
83838
+ const hasAnyMargin = bodySectionData.headerPx != null || bodySectionData.footerPx != null || bodySectionData.topPx != null || bodySectionData.rightPx != null || bodySectionData.bottomPx != null || bodySectionData.leftPx != null;
83177
83839
  return {
83178
83840
  sectionIndex,
83179
83841
  startParagraphIndex: currentStart,
83180
83842
  endParagraphIndex: totalParagraphs - 1,
83181
83843
  sectPr: bodySectPr,
83182
- margins: bodySectionData.headerPx != null || bodySectionData.footerPx != null ? {
83183
- header: bodySectionData.headerPx ?? 0,
83184
- footer: bodySectionData.footerPx ?? 0,
83844
+ margins: hasAnyMargin ? {
83845
+ header: bodySectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
83846
+ footer: bodySectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
83185
83847
  top: bodySectionData.topPx,
83186
83848
  right: bodySectionData.rightPx,
83187
83849
  bottom: bodySectionData.bottomPx,
@@ -84165,11 +84827,27 @@ const collectTrackedChangeFromMarks = (marks) => {
84165
84827
  }, void 0);
84166
84828
  };
84167
84829
  const normalizeUnderlineStyle = (value) => {
84168
- if (value === "none") {
84169
- return void 0;
84830
+ if (value === void 0 || value === null) {
84831
+ return "single";
84170
84832
  }
84171
- if (value === "double" || value === "dotted" || value === "dashed" || value === "wavy") {
84172
- return value;
84833
+ if (typeof value === "boolean") {
84834
+ return value ? "single" : void 0;
84835
+ }
84836
+ if (typeof value === "number") {
84837
+ return value === 0 ? void 0 : "single";
84838
+ }
84839
+ if (typeof value === "string") {
84840
+ const normalized = value.trim().toLowerCase();
84841
+ if (!normalized) {
84842
+ return "single";
84843
+ }
84844
+ if (normalized === "none" || normalized === "0" || normalized === "false" || normalized === "off") {
84845
+ return void 0;
84846
+ }
84847
+ if (normalized === "double" || normalized === "dotted" || normalized === "dashed" || normalized === "wavy") {
84848
+ return normalized;
84849
+ }
84850
+ return "single";
84173
84851
  }
84174
84852
  return "single";
84175
84853
  };
@@ -84321,13 +84999,16 @@ const applyMarksToRun = (run2, marks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG
84321
84999
  break;
84322
85000
  }
84323
85001
  case "underline": {
84324
- const style2 = normalizeUnderlineStyle(mark.attrs?.underlineType);
85002
+ const underlineValue = mark.attrs?.underlineType ?? mark.attrs?.value ?? mark.attrs?.underline ?? mark.attrs?.style;
85003
+ const style2 = normalizeUnderlineStyle(underlineValue);
84325
85004
  if (style2) {
84326
85005
  const underlineColor = resolveColorFromAttributes(mark.attrs ?? {}, themeColors);
84327
85006
  run2.underline = {
84328
85007
  style: style2,
84329
85008
  color: underlineColor ?? run2.underline?.color
84330
85009
  };
85010
+ } else if (underlineValue !== void 0 && underlineValue !== null) {
85011
+ delete run2.underline;
84331
85012
  }
84332
85013
  break;
84333
85014
  }
@@ -85263,8 +85944,8 @@ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
85263
85944
  }
85264
85945
  return void 0;
85265
85946
  }
85266
- const DEFAULT_LIST_HANGING_PX$1 = 18;
85267
- const LIST_MARKER_GAP$1 = 8;
85947
+ const DEFAULT_LIST_HANGING_PX = 18;
85948
+ const LIST_MARKER_GAP = 8;
85268
85949
  const DEFAULT_BULLET_GLYPH = "•";
85269
85950
  const DEFAULT_DECIMAL_PATTERN = "%1.";
85270
85951
  const ASCII_UPPERCASE_A = 65;
@@ -85675,7 +86356,7 @@ function computeWordParagraphLayout(input) {
85675
86356
  let markerBoxWidthPx;
85676
86357
  let markerX;
85677
86358
  if (hasFirstLineIndent) {
85678
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
86359
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
85679
86360
  markerX = indentLeftPx + (firstLinePx ?? 0);
85680
86361
  layout.textStartPx = markerX + markerBoxWidthPx;
85681
86362
  layout.hangingPx = 0;
@@ -85775,12 +86456,12 @@ const resolveMarkerBoxWidth = (hangingPxRaw, glyphWidthPx) => {
85775
86456
  let markerBox = Math.max(hangingPxRaw || 0, 0);
85776
86457
  if (markerBox <= 0) {
85777
86458
  if (glyphWidthPx != null && glyphWidthPx > 0) {
85778
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
86459
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
85779
86460
  } else {
85780
- markerBox = DEFAULT_LIST_HANGING_PX$1;
86461
+ markerBox = DEFAULT_LIST_HANGING_PX;
85781
86462
  }
85782
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
85783
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
86463
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
86464
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
85784
86465
  }
85785
86466
  return markerBox;
85786
86467
  };
@@ -85800,7 +86481,7 @@ const buildMarkerLayout = ({
85800
86481
  textStartX: textStartPx,
85801
86482
  baselineOffsetPx: markerRun.baselineShift ?? 0,
85802
86483
  // Gutter is the small gap between marker and text, not the full marker box width
85803
- gutterWidthPx: LIST_MARKER_GAP$1,
86484
+ gutterWidthPx: LIST_MARKER_GAP,
85804
86485
  justification: numbering.lvlJc ?? "left",
85805
86486
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
85806
86487
  run: markerRun,
@@ -85890,7 +86571,10 @@ const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
85890
86571
  tabStops: cloneIfObject(resolvedExtended.tabStops),
85891
86572
  keepLines: resolvedExtended.keepLines,
85892
86573
  keepNext: resolvedExtended.keepNext,
85893
- numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties)
86574
+ numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties),
86575
+ // Extract contextualSpacing from style resolution - this is a sibling to spacing in OOXML,
86576
+ // not nested within it. When true, suppresses spacing between paragraphs of the same style.
86577
+ contextualSpacing: resolvedExtended.contextualSpacing
85894
86578
  };
85895
86579
  return hydrated;
85896
86580
  };
@@ -86492,6 +87176,31 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
86492
87176
  return null;
86493
87177
  }
86494
87178
  };
87179
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
87180
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
87181
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
87182
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
87183
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
87184
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
87185
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
87186
+ wordLayout.firstLineIndentMode = false;
87187
+ }
87188
+ if (wordLayout.firstLineIndentMode === true) {
87189
+ if (isFiniteNumber(wordLayout.textStartPx)) {
87190
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
87191
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
87192
+ }
87193
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
87194
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
87195
+ }
87196
+ } else {
87197
+ wordLayout.textStartPx = indentLeft;
87198
+ if (wordLayout.marker) {
87199
+ wordLayout.marker.textStartX = indentLeft;
87200
+ }
87201
+ }
87202
+ return wordLayout;
87203
+ };
86495
87204
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
86496
87205
  const attrs = para.attrs ?? {};
86497
87206
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -86600,7 +87309,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86600
87309
  paragraphAttrs.spacing.afterAutospacing = normalizedSpacing.afterAutospacing;
86601
87310
  }
86602
87311
  }
86603
- const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing");
87312
+ const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing") ?? hydrated?.contextualSpacing;
86604
87313
  if (contextualSpacingValue != null) {
86605
87314
  paragraphAttrs.contextualSpacing = isTruthy(contextualSpacingValue);
86606
87315
  }
@@ -86814,8 +87523,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86814
87523
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
86815
87524
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
86816
87525
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
86817
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
86818
- if (firstLinePx > 0) {
87526
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
87527
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
87528
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
87529
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
87530
+ if (firstLinePx > 0 && !hangingPx) {
86819
87531
  wordLayout = {
86820
87532
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
86821
87533
  firstLineIndentMode: true,
@@ -86823,10 +87535,13 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86823
87535
  };
86824
87536
  }
86825
87537
  }
86826
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
87538
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
86827
87539
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
86828
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
86829
- if (firstLinePx > 0) {
87540
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
87541
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
87542
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
87543
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
87544
+ if (firstLinePx > 0 && !hangingPx) {
86830
87545
  wordLayout = {
86831
87546
  ...wordLayout,
86832
87547
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -86846,6 +87561,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
86846
87561
  wordLayout.marker.suffix = listRendering.suffix;
86847
87562
  }
86848
87563
  }
87564
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
86849
87565
  paragraphAttrs.wordLayout = wordLayout;
86850
87566
  }
86851
87567
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -90962,11 +91678,6 @@ function initHeaderFooterRegistry({
90962
91678
  cleanups
90963
91679
  };
90964
91680
  }
90965
- const LIST_MARKER_GAP = 8;
90966
- const MIN_MARKER_GUTTER = 24;
90967
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
90968
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
90969
- const DEFAULT_LIST_HANGING_PX = 18;
90970
91681
  function calculateRotatedBounds(input) {
90971
91682
  const width = Math.max(0, input.width);
90972
91683
  const height = Math.max(0, input.height);
@@ -91136,7 +91847,7 @@ function measureText(text, font, ctx2, _fontFamily, _letterSpacing) {
91136
91847
  return Math.max(advanceWidth, paintedWidth);
91137
91848
  }
91138
91849
  const MIN_SINGLE_LINE_PX = 12 * 96 / 72;
91139
- const LINE_HEIGHT_SAFETY_MARGIN_PX = 1;
91850
+ const WORD_SINGLE_LINE_SPACING_MULTIPLIER = 1.15;
91140
91851
  function calculateTypographyMetrics(fontSize2, spacing, fontInfo) {
91141
91852
  let ascent;
91142
91853
  let descent;
@@ -91149,7 +91860,7 @@ function calculateTypographyMetrics(fontSize2, spacing, fontInfo) {
91149
91860
  ascent = roundValue(fontSize2 * 0.8);
91150
91861
  descent = roundValue(fontSize2 * 0.2);
91151
91862
  }
91152
- const baseLineHeight = Math.max(ascent + descent + LINE_HEIGHT_SAFETY_MARGIN_PX, MIN_SINGLE_LINE_PX);
91863
+ const baseLineHeight = Math.max(fontSize2 * WORD_SINGLE_LINE_SPACING_MULTIPLIER, ascent + descent, MIN_SINGLE_LINE_PX);
91153
91864
  const lineHeight2 = roundValue(resolveLineHeight(spacing, baseLineHeight));
91154
91865
  return {
91155
91866
  ascent,
@@ -91230,8 +91941,25 @@ async function measureParagraphBlock(block, maxWidth) {
91230
91941
  const rawTextStartPx = wordLayout?.textStartPx;
91231
91942
  const markerTextStartX = wordLayout?.marker?.textStartX;
91232
91943
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
91233
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
91234
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
91944
+ const resolvedTextStartPx = resolveListTextStartPx(
91945
+ wordLayout,
91946
+ indentLeft,
91947
+ firstLine,
91948
+ hanging,
91949
+ (markerText, marker) => {
91950
+ const markerRun = {
91951
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
91952
+ fontSize: marker.run?.fontSize ?? 16,
91953
+ bold: marker.run?.bold ?? false,
91954
+ italic: marker.run?.italic ?? false
91955
+ };
91956
+ const { font: markerFont } = buildFontString(markerRun);
91957
+ return measureText(markerText, markerFont, ctx2);
91958
+ }
91959
+ );
91960
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
91961
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
91962
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
91235
91963
  } else {
91236
91964
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
91237
91965
  }
@@ -91318,7 +92046,7 @@ async function measureParagraphBlock(block, maxWidth) {
91318
92046
  pendingTabAlignment = null;
91319
92047
  return startX;
91320
92048
  };
91321
- const alignSegmentAtTab = (segmentText, font, runContext) => {
92049
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
91322
92050
  if (!pendingTabAlignment || !currentLine) return void 0;
91323
92051
  const { val } = pendingTabAlignment;
91324
92052
  let segmentWidth = 0;
@@ -91327,11 +92055,11 @@ async function measureParagraphBlock(block, maxWidth) {
91327
92055
  const idx = segmentText.indexOf(decimalSeparator);
91328
92056
  if (idx >= 0) {
91329
92057
  const beforeText = segmentText.slice(0, idx);
91330
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
92058
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
91331
92059
  }
91332
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
92060
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
91333
92061
  } else if (val === "end" || val === "center") {
91334
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
92062
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
91335
92063
  }
91336
92064
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
91337
92065
  };
@@ -91383,8 +92111,8 @@ async function measureParagraphBlock(block, maxWidth) {
91383
92111
  const { font } = buildFontString(
91384
92112
  lastRun
91385
92113
  );
91386
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
91387
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
92114
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
92115
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
91388
92116
  const delta = Math.max(0, fullWidth - keptWidth);
91389
92117
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
91390
92118
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -91595,7 +92323,8 @@ async function measureParagraphBlock(block, maxWidth) {
91595
92323
  continue;
91596
92324
  }
91597
92325
  if (isFieldAnnotationRun(run2)) {
91598
- const displayText = run2.displayLabel || "";
92326
+ const rawDisplayText = run2.displayLabel || "";
92327
+ const displayText = applyTextTransform(rawDisplayText, run2);
91599
92328
  const annotationFontSize = typeof run2.fontSize === "number" ? run2.fontSize : typeof run2.fontSize === "string" ? parseFloat(run2.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
91600
92329
  const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
91601
92330
  const fontWeight = run2.bold ? "bold" : "normal";
@@ -91698,7 +92427,7 @@ async function measureParagraphBlock(block, maxWidth) {
91698
92427
  const spacesLength = segment.length;
91699
92428
  const spacesStartChar = charPosInRun;
91700
92429
  const spacesEndChar = charPosInRun + spacesLength;
91701
- const spacesWidth = measureRunWidth(segment, font, ctx2, run2);
92430
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run2, spacesStartChar);
91702
92431
  if (!currentLine) {
91703
92432
  currentLine = {
91704
92433
  fromRun: runIndex,
@@ -91762,7 +92491,7 @@ async function measureParagraphBlock(block, maxWidth) {
91762
92491
  }
91763
92492
  let segmentStartX;
91764
92493
  if (currentLine && pendingTabAlignment) {
91765
- segmentStartX = alignSegmentAtTab(segment, font, run2);
92494
+ segmentStartX = alignSegmentAtTab(segment, font, run2, charPosInRun);
91766
92495
  if (segmentStartX == null) {
91767
92496
  segmentStartX = currentLine.width;
91768
92497
  }
@@ -91772,7 +92501,7 @@ async function measureParagraphBlock(block, maxWidth) {
91772
92501
  if (word2 === "") {
91773
92502
  const spaceStartChar = charPosInRun;
91774
92503
  const spaceEndChar = charPosInRun + 1;
91775
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
92504
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2, spaceStartChar);
91776
92505
  if (!currentLine) {
91777
92506
  currentLine = {
91778
92507
  fromRun: runIndex,
@@ -91823,12 +92552,12 @@ async function measureParagraphBlock(block, maxWidth) {
91823
92552
  charPosInRun = spaceEndChar;
91824
92553
  continue;
91825
92554
  }
91826
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2);
91827
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
91828
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2) : 0;
91829
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
91830
92555
  const wordStartChar = charPosInRun;
92556
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2, wordStartChar);
92557
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
91831
92558
  const wordEndNoSpace = charPosInRun + word2.length;
92559
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) : 0;
92560
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
91832
92561
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
91833
92562
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
91834
92563
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -91847,7 +92576,7 @@ async function measureParagraphBlock(block, maxWidth) {
91847
92576
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
91848
92577
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
91849
92578
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
91850
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
92579
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2, wordStartChar);
91851
92580
  let chunkCharOffset = wordStartChar;
91852
92581
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
91853
92582
  const chunk = chunks[chunkIndex];
@@ -91949,6 +92678,10 @@ async function measureParagraphBlock(block, maxWidth) {
91949
92678
  currentLine.width = roundValue(currentLine.width + spaceWidth + ls);
91950
92679
  charPosInRun = wordEndWithSpace;
91951
92680
  currentLine.spaceCount += 1;
92681
+ if (currentLine.segments?.[0]) {
92682
+ currentLine.segments[0].toChar = wordEndWithSpace;
92683
+ currentLine.segments[0].width += spaceWidth;
92684
+ }
91952
92685
  } else {
91953
92686
  charPosInRun = wordEndWithSpace;
91954
92687
  }
@@ -91971,7 +92704,7 @@ async function measureParagraphBlock(block, maxWidth) {
91971
92704
  if (candidateSpaces > 0) {
91972
92705
  const overflow = totalWidthWithWord - availableWidth;
91973
92706
  if (overflow > 0) {
91974
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
92707
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) || Math.max(1, boundarySpacing);
91975
92708
  const perSpaceCompression = overflow / candidateSpaces;
91976
92709
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
91977
92710
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -92011,6 +92744,10 @@ async function measureParagraphBlock(block, maxWidth) {
92011
92744
  currentLine.width = roundValue(currentLine.width + spaceWidth + (run2.letterSpacing ?? 0));
92012
92745
  charPosInRun = wordEndWithSpace;
92013
92746
  currentLine.spaceCount += 1;
92747
+ if (currentLine.segments?.[0]) {
92748
+ currentLine.segments[0].toChar = wordEndWithSpace;
92749
+ currentLine.segments[0].width += spaceWidth;
92750
+ }
92014
92751
  } else {
92015
92752
  charPosInRun = wordEndWithSpace;
92016
92753
  }
@@ -92146,8 +92883,8 @@ async function measureParagraphBlock(block, maxWidth) {
92146
92883
  const { font: markerFont } = buildFontString(markerRun);
92147
92884
  const markerText = wordLayout.marker.markerText ?? "";
92148
92885
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
92149
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
92150
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
92886
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
92887
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
92151
92888
  markerInfo = {
92152
92889
  markerWidth: markerBoxWidth,
92153
92890
  markerTextWidth: glyphWidth,
@@ -92491,7 +93228,7 @@ async function measureListBlock(block, constraints) {
92491
93228
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
92492
93229
  indentLeft = resolveIndentLeft(item);
92493
93230
  const indentHanging = resolveIndentHanging(item);
92494
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
93231
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
92495
93232
  }
92496
93233
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
92497
93234
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -92517,16 +93254,46 @@ const getPrimaryRun = (paragraph) => {
92517
93254
  fontSize: 16
92518
93255
  };
92519
93256
  };
92520
- const measureRunWidth = (text, font, ctx2, run2) => {
93257
+ const isWordChar = (char) => {
93258
+ if (!char) return false;
93259
+ const code = char.charCodeAt(0);
93260
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
93261
+ };
93262
+ const capitalizeText = (text, fullText, startOffset) => {
93263
+ if (!text) return text;
93264
+ const hasFullText = typeof startOffset === "number" && fullText != null;
93265
+ let result = "";
93266
+ for (let i = 0; i < text.length; i += 1) {
93267
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
93268
+ const ch = text[i];
93269
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
93270
+ }
93271
+ return result;
93272
+ };
93273
+ const applyTextTransform = (text, run2, startOffset) => {
93274
+ const transform = "textTransform" in run2 ? run2.textTransform : void 0;
93275
+ if (!text || !transform || transform === "none") return text;
93276
+ if (transform === "uppercase") return text.toUpperCase();
93277
+ if (transform === "lowercase") return text.toLowerCase();
93278
+ if (transform === "capitalize") {
93279
+ const fullText = "text" in run2 && typeof run2.text === "string" ? run2.text : text;
93280
+ return capitalizeText(text, fullText, startOffset);
93281
+ }
93282
+ return text;
93283
+ };
93284
+ const measureRunWidth = (text, font, ctx2, run2, startOffset) => {
92521
93285
  const letterSpacing = run2.kind === "text" || run2.kind === void 0 ? run2.letterSpacing || 0 : 0;
92522
- const width = getMeasuredTextWidth(text, font, letterSpacing, ctx2);
93286
+ const displayText = applyTextTransform(text, run2, startOffset);
93287
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
92523
93288
  return roundValue(width);
92524
93289
  };
92525
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
93290
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2, startOffset) => {
92526
93291
  const chunks = [];
93292
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
92527
93293
  if (maxWidth <= 0) {
92528
- for (const char of word2) {
92529
- const charWidth = measureRunWidth(char, font, ctx2, run2);
93294
+ for (let i = 0; i < word2.length; i++) {
93295
+ const char = word2[i];
93296
+ const charWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i);
92530
93297
  chunks.push({ text: char, width: charWidth });
92531
93298
  }
92532
93299
  return chunks;
@@ -92536,11 +93303,11 @@ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
92536
93303
  for (let i = 0; i < word2.length; i++) {
92537
93304
  const char = word2[i];
92538
93305
  const testChunk = currentChunk + char;
92539
- const testWidth = measureRunWidth(testChunk, font, ctx2, run2);
93306
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run2, baseOffset);
92540
93307
  if (testWidth > maxWidth && currentChunk.length > 0) {
92541
93308
  chunks.push({ text: currentChunk, width: currentWidth });
92542
93309
  currentChunk = char;
92543
- currentWidth = measureRunWidth(char, font, ctx2, run2);
93310
+ currentWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i);
92544
93311
  } else {
92545
93312
  currentChunk = testChunk;
92546
93313
  currentWidth = testWidth;
@@ -92594,12 +93361,13 @@ const measureDropCap = (ctx2, descriptor, spacing) => {
92594
93361
  italic: run2.italic
92595
93362
  });
92596
93363
  ctx2.font = font;
92597
- const metrics = ctx2.measureText(run2.text);
93364
+ const displayText = applyTextTransform(run2.text, run2);
93365
+ const metrics = ctx2.measureText(displayText);
92598
93366
  const advanceWidth = metrics.width;
92599
93367
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
92600
93368
  const textWidth = Math.max(advanceWidth, paintedWidth);
92601
93369
  const width = roundValue(textWidth + DROP_CAP_PADDING_PX);
92602
- const baseLineHeight = resolveLineHeight(spacing, run2.fontSize * 1.2);
93370
+ const baseLineHeight = resolveLineHeight(spacing, run2.fontSize * WORD_SINGLE_LINE_SPACING_MULTIPLIER);
92603
93371
  const height = roundValue(baseLineHeight * lines);
92604
93372
  return {
92605
93373
  width,
@@ -92620,7 +93388,7 @@ const resolveIndentHanging = (item) => {
92620
93388
  if (indentHanging > 0) {
92621
93389
  return indentHanging;
92622
93390
  }
92623
- return DEFAULT_LIST_HANGING_PX;
93391
+ return DEFAULT_LIST_HANGING_PX$1;
92624
93392
  };
92625
93393
  const buildTabStopsPx = (indent, tabs, tabIntervalTwips) => {
92626
93394
  const paragraphIndentTwips = {
@@ -92826,6 +93594,9 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
92826
93594
  if (event.button !== 0) {
92827
93595
  return;
92828
93596
  }
93597
+ if (event.ctrlKey && navigator.platform.includes("Mac")) {
93598
+ return;
93599
+ }
92829
93600
  __privateSet(this, _pendingMarginClick, null);
92830
93601
  const target = event.target;
92831
93602
  if (target?.closest?.(".superdoc-ruler-handle") != null) {
@@ -93322,6 +94093,10 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
93322
94093
  __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
93323
94094
  return;
93324
94095
  }
94096
+ if (__privateGet$1(this, _documentMode) === "viewing") {
94097
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
94098
+ return;
94099
+ }
93325
94100
  const region = __privateMethod$1(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, normalized.x, normalized.y);
93326
94101
  if (!region) {
93327
94102
  __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
@@ -93550,6 +94325,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
93550
94325
  __privateSet(this, _visibleHost, options.element);
93551
94326
  __privateGet$1(this, _visibleHost).innerHTML = "";
93552
94327
  __privateGet$1(this, _visibleHost).classList.add("presentation-editor");
94328
+ __privateMethod$1(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
93553
94329
  if (!__privateGet$1(this, _visibleHost).hasAttribute("tabindex")) {
93554
94330
  __privateGet$1(this, _visibleHost).tabIndex = 0;
93555
94331
  }
@@ -94045,6 +94821,7 @@ const _PresentationEditor = class _PresentationEditor2 extends EventEmitter$1 {
94045
94821
  }
94046
94822
  __privateSet(this, _documentMode, mode);
94047
94823
  __privateGet$1(this, _editor3).setDocumentMode(mode);
94824
+ __privateMethod$1(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
94048
94825
  __privateMethod$1(this, _PresentationEditor_instances, syncHiddenEditorA11yAttributes_fn).call(this);
94049
94826
  const trackedChangesChanged = __privateMethod$1(this, _PresentationEditor_instances, syncTrackedChangesPreferences_fn).call(this);
94050
94827
  if (trackedChangesChanged) {
@@ -94955,6 +95732,10 @@ wrapHiddenEditorFocus_fn = function() {
94955
95732
  }
94956
95733
  };
94957
95734
  };
95735
+ syncDocumentModeClass_fn = function() {
95736
+ if (!__privateGet$1(this, _visibleHost)) return;
95737
+ __privateGet$1(this, _visibleHost).classList.toggle("presentation-editor--viewing", __privateGet$1(this, _documentMode) === "viewing");
95738
+ };
94958
95739
  collectCommentPositions_fn = function() {
94959
95740
  return collectCommentPositions(__privateGet$1(this, _editor3)?.state?.doc ?? null, {
94960
95741
  commentMarkName: CommentMarkName,
@@ -95588,7 +96369,7 @@ rerender_fn = async function() {
95588
96369
  const atomNodeTypes = getAtomNodeTypes(__privateGet$1(this, _editor3)?.schema ?? null);
95589
96370
  const positionMap = __privateGet$1(this, _editor3)?.state?.doc && docJson ? buildPositionMapFromPmDoc(__privateGet$1(this, _editor3).state.doc, docJson) : null;
95590
96371
  const result = toFlowBlocks(docJson, {
95591
- mediaFiles: __privateGet$1(this, _options).mediaFiles,
96372
+ mediaFiles: __privateGet$1(this, _editor3)?.storage?.image?.media,
95592
96373
  emitSectionBreaks: true,
95593
96374
  sectionMetadata,
95594
96375
  trackedChangesMode: __privateGet$1(this, _trackedChangesMode),
@@ -95912,7 +96693,14 @@ computeHeaderFooterConstraints_fn = function() {
95912
96693
  const footerMargin = margins.footer ?? 0;
95913
96694
  const headerContentSpace = Math.max(marginTop - headerMargin, 0);
95914
96695
  const footerContentSpace = Math.max(marginBottom - footerMargin, 0);
95915
- const height = Math.max(headerContentSpace, footerContentSpace, 1);
96696
+ const height = Math.max(
96697
+ headerContentSpace,
96698
+ footerContentSpace,
96699
+ headerMargin,
96700
+ footerMargin,
96701
+ marginTop,
96702
+ marginBottom
96703
+ );
95916
96704
  return {
95917
96705
  width: measurementWidth,
95918
96706
  height,
@@ -96062,7 +96850,8 @@ computeDecorationBox_fn = function(kind, pageMargins, pageHeight) {
96062
96850
  const headerMargin = margins.header ?? 0;
96063
96851
  const topMargin = margins.top ?? DEFAULT_MARGINS.top ?? 0;
96064
96852
  const height = Math.max(topMargin - headerMargin, 1);
96065
- return { x: left2, width, height, offset: headerMargin };
96853
+ const offset2 = headerMargin;
96854
+ return { x: left2, width, height, offset: offset2 };
96066
96855
  } else {
96067
96856
  const footerMargin = margins.footer ?? 0;
96068
96857
  const bottomMargin = margins.bottom ?? DEFAULT_MARGINS.bottom ?? 0;
@@ -96655,6 +97444,10 @@ renderCellSelectionOverlay_fn = function(selection, layout) {
96655
97444
  });
96656
97445
  };
96657
97446
  renderHoverRegion_fn = function(region) {
97447
+ if (__privateGet$1(this, _documentMode) === "viewing") {
97448
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
97449
+ return;
97450
+ }
96658
97451
  if (!__privateGet$1(this, _hoverOverlay) || !__privateGet$1(this, _hoverTooltip)) return;
96659
97452
  const coords = __privateMethod$1(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, region.pageIndex, region.localX, region.localY);
96660
97453
  if (!coords) {
@@ -98235,6 +99028,8 @@ const SlashMenu = Extension.create({
98235
99028
  const cbRect = containingBlock.getBoundingClientRect();
98236
99029
  left2 -= cbRect.left;
98237
99030
  top2 -= cbRect.top;
99031
+ left2 += containingBlock.scrollLeft || 0;
99032
+ top2 += containingBlock.scrollTop || 0;
98238
99033
  } catch (error) {
98239
99034
  console.warn("SlashMenu: Failed to adjust for containing block", error);
98240
99035
  }
@@ -114142,7 +114937,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
114142
114937
  document.addEventListener("mousedown", globalMousedownHandler);
114143
114938
  scrollHandler = () => {
114144
114939
  if (currentWrapper && resizeContainer) {
114145
- updateHandlePositions(currentWrapper.firstElementChild);
114940
+ updateHandlePositions(currentWrapper);
114146
114941
  }
114147
114942
  };
114148
114943
  window.addEventListener("scroll", scrollHandler, true);
@@ -114204,7 +114999,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
114204
114999
  }
114205
115000
  applyStyleIsolationClass(resizeContainer);
114206
115001
  document.body.appendChild(resizeContainer);
114207
- updateHandlePositions(wrapper.firstElementChild);
115002
+ updateHandlePositions(wrapper);
114208
115003
  }
114209
115004
  function hideResizeHandles() {
114210
115005
  if (resizeContainer?.parentNode) {
@@ -129573,7 +130368,7 @@ const _sfc_main$8 = {
129573
130368
  if (open) {
129574
130369
  nextTick(() => {
129575
130370
  if (searchInput.value) {
129576
- searchInput.value.focus();
130371
+ searchInput.value.focus({ preventScroll: true });
129577
130372
  }
129578
130373
  });
129579
130374
  }
@@ -129678,7 +130473,11 @@ const _sfc_main$8 = {
129678
130473
  };
129679
130474
  const handleGlobalOutsideClick = (event) => {
129680
130475
  if (isOpen.value && menuRef.value && !menuRef.value.contains(event.target)) {
129681
- moveCursorToMouseEvent(event, props.editor);
130476
+ const isCtrlClickOnMac = event.ctrlKey && isMacOS();
130477
+ const isLeftClick = event.button === 0 && !isCtrlClickOnMac;
130478
+ if (isLeftClick) {
130479
+ moveCursorToMouseEvent(event, props.editor);
130480
+ }
129682
130481
  closeMenu({ restoreCursor: false });
129683
130482
  }
129684
130483
  };
@@ -131800,6 +132599,12 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
131800
132599
  if (props.options?.suppressSkeletonLoader || !props.options?.collaborationProvider) editorReady.value = true;
131801
132600
  });
131802
132601
  const handleMarginClick = (event) => {
132602
+ if (event.button !== 0) {
132603
+ return;
132604
+ }
132605
+ if (event.ctrlKey && isMacOS()) {
132606
+ return;
132607
+ }
131803
132608
  if (event.target.classList.contains("ProseMirror")) return;
131804
132609
  onMarginClickCursorChange(event, activeEditor.value);
131805
132610
  };
@@ -131938,7 +132743,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
131938
132743
  };
131939
132744
  }
131940
132745
  });
131941
- const SuperEditor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-209a1e8b"]]);
132746
+ const SuperEditor = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-c9a3c876"]]);
131942
132747
  const _hoisted_1 = ["innerHTML"];
131943
132748
  const _sfc_main = {
131944
132749
  __name: "SuperInput",