@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
@@ -38547,8 +38547,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
38547
38547
  );
38548
38548
  const isInternal = parentComment?.isInternal || originalComment.isInternal;
38549
38549
  if (commentsExportType === "external" && isInternal) return;
38550
- const isResolved = !!originalComment.resolvedTime;
38551
- if (isResolved) return;
38552
38550
  if (node2.type !== "commentRangeStart" && node2.type !== "commentRangeEnd") {
38553
38551
  return;
38554
38552
  }
@@ -39217,11 +39215,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
39217
39215
  }
39218
39216
  if (elements.length === 1) {
39219
39217
  text2 = elements[0].text;
39220
- const xmlSpace = encodedAttrs.xmlSpace ?? elements[0]?.attributes?.["xml:space"];
39218
+ const docXmlSpace = params2.converter?.documentAttributes?.["xml:space"];
39219
+ const xmlSpace = encodedAttrs.xmlSpace ?? attributes?.["xml:space"] ?? elements[0]?.attributes?.["xml:space"] ?? docXmlSpace;
39221
39220
  if (xmlSpace !== "preserve" && typeof text2 === "string") {
39222
39221
  text2 = text2.replace(/^[ \t\n\r]+/, "").replace(/[ \t\n\r]+$/, "");
39223
39222
  }
39224
39223
  text2 = text2.replace(/\[\[sdspace\]\]/g, "");
39224
+ if (xmlSpace !== "preserve" && typeof text2 === "string" && !text2.trim()) {
39225
+ return null;
39226
+ }
39225
39227
  } else if (!elements.length && encodedAttrs.xmlSpace === "preserve") {
39226
39228
  text2 = " ";
39227
39229
  } else return null;
@@ -42204,8 +42206,46 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42204
42206
  this.declaration = this.initialJSON?.declaration;
42205
42207
  this.resolveDocumentGuid();
42206
42208
  }
42209
+ /**
42210
+ * Parses XML content into JSON format while preserving whitespace-only text runs.
42211
+ *
42212
+ * This method wraps xml-js's xml2json parser with additional preprocessing to prevent
42213
+ * the parser from dropping whitespace-only content in <w:t> and <w:delText> elements.
42214
+ * This is critical for correctly handling documents that rely on document-level
42215
+ * xml:space="preserve" rather than per-element attributes, which is common in
42216
+ * PDF-to-DOCX converted documents.
42217
+ *
42218
+ * The whitespace preservation strategy:
42219
+ * 1. Before parsing, wraps whitespace-only content with [[sdspace]] placeholders
42220
+ * 2. xml-js parser preserves the placeholder-wrapped text
42221
+ * 3. During text node processing (t-translator.js), placeholders are removed
42222
+ *
42223
+ * @param {string} xml - The XML string to parse
42224
+ * @returns {Object} The parsed JSON representation of the XML document
42225
+ *
42226
+ * @example
42227
+ * // Handles whitespace-only text runs
42228
+ * const xml = '<w:t> </w:t>';
42229
+ * const result = parseXmlToJson(xml);
42230
+ * // Result preserves the space: { elements: [{ text: '[[sdspace]] [[sdspace]]' }] }
42231
+ *
42232
+ * @example
42233
+ * // Handles elements with attributes
42234
+ * const xml = '<w:t xml:space="preserve"> text </w:t>';
42235
+ * const result = parseXmlToJson(xml);
42236
+ * // Preserves content and attributes
42237
+ *
42238
+ * @example
42239
+ * // Handles both w:t and w:delText elements
42240
+ * const xml = '<w:delText> </w:delText>';
42241
+ * const result = parseXmlToJson(xml);
42242
+ * // Preserves whitespace in deleted text
42243
+ */
42207
42244
  parseXmlToJson(xml2) {
42208
- const newXml = xml2.replace(/(<w:t xml:space="preserve">)(\s+)(<\/w:t>)/g, "$1[[sdspace]]$2[[sdspace]]$3");
42245
+ const newXml = xml2.replace(
42246
+ /(<w:(?:t|delText)(?:\s[^>]*)?>)(\s+)(<\/w:(?:t|delText)>)/g,
42247
+ "$1[[sdspace]]$2[[sdspace]]$3"
42248
+ );
42209
42249
  return JSON.parse(xmljs.xml2json(newXml, null, 2));
42210
42250
  }
42211
42251
  /**
@@ -42428,7 +42468,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
42428
42468
  static getStoredSuperdocVersion(docx) {
42429
42469
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
42430
42470
  }
42431
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.2") {
42471
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "2.0.0-next.21") {
42432
42472
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
42433
42473
  }
42434
42474
  /**
@@ -53615,7 +53655,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
53615
53655
  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);
53616
53656
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
53617
53657
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
53618
- 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;
53658
+ 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;
53619
53659
  var GOOD_LEAF_SIZE = 200;
53620
53660
  var RopeSequence = function RopeSequence2() {
53621
53661
  };
@@ -65451,6 +65491,9 @@ ${err.toString()}`);
65451
65491
  return null;
65452
65492
  }
65453
65493
  const actualMark = start2.node.marks.find((mark2) => mark2.type.name === markName);
65494
+ if (!actualMark) {
65495
+ return null;
65496
+ }
65454
65497
  let startIndex = $pos.index();
65455
65498
  let startPos = $pos.start() + start2.offset;
65456
65499
  while (startIndex > 0 && actualMark.isInSet(parent.child(startIndex - 1).marks)) {
@@ -65740,6 +65783,70 @@ ${err.toString()}`);
65740
65783
  });
65741
65784
  return positions;
65742
65785
  };
65786
+ const getCommentMarkSegmentsById = (commentId, doc2) => {
65787
+ const segments = [];
65788
+ doc2.descendants((node2, pos) => {
65789
+ if (!node2.isInline) return;
65790
+ const commentMark = node2.marks?.find(
65791
+ (mark2) => mark2.type.name === CommentMarkName$1 && mark2.attrs?.commentId === commentId
65792
+ );
65793
+ if (!commentMark) return;
65794
+ segments.push({
65795
+ from: pos,
65796
+ to: pos + node2.nodeSize,
65797
+ attrs: commentMark.attrs || {}
65798
+ });
65799
+ });
65800
+ return segments;
65801
+ };
65802
+ const getCommentMarkRangesById = (commentId, doc2) => {
65803
+ const segments = getCommentMarkSegmentsById(commentId, doc2);
65804
+ if (!segments.length) return { segments, ranges: [] };
65805
+ const ranges = [];
65806
+ let active = null;
65807
+ segments.forEach((seg) => {
65808
+ if (!active) {
65809
+ active = {
65810
+ from: seg.from,
65811
+ to: seg.to,
65812
+ internal: !!seg.attrs?.internal
65813
+ };
65814
+ return;
65815
+ }
65816
+ if (seg.from <= active.to) {
65817
+ active.to = Math.max(active.to, seg.to);
65818
+ return;
65819
+ }
65820
+ ranges.push(active);
65821
+ active = {
65822
+ from: seg.from,
65823
+ to: seg.to,
65824
+ internal: !!seg.attrs?.internal
65825
+ };
65826
+ });
65827
+ if (active) ranges.push(active);
65828
+ return { segments, ranges };
65829
+ };
65830
+ const resolveCommentById = ({ commentId, state: state2, tr, dispatch }) => {
65831
+ const { schema } = state2;
65832
+ const markType = schema.marks?.[CommentMarkName$1];
65833
+ if (!markType) return false;
65834
+ const { segments, ranges } = getCommentMarkRangesById(commentId, state2.doc);
65835
+ if (!segments.length) return false;
65836
+ segments.forEach(({ from: from2, to, attrs }) => {
65837
+ tr.removeMark(from2, to, markType.create(attrs));
65838
+ });
65839
+ const startType = schema.nodes?.commentRangeStart;
65840
+ const endType = schema.nodes?.commentRangeEnd;
65841
+ if (startType && endType) {
65842
+ ranges.slice().sort((a2, b2) => b2.from - a2.from).forEach(({ from: from2, to, internal }) => {
65843
+ tr.insert(to, endType.create({ "w:id": commentId }));
65844
+ tr.insert(from2, startType.create({ "w:id": commentId, internal }));
65845
+ });
65846
+ }
65847
+ dispatch(tr);
65848
+ return true;
65849
+ };
65743
65850
  const prepareCommentsForExport = (doc2, tr, schema, comments = []) => {
65744
65851
  const commentMap = /* @__PURE__ */ new Map();
65745
65852
  comments.forEach((c2) => {
@@ -65846,6 +65953,7 @@ ${err.toString()}`);
65846
65953
  const prepareCommentsForImport = (doc2, tr, schema, converter) => {
65847
65954
  const toMark = [];
65848
65955
  const toDelete = [];
65956
+ const toUpdate = [];
65849
65957
  doc2.descendants((node2, pos) => {
65850
65958
  const { type: type2 } = node2;
65851
65959
  const commentNodes = ["commentRangeStart", "commentRangeEnd", "commentReference"];
@@ -65854,8 +65962,9 @@ ${err.toString()}`);
65854
65962
  converter,
65855
65963
  importedId: node2.attrs["w:id"]
65856
65964
  });
65965
+ const isDone = !!matchingImportedComment?.isDone;
65857
65966
  if (type2.name === "commentRangeStart") {
65858
- if (!matchingImportedComment?.isDone) {
65967
+ if (!isDone) {
65859
65968
  toMark.push({
65860
65969
  commentId: resolvedCommentId,
65861
65970
  importedId,
@@ -65869,8 +65978,29 @@ ${err.toString()}`);
65869
65978
  commentId: resolvedCommentId,
65870
65979
  importedId
65871
65980
  });
65872
- toDelete.push({ start: pos, end: pos + 1 });
65981
+ if (isDone) {
65982
+ toUpdate.push({
65983
+ pos,
65984
+ attrs: {
65985
+ ...node2.attrs,
65986
+ "w:id": resolvedCommentId,
65987
+ internal
65988
+ }
65989
+ });
65990
+ } else {
65991
+ toDelete.push({ start: pos, end: pos + 1 });
65992
+ }
65873
65993
  } else if (type2.name === "commentRangeEnd") {
65994
+ if (isDone) {
65995
+ toUpdate.push({
65996
+ pos,
65997
+ attrs: {
65998
+ ...node2.attrs,
65999
+ "w:id": resolvedCommentId
66000
+ }
66001
+ });
66002
+ return;
66003
+ }
65874
66004
  const itemToMark = toMark.find((p2) => p2.importedId === importedId);
65875
66005
  if (!itemToMark) return;
65876
66006
  const { start: start2 } = itemToMark;
@@ -65885,6 +66015,11 @@ ${err.toString()}`);
65885
66015
  toDelete.push({ start: pos, end: pos + 1 });
65886
66016
  }
65887
66017
  });
66018
+ if (typeof tr.setNodeMarkup === "function") {
66019
+ toUpdate.sort((a2, b2) => b2.pos - a2.pos).forEach(({ pos, attrs }) => {
66020
+ tr.setNodeMarkup(pos, void 0, attrs);
66021
+ });
66022
+ }
65888
66023
  toDelete.sort((a2, b2) => b2.start - a2.start).forEach(({ start: start2, end: end2 }) => {
65889
66024
  tr.delete(start2, end2);
65890
66025
  });
@@ -66078,7 +66213,7 @@ ${err.toString()}`);
66078
66213
  },
66079
66214
  resolveComment: ({ commentId }) => ({ tr, dispatch, state: state2 }) => {
66080
66215
  tr.setMeta(CommentsPluginKey, { event: "update" });
66081
- removeCommentsById({ commentId, state: state2, tr, dispatch });
66216
+ return resolveCommentById({ commentId, state: state2, tr, dispatch });
66082
66217
  },
66083
66218
  setCursorById: (id) => ({ state: state2, editor }) => {
66084
66219
  const { from: from2 } = findRangeById(state2.doc, id) || {};
@@ -66511,47 +66646,58 @@ ${err.toString()}`);
66511
66646
  return from2 !== null && to !== null ? { from: from2, to } : null;
66512
66647
  }
66513
66648
  const replaceStep = ({ state: state2, tr, step, newTr, map: map2, user, date, originalStep, originalStepIndex }) => {
66514
- const deletionMarkSchema = state2.schema.marks[TrackDeleteMarkName$1];
66515
- const deletionMark = findMark(state2, deletionMarkSchema, false);
66516
- const positionTo = deletionMark ? deletionMark.to : step.to;
66517
- const newStep = new ReplaceStep(
66518
- positionTo,
66519
- // We insert all the same steps, but with "from"/"to" both set to "to" in order not to delete content. Mapped as needed.
66520
- positionTo,
66521
- step.slice,
66522
- step.structure
66523
- );
66524
- const invertStep = originalStep.invert(tr.docs[originalStepIndex]).map(map2);
66525
- map2.appendMap(invertStep.getMap());
66526
- const meta2 = {};
66527
- if (newStep) {
66528
- const trTemp = state2.apply(newTr).tr;
66529
- if (trTemp.maybeStep(newStep).failed) {
66530
- return;
66531
- }
66532
- const mappedNewStepTo = newStep.getMap().map(newStep.to);
66533
- const insertedMark = markInsertion({
66534
- tr: trTemp,
66535
- from: newStep.from,
66536
- to: mappedNewStepTo,
66537
- user,
66538
- date
66539
- });
66540
- const condensedStep = new ReplaceStep(newStep.from, newStep.to, trTemp.doc.slice(newStep.from, mappedNewStepTo));
66541
- newTr.step(condensedStep);
66542
- const mirrorIndex = map2.maps.length - 1;
66543
- map2.appendMap(condensedStep.getMap(), mirrorIndex);
66544
- if (newStep.from !== mappedNewStepTo) {
66545
- meta2.insertedMark = insertedMark;
66546
- meta2.step = condensedStep;
66649
+ const trTemp = state2.apply(newTr).tr;
66650
+ let positionTo = step.to;
66651
+ const probePos = Math.max(step.from, step.to - 1);
66652
+ const deletionSpan = findMarkPosition(trTemp.doc, probePos, TrackDeleteMarkName$1);
66653
+ if (deletionSpan && deletionSpan.to > positionTo) {
66654
+ positionTo = deletionSpan.to;
66655
+ }
66656
+ const tryInsert = (slice2) => {
66657
+ const insertionStep = new ReplaceStep(positionTo, positionTo, slice2, false);
66658
+ if (trTemp.maybeStep(insertionStep).failed) return null;
66659
+ return {
66660
+ insertedFrom: insertionStep.from,
66661
+ insertedTo: insertionStep.getMap().map(insertionStep.to, 1)
66662
+ };
66663
+ };
66664
+ const insertion = tryInsert(step.slice) || tryInsert(Slice.maxOpen(step.slice.content, true));
66665
+ if (!insertion) {
66666
+ if (!newTr.maybeStep(step).failed) {
66667
+ map2.appendMap(step.getMap());
66547
66668
  }
66548
- if (!newTr.selection.eq(trTemp.selection)) {
66549
- newTr.setSelection(trTemp.selection);
66669
+ return;
66670
+ }
66671
+ const meta2 = {};
66672
+ const insertedMark = markInsertion({
66673
+ tr: trTemp,
66674
+ from: insertion.insertedFrom,
66675
+ to: insertion.insertedTo,
66676
+ user,
66677
+ date
66678
+ });
66679
+ const trackedInsertedSlice = trTemp.doc.slice(insertion.insertedFrom, insertion.insertedTo);
66680
+ const condensedStep = new ReplaceStep(positionTo, positionTo, trackedInsertedSlice, false);
66681
+ if (newTr.maybeStep(condensedStep).failed) {
66682
+ if (!newTr.maybeStep(step).failed) {
66683
+ map2.appendMap(step.getMap());
66550
66684
  }
66685
+ return;
66686
+ }
66687
+ const invertStep = originalStep.invert(tr.docs[originalStepIndex]).map(map2);
66688
+ map2.appendMap(invertStep.getMap());
66689
+ const mirrorIndex = map2.maps.length - 1;
66690
+ map2.appendMap(condensedStep.getMap(), mirrorIndex);
66691
+ if (insertion.insertedFrom !== insertion.insertedTo) {
66692
+ meta2.insertedMark = insertedMark;
66693
+ meta2.step = condensedStep;
66694
+ }
66695
+ if (!newTr.selection.eq(trTemp.selection)) {
66696
+ newTr.setSelection(trTemp.selection);
66551
66697
  }
66552
66698
  if (step.from !== step.to) {
66553
66699
  const {
66554
- deletionMark: deletionMark2,
66700
+ deletionMark,
66555
66701
  deletionMap,
66556
66702
  nodes: deletionNodes
66557
66703
  } = markDeletion({
@@ -66563,7 +66709,7 @@ ${err.toString()}`);
66563
66709
  id: meta2.insertedMark?.attrs?.id
66564
66710
  });
66565
66711
  meta2.deletionNodes = deletionNodes;
66566
- meta2.deletionMark = deletionMark2;
66712
+ meta2.deletionMark = deletionMark;
66567
66713
  map2.appendMapping(deletionMap);
66568
66714
  }
66569
66715
  newTr.setMeta(TrackChangesBasePluginKey, meta2);
@@ -68384,7 +68530,7 @@ ${err.toString()}`);
68384
68530
  const shouldSkipNodeView = (editor) => {
68385
68531
  return isHeadless(editor);
68386
68532
  };
68387
- const summaryVersion = "2.0.0-next.2";
68533
+ const summaryVersion = "2.0.0-next.21";
68388
68534
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
68389
68535
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
68390
68536
  function mapAttributes(attrs) {
@@ -69173,7 +69319,7 @@ ${err.toString()}`);
69173
69319
  { default: remarkStringify2 },
69174
69320
  { default: remarkGfm2 }
69175
69321
  ] = await Promise.all([
69176
- Promise.resolve().then(() => indexBqPa6D4q),
69322
+ Promise.resolve().then(() => index_W_Fk0WX),
69177
69323
  Promise.resolve().then(() => indexDRCvimau),
69178
69324
  Promise.resolve().then(() => indexC_x_N6Uh),
69179
69325
  Promise.resolve().then(() => indexD_sWOSiG),
@@ -69378,7 +69524,7 @@ ${err.toString()}`);
69378
69524
  * Process collaboration migrations
69379
69525
  */
69380
69526
  processCollaborationMigrations() {
69381
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.2");
69527
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.21");
69382
69528
  if (!this.options.ydoc) return;
69383
69529
  const metaMap = this.options.ydoc.getMap("meta");
69384
69530
  let docVersion = metaMap.get("version");
@@ -74942,6 +75088,24 @@ ${l}
74942
75088
  display: block;
74943
75089
  }
74944
75090
 
75091
+ /* Viewing mode: remove structured content affordances */
75092
+ .presentation-editor--viewing .superdoc-structured-content-block,
75093
+ .presentation-editor--viewing .superdoc-structured-content-inline {
75094
+ background: none;
75095
+ border: none;
75096
+ padding: 0;
75097
+ }
75098
+
75099
+ .presentation-editor--viewing .superdoc-structured-content-inline:hover {
75100
+ background: none;
75101
+ border: none;
75102
+ }
75103
+
75104
+ .presentation-editor--viewing .superdoc-structured-content__label,
75105
+ .presentation-editor--viewing .superdoc-structured-content-inline__label {
75106
+ display: none !important;
75107
+ }
75108
+
74945
75109
  /* Print mode: hide visual styling for SDT containers */
74946
75110
  @media print {
74947
75111
  .superdoc-document-section,
@@ -76630,7 +76794,7 @@ ${l}
76630
76794
  return true;
76631
76795
  }
76632
76796
  const LIST_MARKER_GAP$2 = 8;
76633
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
76797
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
76634
76798
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
76635
76799
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
76636
76800
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -77557,6 +77721,7 @@ ${l}
77557
77721
  const block = lookup2.block;
77558
77722
  const measure = lookup2.measure;
77559
77723
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
77724
+ const alignment2 = block.attrs?.alignment;
77560
77725
  const fragmentEl = this.doc.createElement("div");
77561
77726
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
77562
77727
  const isTocEntry = block.attrs?.isTocEntry;
@@ -77635,7 +77800,7 @@ ${l}
77635
77800
  const textStart = paraIndentLeft + firstLine;
77636
77801
  tabWidth = textStart - currentPos;
77637
77802
  if (tabWidth <= 0) {
77638
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
77803
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
77639
77804
  } else if (tabWidth < LIST_MARKER_GAP$2) {
77640
77805
  tabWidth = LIST_MARKER_GAP$2;
77641
77806
  }
@@ -77662,6 +77827,21 @@ ${l}
77662
77827
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
77663
77828
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
77664
77829
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
77830
+ if (alignment2 === "justify" || alignment2 === "both") {
77831
+ console.log(
77832
+ "[justify-debug][painter-firstline-available]",
77833
+ JSON.stringify({
77834
+ blockId: block.id,
77835
+ fragmentWidth: fragment.width,
77836
+ markerTabWidth: listFirstLineMarkerTabWidth,
77837
+ paraIndentRight,
77838
+ availableWidthOverride,
77839
+ lineMaxWidth: line.maxWidth ?? null,
77840
+ lineWidth: line.width,
77841
+ lineNaturalWidth: line.naturalWidth ?? null
77842
+ })
77843
+ );
77844
+ }
77665
77845
  }
77666
77846
  const isLastLineOfFragment = index2 === lines.length - 1;
77667
77847
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -77787,7 +77967,7 @@ ${l}
77787
77967
  const textStart = paraIndentLeft + firstLine;
77788
77968
  tabWidth = textStart - currentPos;
77789
77969
  if (tabWidth <= 0) {
77790
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
77970
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
77791
77971
  } else if (tabWidth < LIST_MARKER_GAP$2) {
77792
77972
  tabWidth = LIST_MARKER_GAP$2;
77793
77973
  }
@@ -79321,6 +79501,23 @@ ${l}
79321
79501
  if (spacingPerSpace !== 0) {
79322
79502
  el.style.wordSpacing = `${spacingPerSpace}px`;
79323
79503
  }
79504
+ if (justifyShouldApply && spacingPerSpace < 0) {
79505
+ console.log(
79506
+ "[justify-debug][painter-wordspacing-negative]",
79507
+ JSON.stringify({
79508
+ blockId: block.id,
79509
+ lineIndex: lineIndex ?? null,
79510
+ alignment: alignment2 ?? null,
79511
+ availableWidth,
79512
+ lineWidth,
79513
+ lineMaxWidth: line.maxWidth ?? null,
79514
+ lineNaturalWidth: line.naturalWidth ?? null,
79515
+ spaceCount,
79516
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
79517
+ skipJustify: Boolean(skipJustify)
79518
+ })
79519
+ );
79520
+ }
79324
79521
  if (hasExplicitPositioning && line.segments) {
79325
79522
  const paraIndent = block.attrs?.indent;
79326
79523
  const indentLeft = paraIndent?.left ?? 0;
@@ -81514,6 +81711,28 @@ ${l}
81514
81711
  const TAB_CHAR_LENGTH = 1;
81515
81712
  const SPACE_CHARS = SPACE_CHARS$1;
81516
81713
  const isTabRun$1 = (run2) => run2?.kind === "tab";
81714
+ const isWordChar$3 = (char) => {
81715
+ if (!char) return false;
81716
+ const code2 = char.charCodeAt(0);
81717
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
81718
+ };
81719
+ const capitalizeText$2 = (text2) => {
81720
+ if (!text2) return text2;
81721
+ let result = "";
81722
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
81723
+ const prevChar = i2 > 0 ? text2[i2 - 1] : "";
81724
+ const ch = text2[i2];
81725
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
81726
+ }
81727
+ return result;
81728
+ };
81729
+ const applyTextTransform$2 = (text2, transform) => {
81730
+ if (!text2 || !transform || transform === "none") return text2;
81731
+ if (transform === "uppercase") return text2.toUpperCase();
81732
+ if (transform === "lowercase") return text2.toLowerCase();
81733
+ if (transform === "capitalize") return capitalizeText$2(text2);
81734
+ return text2;
81735
+ };
81517
81736
  function getMeasurementContext() {
81518
81737
  if (measurementCtx) return measurementCtx;
81519
81738
  if (typeof document === "undefined") {
@@ -81689,17 +81908,19 @@ ${l}
81689
81908
  }
81690
81909
  const text2 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
81691
81910
  const runLength = text2.length;
81911
+ const transform = isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? void 0 : run2.textTransform;
81912
+ const displayText = applyTextTransform$2(text2, transform);
81692
81913
  if (currentCharOffset + runLength >= charOffset) {
81693
81914
  const offsetInRun = charOffset - currentCharOffset;
81694
81915
  ctx2.font = getRunFontString(run2);
81695
- const textUpToTarget = text2.slice(0, offsetInRun);
81916
+ const textUpToTarget = displayText.slice(0, offsetInRun);
81696
81917
  const measured2 = ctx2.measureText(textUpToTarget);
81697
81918
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInRun, runLength);
81698
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
81919
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text2.slice(0, offsetInRun)) : 0;
81699
81920
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
81700
81921
  }
81701
81922
  ctx2.font = getRunFontString(run2);
81702
- const measured = ctx2.measureText(text2);
81923
+ const measured = ctx2.measureText(displayText);
81703
81924
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
81704
81925
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text2) : 0;
81705
81926
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -81738,8 +81959,10 @@ ${l}
81738
81959
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
81739
81960
  }
81740
81961
  const text2 = run2.text ?? "";
81741
- const segmentText = text2.slice(segment.fromChar, segment.toChar);
81742
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
81962
+ const transform = "textTransform" in run2 ? run2.textTransform : void 0;
81963
+ const displayText = applyTextTransform$2(text2, transform);
81964
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
81965
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
81743
81966
  ctx2.font = getRunFontString(run2);
81744
81967
  const measured = ctx2.measureText(textUpToTarget);
81745
81968
  const spacingWidth = computeLetterSpacingWidth(run2, offsetInSegment, segmentChars);
@@ -81835,12 +82058,14 @@ ${l}
81835
82058
  }
81836
82059
  const text2 = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
81837
82060
  const runLength = text2.length;
82061
+ const transform = isTabRun$1(run2) || "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? void 0 : run2.textTransform;
82062
+ const displayText = applyTextTransform$2(text2, transform);
81838
82063
  if (runLength === 0) continue;
81839
82064
  ctx2.font = getRunFontString(run2);
81840
82065
  for (let i2 = 0; i2 <= runLength; i2++) {
81841
- const textUpToChar = text2.slice(0, i2);
82066
+ const textUpToChar = displayText.slice(0, i2);
81842
82067
  const measured2 = ctx2.measureText(textUpToChar);
81843
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
82068
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text2.slice(0, i2)) : 0;
81844
82069
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run2, i2, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
81845
82070
  if (charX >= safeX) {
81846
82071
  if (i2 === 0) {
@@ -81850,7 +82075,7 @@ ${l}
81850
82075
  pmPosition: pmPosition3
81851
82076
  };
81852
82077
  }
81853
- const prevText = text2.slice(0, i2 - 1);
82078
+ const prevText = displayText.slice(0, i2 - 1);
81854
82079
  const prevMeasured = ctx2.measureText(prevText);
81855
82080
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run2, i2 - 1, runLength);
81856
82081
  const distToPrev = Math.abs(safeX - prevX);
@@ -81863,7 +82088,7 @@ ${l}
81863
82088
  };
81864
82089
  }
81865
82090
  }
81866
- const measured = ctx2.measureText(text2);
82091
+ const measured = ctx2.measureText(displayText);
81867
82092
  const runLetterSpacing = computeLetterSpacingWidth(run2, runLength, runLength);
81868
82093
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text2) : 0;
81869
82094
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -82294,6 +82519,83 @@ ${l}
82294
82519
  }
82295
82520
  return index2;
82296
82521
  }
82522
+ const LIST_MARKER_GAP$1 = 8;
82523
+ const MIN_MARKER_GUTTER = 24;
82524
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
82525
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
82526
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
82527
+ const SPACE_SUFFIX_GAP_PX = 4;
82528
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
82529
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
82530
+ const marker = wordLayout?.marker;
82531
+ if (!marker) {
82532
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
82533
+ return textStartPx;
82534
+ }
82535
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
82536
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
82537
+ if (markerTextWidth == null && marker.markerText) {
82538
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
82539
+ }
82540
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth !== void 0 && markerTextWidth < 0) {
82541
+ markerTextWidth = markerBoxWidth;
82542
+ }
82543
+ const finalMarkerTextWidth = Math.max(0, markerTextWidth ?? 0);
82544
+ let markerStartPos;
82545
+ if (wordLayout?.firstLineIndentMode === true && typeof marker.markerX === "number" && Number.isFinite(marker.markerX)) {
82546
+ markerStartPos = marker.markerX;
82547
+ } else {
82548
+ markerStartPos = indentLeft - hanging + firstLine;
82549
+ }
82550
+ if (!Number.isFinite(markerStartPos)) {
82551
+ markerStartPos = 0;
82552
+ }
82553
+ const currentPos = markerStartPos + finalMarkerTextWidth;
82554
+ const suffix2 = marker.suffix ?? "tab";
82555
+ if (suffix2 === "space") {
82556
+ return markerStartPos + finalMarkerTextWidth + SPACE_SUFFIX_GAP_PX;
82557
+ }
82558
+ if (suffix2 === "nothing") {
82559
+ return markerStartPos + finalMarkerTextWidth;
82560
+ }
82561
+ const markerJustification = marker.justification ?? "left";
82562
+ if (markerJustification !== "left") {
82563
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
82564
+ return markerStartPos + finalMarkerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
82565
+ }
82566
+ if (wordLayout?.firstLineIndentMode === true) {
82567
+ let targetTabStop;
82568
+ if (Array.isArray(wordLayout.tabsPx)) {
82569
+ for (const tab of wordLayout.tabsPx) {
82570
+ if (typeof tab === "number" && tab > currentPos) {
82571
+ targetTabStop = tab;
82572
+ break;
82573
+ }
82574
+ }
82575
+ }
82576
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
82577
+ let tabWidth2;
82578
+ if (targetTabStop !== void 0) {
82579
+ tabWidth2 = targetTabStop - currentPos;
82580
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
82581
+ tabWidth2 = textStartTarget - currentPos;
82582
+ } else {
82583
+ tabWidth2 = LIST_MARKER_GAP$1;
82584
+ }
82585
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
82586
+ tabWidth2 = LIST_MARKER_GAP$1;
82587
+ }
82588
+ return markerStartPos + finalMarkerTextWidth + tabWidth2;
82589
+ }
82590
+ const textStart = indentLeft + firstLine;
82591
+ let tabWidth = textStart - currentPos;
82592
+ if (tabWidth <= 0) {
82593
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
82594
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
82595
+ tabWidth = LIST_MARKER_GAP$1;
82596
+ }
82597
+ return markerStartPos + finalMarkerTextWidth + tabWidth;
82598
+ }
82297
82599
  function getWordLayoutConfig(block) {
82298
82600
  if (!block || block.kind !== "paragraph") {
82299
82601
  return void 0;
@@ -82326,9 +82628,16 @@ ${l}
82326
82628
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
82327
82629
  let indentAdjust = paraIndentLeft;
82328
82630
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
82631
+ const resolvedTextStart = resolveListTextStartPx(
82632
+ wordLayout,
82633
+ paraIndentLeft,
82634
+ Math.max(firstLineIndent, 0),
82635
+ Math.max(hangingIndent, 0),
82636
+ () => markerWidth
82637
+ // Use provided markerWidth since we don't have canvas access here
82638
+ );
82329
82639
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
82330
- const markerTextStartX = wordLayout?.marker?.textStartX;
82331
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
82640
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
82332
82641
  } else if (isFirstLine && !isListItem2) {
82333
82642
  indentAdjust += firstLineOffset;
82334
82643
  }
@@ -82484,7 +82793,10 @@ ${l}
82484
82793
  }
82485
82794
  function createFloatingObjectManager(columns, margins, pageWidth) {
82486
82795
  const zones = [];
82487
- const marginLeft = Math.max(0, margins?.left ?? 0);
82796
+ let currentColumns = columns;
82797
+ let currentMargins = margins;
82798
+ let currentPageWidth = pageWidth;
82799
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
82488
82800
  return {
82489
82801
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
82490
82802
  if (!drawingBlock.anchor?.isAnchored) {
@@ -82497,7 +82809,7 @@ ${l}
82497
82809
  }
82498
82810
  const objectWidth = measure.width ?? 0;
82499
82811
  const objectHeight = measure.height ?? 0;
82500
- const x2 = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
82812
+ const x2 = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
82501
82813
  const y2 = anchorY + (anchor.offsetV ?? 0);
82502
82814
  const zone = {
82503
82815
  imageBlockId: drawingBlock.id,
@@ -82531,7 +82843,7 @@ ${l}
82531
82843
  }
82532
82844
  const tableWidth = measure.totalWidth ?? 0;
82533
82845
  const tableHeight = measure.totalHeight ?? 0;
82534
- const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
82846
+ const x2 = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
82535
82847
  const y2 = anchorY + (anchor.offsetV ?? 0);
82536
82848
  const zone = {
82537
82849
  imageBlockId: tableBlock.id,
@@ -82579,7 +82891,7 @@ ${l}
82579
82891
  }
82580
82892
  const leftFloats = [];
82581
82893
  const rightFloats = [];
82582
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
82894
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
82583
82895
  const columnCenter = columnOrigin + baseWidth / 2;
82584
82896
  for (const zone of wrappingZones) {
82585
82897
  if (zone.wrapMode === "left") {
@@ -82618,6 +82930,22 @@ ${l}
82618
82930
  },
82619
82931
  clear() {
82620
82932
  zones.length = 0;
82933
+ },
82934
+ /**
82935
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
82936
+ * This method should be called when the layout configuration changes (e.g., section breaks,
82937
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
82938
+ * correctly relative to the new layout boundaries.
82939
+ *
82940
+ * @param nextColumns - Column layout configuration (width, gap, count)
82941
+ * @param nextMargins - Optional page margins (left, right) in pixels
82942
+ * @param nextPageWidth - Optional total page width in pixels
82943
+ */
82944
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
82945
+ currentColumns = nextColumns;
82946
+ currentMargins = nextMargins;
82947
+ currentPageWidth = nextPageWidth;
82948
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
82621
82949
  }
82622
82950
  };
82623
82951
  }
@@ -82717,7 +83045,14 @@ ${l}
82717
83045
  const props = {};
82718
83046
  if (source.kind !== "sectionBreak") return props;
82719
83047
  if (source.margins) {
82720
- props.margins = { header: source.margins.header, footer: source.margins.footer };
83048
+ props.margins = {
83049
+ header: source.margins.header,
83050
+ footer: source.margins.footer,
83051
+ top: source.margins.top,
83052
+ right: source.margins.right,
83053
+ bottom: source.margins.bottom,
83054
+ left: source.margins.left
83055
+ };
82721
83056
  }
82722
83057
  if (source.pageSize) {
82723
83058
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -82748,13 +83083,13 @@ ${l}
82748
83083
  if (maxHeaderContentHeight > 0) {
82749
83084
  return Math.max(baseTop, headerDistance + maxHeaderContentHeight);
82750
83085
  }
82751
- return Math.max(baseTop, headerDistance);
83086
+ return baseTop;
82752
83087
  };
82753
83088
  const calcRequiredBottomMargin = (footerDistance, baseBottom) => {
82754
83089
  if (maxFooterContentHeight > 0) {
82755
83090
  return Math.max(baseBottom, footerDistance + maxFooterContentHeight);
82756
83091
  }
82757
- return Math.max(baseBottom, footerDistance);
83092
+ return baseBottom;
82758
83093
  };
82759
83094
  if (block.attrs?.isFirstSection && !next2.hasAnyPages) {
82760
83095
  if (block.pageSize) {
@@ -82765,20 +83100,36 @@ ${l}
82765
83100
  next2.activeOrientation = block.orientation;
82766
83101
  next2.pendingOrientation = null;
82767
83102
  }
83103
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next2.activeHeaderDistance;
83104
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next2.activeFooterDistance;
83105
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
83106
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
82768
83107
  if (block.margins?.header !== void 0) {
82769
- const headerDistance = Math.max(0, block.margins.header);
82770
83108
  next2.activeHeaderDistance = headerDistance;
82771
83109
  next2.pendingHeaderDistance = headerDistance;
82772
- next2.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
82773
- next2.pendingTopMargin = next2.activeTopMargin;
82774
83110
  }
82775
83111
  if (block.margins?.footer !== void 0) {
82776
- const footerDistance = Math.max(0, block.margins.footer);
82777
83112
  next2.activeFooterDistance = footerDistance;
82778
83113
  next2.pendingFooterDistance = footerDistance;
82779
- next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
83114
+ }
83115
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
83116
+ next2.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
83117
+ next2.pendingTopMargin = next2.activeTopMargin;
83118
+ }
83119
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
83120
+ next2.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
82780
83121
  next2.pendingBottomMargin = next2.activeBottomMargin;
82781
83122
  }
83123
+ if (block.margins?.left !== void 0) {
83124
+ const leftMargin = Math.max(0, block.margins.left);
83125
+ next2.activeLeftMargin = leftMargin;
83126
+ next2.pendingLeftMargin = leftMargin;
83127
+ }
83128
+ if (block.margins?.right !== void 0) {
83129
+ const rightMargin = Math.max(0, block.margins.right);
83130
+ next2.activeRightMargin = rightMargin;
83131
+ next2.pendingRightMargin = rightMargin;
83132
+ }
82782
83133
  if (block.columns) {
82783
83134
  next2.activeColumns = { count: block.columns.count, gap: block.columns.gap };
82784
83135
  next2.pendingColumns = null;
@@ -82787,26 +83138,42 @@ ${l}
82787
83138
  }
82788
83139
  const headerPx = block.margins?.header;
82789
83140
  const footerPx = block.margins?.footer;
83141
+ const topPx = block.margins?.top;
83142
+ const bottomPx = block.margins?.bottom;
82790
83143
  const nextTop = next2.pendingTopMargin ?? next2.activeTopMargin;
82791
83144
  const nextBottom = next2.pendingBottomMargin ?? next2.activeBottomMargin;
83145
+ const nextLeft = next2.pendingLeftMargin ?? next2.activeLeftMargin;
83146
+ const nextRight = next2.pendingRightMargin ?? next2.activeRightMargin;
82792
83147
  const nextHeader = next2.pendingHeaderDistance ?? next2.activeHeaderDistance;
82793
83148
  const nextFooter = next2.pendingFooterDistance ?? next2.activeFooterDistance;
82794
- if (typeof headerPx === "number") {
82795
- const newHeaderDist = Math.max(0, headerPx);
83149
+ if (typeof headerPx === "number" || typeof topPx === "number") {
83150
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
83151
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
82796
83152
  next2.pendingHeaderDistance = newHeaderDist;
82797
- next2.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
83153
+ next2.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
82798
83154
  } else {
82799
83155
  next2.pendingTopMargin = nextTop;
82800
83156
  next2.pendingHeaderDistance = nextHeader;
82801
83157
  }
82802
- if (typeof footerPx === "number") {
82803
- const newFooterDist = Math.max(0, footerPx);
83158
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
83159
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
83160
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
82804
83161
  next2.pendingFooterDistance = newFooterDist;
82805
- next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
83162
+ next2.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
82806
83163
  } else {
82807
83164
  next2.pendingBottomMargin = nextBottom;
82808
83165
  next2.pendingFooterDistance = nextFooter;
82809
83166
  }
83167
+ if (typeof block.margins?.left === "number") {
83168
+ next2.pendingLeftMargin = Math.max(0, block.margins.left);
83169
+ } else {
83170
+ next2.pendingLeftMargin = nextLeft;
83171
+ }
83172
+ if (typeof block.margins?.right === "number") {
83173
+ next2.pendingRightMargin = Math.max(0, block.margins.right);
83174
+ } else {
83175
+ next2.pendingRightMargin = nextRight;
83176
+ }
82810
83177
  if (block.pageSize) {
82811
83178
  next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
82812
83179
  }
@@ -82866,6 +83233,12 @@ ${l}
82866
83233
  if (next2.pendingBottomMargin != null) {
82867
83234
  next2.activeBottomMargin = next2.pendingBottomMargin;
82868
83235
  }
83236
+ if (next2.pendingLeftMargin != null) {
83237
+ next2.activeLeftMargin = next2.pendingLeftMargin;
83238
+ }
83239
+ if (next2.pendingRightMargin != null) {
83240
+ next2.activeRightMargin = next2.pendingRightMargin;
83241
+ }
82869
83242
  if (next2.pendingHeaderDistance != null) {
82870
83243
  next2.activeHeaderDistance = next2.pendingHeaderDistance;
82871
83244
  }
@@ -82883,6 +83256,8 @@ ${l}
82883
83256
  }
82884
83257
  next2.pendingTopMargin = null;
82885
83258
  next2.pendingBottomMargin = null;
83259
+ next2.pendingLeftMargin = null;
83260
+ next2.pendingRightMargin = null;
82886
83261
  next2.pendingHeaderDistance = null;
82887
83262
  next2.pendingFooterDistance = null;
82888
83263
  next2.pendingPageSize = null;
@@ -83111,7 +83486,8 @@ ${l}
83111
83486
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
83112
83487
  const firstLineIndent = calculateFirstLineIndent(block, measure);
83113
83488
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
83114
- lines = normalizeLines(newMeasure);
83489
+ const newLines = normalizeLines(newMeasure);
83490
+ lines = newLines;
83115
83491
  didRemeasureForColumnWidth = true;
83116
83492
  }
83117
83493
  let fromLine = 0;
@@ -83193,7 +83569,8 @@ ${l}
83193
83569
  if (narrowestRemeasureWidth < remeasureWidth) {
83194
83570
  const firstLineIndent = calculateFirstLineIndent(block, measure);
83195
83571
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
83196
- lines = normalizeLines(newMeasure);
83572
+ const newLines = normalizeLines(newMeasure);
83573
+ lines = newLines;
83197
83574
  didRemeasureForFloats = true;
83198
83575
  }
83199
83576
  }
@@ -83213,6 +83590,11 @@ ${l}
83213
83590
  const prevTrailing = state2.trailingSpacing ?? 0;
83214
83591
  const neededSpacingBefore = Math.max(spacingBefore - prevTrailing, 0);
83215
83592
  if (state2.cursorY + neededSpacingBefore > state2.contentBottom) {
83593
+ if (state2.cursorY <= state2.topMargin) {
83594
+ state2.trailingSpacing = 0;
83595
+ appliedSpacingBefore = true;
83596
+ break;
83597
+ }
83216
83598
  state2 = advanceColumn(state2);
83217
83599
  if (state2.trailingSpacing == null) state2.trailingSpacing = 0;
83218
83600
  continue;
@@ -83537,6 +83919,94 @@ ${l}
83537
83919
  function getCellTotalLines(cell2) {
83538
83920
  return getCellLines(cell2).length;
83539
83921
  }
83922
+ function mergePmRange(target, range2) {
83923
+ if (typeof range2.pmStart === "number") {
83924
+ target.pmStart = target.pmStart == null ? range2.pmStart : Math.min(target.pmStart, range2.pmStart);
83925
+ }
83926
+ if (typeof range2.pmEnd === "number") {
83927
+ target.pmEnd = target.pmEnd == null ? range2.pmEnd : Math.max(target.pmEnd, range2.pmEnd);
83928
+ }
83929
+ }
83930
+ function computeCellPmRange(cell2, cellMeasure, fromLine, toLine) {
83931
+ const range2 = {};
83932
+ if (!cell2 || !cellMeasure) return range2;
83933
+ const cellBlocks = cell2.blocks ?? (cell2.paragraph ? [cell2.paragraph] : []);
83934
+ const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
83935
+ const maxBlocks = Math.min(cellBlocks.length, blockMeasures.length);
83936
+ let cumulativeLineCount = 0;
83937
+ for (let i2 = 0; i2 < maxBlocks; i2++) {
83938
+ const block = cellBlocks[i2];
83939
+ const blockMeasure = blockMeasures[i2];
83940
+ if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
83941
+ const paraMeasure = blockMeasure;
83942
+ const lines = paraMeasure.lines;
83943
+ const blockLineCount = lines?.length ?? 0;
83944
+ const blockStartGlobal = cumulativeLineCount;
83945
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
83946
+ const localFrom = Math.max(fromLine, blockStartGlobal) - blockStartGlobal;
83947
+ const localTo = Math.min(toLine, blockEndGlobal) - blockStartGlobal;
83948
+ if (lines && lines.length > 0 && localFrom < localTo) {
83949
+ mergePmRange(range2, computeFragmentPmRange(block, lines, localFrom, localTo));
83950
+ } else {
83951
+ mergePmRange(range2, extractBlockPmRange(block));
83952
+ }
83953
+ cumulativeLineCount += blockLineCount;
83954
+ continue;
83955
+ }
83956
+ mergePmRange(range2, extractBlockPmRange(block));
83957
+ }
83958
+ return range2;
83959
+ }
83960
+ function computeTableFragmentPmRange(block, measure, fromRow, toRow, partialRow) {
83961
+ const range2 = {};
83962
+ for (let rowIndex = fromRow; rowIndex < toRow; rowIndex++) {
83963
+ const row2 = block.rows[rowIndex];
83964
+ const rowMeasure = measure.rows[rowIndex];
83965
+ if (!row2 || !rowMeasure) continue;
83966
+ const isPartial = partialRow?.rowIndex === rowIndex;
83967
+ const cellCount = Math.min(row2.cells.length, rowMeasure.cells.length);
83968
+ for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
83969
+ const cell2 = row2.cells[cellIndex];
83970
+ const cellMeasure = rowMeasure.cells[cellIndex];
83971
+ if (!cell2 || !cellMeasure) continue;
83972
+ const totalLines = getCellTotalLines(cellMeasure);
83973
+ let fromLine = 0;
83974
+ let toLine = totalLines;
83975
+ if (isPartial) {
83976
+ const hasValidFromLineByCell = partialRow?.fromLineByCell && cellIndex < partialRow.fromLineByCell.length;
83977
+ const hasValidToLineByCell = partialRow?.toLineByCell && cellIndex < partialRow.toLineByCell.length;
83978
+ if (hasValidFromLineByCell) {
83979
+ const rawFrom = partialRow.fromLineByCell[cellIndex];
83980
+ if (typeof rawFrom === "number" && rawFrom >= 0) {
83981
+ fromLine = rawFrom;
83982
+ }
83983
+ }
83984
+ if (hasValidToLineByCell) {
83985
+ const rawTo = partialRow.toLineByCell[cellIndex];
83986
+ if (typeof rawTo === "number") {
83987
+ toLine = rawTo === -1 ? totalLines : rawTo;
83988
+ }
83989
+ }
83990
+ }
83991
+ fromLine = Math.max(0, Math.min(fromLine, totalLines));
83992
+ toLine = Math.max(0, Math.min(toLine, totalLines));
83993
+ if (toLine < fromLine) {
83994
+ toLine = fromLine;
83995
+ }
83996
+ mergePmRange(range2, computeCellPmRange(cell2, cellMeasure, fromLine, toLine));
83997
+ }
83998
+ }
83999
+ return range2;
84000
+ }
84001
+ function applyTableFragmentPmRange(fragment, block, measure) {
84002
+ const range2 = computeTableFragmentPmRange(block, measure, fragment.fromRow, fragment.toRow, fragment.partialRow);
84003
+ if (range2.pmStart != null) {
84004
+ fragment.pmStart = range2.pmStart;
84005
+ }
84006
+ if (range2.pmEnd != null) {
84007
+ fragment.pmEnd = range2.pmEnd;
84008
+ }
84009
+ }
83540
84010
  function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
83541
84011
  const row2 = measure.rows[rowIndex];
83542
84012
  if (!row2) {
@@ -83681,6 +84151,7 @@ ${l}
83681
84151
  height,
83682
84152
  metadata
83683
84153
  };
84154
+ applyTableFragmentPmRange(fragment, context.block, context.measure);
83684
84155
  state2.page.fragments.push(fragment);
83685
84156
  state2.cursorY += height;
83686
84157
  }
@@ -83759,6 +84230,7 @@ ${l}
83759
84230
  height,
83760
84231
  metadata
83761
84232
  };
84233
+ applyTableFragmentPmRange(fragment, block, measure);
83762
84234
  state2.page.fragments.push(fragment);
83763
84235
  state2.cursorY += height;
83764
84236
  return;
@@ -83822,6 +84294,7 @@ ${l}
83822
84294
  partialRow: continuationPartialRow,
83823
84295
  metadata: generateFragmentMetadata(measure)
83824
84296
  };
84297
+ applyTableFragmentPmRange(fragment2, block, measure);
83825
84298
  state2.page.fragments.push(fragment2);
83826
84299
  state2.cursorY += fragmentHeight2;
83827
84300
  }
@@ -83866,6 +84339,7 @@ ${l}
83866
84339
  partialRow: forcedPartialRow,
83867
84340
  metadata: generateFragmentMetadata(measure)
83868
84341
  };
84342
+ applyTableFragmentPmRange(fragment2, block, measure);
83869
84343
  state2.page.fragments.push(fragment2);
83870
84344
  state2.cursorY += fragmentHeight2;
83871
84345
  pendingPartialRow = forcedPartialRow;
@@ -83901,6 +84375,7 @@ ${l}
83901
84375
  partialRow: partialRow || void 0,
83902
84376
  metadata: generateFragmentMetadata(measure)
83903
84377
  };
84378
+ applyTableFragmentPmRange(fragment, block, measure);
83904
84379
  state2.page.fragments.push(fragment);
83905
84380
  state2.cursorY += fragmentHeight;
83906
84381
  if (partialRow && !partialRow.isLastPart) {
@@ -83918,7 +84393,7 @@ ${l}
83918
84393
  columnBoundaries: generateColumnBoundaries(measure),
83919
84394
  coordinateSystem: "fragment"
83920
84395
  };
83921
- return {
84396
+ const fragment = {
83922
84397
  kind: "table",
83923
84398
  blockId: block.id,
83924
84399
  fromRow: 0,
@@ -83929,6 +84404,8 @@ ${l}
83929
84404
  height: measure.totalHeight ?? 0,
83930
84405
  metadata
83931
84406
  };
84407
+ applyTableFragmentPmRange(fragment, block, measure);
84408
+ return fragment;
83932
84409
  }
83933
84410
  function isPageRelativeAnchor(block) {
83934
84411
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -84350,8 +84827,8 @@ ${l}
84350
84827
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
84351
84828
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
84352
84829
  };
84353
- const contentWidth = pageSize.w - (margins.left + margins.right);
84354
- if (contentWidth <= 0) {
84830
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
84831
+ if (baseContentWidth <= 0) {
84355
84832
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
84356
84833
  }
84357
84834
  const validateContentHeight = (height) => {
@@ -84381,8 +84858,12 @@ ${l}
84381
84858
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
84382
84859
  let activeTopMargin = effectiveTopMargin;
84383
84860
  let activeBottomMargin = effectiveBottomMargin;
84861
+ let activeLeftMargin = margins.left;
84862
+ let activeRightMargin = margins.right;
84384
84863
  let pendingTopMargin = null;
84385
84864
  let pendingBottomMargin = null;
84865
+ let pendingLeftMargin = null;
84866
+ let pendingRightMargin = null;
84386
84867
  let activeHeaderDistance = margins.header ?? margins.top;
84387
84868
  let pendingHeaderDistance = null;
84388
84869
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -84395,10 +84876,11 @@ ${l}
84395
84876
  let pendingOrientation = null;
84396
84877
  let activeVAlign = null;
84397
84878
  let pendingVAlign = null;
84879
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
84398
84880
  const floatManager = createFloatingObjectManager(
84399
- normalizeColumns(activeColumns, contentWidth),
84400
- { left: margins.left, right: margins.right },
84401
- pageSize.w
84881
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
84882
+ { left: activeLeftMargin, right: activeRightMargin },
84883
+ activePageSize.w
84402
84884
  );
84403
84885
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks2);
84404
84886
  const scheduleSectionBreakCompat = (block, state2, baseMargins) => {
@@ -84415,22 +84897,38 @@ ${l}
84415
84897
  next2.activeOrientation = block.orientation;
84416
84898
  next2.pendingOrientation = null;
84417
84899
  }
84900
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next2.activeHeaderDistance;
84901
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next2.activeFooterDistance;
84902
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
84903
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
84418
84904
  if (block.margins?.header !== void 0) {
84419
- const headerDist = Math.max(0, block.margins.header);
84420
- next2.activeHeaderDistance = headerDist;
84421
- next2.pendingHeaderDistance = headerDist;
84422
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
84423
- next2.activeTopMargin = Math.max(baseMargins.top, requiredTop);
84424
- next2.pendingTopMargin = next2.activeTopMargin;
84905
+ next2.activeHeaderDistance = headerDistance2;
84906
+ next2.pendingHeaderDistance = headerDistance2;
84425
84907
  }
84426
84908
  if (block.margins?.footer !== void 0) {
84427
- const footerDistance2 = Math.max(0, block.margins.footer);
84428
84909
  next2.activeFooterDistance = footerDistance2;
84429
84910
  next2.pendingFooterDistance = footerDistance2;
84430
- const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
84431
- next2.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
84911
+ }
84912
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
84913
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : 0;
84914
+ next2.activeTopMargin = Math.max(sectionTop, requiredTop);
84915
+ next2.pendingTopMargin = next2.activeTopMargin;
84916
+ }
84917
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
84918
+ const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : 0;
84919
+ next2.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
84432
84920
  next2.pendingBottomMargin = next2.activeBottomMargin;
84433
84921
  }
84922
+ if (block.margins?.left !== void 0) {
84923
+ const leftMargin = Math.max(0, block.margins.left);
84924
+ next2.activeLeftMargin = leftMargin;
84925
+ next2.pendingLeftMargin = leftMargin;
84926
+ }
84927
+ if (block.margins?.right !== void 0) {
84928
+ const rightMargin = Math.max(0, block.margins.right);
84929
+ next2.activeRightMargin = rightMargin;
84930
+ next2.pendingRightMargin = rightMargin;
84931
+ }
84434
84932
  if (block.columns) {
84435
84933
  next2.activeColumns = { count: block.columns.count, gap: block.columns.gap };
84436
84934
  next2.pendingColumns = null;
@@ -84459,27 +84957,35 @@ ${l}
84459
84957
  const headerPx = block.margins?.header;
84460
84958
  const footerPx = block.margins?.footer;
84461
84959
  const topPx = block.margins?.top;
84960
+ const bottomPx = block.margins?.bottom;
84961
+ const leftPx = block.margins?.left;
84962
+ const rightPx = block.margins?.right;
84462
84963
  const nextTop = next2.pendingTopMargin ?? next2.activeTopMargin;
84463
84964
  const nextBottom = next2.pendingBottomMargin ?? next2.activeBottomMargin;
84965
+ const nextLeft = next2.pendingLeftMargin ?? next2.activeLeftMargin;
84966
+ const nextRight = next2.pendingRightMargin ?? next2.activeRightMargin;
84464
84967
  const nextHeader = next2.pendingHeaderDistance ?? next2.activeHeaderDistance;
84465
84968
  const nextFooter = next2.pendingFooterDistance ?? next2.activeFooterDistance;
84466
84969
  next2.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
84467
84970
  next2.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
84468
84971
  if (typeof headerPx === "number" || typeof topPx === "number") {
84469
- const sectionTop = topPx ?? baseMargins.top;
84972
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
84470
84973
  const sectionHeader = next2.pendingHeaderDistance;
84471
84974
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
84472
84975
  next2.pendingTopMargin = Math.max(sectionTop, requiredTop);
84473
84976
  } else {
84474
84977
  next2.pendingTopMargin = nextTop;
84475
84978
  }
84476
- if (typeof footerPx === "number") {
84979
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
84477
84980
  const sectionFooter = next2.pendingFooterDistance;
84981
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
84478
84982
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
84479
- next2.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
84983
+ next2.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
84480
84984
  } else {
84481
84985
  next2.pendingBottomMargin = nextBottom;
84482
84986
  }
84987
+ next2.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
84988
+ next2.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
84483
84989
  if (block.pageSize) next2.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
84484
84990
  if (block.orientation) next2.pendingOrientation = block.orientation;
84485
84991
  const sectionType = block.type ?? "continuous";
@@ -84564,7 +85070,7 @@ ${l}
84564
85070
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
84565
85071
  let pendingSectionIndex = null;
84566
85072
  const paginator = createPaginator({
84567
- margins: { left: margins.left, right: margins.right },
85073
+ margins: paginatorMargins,
84568
85074
  getActiveTopMargin: () => activeTopMargin,
84569
85075
  getActiveBottomMargin: () => activeBottomMargin,
84570
85076
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -84579,8 +85085,12 @@ ${l}
84579
85085
  const applied = applyPendingToActive({
84580
85086
  activeTopMargin,
84581
85087
  activeBottomMargin,
85088
+ activeLeftMargin,
85089
+ activeRightMargin,
84582
85090
  pendingTopMargin,
84583
85091
  pendingBottomMargin,
85092
+ pendingLeftMargin,
85093
+ pendingRightMargin,
84584
85094
  activeHeaderDistance,
84585
85095
  activeFooterDistance,
84586
85096
  pendingHeaderDistance,
@@ -84595,8 +85105,12 @@ ${l}
84595
85105
  });
84596
85106
  activeTopMargin = applied.activeTopMargin;
84597
85107
  activeBottomMargin = applied.activeBottomMargin;
85108
+ activeLeftMargin = applied.activeLeftMargin;
85109
+ activeRightMargin = applied.activeRightMargin;
84598
85110
  pendingTopMargin = applied.pendingTopMargin;
84599
85111
  pendingBottomMargin = applied.pendingBottomMargin;
85112
+ pendingLeftMargin = applied.pendingLeftMargin;
85113
+ pendingRightMargin = applied.pendingRightMargin;
84600
85114
  activeHeaderDistance = applied.activeHeaderDistance;
84601
85115
  activeFooterDistance = applied.activeFooterDistance;
84602
85116
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -84608,6 +85122,14 @@ ${l}
84608
85122
  activeOrientation = applied.activeOrientation;
84609
85123
  pendingOrientation = applied.pendingOrientation;
84610
85124
  cachedColumnsState.state = null;
85125
+ paginatorMargins.left = activeLeftMargin;
85126
+ paginatorMargins.right = activeRightMargin;
85127
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
85128
+ floatManager.setLayoutContext(
85129
+ normalizeColumns(activeColumns, contentWidth),
85130
+ { left: activeLeftMargin, right: activeRightMargin },
85131
+ activePageSize.w
85132
+ );
84611
85133
  if (pendingNumbering) {
84612
85134
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
84613
85135
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -84652,7 +85174,7 @@ ${l}
84652
85174
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
84653
85175
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
84654
85176
  const getCurrentColumns = () => {
84655
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
85177
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84656
85178
  const state2 = states[states.length - 1] ?? null;
84657
85179
  const colsConfig = state2 ? getActiveColumnsForState(state2) : activeColumns;
84658
85180
  const constraintIndex = state2 ? state2.activeConstraintIndex : -1;
@@ -84685,6 +85207,12 @@ ${l}
84685
85207
  layoutLog(` Current page: ${state2.page.number}, cursorY: ${state2.cursorY}`);
84686
85208
  activeColumns = newColumns;
84687
85209
  cachedColumnsState.state = null;
85210
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
85211
+ floatManager.setLayoutContext(
85212
+ normalizeColumns(activeColumns, contentWidth),
85213
+ { left: activeLeftMargin, right: activeRightMargin },
85214
+ activePageSize.w
85215
+ );
84688
85216
  };
84689
85217
  const anchoredByParagraph = collectAnchoredDrawings(blocks2, measures);
84690
85218
  const anchoredTablesByParagraph = collectAnchoredTables(blocks2, measures);
@@ -84716,10 +85244,10 @@ ${l}
84716
85244
  if (alignV === "top") {
84717
85245
  anchorY = offsetV;
84718
85246
  } else if (alignV === "bottom") {
84719
- const pageHeight = contentBottom + margins.bottom;
85247
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
84720
85248
  anchorY = pageHeight - imageHeight + offsetV;
84721
85249
  } else if (alignV === "center") {
84722
- const pageHeight = contentBottom + margins.bottom;
85250
+ const pageHeight = contentBottom + (state2.page.margins?.bottom ?? activeBottomMargin);
84723
85251
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
84724
85252
  } else {
84725
85253
  anchorY = offsetV;
@@ -84730,11 +85258,11 @@ ${l}
84730
85258
  const anchorX = entry.block.anchor ? computeAnchorX(
84731
85259
  entry.block.anchor,
84732
85260
  state2.columnIndex,
84733
- normalizeColumns(activeColumns, contentWidth),
85261
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
84734
85262
  entry.measure.width,
84735
- { left: margins.left, right: margins.right },
85263
+ { left: activeLeftMargin, right: activeRightMargin },
84736
85264
  activePageSize.w
84737
- ) : margins.left;
85265
+ ) : activeLeftMargin;
84738
85266
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state2.columnIndex, state2.page.number);
84739
85267
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state2.page.number });
84740
85268
  }
@@ -84772,8 +85300,12 @@ ${l}
84772
85300
  const sectionState = {
84773
85301
  activeTopMargin,
84774
85302
  activeBottomMargin,
85303
+ activeLeftMargin,
85304
+ activeRightMargin,
84775
85305
  pendingTopMargin,
84776
85306
  pendingBottomMargin,
85307
+ pendingLeftMargin,
85308
+ pendingRightMargin,
84777
85309
  activeHeaderDistance,
84778
85310
  activeFooterDistance,
84779
85311
  pendingHeaderDistance,
@@ -84807,8 +85339,12 @@ ${l}
84807
85339
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
84808
85340
  activeTopMargin = updatedState.activeTopMargin;
84809
85341
  activeBottomMargin = updatedState.activeBottomMargin;
85342
+ activeLeftMargin = updatedState.activeLeftMargin;
85343
+ activeRightMargin = updatedState.activeRightMargin;
84810
85344
  pendingTopMargin = updatedState.pendingTopMargin;
84811
85345
  pendingBottomMargin = updatedState.pendingBottomMargin;
85346
+ pendingLeftMargin = updatedState.pendingLeftMargin;
85347
+ pendingRightMargin = updatedState.pendingRightMargin;
84812
85348
  activeHeaderDistance = updatedState.activeHeaderDistance;
84813
85349
  activeFooterDistance = updatedState.activeFooterDistance;
84814
85350
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -84946,8 +85482,8 @@ ${l}
84946
85482
  pageMargins: {
84947
85483
  top: activeTopMargin,
84948
85484
  bottom: activeBottomMargin,
84949
- left: margins.left,
84950
- right: margins.right
85485
+ left: activeLeftMargin,
85486
+ right: activeRightMargin
84951
85487
  },
84952
85488
  columns: getCurrentColumns(),
84953
85489
  placedAnchoredIds
@@ -84969,9 +85505,9 @@ ${l}
84969
85505
  const cols = getCurrentColumns();
84970
85506
  let maxWidth;
84971
85507
  if (relativeFrom === "page") {
84972
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
85508
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
84973
85509
  } else if (relativeFrom === "margin") {
84974
- maxWidth = activePageSize.w - margins.left - margins.right;
85510
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
84975
85511
  } else {
84976
85512
  maxWidth = cols.width;
84977
85513
  }
@@ -85129,8 +85665,11 @@ ${l}
85129
85665
  throw new Error("layoutHeaderFooter: width must be positive");
85130
85666
  }
85131
85667
  if (!Number.isFinite(height) || height <= 0) {
85132
- throw new Error("layoutHeaderFooter: height must be positive");
85668
+ return { pages: [], height: 0 };
85133
85669
  }
85670
+ const maxBehindDocOverflow = Math.max(192, height * 4);
85671
+ const minBehindDocY = -maxBehindDocOverflow;
85672
+ const maxBehindDocY = height + maxBehindDocOverflow;
85134
85673
  const marginLeft = constraints.margins?.left ?? 0;
85135
85674
  const transformedBlocks = marginLeft > 0 ? blocks2.map((block) => {
85136
85675
  const hasPageRelativeAnchor = (block.kind === "image" || block.kind === "drawing") && block.anchor?.hRelativeFrom === "page" && block.anchor.offsetH != null;
@@ -85161,6 +85700,18 @@ ${l}
85161
85700
  if (idx == null) continue;
85162
85701
  const block = blocks2[idx];
85163
85702
  const measure = measures[idx];
85703
+ const isAnchoredFragment = (fragment.kind === "image" || fragment.kind === "drawing") && fragment.isAnchored === true;
85704
+ if (isAnchoredFragment) {
85705
+ if (block.kind !== "image" && block.kind !== "drawing") {
85706
+ throw new Error(
85707
+ `Type mismatch: fragment kind is ${fragment.kind} but block kind is ${block.kind} for block ${block.id}`
85708
+ );
85709
+ }
85710
+ const anchoredBlock = block;
85711
+ if (anchoredBlock.anchor?.behindDoc && (fragment.y < minBehindDocY || fragment.y > maxBehindDocY)) {
85712
+ continue;
85713
+ }
85714
+ }
85164
85715
  if (fragment.y < minY) minY = fragment.y;
85165
85716
  let bottom2 = fragment.y;
85166
85717
  if (fragment.kind === "para" && measure?.kind === "paragraph") {
@@ -86158,11 +86709,11 @@ ${l}
86158
86709
  if (text2.length === 0) return null;
86159
86710
  const clampedPos = Math.max(0, Math.min(localPos, text2.length));
86160
86711
  let wordStart = clampedPos;
86161
- while (wordStart > 0 && isWordChar(text2[wordStart - 1])) {
86712
+ while (wordStart > 0 && isWordChar$2(text2[wordStart - 1])) {
86162
86713
  wordStart--;
86163
86714
  }
86164
86715
  let wordEnd = clampedPos;
86165
- while (wordEnd < text2.length && isWordChar(text2[wordEnd])) {
86716
+ while (wordEnd < text2.length && isWordChar$2(text2[wordEnd])) {
86166
86717
  wordEnd++;
86167
86718
  }
86168
86719
  if (wordStart === wordEnd) {
@@ -86225,7 +86776,7 @@ ${l}
86225
86776
  }
86226
86777
  return null;
86227
86778
  }
86228
- function isWordChar(char) {
86779
+ function isWordChar$2(char) {
86229
86780
  return /[\p{L}\p{N}_]/u.test(char);
86230
86781
  }
86231
86782
  function isWhitespace$1(char) {
@@ -86260,6 +86811,29 @@ ${l}
86260
86811
  function runText(run2) {
86261
86812
  return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" || run2.kind === "fieldAnnotation" ? "" : run2.text ?? "";
86262
86813
  }
86814
+ const isWordChar$1 = (char) => {
86815
+ if (!char) return false;
86816
+ const code2 = char.charCodeAt(0);
86817
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
86818
+ };
86819
+ const capitalizeText$1 = (text2, fullText, startOffset) => {
86820
+ if (!text2) return text2;
86821
+ const hasFullText = typeof startOffset === "number" && fullText != null;
86822
+ let result = "";
86823
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
86824
+ const prevChar = hasFullText ? startOffset + i2 > 0 ? fullText[startOffset + i2 - 1] : "" : i2 > 0 ? text2[i2 - 1] : "";
86825
+ const ch = text2[i2];
86826
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
86827
+ }
86828
+ return result;
86829
+ };
86830
+ const applyTextTransform$1 = (text2, transform, fullText, startOffset) => {
86831
+ if (!text2 || !transform || transform === "none") return text2;
86832
+ if (transform === "uppercase") return text2.toUpperCase();
86833
+ if (transform === "lowercase") return text2.toLowerCase();
86834
+ if (transform === "capitalize") return capitalizeText$1(text2, fullText, startOffset);
86835
+ return text2;
86836
+ };
86263
86837
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
86264
86838
  const TWIPS_PER_INCH$4 = 1440;
86265
86839
  const PX_PER_INCH$3 = 96;
@@ -86268,6 +86842,13 @@ ${l}
86268
86842
  const WIDTH_FUDGE_PX = 0.5;
86269
86843
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
86270
86844
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
86845
+ const markerFontString = (run2) => {
86846
+ const size2 = run2?.fontSize ?? 16;
86847
+ const family = run2?.fontFamily ?? "Arial";
86848
+ const italic = run2?.italic ? "italic " : "";
86849
+ const bold = run2?.bold ? "bold " : "";
86850
+ return `${italic}${bold}${size2}px ${family}`.trim();
86851
+ };
86271
86852
  const buildTabStopsPx$1 = (indent2, tabs, tabIntervalTwips) => {
86272
86853
  const paragraphIndentTwips = {
86273
86854
  left: pxToTwips$1(Math.max(0, indent2?.left ?? 0)),
@@ -86298,7 +86879,9 @@ ${l}
86298
86879
  };
86299
86880
  function measureRunSliceWidth(run2, fromChar, toChar) {
86300
86881
  const context = getCtx();
86301
- const text2 = runText(run2).slice(fromChar, toChar);
86882
+ const fullText = runText(run2);
86883
+ const transform = isTextRun$2(run2) ? run2.textTransform : void 0;
86884
+ const text2 = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
86302
86885
  if (!context) {
86303
86886
  const textRun = isTextRun$2(run2) ? run2 : null;
86304
86887
  const size2 = textRun?.fontSize ?? 16;
@@ -86344,8 +86927,21 @@ ${l}
86344
86927
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
86345
86928
  const markerTextStartX = wordLayout?.marker?.textStartX;
86346
86929
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
86347
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
86348
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
86930
+ const resolvedTextStartPx = resolveListTextStartPx(
86931
+ wordLayout,
86932
+ indentLeft,
86933
+ indentFirstLine,
86934
+ indentHanging,
86935
+ (markerText, marker) => {
86936
+ const context = getCtx();
86937
+ if (!context) return 0;
86938
+ context.font = markerFontString(marker.run);
86939
+ return context.measureText(markerText).width;
86940
+ }
86941
+ );
86942
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
86943
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
86944
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
86349
86945
  const tabStops = buildTabStopsPx$1(indent2, attrs?.tabs, attrs?.tabIntervalTwips);
86350
86946
  let currentRun = 0;
86351
86947
  let currentChar = 0;
@@ -86885,7 +87481,7 @@ ${l}
86885
87481
  if (dirty.deletedBlockIds.length > 0) {
86886
87482
  measureCache.invalidate(dirty.deletedBlockIds);
86887
87483
  }
86888
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
87484
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
86889
87485
  if (measurementWidth <= 0 || measurementHeight <= 0) {
86890
87486
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
86891
87487
  }
@@ -86915,7 +87511,9 @@ ${l}
86915
87511
  `[Perf] 4.1 Measure all blocks: ${(measureEnd - measureStart).toFixed(2)}ms (${cacheMisses} measured, ${cacheHits} cached)`
86916
87512
  );
86917
87513
  let headerContentHeights;
86918
- if (headerFooter?.constraints && headerFooter.headerBlocks) {
87514
+ const hasHeaderBlocks = headerFooter?.headerBlocks && Object.keys(headerFooter.headerBlocks).length > 0;
87515
+ const hasHeaderBlocksByRId = headerFooter?.headerBlocksByRId && headerFooter.headerBlocksByRId.size > 0;
87516
+ if (headerFooter?.constraints && (hasHeaderBlocks || hasHeaderBlocksByRId)) {
86919
87517
  const hfPreStart = performance.now();
86920
87518
  const measureFn = headerFooter.measure ?? measureBlock2;
86921
87519
  invalidateHeaderFooterCache(
@@ -86927,25 +87525,45 @@ ${l}
86927
87525
  options.sectionMetadata
86928
87526
  );
86929
87527
  const HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
86930
- const preHeaderLayouts = await layoutHeaderFooterWithCache(
86931
- headerFooter.headerBlocks,
86932
- headerFooter.constraints,
86933
- measureFn,
86934
- headerMeasureCache,
86935
- HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
86936
- void 0
86937
- // No page resolver needed for height calculation
86938
- );
86939
87528
  const isValidHeaderType = (key2) => {
86940
87529
  return ["default", "first", "even", "odd"].includes(key2);
86941
87530
  };
86942
87531
  headerContentHeights = {};
86943
- for (const [type2, value] of Object.entries(preHeaderLayouts)) {
86944
- if (!isValidHeaderType(type2)) continue;
86945
- if (value?.layout && typeof value.layout.height === "number") {
86946
- const height = value.layout.height;
86947
- if (Number.isFinite(height) && height >= 0) {
86948
- headerContentHeights[type2] = height;
87532
+ if (hasHeaderBlocks && headerFooter.headerBlocks) {
87533
+ const preHeaderLayouts = await layoutHeaderFooterWithCache(
87534
+ headerFooter.headerBlocks,
87535
+ headerFooter.constraints,
87536
+ measureFn,
87537
+ headerMeasureCache,
87538
+ HEADER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
87539
+ void 0
87540
+ // No page resolver needed for height calculation
87541
+ );
87542
+ for (const [type2, value] of Object.entries(preHeaderLayouts)) {
87543
+ if (!isValidHeaderType(type2)) continue;
87544
+ if (value?.layout && typeof value.layout.height === "number") {
87545
+ const height = value.layout.height;
87546
+ if (Number.isFinite(height) && height >= 0) {
87547
+ headerContentHeights[type2] = height;
87548
+ }
87549
+ }
87550
+ }
87551
+ }
87552
+ if (hasHeaderBlocksByRId && headerFooter.headerBlocksByRId) {
87553
+ for (const [_rId, blocks2] of headerFooter.headerBlocksByRId) {
87554
+ if (!blocks2 || blocks2.length === 0) continue;
87555
+ const measureConstraints = {
87556
+ maxWidth: headerFooter.constraints.width,
87557
+ maxHeight: headerFooter.constraints.height
87558
+ };
87559
+ const measures2 = await Promise.all(blocks2.map((block) => measureFn(block, measureConstraints)));
87560
+ const layout2 = layoutHeaderFooter(blocks2, measures2, {
87561
+ width: headerFooter.constraints.width,
87562
+ height: headerFooter.constraints.height
87563
+ });
87564
+ if (layout2.height > 0) {
87565
+ const currentDefault = headerContentHeights.default ?? 0;
87566
+ headerContentHeights.default = Math.max(currentDefault, layout2.height);
86949
87567
  }
86950
87568
  }
86951
87569
  }
@@ -86953,10 +87571,12 @@ ${l}
86953
87571
  perfLog(`[Perf] 4.1.5 Pre-layout headers for height: ${(hfPreEnd - hfPreStart).toFixed(2)}ms`);
86954
87572
  }
86955
87573
  let footerContentHeights;
86956
- if (headerFooter?.constraints && headerFooter.footerBlocks) {
87574
+ const hasFooterBlocks = headerFooter?.footerBlocks && Object.keys(headerFooter.footerBlocks).length > 0;
87575
+ const hasFooterBlocksByRId = headerFooter?.footerBlocksByRId && headerFooter.footerBlocksByRId.size > 0;
87576
+ if (headerFooter?.constraints && (hasFooterBlocks || hasFooterBlocksByRId)) {
86957
87577
  const footerPreStart = performance.now();
86958
87578
  const measureFn = headerFooter.measure ?? measureBlock2;
86959
- if (!headerFooter.headerBlocks) {
87579
+ if (!hasHeaderBlocks && !hasHeaderBlocksByRId) {
86960
87580
  invalidateHeaderFooterCache(
86961
87581
  headerMeasureCache,
86962
87582
  headerFooterCacheState,
@@ -86967,26 +87587,46 @@ ${l}
86967
87587
  );
86968
87588
  }
86969
87589
  const FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT = 1;
87590
+ const isValidFooterType = (key2) => {
87591
+ return ["default", "first", "even", "odd"].includes(key2);
87592
+ };
87593
+ footerContentHeights = {};
86970
87594
  try {
86971
- const preFooterLayouts = await layoutHeaderFooterWithCache(
86972
- headerFooter.footerBlocks,
86973
- headerFooter.constraints,
86974
- measureFn,
86975
- headerMeasureCache,
86976
- FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
86977
- void 0
86978
- // No page resolver needed for height calculation
86979
- );
86980
- const isValidFooterType = (key2) => {
86981
- return ["default", "first", "even", "odd"].includes(key2);
86982
- };
86983
- footerContentHeights = {};
86984
- for (const [type2, value] of Object.entries(preFooterLayouts)) {
86985
- if (!isValidFooterType(type2)) continue;
86986
- if (value?.layout && typeof value.layout.height === "number") {
86987
- const height = value.layout.height;
86988
- if (Number.isFinite(height) && height >= 0) {
86989
- footerContentHeights[type2] = height;
87595
+ if (hasFooterBlocks && headerFooter.footerBlocks) {
87596
+ const preFooterLayouts = await layoutHeaderFooterWithCache(
87597
+ headerFooter.footerBlocks,
87598
+ headerFooter.constraints,
87599
+ measureFn,
87600
+ headerMeasureCache,
87601
+ FOOTER_PRELAYOUT_PLACEHOLDER_PAGE_COUNT,
87602
+ void 0
87603
+ // No page resolver needed for height calculation
87604
+ );
87605
+ for (const [type2, value] of Object.entries(preFooterLayouts)) {
87606
+ if (!isValidFooterType(type2)) continue;
87607
+ if (value?.layout && typeof value.layout.height === "number") {
87608
+ const height = value.layout.height;
87609
+ if (Number.isFinite(height) && height >= 0) {
87610
+ footerContentHeights[type2] = height;
87611
+ }
87612
+ }
87613
+ }
87614
+ }
87615
+ if (hasFooterBlocksByRId && headerFooter.footerBlocksByRId) {
87616
+ for (const [_rId, blocks2] of headerFooter.footerBlocksByRId) {
87617
+ if (!blocks2 || blocks2.length === 0) continue;
87618
+ const measureConstraints = {
87619
+ maxWidth: headerFooter.constraints.width,
87620
+ maxHeight: headerFooter.constraints.height
87621
+ };
87622
+ const measures2 = await Promise.all(blocks2.map((block) => measureFn(block, measureConstraints)));
87623
+ const layout2 = layoutHeaderFooter(blocks2, measures2, {
87624
+ width: headerFooter.constraints.width,
87625
+ height: headerFooter.constraints.height
87626
+ });
87627
+ if (layout2.height > 0) {
87628
+ const currentDefault = footerContentHeights.default ?? 0;
87629
+ footerContentHeights.default = Math.max(currentDefault, layout2.height);
86990
87630
  }
86991
87631
  }
86992
87632
  }
@@ -87154,7 +87794,7 @@ ${l}
87154
87794
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
87155
87795
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
87156
87796
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
87157
- function resolveMeasurementConstraints(options) {
87797
+ function resolveMeasurementConstraints(options, blocks2) {
87158
87798
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
87159
87799
  const margins = {
87160
87800
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -87162,23 +87802,41 @@ ${l}
87162
87802
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
87163
87803
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
87164
87804
  };
87165
- const contentWidth = pageSize.w - (margins.left + margins.right);
87166
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
87167
- const columns = options.columns;
87168
- if (columns && columns.count > 1) {
87805
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
87806
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
87807
+ const computeColumnWidth = (contentWidth, columns) => {
87808
+ if (!columns || columns.count <= 1) return contentWidth;
87169
87809
  const gap = Math.max(0, columns.gap ?? 0);
87170
87810
  const totalGap = gap * (columns.count - 1);
87171
- const columnWidth = (contentWidth - totalGap) / columns.count;
87172
- if (columnWidth > 0) {
87173
- return {
87174
- measurementWidth: columnWidth,
87175
- measurementHeight: contentHeight
87811
+ return (contentWidth - totalGap) / columns.count;
87812
+ };
87813
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
87814
+ let measurementHeight = baseContentHeight;
87815
+ if (blocks2 && blocks2.length > 0) {
87816
+ for (const block of blocks2) {
87817
+ if (block.kind !== "sectionBreak") continue;
87818
+ const sectionPageSize = block.pageSize ?? pageSize;
87819
+ const sectionMargins = {
87820
+ top: normalizeMargin(block.margins?.top, margins.top),
87821
+ right: normalizeMargin(block.margins?.right, margins.right),
87822
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
87823
+ left: normalizeMargin(block.margins?.left, margins.left)
87176
87824
  };
87825
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
87826
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
87827
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
87828
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
87829
+ if (columnWidth > measurementWidth) {
87830
+ measurementWidth = columnWidth;
87831
+ }
87832
+ if (contentHeight > measurementHeight) {
87833
+ measurementHeight = contentHeight;
87834
+ }
87177
87835
  }
87178
87836
  }
87179
87837
  return {
87180
- measurementWidth: contentWidth,
87181
- measurementHeight: contentHeight
87838
+ measurementWidth,
87839
+ measurementHeight
87182
87840
  };
87183
87841
  }
87184
87842
  const serializeHeaderFooterResults = (kind, batch2) => {
@@ -89568,14 +90226,15 @@ ${l}
89568
90226
  if (!schema) return [];
89569
90227
  const types2 = [];
89570
90228
  try {
89571
- schema.nodes.forEach((nodeType, name) => {
90229
+ for (const name in schema.nodes) {
89572
90230
  if (name === "text") {
89573
- return;
90231
+ continue;
89574
90232
  }
89575
- if (nodeType.isAtom || nodeType.isLeaf) {
90233
+ const nodeType = schema.nodes[name];
90234
+ if (nodeType && (nodeType.isAtom || nodeType.isLeaf)) {
89576
90235
  types2.push(name);
89577
90236
  }
89578
- });
90237
+ }
89579
90238
  } catch {
89580
90239
  return [];
89581
90240
  }
@@ -90978,6 +91637,7 @@ ${l}
90978
91637
  function hasIntrinsicBoundarySignals(_2) {
90979
91638
  return false;
90980
91639
  }
91640
+ const DEFAULT_HEADER_FOOTER_MARGIN_PX = 0;
90981
91641
  function shouldIgnoreSectionBreak(paragraph2, index2, total, hasBodySectPr) {
90982
91642
  const paragraphAttrs = paragraph2.attrs ?? {};
90983
91643
  const paragraphProperties = paragraphAttrs?.paragraphProperties;
@@ -91018,14 +91678,15 @@ ${l}
91018
91678
  const sectionData = extractSectionData(item.node);
91019
91679
  if (!sectionData) return;
91020
91680
  const sectPr = getSectPrFromNode(item.node);
91681
+ const hasAnyMargin = sectionData.headerPx != null || sectionData.footerPx != null || sectionData.topPx != null || sectionData.rightPx != null || sectionData.bottomPx != null || sectionData.leftPx != null;
91021
91682
  const range2 = {
91022
91683
  sectionIndex: idx,
91023
91684
  startParagraphIndex: currentStart,
91024
91685
  endParagraphIndex: item.index,
91025
91686
  sectPr,
91026
- margins: sectionData.headerPx != null || sectionData.footerPx != null ? {
91027
- header: sectionData.headerPx ?? 0,
91028
- footer: sectionData.footerPx ?? 0,
91687
+ margins: hasAnyMargin ? {
91688
+ header: sectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
91689
+ footer: sectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
91029
91690
  top: sectionData.topPx,
91030
91691
  right: sectionData.rightPx,
91031
91692
  bottom: sectionData.bottomPx,
@@ -91067,14 +91728,15 @@ ${l}
91067
91728
  };
91068
91729
  const bodySectionData = extractSectionData(tempNode);
91069
91730
  if (!bodySectionData) return null;
91731
+ const hasAnyMargin = bodySectionData.headerPx != null || bodySectionData.footerPx != null || bodySectionData.topPx != null || bodySectionData.rightPx != null || bodySectionData.bottomPx != null || bodySectionData.leftPx != null;
91070
91732
  return {
91071
91733
  sectionIndex,
91072
91734
  startParagraphIndex: currentStart,
91073
91735
  endParagraphIndex: totalParagraphs - 1,
91074
91736
  sectPr: bodySectPr,
91075
- margins: bodySectionData.headerPx != null || bodySectionData.footerPx != null ? {
91076
- header: bodySectionData.headerPx ?? 0,
91077
- footer: bodySectionData.footerPx ?? 0,
91737
+ margins: hasAnyMargin ? {
91738
+ header: bodySectionData.headerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
91739
+ footer: bodySectionData.footerPx ?? DEFAULT_HEADER_FOOTER_MARGIN_PX,
91078
91740
  top: bodySectionData.topPx,
91079
91741
  right: bodySectionData.rightPx,
91080
91742
  bottom: bodySectionData.bottomPx,
@@ -92058,11 +92720,27 @@ ${l}
92058
92720
  }, void 0);
92059
92721
  };
92060
92722
  const normalizeUnderlineStyle = (value) => {
92061
- if (value === "none") {
92062
- return void 0;
92723
+ if (value === void 0 || value === null) {
92724
+ return "single";
92063
92725
  }
92064
- if (value === "double" || value === "dotted" || value === "dashed" || value === "wavy") {
92065
- return value;
92726
+ if (typeof value === "boolean") {
92727
+ return value ? "single" : void 0;
92728
+ }
92729
+ if (typeof value === "number") {
92730
+ return value === 0 ? void 0 : "single";
92731
+ }
92732
+ if (typeof value === "string") {
92733
+ const normalized = value.trim().toLowerCase();
92734
+ if (!normalized) {
92735
+ return "single";
92736
+ }
92737
+ if (normalized === "none" || normalized === "0" || normalized === "false" || normalized === "off") {
92738
+ return void 0;
92739
+ }
92740
+ if (normalized === "double" || normalized === "dotted" || normalized === "dashed" || normalized === "wavy") {
92741
+ return normalized;
92742
+ }
92743
+ return "single";
92066
92744
  }
92067
92745
  return "single";
92068
92746
  };
@@ -92214,13 +92892,16 @@ ${l}
92214
92892
  break;
92215
92893
  }
92216
92894
  case "underline": {
92217
- const style2 = normalizeUnderlineStyle(mark2.attrs?.underlineType);
92895
+ const underlineValue = mark2.attrs?.underlineType ?? mark2.attrs?.value ?? mark2.attrs?.underline ?? mark2.attrs?.style;
92896
+ const style2 = normalizeUnderlineStyle(underlineValue);
92218
92897
  if (style2) {
92219
92898
  const underlineColor = resolveColorFromAttributes(mark2.attrs ?? {}, themeColors);
92220
92899
  run2.underline = {
92221
92900
  style: style2,
92222
92901
  color: underlineColor ?? run2.underline?.color
92223
92902
  };
92903
+ } else if (underlineValue !== void 0 && underlineValue !== null) {
92904
+ delete run2.underline;
92224
92905
  }
92225
92906
  break;
92226
92907
  }
@@ -93156,8 +93837,8 @@ ${l}
93156
93837
  }
93157
93838
  return void 0;
93158
93839
  }
93159
- const DEFAULT_LIST_HANGING_PX$1 = 18;
93160
- const LIST_MARKER_GAP$1 = 8;
93840
+ const DEFAULT_LIST_HANGING_PX = 18;
93841
+ const LIST_MARKER_GAP = 8;
93161
93842
  const DEFAULT_BULLET_GLYPH = "•";
93162
93843
  const DEFAULT_DECIMAL_PATTERN = "%1.";
93163
93844
  const ASCII_UPPERCASE_A = 65;
@@ -93568,7 +94249,7 @@ ${l}
93568
94249
  let markerBoxWidthPx;
93569
94250
  let markerX;
93570
94251
  if (hasFirstLineIndent) {
93571
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
94252
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
93572
94253
  markerX = indentLeftPx + (firstLinePx ?? 0);
93573
94254
  layout.textStartPx = markerX + markerBoxWidthPx;
93574
94255
  layout.hangingPx = 0;
@@ -93668,12 +94349,12 @@ ${l}
93668
94349
  let markerBox = Math.max(hangingPxRaw || 0, 0);
93669
94350
  if (markerBox <= 0) {
93670
94351
  if (glyphWidthPx != null && glyphWidthPx > 0) {
93671
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
94352
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
93672
94353
  } else {
93673
- markerBox = DEFAULT_LIST_HANGING_PX$1;
94354
+ markerBox = DEFAULT_LIST_HANGING_PX;
93674
94355
  }
93675
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
93676
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
94356
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
94357
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
93677
94358
  }
93678
94359
  return markerBox;
93679
94360
  };
@@ -93693,7 +94374,7 @@ ${l}
93693
94374
  textStartX: textStartPx,
93694
94375
  baselineOffsetPx: markerRun.baselineShift ?? 0,
93695
94376
  // Gutter is the small gap between marker and text, not the full marker box width
93696
- gutterWidthPx: LIST_MARKER_GAP$1,
94377
+ gutterWidthPx: LIST_MARKER_GAP,
93697
94378
  justification: numbering.lvlJc ?? "left",
93698
94379
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
93699
94380
  run: markerRun,
@@ -93783,7 +94464,10 @@ ${l}
93783
94464
  tabStops: cloneIfObject(resolvedExtended.tabStops),
93784
94465
  keepLines: resolvedExtended.keepLines,
93785
94466
  keepNext: resolvedExtended.keepNext,
93786
- numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties)
94467
+ numberingProperties: cloneIfObject(resolvedAsRecord.numberingProperties),
94468
+ // Extract contextualSpacing from style resolution - this is a sibling to spacing in OOXML,
94469
+ // not nested within it. When true, suppresses spacing between paragraphs of the same style.
94470
+ contextualSpacing: resolvedExtended.contextualSpacing
93787
94471
  };
93788
94472
  return hydrated;
93789
94473
  };
@@ -94385,6 +95069,31 @@ ${l}
94385
95069
  return null;
94386
95070
  }
94387
95071
  };
95072
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
95073
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
95074
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
95075
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
95076
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
95077
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
95078
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
95079
+ wordLayout.firstLineIndentMode = false;
95080
+ }
95081
+ if (wordLayout.firstLineIndentMode === true) {
95082
+ if (isFiniteNumber(wordLayout.textStartPx)) {
95083
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
95084
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
95085
+ }
95086
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
95087
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
95088
+ }
95089
+ } else {
95090
+ wordLayout.textStartPx = indentLeft;
95091
+ if (wordLayout.marker) {
95092
+ wordLayout.marker.textStartX = indentLeft;
95093
+ }
95094
+ }
95095
+ return wordLayout;
95096
+ };
94388
95097
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
94389
95098
  const attrs = para.attrs ?? {};
94390
95099
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -94493,7 +95202,7 @@ ${l}
94493
95202
  paragraphAttrs.spacing.afterAutospacing = normalizedSpacing.afterAutospacing;
94494
95203
  }
94495
95204
  }
94496
- const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing");
95205
+ const contextualSpacingValue = normalizedSpacing?.contextualSpacing ?? safeGetProperty(paragraphProps, "contextualSpacing") ?? safeGetProperty(attrs, "contextualSpacing") ?? hydrated?.contextualSpacing;
94497
95206
  if (contextualSpacingValue != null) {
94498
95207
  paragraphAttrs.contextualSpacing = isTruthy(contextualSpacingValue);
94499
95208
  }
@@ -94707,8 +95416,11 @@ ${l}
94707
95416
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
94708
95417
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
94709
95418
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
94710
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
94711
- if (firstLinePx > 0) {
95419
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
95420
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
95421
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
95422
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
95423
+ if (firstLinePx > 0 && !hangingPx) {
94712
95424
  wordLayout = {
94713
95425
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
94714
95426
  firstLineIndentMode: true,
@@ -94716,10 +95428,13 @@ ${l}
94716
95428
  };
94717
95429
  }
94718
95430
  }
94719
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
95431
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
94720
95432
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
94721
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
94722
- if (firstLinePx > 0) {
95433
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
95434
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
95435
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
95436
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
95437
+ if (firstLinePx > 0 && !hangingPx) {
94723
95438
  wordLayout = {
94724
95439
  ...wordLayout,
94725
95440
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -94739,6 +95454,7 @@ ${l}
94739
95454
  wordLayout.marker.suffix = listRendering.suffix;
94740
95455
  }
94741
95456
  }
95457
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
94742
95458
  paragraphAttrs.wordLayout = wordLayout;
94743
95459
  }
94744
95460
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -98855,11 +99571,6 @@ ${l}
98855
99571
  cleanups
98856
99572
  };
98857
99573
  }
98858
- const LIST_MARKER_GAP = 8;
98859
- const MIN_MARKER_GUTTER = 24;
98860
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
98861
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
98862
- const DEFAULT_LIST_HANGING_PX = 18;
98863
99574
  function calculateRotatedBounds(input2) {
98864
99575
  const width = Math.max(0, input2.width);
98865
99576
  const height = Math.max(0, input2.height);
@@ -99029,7 +99740,7 @@ ${l}
99029
99740
  return Math.max(advanceWidth, paintedWidth);
99030
99741
  }
99031
99742
  const MIN_SINGLE_LINE_PX = 12 * 96 / 72;
99032
- const LINE_HEIGHT_SAFETY_MARGIN_PX = 1;
99743
+ const WORD_SINGLE_LINE_SPACING_MULTIPLIER = 1.15;
99033
99744
  function calculateTypographyMetrics(fontSize2, spacing, fontInfo) {
99034
99745
  let ascent;
99035
99746
  let descent;
@@ -99042,7 +99753,7 @@ ${l}
99042
99753
  ascent = roundValue(fontSize2 * 0.8);
99043
99754
  descent = roundValue(fontSize2 * 0.2);
99044
99755
  }
99045
- const baseLineHeight = Math.max(ascent + descent + LINE_HEIGHT_SAFETY_MARGIN_PX, MIN_SINGLE_LINE_PX);
99756
+ const baseLineHeight = Math.max(fontSize2 * WORD_SINGLE_LINE_SPACING_MULTIPLIER, ascent + descent, MIN_SINGLE_LINE_PX);
99046
99757
  const lineHeight2 = roundValue(resolveLineHeight(spacing, baseLineHeight));
99047
99758
  return {
99048
99759
  ascent,
@@ -99123,8 +99834,25 @@ ${l}
99123
99834
  const rawTextStartPx = wordLayout?.textStartPx;
99124
99835
  const markerTextStartX = wordLayout?.marker?.textStartX;
99125
99836
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
99126
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
99127
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
99837
+ const resolvedTextStartPx = resolveListTextStartPx(
99838
+ wordLayout,
99839
+ indentLeft,
99840
+ firstLine,
99841
+ hanging,
99842
+ (markerText, marker) => {
99843
+ const markerRun = {
99844
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
99845
+ fontSize: marker.run?.fontSize ?? 16,
99846
+ bold: marker.run?.bold ?? false,
99847
+ italic: marker.run?.italic ?? false
99848
+ };
99849
+ const { font: markerFont } = buildFontString(markerRun);
99850
+ return measureText(markerText, markerFont, ctx2);
99851
+ }
99852
+ );
99853
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
99854
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
99855
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
99128
99856
  } else {
99129
99857
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
99130
99858
  }
@@ -99211,7 +99939,7 @@ ${l}
99211
99939
  pendingTabAlignment = null;
99212
99940
  return startX;
99213
99941
  };
99214
- const alignSegmentAtTab = (segmentText, font, runContext) => {
99942
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
99215
99943
  if (!pendingTabAlignment || !currentLine) return void 0;
99216
99944
  const { val } = pendingTabAlignment;
99217
99945
  let segmentWidth = 0;
@@ -99220,11 +99948,11 @@ ${l}
99220
99948
  const idx = segmentText.indexOf(decimalSeparator);
99221
99949
  if (idx >= 0) {
99222
99950
  const beforeText = segmentText.slice(0, idx);
99223
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
99951
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
99224
99952
  }
99225
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
99953
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
99226
99954
  } else if (val === "end" || val === "center") {
99227
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
99955
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
99228
99956
  }
99229
99957
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
99230
99958
  };
@@ -99276,8 +100004,8 @@ ${l}
99276
100004
  const { font } = buildFontString(
99277
100005
  lastRun
99278
100006
  );
99279
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
99280
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
100007
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
100008
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
99281
100009
  const delta = Math.max(0, fullWidth - keptWidth);
99282
100010
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
99283
100011
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -99488,7 +100216,8 @@ ${l}
99488
100216
  continue;
99489
100217
  }
99490
100218
  if (isFieldAnnotationRun(run2)) {
99491
- const displayText = run2.displayLabel || "";
100219
+ const rawDisplayText = run2.displayLabel || "";
100220
+ const displayText = applyTextTransform(rawDisplayText, run2);
99492
100221
  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;
99493
100222
  const annotationFontFamily = run2.fontFamily || "Arial, sans-serif";
99494
100223
  const fontWeight = run2.bold ? "bold" : "normal";
@@ -99591,7 +100320,7 @@ ${l}
99591
100320
  const spacesLength = segment.length;
99592
100321
  const spacesStartChar = charPosInRun;
99593
100322
  const spacesEndChar = charPosInRun + spacesLength;
99594
- const spacesWidth = measureRunWidth(segment, font, ctx2, run2);
100323
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run2, spacesStartChar);
99595
100324
  if (!currentLine) {
99596
100325
  currentLine = {
99597
100326
  fromRun: runIndex,
@@ -99655,7 +100384,7 @@ ${l}
99655
100384
  }
99656
100385
  let segmentStartX;
99657
100386
  if (currentLine && pendingTabAlignment) {
99658
- segmentStartX = alignSegmentAtTab(segment, font, run2);
100387
+ segmentStartX = alignSegmentAtTab(segment, font, run2, charPosInRun);
99659
100388
  if (segmentStartX == null) {
99660
100389
  segmentStartX = currentLine.width;
99661
100390
  }
@@ -99665,7 +100394,7 @@ ${l}
99665
100394
  if (word2 === "") {
99666
100395
  const spaceStartChar = charPosInRun;
99667
100396
  const spaceEndChar = charPosInRun + 1;
99668
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2);
100397
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run2, spaceStartChar);
99669
100398
  if (!currentLine) {
99670
100399
  currentLine = {
99671
100400
  fromRun: runIndex,
@@ -99716,12 +100445,12 @@ ${l}
99716
100445
  charPosInRun = spaceEndChar;
99717
100446
  continue;
99718
100447
  }
99719
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2);
99720
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
99721
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2) : 0;
99722
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
99723
100448
  const wordStartChar = charPosInRun;
100449
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run2, wordStartChar);
100450
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
99724
100451
  const wordEndNoSpace = charPosInRun + word2.length;
100452
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) : 0;
100453
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
99725
100454
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
99726
100455
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
99727
100456
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -99740,7 +100469,7 @@ ${l}
99740
100469
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
99741
100470
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
99742
100471
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
99743
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2);
100472
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run2, wordStartChar);
99744
100473
  let chunkCharOffset = wordStartChar;
99745
100474
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
99746
100475
  const chunk = chunks[chunkIndex];
@@ -99842,6 +100571,10 @@ ${l}
99842
100571
  currentLine.width = roundValue(currentLine.width + spaceWidth + ls);
99843
100572
  charPosInRun = wordEndWithSpace;
99844
100573
  currentLine.spaceCount += 1;
100574
+ if (currentLine.segments?.[0]) {
100575
+ currentLine.segments[0].toChar = wordEndWithSpace;
100576
+ currentLine.segments[0].width += spaceWidth;
100577
+ }
99845
100578
  } else {
99846
100579
  charPosInRun = wordEndWithSpace;
99847
100580
  }
@@ -99864,7 +100597,7 @@ ${l}
99864
100597
  if (candidateSpaces > 0) {
99865
100598
  const overflow = totalWidthWithWord - availableWidth;
99866
100599
  if (overflow > 0) {
99867
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2) || Math.max(1, boundarySpacing);
100600
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run2, wordEndNoSpace) || Math.max(1, boundarySpacing);
99868
100601
  const perSpaceCompression = overflow / candidateSpaces;
99869
100602
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
99870
100603
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -99904,6 +100637,10 @@ ${l}
99904
100637
  currentLine.width = roundValue(currentLine.width + spaceWidth + (run2.letterSpacing ?? 0));
99905
100638
  charPosInRun = wordEndWithSpace;
99906
100639
  currentLine.spaceCount += 1;
100640
+ if (currentLine.segments?.[0]) {
100641
+ currentLine.segments[0].toChar = wordEndWithSpace;
100642
+ currentLine.segments[0].width += spaceWidth;
100643
+ }
99907
100644
  } else {
99908
100645
  charPosInRun = wordEndWithSpace;
99909
100646
  }
@@ -100039,8 +100776,8 @@ ${l}
100039
100776
  const { font: markerFont } = buildFontString(markerRun);
100040
100777
  const markerText = wordLayout.marker.markerText ?? "";
100041
100778
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
100042
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
100043
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
100779
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
100780
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
100044
100781
  markerInfo = {
100045
100782
  markerWidth: markerBoxWidth,
100046
100783
  markerTextWidth: glyphWidth,
@@ -100384,7 +101121,7 @@ ${l}
100384
101121
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
100385
101122
  indentLeft = resolveIndentLeft(item);
100386
101123
  const indentHanging = resolveIndentHanging(item);
100387
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
101124
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
100388
101125
  }
100389
101126
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
100390
101127
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -100410,16 +101147,46 @@ ${l}
100410
101147
  fontSize: 16
100411
101148
  };
100412
101149
  };
100413
- const measureRunWidth = (text2, font, ctx2, run2) => {
101150
+ const isWordChar = (char) => {
101151
+ if (!char) return false;
101152
+ const code2 = char.charCodeAt(0);
101153
+ return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122 || char === "'";
101154
+ };
101155
+ const capitalizeText = (text2, fullText, startOffset) => {
101156
+ if (!text2) return text2;
101157
+ const hasFullText = typeof startOffset === "number" && fullText != null;
101158
+ let result = "";
101159
+ for (let i2 = 0; i2 < text2.length; i2 += 1) {
101160
+ const prevChar = hasFullText ? startOffset + i2 > 0 ? fullText[startOffset + i2 - 1] : "" : i2 > 0 ? text2[i2 - 1] : "";
101161
+ const ch = text2[i2];
101162
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
101163
+ }
101164
+ return result;
101165
+ };
101166
+ const applyTextTransform = (text2, run2, startOffset) => {
101167
+ const transform = "textTransform" in run2 ? run2.textTransform : void 0;
101168
+ if (!text2 || !transform || transform === "none") return text2;
101169
+ if (transform === "uppercase") return text2.toUpperCase();
101170
+ if (transform === "lowercase") return text2.toLowerCase();
101171
+ if (transform === "capitalize") {
101172
+ const fullText = "text" in run2 && typeof run2.text === "string" ? run2.text : text2;
101173
+ return capitalizeText(text2, fullText, startOffset);
101174
+ }
101175
+ return text2;
101176
+ };
101177
+ const measureRunWidth = (text2, font, ctx2, run2, startOffset) => {
100414
101178
  const letterSpacing = run2.kind === "text" || run2.kind === void 0 ? run2.letterSpacing || 0 : 0;
100415
- const width = getMeasuredTextWidth(text2, font, letterSpacing, ctx2);
101179
+ const displayText = applyTextTransform(text2, run2, startOffset);
101180
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
100416
101181
  return roundValue(width);
100417
101182
  };
100418
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2) => {
101183
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run2, startOffset) => {
100419
101184
  const chunks = [];
101185
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
100420
101186
  if (maxWidth <= 0) {
100421
- for (const char of word2) {
100422
- const charWidth = measureRunWidth(char, font, ctx2, run2);
101187
+ for (let i2 = 0; i2 < word2.length; i2++) {
101188
+ const char = word2[i2];
101189
+ const charWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i2);
100423
101190
  chunks.push({ text: char, width: charWidth });
100424
101191
  }
100425
101192
  return chunks;
@@ -100429,11 +101196,11 @@ ${l}
100429
101196
  for (let i2 = 0; i2 < word2.length; i2++) {
100430
101197
  const char = word2[i2];
100431
101198
  const testChunk = currentChunk + char;
100432
- const testWidth = measureRunWidth(testChunk, font, ctx2, run2);
101199
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run2, baseOffset);
100433
101200
  if (testWidth > maxWidth && currentChunk.length > 0) {
100434
101201
  chunks.push({ text: currentChunk, width: currentWidth });
100435
101202
  currentChunk = char;
100436
- currentWidth = measureRunWidth(char, font, ctx2, run2);
101203
+ currentWidth = measureRunWidth(char, font, ctx2, run2, baseOffset + i2);
100437
101204
  } else {
100438
101205
  currentChunk = testChunk;
100439
101206
  currentWidth = testWidth;
@@ -100487,12 +101254,13 @@ ${l}
100487
101254
  italic: run2.italic
100488
101255
  });
100489
101256
  ctx2.font = font;
100490
- const metrics = ctx2.measureText(run2.text);
101257
+ const displayText = applyTextTransform(run2.text, run2);
101258
+ const metrics = ctx2.measureText(displayText);
100491
101259
  const advanceWidth = metrics.width;
100492
101260
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
100493
101261
  const textWidth = Math.max(advanceWidth, paintedWidth);
100494
101262
  const width = roundValue(textWidth + DROP_CAP_PADDING_PX);
100495
- const baseLineHeight = resolveLineHeight(spacing, run2.fontSize * 1.2);
101263
+ const baseLineHeight = resolveLineHeight(spacing, run2.fontSize * WORD_SINGLE_LINE_SPACING_MULTIPLIER);
100496
101264
  const height = roundValue(baseLineHeight * lines);
100497
101265
  return {
100498
101266
  width,
@@ -100513,7 +101281,7 @@ ${l}
100513
101281
  if (indentHanging > 0) {
100514
101282
  return indentHanging;
100515
101283
  }
100516
- return DEFAULT_LIST_HANGING_PX;
101284
+ return DEFAULT_LIST_HANGING_PX$1;
100517
101285
  };
100518
101286
  const buildTabStopsPx = (indent2, tabs, tabIntervalTwips) => {
100519
101287
  const paragraphIndentTwips = {
@@ -100719,6 +101487,9 @@ ${l}
100719
101487
  if (event.button !== 0) {
100720
101488
  return;
100721
101489
  }
101490
+ if (event.ctrlKey && navigator.platform.includes("Mac")) {
101491
+ return;
101492
+ }
100722
101493
  __privateSet(this, _pendingMarginClick, null);
100723
101494
  const target = event.target;
100724
101495
  if (target?.closest?.(".superdoc-ruler-handle") != null) {
@@ -101215,6 +101986,10 @@ ${l}
101215
101986
  __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
101216
101987
  return;
101217
101988
  }
101989
+ if (__privateGet$1(this, _documentMode) === "viewing") {
101990
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
101991
+ return;
101992
+ }
101218
101993
  const region = __privateMethod$1(this, _PresentationEditor_instances, hitTestHeaderFooterRegion_fn).call(this, normalized.x, normalized.y);
101219
101994
  if (!region) {
101220
101995
  __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
@@ -101443,6 +102218,7 @@ ${l}
101443
102218
  __privateSet(this, _visibleHost, options.element);
101444
102219
  __privateGet$1(this, _visibleHost).innerHTML = "";
101445
102220
  __privateGet$1(this, _visibleHost).classList.add("presentation-editor");
102221
+ __privateMethod$1(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
101446
102222
  if (!__privateGet$1(this, _visibleHost).hasAttribute("tabindex")) {
101447
102223
  __privateGet$1(this, _visibleHost).tabIndex = 0;
101448
102224
  }
@@ -101938,6 +102714,7 @@ ${l}
101938
102714
  }
101939
102715
  __privateSet(this, _documentMode, mode);
101940
102716
  __privateGet$1(this, _editor3).setDocumentMode(mode);
102717
+ __privateMethod$1(this, _PresentationEditor_instances, syncDocumentModeClass_fn).call(this);
101941
102718
  __privateMethod$1(this, _PresentationEditor_instances, syncHiddenEditorA11yAttributes_fn).call(this);
101942
102719
  const trackedChangesChanged = __privateMethod$1(this, _PresentationEditor_instances, syncTrackedChangesPreferences_fn).call(this);
101943
102720
  if (trackedChangesChanged) {
@@ -102848,6 +103625,10 @@ ${l}
102848
103625
  }
102849
103626
  };
102850
103627
  };
103628
+ syncDocumentModeClass_fn = function() {
103629
+ if (!__privateGet$1(this, _visibleHost)) return;
103630
+ __privateGet$1(this, _visibleHost).classList.toggle("presentation-editor--viewing", __privateGet$1(this, _documentMode) === "viewing");
103631
+ };
102851
103632
  collectCommentPositions_fn = function() {
102852
103633
  return collectCommentPositions(__privateGet$1(this, _editor3)?.state?.doc ?? null, {
102853
103634
  commentMarkName: CommentMarkName,
@@ -103481,7 +104262,7 @@ ${l}
103481
104262
  const atomNodeTypes = getAtomNodeTypes(__privateGet$1(this, _editor3)?.schema ?? null);
103482
104263
  const positionMap2 = __privateGet$1(this, _editor3)?.state?.doc && docJson ? buildPositionMapFromPmDoc(__privateGet$1(this, _editor3).state.doc, docJson) : null;
103483
104264
  const result = toFlowBlocks(docJson, {
103484
- mediaFiles: __privateGet$1(this, _options).mediaFiles,
104265
+ mediaFiles: __privateGet$1(this, _editor3)?.storage?.image?.media,
103485
104266
  emitSectionBreaks: true,
103486
104267
  sectionMetadata,
103487
104268
  trackedChangesMode: __privateGet$1(this, _trackedChangesMode),
@@ -103805,7 +104586,14 @@ ${l}
103805
104586
  const footerMargin = margins.footer ?? 0;
103806
104587
  const headerContentSpace = Math.max(marginTop - headerMargin, 0);
103807
104588
  const footerContentSpace = Math.max(marginBottom - footerMargin, 0);
103808
- const height = Math.max(headerContentSpace, footerContentSpace, 1);
104589
+ const height = Math.max(
104590
+ headerContentSpace,
104591
+ footerContentSpace,
104592
+ headerMargin,
104593
+ footerMargin,
104594
+ marginTop,
104595
+ marginBottom
104596
+ );
103809
104597
  return {
103810
104598
  width: measurementWidth,
103811
104599
  height,
@@ -103955,7 +104743,8 @@ ${l}
103955
104743
  const headerMargin = margins.header ?? 0;
103956
104744
  const topMargin = margins.top ?? DEFAULT_MARGINS.top ?? 0;
103957
104745
  const height = Math.max(topMargin - headerMargin, 1);
103958
- return { x: left2, width, height, offset: headerMargin };
104746
+ const offset2 = headerMargin;
104747
+ return { x: left2, width, height, offset: offset2 };
103959
104748
  } else {
103960
104749
  const footerMargin = margins.footer ?? 0;
103961
104750
  const bottomMargin = margins.bottom ?? DEFAULT_MARGINS.bottom ?? 0;
@@ -104548,6 +105337,10 @@ ${l}
104548
105337
  });
104549
105338
  };
104550
105339
  renderHoverRegion_fn = function(region) {
105340
+ if (__privateGet$1(this, _documentMode) === "viewing") {
105341
+ __privateMethod$1(this, _PresentationEditor_instances, clearHoverRegion_fn).call(this);
105342
+ return;
105343
+ }
104551
105344
  if (!__privateGet$1(this, _hoverOverlay) || !__privateGet$1(this, _hoverTooltip)) return;
104552
105345
  const coords = __privateMethod$1(this, _PresentationEditor_instances, convertPageLocalToOverlayCoords_fn).call(this, region.pageIndex, region.localX, region.localY);
104553
105346
  if (!coords) {
@@ -106128,6 +106921,8 @@ ${l}
106128
106921
  const cbRect = containingBlock.getBoundingClientRect();
106129
106922
  left2 -= cbRect.left;
106130
106923
  top2 -= cbRect.top;
106924
+ left2 += containingBlock.scrollLeft || 0;
106925
+ top2 += containingBlock.scrollTop || 0;
106131
106926
  } catch (error) {
106132
106927
  console.warn("SlashMenu: Failed to adjust for containing block", error);
106133
106928
  }
@@ -122035,7 +122830,7 @@ ${l}
122035
122830
  document.addEventListener("mousedown", globalMousedownHandler);
122036
122831
  scrollHandler = () => {
122037
122832
  if (currentWrapper && resizeContainer) {
122038
- updateHandlePositions(currentWrapper.firstElementChild);
122833
+ updateHandlePositions(currentWrapper);
122039
122834
  }
122040
122835
  };
122041
122836
  window.addEventListener("scroll", scrollHandler, true);
@@ -122097,7 +122892,7 @@ ${l}
122097
122892
  }
122098
122893
  applyStyleIsolationClass(resizeContainer);
122099
122894
  document.body.appendChild(resizeContainer);
122100
- updateHandlePositions(wrapper.firstElementChild);
122895
+ updateHandlePositions(wrapper);
122101
122896
  }
122102
122897
  function hideResizeHandles() {
122103
122898
  if (resizeContainer?.parentNode) {
@@ -137466,7 +138261,7 @@ ${style2}
137466
138261
  if (open) {
137467
138262
  nextTick(() => {
137468
138263
  if (searchInput.value) {
137469
- searchInput.value.focus();
138264
+ searchInput.value.focus({ preventScroll: true });
137470
138265
  }
137471
138266
  });
137472
138267
  }
@@ -137571,7 +138366,11 @@ ${style2}
137571
138366
  };
137572
138367
  const handleGlobalOutsideClick = (event) => {
137573
138368
  if (isOpen.value && menuRef.value && !menuRef.value.contains(event.target)) {
137574
- moveCursorToMouseEvent(event, props.editor);
138369
+ const isCtrlClickOnMac = event.ctrlKey && isMacOS();
138370
+ const isLeftClick = event.button === 0 && !isCtrlClickOnMac;
138371
+ if (isLeftClick) {
138372
+ moveCursorToMouseEvent(event, props.editor);
138373
+ }
137575
138374
  closeMenu({ restoreCursor: false });
137576
138375
  }
137577
138376
  };
@@ -139666,6 +140465,12 @@ ${style2}
139666
140465
  if (props.options?.suppressSkeletonLoader || !props.options?.collaborationProvider) editorReady.value = true;
139667
140466
  });
139668
140467
  const handleMarginClick = (event) => {
140468
+ if (event.button !== 0) {
140469
+ return;
140470
+ }
140471
+ if (event.ctrlKey && isMacOS()) {
140472
+ return;
140473
+ }
139669
140474
  if (event.target.classList.contains("ProseMirror")) return;
139670
140475
  onMarginClickCursorChange(event, activeEditor.value);
139671
140476
  };
@@ -139804,7 +140609,7 @@ ${style2}
139804
140609
  };
139805
140610
  }
139806
140611
  });
139807
- const SuperEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$1$1, [["__scopeId", "data-v-209a1e8b"]]);
140612
+ const SuperEditor = /* @__PURE__ */ _export_sfc$1(_sfc_main$1$1, [["__scopeId", "data-v-c9a3c876"]]);
139808
140613
  const _hoisted_1$h = ["innerHTML"];
139809
140614
  const _sfc_main$i = {
139810
140615
  __name: "SuperInput",
@@ -143012,12 +143817,10 @@ ${reason}`);
143012
143817
  return processedComments;
143013
143818
  };
143014
143819
  const convertHtmlToSchema = (commentHTML) => {
143015
- const div2 = document.createElement("div");
143016
- div2.innerHTML = commentHTML;
143017
143820
  const editor = new Editor({
143018
143821
  mode: "text",
143019
143822
  isHeadless: true,
143020
- content: div2,
143823
+ content: commentHTML,
143021
143824
  extensions: getRichTextExtensions()
143022
143825
  });
143023
143826
  return editor.getJSON().content[0];
@@ -157258,7 +158061,7 @@ ${style2}
157258
158061
  this.config.colors = shuffleArray(this.config.colors);
157259
158062
  this.userColorMap = /* @__PURE__ */ new Map();
157260
158063
  this.colorIndex = 0;
157261
- this.version = "2.0.0-next.2";
158064
+ this.version = "2.0.0-next.21";
157262
158065
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
157263
158066
  this.superdocId = config2.superdocId || v4();
157264
158067
  this.colors = this.config.colors;
@@ -159731,7 +160534,7 @@ ${style2}
159731
160534
  value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
159732
160535
  );
159733
160536
  }
159734
- const indexBqPa6D4q = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
160537
+ const index_W_Fk0WX = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
159735
160538
  __proto__: null,
159736
160539
  unified
159737
160540
  }, Symbol.toStringTag, { value: "Module" }));