superdoc 2.0.0-next.2 → 2.0.0-next.4

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 (27) hide show
  1. package/dist/chunks/{PdfViewer-C4xgIIbF.es.js → PdfViewer-D3PZ6zBK.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-CWO98Qls.cjs → PdfViewer-DW9Jjot9.cjs} +1 -1
  3. package/dist/chunks/{index-s9GUR_Gc.es.js → index-NcWPPbrQ.es.js} +3 -3
  4. package/dist/chunks/{index-BY-3Vl72.cjs → index-VXujz1iS.cjs} +3 -3
  5. package/dist/chunks/{index-BqPa6D4q-Dulj8zfc.cjs → index-YoL4XmHs-DgX6YU__.cjs} +1 -1
  6. package/dist/chunks/{index-BqPa6D4q-8U4x8RP6.es.js → index-YoL4XmHs-DnigArXx.es.js} +1 -1
  7. package/dist/chunks/{super-editor.es-BM-ulSRj.cjs → super-editor.es-CeYiIfGN.cjs} +642 -135
  8. package/dist/chunks/{super-editor.es-CT28vUbx.es.js → super-editor.es-o4f9FxT-.es.js} +642 -135
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-CDlAWcRu.js → converter-Cv-PWHhI.js} +1 -1
  11. package/dist/super-editor/chunks/{docx-zipper-B2VXuf8h.js → docx-zipper-aIZi_y1u.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-B4Q_tNET.js → editor-R1nZ8Y4J.js} +643 -136
  13. package/dist/super-editor/chunks/{index-BqPa6D4q.js → index-YoL4XmHs.js} +1 -1
  14. package/dist/super-editor/chunks/{toolbar-BD-lDCLr.js → toolbar-DTrmhth_.js} +2 -2
  15. package/dist/super-editor/converter.es.js +1 -1
  16. package/dist/super-editor/docx-zipper.es.js +2 -2
  17. package/dist/super-editor/editor.es.js +3 -3
  18. package/dist/super-editor/file-zipper.es.js +1 -1
  19. package/dist/super-editor/super-editor.es.js +6 -6
  20. package/dist/super-editor/toolbar.es.js +2 -2
  21. package/dist/super-editor.cjs +1 -1
  22. package/dist/super-editor.es.js +1 -1
  23. package/dist/superdoc.cjs +2 -2
  24. package/dist/superdoc.es.js +2 -2
  25. package/dist/superdoc.umd.js +644 -137
  26. package/dist/superdoc.umd.js.map +1 -1
  27. package/package.json +1 -1
@@ -12,8 +12,8 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
12
12
  var _a, _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, dispatchWithFallback_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, getPluginKeyName_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _currentEpoch, _mapsByFromEpoch, _maxEpochsToKeep, _EpochPositionMapper_instances, pruneByCurrentEpoch_fn, _entries, _windowRoot, _getPainterHost, _onRebuild, _observer, _rebuildScheduled, _rebuildRafId, _docEpoch, _layoutEpoch, _layoutUpdating, _pending, _scheduled, _rafHandle, _scheduler, _SelectionSyncCoordinator_instances, isSafeToRender_fn, maybeSchedule_fn, cancelScheduledRender_fn, _windowRoot2, _layoutSurfaces, _getTargetDom, _isEditable, _onTargetChanged, _listeners, _currentTarget, _destroyed, _useWindowFallback, _PresentationInputBridge_instances, addListener_fn, dispatchToTarget_fn, forwardKeyboardEvent_fn, forwardTextEvent_fn, forwardCompositionEvent_fn, forwardContextMenu_fn, isEventOnActiveTarget_fn, shouldSkipSurface_fn, isInLayoutSurface_fn, getListenerTargets_fn, isPlainCharacterKey_fn, _map, _editor2, _descriptors, _collections, _editorEntries, _maxCachedEditors, _editorAccessOrder, _pendingCreations, _cacheHits, _cacheMisses, _evictions, _HeaderFooterEditorManager_instances, hasConverter_fn, extractCollections_fn, collectDescriptors_fn, teardownMissingEditors_fn, teardownEditors_fn, createEditor_fn, createEditorContainer_fn, registerConverterEditor_fn, unregisterConverterEditor_fn, updateAccessOrder_fn, enforceCacheSizeLimit_fn, _manager, _mediaFiles, _blockCache, _HeaderFooterLayoutAdapter_instances, getBlocks_fn, getConverterContext_fn, _selectionOverlay, _activeEditorHost, _activeDecorationContainer, _activeRegion, _borderLine, _dimmingOverlay, _EditorOverlayManager_instances, findDecorationContainer_fn, ensureEditorHost_fn, positionEditorHost_fn, hideDimmingOverlay_fn, showHeaderFooterBorder_fn, hideHeaderFooterBorder_fn, _instances, _options, _editor3, _visibleHost, _viewportHost, _painterHost, _selectionOverlay2, _hiddenHost, _layoutOptions, _layoutState, _domPainter, _pageGeometryHelper, _dragHandlerCleanup, _layoutError, _layoutErrorState, _errorBanner, _errorBannerMessage, _telemetryEmitter, _renderScheduled, _pendingDocChange, _isRerendering, _selectionSync, _remoteCursorUpdateScheduled, _epochMapper, _layoutEpoch2, _domPositionIndex, _domIndexObserverManager, _debugLastPointer, _debugLastHit, _pendingMarginClick, _rafHandle2, _editorListeners, _sectionMetadata, _documentMode, _inputBridge, _trackedChangesMode, _trackedChangesEnabled, _trackedChangesOverrides, _headerFooterManager, _headerFooterAdapter, _headerFooterIdentifier, _multiSectionIdentifier, _headerLayoutResults, _footerLayoutResults, _headerLayoutsByRId, _footerLayoutsByRId, _headerDecorationProvider, _footerDecorationProvider, _headerFooterManagerCleanups, _headerRegions, _footerRegions, _session, _activeHeaderFooterEditor, _overlayManager, _hoverOverlay, _hoverTooltip, _modeBanner, _ariaLiveRegion, _a11ySelectionAnnounceTimeout, _a11yLastAnnouncedSelectionKey, _hoverRegion, _clickCount, _lastClickTime, _lastClickPosition, _lastSelectedImageBlockId, _dragAnchor, _dragAnchorPageIndex, _isDragging, _dragExtensionMode, _dragLastPointer, _dragLastRawHit, _dragUsedPageNotMountedFallback, _cellAnchor, _cellDragMode, _remoteCursorState, _remoteCursorElements, _remoteCursorDirty, _remoteCursorOverlay, _localSelectionLayer, _awarenessCleanup, _scrollCleanup, _scrollTimeout, _lastRemoteCursorRenderTime, _remoteCursorThrottleTimeout, _PresentationEditor_instances, wrapHiddenEditorFocus_fn, collectCommentPositions_fn, updateSelectionDebugHud_fn, computePendingMarginClick_fn, aggregateLayoutBounds_fn, rebuildDomPositionIndex_fn, setupEditorListeners_fn, setupCollaborationCursors_fn, updateLocalAwarenessCursor_fn, scheduleRemoteCursorUpdate_fn, scheduleRemoteCursorReRender_fn, updateRemoteCursors_fn, renderRemoteCursors_fn, setupPointerHandlers_fn, setupDragHandlers_fn, focusEditorAfterImageSelection_fn, setupInputBridge_fn, initHeaderFooterRegistry_fn, _handlePointerDown, getFirstTextPosition_fn, registerPointerClick_fn, getCellPosFromTableHit_fn, getTablePosFromHit_fn, shouldUseCellSelection_fn, setCellAnchor_fn, clearCellAnchor_fn, hitTestTable_fn, selectWordAt_fn, selectParagraphAt_fn, calculateExtendedSelection_fn, _handlePointerMove, _handlePointerLeave, _handleVisibleHostFocusIn, _handlePointerUp, _handleDragOver, _handleDrop, _handleDoubleClick, _handleKeyDown, focusHeaderFooterShortcut_fn, scheduleRerender_fn, flushRerenderQueue_fn, rerender_fn, ensurePainter_fn, scheduleSelectionUpdate_fn, updateSelection_fn, resolveLayoutOptions_fn, buildHeaderFooterInput_fn, computeHeaderFooterConstraints_fn, layoutPerRIdHeaderFooters_fn, updateDecorationProviders_fn, createDecorationProvider_fn, findHeaderFooterPageForPageNumber_fn, computeDecorationBox_fn, computeExpectedSectionType_fn, rebuildHeaderFooterRegions_fn, hitTestHeaderFooterRegion_fn, pointInRegion_fn, activateHeaderFooterRegion_fn, enterHeaderFooterMode_fn, exitHeaderFooterMode_fn, getActiveDomTarget_fn, emitHeaderFooterModeChanged_fn, emitHeaderFooterEditingContext_fn, updateAwarenessSession_fn, updateModeBanner_fn, announce_fn, syncHiddenEditorA11yAttributes_fn, scheduleA11ySelectionAnnouncement_fn, announceSelectionNow_fn, validateHeaderFooterEditPermission_fn, emitHeaderFooterEditBlocked_fn, resolveDescriptorForRegion_fn, createDefaultHeaderFooter_fn, getPageElement_fn, isSelectionAwareVirtualizationEnabled_fn, updateSelectionVirtualizationPins_fn, finalizeDragSelectionWithDom_fn, scrollPageIntoView_fn, waitForPageMount_fn, getEffectivePageGap_fn, getBodyPageHeight_fn, getHeaderFooterPageHeight_fn, renderCellSelectionOverlay_fn, renderHoverRegion_fn, clearHoverRegion_fn, getHeaderFooterContext_fn, computeHeaderFooterSelectionRects_fn, syncTrackedChangesPreferences_fn, deriveTrackedChangesMode_fn, deriveTrackedChangesEnabled_fn, getTrackChangesPluginState_fn, computeDefaultLayoutDefaults_fn, applyZoom_fn, getPageOffsetX_fn, convertPageLocalToOverlayCoords_fn, computeSelectionRectsFromDom_fn, computeDomCaretPageLocal_fn, normalizeClientPoint_fn, computeCaretLayoutRectGeometry_fn, computeCaretLayoutRect_fn, getCurrentPageIndex_fn, findRegionForPage_fn, handleLayoutError_fn, decorateError_fn, showLayoutErrorBanner_fn, dismissErrorBanner_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ParagraphNodeView_instances, checkShouldUpdate_fn, updateHTMLAttributes_fn, updateDOMStyles_fn, resolveNeighborParagraphProperties_fn, updateListStyles_fn, initList_fn, checkIsList_fn, createMarker_fn, createSeparator_fn, calculateTabSeparatorStyle_fn, calculateMarkerStyle_fn, removeList_fn, getParagraphContext_fn, scheduleAnimation_fn, cancelScheduledAnimation_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn, _VectorShapeView_instances, ensureParentPositioned_fn, _ShapeGroupView_instances, ensureParentPositioned_fn2;
13
13
  import * as Y from "yjs";
14
14
  import { UndoManager, Item as Item$1, ContentType, Text as Text$1, XmlElement, encodeStateAsUpdate } from "yjs";
15
- import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$2, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as htmlHandler, E as ReplaceStep, G as twipsToInches, H as inchesToTwips, I as ptToTwips, J as getResolvedParagraphProperties, K as linesToTwips, L as changeListLevel, O as findParentNode, Q as isList, U as updateNumberingProperties, V as ListHelpers, W as isMacOS, X as isIOS, Y as getSchemaTypeByName, Z as inputRulesPlugin, _ as TrackDeleteMarkName$1, $ as TrackInsertMarkName$1, a0 as v4, a1 as TrackFormatMarkName$1, a2 as comments_module_events, a3 as findMark, a4 as objectIncludes, a5 as AddMarkStep, a6 as RemoveMarkStep, a7 as twipsToLines, a8 as pixelsToTwips, a9 as helpers, aa as posToDOMRect, ab as CommandService, ac as SuperConverter, ad as createDocument, ae as createDocFromMarkdown, af as createDocFromHTML, ag as EditorState, ah as isActive, ai as unflattenListsInHtml, aj as SelectionRange, ak as Transform, al as resolveParagraphProperties, am as _getReferencedTableStyles, an as parseSizeUnit, ao as minMax, ap as updateDOMAttributes, aq as findChildren$5, ar as generateRandomSigned32BitIntStrId, as as decodeRPrFromMarks, at as calculateResolvedParagraphProperties, au as resolveRunProperties, av as encodeCSSFromPPr, aw as twipsToPixels$2, ax as encodeCSSFromRPr, ay as generateOrderedListIndex, az as docxNumberingHelpers, aA as InputRule, aB as convertSizeToCSS, aC as findParentNodeClosestToPos, aD as isInTable$1, aE as generateDocxRandomId, aF as insertNewRelationship, aG as inchesToPixels, aH as kebabCase, aI as getUnderlineCssString } from "./converter-CDlAWcRu.js";
16
- import { D as DocxZipper } from "./docx-zipper-B2VXuf8h.js";
15
+ import { P as PluginKey, a as Plugin, M as Mapping, N as NodeSelection, S as Selection, T as TextSelection, b as Slice, D as DOMSerializer, F as Fragment, c as DOMParser$1, d as Mark$1, e as dropPoint, A as AllSelection, p as process$1, B as Buffer2, f as callOrGet, g as getExtensionConfigField, h as getMarkType, i as getMarksFromSelection, j as getNodeType, k as getSchemaTypeNameByName, l as Schema$2, m as cleanSchemaItem, n as canSplit, o as defaultBlockAt$1, q as liftTarget, r as canJoin, s as joinPoint, t as replaceStep$1, R as ReplaceAroundStep$1, u as isTextSelection, v as getMarkRange, w as isMarkActive, x as isNodeActive, y as deleteProps, z as processContent, C as htmlHandler, E as ReplaceStep, G as twipsToInches, H as inchesToTwips, I as ptToTwips, J as getResolvedParagraphProperties, K as linesToTwips, L as changeListLevel, O as findParentNode, Q as isList, U as updateNumberingProperties, V as ListHelpers, W as isMacOS, X as isIOS, Y as getSchemaTypeByName, Z as inputRulesPlugin, _ as TrackDeleteMarkName$1, $ as TrackInsertMarkName$1, a0 as v4, a1 as TrackFormatMarkName$1, a2 as comments_module_events, a3 as findMark, a4 as objectIncludes, a5 as AddMarkStep, a6 as RemoveMarkStep, a7 as twipsToLines, a8 as pixelsToTwips, a9 as helpers, aa as posToDOMRect, ab as CommandService, ac as SuperConverter, ad as createDocument, ae as createDocFromMarkdown, af as createDocFromHTML, ag as EditorState, ah as isActive, ai as unflattenListsInHtml, aj as SelectionRange, ak as Transform, al as resolveParagraphProperties, am as _getReferencedTableStyles, an as parseSizeUnit, ao as minMax, ap as updateDOMAttributes, aq as findChildren$5, ar as generateRandomSigned32BitIntStrId, as as decodeRPrFromMarks, at as calculateResolvedParagraphProperties, au as resolveRunProperties, av as encodeCSSFromPPr, aw as twipsToPixels$2, ax as encodeCSSFromRPr, ay as generateOrderedListIndex, az as docxNumberingHelpers, aA as InputRule, aB as convertSizeToCSS, aC as findParentNodeClosestToPos, aD as isInTable$1, aE as generateDocxRandomId, aF as insertNewRelationship, aG as inchesToPixels, aH as kebabCase, aI as getUnderlineCssString } from "./converter-Cv-PWHhI.js";
16
+ import { D as DocxZipper } from "./docx-zipper-aIZi_y1u.js";
17
17
  import { ref, computed, createElementBlock, openBlock, withModifiers, Fragment as Fragment$1, renderList, normalizeClass, createCommentVNode, toDisplayString, createElementVNode, createApp } from "vue";
18
18
  var GOOD_LEAF_SIZE = 200;
19
19
  var RopeSequence = function RopeSequence2() {
@@ -14815,7 +14815,7 @@ const isHeadless = (editor) => {
14815
14815
  const shouldSkipNodeView = (editor) => {
14816
14816
  return isHeadless(editor);
14817
14817
  };
14818
- const summaryVersion = "2.0.0-next.2";
14818
+ const summaryVersion = "2.0.0-next.4";
14819
14819
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
14820
14820
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
14821
14821
  function mapAttributes(attrs) {
@@ -15607,7 +15607,7 @@ const _Editor = class _Editor extends EventEmitter {
15607
15607
  { default: remarkStringify },
15608
15608
  { default: remarkGfm }
15609
15609
  ] = await Promise.all([
15610
- import("./index-BqPa6D4q.js"),
15610
+ import("./index-YoL4XmHs.js"),
15611
15611
  import("./index-DRCvimau.js"),
15612
15612
  import("./index-C_x_N6Uh.js"),
15613
15613
  import("./index-D_sWOSiG.js"),
@@ -15812,7 +15812,7 @@ const _Editor = class _Editor extends EventEmitter {
15812
15812
  * Process collaboration migrations
15813
15813
  */
15814
15814
  processCollaborationMigrations() {
15815
- console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.2");
15815
+ console.debug("[checkVersionMigrations] Current editor version", "2.0.0-next.4");
15816
15816
  if (!this.options.ydoc) return;
15817
15817
  const metaMap = this.options.ydoc.getMap("meta");
15818
15818
  let docVersion = metaMap.get("version");
@@ -23152,7 +23152,7 @@ function isMinimalWordLayout(value) {
23152
23152
  return true;
23153
23153
  }
23154
23154
  const LIST_MARKER_GAP$2 = 8;
23155
- const DEFAULT_TAB_INTERVAL_PX$1 = 48;
23155
+ const DEFAULT_TAB_INTERVAL_PX$2 = 48;
23156
23156
  const DEFAULT_PAGE_HEIGHT_PX = 1056;
23157
23157
  const DEFAULT_VIRTUALIZED_PAGE_GAP$1 = 72;
23158
23158
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
@@ -24079,6 +24079,7 @@ const _DomPainter = class _DomPainter {
24079
24079
  const block = lookup.block;
24080
24080
  const measure = lookup.measure;
24081
24081
  const wordLayout = isMinimalWordLayout(block.attrs?.wordLayout) ? block.attrs.wordLayout : void 0;
24082
+ const alignment = block.attrs?.alignment;
24082
24083
  const fragmentEl = this.doc.createElement("div");
24083
24084
  fragmentEl.classList.add(CLASS_NAMES$1.fragment);
24084
24085
  const isTocEntry = block.attrs?.isTocEntry;
@@ -24157,7 +24158,7 @@ const _DomPainter = class _DomPainter {
24157
24158
  const textStart = paraIndentLeft + firstLine;
24158
24159
  tabWidth = textStart - currentPos;
24159
24160
  if (tabWidth <= 0) {
24160
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
24161
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
24161
24162
  } else if (tabWidth < LIST_MARKER_GAP$2) {
24162
24163
  tabWidth = LIST_MARKER_GAP$2;
24163
24164
  }
@@ -24184,6 +24185,21 @@ const _DomPainter = class _DomPainter {
24184
24185
  let availableWidthOverride = line.maxWidth != null ? Math.min(line.maxWidth, fallbackAvailableWidth) : fallbackAvailableWidth;
24185
24186
  if (index2 === 0 && listFirstLineMarkerTabWidth != null) {
24186
24187
  availableWidthOverride = fragment.width - listFirstLineMarkerTabWidth - Math.max(0, paraIndentRight);
24188
+ if (alignment === "justify" || alignment === "both") {
24189
+ console.log(
24190
+ "[justify-debug][painter-firstline-available]",
24191
+ JSON.stringify({
24192
+ blockId: block.id,
24193
+ fragmentWidth: fragment.width,
24194
+ markerTabWidth: listFirstLineMarkerTabWidth,
24195
+ paraIndentRight,
24196
+ availableWidthOverride,
24197
+ lineMaxWidth: line.maxWidth ?? null,
24198
+ lineWidth: line.width,
24199
+ lineNaturalWidth: line.naturalWidth ?? null
24200
+ })
24201
+ );
24202
+ }
24187
24203
  }
24188
24204
  const isLastLineOfFragment = index2 === lines.length - 1;
24189
24205
  const isLastLineOfParagraph = isLastLineOfFragment && !fragment.continuesOnNext;
@@ -24309,7 +24325,7 @@ const _DomPainter = class _DomPainter {
24309
24325
  const textStart = paraIndentLeft + firstLine;
24310
24326
  tabWidth = textStart - currentPos;
24311
24327
  if (tabWidth <= 0) {
24312
- tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
24328
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$2 - currentPos % DEFAULT_TAB_INTERVAL_PX$2;
24313
24329
  } else if (tabWidth < LIST_MARKER_GAP$2) {
24314
24330
  tabWidth = LIST_MARKER_GAP$2;
24315
24331
  }
@@ -25843,6 +25859,23 @@ const _DomPainter = class _DomPainter {
25843
25859
  if (spacingPerSpace !== 0) {
25844
25860
  el.style.wordSpacing = `${spacingPerSpace}px`;
25845
25861
  }
25862
+ if (justifyShouldApply && spacingPerSpace < 0) {
25863
+ console.log(
25864
+ "[justify-debug][painter-wordspacing-negative]",
25865
+ JSON.stringify({
25866
+ blockId: block.id,
25867
+ lineIndex: lineIndex ?? null,
25868
+ alignment: alignment ?? null,
25869
+ availableWidth,
25870
+ lineWidth,
25871
+ lineMaxWidth: line.maxWidth ?? null,
25872
+ lineNaturalWidth: line.naturalWidth ?? null,
25873
+ spaceCount,
25874
+ hasExplicitPositioning: Boolean(hasExplicitPositioning),
25875
+ skipJustify: Boolean(skipJustify)
25876
+ })
25877
+ );
25878
+ }
25846
25879
  if (hasExplicitPositioning && line.segments) {
25847
25880
  const paraIndent = block.attrs?.indent;
25848
25881
  const indentLeft = paraIndent?.left ?? 0;
@@ -28036,6 +28069,28 @@ let measurementCtx = null;
28036
28069
  const TAB_CHAR_LENGTH = 1;
28037
28070
  const SPACE_CHARS = SPACE_CHARS$1;
28038
28071
  const isTabRun$1 = (run) => run?.kind === "tab";
28072
+ const isWordChar$3 = (char) => {
28073
+ if (!char) return false;
28074
+ const code = char.charCodeAt(0);
28075
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
28076
+ };
28077
+ const capitalizeText$2 = (text) => {
28078
+ if (!text) return text;
28079
+ let result = "";
28080
+ for (let i = 0; i < text.length; i += 1) {
28081
+ const prevChar = i > 0 ? text[i - 1] : "";
28082
+ const ch = text[i];
28083
+ result += isWordChar$3(ch) && !isWordChar$3(prevChar) ? ch.toUpperCase() : ch;
28084
+ }
28085
+ return result;
28086
+ };
28087
+ const applyTextTransform$2 = (text, transform) => {
28088
+ if (!text || !transform || transform === "none") return text;
28089
+ if (transform === "uppercase") return text.toUpperCase();
28090
+ if (transform === "lowercase") return text.toLowerCase();
28091
+ if (transform === "capitalize") return capitalizeText$2(text);
28092
+ return text;
28093
+ };
28039
28094
  function getMeasurementContext() {
28040
28095
  if (measurementCtx) return measurementCtx;
28041
28096
  if (typeof document === "undefined") {
@@ -28211,17 +28266,19 @@ function measureCharacterX(block, line, charOffset, availableWidthOverride, alig
28211
28266
  }
28212
28267
  const text = "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
28213
28268
  const runLength = text.length;
28269
+ const transform = isTabRun$1(run) || "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? void 0 : run.textTransform;
28270
+ const displayText = applyTextTransform$2(text, transform);
28214
28271
  if (currentCharOffset + runLength >= charOffset) {
28215
28272
  const offsetInRun = charOffset - currentCharOffset;
28216
28273
  ctx2.font = getRunFontString(run);
28217
- const textUpToTarget = text.slice(0, offsetInRun);
28274
+ const textUpToTarget = displayText.slice(0, offsetInRun);
28218
28275
  const measured2 = ctx2.measureText(textUpToTarget);
28219
28276
  const spacingWidth = computeLetterSpacingWidth(run, offsetInRun, runLength);
28220
- const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(textUpToTarget) : 0;
28277
+ const spacesInPortion = justify.extraPerSpace !== 0 ? countSpaces(text.slice(0, offsetInRun)) : 0;
28221
28278
  return alignmentOffset + currentX + measured2.width + spacingWidth + justify.extraPerSpace * (spaceTally + spacesInPortion);
28222
28279
  }
28223
28280
  ctx2.font = getRunFontString(run);
28224
- const measured = ctx2.measureText(text);
28281
+ const measured = ctx2.measureText(displayText);
28225
28282
  const runLetterSpacing = computeLetterSpacingWidth(run, runLength, runLength);
28226
28283
  const spacesInRun = justify.extraPerSpace !== 0 ? countSpaces(text) : 0;
28227
28284
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -28260,8 +28317,10 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
28260
28317
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
28261
28318
  }
28262
28319
  const text = run.text ?? "";
28263
- const segmentText = text.slice(segment.fromChar, segment.toChar);
28264
- const textUpToTarget = segmentText.slice(0, offsetInSegment);
28320
+ const transform = "textTransform" in run ? run.textTransform : void 0;
28321
+ const displayText = applyTextTransform$2(text, transform);
28322
+ const displaySegmentText = displayText.slice(segment.fromChar, segment.toChar);
28323
+ const textUpToTarget = displaySegmentText.slice(0, offsetInSegment);
28265
28324
  ctx2.font = getRunFontString(run);
28266
28325
  const measured = ctx2.measureText(textUpToTarget);
28267
28326
  const spacingWidth = computeLetterSpacingWidth(run, offsetInSegment, segmentChars);
@@ -28357,12 +28416,14 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
28357
28416
  }
28358
28417
  const text = "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
28359
28418
  const runLength = text.length;
28419
+ const transform = isTabRun$1(run) || "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? void 0 : run.textTransform;
28420
+ const displayText = applyTextTransform$2(text, transform);
28360
28421
  if (runLength === 0) continue;
28361
28422
  ctx2.font = getRunFontString(run);
28362
28423
  for (let i = 0; i <= runLength; i++) {
28363
- const textUpToChar = text.slice(0, i);
28424
+ const textUpToChar = displayText.slice(0, i);
28364
28425
  const measured2 = ctx2.measureText(textUpToChar);
28365
- const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(textUpToChar) : 0;
28426
+ const spacesInPortion = justify.extraPerSpace > 0 ? countSpaces(text.slice(0, i)) : 0;
28366
28427
  const charX = currentX + measured2.width + computeLetterSpacingWidth(run, i, runLength) + justify.extraPerSpace * (spaceTally + spacesInPortion);
28367
28428
  if (charX >= safeX) {
28368
28429
  if (i === 0) {
@@ -28372,7 +28433,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
28372
28433
  pmPosition: pmPosition3
28373
28434
  };
28374
28435
  }
28375
- const prevText = text.slice(0, i - 1);
28436
+ const prevText = displayText.slice(0, i - 1);
28376
28437
  const prevMeasured = ctx2.measureText(prevText);
28377
28438
  const prevX = currentX + prevMeasured.width + computeLetterSpacingWidth(run, i - 1, runLength);
28378
28439
  const distToPrev = Math.abs(safeX - prevX);
@@ -28385,7 +28446,7 @@ function findCharacterAtX(block, line, x, pmStart, availableWidthOverride, align
28385
28446
  };
28386
28447
  }
28387
28448
  }
28388
- const measured = ctx2.measureText(text);
28449
+ const measured = ctx2.measureText(displayText);
28389
28450
  const runLetterSpacing = computeLetterSpacingWidth(run, runLength, runLength);
28390
28451
  const spacesInRun = justify.extraPerSpace > 0 ? countSpaces(text) : 0;
28391
28452
  currentX += measured.width + runLetterSpacing + justify.extraPerSpace * spacesInRun;
@@ -28816,6 +28877,83 @@ function findCharIndexAtX(textNode, container, targetX) {
28816
28877
  }
28817
28878
  return index2;
28818
28879
  }
28880
+ const LIST_MARKER_GAP$1 = 8;
28881
+ const MIN_MARKER_GUTTER = 24;
28882
+ const DEFAULT_LIST_INDENT_BASE_PX = 24;
28883
+ const DEFAULT_LIST_INDENT_STEP_PX = 24;
28884
+ const DEFAULT_LIST_HANGING_PX$1 = 18;
28885
+ const SPACE_SUFFIX_GAP_PX = 4;
28886
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
28887
+ function resolveListTextStartPx(wordLayout, indentLeft, firstLine, hanging, measureMarkerText) {
28888
+ const marker = wordLayout?.marker;
28889
+ if (!marker) {
28890
+ const textStartPx = wordLayout?.firstLineIndentMode === true && typeof wordLayout.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
28891
+ return textStartPx;
28892
+ }
28893
+ const markerBoxWidth = typeof marker.markerBoxWidthPx === "number" && Number.isFinite(marker.markerBoxWidthPx) ? marker.markerBoxWidthPx : 0;
28894
+ let markerTextWidth = typeof marker.glyphWidthPx === "number" && Number.isFinite(marker.glyphWidthPx) ? marker.glyphWidthPx : void 0;
28895
+ if (markerTextWidth == null && marker.markerText) {
28896
+ markerTextWidth = measureMarkerText(marker.markerText, marker);
28897
+ }
28898
+ if (!Number.isFinite(markerTextWidth) || markerTextWidth !== void 0 && markerTextWidth < 0) {
28899
+ markerTextWidth = markerBoxWidth;
28900
+ }
28901
+ const finalMarkerTextWidth = Math.max(0, markerTextWidth ?? 0);
28902
+ let markerStartPos;
28903
+ if (wordLayout?.firstLineIndentMode === true && typeof marker.markerX === "number" && Number.isFinite(marker.markerX)) {
28904
+ markerStartPos = marker.markerX;
28905
+ } else {
28906
+ markerStartPos = indentLeft - hanging + firstLine;
28907
+ }
28908
+ if (!Number.isFinite(markerStartPos)) {
28909
+ markerStartPos = 0;
28910
+ }
28911
+ const currentPos = markerStartPos + finalMarkerTextWidth;
28912
+ const suffix = marker.suffix ?? "tab";
28913
+ if (suffix === "space") {
28914
+ return markerStartPos + finalMarkerTextWidth + SPACE_SUFFIX_GAP_PX;
28915
+ }
28916
+ if (suffix === "nothing") {
28917
+ return markerStartPos + finalMarkerTextWidth;
28918
+ }
28919
+ const markerJustification = marker.justification ?? "left";
28920
+ if (markerJustification !== "left") {
28921
+ const gutterWidth = typeof marker.gutterWidthPx === "number" && Number.isFinite(marker.gutterWidthPx) && marker.gutterWidthPx > 0 ? marker.gutterWidthPx : LIST_MARKER_GAP$1;
28922
+ return markerStartPos + finalMarkerTextWidth + Math.max(gutterWidth, LIST_MARKER_GAP$1);
28923
+ }
28924
+ if (wordLayout?.firstLineIndentMode === true) {
28925
+ let targetTabStop;
28926
+ if (Array.isArray(wordLayout.tabsPx)) {
28927
+ for (const tab of wordLayout.tabsPx) {
28928
+ if (typeof tab === "number" && tab > currentPos) {
28929
+ targetTabStop = tab;
28930
+ break;
28931
+ }
28932
+ }
28933
+ }
28934
+ const textStartTarget = typeof marker.textStartX === "number" && Number.isFinite(marker.textStartX) ? marker.textStartX : wordLayout.textStartPx;
28935
+ let tabWidth2;
28936
+ if (targetTabStop !== void 0) {
28937
+ tabWidth2 = targetTabStop - currentPos;
28938
+ } else if (textStartTarget !== void 0 && Number.isFinite(textStartTarget) && textStartTarget > currentPos) {
28939
+ tabWidth2 = textStartTarget - currentPos;
28940
+ } else {
28941
+ tabWidth2 = LIST_MARKER_GAP$1;
28942
+ }
28943
+ if (tabWidth2 < LIST_MARKER_GAP$1) {
28944
+ tabWidth2 = LIST_MARKER_GAP$1;
28945
+ }
28946
+ return markerStartPos + finalMarkerTextWidth + tabWidth2;
28947
+ }
28948
+ const textStart = indentLeft + firstLine;
28949
+ let tabWidth = textStart - currentPos;
28950
+ if (tabWidth <= 0) {
28951
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
28952
+ } else if (tabWidth < LIST_MARKER_GAP$1) {
28953
+ tabWidth = LIST_MARKER_GAP$1;
28954
+ }
28955
+ return markerStartPos + finalMarkerTextWidth + tabWidth;
28956
+ }
28819
28957
  function getWordLayoutConfig(block) {
28820
28958
  if (!block || block.kind !== "paragraph") {
28821
28959
  return void 0;
@@ -28848,9 +28986,16 @@ function calculateTextStartIndent(params2) {
28848
28986
  const isFirstLineIndentMode = wordLayout?.firstLineIndentMode === true;
28849
28987
  let indentAdjust = paraIndentLeft;
28850
28988
  if (isListItem2 && isFirstLine && isFirstLineIndentMode) {
28989
+ const resolvedTextStart = resolveListTextStartPx(
28990
+ wordLayout,
28991
+ paraIndentLeft,
28992
+ Math.max(firstLineIndent, 0),
28993
+ Math.max(hangingIndent, 0),
28994
+ () => markerWidth
28995
+ // Use provided markerWidth since we don't have canvas access here
28996
+ );
28851
28997
  const textStartFallback = paraIndentLeft + Math.max(firstLineIndent, 0) + markerWidth;
28852
- const markerTextStartX = wordLayout?.marker?.textStartX;
28853
- indentAdjust = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : textStartFallback;
28998
+ indentAdjust = typeof resolvedTextStart === "number" && Number.isFinite(resolvedTextStart) ? resolvedTextStart : textStartFallback;
28854
28999
  } else if (isFirstLine && !isListItem2) {
28855
29000
  indentAdjust += firstLineOffset;
28856
29001
  }
@@ -29006,7 +29151,10 @@ function getHeaderFooterTypeForSection(pageNumber, sectionIndex, identifier, opt
29006
29151
  }
29007
29152
  function createFloatingObjectManager(columns, margins, pageWidth) {
29008
29153
  const zones = [];
29009
- const marginLeft = Math.max(0, margins?.left ?? 0);
29154
+ let currentColumns = columns;
29155
+ let currentMargins = margins;
29156
+ let currentPageWidth = pageWidth;
29157
+ let marginLeft = Math.max(0, currentMargins?.left ?? 0);
29010
29158
  return {
29011
29159
  registerDrawing(drawingBlock, measure, anchorY, columnIndex, pageNumber) {
29012
29160
  if (!drawingBlock.anchor?.isAnchored) {
@@ -29019,7 +29167,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29019
29167
  }
29020
29168
  const objectWidth = measure.width ?? 0;
29021
29169
  const objectHeight = measure.height ?? 0;
29022
- const x = computeAnchorX(anchor, columnIndex, columns, objectWidth, margins, pageWidth);
29170
+ const x = computeAnchorX(anchor, columnIndex, currentColumns, objectWidth, currentMargins, currentPageWidth);
29023
29171
  const y = anchorY + (anchor.offsetV ?? 0);
29024
29172
  const zone = {
29025
29173
  imageBlockId: drawingBlock.id,
@@ -29053,7 +29201,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29053
29201
  }
29054
29202
  const tableWidth = measure.totalWidth ?? 0;
29055
29203
  const tableHeight = measure.totalHeight ?? 0;
29056
- const x = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
29204
+ const x = computeTableAnchorX(anchor, columnIndex, currentColumns, tableWidth, currentMargins, currentPageWidth);
29057
29205
  const y = anchorY + (anchor.offsetV ?? 0);
29058
29206
  const zone = {
29059
29207
  imageBlockId: tableBlock.id,
@@ -29101,7 +29249,7 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29101
29249
  }
29102
29250
  const leftFloats = [];
29103
29251
  const rightFloats = [];
29104
- const columnOrigin = marginLeft + columnIndex * (columns.width + columns.gap);
29252
+ const columnOrigin = marginLeft + columnIndex * (currentColumns.width + currentColumns.gap);
29105
29253
  const columnCenter = columnOrigin + baseWidth / 2;
29106
29254
  for (const zone of wrappingZones) {
29107
29255
  if (zone.wrapMode === "left") {
@@ -29140,6 +29288,22 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
29140
29288
  },
29141
29289
  clear() {
29142
29290
  zones.length = 0;
29291
+ },
29292
+ /**
29293
+ * Update layout context used for positioning and wrapping (columns, margins, page width).
29294
+ * This method should be called when the layout configuration changes (e.g., section breaks,
29295
+ * column changes, page size changes) to ensure floating objects are positioned and wrapped
29296
+ * correctly relative to the new layout boundaries.
29297
+ *
29298
+ * @param nextColumns - Column layout configuration (width, gap, count)
29299
+ * @param nextMargins - Optional page margins (left, right) in pixels
29300
+ * @param nextPageWidth - Optional total page width in pixels
29301
+ */
29302
+ setLayoutContext(nextColumns, nextMargins, nextPageWidth) {
29303
+ currentColumns = nextColumns;
29304
+ currentMargins = nextMargins;
29305
+ currentPageWidth = nextPageWidth;
29306
+ marginLeft = Math.max(0, currentMargins?.left ?? 0);
29143
29307
  }
29144
29308
  };
29145
29309
  }
@@ -29239,7 +29403,14 @@ function computeNextSectionPropsAtBreak(blocks) {
29239
29403
  const props = {};
29240
29404
  if (source.kind !== "sectionBreak") return props;
29241
29405
  if (source.margins) {
29242
- props.margins = { header: source.margins.header, footer: source.margins.footer };
29406
+ props.margins = {
29407
+ header: source.margins.header,
29408
+ footer: source.margins.footer,
29409
+ top: source.margins.top,
29410
+ right: source.margins.right,
29411
+ bottom: source.margins.bottom,
29412
+ left: source.margins.left
29413
+ };
29243
29414
  }
29244
29415
  if (source.pageSize) {
29245
29416
  props.pageSize = { w: source.pageSize.w, h: source.pageSize.h };
@@ -29287,20 +29458,36 @@ function scheduleSectionBreak(block, state, baseMargins, maxHeaderContentHeight
29287
29458
  next.activeOrientation = block.orientation;
29288
29459
  next.pendingOrientation = null;
29289
29460
  }
29461
+ const headerDistance = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
29462
+ const footerDistance = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
29463
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
29464
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
29290
29465
  if (block.margins?.header !== void 0) {
29291
- const headerDistance = Math.max(0, block.margins.header);
29292
29466
  next.activeHeaderDistance = headerDistance;
29293
29467
  next.pendingHeaderDistance = headerDistance;
29294
- next.activeTopMargin = calcRequiredTopMargin(headerDistance, baseMargins.top);
29295
- next.pendingTopMargin = next.activeTopMargin;
29296
29468
  }
29297
29469
  if (block.margins?.footer !== void 0) {
29298
- const footerDistance = Math.max(0, block.margins.footer);
29299
29470
  next.activeFooterDistance = footerDistance;
29300
29471
  next.pendingFooterDistance = footerDistance;
29301
- next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, baseMargins.bottom);
29472
+ }
29473
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
29474
+ next.activeTopMargin = calcRequiredTopMargin(headerDistance, sectionTop);
29475
+ next.pendingTopMargin = next.activeTopMargin;
29476
+ }
29477
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
29478
+ next.activeBottomMargin = calcRequiredBottomMargin(footerDistance, sectionBottom);
29302
29479
  next.pendingBottomMargin = next.activeBottomMargin;
29303
29480
  }
29481
+ if (block.margins?.left !== void 0) {
29482
+ const leftMargin = Math.max(0, block.margins.left);
29483
+ next.activeLeftMargin = leftMargin;
29484
+ next.pendingLeftMargin = leftMargin;
29485
+ }
29486
+ if (block.margins?.right !== void 0) {
29487
+ const rightMargin = Math.max(0, block.margins.right);
29488
+ next.activeRightMargin = rightMargin;
29489
+ next.pendingRightMargin = rightMargin;
29490
+ }
29304
29491
  if (block.columns) {
29305
29492
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
29306
29493
  next.pendingColumns = null;
@@ -29309,26 +29496,42 @@ function scheduleSectionBreak(block, state, baseMargins, maxHeaderContentHeight
29309
29496
  }
29310
29497
  const headerPx = block.margins?.header;
29311
29498
  const footerPx = block.margins?.footer;
29499
+ const topPx = block.margins?.top;
29500
+ const bottomPx = block.margins?.bottom;
29312
29501
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
29313
29502
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
29503
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
29504
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
29314
29505
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
29315
29506
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
29316
- if (typeof headerPx === "number") {
29317
- const newHeaderDist = Math.max(0, headerPx);
29507
+ if (typeof headerPx === "number" || typeof topPx === "number") {
29508
+ const newHeaderDist = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
29509
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
29318
29510
  next.pendingHeaderDistance = newHeaderDist;
29319
- next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, baseMargins.top);
29511
+ next.pendingTopMargin = calcRequiredTopMargin(newHeaderDist, sectionTop);
29320
29512
  } else {
29321
29513
  next.pendingTopMargin = nextTop;
29322
29514
  next.pendingHeaderDistance = nextHeader;
29323
29515
  }
29324
- if (typeof footerPx === "number") {
29325
- const newFooterDist = Math.max(0, footerPx);
29516
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
29517
+ const newFooterDist = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
29518
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
29326
29519
  next.pendingFooterDistance = newFooterDist;
29327
- next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, baseMargins.bottom);
29520
+ next.pendingBottomMargin = calcRequiredBottomMargin(newFooterDist, sectionBottom);
29328
29521
  } else {
29329
29522
  next.pendingBottomMargin = nextBottom;
29330
29523
  next.pendingFooterDistance = nextFooter;
29331
29524
  }
29525
+ if (typeof block.margins?.left === "number") {
29526
+ next.pendingLeftMargin = Math.max(0, block.margins.left);
29527
+ } else {
29528
+ next.pendingLeftMargin = nextLeft;
29529
+ }
29530
+ if (typeof block.margins?.right === "number") {
29531
+ next.pendingRightMargin = Math.max(0, block.margins.right);
29532
+ } else {
29533
+ next.pendingRightMargin = nextRight;
29534
+ }
29332
29535
  if (block.pageSize) {
29333
29536
  next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
29334
29537
  }
@@ -29388,6 +29591,12 @@ function applyPendingToActive(state) {
29388
29591
  if (next.pendingBottomMargin != null) {
29389
29592
  next.activeBottomMargin = next.pendingBottomMargin;
29390
29593
  }
29594
+ if (next.pendingLeftMargin != null) {
29595
+ next.activeLeftMargin = next.pendingLeftMargin;
29596
+ }
29597
+ if (next.pendingRightMargin != null) {
29598
+ next.activeRightMargin = next.pendingRightMargin;
29599
+ }
29391
29600
  if (next.pendingHeaderDistance != null) {
29392
29601
  next.activeHeaderDistance = next.pendingHeaderDistance;
29393
29602
  }
@@ -29405,6 +29614,8 @@ function applyPendingToActive(state) {
29405
29614
  }
29406
29615
  next.pendingTopMargin = null;
29407
29616
  next.pendingBottomMargin = null;
29617
+ next.pendingLeftMargin = null;
29618
+ next.pendingRightMargin = null;
29408
29619
  next.pendingHeaderDistance = null;
29409
29620
  next.pendingFooterDistance = null;
29410
29621
  next.pendingPageSize = null;
@@ -29633,7 +29844,8 @@ function layoutParagraphBlock(ctx2, anchors) {
29633
29844
  if (typeof remeasureParagraph2 === "function" && typeof measurementWidth === "number" && measurementWidth > remeasureWidth) {
29634
29845
  const firstLineIndent = calculateFirstLineIndent(block, measure);
29635
29846
  const newMeasure = remeasureParagraph2(block, columnWidth, firstLineIndent);
29636
- lines = normalizeLines(newMeasure);
29847
+ const newLines = normalizeLines(newMeasure);
29848
+ lines = newLines;
29637
29849
  didRemeasureForColumnWidth = true;
29638
29850
  }
29639
29851
  let fromLine = 0;
@@ -29715,7 +29927,8 @@ function layoutParagraphBlock(ctx2, anchors) {
29715
29927
  if (narrowestRemeasureWidth < remeasureWidth) {
29716
29928
  const firstLineIndent = calculateFirstLineIndent(block, measure);
29717
29929
  const newMeasure = remeasureParagraph2(block, narrowestRemeasureWidth, firstLineIndent);
29718
- lines = normalizeLines(newMeasure);
29930
+ const newLines = normalizeLines(newMeasure);
29931
+ lines = newLines;
29719
29932
  didRemeasureForFloats = true;
29720
29933
  }
29721
29934
  }
@@ -30059,6 +30272,94 @@ function getCellPadding(cellIdx, blockRow) {
30059
30272
  function getCellTotalLines(cell) {
30060
30273
  return getCellLines(cell).length;
30061
30274
  }
30275
+ function mergePmRange(target, range) {
30276
+ if (typeof range.pmStart === "number") {
30277
+ target.pmStart = target.pmStart == null ? range.pmStart : Math.min(target.pmStart, range.pmStart);
30278
+ }
30279
+ if (typeof range.pmEnd === "number") {
30280
+ target.pmEnd = target.pmEnd == null ? range.pmEnd : Math.max(target.pmEnd, range.pmEnd);
30281
+ }
30282
+ }
30283
+ function computeCellPmRange(cell, cellMeasure, fromLine, toLine) {
30284
+ const range = {};
30285
+ if (!cell || !cellMeasure) return range;
30286
+ const cellBlocks = cell.blocks ?? (cell.paragraph ? [cell.paragraph] : []);
30287
+ const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
30288
+ const maxBlocks = Math.min(cellBlocks.length, blockMeasures.length);
30289
+ let cumulativeLineCount = 0;
30290
+ for (let i = 0; i < maxBlocks; i++) {
30291
+ const block = cellBlocks[i];
30292
+ const blockMeasure = blockMeasures[i];
30293
+ if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
30294
+ const paraMeasure = blockMeasure;
30295
+ const lines = paraMeasure.lines;
30296
+ const blockLineCount = lines?.length ?? 0;
30297
+ const blockStartGlobal = cumulativeLineCount;
30298
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
30299
+ const localFrom = Math.max(fromLine, blockStartGlobal) - blockStartGlobal;
30300
+ const localTo = Math.min(toLine, blockEndGlobal) - blockStartGlobal;
30301
+ if (lines && lines.length > 0 && localFrom < localTo) {
30302
+ mergePmRange(range, computeFragmentPmRange(block, lines, localFrom, localTo));
30303
+ } else {
30304
+ mergePmRange(range, extractBlockPmRange(block));
30305
+ }
30306
+ cumulativeLineCount += blockLineCount;
30307
+ continue;
30308
+ }
30309
+ mergePmRange(range, extractBlockPmRange(block));
30310
+ }
30311
+ return range;
30312
+ }
30313
+ function computeTableFragmentPmRange(block, measure, fromRow, toRow, partialRow) {
30314
+ const range = {};
30315
+ for (let rowIndex = fromRow; rowIndex < toRow; rowIndex++) {
30316
+ const row = block.rows[rowIndex];
30317
+ const rowMeasure = measure.rows[rowIndex];
30318
+ if (!row || !rowMeasure) continue;
30319
+ const isPartial = partialRow?.rowIndex === rowIndex;
30320
+ const cellCount = Math.min(row.cells.length, rowMeasure.cells.length);
30321
+ for (let cellIndex = 0; cellIndex < cellCount; cellIndex++) {
30322
+ const cell = row.cells[cellIndex];
30323
+ const cellMeasure = rowMeasure.cells[cellIndex];
30324
+ if (!cell || !cellMeasure) continue;
30325
+ const totalLines = getCellTotalLines(cellMeasure);
30326
+ let fromLine = 0;
30327
+ let toLine = totalLines;
30328
+ if (isPartial) {
30329
+ const hasValidFromLineByCell = partialRow?.fromLineByCell && cellIndex < partialRow.fromLineByCell.length;
30330
+ const hasValidToLineByCell = partialRow?.toLineByCell && cellIndex < partialRow.toLineByCell.length;
30331
+ if (hasValidFromLineByCell) {
30332
+ const rawFrom = partialRow.fromLineByCell[cellIndex];
30333
+ if (typeof rawFrom === "number" && rawFrom >= 0) {
30334
+ fromLine = rawFrom;
30335
+ }
30336
+ }
30337
+ if (hasValidToLineByCell) {
30338
+ const rawTo = partialRow.toLineByCell[cellIndex];
30339
+ if (typeof rawTo === "number") {
30340
+ toLine = rawTo === -1 ? totalLines : rawTo;
30341
+ }
30342
+ }
30343
+ }
30344
+ fromLine = Math.max(0, Math.min(fromLine, totalLines));
30345
+ toLine = Math.max(0, Math.min(toLine, totalLines));
30346
+ if (toLine < fromLine) {
30347
+ toLine = fromLine;
30348
+ }
30349
+ mergePmRange(range, computeCellPmRange(cell, cellMeasure, fromLine, toLine));
30350
+ }
30351
+ }
30352
+ return range;
30353
+ }
30354
+ function applyTableFragmentPmRange(fragment, block, measure) {
30355
+ const range = computeTableFragmentPmRange(block, measure, fragment.fromRow, fragment.toRow, fragment.partialRow);
30356
+ if (range.pmStart != null) {
30357
+ fragment.pmStart = range.pmStart;
30358
+ }
30359
+ if (range.pmEnd != null) {
30360
+ fragment.pmEnd = range.pmEnd;
30361
+ }
30362
+ }
30062
30363
  function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
30063
30364
  const row = measure.rows[rowIndex];
30064
30365
  if (!row) {
@@ -30203,6 +30504,7 @@ function layoutMonolithicTable(context) {
30203
30504
  height,
30204
30505
  metadata
30205
30506
  };
30507
+ applyTableFragmentPmRange(fragment, context.block, context.measure);
30206
30508
  state.page.fragments.push(fragment);
30207
30509
  state.cursorY += height;
30208
30510
  }
@@ -30281,6 +30583,7 @@ function layoutTableBlock({
30281
30583
  height,
30282
30584
  metadata
30283
30585
  };
30586
+ applyTableFragmentPmRange(fragment, block, measure);
30284
30587
  state.page.fragments.push(fragment);
30285
30588
  state.cursorY += height;
30286
30589
  return;
@@ -30344,6 +30647,7 @@ function layoutTableBlock({
30344
30647
  partialRow: continuationPartialRow,
30345
30648
  metadata: generateFragmentMetadata(measure)
30346
30649
  };
30650
+ applyTableFragmentPmRange(fragment2, block, measure);
30347
30651
  state.page.fragments.push(fragment2);
30348
30652
  state.cursorY += fragmentHeight2;
30349
30653
  }
@@ -30388,6 +30692,7 @@ function layoutTableBlock({
30388
30692
  partialRow: forcedPartialRow,
30389
30693
  metadata: generateFragmentMetadata(measure)
30390
30694
  };
30695
+ applyTableFragmentPmRange(fragment2, block, measure);
30391
30696
  state.page.fragments.push(fragment2);
30392
30697
  state.cursorY += fragmentHeight2;
30393
30698
  pendingPartialRow = forcedPartialRow;
@@ -30423,6 +30728,7 @@ function layoutTableBlock({
30423
30728
  partialRow: partialRow || void 0,
30424
30729
  metadata: generateFragmentMetadata(measure)
30425
30730
  };
30731
+ applyTableFragmentPmRange(fragment, block, measure);
30426
30732
  state.page.fragments.push(fragment);
30427
30733
  state.cursorY += fragmentHeight;
30428
30734
  if (partialRow && !partialRow.isLastPart) {
@@ -30440,7 +30746,7 @@ function createAnchoredTableFragment(block, measure, x, y) {
30440
30746
  columnBoundaries: generateColumnBoundaries(measure),
30441
30747
  coordinateSystem: "fragment"
30442
30748
  };
30443
- return {
30749
+ const fragment = {
30444
30750
  kind: "table",
30445
30751
  blockId: block.id,
30446
30752
  fromRow: 0,
@@ -30451,6 +30757,8 @@ function createAnchoredTableFragment(block, measure, x, y) {
30451
30757
  height: measure.totalHeight ?? 0,
30452
30758
  metadata
30453
30759
  };
30760
+ applyTableFragmentPmRange(fragment, block, measure);
30761
+ return fragment;
30454
30762
  }
30455
30763
  function isPageRelativeAnchor(block) {
30456
30764
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -30872,8 +31180,8 @@ function layoutDocument(blocks, measures, options = {}) {
30872
31180
  header: options.margins?.header ?? options.margins?.top ?? DEFAULT_MARGINS$2.top,
30873
31181
  footer: options.margins?.footer ?? options.margins?.bottom ?? DEFAULT_MARGINS$2.bottom
30874
31182
  };
30875
- const contentWidth = pageSize.w - (margins.left + margins.right);
30876
- if (contentWidth <= 0) {
31183
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
31184
+ if (baseContentWidth <= 0) {
30877
31185
  throw new Error("layoutDocument: pageSize and margins yield non-positive content area");
30878
31186
  }
30879
31187
  const validateContentHeight = (height) => {
@@ -30903,8 +31211,12 @@ function layoutDocument(blocks, measures, options = {}) {
30903
31211
  const effectiveBottomMargin = maxFooterContentHeight > 0 ? Math.max(margins.bottom, footerDistance + maxFooterContentHeight) : margins.bottom;
30904
31212
  let activeTopMargin = effectiveTopMargin;
30905
31213
  let activeBottomMargin = effectiveBottomMargin;
31214
+ let activeLeftMargin = margins.left;
31215
+ let activeRightMargin = margins.right;
30906
31216
  let pendingTopMargin = null;
30907
31217
  let pendingBottomMargin = null;
31218
+ let pendingLeftMargin = null;
31219
+ let pendingRightMargin = null;
30908
31220
  let activeHeaderDistance = margins.header ?? margins.top;
30909
31221
  let pendingHeaderDistance = null;
30910
31222
  let activeFooterDistance = margins.footer ?? margins.bottom;
@@ -30917,10 +31229,11 @@ function layoutDocument(blocks, measures, options = {}) {
30917
31229
  let pendingOrientation = null;
30918
31230
  let activeVAlign = null;
30919
31231
  let pendingVAlign = null;
31232
+ const paginatorMargins = { left: activeLeftMargin, right: activeRightMargin };
30920
31233
  const floatManager = createFloatingObjectManager(
30921
- normalizeColumns(activeColumns, contentWidth),
30922
- { left: margins.left, right: margins.right },
30923
- pageSize.w
31234
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
31235
+ { left: activeLeftMargin, right: activeRightMargin },
31236
+ activePageSize.w
30924
31237
  );
30925
31238
  const nextSectionPropsAtBreak = computeNextSectionPropsAtBreak(blocks);
30926
31239
  const scheduleSectionBreakCompat = (block, state, baseMargins) => {
@@ -30937,22 +31250,38 @@ function layoutDocument(blocks, measures, options = {}) {
30937
31250
  next.activeOrientation = block.orientation;
30938
31251
  next.pendingOrientation = null;
30939
31252
  }
31253
+ const headerDistance2 = typeof block.margins?.header === "number" ? Math.max(0, block.margins.header) : next.activeHeaderDistance;
31254
+ const footerDistance2 = typeof block.margins?.footer === "number" ? Math.max(0, block.margins.footer) : next.activeFooterDistance;
31255
+ const sectionTop = typeof block.margins?.top === "number" ? Math.max(0, block.margins.top) : baseMargins.top;
31256
+ const sectionBottom = typeof block.margins?.bottom === "number" ? Math.max(0, block.margins.bottom) : baseMargins.bottom;
30940
31257
  if (block.margins?.header !== void 0) {
30941
- const headerDist = Math.max(0, block.margins.header);
30942
- next.activeHeaderDistance = headerDist;
30943
- next.pendingHeaderDistance = headerDist;
30944
- const requiredTop = maxHeaderContentHeight > 0 ? headerDist + maxHeaderContentHeight : headerDist;
30945
- next.activeTopMargin = Math.max(baseMargins.top, requiredTop);
30946
- next.pendingTopMargin = next.activeTopMargin;
31258
+ next.activeHeaderDistance = headerDistance2;
31259
+ next.pendingHeaderDistance = headerDistance2;
30947
31260
  }
30948
31261
  if (block.margins?.footer !== void 0) {
30949
- const footerDistance2 = Math.max(0, block.margins.footer);
30950
31262
  next.activeFooterDistance = footerDistance2;
30951
31263
  next.pendingFooterDistance = footerDistance2;
31264
+ }
31265
+ if (block.margins?.top !== void 0 || block.margins?.header !== void 0) {
31266
+ const requiredTop = maxHeaderContentHeight > 0 ? headerDistance2 + maxHeaderContentHeight : headerDistance2;
31267
+ next.activeTopMargin = Math.max(sectionTop, requiredTop);
31268
+ next.pendingTopMargin = next.activeTopMargin;
31269
+ }
31270
+ if (block.margins?.bottom !== void 0 || block.margins?.footer !== void 0) {
30952
31271
  const requiredBottom = maxFooterContentHeight > 0 ? footerDistance2 + maxFooterContentHeight : footerDistance2;
30953
- next.activeBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
31272
+ next.activeBottomMargin = Math.max(sectionBottom, requiredBottom);
30954
31273
  next.pendingBottomMargin = next.activeBottomMargin;
30955
31274
  }
31275
+ if (block.margins?.left !== void 0) {
31276
+ const leftMargin = Math.max(0, block.margins.left);
31277
+ next.activeLeftMargin = leftMargin;
31278
+ next.pendingLeftMargin = leftMargin;
31279
+ }
31280
+ if (block.margins?.right !== void 0) {
31281
+ const rightMargin = Math.max(0, block.margins.right);
31282
+ next.activeRightMargin = rightMargin;
31283
+ next.pendingRightMargin = rightMargin;
31284
+ }
30956
31285
  if (block.columns) {
30957
31286
  next.activeColumns = { count: block.columns.count, gap: block.columns.gap };
30958
31287
  next.pendingColumns = null;
@@ -30981,27 +31310,35 @@ function layoutDocument(blocks, measures, options = {}) {
30981
31310
  const headerPx = block.margins?.header;
30982
31311
  const footerPx = block.margins?.footer;
30983
31312
  const topPx = block.margins?.top;
31313
+ const bottomPx = block.margins?.bottom;
31314
+ const leftPx = block.margins?.left;
31315
+ const rightPx = block.margins?.right;
30984
31316
  const nextTop = next.pendingTopMargin ?? next.activeTopMargin;
30985
31317
  const nextBottom = next.pendingBottomMargin ?? next.activeBottomMargin;
31318
+ const nextLeft = next.pendingLeftMargin ?? next.activeLeftMargin;
31319
+ const nextRight = next.pendingRightMargin ?? next.activeRightMargin;
30986
31320
  const nextHeader = next.pendingHeaderDistance ?? next.activeHeaderDistance;
30987
31321
  const nextFooter = next.pendingFooterDistance ?? next.activeFooterDistance;
30988
31322
  next.pendingHeaderDistance = typeof headerPx === "number" ? Math.max(0, headerPx) : nextHeader;
30989
31323
  next.pendingFooterDistance = typeof footerPx === "number" ? Math.max(0, footerPx) : nextFooter;
30990
31324
  if (typeof headerPx === "number" || typeof topPx === "number") {
30991
- const sectionTop = topPx ?? baseMargins.top;
31325
+ const sectionTop = typeof topPx === "number" ? Math.max(0, topPx) : baseMargins.top;
30992
31326
  const sectionHeader = next.pendingHeaderDistance;
30993
31327
  const requiredTop = maxHeaderContentHeight > 0 ? sectionHeader + maxHeaderContentHeight : sectionHeader;
30994
31328
  next.pendingTopMargin = Math.max(sectionTop, requiredTop);
30995
31329
  } else {
30996
31330
  next.pendingTopMargin = nextTop;
30997
31331
  }
30998
- if (typeof footerPx === "number") {
31332
+ if (typeof footerPx === "number" || typeof bottomPx === "number") {
30999
31333
  const sectionFooter = next.pendingFooterDistance;
31334
+ const sectionBottom = typeof bottomPx === "number" ? Math.max(0, bottomPx) : baseMargins.bottom;
31000
31335
  const requiredBottom = maxFooterContentHeight > 0 ? sectionFooter + maxFooterContentHeight : sectionFooter;
31001
- next.pendingBottomMargin = Math.max(baseMargins.bottom, requiredBottom);
31336
+ next.pendingBottomMargin = Math.max(sectionBottom, requiredBottom);
31002
31337
  } else {
31003
31338
  next.pendingBottomMargin = nextBottom;
31004
31339
  }
31340
+ next.pendingLeftMargin = typeof leftPx === "number" ? Math.max(0, leftPx) : nextLeft;
31341
+ next.pendingRightMargin = typeof rightPx === "number" ? Math.max(0, rightPx) : nextRight;
31005
31342
  if (block.pageSize) next.pendingPageSize = { w: block.pageSize.w, h: block.pageSize.h };
31006
31343
  if (block.orientation) next.pendingOrientation = block.orientation;
31007
31344
  const sectionType = block.type ?? "continuous";
@@ -31086,7 +31423,7 @@ function layoutDocument(blocks, measures, options = {}) {
31086
31423
  let activeSectionIndex = initialSectionMetadata?.sectionIndex ?? 0;
31087
31424
  let pendingSectionIndex = null;
31088
31425
  const paginator = createPaginator({
31089
- margins: { left: margins.left, right: margins.right },
31426
+ margins: paginatorMargins,
31090
31427
  getActiveTopMargin: () => activeTopMargin,
31091
31428
  getActiveBottomMargin: () => activeBottomMargin,
31092
31429
  getActiveHeaderDistance: () => activeHeaderDistance,
@@ -31101,8 +31438,12 @@ function layoutDocument(blocks, measures, options = {}) {
31101
31438
  const applied = applyPendingToActive({
31102
31439
  activeTopMargin,
31103
31440
  activeBottomMargin,
31441
+ activeLeftMargin,
31442
+ activeRightMargin,
31104
31443
  pendingTopMargin,
31105
31444
  pendingBottomMargin,
31445
+ pendingLeftMargin,
31446
+ pendingRightMargin,
31106
31447
  activeHeaderDistance,
31107
31448
  activeFooterDistance,
31108
31449
  pendingHeaderDistance,
@@ -31117,8 +31458,12 @@ function layoutDocument(blocks, measures, options = {}) {
31117
31458
  });
31118
31459
  activeTopMargin = applied.activeTopMargin;
31119
31460
  activeBottomMargin = applied.activeBottomMargin;
31461
+ activeLeftMargin = applied.activeLeftMargin;
31462
+ activeRightMargin = applied.activeRightMargin;
31120
31463
  pendingTopMargin = applied.pendingTopMargin;
31121
31464
  pendingBottomMargin = applied.pendingBottomMargin;
31465
+ pendingLeftMargin = applied.pendingLeftMargin;
31466
+ pendingRightMargin = applied.pendingRightMargin;
31122
31467
  activeHeaderDistance = applied.activeHeaderDistance;
31123
31468
  activeFooterDistance = applied.activeFooterDistance;
31124
31469
  pendingHeaderDistance = applied.pendingHeaderDistance;
@@ -31130,6 +31475,14 @@ function layoutDocument(blocks, measures, options = {}) {
31130
31475
  activeOrientation = applied.activeOrientation;
31131
31476
  pendingOrientation = applied.pendingOrientation;
31132
31477
  cachedColumnsState.state = null;
31478
+ paginatorMargins.left = activeLeftMargin;
31479
+ paginatorMargins.right = activeRightMargin;
31480
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31481
+ floatManager.setLayoutContext(
31482
+ normalizeColumns(activeColumns, contentWidth),
31483
+ { left: activeLeftMargin, right: activeRightMargin },
31484
+ activePageSize.w
31485
+ );
31133
31486
  if (pendingNumbering) {
31134
31487
  if (pendingNumbering.format) activeNumberFormat = pendingNumbering.format;
31135
31488
  if (typeof pendingNumbering.start === "number" && Number.isFinite(pendingNumbering.start)) {
@@ -31174,7 +31527,7 @@ function layoutDocument(blocks, measures, options = {}) {
31174
31527
  const getActiveColumnsForState = paginator.getActiveColumnsForState;
31175
31528
  let cachedColumnsState = { state: null, constraintIndex: -2, contentWidth: -1, colsConfig: null, normalized: null };
31176
31529
  const getCurrentColumns = () => {
31177
- const currentContentWidth = activePageSize.w - (margins.left + margins.right);
31530
+ const currentContentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31178
31531
  const state = states[states.length - 1] ?? null;
31179
31532
  const colsConfig = state ? getActiveColumnsForState(state) : activeColumns;
31180
31533
  const constraintIndex = state ? state.activeConstraintIndex : -1;
@@ -31207,6 +31560,12 @@ function layoutDocument(blocks, measures, options = {}) {
31207
31560
  layoutLog(` Current page: ${state.page.number}, cursorY: ${state.cursorY}`);
31208
31561
  activeColumns = newColumns;
31209
31562
  cachedColumnsState.state = null;
31563
+ const contentWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31564
+ floatManager.setLayoutContext(
31565
+ normalizeColumns(activeColumns, contentWidth),
31566
+ { left: activeLeftMargin, right: activeRightMargin },
31567
+ activePageSize.w
31568
+ );
31210
31569
  };
31211
31570
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
31212
31571
  const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
@@ -31238,10 +31597,10 @@ function layoutDocument(blocks, measures, options = {}) {
31238
31597
  if (alignV === "top") {
31239
31598
  anchorY = offsetV;
31240
31599
  } else if (alignV === "bottom") {
31241
- const pageHeight = contentBottom + margins.bottom;
31600
+ const pageHeight = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin);
31242
31601
  anchorY = pageHeight - imageHeight + offsetV;
31243
31602
  } else if (alignV === "center") {
31244
- const pageHeight = contentBottom + margins.bottom;
31603
+ const pageHeight = contentBottom + (state.page.margins?.bottom ?? activeBottomMargin);
31245
31604
  anchorY = (pageHeight - imageHeight) / 2 + offsetV;
31246
31605
  } else {
31247
31606
  anchorY = offsetV;
@@ -31252,11 +31611,11 @@ function layoutDocument(blocks, measures, options = {}) {
31252
31611
  const anchorX = entry.block.anchor ? computeAnchorX(
31253
31612
  entry.block.anchor,
31254
31613
  state.columnIndex,
31255
- normalizeColumns(activeColumns, contentWidth),
31614
+ normalizeColumns(activeColumns, activePageSize.w - (activeLeftMargin + activeRightMargin)),
31256
31615
  entry.measure.width,
31257
- { left: margins.left, right: margins.right },
31616
+ { left: activeLeftMargin, right: activeRightMargin },
31258
31617
  activePageSize.w
31259
- ) : margins.left;
31618
+ ) : activeLeftMargin;
31260
31619
  floatManager.registerDrawing(entry.block, entry.measure, anchorY, state.columnIndex, state.page.number);
31261
31620
  preRegisteredPositions.set(entry.block.id, { anchorX, anchorY, pageNumber: state.page.number });
31262
31621
  }
@@ -31294,8 +31653,12 @@ function layoutDocument(blocks, measures, options = {}) {
31294
31653
  const sectionState = {
31295
31654
  activeTopMargin,
31296
31655
  activeBottomMargin,
31656
+ activeLeftMargin,
31657
+ activeRightMargin,
31297
31658
  pendingTopMargin,
31298
31659
  pendingBottomMargin,
31660
+ pendingLeftMargin,
31661
+ pendingRightMargin,
31299
31662
  activeHeaderDistance,
31300
31663
  activeFooterDistance,
31301
31664
  pendingHeaderDistance,
@@ -31329,8 +31692,12 @@ function layoutDocument(blocks, measures, options = {}) {
31329
31692
  layoutLog(`[Layout] ========== END SECTION BREAK ==========`);
31330
31693
  activeTopMargin = updatedState.activeTopMargin;
31331
31694
  activeBottomMargin = updatedState.activeBottomMargin;
31695
+ activeLeftMargin = updatedState.activeLeftMargin;
31696
+ activeRightMargin = updatedState.activeRightMargin;
31332
31697
  pendingTopMargin = updatedState.pendingTopMargin;
31333
31698
  pendingBottomMargin = updatedState.pendingBottomMargin;
31699
+ pendingLeftMargin = updatedState.pendingLeftMargin;
31700
+ pendingRightMargin = updatedState.pendingRightMargin;
31334
31701
  activeHeaderDistance = updatedState.activeHeaderDistance;
31335
31702
  activeFooterDistance = updatedState.activeFooterDistance;
31336
31703
  pendingHeaderDistance = updatedState.pendingHeaderDistance;
@@ -31468,8 +31835,8 @@ function layoutDocument(blocks, measures, options = {}) {
31468
31835
  pageMargins: {
31469
31836
  top: activeTopMargin,
31470
31837
  bottom: activeBottomMargin,
31471
- left: margins.left,
31472
- right: margins.right
31838
+ left: activeLeftMargin,
31839
+ right: activeRightMargin
31473
31840
  },
31474
31841
  columns: getCurrentColumns(),
31475
31842
  placedAnchoredIds
@@ -31491,9 +31858,9 @@ function layoutDocument(blocks, measures, options = {}) {
31491
31858
  const cols = getCurrentColumns();
31492
31859
  let maxWidth;
31493
31860
  if (relativeFrom === "page") {
31494
- maxWidth = cols.count === 1 ? activePageSize.w - margins.left - margins.right : activePageSize.w;
31861
+ maxWidth = cols.count === 1 ? activePageSize.w - (activeLeftMargin + activeRightMargin) : activePageSize.w;
31495
31862
  } else if (relativeFrom === "margin") {
31496
- maxWidth = activePageSize.w - margins.left - margins.right;
31863
+ maxWidth = activePageSize.w - (activeLeftMargin + activeRightMargin);
31497
31864
  } else {
31498
31865
  maxWidth = cols.width;
31499
31866
  }
@@ -32680,11 +33047,11 @@ function findWordBoundaries(blocks, pos) {
32680
33047
  if (text.length === 0) return null;
32681
33048
  const clampedPos = Math.max(0, Math.min(localPos, text.length));
32682
33049
  let wordStart = clampedPos;
32683
- while (wordStart > 0 && isWordChar(text[wordStart - 1])) {
33050
+ while (wordStart > 0 && isWordChar$2(text[wordStart - 1])) {
32684
33051
  wordStart--;
32685
33052
  }
32686
33053
  let wordEnd = clampedPos;
32687
- while (wordEnd < text.length && isWordChar(text[wordEnd])) {
33054
+ while (wordEnd < text.length && isWordChar$2(text[wordEnd])) {
32688
33055
  wordEnd++;
32689
33056
  }
32690
33057
  if (wordStart === wordEnd) {
@@ -32747,7 +33114,7 @@ function findBlockAtPosition(blocks, pos) {
32747
33114
  }
32748
33115
  return null;
32749
33116
  }
32750
- function isWordChar(char) {
33117
+ function isWordChar$2(char) {
32751
33118
  return /[\p{L}\p{N}_]/u.test(char);
32752
33119
  }
32753
33120
  function isWhitespace(char) {
@@ -32782,6 +33149,29 @@ function fontString(run) {
32782
33149
  function runText(run) {
32783
33150
  return "src" in run || run.kind === "lineBreak" || run.kind === "break" || run.kind === "fieldAnnotation" ? "" : run.text ?? "";
32784
33151
  }
33152
+ const isWordChar$1 = (char) => {
33153
+ if (!char) return false;
33154
+ const code = char.charCodeAt(0);
33155
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
33156
+ };
33157
+ const capitalizeText$1 = (text, fullText, startOffset) => {
33158
+ if (!text) return text;
33159
+ const hasFullText = typeof startOffset === "number" && fullText != null;
33160
+ let result = "";
33161
+ for (let i = 0; i < text.length; i += 1) {
33162
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
33163
+ const ch = text[i];
33164
+ result += isWordChar$1(ch) && !isWordChar$1(prevChar) ? ch.toUpperCase() : ch;
33165
+ }
33166
+ return result;
33167
+ };
33168
+ const applyTextTransform$1 = (text, transform, fullText, startOffset) => {
33169
+ if (!text || !transform || transform === "none") return text;
33170
+ if (transform === "uppercase") return text.toUpperCase();
33171
+ if (transform === "lowercase") return text.toLowerCase();
33172
+ if (transform === "capitalize") return capitalizeText$1(text, fullText, startOffset);
33173
+ return text;
33174
+ };
32785
33175
  const DEFAULT_TAB_INTERVAL_TWIPS$1 = 720;
32786
33176
  const TWIPS_PER_INCH$4 = 1440;
32787
33177
  const PX_PER_INCH$3 = 96;
@@ -32790,6 +33180,13 @@ const TAB_EPSILON$1 = 0.1;
32790
33180
  const WIDTH_FUDGE_PX = 0.5;
32791
33181
  const twipsToPx$2 = (twips) => twips / TWIPS_PER_PX$1;
32792
33182
  const pxToTwips$1 = (px) => Math.round(px * TWIPS_PER_PX$1);
33183
+ const markerFontString = (run) => {
33184
+ const size2 = run?.fontSize ?? 16;
33185
+ const family = run?.fontFamily ?? "Arial";
33186
+ const italic = run?.italic ? "italic " : "";
33187
+ const bold = run?.bold ? "bold " : "";
33188
+ return `${italic}${bold}${size2}px ${family}`.trim();
33189
+ };
32793
33190
  const buildTabStopsPx$1 = (indent, tabs, tabIntervalTwips) => {
32794
33191
  const paragraphIndentTwips = {
32795
33192
  left: pxToTwips$1(Math.max(0, indent?.left ?? 0)),
@@ -32820,7 +33217,9 @@ const getNextTabStopPx$1 = (currentX, tabStops, startIndex) => {
32820
33217
  };
32821
33218
  function measureRunSliceWidth(run, fromChar, toChar) {
32822
33219
  const context = getCtx();
32823
- const text = runText(run).slice(fromChar, toChar);
33220
+ const fullText = runText(run);
33221
+ const transform = isTextRun$2(run) ? run.textTransform : void 0;
33222
+ const text = applyTextTransform$1(fullText.slice(fromChar, toChar), transform, fullText, fromChar);
32824
33223
  if (!context) {
32825
33224
  const textRun = isTextRun$2(run) ? run : null;
32826
33225
  const size2 = textRun?.fontSize ?? 16;
@@ -32866,8 +33265,21 @@ function remeasureParagraph(block, maxWidth, firstLineIndent = 0) {
32866
33265
  const contentWidth = Math.max(1, maxWidth - indentLeft - indentRight);
32867
33266
  const markerTextStartX = wordLayout?.marker?.textStartX;
32868
33267
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
32869
- const treatAsHanging = textStartPx && indentLeft === 0 && indentHanging === 0;
32870
- const firstLineWidth = typeof textStartPx === "number" && textStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - textStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
33268
+ const resolvedTextStartPx = resolveListTextStartPx(
33269
+ wordLayout,
33270
+ indentLeft,
33271
+ indentFirstLine,
33272
+ indentHanging,
33273
+ (markerText, marker) => {
33274
+ const context = getCtx();
33275
+ if (!context) return 0;
33276
+ context.font = markerFontString(marker.run);
33277
+ return context.measureText(markerText).width;
33278
+ }
33279
+ );
33280
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
33281
+ const treatAsHanging = !wordLayout?.marker && effectiveTextStartPx && indentLeft === 0 && indentHanging === 0;
33282
+ const firstLineWidth = typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft && !treatAsHanging ? Math.max(1, maxWidth - effectiveTextStartPx - indentRight) : Math.max(1, contentWidth - rawFirstLineOffset);
32871
33283
  const tabStops = buildTabStopsPx$1(indent, attrs?.tabs, attrs?.tabIntervalTwips);
32872
33284
  let currentRun = 0;
32873
33285
  let currentChar = 0;
@@ -33407,7 +33819,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33407
33819
  if (dirty.deletedBlockIds.length > 0) {
33408
33820
  measureCache.invalidate(dirty.deletedBlockIds);
33409
33821
  }
33410
- const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options);
33822
+ const { measurementWidth, measurementHeight } = resolveMeasurementConstraints(options, nextBlocks);
33411
33823
  if (measurementWidth <= 0 || measurementHeight <= 0) {
33412
33824
  throw new Error("incrementalLayout: invalid measurement constraints resolved from options");
33413
33825
  }
@@ -33676,7 +34088,7 @@ async function incrementalLayout(previousBlocks, _previousLayout, nextBlocks, op
33676
34088
  const DEFAULT_PAGE_SIZE$1 = { w: 612, h: 792 };
33677
34089
  const DEFAULT_MARGINS$1 = { top: 72, right: 72, bottom: 72, left: 72 };
33678
34090
  const normalizeMargin = (value, fallback) => Number.isFinite(value) ? value : fallback;
33679
- function resolveMeasurementConstraints(options) {
34091
+ function resolveMeasurementConstraints(options, blocks) {
33680
34092
  const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE$1;
33681
34093
  const margins = {
33682
34094
  top: normalizeMargin(options.margins?.top, DEFAULT_MARGINS$1.top),
@@ -33684,23 +34096,41 @@ function resolveMeasurementConstraints(options) {
33684
34096
  bottom: normalizeMargin(options.margins?.bottom, DEFAULT_MARGINS$1.bottom),
33685
34097
  left: normalizeMargin(options.margins?.left, DEFAULT_MARGINS$1.left)
33686
34098
  };
33687
- const contentWidth = pageSize.w - (margins.left + margins.right);
33688
- const contentHeight = pageSize.h - (margins.top + margins.bottom);
33689
- const columns = options.columns;
33690
- if (columns && columns.count > 1) {
34099
+ const baseContentWidth = pageSize.w - (margins.left + margins.right);
34100
+ const baseContentHeight = pageSize.h - (margins.top + margins.bottom);
34101
+ const computeColumnWidth = (contentWidth, columns) => {
34102
+ if (!columns || columns.count <= 1) return contentWidth;
33691
34103
  const gap = Math.max(0, columns.gap ?? 0);
33692
34104
  const totalGap = gap * (columns.count - 1);
33693
- const columnWidth = (contentWidth - totalGap) / columns.count;
33694
- if (columnWidth > 0) {
33695
- return {
33696
- measurementWidth: columnWidth,
33697
- measurementHeight: contentHeight
34105
+ return (contentWidth - totalGap) / columns.count;
34106
+ };
34107
+ let measurementWidth = computeColumnWidth(baseContentWidth, options.columns);
34108
+ let measurementHeight = baseContentHeight;
34109
+ if (blocks && blocks.length > 0) {
34110
+ for (const block of blocks) {
34111
+ if (block.kind !== "sectionBreak") continue;
34112
+ const sectionPageSize = block.pageSize ?? pageSize;
34113
+ const sectionMargins = {
34114
+ top: normalizeMargin(block.margins?.top, margins.top),
34115
+ right: normalizeMargin(block.margins?.right, margins.right),
34116
+ bottom: normalizeMargin(block.margins?.bottom, margins.bottom),
34117
+ left: normalizeMargin(block.margins?.left, margins.left)
33698
34118
  };
34119
+ const contentWidth = sectionPageSize.w - (sectionMargins.left + sectionMargins.right);
34120
+ const contentHeight = sectionPageSize.h - (sectionMargins.top + sectionMargins.bottom);
34121
+ if (contentWidth <= 0 || contentHeight <= 0) continue;
34122
+ const columnWidth = computeColumnWidth(contentWidth, block.columns ?? options.columns);
34123
+ if (columnWidth > measurementWidth) {
34124
+ measurementWidth = columnWidth;
34125
+ }
34126
+ if (contentHeight > measurementHeight) {
34127
+ measurementHeight = contentHeight;
34128
+ }
33699
34129
  }
33700
34130
  }
33701
34131
  return {
33702
- measurementWidth: contentWidth,
33703
- measurementHeight: contentHeight
34132
+ measurementWidth,
34133
+ measurementHeight
33704
34134
  };
33705
34135
  }
33706
34136
  const serializeHeaderFooterResults = (kind, batch) => {
@@ -36159,14 +36589,15 @@ function getAtomNodeTypes(schema) {
36159
36589
  if (!schema) return [];
36160
36590
  const types = [];
36161
36591
  try {
36162
- schema.nodes.forEach((nodeType, name) => {
36592
+ for (const name in schema.nodes) {
36163
36593
  if (name === "text") {
36164
- return;
36594
+ continue;
36165
36595
  }
36166
- if (nodeType.isAtom || nodeType.isLeaf) {
36596
+ const nodeType = schema.nodes[name];
36597
+ if (nodeType && (nodeType.isAtom || nodeType.isLeaf)) {
36167
36598
  types.push(name);
36168
36599
  }
36169
- });
36600
+ }
36170
36601
  } catch {
36171
36602
  return [];
36172
36603
  }
@@ -39747,8 +40178,8 @@ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
39747
40178
  }
39748
40179
  return void 0;
39749
40180
  }
39750
- const DEFAULT_LIST_HANGING_PX$1 = 18;
39751
- const LIST_MARKER_GAP$1 = 8;
40181
+ const DEFAULT_LIST_HANGING_PX = 18;
40182
+ const LIST_MARKER_GAP = 8;
39752
40183
  const DEFAULT_BULLET_GLYPH = "•";
39753
40184
  const DEFAULT_DECIMAL_PATTERN = "%1.";
39754
40185
  const ASCII_UPPERCASE_A = 65;
@@ -40159,7 +40590,7 @@ function computeWordParagraphLayout(input) {
40159
40590
  let markerBoxWidthPx;
40160
40591
  let markerX;
40161
40592
  if (hasFirstLineIndent) {
40162
- markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP$1 : DEFAULT_LIST_HANGING_PX$1;
40593
+ markerBoxWidthPx = glyphWidthPx != null && glyphWidthPx > 0 ? glyphWidthPx + LIST_MARKER_GAP : DEFAULT_LIST_HANGING_PX;
40163
40594
  markerX = indentLeftPx + (firstLinePx ?? 0);
40164
40595
  layout.textStartPx = markerX + markerBoxWidthPx;
40165
40596
  layout.hangingPx = 0;
@@ -40259,12 +40690,12 @@ const resolveMarkerBoxWidth = (hangingPxRaw, glyphWidthPx) => {
40259
40690
  let markerBox = Math.max(hangingPxRaw || 0, 0);
40260
40691
  if (markerBox <= 0) {
40261
40692
  if (glyphWidthPx != null && glyphWidthPx > 0) {
40262
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
40693
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
40263
40694
  } else {
40264
- markerBox = DEFAULT_LIST_HANGING_PX$1;
40695
+ markerBox = DEFAULT_LIST_HANGING_PX;
40265
40696
  }
40266
- } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP$1 > markerBox) {
40267
- markerBox = glyphWidthPx + LIST_MARKER_GAP$1;
40697
+ } else if (glyphWidthPx != null && glyphWidthPx + LIST_MARKER_GAP > markerBox) {
40698
+ markerBox = glyphWidthPx + LIST_MARKER_GAP;
40268
40699
  }
40269
40700
  return markerBox;
40270
40701
  };
@@ -40284,7 +40715,7 @@ const buildMarkerLayout = ({
40284
40715
  textStartX: textStartPx,
40285
40716
  baselineOffsetPx: markerRun.baselineShift ?? 0,
40286
40717
  // Gutter is the small gap between marker and text, not the full marker box width
40287
- gutterWidthPx: LIST_MARKER_GAP$1,
40718
+ gutterWidthPx: LIST_MARKER_GAP,
40288
40719
  justification: numbering.lvlJc ?? "left",
40289
40720
  suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
40290
40721
  run: markerRun,
@@ -40976,6 +41407,31 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
40976
41407
  return null;
40977
41408
  }
40978
41409
  };
41410
+ const normalizeWordLayoutForIndent = (wordLayout, paragraphIndent) => {
41411
+ const resolvedIndent = wordLayout.resolvedIndent ?? paragraphIndent ?? {};
41412
+ const indentLeft = isFiniteNumber(resolvedIndent.left) ? resolvedIndent.left : 0;
41413
+ const firstLine = isFiniteNumber(resolvedIndent.firstLine) ? resolvedIndent.firstLine : 0;
41414
+ const hanging = isFiniteNumber(resolvedIndent.hanging) ? resolvedIndent.hanging : 0;
41415
+ const shouldFirstLineIndentMode = firstLine > 0 && !hanging;
41416
+ if (wordLayout.firstLineIndentMode === true && !shouldFirstLineIndentMode) {
41417
+ wordLayout.firstLineIndentMode = false;
41418
+ }
41419
+ if (wordLayout.firstLineIndentMode === true) {
41420
+ if (isFiniteNumber(wordLayout.textStartPx)) {
41421
+ if (wordLayout.marker && (!isFiniteNumber(wordLayout.marker.textStartX) || wordLayout.marker.textStartX !== wordLayout.textStartPx)) {
41422
+ wordLayout.marker.textStartX = wordLayout.textStartPx;
41423
+ }
41424
+ } else if (wordLayout.marker && isFiniteNumber(wordLayout.marker.textStartX)) {
41425
+ wordLayout.textStartPx = wordLayout.marker.textStartX;
41426
+ }
41427
+ } else {
41428
+ wordLayout.textStartPx = indentLeft;
41429
+ if (wordLayout.marker) {
41430
+ wordLayout.marker.textStartX = indentLeft;
41431
+ }
41432
+ }
41433
+ return wordLayout;
41434
+ };
40979
41435
  const computeParagraphAttrs = (para, styleContext, listCounterContext, converterContext, hydrationOverride) => {
40980
41436
  const attrs = para.attrs ?? {};
40981
41437
  const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
@@ -41298,8 +41754,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41298
41754
  let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
41299
41755
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
41300
41756
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
41301
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
41302
- if (firstLinePx > 0) {
41757
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
41758
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
41759
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
41760
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
41761
+ if (firstLinePx > 0 && !hangingPx) {
41303
41762
  wordLayout = {
41304
41763
  // Treat as first-line-indent mode: text starts after the marker+firstLine offset.
41305
41764
  firstLineIndentMode: true,
@@ -41307,10 +41766,13 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41307
41766
  };
41308
41767
  }
41309
41768
  }
41310
- if (wordLayout && (!wordLayout.textStartPx || !Number.isFinite(wordLayout.textStartPx)) && enrichedNumberingProps.resolvedLevelIndent) {
41769
+ if (wordLayout && !Number.isFinite(wordLayout.textStartPx) && enrichedNumberingProps.resolvedLevelIndent) {
41311
41770
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
41312
- const firstLinePx = resolvedIndentPx?.firstLine ?? 0;
41313
- if (firstLinePx > 0) {
41771
+ const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
41772
+ const mergedIndent = { ...baseIndent, ...paragraphAttrs.indent ?? {} };
41773
+ const firstLinePx = isFiniteNumber(mergedIndent.firstLine) ? mergedIndent.firstLine : 0;
41774
+ const hangingPx = isFiniteNumber(mergedIndent.hanging) ? mergedIndent.hanging : 0;
41775
+ if (firstLinePx > 0 && !hangingPx) {
41314
41776
  wordLayout = {
41315
41777
  ...wordLayout,
41316
41778
  firstLineIndentMode: wordLayout.firstLineIndentMode ?? true,
@@ -41330,6 +41792,7 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
41330
41792
  wordLayout.marker.suffix = listRendering.suffix;
41331
41793
  }
41332
41794
  }
41795
+ wordLayout = normalizeWordLayoutForIndent(wordLayout, paragraphAttrs.indent);
41333
41796
  paragraphAttrs.wordLayout = wordLayout;
41334
41797
  }
41335
41798
  if (enrichedNumberingProps.resolvedLevelIndent) {
@@ -45563,11 +46026,6 @@ function initHeaderFooterRegistry({
45563
46026
  cleanups
45564
46027
  };
45565
46028
  }
45566
- const LIST_MARKER_GAP = 8;
45567
- const MIN_MARKER_GUTTER = 24;
45568
- const DEFAULT_LIST_INDENT_BASE_PX = 24;
45569
- const DEFAULT_LIST_INDENT_STEP_PX = 24;
45570
- const DEFAULT_LIST_HANGING_PX = 18;
45571
46029
  function calculateRotatedBounds(input) {
45572
46030
  const width = Math.max(0, input.width);
45573
46031
  const height = Math.max(0, input.height);
@@ -45831,8 +46289,25 @@ async function measureParagraphBlock(block, maxWidth) {
45831
46289
  const rawTextStartPx = wordLayout?.textStartPx;
45832
46290
  const markerTextStartX = wordLayout?.marker?.textStartX;
45833
46291
  const textStartPx = typeof markerTextStartX === "number" && Number.isFinite(markerTextStartX) ? markerTextStartX : typeof rawTextStartPx === "number" && Number.isFinite(rawTextStartPx) ? rawTextStartPx : void 0;
45834
- if (typeof textStartPx === "number" && textStartPx > indentLeft) {
45835
- initialAvailableWidth = Math.max(1, maxWidth - textStartPx - indentRight);
46292
+ const resolvedTextStartPx = resolveListTextStartPx(
46293
+ wordLayout,
46294
+ indentLeft,
46295
+ firstLine,
46296
+ hanging,
46297
+ (markerText, marker) => {
46298
+ const markerRun = {
46299
+ fontFamily: toCssFontFamily(marker.run?.fontFamily) ?? marker.run?.fontFamily ?? "Arial",
46300
+ fontSize: marker.run?.fontSize ?? 16,
46301
+ bold: marker.run?.bold ?? false,
46302
+ italic: marker.run?.italic ?? false
46303
+ };
46304
+ const { font: markerFont } = buildFontString(markerRun);
46305
+ return measureText(markerText, markerFont, ctx2);
46306
+ }
46307
+ );
46308
+ const effectiveTextStartPx = resolvedTextStartPx ?? textStartPx;
46309
+ if (typeof effectiveTextStartPx === "number" && effectiveTextStartPx > indentLeft) {
46310
+ initialAvailableWidth = Math.max(1, maxWidth - effectiveTextStartPx - indentRight);
45836
46311
  } else {
45837
46312
  initialAvailableWidth = Math.max(1, contentWidth - firstLineOffset);
45838
46313
  }
@@ -45919,7 +46394,7 @@ async function measureParagraphBlock(block, maxWidth) {
45919
46394
  pendingTabAlignment = null;
45920
46395
  return startX;
45921
46396
  };
45922
- const alignSegmentAtTab = (segmentText, font, runContext) => {
46397
+ const alignSegmentAtTab = (segmentText, font, runContext, segmentStartChar) => {
45923
46398
  if (!pendingTabAlignment || !currentLine) return void 0;
45924
46399
  const { val } = pendingTabAlignment;
45925
46400
  let segmentWidth = 0;
@@ -45928,11 +46403,11 @@ async function measureParagraphBlock(block, maxWidth) {
45928
46403
  const idx = segmentText.indexOf(decimalSeparator);
45929
46404
  if (idx >= 0) {
45930
46405
  const beforeText = segmentText.slice(0, idx);
45931
- beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext) : 0;
46406
+ beforeDecimalWidth = beforeText.length > 0 ? measureRunWidth(beforeText, font, ctx2, runContext, segmentStartChar) : 0;
45932
46407
  }
45933
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
46408
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
45934
46409
  } else if (val === "end" || val === "center") {
45935
- segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext) : 0;
46410
+ segmentWidth = segmentText.length > 0 ? measureRunWidth(segmentText, font, ctx2, runContext, segmentStartChar) : 0;
45936
46411
  }
45937
46412
  return alignPendingTabForWidth(segmentWidth, beforeDecimalWidth);
45938
46413
  };
@@ -45984,8 +46459,8 @@ async function measureParagraphBlock(block, maxWidth) {
45984
46459
  const { font } = buildFontString(
45985
46460
  lastRun
45986
46461
  );
45987
- const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun);
45988
- const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun) : 0;
46462
+ const fullWidth = measureRunWidth(sliceText, font, ctx2, lastRun, sliceStart);
46463
+ const keptWidth = keptText.length > 0 ? measureRunWidth(keptText, font, ctx2, lastRun, sliceStart) : 0;
45989
46464
  const delta = Math.max(0, fullWidth - keptWidth);
45990
46465
  lineToTrim.width = roundValue(Math.max(0, lineToTrim.width - delta));
45991
46466
  lineToTrim.spaceCount = Math.max(0, lineToTrim.spaceCount - trimCount);
@@ -46196,7 +46671,8 @@ async function measureParagraphBlock(block, maxWidth) {
46196
46671
  continue;
46197
46672
  }
46198
46673
  if (isFieldAnnotationRun(run)) {
46199
- const displayText = run.displayLabel || "";
46674
+ const rawDisplayText = run.displayLabel || "";
46675
+ const displayText = applyTextTransform(rawDisplayText, run);
46200
46676
  const annotationFontSize = typeof run.fontSize === "number" ? run.fontSize : typeof run.fontSize === "string" ? parseFloat(run.fontSize) || DEFAULT_FIELD_ANNOTATION_FONT_SIZE : DEFAULT_FIELD_ANNOTATION_FONT_SIZE;
46201
46677
  const annotationFontFamily = run.fontFamily || "Arial, sans-serif";
46202
46678
  const fontWeight = run.bold ? "bold" : "normal";
@@ -46299,7 +46775,7 @@ async function measureParagraphBlock(block, maxWidth) {
46299
46775
  const spacesLength = segment.length;
46300
46776
  const spacesStartChar = charPosInRun;
46301
46777
  const spacesEndChar = charPosInRun + spacesLength;
46302
- const spacesWidth = measureRunWidth(segment, font, ctx2, run);
46778
+ const spacesWidth = measureRunWidth(segment, font, ctx2, run, spacesStartChar);
46303
46779
  if (!currentLine) {
46304
46780
  currentLine = {
46305
46781
  fromRun: runIndex,
@@ -46363,7 +46839,7 @@ async function measureParagraphBlock(block, maxWidth) {
46363
46839
  }
46364
46840
  let segmentStartX;
46365
46841
  if (currentLine && pendingTabAlignment) {
46366
- segmentStartX = alignSegmentAtTab(segment, font, run);
46842
+ segmentStartX = alignSegmentAtTab(segment, font, run, charPosInRun);
46367
46843
  if (segmentStartX == null) {
46368
46844
  segmentStartX = currentLine.width;
46369
46845
  }
@@ -46373,7 +46849,7 @@ async function measureParagraphBlock(block, maxWidth) {
46373
46849
  if (word2 === "") {
46374
46850
  const spaceStartChar = charPosInRun;
46375
46851
  const spaceEndChar = charPosInRun + 1;
46376
- const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run);
46852
+ const singleSpaceWidth = measureRunWidth(" ", font, ctx2, run, spaceStartChar);
46377
46853
  if (!currentLine) {
46378
46854
  currentLine = {
46379
46855
  fromRun: runIndex,
@@ -46424,12 +46900,12 @@ async function measureParagraphBlock(block, maxWidth) {
46424
46900
  charPosInRun = spaceEndChar;
46425
46901
  continue;
46426
46902
  }
46427
- const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run);
46428
- const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
46429
- const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run) : 0;
46430
- const wordCommitWidth = wordOnlyWidth + spaceWidth;
46431
46903
  const wordStartChar = charPosInRun;
46904
+ const wordOnlyWidth = measureRunWidth(word2, font, ctx2, run, wordStartChar);
46905
+ const shouldIncludeDelimiterSpace = wordIndex < lastNonEmptyWordIndex;
46432
46906
  const wordEndNoSpace = charPosInRun + word2.length;
46907
+ const spaceWidth = shouldIncludeDelimiterSpace ? measureRunWidth(" ", font, ctx2, run, wordEndNoSpace) : 0;
46908
+ const wordCommitWidth = wordOnlyWidth + spaceWidth;
46433
46909
  const wordEndWithSpace = wordEndNoSpace + (shouldIncludeDelimiterSpace ? 1 : 0);
46434
46910
  const effectiveMaxWidth = currentLine ? currentLine.maxWidth : getEffectiveWidth(lines.length === 0 ? initialAvailableWidth : contentWidth);
46435
46911
  if (wordOnlyWidth > effectiveMaxWidth && word2.length > 1) {
@@ -46448,7 +46924,7 @@ async function measureParagraphBlock(block, maxWidth) {
46448
46924
  const hasTabOnlyLine = currentLine && currentLine.segments && currentLine.segments.length === 0 && currentLine.width > 0;
46449
46925
  const remainingWidthAfterTab = hasTabOnlyLine ? currentLine.maxWidth - currentLine.width : lineMaxWidth;
46450
46926
  const chunkWidth = hasTabOnlyLine ? Math.max(remainingWidthAfterTab, lineMaxWidth * 0.25) : lineMaxWidth;
46451
- const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run);
46927
+ const chunks = breakWordIntoChunks(word2, chunkWidth - WIDTH_FUDGE_PX2, font, ctx2, run, wordStartChar);
46452
46928
  let chunkCharOffset = wordStartChar;
46453
46929
  for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
46454
46930
  const chunk = chunks[chunkIndex];
@@ -46572,7 +47048,7 @@ async function measureParagraphBlock(block, maxWidth) {
46572
47048
  if (candidateSpaces > 0) {
46573
47049
  const overflow = totalWidthWithWord - availableWidth;
46574
47050
  if (overflow > 0) {
46575
- const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run) || Math.max(1, boundarySpacing);
47051
+ const baseSpaceWidth = spaceWidth || measureRunWidth(" ", font, ctx2, run, wordEndNoSpace) || Math.max(1, boundarySpacing);
46576
47052
  const perSpaceCompression = overflow / candidateSpaces;
46577
47053
  const maxPerSpaceCompression = baseSpaceWidth * 0.25;
46578
47054
  if (perSpaceCompression <= maxPerSpaceCompression) {
@@ -46747,8 +47223,8 @@ async function measureParagraphBlock(block, maxWidth) {
46747
47223
  const { font: markerFont } = buildFontString(markerRun);
46748
47224
  const markerText = wordLayout.marker.markerText ?? "";
46749
47225
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
46750
- const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
46751
- const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
47226
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
47227
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP$1);
46752
47228
  markerInfo = {
46753
47229
  markerWidth: markerBoxWidth,
46754
47230
  markerTextWidth: glyphWidth,
@@ -47092,7 +47568,7 @@ async function measureListBlock(block, constraints) {
47092
47568
  markerTextWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
47093
47569
  indentLeft = resolveIndentLeft(item);
47094
47570
  const indentHanging = resolveIndentHanging(item);
47095
- markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP, indentHanging);
47571
+ markerWidth = Math.max(MIN_MARKER_GUTTER, markerTextWidth + LIST_MARKER_GAP$1, indentHanging);
47096
47572
  }
47097
47573
  const paragraphWidth = Math.max(1, constraints.maxWidth - indentLeft - markerWidth);
47098
47574
  const paragraphMeasure = await measureParagraphBlock(item.paragraph, paragraphWidth);
@@ -47118,16 +47594,46 @@ const getPrimaryRun = (paragraph) => {
47118
47594
  fontSize: 16
47119
47595
  };
47120
47596
  };
47121
- const measureRunWidth = (text, font, ctx2, run) => {
47597
+ const isWordChar = (char) => {
47598
+ if (!char) return false;
47599
+ const code = char.charCodeAt(0);
47600
+ return code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122 || char === "'";
47601
+ };
47602
+ const capitalizeText = (text, fullText, startOffset) => {
47603
+ if (!text) return text;
47604
+ const hasFullText = typeof startOffset === "number" && fullText != null;
47605
+ let result = "";
47606
+ for (let i = 0; i < text.length; i += 1) {
47607
+ const prevChar = hasFullText ? startOffset + i > 0 ? fullText[startOffset + i - 1] : "" : i > 0 ? text[i - 1] : "";
47608
+ const ch = text[i];
47609
+ result += isWordChar(ch) && !isWordChar(prevChar) ? ch.toUpperCase() : ch;
47610
+ }
47611
+ return result;
47612
+ };
47613
+ const applyTextTransform = (text, run, startOffset) => {
47614
+ const transform = "textTransform" in run ? run.textTransform : void 0;
47615
+ if (!text || !transform || transform === "none") return text;
47616
+ if (transform === "uppercase") return text.toUpperCase();
47617
+ if (transform === "lowercase") return text.toLowerCase();
47618
+ if (transform === "capitalize") {
47619
+ const fullText = "text" in run && typeof run.text === "string" ? run.text : text;
47620
+ return capitalizeText(text, fullText, startOffset);
47621
+ }
47622
+ return text;
47623
+ };
47624
+ const measureRunWidth = (text, font, ctx2, run, startOffset) => {
47122
47625
  const letterSpacing = run.kind === "text" || run.kind === void 0 ? run.letterSpacing || 0 : 0;
47123
- const width = getMeasuredTextWidth(text, font, letterSpacing, ctx2);
47626
+ const displayText = applyTextTransform(text, run, startOffset);
47627
+ const width = getMeasuredTextWidth(displayText, font, letterSpacing, ctx2);
47124
47628
  return roundValue(width);
47125
47629
  };
47126
- const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run) => {
47630
+ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run, startOffset) => {
47127
47631
  const chunks = [];
47632
+ const baseOffset = typeof startOffset === "number" ? startOffset : 0;
47128
47633
  if (maxWidth <= 0) {
47129
- for (const char of word2) {
47130
- const charWidth = measureRunWidth(char, font, ctx2, run);
47634
+ for (let i = 0; i < word2.length; i++) {
47635
+ const char = word2[i];
47636
+ const charWidth = measureRunWidth(char, font, ctx2, run, baseOffset + i);
47131
47637
  chunks.push({ text: char, width: charWidth });
47132
47638
  }
47133
47639
  return chunks;
@@ -47137,11 +47643,11 @@ const breakWordIntoChunks = (word2, maxWidth, font, ctx2, run) => {
47137
47643
  for (let i = 0; i < word2.length; i++) {
47138
47644
  const char = word2[i];
47139
47645
  const testChunk = currentChunk + char;
47140
- const testWidth = measureRunWidth(testChunk, font, ctx2, run);
47646
+ const testWidth = measureRunWidth(testChunk, font, ctx2, run, baseOffset);
47141
47647
  if (testWidth > maxWidth && currentChunk.length > 0) {
47142
47648
  chunks.push({ text: currentChunk, width: currentWidth });
47143
47649
  currentChunk = char;
47144
- currentWidth = measureRunWidth(char, font, ctx2, run);
47650
+ currentWidth = measureRunWidth(char, font, ctx2, run, baseOffset + i);
47145
47651
  } else {
47146
47652
  currentChunk = testChunk;
47147
47653
  currentWidth = testWidth;
@@ -47195,7 +47701,8 @@ const measureDropCap = (ctx2, descriptor, spacing) => {
47195
47701
  italic: run.italic
47196
47702
  });
47197
47703
  ctx2.font = font;
47198
- const metrics = ctx2.measureText(run.text);
47704
+ const displayText = applyTextTransform(run.text, run);
47705
+ const metrics = ctx2.measureText(displayText);
47199
47706
  const advanceWidth = metrics.width;
47200
47707
  const paintedWidth = (metrics.actualBoundingBoxLeft || 0) + (metrics.actualBoundingBoxRight || 0);
47201
47708
  const textWidth = Math.max(advanceWidth, paintedWidth);
@@ -47221,7 +47728,7 @@ const resolveIndentHanging = (item) => {
47221
47728
  if (indentHanging > 0) {
47222
47729
  return indentHanging;
47223
47730
  }
47224
- return DEFAULT_LIST_HANGING_PX;
47731
+ return DEFAULT_LIST_HANGING_PX$1;
47225
47732
  };
47226
47733
  const buildTabStopsPx = (indent, tabs, tabIntervalTwips) => {
47227
47734
  const paragraphIndentTwips = {